summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-01-22 15:19:18 +0100
committerAndreas Kling <kling@serenityos.org>2022-01-23 01:22:41 +0100
commit0ea438e45be830727004f6a88ebebaffc0855ccb (patch)
tree2bbd816012a34d3355ce7f91f68b342ee699a07d /Userland
parent70a56d21dcca95f86ea5c76a68e53f2a887a2365 (diff)
downloadserenity-0ea438e45be830727004f6a88ebebaffc0855ccb.zip
LibWeb: Put BFC floating object state into a struct
This patch adds a BFC::FloatSideData struct so we can contain left and right floating object layout state in a struct. This is preparation for adding more per-side state.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp30
-rw-r--r--Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h14
-rw-r--r--Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp8
3 files changed, 28 insertions, 24 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
index 901be0b723..0a3d3cef00 100644
--- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
@@ -515,22 +515,22 @@ void BlockFormattingContext::place_block_level_non_replaced_element_in_normal_fl
}
}
- auto clear_floating_boxes = [&](auto& floating_boxes) {
- if (!floating_boxes.is_empty()) {
+ auto clear_floating_boxes = [&](auto& float_side) {
+ if (!float_side.boxes.is_empty()) {
float clearance_y = 0;
- for (auto* floating_box : floating_boxes) {
- clearance_y = max(clearance_y, floating_box->effective_offset().y() + floating_box->border_box_height());
+ for (auto& floating_box : float_side.boxes) {
+ clearance_y = max(clearance_y, floating_box.effective_offset().y() + floating_box.border_box_height());
}
y = max(y, clearance_y);
- floating_boxes.clear();
+ float_side.boxes.clear();
}
};
// Flex-items don't float and also don't clear.
if ((computed_values.clear() == CSS::Clear::Left || computed_values.clear() == CSS::Clear::Both) && !child_box.is_flex_item())
- clear_floating_boxes(m_left_floating_boxes);
+ clear_floating_boxes(m_left_floats);
if ((computed_values.clear() == CSS::Clear::Right || computed_values.clear() == CSS::Clear::Both) && !child_box.is_flex_item())
- clear_floating_boxes(m_right_floating_boxes);
+ clear_floating_boxes(m_right_floats);
child_box.set_offset(x, y);
}
@@ -601,8 +601,8 @@ void BlockFormattingContext::layout_floating_child(Box& box, BlockContainer cons
// Next, float to the left and/or right
if (box.computed_values().float_() == CSS::Float::Left) {
- if (!m_left_floating_boxes.is_empty()) {
- auto& previous_floating_box = *m_left_floating_boxes.last();
+ if (!m_left_floats.boxes.is_empty()) {
+ auto& previous_floating_box = m_left_floats.boxes.last();
auto previous_rect = rect_in_coordinate_space(previous_floating_box, root());
if (previous_rect.contains_vertically(y_in_root)) {
// This box touches another already floating box. Stack to the right.
@@ -611,16 +611,16 @@ void BlockFormattingContext::layout_floating_child(Box& box, BlockContainer cons
// This box does not touch another floating box, go all the way to the left.
x = box.box_model().margin_box().left;
// Also, forget all previous left-floating boxes while we're here since they're no longer relevant.
- m_left_floating_boxes.clear();
+ m_left_floats.boxes.clear();
}
} else {
// This is the first left-floating box. Go all the way to the left.
x = box.box_model().margin_box().left;
}
- m_left_floating_boxes.append(&box);
+ m_left_floats.boxes.append(box);
} else if (box.computed_values().float_() == CSS::Float::Right) {
- if (!m_right_floating_boxes.is_empty()) {
- auto& previous_floating_box = *m_right_floating_boxes.last();
+ if (!m_right_floats.boxes.is_empty()) {
+ auto& previous_floating_box = m_right_floats.boxes.last();
auto previous_rect = rect_in_coordinate_space(previous_floating_box, root());
if (previous_rect.contains_vertically(y_in_root)) {
// This box touches another already floating box. Stack to the left.
@@ -629,13 +629,13 @@ void BlockFormattingContext::layout_floating_child(Box& box, BlockContainer cons
// This box does not touch another floating box, go all the way to the right.
x = containing_block.width() - box.box_model().margin_box().right - box.width();
// Also, forget all previous right-floating boxes while we're here since they're no longer relevant.
- m_right_floating_boxes.clear();
+ m_right_floats.boxes.clear();
}
} else {
// This is the first right-floating box. Go all the way to the right.
x = containing_block.width() - box.box_model().margin_box().right - box.width();
}
- m_right_floating_boxes.append(&box);
+ m_right_floats.boxes.append(box);
}
box.set_offset(x, box.effective_offset().y());
diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h
index 6a55d67be1..6223a90230 100644
--- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h
+++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h
@@ -23,8 +23,8 @@ public:
bool is_initial() const;
- const Vector<Box*>& left_floating_boxes() const { return m_left_floating_boxes; }
- const Vector<Box*>& right_floating_boxes() const { return m_right_floating_boxes; }
+ auto const& left_side_floats() const { return m_left_floats; }
+ auto const& right_side_floats() const { return m_right_floats; }
static float compute_theoretical_height(Box const&);
void compute_width(Box&);
@@ -50,14 +50,18 @@ private:
void layout_inline_children(BlockContainer&, LayoutMode);
void place_block_level_replaced_element_in_normal_flow(Box& child, BlockContainer const&);
- void place_block_level_non_replaced_element_in_normal_flow(Box& child, BlockContainer const&);
+ void place_block_level_non_replaced_element_in_normal_flow(Box& float_side, BlockContainer const&);
void layout_floating_child(Box& child, BlockContainer const& containing_block);
void apply_transformations_to_children(Box&);
- Vector<Box*> m_left_floating_boxes;
- Vector<Box*> m_right_floating_boxes;
+ struct FloatSideData {
+ Vector<Box&> boxes;
+ };
+
+ FloatSideData m_left_floats;
+ FloatSideData m_right_floats;
};
}
diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp
index 5339045fff..ec16eeaeba 100644
--- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp
@@ -35,8 +35,8 @@ InlineFormattingContext::AvailableSpaceForLineInfo InlineFormattingContext::avai
auto const& bfc = static_cast<BlockFormattingContext const&>(*parent());
- for (ssize_t i = bfc.left_floating_boxes().size() - 1; i >= 0; --i) {
- auto& floating_box = *bfc.left_floating_boxes().at(i);
+ for (ssize_t i = bfc.left_side_floats().boxes.size() - 1; i >= 0; --i) {
+ auto const& floating_box = bfc.left_side_floats().boxes.at(i);
auto rect = floating_box.margin_box_as_relative_rect();
if (rect.contains_vertically(y)) {
info.left = rect.right() + 1;
@@ -46,8 +46,8 @@ InlineFormattingContext::AvailableSpaceForLineInfo InlineFormattingContext::avai
info.right = containing_block().width();
- for (ssize_t i = bfc.right_floating_boxes().size() - 1; i >= 0; --i) {
- auto& floating_box = *bfc.right_floating_boxes().at(i);
+ for (ssize_t i = bfc.right_side_floats().boxes.size() - 1; i >= 0; --i) {
+ auto const& floating_box = bfc.right_side_floats().boxes.at(i);
auto rect = floating_box.margin_box_as_relative_rect();
if (rect.contains_vertically(y)) {
info.right = rect.left() - 1;