diff options
author | Andreas Kling <kling@serenityos.org> | 2022-03-17 12:30:30 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-18 15:18:48 +0100 |
commit | ef8a72ff3f653094f615110efe30d72f8b54733d (patch) | |
tree | d34662295d7d4c39970282e1755b5276183d7f9e /Userland/Libraries | |
parent | fc6b7fcd97f5662f92864e5496d995da8f52a3e8 (diff) | |
download | serenity-ef8a72ff3f653094f615110efe30d72f8b54733d.zip |
LibWeb: Move available_space_for_line() from IFC to BFC
This is preparation for allowing blocks with their own internal BFC to
flow around floating boxes in the parent BFC.
Note that IFC still has the available_space_for_line() API, which
returns space available within the IFC's own containing block, while the
BFC available_space_for_line() returns space available within its root.
Diffstat (limited to 'Userland/Libraries')
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: |