[LFC][Floating] Use non-computed horizontal margins when intersecting floats with...
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Aug 2018 14:28:54 +0000 (14:28 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Aug 2018 14:28:54 +0000 (14:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=189143

Reviewed by Antti Koivisto.

* layout/Verification.cpp:
(WebCore::Layout::LayoutContext::verifyAndOutputMismatchingLayoutTree const):
* layout/floats/FloatAvoider.cpp:
(WebCore::Layout::FloatAvoider::setHorizontalConstraints):
(WebCore::Layout::FloatAvoider::initialHorizontalPosition const):
* layout/floats/FloatAvoider.h:
(WebCore::Layout::FloatAvoider::marginTop const):
(WebCore::Layout::FloatAvoider::marginBottom const):
(WebCore::Layout::FloatAvoider::marginLeft const):
(WebCore::Layout::FloatAvoider::marginRight const):
(WebCore::Layout::FloatAvoider::marginBoxWidth const):
* layout/floats/FloatBox.cpp:
(WebCore::Layout::FloatBox::rect const):
(WebCore::Layout::FloatBox::horizontalPositionCandidate):
(WebCore::Layout::FloatBox::verticalPositionCandidate):
(WebCore::Layout::FloatBox::initialVerticalPosition const):
* layout/floats/FloatBox.h:

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

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

index a20b53b..d9d4b8d 100644 (file)
@@ -1,5 +1,30 @@
 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
+
+        Reviewed by Antti Koivisto.
+
+        * layout/Verification.cpp:
+        (WebCore::Layout::LayoutContext::verifyAndOutputMismatchingLayoutTree const):
+        * layout/floats/FloatAvoider.cpp:
+        (WebCore::Layout::FloatAvoider::setHorizontalConstraints):
+        (WebCore::Layout::FloatAvoider::initialHorizontalPosition const):
+        * layout/floats/FloatAvoider.h:
+        (WebCore::Layout::FloatAvoider::marginTop const):
+        (WebCore::Layout::FloatAvoider::marginBottom const):
+        (WebCore::Layout::FloatAvoider::marginLeft const):
+        (WebCore::Layout::FloatAvoider::marginRight const):
+        (WebCore::Layout::FloatAvoider::marginBoxWidth const):
+        * layout/floats/FloatBox.cpp:
+        (WebCore::Layout::FloatBox::rect const):
+        (WebCore::Layout::FloatBox::horizontalPositionCandidate):
+        (WebCore::Layout::FloatBox::verticalPositionCandidate):
+        (WebCore::Layout::FloatBox::initialVerticalPosition const):
+        * layout/floats/FloatBox.h:
+
+2018-08-30  Zalan Bujtas  <zalan@apple.com>
+
         [LFC][Margins] Add non-computed horizontal margins to DisplayBox
         https://bugs.webkit.org/show_bug.cgi?id=189141
 
index 3f79df7..af52d34 100644 (file)
@@ -61,10 +61,9 @@ void FloatAvoider::setHorizontalConstraints(HorizontalConstraints horizontalCons
         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 + m_absoluteDisplayBox.marginLeft(), left);
+        left = std::max(containingBlockContentBoxLeft + marginLeft(), left);
         // Make sure it does not overflow the containing block on the right.
-        auto marginBoxSize = m_absoluteDisplayBox.marginBox().width();
-        left = std::min(left, containingBlockContentBoxRight - marginBoxSize + m_absoluteDisplayBox.marginLeft());
+        left = std::min(left, containingBlockContentBoxRight - marginBoxWidth() + marginLeft());
 
         return left;
     };
@@ -99,8 +98,8 @@ PositionInContextRoot FloatAvoider::initialHorizontalPosition() const
     auto containingBlockContentBoxLeft = m_containingBlockAbsoluteDisplayBox.left() + m_containingBlockAbsoluteDisplayBox.contentBoxLeft();
     auto containingBlockContentBoxRight = containingBlockContentBoxLeft + m_containingBlockAbsoluteDisplayBox.contentBoxWidth();
 
-    auto left = isLeftAligned() ? containingBlockContentBoxLeft : containingBlockContentBoxRight - m_absoluteDisplayBox.marginBox().width();
-    left += m_absoluteDisplayBox.marginLeft();
+    auto left = isLeftAligned() ? containingBlockContentBoxLeft : containingBlockContentBoxRight - marginBoxWidth();
+    left += marginLeft();
 
     return left;
 }
index 55562ea..ce91d9c 100644 (file)
@@ -68,6 +68,13 @@ protected:
     virtual PositionInContextRoot horizontalPositionCandidate(HorizontalConstraints);
     virtual PositionInContextRoot verticalPositionCandidate(PositionInContextRoot);
 
+    LayoutUnit marginTop() const { return displayBox().marginTop(); }
+    LayoutUnit marginBottom() const { return displayBox().marginBottom(); }
+    LayoutUnit marginLeft() const { return displayBox().nonComputedMarginLeft(); }
+    LayoutUnit marginRight() const { return displayBox().nonComputedMarginRight(); }
+
+    LayoutUnit marginBoxWidth() const { return marginLeft() + displayBox().width() + marginRight(); }
+
     const FloatingState& floatingState() const { return m_floatingState; }
     const Box& layoutBox() const { return *m_layoutBox; }
     const Display::Box& displayBox() const { return m_absoluteDisplayBox; }
index 290736f..27ab341 100644 (file)
@@ -40,27 +40,33 @@ FloatBox::FloatBox(const Box& layoutBox, const FloatingState& floatingState, con
 {
 }
 
+Display::Box::Rect FloatBox::rect() const
+{
+    auto rect = displayBox().rect();
+    return { rect.top() - marginTop(), rect.left() - marginLeft(), marginLeft() + rect.width() + marginRight(), marginTop() + rect.height() + marginBottom() };
+}
+
 PositionInContextRoot FloatBox::horizontalPositionCandidate(HorizontalConstraints horizontalConstraints)
 {
     auto positionCandidate = isLeftAligned() ? *horizontalConstraints.left : *horizontalConstraints.right - rect().width();
-    positionCandidate += displayBox().marginLeft();
+    positionCandidate += marginLeft();
 
     return positionCandidate;
 }
 
 PositionInContextRoot FloatBox::verticalPositionCandidate(PositionInContextRoot verticalConstraint)
 {
-    return verticalConstraint + displayBox().marginTop();
+    return verticalConstraint + marginTop();
 }
 
 PositionInContextRoot FloatBox::initialVerticalPosition() const
 {
     // Incoming float cannot be placed higher than existing floats (margin box of the last float).
     // Take the static position (where the box would go if it wasn't floating) and adjust it with the last float.
-    auto top = FloatAvoider::initialVerticalPosition() - displayBox().marginTop();
+    auto top = FloatAvoider::initialVerticalPosition() - marginTop();
     if (auto lastFloat = floatingState().last())
         top = std::max(top, lastFloat->rectWithMargin().top());
-    top += displayBox().marginTop();
+    top += marginTop();
 
     return top;
 }
index ed7edae..32fb3c2 100644 (file)
@@ -43,7 +43,7 @@ class FloatBox : public FloatAvoider {
 public:
     FloatBox(const Box&, const FloatingState&, const LayoutContext&);
 
-    Display::Box::Rect rect() const final { return displayBox().rectWithMargin(); }
+    Display::Box::Rect rect() const final;
 
 private:
     bool isLeftAligned() const final { return layoutBox().isLeftFloatingPositioned(); }