Title: [256708] trunk/Source/WebCore
Revision
256708
Author
[email protected]
Date
2020-02-16 07:14:58 -0800 (Sun, 16 Feb 2020)

Log Message

[LFC][Floats] FloatingContext::positionForFloat needs the horizontal constrains
https://bugs.webkit.org/show_bug.cgi?id=207818
<rdar://problem/59489777>

Reviewed by Antti Koivisto.

We need to access the containing block's geometry (horizontal constraints) to align a floating positioned
box in an empty floating context.

* layout/floats/FloatingContext.cpp:
(WebCore::Layout::FloatingContext::positionForFloat const):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (256707 => 256708)


--- trunk/Source/WebCore/ChangeLog	2020-02-16 15:09:50 UTC (rev 256707)
+++ trunk/Source/WebCore/ChangeLog	2020-02-16 15:14:58 UTC (rev 256708)
@@ -1,5 +1,19 @@
 2020-02-16  Zalan Bujtas  <[email protected]>
 
+        [LFC][Floats] FloatingContext::positionForFloat needs the horizontal constrains
+        https://bugs.webkit.org/show_bug.cgi?id=207818
+        <rdar://problem/59489777>
+
+        Reviewed by Antti Koivisto.
+
+        We need to access the containing block's geometry (horizontal constraints) to align a floating positioned
+        box in an empty floating context.
+
+        * layout/floats/FloatingContext.cpp:
+        (WebCore::Layout::FloatingContext::positionForFloat const):
+
+2020-02-16  Zalan Bujtas  <[email protected]>
+
         [LFC][BFC] Fix horizontal/verticalConstraintsForAncestor in BlockFormattingContext::precomputeVerticalPositionForAncestors
         https://bugs.webkit.org/show_bug.cgi?id=207817
         <rdar://problem/59489735>

Modified: trunk/Source/WebCore/layout/LayoutUnits.h (256707 => 256708)


--- trunk/Source/WebCore/layout/LayoutUnits.h	2020-02-16 15:09:50 UTC (rev 256707)
+++ trunk/Source/WebCore/layout/LayoutUnits.h	2020-02-16 15:14:58 UTC (rev 256708)
@@ -153,6 +153,8 @@
 };
 
 struct HorizontalConstraints {
+    LayoutUnit logicalRight() const { return logicalLeft + logicalWidth; }
+
     LayoutUnit logicalLeft;
     LayoutUnit logicalWidth;
 };

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp (256707 => 256708)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp	2020-02-16 15:09:50 UTC (rev 256707)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp	2020-02-16 15:14:58 UTC (rev 256708)
@@ -318,7 +318,7 @@
     // However according to the BFC rules, at this point of the layout flow we don't yet have computed vertical positions for the ancestors.
     if (layoutBox.isFloatingPositioned()) {
         precomputeVerticalPositionForAncestors(layoutBox, horizontalConstraints, verticalConstraints);
-        formattingState().displayBox(layoutBox).setTopLeft(floatingContext.positionForFloat(layoutBox));
+        formattingState().displayBox(layoutBox).setTopLeft(floatingContext.positionForFloat(layoutBox, horizontalConstraints.containingBlock));
         return;
     }
     // Non-float positioned float avoiders (formatting context roots and clear boxes) should be fine unless there are floats in this context.

Modified: trunk/Source/WebCore/layout/floats/FloatingContext.cpp (256707 => 256708)


--- trunk/Source/WebCore/layout/floats/FloatingContext.cpp	2020-02-16 15:09:50 UTC (rev 256707)
+++ trunk/Source/WebCore/layout/floats/FloatingContext.cpp	2020-02-16 15:14:58 UTC (rev 256708)
@@ -162,7 +162,7 @@
 {
 }
 
-Point FloatingContext::positionForFloat(const Box& layoutBox) const
+Point FloatingContext::positionForFloat(const Box& layoutBox, const HorizontalConstraints& horizontalConstraints) const
 {
     ASSERT(layoutBox.isFloatingPositioned());
     ASSERT(areFloatsHorizontallySorted(m_floatingState));
@@ -172,12 +172,10 @@
 
         auto alignWithContainingBlock = [&]() -> Position {
             // If there is no floating to align with, push the box to the left/right edge of its containing block's content box.
-            auto& containingBlockGeometry = formattingContext().geometryForBox(*layoutBox.containingBlock());
-
             if (layoutBox.isLeftFloatingPositioned())
-                return Position { containingBlockGeometry.contentBoxLeft() + boxGeometry.marginStart() };
+                return { horizontalConstraints.logicalLeft + boxGeometry.marginStart() };
 
-            return Position { containingBlockGeometry.contentBoxRight() - boxGeometry.marginEnd() - boxGeometry.width() };
+            return { horizontalConstraints.logicalRight() - boxGeometry.marginEnd() - boxGeometry.width() };
         };
 
         // No float box on the context yet -> align it with the containing block's left/right edge.
@@ -186,10 +184,8 @@
 
     // Find the top most position where the float box fits.
     auto absoluteDisplayBoxCoordinates = this->absoluteDisplayBoxCoordinates(layoutBox);
-
-    Optional<LayoutUnit> previousFloatAbsoluteTop;
-    if (!isEmpty())
-        previousFloatAbsoluteTop = floatingState().floats().last().rectWithMargin().top();
+    ASSERT(!isEmpty());
+    auto previousFloatAbsoluteTop = floatingState().floats().last().rectWithMargin().top();
     auto floatBox = FloatBox { layoutBox, absoluteDisplayBoxCoordinates.displayBox, absoluteDisplayBoxCoordinates.containingBlockTopLeft, absoluteDisplayBoxCoordinates.containingBlockContentBox, previousFloatAbsoluteTop };
     findPositionForFloatBox(floatBox);
     return floatBox.rectInContainingBlock().topLeft();

Modified: trunk/Source/WebCore/layout/floats/FloatingContext.h (256707 => 256708)


--- trunk/Source/WebCore/layout/floats/FloatingContext.h	2020-02-16 15:09:50 UTC (rev 256707)
+++ trunk/Source/WebCore/layout/floats/FloatingContext.h	2020-02-16 15:14:58 UTC (rev 256708)
@@ -49,7 +49,7 @@
 
     FloatingState& floatingState() const { return m_floatingState; }
 
-    Point positionForFloat(const Box&) const;
+    Point positionForFloat(const Box&, const HorizontalConstraints&) const;
     Optional<Point> positionForFormattingContextRoot(const Box&) const;
 
     struct ClearancePosition {

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp (256707 => 256708)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2020-02-16 15:09:50 UTC (rev 256707)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2020-02-16 15:14:58 UTC (rev 256708)
@@ -445,7 +445,7 @@
             // Set static position first.
             displayBox.setTopLeft({ lineBox.logicalLeft(), lineBox.logicalTop() });
             // Float it.
-            displayBox.setTopLeft(floatingContext.positionForFloat(floatBox));
+            displayBox.setTopLeft(floatingContext.positionForFloat(floatBox, horizontalConstraints));
             floatingContext.append(floatBox);
         }
     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to