mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:47:45 +00:00
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.
This commit is contained in:
parent
fc6b7fcd97
commit
ef8a72ff3f
5 changed files with 36 additions and 32 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue