summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Layout/FormattingContext.h
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-03-18 14:44:36 +0100
committerAndreas Kling <kling@serenityos.org>2022-03-18 15:18:48 +0100
commit39b7fbfeb9e469b4089f5424dc61aa074023bb5a (patch)
tree4170b708d3cefbef741e07bdc221e462a03dec1f /Userland/Libraries/LibWeb/Layout/FormattingContext.h
parent28642de6ed75133712d9936180874a4bb2ee989e (diff)
downloadserenity-39b7fbfeb9e469b4089f5424dc61aa074023bb5a.zip
LibWeb: Rewrite CSS float implementation to use offset-from-edge
The previous implementation used relative X offsets for both left and right-side floats. This made right-side floats super awkward, since we could only determine their X position once the width of the BFC root was known, and for BFC roots with automatic width, this was not even working at all most of the time. This patch changes the way we deal with floats so that BFC keeps track of the offset-from-edge for each float. The offset is the distance from the BFC root edge (left or right, depending on float direction) to the "innermost" margin edge of the floating box. Floating box are now laid out in two passes: while going through the normal flow layout, we put floats in their *static* position (i.e the position they would have occupied if they weren't floating) and then update the Y position value to the final one. The second pass occurs later on, when the BFC root has had its width assigned by the parent context. Once we know the root width, we can set the X position value of floating boxes. (Because the X position of right-side floats is relative to the right edge of the BFC root.)
Diffstat (limited to 'Userland/Libraries/LibWeb/Layout/FormattingContext.h')
-rw-r--r--Userland/Libraries/LibWeb/Layout/FormattingContext.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.h b/Userland/Libraries/LibWeb/Layout/FormattingContext.h
index 75869089ec..160a1408aa 100644
--- a/Userland/Libraries/LibWeb/Layout/FormattingContext.h
+++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.h
@@ -56,6 +56,8 @@ public:
float calculate_fit_content_height(Layout::Box const&, Optional<float> available_height) const;
float calculate_fit_content_width(Layout::Box const&, Optional<float> available_width) const;
+ virtual float greatest_child_width(Box const&);
+
protected:
FormattingContext(Type, FormattingState&, Box const&, FormattingContext* parent = nullptr);
@@ -65,7 +67,7 @@ protected:
OwnPtr<FormattingContext> layout_inside(Box const&, LayoutMode);
void compute_position(Box const&);
- struct AvailableSpaceForLineInfo {
+ struct SpaceUsedByFloats {
float left { 0 };
float right { 0 };
};