[LFC][Floating] FloatingState should take the formatting root box.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Aug 2018 20:53:47 +0000 (20:53 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Aug 2018 20:53:47 +0000 (20:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=188214

Reviewed by Antti Koivisto.

This will be taken into use when FormattingContext takes all boxes in the coordinate system of the formatting root.

* layout/FloatingState.cpp:
(WebCore::Layout::FloatingState::FloatingState):
(WebCore::Layout::belongsToThisFloatingContext):
(WebCore::Layout::FloatingState::append):
* layout/FloatingState.h:
(WebCore::Layout::FloatingState::create):
* layout/LayoutContext.cpp:
(WebCore::Layout::LayoutContext::establishedFormattingState):

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

Source/WebCore/ChangeLog
Source/WebCore/layout/FloatingState.cpp
Source/WebCore/layout/FloatingState.h
Source/WebCore/layout/LayoutContext.cpp

index 1bc8ad1..42baa7b 100644 (file)
@@ -1,5 +1,23 @@
 2018-08-01  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC][Floating] FloatingState should take the formatting root box.
+        https://bugs.webkit.org/show_bug.cgi?id=188214
+
+        Reviewed by Antti Koivisto.
+
+        This will be taken into use when FormattingContext takes all boxes in the coordinate system of the formatting root.
+
+        * layout/FloatingState.cpp:
+        (WebCore::Layout::FloatingState::FloatingState):
+        (WebCore::Layout::belongsToThisFloatingContext):
+        (WebCore::Layout::FloatingState::append):
+        * layout/FloatingState.h:
+        (WebCore::Layout::FloatingState::create):
+        * layout/LayoutContext.cpp:
+        (WebCore::Layout::LayoutContext::establishedFormattingState):
+
+2018-08-01  Zalan Bujtas  <zalan@apple.com>
+
         [LFC][Floating] Align new floating with the bottom of the existing floatings.
         https://bugs.webkit.org/show_bug.cgi?id=188213
 
index 3972590..bc63036 100644 (file)
@@ -37,13 +37,32 @@ namespace Layout {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(FloatingState);
 
-FloatingState::FloatingState(LayoutContext& layoutContext)
+FloatingState::FloatingState(LayoutContext& layoutContext, const Box& formattingContextRoot)
     : m_layoutContext(layoutContext)
+    , m_formattingContextRoot(makeWeakPtr(const_cast<Box&>(formattingContextRoot)))
 {
 }
 
+#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::append(const Box& layoutBox)
 {
+    ASSERT(is<Container>(*m_formattingContextRoot));
+    ASSERT(belongsToThisFloatingContext(layoutBox, *m_formattingContextRoot));
+
     // Floating state should hold boxes with computed position/size.
     ASSERT(m_layoutContext.displayBoxForLayoutBox(layoutBox));
     m_last = makeWeakPtr(const_cast<Box&>(layoutBox));
index 96f8873..79f9824 100644 (file)
@@ -43,7 +43,7 @@ class LayoutContext;
 class FloatingState : public RefCounted<FloatingState> {
     WTF_MAKE_ISO_ALLOCATED(FloatingState);
 public:
-    static Ref<FloatingState> create(LayoutContext& layoutContext) { return adoptRef(*new FloatingState(layoutContext)); }
+    static Ref<FloatingState> create(LayoutContext& layoutContext, const Box& formattingContextRoot) { return adoptRef(*new FloatingState(layoutContext, formattingContextRoot)); }
 
     void append(const Box& layoutBox);
 
@@ -59,11 +59,12 @@ public:
 
 private:
     friend class FloatingContext;
-    FloatingState(LayoutContext&);
+    FloatingState(LayoutContext&, const Box& formattingContextRoot);
 
     LayoutContext& layoutContext() const { return m_layoutContext; }
 
     LayoutContext& m_layoutContext;
+    WeakPtr<Box> m_formattingContextRoot;
 
     FloatingList m_leftFloatings;
     FloatingList m_rightFloatings;
index 482a47f..3cb6f9d 100644 (file)
@@ -127,7 +127,7 @@ FormattingState& LayoutContext::establishedFormattingState(const Box& formatting
             // should not interfere with the content inside.
             // <div style="float: left"></div><div style="overflow: hidden"> <- is a non-intrusive float, because overflow: hidden triggers new block formatting context.</div>
             if (formattingRoot.establishesBlockFormattingContext())
-                return std::make_unique<InlineFormattingState>(FloatingState::create(*this), *this);
+                return std::make_unique<InlineFormattingState>(FloatingState::create(*this, formattingRoot), *this);
 
             // Otherwise, the formatting context inherits the floats from the parent formatting context.
             // Find the formatting state in which this formatting root lives, not the one it creates and use its floating state.
@@ -139,7 +139,7 @@ FormattingState& LayoutContext::establishedFormattingState(const Box& formatting
         return *m_formattingStates.ensure(&formattingRoot, [&] {
 
             // Block formatting context always establishes a new floating state.
-            return std::make_unique<BlockFormattingState>(FloatingState::create(*this), *this);
+            return std::make_unique<BlockFormattingState>(FloatingState::create(*this, formattingRoot), *this);
         }).iterator->value;
     }
     CRASH();