From 67066c5140b1a2f026f099cec3fe90525cdf41ec Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 18 Feb 2022 16:17:27 +0000 Subject: [PATCH] LibWeb: Remove fallback value from Length::resolved() Nobody makes undefined Lengths now, (although actually removing Undefined will come in a later commit) so we can remove this parameter, and `resolved_or_auto()`/`resolved_or_zero()`. --- Userland/Libraries/LibWeb/CSS/Length.cpp | 14 +--- Userland/Libraries/LibWeb/CSS/Length.h | 4 +- .../LibWeb/Layout/BlockFormattingContext.cpp | 54 ++++++------- Userland/Libraries/LibWeb/Layout/Box.cpp | 8 +- .../LibWeb/Layout/FlexFormattingContext.cpp | 24 +++--- .../LibWeb/Layout/FormattingContext.cpp | 80 +++++++++---------- .../LibWeb/Layout/InlineFormattingContext.cpp | 12 +-- .../Libraries/LibWeb/Layout/InlineNode.cpp | 8 +- Userland/Libraries/LibWeb/Layout/Node.cpp | 2 +- .../LibWeb/Painting/BackgroundPainting.cpp | 12 +-- .../LibWeb/Painting/BorderPainting.cpp | 8 +- 11 files changed, 106 insertions(+), 120 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Length.cpp b/Userland/Libraries/LibWeb/CSS/Length.cpp index b85657a567..09503162c0 100644 --- a/Userland/Libraries/LibWeb/CSS/Length.cpp +++ b/Userland/Libraries/LibWeb/CSS/Length.cpp @@ -57,10 +57,8 @@ Length Length::percentage_of(Percentage const& percentage) const return Length { percentage.as_fraction() * raw_value(), m_type }; } -Length Length::resolved(Length const& fallback_for_undefined, Layout::Node const& layout_node) const +Length Length::resolved(Layout::Node const& layout_node) const { - if (is_undefined()) - return fallback_for_undefined; if (is_calculated()) return m_calculated_style->resolve_length(layout_node).release_value(); if (is_relative()) @@ -68,16 +66,6 @@ Length Length::resolved(Length const& fallback_for_undefined, Layout::Node const return *this; } -Length Length::resolved_or_auto(Layout::Node const& layout_node) const -{ - return resolved(make_auto(), layout_node); -} - -Length Length::resolved_or_zero(Layout::Node const& layout_node) const -{ - return resolved(make_px(0), layout_node); -} - float Length::relative_length_to_px(Gfx::IntRect const& viewport_rect, Gfx::FontMetrics const& font_metrics, float root_font_size) const { switch (m_type) { diff --git a/Userland/Libraries/LibWeb/CSS/Length.h b/Userland/Libraries/LibWeb/CSS/Length.h index 4087d52994..cbfd43d34f 100644 --- a/Userland/Libraries/LibWeb/CSS/Length.h +++ b/Userland/Libraries/LibWeb/CSS/Length.h @@ -46,9 +46,7 @@ public: static Length make_calculated(NonnullRefPtr); Length percentage_of(Percentage const&) const; - Length resolved(Length const& fallback_for_undefined, Layout::Node const& layout_node) const; - Length resolved_or_auto(Layout::Node const& layout_node) const; - Length resolved_or_zero(Layout::Node const& layout_node) const; + Length resolved(Layout::Node const& layout_node) const; bool is_undefined_or_auto() const { return m_type == Type::Undefined || m_type == Type::Auto; } bool is_undefined() const { return m_type == Type::Undefined; } diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index b2a16757e3..740ce04665 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -67,7 +67,7 @@ void BlockFormattingContext::apply_transformations_to_children(Box& box) continue; transformation.values.first().visit( [&](CSS::Length& value) { - transform_y_offset += value.resolved_or_zero(child_box).to_px(child_box); + transform_y_offset += value.resolved(child_box).to_px(child_box); }, [&](float value) { transform_y_offset += value; @@ -115,13 +115,13 @@ void BlockFormattingContext::compute_width(Box& box) auto margin_left = CSS::Length::make_auto(); auto margin_right = CSS::Length::make_auto(); - const auto padding_left = computed_values.padding().left.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box); - const auto padding_right = computed_values.padding().right.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box); + const auto padding_left = computed_values.padding().left.resolved(box, width_of_containing_block_as_length).resolved(box); + const auto padding_right = computed_values.padding().right.resolved(box, width_of_containing_block_as_length).resolved(box); auto try_compute_width = [&](const auto& a_width) { CSS::Length width = a_width; - margin_left = computed_values.margin().left.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box); - margin_right = computed_values.margin().right.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box); + margin_left = computed_values.margin().left.resolved(box, width_of_containing_block_as_length).resolved(box); + margin_right = computed_values.margin().right.resolved(box, width_of_containing_block_as_length).resolved(box); float total_px = computed_values.border_left().width + computed_values.border_right().width; for (auto& value : { margin_left, padding_left, width, padding_right, margin_right }) { @@ -195,14 +195,14 @@ void BlockFormattingContext::compute_width(Box& box) return width; }; - auto specified_width = computed_values.width().has_value() ? computed_values.width()->resolved(box, width_of_containing_block_as_length).resolved_or_auto(box) : CSS::Length::make_auto(); + 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(); // 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_or_auto(box) : CSS::Length::make_auto(); + 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(); 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); @@ -211,7 +211,7 @@ void BlockFormattingContext::compute_width(Box& box) // 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_or_auto(box) : CSS::Length::make_auto(); + 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(); 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); @@ -235,10 +235,10 @@ void BlockFormattingContext::compute_width_for_floating_box(Box& box) auto width_of_containing_block_as_length = CSS::Length::make_px(width_of_containing_block); auto zero_value = CSS::Length::make_px(0); - auto margin_left = computed_values.margin().left.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box); - auto margin_right = computed_values.margin().right.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box); - const auto padding_left = computed_values.padding().left.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box); - const auto padding_right = computed_values.padding().right.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box); + auto margin_left = computed_values.margin().left.resolved(box, width_of_containing_block_as_length).resolved(box); + auto margin_right = computed_values.margin().right.resolved(box, width_of_containing_block_as_length).resolved(box); + const auto padding_left = computed_values.padding().left.resolved(box, width_of_containing_block_as_length).resolved(box); + const auto padding_right = computed_values.padding().right.resolved(box, width_of_containing_block_as_length).resolved(box); // If 'margin-left', or 'margin-right' are computed as 'auto', their used value is '0'. if (margin_left.is_auto()) @@ -246,7 +246,7 @@ void BlockFormattingContext::compute_width_for_floating_box(Box& box) if (margin_right.is_auto()) margin_right = zero_value; - auto width = computed_values.width().has_value() ? computed_values.width()->resolved(box, width_of_containing_block_as_length).resolved_or_auto(box) : CSS::Length::make_auto(); + auto width = computed_values.width().has_value() ? computed_values.width()->resolved(box, width_of_containing_block_as_length).resolved(box) : CSS::Length::make_auto(); // If 'width' is computed as 'auto', the used value is the "shrink-to-fit" width. if (width.is_auto()) { @@ -264,7 +264,7 @@ void BlockFormattingContext::compute_width_for_floating_box(Box& box) width = CSS::Length(min(max(result.preferred_minimum_width, available_width), result.preferred_width), CSS::Length::Type::Px); } - float final_width = width.resolved_or_zero(box).to_px(box); + float final_width = width.resolved(box).to_px(box); box.set_content_width(final_width); box.box_model().margin.left = margin_left.to_px(box); box.box_model().margin.right = margin_right.to_px(box); @@ -299,15 +299,15 @@ float BlockFormattingContext::compute_theoretical_height(Box const& box) || (computed_values.height().has_value() && computed_values.height()->is_percentage() && !is_absolute(containing_block.computed_values().height()))) { height = compute_auto_height_for_block_level_element(box, ConsiderFloats::No); } else { - height = computed_values.height().has_value() ? computed_values.height()->resolved(box, containing_block_height).resolved_or_auto(box).to_px(box) : 0; + height = computed_values.height().has_value() ? computed_values.height()->resolved(box, containing_block_height).resolved(box).to_px(box) : 0; } } - auto specified_max_height = computed_values.max_height().has_value() ? computed_values.max_height()->resolved(box, containing_block_height).resolved_or_auto(box) : CSS::Length::make_auto(); + 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(); 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()))) 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_or_auto(box) : CSS::Length::make_auto(); + 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(); 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()))) height = max(height, specified_min_height.to_px(box)); @@ -323,13 +323,13 @@ void BlockFormattingContext::compute_height(Box& box) // First, resolve the top/bottom parts of the surrounding box model. // FIXME: While negative values are generally allowed for margins, for now just ignore those for height calculation - box.box_model().margin.top = max(computed_values.margin().top.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box).to_px(box), 0); - box.box_model().margin.bottom = max(computed_values.margin().bottom.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box).to_px(box), 0); + box.box_model().margin.top = max(computed_values.margin().top.resolved(box, width_of_containing_block_as_length).resolved(box).to_px(box), 0); + box.box_model().margin.bottom = max(computed_values.margin().bottom.resolved(box, width_of_containing_block_as_length).resolved(box).to_px(box), 0); box.box_model().border.top = computed_values.border_top().width; box.box_model().border.bottom = computed_values.border_bottom().width; - box.box_model().padding.top = computed_values.padding().top.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box).to_px(box); - box.box_model().padding.bottom = computed_values.padding().bottom.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box).to_px(box); + box.box_model().padding.top = computed_values.padding().top.resolved(box, width_of_containing_block_as_length).resolved(box).to_px(box); + box.box_model().padding.bottom = computed_values.padding().bottom.resolved(box, width_of_containing_block_as_length).resolved(box).to_px(box); auto height = compute_theoretical_height(box); box.set_content_height(height); @@ -345,8 +345,8 @@ void BlockFormattingContext::compute_position(Box& box) float width_of_containing_block = box.containing_block()->content_width(); auto width_of_containing_block_as_length = CSS::Length::make_px(width_of_containing_block); - auto specified_left = computed_values.offset().left.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box); - auto specified_right = computed_values.offset().right.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box); + auto specified_left = computed_values.offset().left.resolved(box, width_of_containing_block_as_length).resolved(box); + auto specified_right = computed_values.offset().right.resolved(box, width_of_containing_block_as_length).resolved(box); if (specified_left.is_auto() && specified_right.is_auto()) { // If both 'left' and 'right' are 'auto' (their initial values), the used values are '0' (i.e., the boxes stay in their original position). @@ -452,12 +452,12 @@ void BlockFormattingContext::compute_vertical_box_model_metrics(Box& child_box, auto const& computed_values = child_box.computed_values(); auto width_of_containing_block = CSS::Length::make_px(containing_block.content_width()); - box_model.margin.top = computed_values.margin().top.resolved(child_box, width_of_containing_block).resolved_or_zero(containing_block).to_px(child_box); - box_model.margin.bottom = computed_values.margin().bottom.resolved(child_box, width_of_containing_block).resolved_or_zero(containing_block).to_px(child_box); + box_model.margin.top = computed_values.margin().top.resolved(child_box, width_of_containing_block).resolved(containing_block).to_px(child_box); + box_model.margin.bottom = computed_values.margin().bottom.resolved(child_box, width_of_containing_block).resolved(containing_block).to_px(child_box); box_model.border.top = computed_values.border_top().width; box_model.border.bottom = computed_values.border_bottom().width; - box_model.padding.top = computed_values.padding().top.resolved(child_box, width_of_containing_block).resolved_or_zero(containing_block).to_px(child_box); - box_model.padding.bottom = computed_values.padding().bottom.resolved(child_box, width_of_containing_block).resolved_or_zero(containing_block).to_px(child_box); + box_model.padding.top = computed_values.padding().top.resolved(child_box, width_of_containing_block).resolved(containing_block).to_px(child_box); + box_model.padding.bottom = computed_values.padding().bottom.resolved(child_box, width_of_containing_block).resolved(containing_block).to_px(child_box); } void BlockFormattingContext::place_block_level_element_in_normal_flow_vertically(Box& child_box, BlockContainer const& containing_block) diff --git a/Userland/Libraries/LibWeb/Layout/Box.cpp b/Userland/Libraries/LibWeb/Layout/Box.cpp index 21e8b2a86b..0eb92dfbee 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.cpp +++ b/Userland/Libraries/LibWeb/Layout/Box.cpp @@ -107,10 +107,10 @@ void Box::paint_box_shadow(PaintContext& context) for (auto const& layer : box_shadow_data) { resolved_box_shadow_data.empend( layer.color, - static_cast(layer.offset_x.resolved_or_zero(*this).to_px(*this)), - static_cast(layer.offset_y.resolved_or_zero(*this).to_px(*this)), - static_cast(layer.blur_radius.resolved_or_zero(*this).to_px(*this)), - static_cast(layer.spread_distance.resolved_or_zero(*this).to_px(*this)), + static_cast(layer.offset_x.resolved(*this).to_px(*this)), + static_cast(layer.offset_y.resolved(*this).to_px(*this)), + static_cast(layer.blur_radius.resolved(*this).to_px(*this)), + static_cast(layer.spread_distance.resolved(*this).to_px(*this)), layer.placement == CSS::BoxShadowPlacement::Outer ? Painting::BoxShadowPlacement::Outer : Painting::BoxShadowPlacement::Inner); } Painting::paint_box_shadow(context, enclosing_int_rect(absolute_border_box_rect()), resolved_box_shadow_data); diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp index eba2536701..d5bc06a894 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp @@ -22,7 +22,7 @@ static float get_pixel_size(Box const& box, Optional cons if (!length_percentage.has_value()) return 0; auto inner_main_size = CSS::Length::make_px(box.containing_block()->content_width()); - return length_percentage->resolved(box, inner_main_size).resolved(CSS::Length::make_px(0), box).to_px(box); + return length_percentage->resolved(box, inner_main_size).resolved(box).to_px(box); } static bool is_undefined_or_auto(Optional const& length_percentage) @@ -120,15 +120,15 @@ void FlexFormattingContext::populate_specified_margins(FlexItem& item, CSS::Flex auto width_of_containing_block_as_length = CSS::Length::make_px(width_of_containing_block); // FIXME: This should also take reverse-ness into account if (flex_direction == CSS::FlexDirection::Row || flex_direction == CSS::FlexDirection::RowReverse) { - item.margins.main_before = item.box.computed_values().margin().left.resolved(item.box, width_of_containing_block_as_length).resolved_or_zero(item.box).to_px(item.box); - item.margins.main_after = item.box.computed_values().margin().right.resolved(item.box, width_of_containing_block_as_length).resolved_or_zero(item.box).to_px(item.box); - item.margins.cross_before = item.box.computed_values().margin().top.resolved(item.box, width_of_containing_block_as_length).resolved_or_zero(item.box).to_px(item.box); - item.margins.cross_after = item.box.computed_values().margin().bottom.resolved(item.box, width_of_containing_block_as_length).resolved_or_zero(item.box).to_px(item.box); + item.margins.main_before = item.box.computed_values().margin().left.resolved(item.box, width_of_containing_block_as_length).resolved(item.box).to_px(item.box); + item.margins.main_after = item.box.computed_values().margin().right.resolved(item.box, width_of_containing_block_as_length).resolved(item.box).to_px(item.box); + item.margins.cross_before = item.box.computed_values().margin().top.resolved(item.box, width_of_containing_block_as_length).resolved(item.box).to_px(item.box); + item.margins.cross_after = item.box.computed_values().margin().bottom.resolved(item.box, width_of_containing_block_as_length).resolved(item.box).to_px(item.box); } else { - item.margins.main_before = item.box.computed_values().margin().top.resolved(item.box, width_of_containing_block_as_length).resolved_or_zero(item.box).to_px(item.box); - item.margins.main_after = item.box.computed_values().margin().bottom.resolved(item.box, width_of_containing_block_as_length).resolved_or_zero(item.box).to_px(item.box); - item.margins.cross_before = item.box.computed_values().margin().left.resolved(item.box, width_of_containing_block_as_length).resolved_or_zero(item.box).to_px(item.box); - item.margins.cross_after = item.box.computed_values().margin().right.resolved(item.box, width_of_containing_block_as_length).resolved_or_zero(item.box).to_px(item.box); + item.margins.main_before = item.box.computed_values().margin().top.resolved(item.box, width_of_containing_block_as_length).resolved(item.box).to_px(item.box); + item.margins.main_after = item.box.computed_values().margin().bottom.resolved(item.box, width_of_containing_block_as_length).resolved(item.box).to_px(item.box); + item.margins.cross_before = item.box.computed_values().margin().left.resolved(item.box, width_of_containing_block_as_length).resolved(item.box).to_px(item.box); + item.margins.cross_after = item.box.computed_values().margin().right.resolved(item.box, width_of_containing_block_as_length).resolved(item.box).to_px(item.box); } }; @@ -148,7 +148,7 @@ void FlexFormattingContext::generate_anonymous_flex_items() auto& maybe_width = flex_container().computed_values().width(); if (maybe_width.has_value()) { - auto width = maybe_width->resolved(flex_container(), CSS::Length::make_px(container_width)).resolved_or_zero(flex_container()).to_px(flex_container()); + auto width = maybe_width->resolved(flex_container(), CSS::Length::make_px(container_width)).resolved(flex_container()).to_px(flex_container()); flex_container().set_content_width(width); } else { flex_container().set_content_width(0); @@ -161,7 +161,7 @@ void FlexFormattingContext::generate_anonymous_flex_items() auto container_height = flex_container().containing_block()->content_height(); auto& maybe_height = flex_container().computed_values().height(); if (maybe_height.has_value()) { - auto height = maybe_height->resolved(flex_container(), CSS::Length::make_px(container_height)).resolved_or_zero(flex_container()).to_px(flex_container()); + auto height = maybe_height->resolved(flex_container(), CSS::Length::make_px(container_height)).resolved(flex_container()).to_px(flex_container()); flex_container().set_content_height(height); } else { flex_container().set_content_height(0); @@ -256,7 +256,7 @@ float FlexFormattingContext::specified_main_size_of_child_box(Box const& child_b 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)).resolved_or_zero(child_box).to_px(child_box); + return value->resolved(child_box, CSS::Length::make_px(main_size_of_parent)).resolved(child_box).to_px(child_box); } float FlexFormattingContext::specified_main_min_size(Box const& box) const diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index d3fd918a16..878712e265 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -157,10 +157,10 @@ static Gfx::FloatSize solve_replaced_size_constraint(float w, float h, const Rep auto width_of_containing_block = CSS::Length::make_px(containing_block.content_width()); auto height_of_containing_block = CSS::Length::make_px(containing_block.content_height()); - auto specified_min_width = box.computed_values().min_width().has_value() ? box.computed_values().min_width()->resolved(box, width_of_containing_block).resolved_or_zero(box).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).resolved(CSS::Length::make_px(w), box).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).resolved_or_auto(box).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).resolved(CSS::Length::make_px(h), box).to_px(box) : h; + auto specified_min_width = box.computed_values().min_width().has_value() ? box.computed_values().min_width()->resolved(box, width_of_containing_block).resolved(box).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).resolved(box).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).resolved(box).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).resolved(box).to_px(box) : h; auto min_width = min(specified_min_width, specified_max_width); auto max_width = max(specified_min_width, specified_max_width); @@ -252,7 +252,7 @@ float FormattingContext::tentative_width_for_replaced_element(ReplacedBox const& { auto& containing_block = *box.containing_block(); auto height_of_containing_block = CSS::Length::make_px(containing_block.content_height()); - auto computed_height = box.computed_values().height().has_value() ? box.computed_values().height()->resolved(box, height_of_containing_block).resolved_or_auto(box) : CSS::Length::make_auto(); + 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(); float used_width = computed_width.to_px(box); @@ -314,8 +314,8 @@ float FormattingContext::compute_width_for_replaced_element(const ReplacedBox& b auto& containing_block = *box.containing_block(); auto width_of_containing_block = CSS::Length::make_px(containing_block.content_width()); - auto margin_left = box.computed_values().margin().left.resolved(box, width_of_containing_block).resolved_or_zero(box); - auto margin_right = box.computed_values().margin().right.resolved(box, width_of_containing_block).resolved_or_zero(box); + auto margin_left = box.computed_values().margin().left.resolved(box, width_of_containing_block).resolved(box); + auto margin_right = box.computed_values().margin().right.resolved(box, width_of_containing_block).resolved(box); // A computed value of 'auto' for 'margin-left' or 'margin-right' becomes a used value of '0'. if (margin_left.is_auto()) @@ -323,14 +323,14 @@ float FormattingContext::compute_width_for_replaced_element(const ReplacedBox& b 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_or_auto(box) : CSS::Length::make_auto(); + 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(); // 1. The tentative used width is calculated (without 'min-width' and 'max-width') auto used_width = tentative_width_for_replaced_element(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_or_auto(box) : CSS::Length::make_auto(); + 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(); if (!specified_max_width.is_auto()) { if (used_width > specified_max_width.to_px(box)) { used_width = tentative_width_for_replaced_element(box, specified_max_width); @@ -339,7 +339,7 @@ float FormattingContext::compute_width_for_replaced_element(const ReplacedBox& b // 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_or_auto(box) : CSS::Length::make_auto(); + 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(); if (!specified_min_width.is_auto()) { if (used_width < specified_min_width.to_px(box)) { used_width = tentative_width_for_replaced_element(box, specified_min_width); @@ -355,7 +355,7 @@ float FormattingContext::tentative_height_for_replaced_element(ReplacedBox const { auto& containing_block = *box.containing_block(); auto width_of_containing_block = CSS::Length::make_px(containing_block.content_width()); - auto computed_width = box.computed_values().width().has_value() ? box.computed_values().width()->resolved(box, width_of_containing_block).resolved_or_auto(box) : CSS::Length::make_auto(); + 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(); // 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'. @@ -389,8 +389,8 @@ float FormattingContext::compute_height_for_replaced_element(const ReplacedBox& auto& containing_block = *box.containing_block(); auto width_of_containing_block = CSS::Length::make_px(containing_block.content_width()); auto height_of_containing_block = CSS::Length::make_px(containing_block.content_height()); - auto specified_width = box.computed_values().width().has_value() ? box.computed_values().width()->resolved(box, width_of_containing_block).resolved_or_auto(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_or_auto(box) : CSS::Length::make_auto(); + 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(); float used_height = tentative_height_for_replaced_element(box, specified_height); @@ -414,15 +414,15 @@ void FormattingContext::compute_width_for_absolutely_positioned_non_replaced_ele auto margin_right = CSS::Length::make_auto(); const auto border_left = computed_values.border_left().width; const auto border_right = computed_values.border_right().width; - const auto padding_left = computed_values.padding().left.resolved(box, width_of_containing_block).resolved_or_zero(box); - const auto padding_right = computed_values.padding().right.resolved(box, width_of_containing_block).resolved_or_zero(box); + const auto padding_left = computed_values.padding().left.resolved(box, width_of_containing_block).resolved(box); + const auto padding_right = computed_values.padding().right.resolved(box, width_of_containing_block).resolved(box); auto try_compute_width = [&](const auto& a_width) { - margin_left = computed_values.margin().left.resolved(box, width_of_containing_block).resolved_or_zero(box); - margin_right = computed_values.margin().right.resolved(box, width_of_containing_block).resolved_or_zero(box); + margin_left = computed_values.margin().left.resolved(box, width_of_containing_block).resolved(box); + margin_right = computed_values.margin().right.resolved(box, width_of_containing_block).resolved(box); - auto left = computed_values.offset().left.resolved(box, width_of_containing_block).resolved_or_auto(box); - auto right = computed_values.offset().right.resolved(box, width_of_containing_block).resolved_or_auto(box); + auto left = computed_values.offset().left.resolved(box, width_of_containing_block).resolved(box); + auto right = computed_values.offset().right.resolved(box, width_of_containing_block).resolved(box); auto width = a_width; auto solve_for_left = [&] { @@ -511,14 +511,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_or_auto(box) : CSS::Length::make_auto(); + auto specified_width = computed_values.width().has_value() ? computed_values.width()->resolved(box, width_of_containing_block).resolved(box) : CSS::Length::make_auto(); // 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_or_auto(box) : CSS::Length::make_auto(); + 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(); 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); @@ -527,7 +527,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_or_auto(box) : CSS::Length::make_auto(); + 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(); 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); @@ -559,26 +559,26 @@ void FormattingContext::compute_height_for_absolutely_positioned_non_replaced_el auto width_of_containing_block = CSS::Length::make_px(containing_block.content_width()); auto height_of_containing_block = CSS::Length::make_px(containing_block.content_height()); - CSS::Length specified_top = computed_values.offset().top.resolved(box, height_of_containing_block).resolved_or_auto(box); - CSS::Length specified_bottom = computed_values.offset().bottom.resolved(box, height_of_containing_block).resolved_or_auto(box); + CSS::Length specified_top = computed_values.offset().top.resolved(box, height_of_containing_block).resolved(box); + CSS::Length specified_bottom = computed_values.offset().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())) { // specified_height is already auto } else { - specified_height = computed_values.height().has_value() ? computed_values.height()->resolved(box, height_of_containing_block).resolved_or_auto(box) : CSS::Length::make_auto(); + specified_height = computed_values.height().has_value() ? computed_values.height()->resolved(box, height_of_containing_block).resolved(box) : CSS::Length::make_auto(); } - auto specified_max_height = computed_values.max_height().has_value() ? computed_values.max_height()->resolved(box, height_of_containing_block).resolved_or_auto(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_or_auto(box) : CSS::Length::make_auto(); + 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(); - box.box_model().margin.top = computed_values.margin().top.resolved(box, width_of_containing_block).resolved_or_zero(box).to_px(box); - box.box_model().margin.bottom = computed_values.margin().bottom.resolved(box, width_of_containing_block).resolved_or_zero(box).to_px(box); + box.box_model().margin.top = computed_values.margin().top.resolved(box, width_of_containing_block).resolved(box).to_px(box); + box.box_model().margin.bottom = computed_values.margin().bottom.resolved(box, width_of_containing_block).resolved(box).to_px(box); box.box_model().border.top = computed_values.border_top().width; box.box_model().border.bottom = computed_values.border_bottom().width; - box.box_model().padding.top = computed_values.padding().top.resolved(box, width_of_containing_block).resolved_or_zero(box).to_px(box); - box.box_model().padding.bottom = computed_values.padding().bottom.resolved(box, width_of_containing_block).resolved_or_zero(box).to_px(box); + box.box_model().padding.top = computed_values.padding().top.resolved(box, width_of_containing_block).resolved(box).to_px(box); + box.box_model().padding.bottom = computed_values.padding().bottom.resolved(box, width_of_containing_block).resolved(box).to_px(box); if (specified_height.is_auto() && !specified_top.is_auto() && specified_bottom.is_auto()) { const auto& margin = box.box_model().margin; @@ -614,26 +614,26 @@ void FormattingContext::layout_absolutely_positioned_element(Box& box) auto height_of_containing_block = CSS::Length::make_px(containing_block.content_height()); auto& box_model = box.box_model(); - auto specified_width = box.computed_values().width().has_value() ? box.computed_values().width()->resolved(box, width_of_containing_block).resolved_or_auto(box) : CSS::Length::make_auto(); + 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(); compute_width_for_absolutely_positioned_element(box); auto independent_formatting_context = layout_inside(box, LayoutMode::Default); compute_height_for_absolutely_positioned_element(box); - box_model.margin.left = box.computed_values().margin().left.resolved(box, width_of_containing_block).resolved_or_auto(box).to_px(box); - box_model.margin.top = box.computed_values().margin().top.resolved(box, height_of_containing_block).resolved_or_auto(box).to_px(box); - box_model.margin.right = box.computed_values().margin().right.resolved(box, width_of_containing_block).resolved_or_auto(box).to_px(box); - box_model.margin.bottom = box.computed_values().margin().bottom.resolved(box, height_of_containing_block).resolved_or_auto(box).to_px(box); + box_model.margin.left = box.computed_values().margin().left.resolved(box, width_of_containing_block).resolved(box).to_px(box); + box_model.margin.top = box.computed_values().margin().top.resolved(box, height_of_containing_block).resolved(box).to_px(box); + box_model.margin.right = box.computed_values().margin().right.resolved(box, width_of_containing_block).resolved(box).to_px(box); + box_model.margin.bottom = box.computed_values().margin().bottom.resolved(box, height_of_containing_block).resolved(box).to_px(box); box_model.border.left = box.computed_values().border_left().width; box_model.border.right = box.computed_values().border_right().width; box_model.border.top = box.computed_values().border_top().width; box_model.border.bottom = box.computed_values().border_bottom().width; - box_model.offset.left = box.computed_values().offset().left.resolved(box, width_of_containing_block).resolved_or_auto(box).to_px(box); - box_model.offset.top = box.computed_values().offset().top.resolved(box, height_of_containing_block).resolved_or_auto(box).to_px(box); - box_model.offset.right = box.computed_values().offset().right.resolved(box, width_of_containing_block).resolved_or_auto(box).to_px(box); - box_model.offset.bottom = box.computed_values().offset().bottom.resolved(box, height_of_containing_block).resolved_or_auto(box).to_px(box); + box_model.offset.left = box.computed_values().offset().left.resolved(box, width_of_containing_block).resolved(box).to_px(box); + box_model.offset.top = box.computed_values().offset().top.resolved(box, height_of_containing_block).resolved(box).to_px(box); + box_model.offset.right = box.computed_values().offset().right.resolved(box, width_of_containing_block).resolved(box).to_px(box); + box_model.offset.bottom = box.computed_values().offset().bottom.resolved(box, height_of_containing_block).resolved(box).to_px(box); auto is_auto = [](auto const& length_percentage) { return length_percentage.is_length() && length_percentage.length().is_auto(); diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index fe6f778a07..f838ff039e 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -108,12 +108,12 @@ void InlineFormattingContext::dimension_box_on_line(Box& box, LayoutMode layout_ auto width_of_containing_block = CSS::Length::make_px(containing_block().content_width()); auto& box_model = box.box_model(); - box_model.margin.left = box.computed_values().margin().left.resolved(box, width_of_containing_block).resolved_or_zero(box).to_px(box); + box_model.margin.left = box.computed_values().margin().left.resolved(box, width_of_containing_block).resolved(box).to_px(box); box_model.border.left = box.computed_values().border_left().width; - box_model.padding.left = box.computed_values().padding().left.resolved(box, width_of_containing_block).resolved_or_zero(box).to_px(box); - box_model.margin.right = box.computed_values().margin().right.resolved(box, width_of_containing_block).resolved_or_zero(box).to_px(box); + box_model.padding.left = box.computed_values().padding().left.resolved(box, width_of_containing_block).resolved(box).to_px(box); + box_model.margin.right = box.computed_values().margin().right.resolved(box, width_of_containing_block).resolved(box).to_px(box); box_model.border.right = box.computed_values().border_right().width; - box_model.padding.right = box.computed_values().padding().right.resolved(box, width_of_containing_block).resolved_or_zero(box).to_px(box); + box_model.padding.right = box.computed_values().padding().right.resolved(box, width_of_containing_block).resolved(box).to_px(box); if (is(box)) { auto& replaced = verify_cast(box); @@ -141,7 +141,7 @@ void InlineFormattingContext::dimension_box_on_line(Box& box, LayoutMode layout_ inline_block.set_content_width(width); } else { auto container_width = CSS::Length::make_px(containing_block().content_width()); - inline_block.set_content_width(width_value->resolved(box, container_width).resolved_or_zero(inline_block).to_px(inline_block)); + inline_block.set_content_width(width_value->resolved(box, container_width).resolved(inline_block).to_px(inline_block)); } auto independent_formatting_context = layout_inside(inline_block, layout_mode); @@ -151,7 +151,7 @@ void InlineFormattingContext::dimension_box_on_line(Box& box, LayoutMode layout_ BlockFormattingContext::compute_height(inline_block); } else { auto container_height = CSS::Length::make_px(containing_block().content_height()); - inline_block.set_content_height(height_value->resolved(box, container_height).resolved_or_zero(inline_block).to_px(inline_block)); + inline_block.set_content_height(height_value->resolved(box, container_height).resolved(inline_block).to_px(inline_block)); } independent_formatting_context->parent_context_did_dimension_child_root_box(); diff --git a/Userland/Libraries/LibWeb/Layout/InlineNode.cpp b/Userland/Libraries/LibWeb/Layout/InlineNode.cpp index 3f4300f830..5996cc2556 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineNode.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineNode.cpp @@ -61,10 +61,10 @@ void InlineNode::paint(PaintContext& context, PaintPhase phase) for (auto const& layer : computed_box_shadow) { resolved_box_shadow_data.empend( layer.color, - static_cast(layer.offset_x.resolved_or_zero(*this).to_px(*this)), - static_cast(layer.offset_y.resolved_or_zero(*this).to_px(*this)), - static_cast(layer.blur_radius.resolved_or_zero(*this).to_px(*this)), - static_cast(layer.spread_distance.resolved_or_zero(*this).to_px(*this)), + static_cast(layer.offset_x.resolved(*this).to_px(*this)), + static_cast(layer.offset_y.resolved(*this).to_px(*this)), + static_cast(layer.blur_radius.resolved(*this).to_px(*this)), + static_cast(layer.spread_distance.resolved(*this).to_px(*this)), layer.placement == CSS::BoxShadowPlacement::Outer ? Painting::BoxShadowPlacement::Outer : Painting::BoxShadowPlacement::Inner); } Painting::paint_box_shadow(context, enclosing_int_rect(absolute_fragment_rect), resolved_box_shadow_data); diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 7562f87e36..75c8584478 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -463,7 +463,7 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style) if (border.line_style == CSS::LineStyle::None) border.width = 0; else - border.width = specified_style.length_or_fallback(width_property, CSS::Length::make_px(0)).resolved_or_zero(*this).to_px(*this); + border.width = specified_style.length_or_fallback(width_property, CSS::Length::make_px(0)).resolved(*this).to_px(*this); }; do_border_style(computed_values.border_left(), CSS::PropertyID::BorderLeftWidth, CSS::PropertyID::BorderLeftColor, CSS::PropertyID::BorderLeftStyle); diff --git a/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp b/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp index 1e6c01291a..35dc6a0f81 100644 --- a/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp +++ b/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp @@ -89,20 +89,20 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet height = image.height(); } else if (x_is_auto) { height = layer.size_y.resolved(layout_node, CSS::Length::make_px(background_positioning_area.height())) - .resolved_or_zero(layout_node) + .resolved(layout_node) .to_px(layout_node); width = roundf(image.width() * ((float)height / (float)image.height())); } else if (y_is_auto) { width = layer.size_x.resolved(layout_node, CSS::Length::make_px(background_positioning_area.width())) - .resolved_or_zero(layout_node) + .resolved(layout_node) .to_px(layout_node); height = roundf(image.height() * ((float)width / (float)image.width())); } else { width = layer.size_x.resolved(layout_node, CSS::Length::make_px(background_positioning_area.width())) - .resolved_or_zero(layout_node) + .resolved(layout_node) .to_px(layout_node); height = layer.size_y.resolved(layout_node, CSS::Length::make_px(background_positioning_area.height())) - .resolved_or_zero(layout_node) + .resolved(layout_node) .to_px(layout_node); } @@ -144,7 +144,7 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet // Position int offset_x = layer.position_offset_x.resolved(layout_node, CSS::Length::make_px(space_x)) - .resolved_or_zero(layout_node) + .resolved(layout_node) .to_px(layout_node); if (layer.position_edge_x == CSS::PositionEdge::Right) { image_rect.set_right_without_resize(background_positioning_area.right() - offset_x); @@ -153,7 +153,7 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet } int offset_y = layer.position_offset_y.resolved(layout_node, CSS::Length::make_px(space_y)) - .resolved_or_zero(layout_node) + .resolved(layout_node) .to_px(layout_node); if (layer.position_edge_y == CSS::PositionEdge::Bottom) { image_rect.set_bottom_without_resize(background_positioning_area.bottom() - offset_y); diff --git a/Userland/Libraries/LibWeb/Painting/BorderPainting.cpp b/Userland/Libraries/LibWeb/Painting/BorderPainting.cpp index deafecc964..116ddcdfcc 100644 --- a/Userland/Libraries/LibWeb/Painting/BorderPainting.cpp +++ b/Userland/Libraries/LibWeb/Painting/BorderPainting.cpp @@ -17,10 +17,10 @@ BorderRadiusData normalized_border_radius_data(Layout::Node const& node, Gfx::Fl // Spec just says "Refer to corresponding dimension of the border box." // For now, all relative values are relative to the width. auto width_length = CSS::Length::make_px(rect.width()); - auto bottom_left_radius_px = bottom_left_radius.resolved(node, width_length).resolved_or_zero(node).to_px(node); - auto bottom_right_radius_px = bottom_right_radius.resolved(node, width_length).resolved_or_zero(node).to_px(node); - auto top_left_radius_px = top_left_radius.resolved(node, width_length).resolved_or_zero(node).to_px(node); - auto top_right_radius_px = top_right_radius.resolved(node, width_length).resolved_or_zero(node).to_px(node); + auto bottom_left_radius_px = bottom_left_radius.resolved(node, width_length).resolved(node).to_px(node); + auto bottom_right_radius_px = bottom_right_radius.resolved(node, width_length).resolved(node).to_px(node); + auto top_left_radius_px = top_left_radius.resolved(node, width_length).resolved(node).to_px(node); + auto top_right_radius_px = top_right_radius.resolved(node, width_length).resolved(node).to_px(node); // Scale overlapping curves according to https://www.w3.org/TR/css-backgrounds-3/#corner-overlap auto f = 1.0f;