- Revision
- 235350
- Author
- [email protected]
- Date
- 2018-08-26 21:03:25 -0700 (Sun, 26 Aug 2018)
Log Message
[LFC][Floating] Simplify FloatingState::FloatItem class
https://bugs.webkit.org/show_bug.cgi?id=188912
Reviewed by Antti Koivisto.
Let's remove some redundant code now that FloatingState::FloatItem is not used for incoming floats anymore.
* layout/Verification.cpp:
(WebCore::Layout::LayoutContext::verifyAndOutputMismatchingLayoutTree const):
* layout/floats/FloatBox.cpp:
(WebCore::Layout::FloatBox::resetVertically):
* layout/floats/FloatingContext.cpp:
(WebCore::Layout::FloatingPair::left const):
(WebCore::Layout::FloatingPair::right const):
(WebCore::Layout::FloatingPair::intersects const):
(WebCore::Layout::previousFloatingIndex):
(WebCore::Layout::Iterator::operator++):
(WebCore::Layout::Iterator::set):
* layout/floats/FloatingState.cpp:
(WebCore::Layout::FloatingState::FloatItem::FloatItem):
(WebCore::Layout::FloatingState::remove):
(WebCore::Layout::FloatingState::bottom const):
* layout/floats/FloatingState.h:
(WebCore::Layout::FloatingState::FloatItem::operator== const):
(WebCore::Layout::FloatingState::FloatItem::isLeftPositioned const):
(WebCore::Layout::FloatingState::FloatItem::rectWithMargin const):
(WebCore::Layout::FloatingState::FloatItem::bottom const):
(WebCore::Layout::FloatingState::leftBottom const):
(WebCore::Layout::FloatingState::rightBottom const):
(WebCore::Layout::FloatingState::bottom const):
(WebCore::Layout::FloatingState::FloatItem::inFormattingContext const):
(WebCore::Layout::FloatingState::FloatItem::layoutBox const): Deleted.
(WebCore::Layout::FloatingState::FloatItem::containingBlock const): Deleted.
(WebCore::Layout::FloatingState::FloatItem::displayBox const): Deleted.
(WebCore::Layout::FloatingState::FloatItem::containingBlockDisplayBox const): Deleted.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (235349 => 235350)
--- trunk/Source/WebCore/ChangeLog 2018-08-27 03:32:48 UTC (rev 235349)
+++ trunk/Source/WebCore/ChangeLog 2018-08-27 04:03:25 UTC (rev 235350)
@@ -1,3 +1,41 @@
+2018-08-26 Zalan Bujtas <[email protected]>
+
+ [LFC][Floating] Simplify FloatingState::FloatItem class
+ https://bugs.webkit.org/show_bug.cgi?id=188912
+
+ Reviewed by Antti Koivisto.
+
+ Let's remove some redundant code now that FloatingState::FloatItem is not used for incoming floats anymore.
+
+ * layout/Verification.cpp:
+ (WebCore::Layout::LayoutContext::verifyAndOutputMismatchingLayoutTree const):
+ * layout/floats/FloatBox.cpp:
+ (WebCore::Layout::FloatBox::resetVertically):
+ * layout/floats/FloatingContext.cpp:
+ (WebCore::Layout::FloatingPair::left const):
+ (WebCore::Layout::FloatingPair::right const):
+ (WebCore::Layout::FloatingPair::intersects const):
+ (WebCore::Layout::previousFloatingIndex):
+ (WebCore::Layout::Iterator::operator++):
+ (WebCore::Layout::Iterator::set):
+ * layout/floats/FloatingState.cpp:
+ (WebCore::Layout::FloatingState::FloatItem::FloatItem):
+ (WebCore::Layout::FloatingState::remove):
+ (WebCore::Layout::FloatingState::bottom const):
+ * layout/floats/FloatingState.h:
+ (WebCore::Layout::FloatingState::FloatItem::operator== const):
+ (WebCore::Layout::FloatingState::FloatItem::isLeftPositioned const):
+ (WebCore::Layout::FloatingState::FloatItem::rectWithMargin const):
+ (WebCore::Layout::FloatingState::FloatItem::bottom const):
+ (WebCore::Layout::FloatingState::leftBottom const):
+ (WebCore::Layout::FloatingState::rightBottom const):
+ (WebCore::Layout::FloatingState::bottom const):
+ (WebCore::Layout::FloatingState::FloatItem::inFormattingContext const):
+ (WebCore::Layout::FloatingState::FloatItem::layoutBox const): Deleted.
+ (WebCore::Layout::FloatingState::FloatItem::containingBlock const): Deleted.
+ (WebCore::Layout::FloatingState::FloatItem::displayBox const): Deleted.
+ (WebCore::Layout::FloatingState::FloatItem::containingBlockDisplayBox const): Deleted.
+
2018-08-26 Andy Estes <[email protected]>
[Apple Pay] Introduce new values for -apple-pay-button-type
Modified: trunk/Source/WebCore/layout/floats/FloatBox.cpp (235349 => 235350)
--- trunk/Source/WebCore/layout/floats/FloatBox.cpp 2018-08-27 03:32:48 UTC (rev 235349)
+++ trunk/Source/WebCore/layout/floats/FloatBox.cpp 2018-08-27 04:03:25 UTC (rev 235350)
@@ -86,7 +86,7 @@
// Take the static position (where the box would go if it wasn't floating) and adjust it with the last float.
auto top = m_absoluteDisplayBox.rectWithMargin().top();
if (auto lastFloat = m_floatingState.last())
- top = std::max(top, lastFloat->displayBox().rectWithMargin().top());
+ top = std::max(top, lastFloat->rectWithMargin().top());
top += m_absoluteDisplayBox.marginTop();
m_absoluteDisplayBox.setTop(top);
Modified: trunk/Source/WebCore/layout/floats/FloatingContext.cpp (235349 => 235350)
--- trunk/Source/WebCore/layout/floats/FloatingContext.cpp 2018-08-27 03:32:48 UTC (rev 235349)
+++ trunk/Source/WebCore/layout/floats/FloatingContext.cpp 2018-08-27 04:03:25 UTC (rev 235350)
@@ -64,8 +64,8 @@
class FloatingPair {
public:
bool isEmpty() const { return !m_leftIndex && !m_rightIndex; }
- const Display::Box* left() const;
- const Display::Box* right() const;
+ const FloatingState::FloatItem* left() const;
+ const FloatingState::FloatItem* right() const;
bool intersects(const Display::Box::Rect&) const;
PositionInContextRoot verticalPosition() const { return m_verticalPosition; }
std::optional<PositionInContextRoot> horiztonalPosition(Float) const;
@@ -254,27 +254,27 @@
{
}
-const Display::Box* FloatingPair::left() const
+const FloatingState::FloatItem* FloatingPair::left() const
{
if (!m_leftIndex)
return nullptr;
- ASSERT(m_floats[*m_leftIndex].layoutBox().isLeftFloatingPositioned());
- return &m_floats[*m_leftIndex].displayBox();
+ ASSERT(m_floats[*m_leftIndex].isLeftPositioned());
+ return &m_floats[*m_leftIndex];
}
-const Display::Box* FloatingPair::right() const
+const FloatingState::FloatItem* FloatingPair::right() const
{
if (!m_rightIndex)
return nullptr;
- ASSERT(m_floats[*m_rightIndex].layoutBox().isRightFloatingPositioned());
- return &m_floats[*m_rightIndex].displayBox();
+ ASSERT(!m_floats[*m_rightIndex].isLeftPositioned());
+ return &m_floats[*m_rightIndex];
}
bool FloatingPair::intersects(const Display::Box::Rect& candidateRect) const
{
- auto intersects = [&](const Display::Box* floating, Float floatingType) {
+ auto intersects = [&](const FloatingState::FloatItem* floating, Float floatingType) {
if (!floating)
return false;
@@ -348,8 +348,8 @@
RELEASE_ASSERT(currentIndex <= floats.size());
while (currentIndex) {
- auto& floating = floats[--currentIndex].layoutBox();
- if ((floatingType == Float::Left && floating.isLeftFloatingPositioned()) || (floatingType == Float::Right && floating.isRightFloatingPositioned()))
+ auto& floating = floats[--currentIndex];
+ if ((floatingType == Float::Left && floating.isLeftPositioned()) || (floatingType == Float::Right && !floating.isLeftPositioned()))
return currentIndex;
}
@@ -371,7 +371,7 @@
if (!currentIndex)
return { };
- auto currentBottom = m_floats[currentIndex].displayBox().rectWithMargin().bottom();
+ auto currentBottom = m_floats[currentIndex].rectWithMargin().bottom();
std::optional<unsigned> index = currentIndex;
while (true) {
@@ -379,7 +379,7 @@
if (!index)
return { };
- if (m_floats[*index].displayBox().rectWithMargin().bottom() > currentBottom)
+ if (m_floats[*index].rectWithMargin().bottom() > currentBottom)
return index;
}
@@ -443,7 +443,7 @@
if (!index)
return { };
- auto bottom = m_floats[*index].displayBox().rectWithMargin().bottom();
+ auto bottom = m_floats[*index].rectWithMargin().bottom();
// Is this floating intrusive on this position?
if (bottom > verticalPosition)
return index;
@@ -455,8 +455,8 @@
m_current.m_leftIndex = findFloatingBelow(Float::Left);
m_current.m_rightIndex = findFloatingBelow(Float::Right);
- ASSERT(!m_current.m_leftIndex || (*m_current.m_leftIndex < m_floats.size() && m_floats[*m_current.m_leftIndex].layoutBox().isLeftFloatingPositioned()));
- ASSERT(!m_current.m_rightIndex || (*m_current.m_rightIndex < m_floats.size() && m_floats[*m_current.m_rightIndex].layoutBox().isRightFloatingPositioned()));
+ ASSERT(!m_current.m_leftIndex || (*m_current.m_leftIndex < m_floats.size() && m_floats[*m_current.m_leftIndex].isLeftPositioned()));
+ ASSERT(!m_current.m_rightIndex || (*m_current.m_rightIndex < m_floats.size() && !m_floats[*m_current.m_rightIndex].isLeftPositioned()));
}
bool Iterator::operator==(const Iterator& other) const
Modified: trunk/Source/WebCore/layout/floats/FloatingState.cpp (235349 => 235350)
--- trunk/Source/WebCore/layout/floats/FloatingState.cpp 2018-08-27 03:32:48 UTC (rev 235349)
+++ trunk/Source/WebCore/layout/floats/FloatingState.cpp 2018-08-27 04:03:25 UTC (rev 235350)
@@ -41,9 +41,7 @@
FloatingState::FloatItem::FloatItem(const Box& layoutBox, const FloatingState& floatingState)
: m_layoutBox(makeWeakPtr(const_cast<Box&>(layoutBox)))
- , m_containingBlock(makeWeakPtr(const_cast<Container&>(*layoutBox.containingBlock())))
, m_absoluteDisplayBox(FormattingContext::mapBoxToAncestor(floatingState.layoutContext(), layoutBox, downcast<Container>(floatingState.root())))
- , m_containingBlockAbsoluteDisplayBox(FormattingContext::mapBoxToAncestor(floatingState.layoutContext(), *m_containingBlock, downcast<Container>(floatingState.root())))
{
}
@@ -71,7 +69,7 @@
void FloatingState::remove(const Box& layoutBox)
{
for (size_t index = 0; index < m_floats.size(); ++index) {
- if (&m_floats[index].layoutBox() == &layoutBox) {
+ if (m_floats[index] == layoutBox) {
m_floats.remove(index);
return;
}
@@ -101,14 +99,14 @@
std::optional<LayoutUnit> bottom;
for (auto& floatItem : m_floats) {
// Ignore floats from other formatting contexts when the floating state is inherited.
- if (&formattingContextRoot != &floatItem.layoutBox().formattingContextRoot())
+ if (!floatItem.inFormattingContext(formattingContextRoot))
continue;
- if ((type == Clear::Left && !floatItem.layoutBox().isLeftFloatingPositioned())
- || (type == Clear::Right && !floatItem.layoutBox().isRightFloatingPositioned()))
+ if ((type == Clear::Left && !floatItem.isLeftPositioned())
+ || (type == Clear::Right && floatItem.isLeftPositioned()))
continue;
- auto floatsBottom = floatItem.displayBox().rectWithMargin().bottom();
+ auto floatsBottom = floatItem.rectWithMargin().bottom();
if (bottom) {
bottom = std::max(*bottom, floatsBottom);
continue;
Modified: trunk/Source/WebCore/layout/floats/FloatingState.h (235349 => 235350)
--- trunk/Source/WebCore/layout/floats/FloatingState.h 2018-08-27 03:32:48 UTC (rev 235349)
+++ trunk/Source/WebCore/layout/floats/FloatingState.h 2018-08-27 04:03:25 UTC (rev 235350)
@@ -28,6 +28,8 @@
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
#include "DisplayBox.h"
+#include "LayoutBox.h"
+#include "LayoutContainer.h"
#include <wtf/IsoMalloc.h>
#include <wtf/Ref.h>
#include <wtf/WeakPtr.h>
@@ -36,8 +38,6 @@
namespace Layout {
-class Box;
-class Container;
class FormattingState;
class LayoutContext;
@@ -62,18 +62,17 @@
public:
FloatItem(const Box&, const FloatingState&);
- const Box& layoutBox() const { return *m_layoutBox; }
- const Container& containingBlock() const { return *m_containingBlock; }
+ bool operator==(const Box& layoutBox) const { return m_layoutBox.get() == &layoutBox; }
- const Display::Box& displayBox() const { return m_absoluteDisplayBox; }
- const Display::Box& containingBlockDisplayBox() const { return m_containingBlockAbsoluteDisplayBox; }
+ bool isLeftPositioned() const { return m_layoutBox->isLeftFloatingPositioned(); }
+ bool inFormattingContext(const Box&) const;
+ Display::Box::Rect rectWithMargin() const { return m_absoluteDisplayBox.rectWithMargin(); }
+ PositionInContextRoot bottom() const { return m_absoluteDisplayBox.bottom(); }
+
private:
WeakPtr<Box> m_layoutBox;
- WeakPtr<Container> m_containingBlock;
-
Display::Box m_absoluteDisplayBox;
- Display::Box m_containingBlockAbsoluteDisplayBox;
};
using FloatList = Vector<FloatItem>;
const FloatList& floats() const { return m_floats; }
@@ -94,19 +93,28 @@
inline std::optional<LayoutUnit> FloatingState::leftBottom(const Box& formattingContextRoot) const
{
+ ASSERT(formattingContextRoot.establishesFormattingContext());
return bottom(formattingContextRoot, Clear::Left);
}
inline std::optional<LayoutUnit> FloatingState::rightBottom(const Box& formattingContextRoot) const
{
+ ASSERT(formattingContextRoot.establishesFormattingContext());
return bottom(formattingContextRoot, Clear::Right);
}
inline std::optional<LayoutUnit> FloatingState::bottom(const Box& formattingContextRoot) const
{
+ ASSERT(formattingContextRoot.establishesFormattingContext());
return bottom(formattingContextRoot, Clear::Both);
}
+inline bool FloatingState::FloatItem::inFormattingContext(const Box& formattingContextRoot) const
+{
+ ASSERT(formattingContextRoot.establishesFormattingContext());
+ return &m_layoutBox->formattingContextRoot() == &formattingContextRoot;
}
+
}
+}
#endif