From 07f6ee9e73d03549c7ac0e61754f6667a230c259 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 10 Mar 2023 10:12:02 +0100 Subject: [PATCH] LibWeb: Simplify FFC get_pixel_{width,height} internal helper API These took an Optional for some reason, but that was not necessary. Just take a CSS::Size. --- .../LibWeb/Layout/FlexFormattingContext.cpp | 16 ++++++---------- .../LibWeb/Layout/FlexFormattingContext.h | 4 ++-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp index d145bc16e2..6d946e2065 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp @@ -37,36 +37,32 @@ static CSS::Size to_css_size(CSS::LengthPercentage const& length_percentage) return CSS::Size::make_percentage(length_percentage.percentage()); } -CSSPixels FlexFormattingContext::get_pixel_width(Box const& box, Optional const& size) const +CSSPixels FlexFormattingContext::get_pixel_width(Box const& box, CSS::Size const& size) const { - if (!size.has_value()) - return 0; auto containing_block_width = CSS::Length::make_px(containing_block_width_for(box)); if (box.computed_values().box_sizing() == CSS::BoxSizing::BorderBox) { 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, containing_block_width).to_px(box) - border_left - border_right - padding_left - padding_right; } - return size->resolved(box, containing_block_width).to_px(box); + return size.resolved(box, containing_block_width).to_px(box); } -CSSPixels FlexFormattingContext::get_pixel_height(Box const& box, Optional const& size) const +CSSPixels FlexFormattingContext::get_pixel_height(Box const& box, CSS::Size const& size) const { - if (!size.has_value()) - return 0; auto containing_block_height = CSS::Length::make_px(containing_block_height_for(box)); if (box.computed_values().box_sizing() == CSS::BoxSizing::BorderBox) { 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 size.resolved(box, containing_block_height).to_px(box) - border_top - border_bottom - padding_top - padding_bottom; } - return size->resolved(box, containing_block_height).to_px(box); + return size.resolved(box, containing_block_height).to_px(box); } FlexFormattingContext::FlexFormattingContext(LayoutState& state, Box const& flex_container, FormattingContext* parent) diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h index 8cc3abfa67..020d8f9253 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h @@ -120,8 +120,8 @@ private: CSS::Size const& computed_cross_min_size(Box const&) const; CSS::Size const& computed_cross_max_size(Box const&) const; - CSSPixels get_pixel_width(Box const& box, Optional const& length_percentage) const; - CSSPixels get_pixel_height(Box const& box, Optional const& length_percentage) const; + CSSPixels get_pixel_width(Box const&, CSS::Size const&) const; + CSSPixels get_pixel_height(Box const&, CSS::Size const&) const; bool flex_item_is_stretched(FlexItem const&) const;