From bd48d9521a4c60ffa1a6e7b0a8bc6b14e1b063ec Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 25 Jul 2022 23:55:20 +0200 Subject: [PATCH] LibWeb: Simplify more code with CSS::LengthPercentage::is_auto() --- .../LibWeb/Layout/FlexFormattingContext.cpp | 8 ++++---- .../LibWeb/Layout/FormattingContext.cpp | 18 +++++++----------- .../LibWeb/Painting/BackgroundPainting.cpp | 8 ++++---- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp index 71a526cbe0..6a7b1fba78 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp @@ -393,15 +393,15 @@ bool FlexFormattingContext::is_cross_auto(Box const& box) const bool FlexFormattingContext::is_main_axis_margin_first_auto(Box const& box) const { if (is_row_layout()) - return box.computed_values().margin().left.length().is_auto(); - return box.computed_values().margin().top.length().is_auto(); + return box.computed_values().margin().left.is_auto(); + return box.computed_values().margin().top.is_auto(); } bool FlexFormattingContext::is_main_axis_margin_second_auto(Box const& box) const { if (is_row_layout()) - return box.computed_values().margin().right.length().is_auto(); - return box.computed_values().margin().bottom.length().is_auto(); + return box.computed_values().margin().right.is_auto(); + return box.computed_values().margin().bottom.is_auto(); } void FlexFormattingContext::set_main_size(Box const& box, float size) diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index 82756ea68a..cfdc57ed22 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -724,24 +724,20 @@ void FormattingContext::layout_absolutely_positioned_element(Box const& box) box_state.inset_right = box.computed_values().inset().right.resolved(box, width_of_containing_block_as_length).to_px(box); box_state.inset_bottom = box.computed_values().inset().bottom.resolved(box, height_of_containing_block_as_length).to_px(box); - auto is_auto = [](auto const& length_percentage) { - return length_percentage.is_length() && length_percentage.length().is_auto(); - }; - - if (is_auto(box.computed_values().inset().left) && specified_width.is_auto() && is_auto(box.computed_values().inset().right)) { - if (is_auto(box.computed_values().margin().left)) + if (box.computed_values().inset().left.is_auto() && specified_width.is_auto() && box.computed_values().inset().right.is_auto()) { + if (box.computed_values().margin().left.is_auto()) box_state.margin_left = 0; - if (is_auto(box.computed_values().margin().right)) + if (box.computed_values().margin().right.is_auto()) box_state.margin_right = 0; } Gfx::FloatPoint used_offset; - if (!is_auto(box.computed_values().inset().left)) { + if (!box.computed_values().inset().left.is_auto()) { float x_offset = box_state.inset_left + box_state.border_box_left(); used_offset.set_x(x_offset + box_state.margin_left); - } else if (!is_auto(box.computed_values().inset().right)) { + } else if (!box.computed_values().inset().right.is_auto()) { float x_offset = 0 - box_state.inset_right - box_state.border_box_right(); @@ -751,11 +747,11 @@ void FormattingContext::layout_absolutely_positioned_element(Box const& box) used_offset.set_x(x_offset); } - if (!is_auto(box.computed_values().inset().top)) { + if (!box.computed_values().inset().top.is_auto()) { float y_offset = box_state.inset_top + box_state.border_box_top(); used_offset.set_y(y_offset + box_state.margin_top); - } else if (!is_auto(box.computed_values().inset().bottom)) { + } else if (!box.computed_values().inset().bottom.is_auto()) { float y_offset = 0 - box_state.inset_bottom - box_state.border_box_bottom(); diff --git a/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp b/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp index 1d664748f4..7ba38a373e 100644 --- a/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp +++ b/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp @@ -139,8 +139,8 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet case CSS::BackgroundSize::LengthPercentage: { float width; float height; - bool x_is_auto = layer.size_x.is_length() && layer.size_x.length().is_auto(); - bool y_is_auto = layer.size_y.is_length() && layer.size_y.length().is_auto(); + bool x_is_auto = layer.size_x.is_auto(); + bool y_is_auto = layer.size_y.is_auto(); if (x_is_auto && y_is_auto) { width = image.width(); height = image.height(); @@ -179,10 +179,10 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet // for the other dimension, then there is a third step: that other dimension is scaled // so that the original aspect ratio is restored. if (layer.repeat_x != layer.repeat_y) { - if (layer.size_x.is_length() && layer.size_x.length().is_auto()) { + if (layer.size_x.is_auto()) { image_rect.set_width(image.width() * (image_rect.height() / image.height())); } - if (layer.size_y.is_length() && layer.size_y.length().is_auto()) { + if (layer.size_y.is_auto()) { image_rect.set_height(image.height() * (image_rect.width() / image.width())); } }