diff options
author | Andreas Kling <kling@serenityos.org> | 2023-03-10 10:04:01 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-03-10 13:15:45 +0100 |
commit | 6b193974527a8370249764a9189b8c6e745c7d1c (patch) | |
tree | af96eee9f98961b67deb1ceff61318bdcf747a28 /Userland/Libraries | |
parent | 64bda6de2a7c3f47aa1a5fd7a0c3f4489046b5d2 (diff) | |
download | serenity-6b193974527a8370249764a9189b8c6e745c7d1c.zip |
LibWeb: Avoid unnecessary work for `box-sizing: content-box` flex items
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp index 892a928aca..d145bc16e2 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp @@ -41,32 +41,32 @@ CSSPixels FlexFormattingContext::get_pixel_width(Box const& box, Optional<CSS::S { if (!size.has_value()) return 0; - auto inner_width = CSS::Length::make_px(containing_block_width_for(box)); - auto border_left = box.computed_values().border_left().width; - auto border_right = box.computed_values().border_right().width; - auto padding_left = box.computed_values().padding().left().resolved(box, inner_width).to_px(box); - auto padding_right = box.computed_values().padding().right().resolved(box, inner_width).to_px(box); + auto containing_block_width = CSS::Length::make_px(containing_block_width_for(box)); if (box.computed_values().box_sizing() == CSS::BoxSizing::BorderBox) { - return size->resolved(box, inner_width).to_px(box) - border_left - border_right - padding_left - padding_right; + auto border_left = box.computed_values().border_left().width; + auto border_right = box.computed_values().border_right().width; + auto padding_left = box.computed_values().padding().left().resolved(box, containing_block_width).to_px(box); + auto padding_right = box.computed_values().padding().right().resolved(box, containing_block_width).to_px(box); + return size->resolved(box, containing_block_width).to_px(box) - border_left - border_right - padding_left - padding_right; } - return size->resolved(box, inner_width).to_px(box); + return size->resolved(box, containing_block_width).to_px(box); } -CSSPixels FlexFormattingContext::get_pixel_height(Box const& box, Optional<CSS::Size> const& length_percentage) const +CSSPixels FlexFormattingContext::get_pixel_height(Box const& box, Optional<CSS::Size> const& size) const { - if (!length_percentage.has_value()) + if (!size.has_value()) return 0; - auto inner_height = CSS::Length::make_px(containing_block_height_for(box)); - auto border_top = box.computed_values().border_top().width; - auto border_bottom = box.computed_values().border_bottom().width; - auto padding_top = box.computed_values().padding().top().resolved(box, inner_height).to_px(box); - auto padding_bottom = box.computed_values().padding().bottom().resolved(box, inner_height).to_px(box); + auto containing_block_height = CSS::Length::make_px(containing_block_height_for(box)); if (box.computed_values().box_sizing() == CSS::BoxSizing::BorderBox) { - return length_percentage->resolved(box, inner_height).to_px(box) - border_top - border_bottom - padding_top - padding_bottom; + auto border_top = box.computed_values().border_top().width; + auto border_bottom = box.computed_values().border_bottom().width; + auto padding_top = box.computed_values().padding().top().resolved(box, containing_block_height).to_px(box); + auto padding_bottom = box.computed_values().padding().bottom().resolved(box, containing_block_height).to_px(box); + return size->resolved(box, containing_block_height).to_px(box) - border_top - border_bottom - padding_top - padding_bottom; } - return length_percentage->resolved(box, inner_height).to_px(box); + return size->resolved(box, containing_block_height).to_px(box); } FlexFormattingContext::FlexFormattingContext(LayoutState& state, Box const& flex_container, FormattingContext* parent) |