diff --git a/Userland/Libraries/LibWeb/CSS/ComputedValues.h b/Userland/Libraries/LibWeb/CSS/ComputedValues.h index 0b1a410830..a8043b875b 100644 --- a/Userland/Libraries/LibWeb/CSS/ComputedValues.h +++ b/Userland/Libraries/LibWeb/CSS/ComputedValues.h @@ -50,6 +50,12 @@ public: static CSS::LengthBox inset() { return { CSS::Length::make_auto(), CSS::Length::make_auto(), CSS::Length::make_auto(), CSS::Length::make_auto() }; } static CSS::LengthBox margin() { return { CSS::Length::make_px(0), CSS::Length::make_px(0), CSS::Length::make_px(0), CSS::Length::make_px(0) }; } static CSS::LengthBox padding() { return { CSS::Length::make_px(0), CSS::Length::make_px(0), CSS::Length::make_px(0), CSS::Length::make_px(0) }; } + static CSS::Length width() { return CSS::Length::make_auto(); } + static CSS::Length min_width() { return CSS::Length::make_auto(); } + static CSS::Length max_width() { return CSS::Length::make_auto(); } + static CSS::Length height() { return CSS::Length::make_auto(); } + static CSS::Length min_height() { return CSS::Length::make_auto(); } + static CSS::Length max_height() { return CSS::Length::make_auto(); } }; struct BackgroundLayerData { @@ -150,12 +156,12 @@ public: CSS::JustifyContent justify_content() const { return m_noninherited.justify_content; } Vector const& box_shadow() const { return m_noninherited.box_shadow; } CSS::BoxSizing box_sizing() const { return m_noninherited.box_sizing; } - Optional const& width() const { return m_noninherited.width; } - Optional const& min_width() const { return m_noninherited.min_width; } - Optional const& max_width() const { return m_noninherited.max_width; } - Optional const& height() const { return m_noninherited.height; } - Optional const& min_height() const { return m_noninherited.min_height; } - Optional const& max_height() const { return m_noninherited.max_height; } + CSS::LengthPercentage const& width() const { return m_noninherited.width; } + CSS::LengthPercentage const& min_width() const { return m_noninherited.min_width; } + CSS::LengthPercentage const& max_width() const { return m_noninherited.max_width; } + CSS::LengthPercentage const& height() const { return m_noninherited.height; } + CSS::LengthPercentage const& min_height() const { return m_noninherited.min_height; } + CSS::LengthPercentage const& max_height() const { return m_noninherited.max_height; } Variant const& vertical_align() const { return m_noninherited.vertical_align; } CSS::LengthBox const& inset() const { return m_noninherited.inset; } @@ -232,12 +238,12 @@ protected: Color text_decoration_color { InitialValues::color() }; Vector text_shadow {}; CSS::Position position { InitialValues::position() }; - Optional width; - Optional min_width; - Optional max_width; - Optional height; - Optional min_height; - Optional max_height; + CSS::LengthPercentage width { InitialValues::width() }; + CSS::LengthPercentage min_width { InitialValues::min_width() }; + CSS::LengthPercentage max_width { InitialValues::max_width() }; + CSS::LengthPercentage height { InitialValues::height() }; + CSS::LengthPercentage min_height { InitialValues::min_height() }; + CSS::LengthPercentage max_height { InitialValues::max_height() }; CSS::LengthBox inset { InitialValues::inset() }; CSS::LengthBox margin { InitialValues::margin() }; CSS::LengthBox padding { InitialValues::padding() }; diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index 8aec140e5f..40a71d7ea7 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -205,25 +205,17 @@ RefPtr ResolvedCSSStyleDeclaration::style_value_for_property(Layout: return StyleValueList::create(move(box_shadow), StyleValueList::Separator::Comma); } case CSS::PropertyID::Width: - return style_value_for_length_percentage(layout_node.computed_values().width().value_or(Length::make_auto())); + return style_value_for_length_percentage(layout_node.computed_values().width()); case CSS::PropertyID::MinWidth: - if (!layout_node.computed_values().min_width().has_value()) - return IdentifierStyleValue::create(CSS::ValueID::Auto); - return style_value_for_length_percentage(layout_node.computed_values().min_width().value()); + return style_value_for_length_percentage(layout_node.computed_values().min_width()); case CSS::PropertyID::MaxWidth: - if (!layout_node.computed_values().max_width().has_value()) - return IdentifierStyleValue::create(CSS::ValueID::None); - return style_value_for_length_percentage(layout_node.computed_values().max_width().value()); + return style_value_for_length_percentage(layout_node.computed_values().max_width()); case CSS::PropertyID::Height: - return style_value_for_length_percentage(layout_node.computed_values().height().value_or(Length::make_auto())); + return style_value_for_length_percentage(layout_node.computed_values().height()); case CSS::PropertyID::MinHeight: - if (!layout_node.computed_values().min_height().has_value()) - return IdentifierStyleValue::create(CSS::ValueID::Auto); - return style_value_for_length_percentage(layout_node.computed_values().min_height().value()); + return style_value_for_length_percentage(layout_node.computed_values().min_height()); case CSS::PropertyID::MaxHeight: - if (!layout_node.computed_values().max_height().has_value()) - return IdentifierStyleValue::create(CSS::ValueID::None); - return style_value_for_length_percentage(layout_node.computed_values().max_height().value()); + return style_value_for_length_percentage(layout_node.computed_values().max_height()); case CSS::PropertyID::Margin: { auto margin = layout_node.computed_values().margin(); auto values = NonnullRefPtrVector {}; diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index f4438f089c..c07742bcdb 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -208,14 +208,14 @@ void BlockFormattingContext::compute_width(Box const& box, LayoutMode layout_mod return width; }; - auto specified_width = computed_values.width().has_value() ? computed_values.width()->resolved(box, width_of_containing_block_as_length).resolved(box) : CSS::Length::make_auto(); + auto specified_width = computed_values.width().resolved(box, width_of_containing_block_as_length).resolved(box); // 1. The tentative used width is calculated (without 'min-width' and 'max-width') auto used_width = try_compute_width(specified_width); // 2. The tentative used width is greater than 'max-width', the rules above are applied again, // but this time using the computed value of 'max-width' as the computed value for 'width'. - auto specified_max_width = computed_values.max_width().has_value() ? computed_values.max_width()->resolved(box, width_of_containing_block_as_length).resolved(box) : CSS::Length::make_auto(); + auto specified_max_width = computed_values.max_width().resolved(box, width_of_containing_block_as_length).resolved(box); if (!specified_max_width.is_auto()) { if (used_width.to_px(box) > specified_max_width.to_px(box)) { used_width = try_compute_width(specified_max_width); @@ -224,7 +224,7 @@ void BlockFormattingContext::compute_width(Box const& box, LayoutMode layout_mod // 3. If the resulting width is smaller than 'min-width', the rules above are applied again, // but this time using the value of 'min-width' as the computed value for 'width'. - auto specified_min_width = computed_values.min_width().has_value() ? computed_values.min_width()->resolved(box, width_of_containing_block_as_length).resolved(box) : CSS::Length::make_auto(); + auto specified_min_width = computed_values.min_width().resolved(box, width_of_containing_block_as_length).resolved(box); if (!specified_min_width.is_auto()) { if (used_width.to_px(box) < specified_min_width.to_px(box)) { used_width = try_compute_width(specified_min_width); @@ -298,14 +298,14 @@ void BlockFormattingContext::compute_width_for_floating_box(Box const& box, Layo return width; }; - auto specified_width = computed_values.width().has_value() ? computed_values.width()->resolved(box, width_of_containing_block_as_length).resolved(box) : CSS::Length::make_auto(); + auto specified_width = computed_values.width().resolved(box, width_of_containing_block_as_length).resolved(box); // 1. The tentative used width is calculated (without 'min-width' and 'max-width') auto width = compute_width(specified_width); // 2. The tentative used width is greater than 'max-width', the rules above are applied again, // but this time using the computed value of 'max-width' as the computed value for 'width'. - auto specified_max_width = computed_values.max_width().has_value() ? computed_values.max_width()->resolved(box, width_of_containing_block_as_length).resolved(box) : CSS::Length::make_auto(); + auto specified_max_width = computed_values.max_width().resolved(box, width_of_containing_block_as_length).resolved(box); if (!specified_max_width.is_auto()) { if (width.to_px(box) > specified_max_width.to_px(box)) width = compute_width(specified_max_width); @@ -313,7 +313,7 @@ void BlockFormattingContext::compute_width_for_floating_box(Box const& box, Layo // 3. If the resulting width is smaller than 'min-width', the rules above are applied again, // but this time using the value of 'min-width' as the computed value for 'width'. - auto specified_min_width = computed_values.min_width().has_value() ? computed_values.min_width()->resolved(box, width_of_containing_block_as_length).resolved(box) : CSS::Length::make_auto(); + auto specified_min_width = computed_values.min_width().resolved(box, width_of_containing_block_as_length).resolved(box); if (!specified_min_width.is_auto()) { if (width.to_px(box) < specified_min_width.to_px(box)) width = compute_width(specified_min_width); @@ -350,22 +350,21 @@ float BlockFormattingContext::compute_theoretical_height(FormattingState const& if (is(box)) { height = compute_height_for_replaced_element(state, verify_cast(box)); } else { - if (!box.computed_values().height().has_value() - || (box.computed_values().height()->is_length() && box.computed_values().height()->length().is_auto()) - || (computed_values.height().has_value() && computed_values.height()->is_percentage() && !is_absolute(containing_block.computed_values().height()))) { + if (box.computed_values().height().is_auto() + || (computed_values.height().is_percentage() && !is_absolute(containing_block.computed_values().height()))) { height = compute_auto_height_for_block_level_element(state, box); } else { - height = computed_values.height().has_value() ? computed_values.height()->resolved(box, containing_block_height).to_px(box) : 0; + height = computed_values.height().resolved(box, containing_block_height).to_px(box); } } - auto specified_max_height = computed_values.max_height().has_value() ? computed_values.max_height()->resolved(box, containing_block_height).resolved(box) : CSS::Length::make_auto(); + auto specified_max_height = computed_values.max_height().resolved(box, containing_block_height).resolved(box); if (!specified_max_height.is_auto() - && !(computed_values.max_height().has_value() && computed_values.max_height()->is_percentage() && !is_absolute(containing_block.computed_values().height()))) + && !(computed_values.max_height().is_percentage() && !is_absolute(containing_block.computed_values().height()))) height = min(height, specified_max_height.to_px(box)); - auto specified_min_height = computed_values.min_height().has_value() ? computed_values.min_height()->resolved(box, containing_block_height).resolved(box) : CSS::Length::make_auto(); + auto specified_min_height = computed_values.min_height().resolved(box, containing_block_height).resolved(box); if (!specified_min_height.is_auto() - && !(computed_values.min_height().has_value() && computed_values.min_height()->is_percentage() && !is_absolute(containing_block.computed_values().height()))) + && !(computed_values.min_height().is_percentage() && !is_absolute(containing_block.computed_values().height()))) height = max(height, specified_min_height.to_px(box)); return height; } @@ -461,7 +460,7 @@ void BlockFormattingContext::layout_block_level_children(BlockContainer const& b if (layout_mode != LayoutMode::Normal) { auto& width = block_container.computed_values().width(); - if (!width.has_value() || (width->is_length() && width->length().is_auto())) { + if (width.is_auto()) { auto& block_container_state = m_state.get_mutable(block_container); block_container_state.content_width = greatest_child_width(block_container); } diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp index 9236edb369..4943f10771 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp @@ -277,9 +277,9 @@ float FlexFormattingContext::resolved_definite_cross_size(Box const& box) const else VERIFY(box.has_definite_width()); auto const& cross_value = is_row_layout() ? box.computed_values().height() : box.computed_values().width(); - if (cross_value->is_length()) - return cross_value->length().to_px(box); - return cross_value->resolved(box, CSS::Length::make_px(specified_cross_size(flex_container()))).to_px(box); + if (cross_value.is_length()) + return cross_value.length().to_px(box); + return cross_value.resolved(box, CSS::Length::make_px(specified_cross_size(flex_container()))).to_px(box); } float FlexFormattingContext::resolved_definite_main_size(Box const& box) const @@ -289,9 +289,9 @@ float FlexFormattingContext::resolved_definite_main_size(Box const& box) const else VERIFY(box.has_definite_height()); auto const& cross_value = is_row_layout() ? box.computed_values().width() : box.computed_values().height(); - if (cross_value->is_length()) - return cross_value->length().to_px(box); - return cross_value->resolved(box, CSS::Length::make_px(specified_main_size(flex_container()))).to_px(box); + if (cross_value.is_length()) + return cross_value.length().to_px(box); + return cross_value.resolved(box, CSS::Length::make_px(specified_main_size(flex_container()))).to_px(box); } bool FlexFormattingContext::has_main_min_size(Box const& box) const @@ -315,9 +315,7 @@ float FlexFormattingContext::specified_main_size_of_child_box(Box const& child_b { auto main_size_of_parent = specified_main_size(flex_container()); auto& value = is_row_layout() ? child_box.computed_values().width() : child_box.computed_values().height(); - if (!value.has_value()) - return 0; - return value->resolved(child_box, CSS::Length::make_px(main_size_of_parent)).to_px(child_box); + return value.resolved(child_box, CSS::Length::make_px(main_size_of_parent)).to_px(child_box); } float FlexFormattingContext::specified_main_min_size(Box const& box) const @@ -371,7 +369,7 @@ float FlexFormattingContext::calculated_main_size(Box const& box) const bool FlexFormattingContext::is_cross_auto(Box const& box) const { auto& cross_length = is_row_layout() ? box.computed_values().height() : box.computed_values().width(); - return cross_length.has_value() && cross_length->is_length() && cross_length->length().is_auto(); + return cross_length.is_auto(); } bool FlexFormattingContext::is_main_axis_margin_first_auto(Box const& box) const @@ -1195,7 +1193,7 @@ void FlexFormattingContext::determine_flex_container_used_cross_size(float const } else { // Flex container has indefinite cross size. auto cross_size_value = is_row_layout() ? flex_container().computed_values().height() : flex_container().computed_values().width(); - if (!cross_size_value.has_value() || (cross_size_value->is_length() && cross_size_value->length().is_auto()) || cross_size_value->is_percentage()) { + if (cross_size_value.is_auto() || cross_size_value.is_percentage()) { // If a content-based cross size is needed, use the sum of the flex lines' cross sizes. float sum_of_flex_lines_cross_sizes = 0; for (auto& flex_line : m_flex_lines) { @@ -1203,12 +1201,12 @@ void FlexFormattingContext::determine_flex_container_used_cross_size(float const } cross_size = sum_of_flex_lines_cross_sizes; - if (cross_size_value->is_percentage()) { + if (cross_size_value.is_percentage()) { // FIXME: Handle percentage values here! Right now we're just treating them as "auto" } } else { // Otherwise, resolve the indefinite size at this point. - cross_size = cross_size_value->resolved(flex_container(), CSS::Length::make_px(specified_cross_size(*flex_container().containing_block()))).to_px(flex_container()); + cross_size = cross_size_value.resolved(flex_container(), CSS::Length::make_px(specified_cross_size(*flex_container().containing_block()))).to_px(flex_container()); } } set_cross_size(flex_container(), css_clamp(cross_size, cross_min_size, cross_max_size)); diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index 7c7ef0f040..db57ee0f76 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -180,10 +180,10 @@ static Gfx::FloatSize solve_replaced_size_constraint(FormattingState const& stat auto width_of_containing_block = CSS::Length::make_px(containing_block_state.content_width); auto height_of_containing_block = CSS::Length::make_px(containing_block_state.content_height); - auto specified_min_width = box.computed_values().min_width().has_value() ? box.computed_values().min_width()->resolved(box, width_of_containing_block).to_px(box) : 0; - auto specified_max_width = box.computed_values().max_width().has_value() ? box.computed_values().max_width()->resolved(box, width_of_containing_block).to_px(box) : w; - auto specified_min_height = box.computed_values().min_height().has_value() ? box.computed_values().min_height()->resolved(box, height_of_containing_block).to_px(box) : 0; - auto specified_max_height = box.computed_values().max_height().has_value() ? box.computed_values().max_height()->resolved(box, height_of_containing_block).to_px(box) : h; + auto specified_min_width = box.computed_values().min_width().is_auto() ? 0 : box.computed_values().min_width().resolved(box, width_of_containing_block).to_px(box); + auto specified_max_width = box.computed_values().max_width().is_auto() ? w : box.computed_values().max_width().resolved(box, width_of_containing_block).to_px(box); + auto specified_min_height = box.computed_values().min_height().is_auto() ? 0 : box.computed_values().min_height().resolved(box, height_of_containing_block).to_px(box); + auto specified_max_height = box.computed_values().max_height().is_auto() ? h : box.computed_values().max_height().resolved(box, height_of_containing_block).to_px(box); auto min_width = min(specified_min_width, specified_max_width); auto max_width = max(specified_min_width, specified_max_width); @@ -329,7 +329,7 @@ float FormattingContext::tentative_width_for_replaced_element(FormattingState co { auto const& containing_block = *box.containing_block(); auto height_of_containing_block = CSS::Length::make_px(state.get(containing_block).content_height); - auto computed_height = box.computed_values().height().has_value() ? box.computed_values().height()->resolved(box, height_of_containing_block).resolved(box) : CSS::Length::make_auto(); + auto computed_height = box.computed_values().height().resolved(box, height_of_containing_block).resolved(box); float used_width = computed_width.to_px(box); @@ -400,14 +400,14 @@ float FormattingContext::compute_width_for_replaced_element(FormattingState cons if (margin_right.is_auto()) margin_right = zero_value; - auto specified_width = box.computed_values().width().has_value() ? box.computed_values().width()->resolved(box, width_of_containing_block).resolved(box) : CSS::Length::make_auto(); + auto specified_width = box.computed_values().width().resolved(box, width_of_containing_block).resolved(box); // 1. The tentative used width is calculated (without 'min-width' and 'max-width') auto used_width = tentative_width_for_replaced_element(state, box, specified_width); // 2. The tentative used width is greater than 'max-width', the rules above are applied again, // but this time using the computed value of 'max-width' as the computed value for 'width'. - auto specified_max_width = box.computed_values().max_width().has_value() ? box.computed_values().max_width()->resolved(box, width_of_containing_block).resolved(box) : CSS::Length::make_auto(); + auto specified_max_width = box.computed_values().max_width().resolved(box, width_of_containing_block).resolved(box); if (!specified_max_width.is_auto()) { if (used_width > specified_max_width.to_px(box)) { used_width = tentative_width_for_replaced_element(state, box, specified_max_width); @@ -416,7 +416,7 @@ float FormattingContext::compute_width_for_replaced_element(FormattingState cons // 3. If the resulting width is smaller than 'min-width', the rules above are applied again, // but this time using the value of 'min-width' as the computed value for 'width'. - auto specified_min_width = box.computed_values().min_width().has_value() ? box.computed_values().min_width()->resolved(box, width_of_containing_block).resolved(box) : CSS::Length::make_auto(); + auto specified_min_width = box.computed_values().min_width().resolved(box, width_of_containing_block).resolved(box); if (!specified_min_width.is_auto()) { if (used_width < specified_min_width.to_px(box)) { used_width = tentative_width_for_replaced_element(state, box, specified_min_width); @@ -432,7 +432,7 @@ float FormattingContext::tentative_height_for_replaced_element(FormattingState c { auto const& containing_block = *box.containing_block(); auto width_of_containing_block = CSS::Length::make_px(state.get(containing_block).content_width); - auto computed_width = box.computed_values().width().has_value() ? box.computed_values().width()->resolved(box, width_of_containing_block).resolved(box) : CSS::Length::make_auto(); + auto computed_width = box.computed_values().width().resolved(box, width_of_containing_block).resolved(box); // If 'height' and 'width' both have computed values of 'auto' and the element also has // an intrinsic height, then that intrinsic height is the used value of 'height'. @@ -467,8 +467,8 @@ float FormattingContext::compute_height_for_replaced_element(FormattingState con auto const& containing_block_state = state.get(containing_block); auto width_of_containing_block = CSS::Length::make_px(containing_block_state.content_width); auto height_of_containing_block = CSS::Length::make_px(containing_block_state.content_height); - auto specified_width = box.computed_values().width().has_value() ? box.computed_values().width()->resolved(box, width_of_containing_block).resolved(box) : CSS::Length::make_auto(); - auto specified_height = box.computed_values().height().has_value() ? box.computed_values().height()->resolved(box, height_of_containing_block).resolved(box) : CSS::Length::make_auto(); + auto specified_width = box.computed_values().width().resolved(box, width_of_containing_block).resolved(box); + auto specified_height = box.computed_values().height().resolved(box, height_of_containing_block).resolved(box); float used_height = tentative_height_for_replaced_element(state, box, specified_height); @@ -591,14 +591,14 @@ void FormattingContext::compute_width_for_absolutely_positioned_non_replaced_ele return width; }; - auto specified_width = computed_values.width().has_value() ? computed_values.width()->resolved(box, width_of_containing_block).resolved(box) : CSS::Length::make_auto(); + auto specified_width = computed_values.width().resolved(box, width_of_containing_block).resolved(box); // 1. The tentative used width is calculated (without 'min-width' and 'max-width') auto used_width = try_compute_width(specified_width); // 2. The tentative used width is greater than 'max-width', the rules above are applied again, // but this time using the computed value of 'max-width' as the computed value for 'width'. - auto specified_max_width = computed_values.max_width().has_value() ? computed_values.max_width()->resolved(box, width_of_containing_block).resolved(box) : CSS::Length::make_auto(); + auto specified_max_width = computed_values.max_width().resolved(box, width_of_containing_block).resolved(box); if (!specified_max_width.is_auto()) { if (used_width.to_px(box) > specified_max_width.to_px(box)) { used_width = try_compute_width(specified_max_width); @@ -607,7 +607,7 @@ void FormattingContext::compute_width_for_absolutely_positioned_non_replaced_ele // 3. If the resulting width is smaller than 'min-width', the rules above are applied again, // but this time using the value of 'min-width' as the computed value for 'width'. - auto specified_min_width = computed_values.min_width().has_value() ? computed_values.min_width()->resolved(box, width_of_containing_block).resolved(box) : CSS::Length::make_auto(); + auto specified_min_width = computed_values.min_width().resolved(box, width_of_containing_block).resolved(box); if (!specified_min_width.is_auto()) { if (used_width.to_px(box) < specified_min_width.to_px(box)) { used_width = try_compute_width(specified_min_width); @@ -650,15 +650,15 @@ void FormattingContext::compute_height_for_absolutely_positioned_non_replaced_el CSS::Length specified_bottom = computed_values.inset().bottom.resolved(box, height_of_containing_block).resolved(box); CSS::Length specified_height = CSS::Length::make_auto(); - if (computed_values.height().has_value() && computed_values.height()->is_percentage() - && !(containing_block.computed_values().height().has_value() && containing_block.computed_values().height()->is_length() && containing_block.computed_values().height()->length().is_absolute())) { + if (computed_values.height().is_percentage() + && !(containing_block.computed_values().height().is_length() && containing_block.computed_values().height().length().is_absolute())) { // specified_height is already auto } else { - specified_height = computed_values.height().has_value() ? computed_values.height()->resolved(box, height_of_containing_block).resolved(box) : CSS::Length::make_auto(); + specified_height = computed_values.height().resolved(box, height_of_containing_block).resolved(box); } - auto specified_max_height = computed_values.max_height().has_value() ? computed_values.max_height()->resolved(box, height_of_containing_block).resolved(box) : CSS::Length::make_auto(); - auto specified_min_height = computed_values.min_height().has_value() ? computed_values.min_height()->resolved(box, height_of_containing_block).resolved(box) : CSS::Length::make_auto(); + auto specified_max_height = computed_values.max_height().resolved(box, height_of_containing_block).resolved(box); + auto specified_min_height = computed_values.min_height().resolved(box, height_of_containing_block).resolved(box); box_state.margin_top = computed_values.margin().top.resolved(box, width_of_containing_block).to_px(box); box_state.margin_bottom = computed_values.margin().bottom.resolved(box, width_of_containing_block).to_px(box); @@ -697,7 +697,7 @@ void FormattingContext::layout_absolutely_positioned_element(Box const& box) auto height_of_containing_block = CSS::Length::make_px(containing_block_state.content_height); auto& box_state = m_state.get_mutable(box); - auto specified_width = box.computed_values().width().has_value() ? box.computed_values().width()->resolved(box, width_of_containing_block).resolved(box) : CSS::Length::make_auto(); + auto specified_width = box.computed_values().width().resolved(box, width_of_containing_block).resolved(box); compute_width_for_absolutely_positioned_element(box); auto independent_formatting_context = layout_inside(box, LayoutMode::Normal); diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index a74235edd3..c276de356c 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -124,7 +124,7 @@ void InlineFormattingContext::dimension_box_on_line(Box const& box, LayoutMode l auto const& containing_block_state = m_state.get(containing_block()); auto& width_value = inline_block.computed_values().width(); - if (!width_value.has_value() || (width_value->is_length() && width_value->length().is_auto())) { + if (width_value.is_auto()) { auto result = calculate_shrink_to_fit_widths(inline_block); auto available_width = containing_block_state.content_width @@ -139,17 +139,17 @@ void InlineFormattingContext::dimension_box_on_line(Box const& box, LayoutMode l box_state.content_width = width; } else { auto container_width = CSS::Length::make_px(containing_block_state.content_width); - box_state.content_width = width_value->resolved(box, container_width).to_px(inline_block); + box_state.content_width = width_value.resolved(box, container_width).to_px(inline_block); } auto independent_formatting_context = layout_inside(inline_block, layout_mode); auto& height_value = inline_block.computed_values().height(); - if (!height_value.has_value() || (height_value->is_length() && height_value->length().is_auto())) { + if (height_value.is_auto()) { // FIXME: (10.6.6) If 'height' is 'auto', the height depends on the element's descendants per 10.6.7. BlockFormattingContext::compute_height(inline_block, m_state); } else { auto container_height = CSS::Length::make_px(containing_block_state.content_height); - box_state.content_height = height_value->resolved(box, container_height).to_px(inline_block); + box_state.content_height = height_value.resolved(box, container_height).to_px(inline_block); } independent_formatting_context->parent_context_did_dimension_child_root_box(); diff --git a/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp index 8bf7ac3509..f2a2a83354 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp @@ -37,8 +37,8 @@ void SVGFormattingContext::run(Box const& box, LayoutMode) auto& layout_node = static_cast(*(svg_element->layout_node())); // FIXME: Allow for relative lengths here - geometry_box_state.content_width = layout_node.computed_values().width().value().resolved(layout_node, { 0, CSS::Length::Type::Px }).to_px(layout_node); - geometry_box_state.content_height = layout_node.computed_values().height().value().resolved(layout_node, { 0, CSS::Length::Type::Px }).to_px(layout_node); + geometry_box_state.content_width = layout_node.computed_values().width().resolved(layout_node, { 0, CSS::Length::Type::Px }).to_px(layout_node); + geometry_box_state.content_height = layout_node.computed_values().height().resolved(layout_node, { 0, CSS::Length::Type::Px }).to_px(layout_node); return IterationDecision::Continue; } diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp index 4833ccfa79..907ba5bd87 100644 --- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp @@ -29,7 +29,7 @@ void TableFormattingContext::run(Box const& box, LayoutMode) compute_width(box); auto table_width = CSS::Length::make_px(box_state.content_width); - auto table_width_is_auto = box.computed_values().width().has_value() && box.computed_values().width()->is_length() && box.computed_values().width()->length().is_auto(); + auto table_width_is_auto = box.computed_values().width().is_auto(); float total_content_width = 0; float total_content_height = 0; @@ -94,7 +94,7 @@ void TableFormattingContext::run(Box const& box, LayoutMode) content_height += row_state.content_height; }); - if (row_group_box.computed_values().width().has_value() && row_group_box.computed_values().width()->is_length() && row_group_box.computed_values().width()->length().is_auto()) + if (row_group_box.computed_values().width().is_auto()) row_group_box_state.content_width = content_width; row_group_box_state.content_height = content_height; @@ -117,7 +117,7 @@ void TableFormattingContext::calculate_column_widths(Box const& row, CSS::Length row.for_each_child_of_type([&](auto& cell) { auto& cell_state = m_state.get_mutable(cell); auto const& computed_values = cell.computed_values(); - auto specified_width = computed_values.width().has_value() ? computed_values.width()->resolved(cell, table_width).resolved(cell) : CSS::Length::make_auto(); + auto specified_width = computed_values.width().resolved(cell, table_width).resolved(cell); compute_width(cell, specified_width.is_auto() ? LayoutMode::MinContent : LayoutMode::Normal); (void)layout_inside(cell, LayoutMode::Normal); @@ -166,7 +166,7 @@ void TableFormattingContext::layout_row(Box const& row, Vector& col float tallest_cell_height = 0; float content_width = 0; auto* table = row.first_ancestor_of_type(); - bool use_auto_layout = !table || (!table->computed_values().width().has_value() || (table->computed_values().width()->is_length() && table->computed_values().width()->length().is_auto())); + bool use_auto_layout = !table || table->computed_values().width().is_auto(); row.for_each_child_of_type([&](auto& cell) { auto& cell_state = m_state.get_mutable(cell); diff --git a/Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp index a8fbbba311..8de189a7ef 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp @@ -70,8 +70,8 @@ Optional SVGGraphicsElement::stroke_width() const float viewport_height = 0; if (auto* svg_svg_element = first_ancestor_of_type()) { if (auto* svg_svg_layout_node = svg_svg_element->layout_node()) { - viewport_width = svg_svg_layout_node->computed_values().width().value().resolved(*svg_svg_layout_node, { 0, CSS::Length::Type::Px }).to_px(*svg_svg_layout_node); - viewport_height = svg_svg_layout_node->computed_values().height().value().resolved(*svg_svg_layout_node, { 0, CSS::Length::Type::Px }).to_px(*svg_svg_layout_node); + viewport_width = svg_svg_layout_node->computed_values().width().resolved(*svg_svg_layout_node, { 0, CSS::Length::Type::Px }).to_px(*svg_svg_layout_node); + viewport_height = svg_svg_layout_node->computed_values().height().resolved(*svg_svg_layout_node, { 0, CSS::Length::Type::Px }).to_px(*svg_svg_layout_node); } } auto scaled_viewport_size = CSS::Length::make_px((viewport_width + viewport_height) * 0.5f);