[LFC][Floating] FloatBox -> FloatAvoider
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Aug 2018 05:01:28 +0000 (05:01 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Aug 2018 05:01:28 +0000 (05:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=188941

Reviewed by Antti Koivisto.

This is in preparation for the float avoidance feature where formatting context root boxes avoid existing floats.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* layout/displaytree/DisplayBox.h:
* layout/floats/FloatAvoider.cpp: Renamed from Source/WebCore/layout/floats/FloatBox.cpp.
(WebCore::Layout::FloatAvoider::FloatAvoider):
(WebCore::Layout::FloatAvoider::initializePosition):
(WebCore::Layout::FloatAvoider::isLeftAligned const):
(WebCore::Layout::FloatAvoider::setLeft):
(WebCore::Layout::FloatAvoider::setTopLeft):
(WebCore::Layout::FloatAvoider::resetVertically):
(WebCore::Layout::FloatAvoider::resetHorizontally):
(WebCore::Layout::FloatAvoider::topLeftInContainingBlock const):
* layout/floats/FloatAvoider.h: Renamed from Source/WebCore/layout/floats/FloatBox.h.
(WebCore::Layout::FloatAvoider::top const):
(WebCore::Layout::FloatAvoider::left const):
(WebCore::Layout::FloatAvoider::marginTop const):
(WebCore::Layout::FloatAvoider::marginLeft const):
(WebCore::Layout::FloatAvoider::marginBottom const):
(WebCore::Layout::FloatAvoider::marginRight const):
(WebCore::Layout::FloatAvoider::rectWithMargin const):
(WebCore::Layout::FloatAvoider::setTop):
* layout/floats/FloatingContext.cpp:
(WebCore::Layout::FloatingContext::positionForFloat const):
(WebCore::Layout::FloatingContext::floatingPosition const):
* layout/floats/FloatingContext.h:

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

Source/WebCore/ChangeLog
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/layout/displaytree/DisplayBox.h
Source/WebCore/layout/floats/FloatAvoider.cpp [moved from Source/WebCore/layout/floats/FloatBox.cpp with 89% similarity]
Source/WebCore/layout/floats/FloatAvoider.h [moved from Source/WebCore/layout/floats/FloatBox.h with 95% similarity]
Source/WebCore/layout/floats/FloatingContext.cpp
Source/WebCore/layout/floats/FloatingContext.h

index 362e158..0b036e4 100644 (file)
@@ -1,3 +1,38 @@
+2018-08-26  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC][Floating] FloatBox -> FloatAvoider
+        https://bugs.webkit.org/show_bug.cgi?id=188941
+
+        Reviewed by Antti Koivisto.
+
+        This is in preparation for the float avoidance feature where formatting context root boxes avoid existing floats.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * layout/displaytree/DisplayBox.h:
+        * layout/floats/FloatAvoider.cpp: Renamed from Source/WebCore/layout/floats/FloatBox.cpp.
+        (WebCore::Layout::FloatAvoider::FloatAvoider):
+        (WebCore::Layout::FloatAvoider::initializePosition):
+        (WebCore::Layout::FloatAvoider::isLeftAligned const):
+        (WebCore::Layout::FloatAvoider::setLeft):
+        (WebCore::Layout::FloatAvoider::setTopLeft):
+        (WebCore::Layout::FloatAvoider::resetVertically):
+        (WebCore::Layout::FloatAvoider::resetHorizontally):
+        (WebCore::Layout::FloatAvoider::topLeftInContainingBlock const):
+        * layout/floats/FloatAvoider.h: Renamed from Source/WebCore/layout/floats/FloatBox.h.
+        (WebCore::Layout::FloatAvoider::top const):
+        (WebCore::Layout::FloatAvoider::left const):
+        (WebCore::Layout::FloatAvoider::marginTop const):
+        (WebCore::Layout::FloatAvoider::marginLeft const):
+        (WebCore::Layout::FloatAvoider::marginBottom const):
+        (WebCore::Layout::FloatAvoider::marginRight const):
+        (WebCore::Layout::FloatAvoider::rectWithMargin const):
+        (WebCore::Layout::FloatAvoider::setTop):
+        * layout/floats/FloatingContext.cpp:
+        (WebCore::Layout::FloatingContext::positionForFloat const):
+        (WebCore::Layout::FloatingContext::floatingPosition const):
+        * layout/floats/FloatingContext.h:
+
 2018-08-26  Christopher Reid  <chris.reid@sony.com>
 
         [Curl] Implement deleteCookie()
index 9769989..80a74e4 100644 (file)
@@ -1229,7 +1229,7 @@ layout/blockformatting/BlockFormattingState.cpp
 layout/blockformatting/BlockMarginCollapse.cpp
 layout/blockformatting/BlockInvalidation.cpp
 layout/displaytree/DisplayBox.cpp
-layout/floats/FloatBox.cpp
+layout/floats/FloatAvoider.cpp
 layout/floats/FloatingContext.cpp
 layout/floats/FloatingState.cpp
 layout/inlineformatting/InlineFormattingContext.cpp
index 6a55d13..3bd6491 100644 (file)
                6F995A381A70833700A735F4 /* JSWebGLTransformFeedback.h in Headers */ = {isa = PBXBuildFile; fileRef = 6F995A2E1A70833700A735F4 /* JSWebGLTransformFeedback.h */; };
                6F995A3A1A70833700A735F4 /* JSWebGLVertexArrayObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 6F995A301A70833700A735F4 /* JSWebGLVertexArrayObject.h */; };
                6FA4454E898F2FC168BC38C1 /* JSBeforeUnloadEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 29E04A27BED2F81F98E9022B /* JSBeforeUnloadEvent.h */; };
-               6FFDC442212EFF1700A9CA91 /* FloatBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FFDC440212EFF1600A9CA91 /* FloatBox.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               6FFDC442212EFF1700A9CA91 /* FloatAvoider.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FFDC440212EFF1600A9CA91 /* FloatAvoider.h */; settings = {ATTRIBUTES = (Private, ); }; };
                709A01FE1E3D0BDD006B0D4C /* ModuleFetchFailureKind.h in Headers */ = {isa = PBXBuildFile; fileRef = 709A01FD1E3D0BCC006B0D4C /* ModuleFetchFailureKind.h */; settings = {ATTRIBUTES = (Private, ); }; };
                71025ECD1F99F0CE004A250C /* AnimationTimeline.h in Headers */ = {isa = PBXBuildFile; fileRef = 71025EC71F99F096004A250C /* AnimationTimeline.h */; settings = {ATTRIBUTES = (Private, ); }; };
                71025ED01F99F0CE004A250C /* DocumentTimeline.h in Headers */ = {isa = PBXBuildFile; fileRef = 71025EC51F99F096004A250C /* DocumentTimeline.h */; settings = {ATTRIBUTES = (Private, ); }; };
                6FCD19C120F9727A00FD4529 /* TextContentProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TextContentProvider.h; sourceTree = "<group>"; };
                6FCD19C720F9727D00FD4529 /* TextContentProvider.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TextContentProvider.cpp; sourceTree = "<group>"; };
                6FCF975220F02B3500214960 /* Runs.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Runs.h; sourceTree = "<group>"; };
-               6FFDC43E212EFF1600A9CA91 /* FloatBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FloatBox.cpp; sourceTree = "<group>"; };
-               6FFDC440212EFF1600A9CA91 /* FloatBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FloatBox.h; sourceTree = "<group>"; };
+               6FFDC43E212EFF1600A9CA91 /* FloatAvoider.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FloatAvoider.cpp; sourceTree = "<group>"; };
+               6FFDC440212EFF1600A9CA91 /* FloatAvoider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FloatAvoider.h; sourceTree = "<group>"; };
                709A01FD1E3D0BCC006B0D4C /* ModuleFetchFailureKind.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ModuleFetchFailureKind.h; sourceTree = "<group>"; };
                71004B9D1DC1398800A52A38 /* playback-support.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = "playback-support.js"; sourceTree = "<group>"; };
                71025EC21F99F096004A250C /* WebAnimation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebAnimation.h; sourceTree = "<group>"; };
                6FCFC055212DACC2007695D2 /* floats */ = {
                        isa = PBXGroup;
                        children = (
-                               6FFDC43E212EFF1600A9CA91 /* FloatBox.cpp */,
-                               6FFDC440212EFF1600A9CA91 /* FloatBox.h */,
+                               6FFDC43E212EFF1600A9CA91 /* FloatAvoider.cpp */,
+                               6FFDC440212EFF1600A9CA91 /* FloatAvoider.h */,
                                115CFA85208B9066001E6991 /* FloatingContext.cpp */,
                                115CFA84208B9066001E6991 /* FloatingContext.h */,
                                115CFA81208B8EDA001E6991 /* FloatingState.cpp */,
                                49ECEB701499790D00CDD3A4 /* FilterOperations.h in Headers */,
                                372C00D9129619F8005C9575 /* FindOptions.h in Headers */,
                                A8CFF04F0A154F09000A4234 /* FixedTableLayout.h in Headers */,
-                               6FFDC442212EFF1700A9CA91 /* FloatBox.h in Headers */,
+                               6FFDC442212EFF1700A9CA91 /* FloatAvoider.h in Headers */,
                                BC073BAA0C399B1F000F5979 /* FloatConversion.h in Headers */,
                                115CFA86208B9066001E6991 /* FloatingContext.h in Headers */,
                                9A528E8417D7F52F00AA9518 /* FloatingObjects.h in Headers */,
index 22851f7..c945b44 100644 (file)
@@ -36,7 +36,7 @@ namespace WebCore {
 class RenderStyle;
 
 namespace Layout {
-class FloatBox;
+class FloatAvoider;
 class BlockFormattingContext;
 class FormattingContext;
 class FloatingContext;
@@ -48,7 +48,7 @@ namespace Display {
 class Box {
     WTF_MAKE_ISO_ALLOCATED(Box);
 public:
-    friend class Layout::FloatBox;
+    friend class Layout::FloatAvoider;
     friend class Layout::BlockFormattingContext;
     friend class Layout::FormattingContext;
     friend class Layout::FloatingContext;
similarity index 89%
rename from Source/WebCore/layout/floats/FloatBox.cpp
rename to Source/WebCore/layout/floats/FloatAvoider.cpp
index a3815b7..16b9375 100644 (file)
@@ -24,7 +24,7 @@
  */
 
 #include "config.h"
-#include "FloatBox.h"
+#include "FloatAvoider.h"
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
@@ -36,9 +36,9 @@
 namespace WebCore {
 namespace Layout {
 
-WTF_MAKE_ISO_ALLOCATED_IMPL(FloatBox);
+WTF_MAKE_ISO_ALLOCATED_IMPL(FloatAvoider);
 
-FloatBox::FloatBox(const Box& layoutBox, const FloatingState& floatingState, const LayoutContext& layoutContext)
+FloatAvoider::FloatAvoider(const Box& layoutBox, const FloatingState& floatingState, const LayoutContext& layoutContext)
     : m_layoutBox(makeWeakPtr(const_cast<Box&>(layoutBox)))
     , m_floatingState(floatingState)
     , m_absoluteDisplayBox(FormattingContext::mapBoxToAncestor(layoutContext, layoutBox, downcast<Container>(floatingState.root())))
@@ -47,18 +47,18 @@ FloatBox::FloatBox(const Box& layoutBox, const FloatingState& floatingState, con
     initializePosition();
 }
 
-void FloatBox::initializePosition()
+void FloatAvoider::initializePosition()
 {
     resetVertically();
     resetHorizontally();
 }
 
-bool FloatBox::isLeftAligned() const
+bool FloatAvoider::isLeftAligned() const
 {
     return m_layoutBox->isLeftFloatingPositioned();
 }
 
-void FloatBox::setLeft(PositionInContextRoot left)
+void FloatAvoider::setLeft(PositionInContextRoot left)
 {
     // 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.
@@ -74,13 +74,13 @@ void FloatBox::setLeft(PositionInContextRoot left)
     m_absoluteDisplayBox.setLeft(left);
 }
 
-void FloatBox::setTopLeft(PointInContextRoot topLeft)
+void FloatAvoider::setTopLeft(PointInContextRoot topLeft)
 {
     setTop(topLeft.y);
     setLeft(topLeft.x);
 }
 
-void FloatBox::resetVertically()
+void FloatAvoider::resetVertically()
 {
     // 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.
@@ -92,7 +92,7 @@ void FloatBox::resetVertically()
     m_absoluteDisplayBox.setTop(top);
 }
 
-void FloatBox::resetHorizontally()
+void FloatAvoider::resetHorizontally()
 {
     // Align the box with the containing block's content box.
     auto containingBlockContentBoxLeft = m_containingBlockAbsoluteDisplayBox.left() + m_containingBlockAbsoluteDisplayBox.contentBoxLeft();
@@ -104,7 +104,7 @@ void FloatBox::resetHorizontally()
     m_absoluteDisplayBox.setLeft(left);
 }
 
-PointInContainingBlock FloatBox::topLeftInContainingBlock() const
+PointInContainingBlock FloatAvoider::topLeftInContainingBlock() const
 {
     // From formatting root coordinate system back to containing block's.
     if (m_layoutBox->containingBlock() == &m_floatingState.root())
similarity index 95%
rename from Source/WebCore/layout/floats/FloatBox.h
rename to Source/WebCore/layout/floats/FloatAvoider.h
index 9ba6f90..305f4a6 100644 (file)
@@ -40,10 +40,10 @@ class Box;
 class FloatingState;
 class LayoutContext;
 
-class FloatBox {
-    WTF_MAKE_ISO_ALLOCATED(FloatBox);
+class FloatAvoider {
+    WTF_MAKE_ISO_ALLOCATED(FloatAvoider);
 public:
-    FloatBox(const Box&, const FloatingState&, const LayoutContext&);
+    FloatAvoider(const Box&, const FloatingState&, const LayoutContext&);
 
     PositionInContextRoot top() const { return m_absoluteDisplayBox.top(); }
     PositionInContextRoot left() const { return m_absoluteDisplayBox.left(); }
index e6d5847..72f9d77 100644 (file)
@@ -29,7 +29,7 @@
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
 #include "DisplayBox.h"
-#include "FloatBox.h"
+#include "FloatAvoider.h"
 #include "LayoutBox.h"
 #include "LayoutContainer.h"
 #include "LayoutContext.h"
@@ -137,7 +137,7 @@ PointInContainingBlock FloatingContext::positionForFloat(const Box& layoutBox) c
     }
 
     // Find the top most position where the float box fits.
-    FloatBox alignedBox = { layoutBox, m_floatingState, layoutContext() };
+    FloatAvoider alignedBox = { layoutBox, m_floatingState, layoutContext() };
     floatingPosition(alignedBox);
     return alignedBox.topLeftInContainingBlock();
 }
@@ -213,28 +213,28 @@ std::optional<PositionInContainingBlock> FloatingContext::verticalPositionWithCl
     return { };
 }
 
-void FloatingContext::floatingPosition(FloatBox& floatBox) const
+void FloatingContext::floatingPosition(FloatAvoider& floatAvoider) const
 {
     std::optional<PositionInContextRoot> bottomMost;
-    auto initialLeft = floatBox.left();
+    auto initialLeft = floatAvoider.left();
     auto end = Layout::end(m_floatingState);
-    for (auto iterator = begin(m_floatingState, floatBox.rectWithMargin().top()); iterator != end; ++iterator) {
+    for (auto iterator = begin(m_floatingState, floatAvoider.rectWithMargin().top()); iterator != end; ++iterator) {
         ASSERT(!(*iterator).isEmpty());
         auto floats = *iterator;
 
-        floatBox.setTop(floats.verticalPosition() + floatBox.marginTop());
+        floatAvoider.setTop(floats.verticalPosition() + floatAvoider.marginTop());
         // Move the box horizontally so that it either
         // 1. aligns with the current floating pair
         // 2. or with the containing block's content box if there's no float to align with at this vertical position.
-        if (auto horiztonalPosition = floats.horiztonalPosition(floatBox.isLeftAligned() ? Float::Left : Float::Right)) {
-            if (!floatBox.isLeftAligned())
-                horiztonalPosition = *horiztonalPosition - floatBox.rectWithMargin().width();
-            floatBox.setLeft(*horiztonalPosition + floatBox.marginLeft());
+        if (auto horiztonalPosition = floats.horiztonalPosition(floatAvoider.isLeftAligned() ? Float::Left : Float::Right)) {
+            if (!floatAvoider.isLeftAligned())
+                horiztonalPosition = *horiztonalPosition - floatAvoider.rectWithMargin().width();
+            floatAvoider.setLeft(*horiztonalPosition + floatAvoider.marginLeft());
         } else
-            floatBox.resetHorizontally();
+            floatAvoider.resetHorizontally();
 
         // Check if the box fits at this position.
-        if (!floats.intersects(floatBox.rectWithMargin()))
+        if (!floats.intersects(floatAvoider.rectWithMargin()))
             return;
 
         bottomMost = floats.bottom();
@@ -246,7 +246,7 @@ void FloatingContext::floatingPosition(FloatBox& floatBox) const
         return;
 
     // Passed all the floats and still does not fit? Push it below the last float.
-    floatBox.setTopLeft({ initialLeft, *bottomMost + floatBox.marginTop() });
+    floatAvoider.setTopLeft({ initialLeft, *bottomMost + floatAvoider.marginTop() });
 }
 
 FloatingPair::FloatingPair(const FloatingState::FloatList& floats)
index 9988e5b..d28df59 100644 (file)
@@ -35,7 +35,7 @@ namespace WebCore {
 
 namespace Layout {
 
-class FloatBox;
+class FloatAvoider;
 class Box;
 class Container;
 class FloatingPair;
@@ -56,7 +56,7 @@ public:
 private:
     LayoutContext& layoutContext() const { return m_floatingState.layoutContext(); }
 
-    void floatingPosition(FloatBox&) const;
+    void floatingPosition(FloatAvoider&) const;
 
     FloatingState& m_floatingState;
 };