summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp25
-rw-r--r--Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h2
-rw-r--r--Userland/Libraries/LibWeb/Layout/FormattingContext.h5
-rw-r--r--Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp31
-rw-r--r--Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h5
5 files changed, 36 insertions, 32 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
index b0aa7d5a01..466d5b000d 100644
--- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
@@ -692,4 +692,29 @@ void BlockFormattingContext::layout_list_item_marker(ListItemBox const& list_ite
list_item_state.content_height = marker_state.content_height;
}
+BlockFormattingContext::AvailableSpaceForLineInfo BlockFormattingContext::available_space_for_line(float y) const
+{
+ AvailableSpaceForLineInfo info;
+
+ for (auto const& floating_box : m_left_floats.boxes.in_reverse()) {
+ auto rect = margin_box_rect_in_ancestor_coordinate_space(floating_box, root(), m_state);
+ if (rect.contains_vertically(y)) {
+ info.left = rect.right() + 1;
+ break;
+ }
+ }
+
+ info.right = m_state.get(root()).content_width;
+
+ for (auto const& floating_box : m_right_floats.boxes.in_reverse()) {
+ auto rect = margin_box_rect_in_ancestor_coordinate_space(floating_box, root(), m_state);
+ if (rect.contains_vertically(y)) {
+ info.right = rect.left();
+ break;
+ }
+ }
+
+ return info;
+}
+
}
diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h
index 1b8f38f8ba..933806c7c3 100644
--- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h
+++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h
@@ -38,6 +38,8 @@ public:
void add_absolutely_positioned_box(Box const& box) { m_absolutely_positioned_boxes.append(box); }
+ AvailableSpaceForLineInfo available_space_for_line(float y) const;
+
private:
virtual bool is_block_formatting_context() const final { return true; }
diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.h b/Userland/Libraries/LibWeb/Layout/FormattingContext.h
index f8f3d7bf58..75869089ec 100644
--- a/Userland/Libraries/LibWeb/Layout/FormattingContext.h
+++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.h
@@ -65,6 +65,11 @@ protected:
OwnPtr<FormattingContext> layout_inside(Box const&, LayoutMode);
void compute_position(Box const&);
+ struct AvailableSpaceForLineInfo {
+ float left { 0 };
+ float right { 0 };
+ };
+
struct ShrinkToFitResult {
float preferred_width { 0 };
float preferred_minimum_width { 0 };
diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp
index 643cb45a75..2fcb5dd5e8 100644
--- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp
@@ -36,37 +36,14 @@ BlockFormattingContext const& InlineFormattingContext::parent() const
return static_cast<BlockFormattingContext const&>(*FormattingContext::parent());
}
-InlineFormattingContext::AvailableSpaceForLineInfo InlineFormattingContext::available_space_for_line(float y) const
+FormattingContext::AvailableSpaceForLineInfo InlineFormattingContext::available_space_for_line(float y) const
{
// NOTE: Floats are relative to the BFC root box, not necessarily the containing block of this IFC.
auto box_in_root_rect = margin_box_rect_in_ancestor_coordinate_space(containing_block(), parent().root(), m_state);
float y_in_root = box_in_root_rect.y() + y;
-
- AvailableSpaceForLineInfo info;
-
- auto const& bfc = parent();
-
- 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 = margin_box_rect_in_ancestor_coordinate_space(floating_box, parent().root(), m_state);
- if (rect.contains_vertically(y_in_root)) {
- info.left = rect.right() + 1;
- break;
- }
- }
-
- info.right = m_state.get(containing_block()).content_width;
-
- 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 = margin_box_rect_in_ancestor_coordinate_space(floating_box, parent().root(), m_state);
- if (rect.contains_vertically(y_in_root)) {
- info.right = rect.left();
- break;
- }
- }
-
- return info;
+ auto space = parent().available_space_for_line(y_in_root);
+ space.right = min(space.right, m_state.get(containing_block()).content_width);
+ return space;
}
void InlineFormattingContext::run(Box const&, LayoutMode layout_mode)
diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h
index 8f36f7048c..d0a5e09d82 100644
--- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h
+++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h
@@ -27,11 +27,6 @@ public:
void dimension_box_on_line(Box const&, LayoutMode);
- struct AvailableSpaceForLineInfo {
- float left { 0 };
- float right { 0 };
- };
-
AvailableSpaceForLineInfo available_space_for_line(float y) const;
private: