summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Layout
diff options
context:
space:
mode:
authormartinfalisse <martinmotteditfalisse@gmail.com>2022-09-17 18:14:11 +0200
committerAndreas Kling <kling@serenityos.org>2022-10-06 21:16:01 +0200
commit9fd07e9cb1af7dd0411a23cf85077d881ea12f47 (patch)
treeaacceebd1cf8d892d1334bccb153d4d7dbf10310 /Userland/Libraries/LibWeb/Layout
parent236795e931f31cbd49219bd0f2ce0ea1932a4468 (diff)
downloadserenity-9fd07e9cb1af7dd0411a23cf85077d881ea12f47.zip
LibWeb: Make it easier to check if grid track is auto positioned
Add some helper functions for checking if a grid-track is auto-positioned. I think this makes the code more legible.
Diffstat (limited to 'Userland/Libraries/LibWeb/Layout')
-rw-r--r--Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp23
-rw-r--r--Userland/Libraries/LibWeb/Layout/GridFormattingContext.h3
2 files changed, 22 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
index dbe4f490af..61375e2bdb 100644
--- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
@@ -107,8 +107,8 @@ void GridFormattingContext::run(Box const& box, LayoutMode, AvailableSpace const
// 1. Position anything that's not auto-positioned.
for (size_t i = 0; i < boxes_to_place.size(); i++) {
auto const& child_box = boxes_to_place[i];
- if ((child_box.computed_values().grid_row_start().is_auto_positioned() && child_box.computed_values().grid_row_end().is_auto_positioned())
- || (child_box.computed_values().grid_column_start().is_auto_positioned() && child_box.computed_values().grid_column_end().is_auto_positioned()))
+ if (is_auto_positioned_row(child_box.computed_values().grid_row_start(), child_box.computed_values().grid_row_end())
+ || is_auto_positioned_column(child_box.computed_values().grid_column_start(), child_box.computed_values().grid_column_end()))
continue;
int row_start = child_box.computed_values().grid_row_start().raw_value();
@@ -219,7 +219,7 @@ void GridFormattingContext::run(Box const& box, LayoutMode, AvailableSpace const
// FIXME: Do "dense" packing
for (size_t i = 0; i < boxes_to_place.size(); i++) {
auto const& child_box = boxes_to_place[i];
- if (child_box.computed_values().grid_row_start().is_auto_positioned() && child_box.computed_values().grid_row_end().is_auto_positioned())
+ if (is_auto_positioned_row(child_box.computed_values().grid_row_start(), child_box.computed_values().grid_row_end()))
continue;
int row_start = child_box.computed_values().grid_row_start().raw_value();
@@ -349,7 +349,7 @@ void GridFormattingContext::run(Box const& box, LayoutMode, AvailableSpace const
// FIXME: no distinction made. See #4.2
// 4.1.1. If the item has a definite column position:
- if (!(child_box.computed_values().grid_column_start().is_auto_positioned() && child_box.computed_values().grid_column_end().is_auto_positioned())) {
+ if (!is_auto_positioned_column(child_box.computed_values().grid_column_start(), child_box.computed_values().grid_column_end())) {
int column_start = child_box.computed_values().grid_column_start().raw_value();
int column_end = child_box.computed_values().grid_column_end().raw_value();
@@ -1136,4 +1136,19 @@ float GridFormattingContext::automatic_content_height() const
return m_automatic_content_height;
}
+bool GridFormattingContext::is_auto_positioned_row(CSS::GridTrackPlacement const& grid_row_start, CSS::GridTrackPlacement const& grid_row_end) const
+{
+ return is_auto_positioned_track(grid_row_start, grid_row_end);
+}
+
+bool GridFormattingContext::is_auto_positioned_column(CSS::GridTrackPlacement const& grid_column_start, CSS::GridTrackPlacement const& grid_column_end) const
+{
+ return is_auto_positioned_track(grid_column_start, grid_column_end);
+}
+
+bool GridFormattingContext::is_auto_positioned_track(CSS::GridTrackPlacement const& grid_track_start, CSS::GridTrackPlacement const& grid_track_end) const
+{
+ return grid_track_start.is_auto_positioned() && grid_track_end.is_auto_positioned();
+}
+
}
diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h
index 0e9f48cc14..e934a690d5 100644
--- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h
+++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h
@@ -22,6 +22,9 @@ public:
private:
float m_automatic_content_height { 0 };
+ bool is_auto_positioned_row(CSS::GridTrackPlacement const&, CSS::GridTrackPlacement const&) const;
+ bool is_auto_positioned_column(CSS::GridTrackPlacement const&, CSS::GridTrackPlacement const&) const;
+ bool is_auto_positioned_track(CSS::GridTrackPlacement const&, CSS::GridTrackPlacement const&) const;
};
}