mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-03 06:39:07 +00:00
LibWeb: Make FC of containing block responsible for abspos layout
Before this change, a formatting context was responsible for layout of absolutely positioned boxes whose FC root box was their parent (either directly or indirectly). This only worked correctly when the containing block of the absolutely positioned child did not escape the FC root. This is because the width and height of an absolutely positioned box are resolved based on the size of its containing block, so we needed to ensure that the containing block's layout was completed before laying out an absolutely positioned box. With this change, the layout of absolutely positioned boxes is delayed until the FC responsible for the containing block's layout is complete. This has affected the way we calculate the static position. It is no longer possible to ask the FC for a box's static position, as this FC's state might be gone by the time the layout for absolutely positioned elements occurs. Instead, the "static position rectangle" (a concept from the spec) is saved in the layout state, along with information on how to align the box within this rectangle when its width and height are resolved.
This commit is contained in:
parent
bea7eec518
commit
863416e3ac
Notes:
github-actions[bot]
2024-09-12 05:37:23 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: 863416e3ac
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1373
18 changed files with 299 additions and 86 deletions
|
@ -25,6 +25,35 @@ enum class SizeConstraint {
|
|||
class AvailableSize;
|
||||
class AvailableSpace;
|
||||
|
||||
// https://www.w3.org/TR/css-position-3/#static-position-rectangle
|
||||
struct StaticPositionRect {
|
||||
enum class Alignment {
|
||||
Start,
|
||||
Center,
|
||||
End,
|
||||
};
|
||||
|
||||
CSSPixelRect rect;
|
||||
Alignment horizontal_alignment { Alignment::Start };
|
||||
Alignment vertical_alignment { Alignment::Start };
|
||||
|
||||
CSSPixelPoint aligned_position_for_box_with_size(CSSPixelSize const& size) const
|
||||
{
|
||||
CSSPixelPoint position = rect.location();
|
||||
if (horizontal_alignment == Alignment::Center)
|
||||
position.set_x(position.x() + (rect.width() - size.width()) / 2);
|
||||
else if (horizontal_alignment == Alignment::End)
|
||||
position.set_x(position.x() + rect.width() - size.width());
|
||||
|
||||
if (vertical_alignment == Alignment::Center)
|
||||
position.set_y(position.y() + (rect.height() - size.height()) / 2);
|
||||
else if (vertical_alignment == Alignment::End)
|
||||
position.set_y(position.y() + rect.height() - size.height());
|
||||
|
||||
return position;
|
||||
}
|
||||
};
|
||||
|
||||
struct LayoutState {
|
||||
LayoutState()
|
||||
: m_root(*this)
|
||||
|
@ -145,6 +174,15 @@ struct LayoutState {
|
|||
void set_grid_template_rows(RefPtr<CSS::GridTrackSizeListStyleValue> used_values_for_grid_template_rows) { m_grid_template_rows = move(used_values_for_grid_template_rows); }
|
||||
auto const& grid_template_rows() const { return m_grid_template_rows; }
|
||||
|
||||
void set_static_position_rect(StaticPositionRect const& static_position_rect) { m_static_position_rect = static_position_rect; }
|
||||
CSSPixelPoint static_position() const
|
||||
{
|
||||
CSSPixelSize size;
|
||||
size.set_width(content_width() + padding_left + padding_right + border_left + border_right + margin_left + margin_right);
|
||||
size.set_height(content_height() + padding_top + padding_bottom + border_top + border_bottom + margin_top + margin_bottom);
|
||||
return m_static_position_rect->aligned_position_for_box_with_size(size);
|
||||
}
|
||||
|
||||
private:
|
||||
AvailableSize available_width_inside() const;
|
||||
AvailableSize available_height_inside() const;
|
||||
|
@ -175,6 +213,8 @@ struct LayoutState {
|
|||
|
||||
RefPtr<CSS::GridTrackSizeListStyleValue> m_grid_template_columns;
|
||||
RefPtr<CSS::GridTrackSizeListStyleValue> m_grid_template_rows;
|
||||
|
||||
Optional<StaticPositionRect> m_static_position_rect;
|
||||
};
|
||||
|
||||
// Commits the used values produced by layout and builds a paintable tree.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue