[LFC][Floats] Make FloatAvoider::resetPosition implicit
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Feb 2019 19:15:32 +0000 (19:15 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Feb 2019 19:15:32 +0000 (19:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=194855

Reviewed by Antti Koivisto.

Let's compute the initial top/left position during c'tor time.
This is in preparation for fixing formatting root box placement in a float context.

* layout/floats/FloatAvoider.cpp:
(WebCore::Layout::FloatAvoider::resetPosition): Deleted.
* layout/floats/FloatAvoider.h:
(WebCore::Layout::FloatAvoider::displayBox):
(WebCore::Layout::FloatAvoider::initialVerticalPosition const): Deleted.
* layout/floats/FloatBox.cpp:
(WebCore::Layout::FloatBox::FloatBox):
(WebCore::Layout::FloatBox::initialVerticalPosition const):
* layout/floats/FloatBox.h:
* layout/floats/FloatingContext.cpp:
(WebCore::Layout::FloatingContext::floatingPosition const):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241822 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
Source/WebCore/layout/floats/FloatingContext.cpp

index 93eade4..b72ab5f 100644 (file)
@@ -1,3 +1,25 @@
+2019-02-20  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC][Floats] Make FloatAvoider::resetPosition implicit
+        https://bugs.webkit.org/show_bug.cgi?id=194855
+
+        Reviewed by Antti Koivisto.
+
+        Let's compute the initial top/left position during c'tor time.
+        This is in preparation for fixing formatting root box placement in a float context.
+
+        * layout/floats/FloatAvoider.cpp:
+        (WebCore::Layout::FloatAvoider::resetPosition): Deleted.
+        * layout/floats/FloatAvoider.h:
+        (WebCore::Layout::FloatAvoider::displayBox):
+        (WebCore::Layout::FloatAvoider::initialVerticalPosition const): Deleted.
+        * layout/floats/FloatBox.cpp:
+        (WebCore::Layout::FloatBox::FloatBox):
+        (WebCore::Layout::FloatBox::initialVerticalPosition const):
+        * layout/floats/FloatBox.h:
+        * layout/floats/FloatingContext.cpp:
+        (WebCore::Layout::FloatingContext::floatingPosition const):
+
 2019-02-20  Don Olmstead  <don.olmstead@sony.com>
 
         [MSVC] Fix compilation errors with lambdas in Service Workers
index db181cd..151d88e 100644 (file)
@@ -43,9 +43,9 @@ FloatAvoider::FloatAvoider(const Box& layoutBox, const FloatingState& floatingSt
     , m_floatingState(floatingState)
     , m_absoluteDisplayBox(FormattingContext::mapBoxToAncestor(layoutState, layoutBox, downcast<Container>(floatingState.root())))
     , m_containingBlockAbsoluteDisplayBox(layoutBox.containingBlock() == &floatingState.root() ? Display::Box(layoutState.displayBoxForLayoutBox(*layoutBox.containingBlock())) : FormattingContext::mapBoxToAncestor(layoutState, *layoutBox.containingBlock(), downcast<Container>(floatingState.root())))
-    , m_initialVerticalPosition({ m_absoluteDisplayBox.top() })
 {
     ASSERT(m_layoutBox->establishesBlockFormattingContext());
+    m_absoluteDisplayBox.setLeft({ initialHorizontalPosition() });
 }
 
 void FloatAvoider::setHorizontalConstraints(HorizontalConstraints horizontalConstraints)
@@ -87,11 +87,6 @@ PositionInContextRoot FloatAvoider::verticalPositionCandidate(PositionInContextR
     return verticalConstraint;
 }
 
-void FloatAvoider::resetPosition()
-{
-    m_absoluteDisplayBox.setTopLeft({ initialHorizontalPosition(), initialVerticalPosition() });
-}
-
 PositionInContextRoot FloatAvoider::initialHorizontalPosition() const
 {
     // Align the box with the containing block's content box.
index 67c9429..2c323dd 100644 (file)
@@ -58,12 +58,9 @@ public:
 
     bool overflowsContainingBlock() const;
 
-    void resetPosition();
-
 protected:
     virtual bool isLeftAligned() const { return layoutBox().style().isLeftToRightDirection(); }
-    virtual PositionInContextRoot initialHorizontalPosition() const;
-    virtual PositionInContextRoot initialVerticalPosition() const { return m_initialVerticalPosition; }
+    PositionInContextRoot initialHorizontalPosition() const;
 
     void resetHorizontalConstraints();
 
@@ -81,13 +78,13 @@ protected:
     const FloatingState& floatingState() const { return m_floatingState; }
     const Box& layoutBox() const { return *m_layoutBox; }
     const Display::Box& displayBox() const { return m_absoluteDisplayBox; }
+    Display::Box& displayBox() { return m_absoluteDisplayBox; }
 
 private:
     WeakPtr<const Box> m_layoutBox;
     const FloatingState& m_floatingState;
     Display::Box m_absoluteDisplayBox;
     Display::Box m_containingBlockAbsoluteDisplayBox;
-    PositionInContextRoot m_initialVerticalPosition;
 };
 
 }
index b557bb0..beb757e 100644 (file)
@@ -38,6 +38,7 @@ WTF_MAKE_ISO_ALLOCATED_IMPL(FloatBox);
 FloatBox::FloatBox(const Box& layoutBox, const FloatingState& floatingState, const LayoutState& layoutState)
     : FloatAvoider(layoutBox, floatingState, layoutState)
 {
+    displayBox().setTopLeft({ initialHorizontalPosition(), initialVerticalPosition() });
 }
 
 Display::Box::Rect FloatBox::rect() const
@@ -63,7 +64,7 @@ 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() - marginBefore();
+    auto top = displayBox().top() - marginBefore();
     if (auto lastFloat = floatingState().last())
         top = std::max(top, lastFloat->rectWithMargin().top());
     top += marginBefore();
index 819b14c..2edcae8 100644 (file)
@@ -51,7 +51,7 @@ private:
     PositionInContextRoot horizontalPositionCandidate(HorizontalConstraints) final;
     PositionInContextRoot verticalPositionCandidate(PositionInContextRoot) final;
 
-    PositionInContextRoot initialVerticalPosition() const final;
+    PositionInContextRoot initialVerticalPosition() const;
 };
 
 }
index a123b2d..98ce2e8 100644 (file)
@@ -261,9 +261,6 @@ FloatingContext::ClearancePosition FloatingContext::verticalPositionWithClearanc
 
 void FloatingContext::floatingPosition(FloatAvoider& floatAvoider) const
 {
-    // Ensure the float avoider starts with no constraints.
-    floatAvoider.resetPosition();
-
     Optional<PositionInContextRoot> bottomMost;
     auto end = Layout::end(m_floatingState);
     for (auto iterator = begin(m_floatingState, { floatAvoider.rect().top() }); iterator != end; ++iterator) {