[LFC][Floating] Move containing block constraint logic from FloatAvoider to FloatingC...
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Aug 2018 14:32:29 +0000 (14:32 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Aug 2018 14:32:29 +0000 (14:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=189145

Reviewed by Antti Koivisto.

When the float avoider is constrained horizontally, simply align it with the left/right edge of its containing block (with the combination of the constraints)
and check the overflow as part of the FloatingContext::floatingPosition() logic. It simplifies the constraint logic/helps implementing the non-float avoider
case.

* layout/floats/FloatAvoider.cpp:
(WebCore::Layout::FloatAvoider::setHorizontalConstraints):
(WebCore::Layout::FloatAvoider::overflowsContainingBlock const):
* layout/floats/FloatAvoider.h:
* layout/floats/FloatingContext.cpp:
(WebCore::Layout::FloatingContext::floatingPosition const):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@235503 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/layout/floats/FloatAvoider.cpp
Source/WebCore/layout/floats/FloatAvoider.h
Source/WebCore/layout/floats/FloatingContext.cpp

index d9d4b8d..c51e780 100644 (file)
@@ -1,5 +1,23 @@
 2018-08-30  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC][Floating] Move containing block constraint logic from FloatAvoider to FloatingContext
+        https://bugs.webkit.org/show_bug.cgi?id=189145
+
+        Reviewed by Antti Koivisto.
+
+        When the float avoider is constrained horizontally, simply align it with the left/right edge of its containing block (with the combination of the constraints)
+        and check the overflow as part of the FloatingContext::floatingPosition() logic. It simplifies the constraint logic/helps implementing the non-float avoider
+        case.
+
+        * layout/floats/FloatAvoider.cpp:
+        (WebCore::Layout::FloatAvoider::setHorizontalConstraints):
+        (WebCore::Layout::FloatAvoider::overflowsContainingBlock const):
+        * layout/floats/FloatAvoider.h:
+        * layout/floats/FloatingContext.cpp:
+        (WebCore::Layout::FloatingContext::floatingPosition const):
+
+2018-08-30  Zalan Bujtas  <zalan@apple.com>
+
         [LFC][Floating] Use non-computed horizontal margins when intersecting floats with float avoiders.
         https://bugs.webkit.org/show_bug.cgi?id=189143
 
index af52d34..e965df3 100644 (file)
@@ -59,13 +59,12 @@ void FloatAvoider::setHorizontalConstraints(HorizontalConstraints horizontalCons
         // Horizontal position is constrained by the containing block's content box.
         // Compute the horizontal position for the new floating by taking both the contining block and the current left/right floats into account.
         auto containingBlockContentBoxLeft = m_containingBlockAbsoluteDisplayBox.left() + m_containingBlockAbsoluteDisplayBox.contentBoxLeft();
-        auto containingBlockContentBoxRight = containingBlockContentBoxLeft + m_containingBlockAbsoluteDisplayBox.contentBoxWidth();
-        // Align it with the containing block's left edge first.
-        left = std::max(containingBlockContentBoxLeft + marginLeft(), left);
-        // Make sure it does not overflow the containing block on the right.
-        left = std::min(left, containingBlockContentBoxRight - marginBoxWidth() + marginLeft());
+        if (isLeftAligned())
+            return std::max(containingBlockContentBoxLeft + marginLeft(), left);
 
-        return left;
+        // Make sure it does not overflow the containing block on the right.
+        auto containingBlockContentBoxRight = containingBlockContentBoxLeft + m_containingBlockAbsoluteDisplayBox.contentBoxWidth();
+        return std::min(left, containingBlockContentBoxRight - marginBoxWidth() + marginLeft());
     };
 
     auto positionCandidate = horizontalPositionCandidate(horizontalConstraints);
@@ -104,6 +103,20 @@ PositionInContextRoot FloatAvoider::initialHorizontalPosition() const
     return left;
 }
 
+bool FloatAvoider::overflowsContainingBlock() const
+{
+    auto containingBlockContentBoxLeft = m_containingBlockAbsoluteDisplayBox.left() + m_containingBlockAbsoluteDisplayBox.contentBoxLeft();
+    auto left = displayBox().left() - marginLeft();
+
+    if (containingBlockContentBoxLeft > left)
+        return true;
+
+    auto containingBlockContentBoxRight = containingBlockContentBoxLeft + m_containingBlockAbsoluteDisplayBox.contentBoxWidth();
+    auto right = displayBox().right() + marginRight();
+
+    return containingBlockContentBoxRight < right;
+}
+
 Display::Box::Rect FloatAvoider::rectInContainingBlock() const
 {
     // From formatting root coordinate system back to containing block's.
index ce91d9c..dcfb173 100644 (file)
@@ -56,6 +56,8 @@ public:
     void setHorizontalConstraints(HorizontalConstraints);
     void setVerticalConstraint(PositionInContextRoot);
 
+    bool overflowsContainingBlock() const;
+
     void resetPosition();
 
 protected:
index f15d68d..24b5532 100644 (file)
@@ -230,8 +230,11 @@ void FloatingContext::floatingPosition(FloatAvoider& floatAvoider) const
         // 2. or with the containing block's content box if there's no float to align with at this vertical position.
         floatAvoider.setHorizontalConstraints(floats.horizontalConstraints());
         floatAvoider.setVerticalConstraint(floats.verticalConstraint());
-        // Check if the box fits at this position.
-        if (!floats.intersects(floatAvoider.rect()))
+
+        // Ensure that the float avoider
+        // 1. does not overflow its containing block with the current horiztonal constraints
+        // 2. avoids floats on both sides.
+        if (!floatAvoider.overflowsContainingBlock() && !floats.intersects(floatAvoider.rect()))
             return;
 
         bottomMost = floats.bottom();