[LFC][Floating] Align new floating with the bottom of the existing floatings.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Aug 2018 20:52:04 +0000 (20:52 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Aug 2018 20:52:04 +0000 (20:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=188213

Reviewed by Antti Koivisto.

When the incoming floating does not fit at all, align its top with the bottom of the existing floatings.

* layout/FloatingContext.cpp:
(WebCore::Layout::FloatingContext::floatingPosition const):
(WebCore::Layout::FloatingPair::bottom const):

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

Source/WebCore/ChangeLog
Source/WebCore/layout/FloatingContext.cpp

index d8cdac9..1bc8ad1 100644 (file)
@@ -1,3 +1,16 @@
+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
+
+        Reviewed by Antti Koivisto.
+
+        When the incoming floating does not fit at all, align its top with the bottom of the existing floatings.
+
+        * layout/FloatingContext.cpp:
+        (WebCore::Layout::FloatingContext::floatingPosition const):
+        (WebCore::Layout::FloatingPair::bottom const):
+
 2018-08-01  Eric Carlson  <eric.carlson@apple.com>
 
         Always use MediaPlayback audio category when playing to AppleTV
index 1859d92..5f83186 100644 (file)
@@ -66,6 +66,7 @@ public:
     const Display::Box* right() const;
     bool intersects(const Display::Box::Rect&) const;
     LayoutUnit verticalPosition() const { return m_verticalPosition; }
+    LayoutUnit bottom() const;
     bool operator==(const FloatingPair&) const;
 
 private:
@@ -132,6 +133,7 @@ Position FloatingContext::floatingPosition(const Box& layoutBox) const
 
     auto end = Layout::end(layoutContext(), m_floatingState);
     auto top = initialVerticalPosition;
+    auto bottomMost = top;
     for (auto iterator = begin(layoutContext(), m_floatingState, initialVerticalPosition); iterator != end; ++iterator) {
         ASSERT(!(*iterator).isEmpty());
 
@@ -144,11 +146,12 @@ Position FloatingContext::floatingPosition(const Box& layoutBox) const
         if (!floatings.intersects({ top, left, boxSize.width(), boxSize.height() }))
             return { left, top };
 
+        bottomMost = floatings.bottom();
         // Move to the next floating pair.
     }
 
     // Passed all the floatings and still does not fit? 
-    return { alignWithContainingBlock(layoutBox), top };
+    return { alignWithContainingBlock(layoutBox), bottomMost };
 }
 
 LayoutUnit FloatingContext::initialVerticalPosition(const Box& layoutBox) const
@@ -264,6 +267,24 @@ bool FloatingPair::operator ==(const FloatingPair& other) const
     return m_leftIndex == other.m_leftIndex && m_rightIndex == other.m_rightIndex;
 }
 
+LayoutUnit FloatingPair::bottom() const
+{
+    auto* left = this->left();
+    auto* right = this->right();
+    ASSERT(left || right);
+
+    auto leftBottom = left ? std::optional<LayoutUnit>(left->bottom()) : std::nullopt;
+    auto rightBottom = right ? std::optional<LayoutUnit>(right->bottom()) : std::nullopt;
+
+    if (leftBottom && rightBottom)
+        return std::max(*leftBottom, *rightBottom);
+
+    if (leftBottom)
+        return *leftBottom;
+
+    return *rightBottom;
+}
+
 Iterator::Iterator(const LayoutContext& layoutContext, const FloatingState& floatingState, std::optional<LayoutUnit> verticalPosition)
     : m_layoutContext(layoutContext)
     , m_floatingState(floatingState)