summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-09-26 15:41:22 +0200
committerAndreas Kling <kling@serenityos.org>2022-09-29 18:33:41 +0200
commit385657a4bf5746aa7e5c8ba72edd35e6507e6d42 (patch)
tree4e1f01d0156b90edab7f86dc227346bb3134be59 /Userland/Libraries/LibWeb
parentfce1c673c74ccac4dd8a78c31be919987832da72 (diff)
downloadserenity-385657a4bf5746aa7e5c8ba72edd35e6507e6d42.zip
LibWeb: Add a helper for calculating the stretch-fit width of a box
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/Layout/FormattingContext.cpp16
-rw-r--r--Userland/Libraries/LibWeb/Layout/FormattingContext.h2
2 files changed, 18 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp
index 1fe9effafb..51e9ca1e89 100644
--- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp
@@ -1178,4 +1178,20 @@ float FormattingContext::compute_box_y_position_with_respect_to_siblings(Box con
}
}
+// https://drafts.csswg.org/css-sizing-3/#stretch-fit-size
+float FormattingContext::calculate_stretch_fit_width(Box const& box, AvailableSpace const& available_width) const
+{
+ // The size a box would take if its outer size filled the available space in the given axis;
+ // in other words, the stretch fit into the available space, if that is definite.
+ // Undefined if the available space is indefinite.
+ auto const& box_state = m_state.get(box);
+ return available_width.to_px()
+ - box_state.margin_left
+ - box_state.margin_right
+ - box_state.padding_left
+ - box_state.padding_right
+ - box_state.border_left
+ - box_state.border_right;
+}
+
}
diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.h b/Userland/Libraries/LibWeb/Layout/FormattingContext.h
index 76b7556a30..1800163763 100644
--- a/Userland/Libraries/LibWeb/Layout/FormattingContext.h
+++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.h
@@ -69,6 +69,8 @@ public:
float compute_box_y_position_with_respect_to_siblings(Box const&, LayoutState::UsedValues const&);
+ float calculate_stretch_fit_width(Box const&, AvailableSpace const& available_width) const;
+
protected:
FormattingContext(Type, LayoutState&, Box const&, FormattingContext* parent = nullptr);