Title: [249439] trunk/Source/WebCore
Revision
249439
Author
za...@apple.com
Date
2019-09-03 12:53:49 -0700 (Tue, 03 Sep 2019)

Log Message

[LFC] FloatingState should not need to query for display boxes.
https://bugs.webkit.org/show_bug.cgi?id=201408
<rdar://problem/54958348>

Reviewed by Antti Koivisto.

This is in preparation for transitioning the floating codebase to use the formatting context for
retrieving display boxes.
FloatingContext should be responsible for adding/removing the new/existing float boxes to the state.

* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot):
* layout/floats/FloatingContext.cpp:
(WebCore::Layout::FloatingContext::append):
(WebCore::Layout::FloatingContext::remove):
* layout/floats/FloatingContext.h:
* layout/floats/FloatingState.cpp:
(WebCore::Layout::FloatingState::append):
(WebCore::Layout::belongsToThisFloatingContext): Deleted.
* layout/floats/FloatingState.h:
(WebCore::Layout::FloatingState::FloatItem::horizontalMargin const):
* layout/inlineformatting/InlineFormattingContextLineLayout.cpp:
(WebCore::Layout::InlineFormattingContext::InlineLayout::createDisplayRuns const):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (249438 => 249439)


--- trunk/Source/WebCore/ChangeLog	2019-09-03 19:48:03 UTC (rev 249438)
+++ trunk/Source/WebCore/ChangeLog	2019-09-03 19:53:49 UTC (rev 249439)
@@ -1,5 +1,31 @@
 2019-09-03  Zalan Bujtas  <za...@apple.com>
 
+        [LFC] FloatingState should not need to query for display boxes.
+        https://bugs.webkit.org/show_bug.cgi?id=201408
+        <rdar://problem/54958348>
+
+        Reviewed by Antti Koivisto.
+
+        This is in preparation for transitioning the floating codebase to use the formatting context for
+        retrieving display boxes.
+        FloatingContext should be responsible for adding/removing the new/existing float boxes to the state.
+
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot):
+        * layout/floats/FloatingContext.cpp:
+        (WebCore::Layout::FloatingContext::append):
+        (WebCore::Layout::FloatingContext::remove):
+        * layout/floats/FloatingContext.h:
+        * layout/floats/FloatingState.cpp:
+        (WebCore::Layout::FloatingState::append):
+        (WebCore::Layout::belongsToThisFloatingContext): Deleted.
+        * layout/floats/FloatingState.h:
+        (WebCore::Layout::FloatingState::FloatItem::horizontalMargin const):
+        * layout/inlineformatting/InlineFormattingContextLineLayout.cpp:
+        (WebCore::Layout::InlineFormattingContext::InlineLayout::createDisplayRuns const):
+
+2019-09-03  Zalan Bujtas  <za...@apple.com>
+
         [LFC][Floats] Do not pass FloatingState to FloatItem
         https://bugs.webkit.org/show_bug.cgi?id=201406
         <rdar://problem/54957097>

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp (249438 => 249439)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp	2019-09-03 19:48:03 UTC (rev 249438)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp	2019-09-03 19:53:49 UTC (rev 249439)
@@ -180,7 +180,7 @@
     // Float related final positioning.
     if (layoutBox.isFloatingPositioned()) {
         computeFloatingPosition(floatingContext, layoutBox);
-        floatingContext.floatingState().append(layoutBox);
+        floatingContext.append(layoutBox);
     } else if (layoutBox.establishesBlockFormattingContext())
         computePositionToAvoidFloats(floatingContext, layoutBox);
 }

Modified: trunk/Source/WebCore/layout/floats/FloatingContext.cpp (249438 => 249439)


--- trunk/Source/WebCore/layout/floats/FloatingContext.cpp	2019-09-03 19:48:03 UTC (rev 249438)
+++ trunk/Source/WebCore/layout/floats/FloatingContext.cpp	2019-09-03 19:53:49 UTC (rev 249439)
@@ -341,6 +341,16 @@
     return constraints;
 }
 
+void FloatingContext::append(const Box& floatBox)
+{
+    floatingState().append(FloatingState::FloatItem { floatBox, FormattingContext::mapBoxToAncestor(layoutState(), floatBox, downcast<Container>(floatingState().root())) });
+}
+
+void FloatingContext::remove(const Box& floatBox)
+{
+    floatingState().remove(floatBox);
+}
+
 static FloatPair::LeftRightIndex findAvailablePosition(FloatAvoider& floatAvoider, const FloatingState::FloatList& floats)
 {
     Optional<PositionInContextRoot> bottomMost;

Modified: trunk/Source/WebCore/layout/floats/FloatingContext.h (249438 => 249439)


--- trunk/Source/WebCore/layout/floats/FloatingContext.h	2019-09-03 19:48:03 UTC (rev 249438)
+++ trunk/Source/WebCore/layout/floats/FloatingContext.h	2019-09-03 19:53:49 UTC (rev 249439)
@@ -66,6 +66,8 @@
         Optional<PointInContextRoot> right;
     };
     Constraints constraints(PositionInContextRoot verticalPosition) const;
+    void append(const Box&);
+    void remove(const Box&);
 
 private:
     LayoutState& layoutState() const { return m_floatingState.layoutState(); }

Modified: trunk/Source/WebCore/layout/floats/FloatingState.cpp (249438 => 249439)


--- trunk/Source/WebCore/layout/floats/FloatingState.cpp	2019-09-03 19:48:03 UTC (rev 249438)
+++ trunk/Source/WebCore/layout/floats/FloatingState.cpp	2019-09-03 19:53:49 UTC (rev 249439)
@@ -51,21 +51,6 @@
 {
 }
 
-#ifndef NDEBUG
-static bool belongsToThisFloatingContext(const Box& layoutBox, const Box& floatingStateRoot)
-{
-    auto& formattingContextRoot = layoutBox.formattingContextRoot();
-    if (&formattingContextRoot == &floatingStateRoot)
-        return true;
-
-    // Maybe the layout box belongs to an inline formatting context that inherits the floating state from the parent (block) formatting context. 
-    if (!formattingContextRoot.establishesInlineFormattingContext())
-        return false;
-
-    return &formattingContextRoot.formattingContextRoot() == &floatingStateRoot;
-}
-#endif
-
 void FloatingState::remove(const Box& layoutBox)
 {
     for (size_t index = 0; index < m_floats.size(); ++index) {
@@ -77,36 +62,33 @@
     ASSERT_NOT_REACHED();
 }
 
-void FloatingState::append(const Box& layoutBox)
+void FloatingState::append(FloatItem floatItem)
 {
     ASSERT(is<Container>(*m_formattingContextRoot));
-    ASSERT(belongsToThisFloatingContext(layoutBox, *m_formattingContextRoot));
-    ASSERT(is<Container>(*m_formattingContextRoot));
 
-    auto newFloatItem = FloatItem { layoutBox, FormattingContext::mapBoxToAncestor(layoutState(), layoutBox, downcast<Container>(root()))};
     if (m_floats.isEmpty())
-        return m_floats.append(newFloatItem);
+        return m_floats.append(floatItem);
 
-    auto& displayBox = m_layoutState.displayBoxForLayoutBox(layoutBox);
-    auto isLeftPositioned = layoutBox.isLeftFloatingPositioned();
+    auto isLeftPositioned = floatItem.isLeftPositioned();
     // When adding a new float item to the list, we have to ensure that it is definitely the left(right)-most item.
     // Normally it is, but negative horizontal margins can push the float box beyond another float box.
     // Float items in m_floats list should stay in horizontal position order (left/right edge) on the same vertical position.
-    auto hasNegativeHorizontalMargin = (isLeftPositioned && displayBox.marginStart() < 0) || (!isLeftPositioned && displayBox.marginEnd() < 0);
+    auto horizontalMargin = floatItem.horizontalMargin();
+    auto hasNegativeHorizontalMargin = (isLeftPositioned && horizontalMargin.start < 0) || (!isLeftPositioned && horizontalMargin.end < 0);
     if (!hasNegativeHorizontalMargin)
-        return m_floats.append(newFloatItem);
+        return m_floats.append(floatItem);
 
     for (int i = m_floats.size() - 1; i >= 0; --i) {
         auto& floatItem = m_floats[i];
         if (isLeftPositioned != floatItem.isLeftPositioned())
             continue;
-        if (newFloatItem.rectWithMargin().top() < floatItem.rectWithMargin().bottom())
+        if (floatItem.rectWithMargin().top() < floatItem.rectWithMargin().bottom())
             continue;
-        if ((isLeftPositioned && newFloatItem.rectWithMargin().right() >= floatItem.rectWithMargin().right())
-            || (!isLeftPositioned && newFloatItem.rectWithMargin().left() <= floatItem.rectWithMargin().left()))
-            return m_floats.insert(i + 1, newFloatItem);
+        if ((isLeftPositioned && floatItem.rectWithMargin().right() >= floatItem.rectWithMargin().right())
+            || (!isLeftPositioned && floatItem.rectWithMargin().left() <= floatItem.rectWithMargin().left()))
+            return m_floats.insert(i + 1, floatItem);
     }
-    return m_floats.insert(0, newFloatItem);
+    return m_floats.insert(0, floatItem);
 }
 
 Optional<PositionInContextRoot> FloatingState::bottom(const Box& formattingContextRoot, Clear type) const

Modified: trunk/Source/WebCore/layout/floats/FloatingState.h (249438 => 249439)


--- trunk/Source/WebCore/layout/floats/FloatingState.h	2019-09-03 19:48:03 UTC (rev 249438)
+++ trunk/Source/WebCore/layout/floats/FloatingState.h	2019-09-03 19:53:49 UTC (rev 249439)
@@ -38,6 +38,7 @@
 
 namespace Layout {
 
+class FloatingContext;
 class FormattingState;
 class LayoutState;
 
@@ -47,9 +48,6 @@
 public:
     static Ref<FloatingState> create(LayoutState& layoutState, const Box& formattingContextRoot) { return adoptRef(*new FloatingState(layoutState, formattingContextRoot)); }
 
-    void append(const Box& layoutBox);
-    void remove(const Box& layoutBox);
-
     const Box& root() const { return *m_formattingContextRoot; }
 
     Optional<PositionInContextRoot> top(const Box& formattingContextRoot) const;
@@ -67,6 +65,7 @@
         bool isDescendantOfFormattingRoot(const Box&) const;
 
         Display::Rect rectWithMargin() const { return m_absoluteDisplayBox.rectWithMargin(); }
+        UsedHorizontalMargin horizontalMargin() const { return m_absoluteDisplayBox.horizontalMargin(); }
         PositionInContextRoot bottom() const { return { m_absoluteDisplayBox.bottom() }; }
 
     private:
@@ -81,6 +80,9 @@
     friend class FloatingContext;
     FloatingState(LayoutState&, const Box& formattingContextRoot);
 
+    void append(FloatItem);
+    void remove(const Box& layoutBox);
+
     LayoutState& layoutState() const { return m_layoutState; }
 
     Optional<PositionInContextRoot> bottom(const Box& formattingContextRoot, Clear) const;

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp (249438 => 249439)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp	2019-09-03 19:48:03 UTC (rev 249438)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp	2019-09-03 19:53:49 UTC (rev 249439)
@@ -364,8 +364,7 @@
     auto& layoutState = this->layoutState();
     auto& formattingContext = this->formattingContext();
     auto& formattingState = downcast<InlineFormattingState>(layoutState.establishedFormattingState(formattingRoot()));
-    auto& floatingState = formattingState.floatingState();
-    auto floatingContext = FloatingContext { formattingRoot(), floatingState };
+    auto floatingContext = FloatingContext { formattingRoot(), formattingState.floatingState() };
 
     // Move floats to their final position.
     for (auto floatItem : floats) {
@@ -376,7 +375,7 @@
         displayBox.setTopLeft({ lineContent.logicalLeft(), lineContent.logicalTop() });
         // Float it.
         displayBox.setTopLeft(floatingContext.positionForFloat(floatBox));
-        floatingState.append(floatBox);
+        floatingContext.append(floatBox);
     }
 
     if (lineContent.isEmpty()) {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to