WebKit Bugzilla
Attachment 339184 Details for
Bug 185158
: [LFC] Implement LayoutContext::createDisplayBox
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-185158-20180430215428.patch (text/plain), 19.95 KB, created by
zalan
on 2018-04-30 21:54:29 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
zalan
Created:
2018-04-30 21:54:29 PDT
Size:
19.95 KB
patch
obsolete
>Subversion Revision: 231175 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 895e2ef9312b218c2c6b621c7208ec1646ab2b6b..abd57aa532807fd49ae3ef1c3d590bccf708d623 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,47 @@ >+2018-04-30 Zalan Bujtas <zalan@apple.com> >+ >+ [LFC] Implement LayoutContext::createDisplayBox >+ https://bugs.webkit.org/show_bug.cgi?id=185158 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ ...and introduce LayoutPair. >+ >+ * layout/FloatingContext.cpp: >+ (WebCore::Layout::FloatingContext::computePosition): >+ * layout/FloatingContext.h: >+ * layout/FormattingContext.cpp: >+ (WebCore::Layout::FormattingContext::computeStaticPosition const): >+ (WebCore::Layout::FormattingContext::computeInFlowPositionedPosition const): >+ (WebCore::Layout::FormattingContext::computeOutOfFlowPosition const): >+ (WebCore::Layout::FormattingContext::computeWidth const): >+ (WebCore::Layout::FormattingContext::computeHeight const): >+ (WebCore::Layout::FormattingContext::computeOutOfFlowWidth const): >+ (WebCore::Layout::FormattingContext::computeFloatingWidth const): >+ (WebCore::Layout::FormattingContext::computeOutOfFlowHeight const): >+ (WebCore::Layout::FormattingContext::computeFloatingHeight const): >+ * layout/FormattingContext.h: >+ * layout/LayoutContext.cpp: >+ (WebCore::Layout::LayoutContext::createDisplayBox): >+ * layout/LayoutContext.h: >+ (WebCore::Layout::LayoutContext::displayBox const): >+ * layout/blockformatting/BlockFormattingContext.cpp: >+ (WebCore::Layout::BlockFormattingContext::layout const): >+ (WebCore::Layout::BlockFormattingContext::computeStaticPosition const): >+ (WebCore::Layout::BlockFormattingContext::computeInFlowWidth const): >+ (WebCore::Layout::BlockFormattingContext::computeInFlowHeight const): >+ * layout/blockformatting/BlockFormattingContext.h: >+ * layout/displaytree/DisplayBox.h: >+ (WebCore::Display::Box::parent const): >+ (WebCore::Display::Box::nextSibling const): >+ (WebCore::Display::Box::previousSibling const): >+ (WebCore::Display::Box::firstChild const): >+ (WebCore::Display::Box::lastChild const): >+ * layout/inlineformatting/InlineFormattingContext.cpp: >+ (WebCore::Layout::InlineFormattingContext::computeInFlowWidth const): >+ (WebCore::Layout::InlineFormattingContext::computeInFlowHeight const): >+ * layout/inlineformatting/InlineFormattingContext.h: >+ > 2018-04-30 JF Bastien <jfbastien@apple.com> > > Use some C++17 features >diff --git a/Source/WebCore/layout/FloatingContext.cpp b/Source/WebCore/layout/FloatingContext.cpp >index f7430cda44b495894e6cb138376ff3f409a28e6b..368a32055a3b83706ca6badfe99855abd3c8aa29 100644 >--- a/Source/WebCore/layout/FloatingContext.cpp >+++ b/Source/WebCore/layout/FloatingContext.cpp >@@ -39,7 +39,7 @@ FloatingContext::FloatingContext(FloatingState&) > { > } > >-void FloatingContext::computePosition(const Box&) >+void FloatingContext::computePosition(FormattingContext::LayoutPair&) > { > } > >diff --git a/Source/WebCore/layout/FloatingContext.h b/Source/WebCore/layout/FloatingContext.h >index b45b944efdbdfc94400c89eea29d83313f944861..67e012d6f4632108f89e507c756b5486cc3385cf 100644 >--- a/Source/WebCore/layout/FloatingContext.h >+++ b/Source/WebCore/layout/FloatingContext.h >@@ -27,6 +27,7 @@ > > #if ENABLE(LAYOUT_FORMATTING_CONTEXT) > >+#include "FormattingContext.h" > #include "LayoutUnit.h" > #include <wtf/IsoMalloc.h> > >@@ -44,7 +45,7 @@ class FloatingContext { > public: > FloatingContext(FloatingState&); > >- void computePosition(const Box&); >+ void computePosition(FormattingContext::LayoutPair&); > LayoutUnit left(LayoutUnit verticalPosition); > LayoutUnit right(LayoutUnit verticalPosition); > LayoutUnit bottom(); >diff --git a/Source/WebCore/layout/FormattingContext.cpp b/Source/WebCore/layout/FormattingContext.cpp >index a81fa536178a7d1c3b706608860c1a91e46ed944..44824662d26ba4a11dcedcbfbd774b52c82f171a 100644 >--- a/Source/WebCore/layout/FormattingContext.cpp >+++ b/Source/WebCore/layout/FormattingContext.cpp >@@ -46,49 +46,49 @@ FormattingContext::~FormattingContext() > { > } > >-void FormattingContext::computeStaticPosition(const Box&) const >+void FormattingContext::computeStaticPosition(LayoutPair&) const > { > } > >-void FormattingContext::computeInFlowPositionedPosition(const Box&) const >+void FormattingContext::computeInFlowPositionedPosition(LayoutPair&) const > { > } > >-void FormattingContext::computeOutOfFlowPosition(const Box&) const >+void FormattingContext::computeOutOfFlowPosition(LayoutPair&) const > { > } > >-void FormattingContext::computeWidth(const Box& layoutBox) const >+void FormattingContext::computeWidth(LayoutPair& layoutPair) const > { >- if (layoutBox.isOutOfFlowPositioned()) >- return computeOutOfFlowWidth(layoutBox); >- if (layoutBox.isFloatingPositioned()) >- return computeFloatingWidth(layoutBox); >- return computeInFlowWidth(layoutBox); >+ if (layoutPair.layoutBox.isOutOfFlowPositioned()) >+ return computeOutOfFlowWidth(layoutPair); >+ if (layoutPair.layoutBox.isFloatingPositioned()) >+ return computeFloatingWidth(layoutPair); >+ return computeInFlowWidth(layoutPair); > } > >-void FormattingContext::computeHeight(const Box& layoutBox) const >+void FormattingContext::computeHeight(LayoutPair& layoutPair) const > { >- if (layoutBox.isOutOfFlowPositioned()) >- return computeOutOfFlowHeight(layoutBox); >- if (layoutBox.isFloatingPositioned()) >- return computeFloatingHeight(layoutBox); >- return computeInFlowHeight(layoutBox); >+ if (layoutPair.layoutBox.isOutOfFlowPositioned()) >+ return computeOutOfFlowHeight(layoutPair); >+ if (layoutPair.layoutBox.isFloatingPositioned()) >+ return computeFloatingHeight(layoutPair); >+ return computeInFlowHeight(layoutPair); > } > >-void FormattingContext::computeOutOfFlowWidth(const Box&) const >+void FormattingContext::computeOutOfFlowWidth(LayoutPair&) const > { > } > >-void FormattingContext::computeFloatingWidth(const Box&) const >+void FormattingContext::computeFloatingWidth(LayoutPair&) const > { > } > >-void FormattingContext::computeOutOfFlowHeight(const Box&) const >+void FormattingContext::computeOutOfFlowHeight(LayoutPair&) const > { > } > >-void FormattingContext::computeFloatingHeight(const Box&) const >+void FormattingContext::computeFloatingHeight(LayoutPair&) const > { > } > >diff --git a/Source/WebCore/layout/FormattingContext.h b/Source/WebCore/layout/FormattingContext.h >index 3a4f5704e15e2b21474afdb531ce41acfc918e98..0eebbfaba357abc3f68014abb81979300e85ae1a 100644 >--- a/Source/WebCore/layout/FormattingContext.h >+++ b/Source/WebCore/layout/FormattingContext.h >@@ -34,6 +34,10 @@ > > namespace WebCore { > >+namespace Display { >+class Box; >+} >+ > namespace Layout { > > class Box; >@@ -51,24 +55,31 @@ public: > virtual std::unique_ptr<FormattingState> createFormattingState(Ref<FloatingState>&&) const = 0; > virtual Ref<FloatingState> createOrFindFloatingState() const = 0; > >+ struct LayoutPair { >+ const Box& layoutBox; >+ Display::Box& displayBox; >+ }; >+ > protected: >+ using LayoutQueue = Vector<std::unique_ptr<LayoutPair>>; >+ > const Box& root() const { return *m_root; } > const LayoutContext& layoutContext() const { return m_layoutContext; } > >- virtual void computeStaticPosition(const Box&) const; >- virtual void computeInFlowPositionedPosition(const Box&) const; >- virtual void computeOutOfFlowPosition(const Box&) const; >+ virtual void computeStaticPosition(LayoutPair&) const; >+ virtual void computeInFlowPositionedPosition(LayoutPair&) const; >+ virtual void computeOutOfFlowPosition(LayoutPair&) const; > >- virtual void computeWidth(const Box&) const; >- virtual void computeHeight(const Box&) const; >+ virtual void computeWidth(LayoutPair&) const; >+ virtual void computeHeight(LayoutPair&) const; > >- virtual void computeOutOfFlowWidth(const Box&) const; >- virtual void computeFloatingWidth(const Box&) const; >- virtual void computeInFlowWidth(const Box&) const = 0; >+ virtual void computeOutOfFlowWidth(LayoutPair&) const; >+ virtual void computeFloatingWidth(LayoutPair&) const; >+ virtual void computeInFlowWidth(LayoutPair&) const = 0; > >- virtual void computeOutOfFlowHeight(const Box&) const; >- virtual void computeFloatingHeight(const Box&) const; >- virtual void computeInFlowHeight(const Box&) const = 0; >+ virtual void computeOutOfFlowHeight(LayoutPair&) const; >+ virtual void computeFloatingHeight(LayoutPair&) const; >+ virtual void computeInFlowHeight(LayoutPair&) const = 0; > > virtual LayoutUnit marginTop(const Box&) const; > virtual LayoutUnit marginLeft(const Box&) const; >diff --git a/Source/WebCore/layout/LayoutContext.cpp b/Source/WebCore/layout/LayoutContext.cpp >index 9c2d4b71f9015956c79b04e87cb9870727f29569..d4f8ab0980e846c5383f00918a04796411e449ec 100644 >--- a/Source/WebCore/layout/LayoutContext.cpp >+++ b/Source/WebCore/layout/LayoutContext.cpp >@@ -30,6 +30,7 @@ > > #include "BlockFormattingContext.h" > #include "BlockFormattingState.h" >+#include "DisplayBox.h" > #include "InlineFormattingContext.h" > #include "InlineFormattingState.h" > #include "LayoutBox.h" >@@ -53,6 +54,28 @@ void LayoutContext::updateLayout() > context->layout(*this, state); > } > >+Display::Box& LayoutContext::createDisplayBox(const Box& layoutBox) >+{ >+ auto* parentLayoutBox = layoutBox.parent(); >+ RELEASE_ASSERT(parentLayoutBox); >+ auto* parentDisplayBox = this->displayBox(*parentLayoutBox); >+ RELEASE_ASSERT(parentDisplayBox); >+ >+ auto* displayBox = new Display::Box(); >+ displayBox->setParent(*parentDisplayBox); >+ if (!parentDisplayBox->firstChild()) { >+ parentDisplayBox->setFirstChild(*displayBox); >+ parentDisplayBox->setLastChild(*displayBox); >+ } else { >+ auto* previousSibling = parentDisplayBox->lastChild(); >+ displayBox->setPreviousSibling(*previousSibling); >+ previousSibling->setNextSibling(*displayBox); >+ parentDisplayBox->setLastChild(*displayBox); >+ } >+ m_layoutToDisplayBox.add(&layoutBox, displayBox); >+ return *displayBox; >+} >+ > FormattingState& LayoutContext::formattingStateForBox(const Box& layoutBox) const > { > auto& root = layoutBox.formattingContextRoot(); >diff --git a/Source/WebCore/layout/LayoutContext.h b/Source/WebCore/layout/LayoutContext.h >index a99b15f7f89476cd19cbbe5a55f3215268f784a4..594edf57f4d55ac6fc6aab55f52cbc220833c2df 100644 >--- a/Source/WebCore/layout/LayoutContext.h >+++ b/Source/WebCore/layout/LayoutContext.h >@@ -54,8 +54,8 @@ public: > > void updateLayout(); > >- void addDisplayBox(const Box&, Display::Box&); >- Display::Box* displayBox(const Box&) const; >+ Display::Box& createDisplayBox(const Box&); >+ Display::Box* displayBox(const Box& layoutBox) const { return m_layoutToDisplayBox.get(&layoutBox); } > > void markNeedsLayout(const Box&, StyleDiff); > bool needsLayout(const Box&) const; >@@ -67,6 +67,7 @@ public: > private: > WeakPtr<Box> m_root; > HashMap<const Box*, std::unique_ptr<FormattingState>> m_formattingStates; >+ HashMap<const Box*, Display::Box*> m_layoutToDisplayBox; > }; > > } >diff --git a/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp b/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp >index 080942667ff571ac713a4b3d2cbea5709442e92c..885736f48d0e3ef814bec673a146d5e6a9532128 100644 >--- a/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp >+++ b/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp >@@ -55,12 +55,12 @@ void BlockFormattingContext::layout(LayoutContext& layoutContext, FormattingStat > if (!is<Container>(root())) > return; > auto& formattingRoot = downcast<Container>(root()); >- Vector<const Box*> layoutQueue; >+ LayoutQueue layoutQueue; > FloatingContext floatingContext(formattingState.floatingState()); > // This is a post-order tree traversal layout. > // The root container layout is done in the formatting context it lives in, not that one it creates, so let's start with the first child. >- if (formattingRoot.hasInFlowOrFloatingChild()) >- layoutQueue.append(formattingRoot.firstInFlowOrFloatingChild()); >+ if (auto* firstChild = formattingRoot.firstInFlowOrFloatingChild()) >+ layoutQueue.append(std::make_unique<LayoutPair>(LayoutPair {*firstChild, layoutContext.createDisplayBox(*firstChild)})); > // 1. Go all the way down to the leaf node > // 2. Compute static position and width as we traverse down > // 3. As we climb back on the tree, compute height and finialize position >@@ -68,9 +68,10 @@ void BlockFormattingContext::layout(LayoutContext& layoutContext, FormattingStat > while (!layoutQueue.isEmpty()) { > // Traverse down on the descendants and compute width/static position until we find a leaf node. > while (true) { >- auto& layoutBox = *layoutQueue.last(); >- computeWidth(layoutBox); >- computeStaticPosition(layoutBox); >+ auto& layoutPair = *layoutQueue.last(); >+ computeWidth(layoutPair); >+ computeStaticPosition(layoutPair); >+ auto& layoutBox = layoutPair.layoutBox; > if (layoutBox.establishesFormattingContext()) { > auto formattingContext = layoutContext.formattingContext(layoutBox); > formattingContext->layout(layoutContext, layoutContext.establishedFormattingState(layoutBox, *formattingContext)); >@@ -78,23 +79,25 @@ void BlockFormattingContext::layout(LayoutContext& layoutContext, FormattingStat > } > if (!is<Container>(layoutBox) || !downcast<Container>(layoutBox).hasInFlowOrFloatingChild()) > break; >- layoutQueue.append(downcast<Container>(layoutBox).firstInFlowOrFloatingChild()); >+ auto& firstChild = *downcast<Container>(layoutBox).firstInFlowOrFloatingChild(); >+ layoutQueue.append(std::make_unique<LayoutPair>(LayoutPair {firstChild, layoutContext.createDisplayBox(firstChild)})); > } > > // Climb back on the ancestors and compute height/final position. > while (!layoutQueue.isEmpty()) { > // All inflow descendants (if there are any) are laid out by now. Let's compute the box's height. >- auto& layoutBox = *layoutQueue.takeLast(); >- computeHeight(layoutBox); >+ auto& layoutPair = *layoutQueue.takeLast(); >+ computeHeight(layoutPair); > // Adjust position now that we have all the previous floats placed in this context -if needed. >- floatingContext.computePosition(layoutBox); >+ floatingContext.computePosition(layoutPair); >+ auto& layoutBox = layoutPair.layoutBox; > if (!is<Container>(layoutBox)) > continue; > auto& container = downcast<Container>(layoutBox); > // Move in-flow positioned children to their final position. > placeInFlowPositionedChildren(container); > if (auto* nextSibling = container.nextInFlowOrFloatingSibling()) { >- layoutQueue.append(nextSibling); >+ layoutQueue.append(std::make_unique<LayoutPair>(LayoutPair {*nextSibling, layoutContext.createDisplayBox(*nextSibling)})); > break; > } > } >@@ -116,15 +119,15 @@ Ref<FloatingState> BlockFormattingContext::createOrFindFloatingState() const > return FloatingState::create(); > } > >-void BlockFormattingContext::computeStaticPosition(const Box&) const >+void BlockFormattingContext::computeStaticPosition(LayoutPair&) const > { > } > >-void BlockFormattingContext::computeInFlowWidth(const Box&) const >+void BlockFormattingContext::computeInFlowWidth(LayoutPair&) const > { > } > >-void BlockFormattingContext::computeInFlowHeight(const Box&) const >+void BlockFormattingContext::computeInFlowHeight(LayoutPair&) const > { > } > >diff --git a/Source/WebCore/layout/blockformatting/BlockFormattingContext.h b/Source/WebCore/layout/blockformatting/BlockFormattingContext.h >index efbac24373a57b8dd0926cd91c511c613016e638..2757ec3cf64b5a482702bfe0bb7c731e434e2f35 100644 >--- a/Source/WebCore/layout/blockformatting/BlockFormattingContext.h >+++ b/Source/WebCore/layout/blockformatting/BlockFormattingContext.h >@@ -50,9 +50,9 @@ public: > Ref<FloatingState> createOrFindFloatingState() const override; > > protected: >- void computeStaticPosition(const Box&) const override; >- void computeInFlowWidth(const Box&) const override; >- void computeInFlowHeight(const Box&) const override; >+ void computeStaticPosition(LayoutPair&) const override; >+ void computeInFlowWidth(LayoutPair&) const override; >+ void computeInFlowHeight(LayoutPair&) const override; > > LayoutUnit marginTop(const Box&) const override; > LayoutUnit marginBottom(const Box&) const override; >diff --git a/Source/WebCore/layout/displaytree/DisplayBox.h b/Source/WebCore/layout/displaytree/DisplayBox.h >index e9d429f8ac99444898e4128ad56ad1dfe00b0c69..4abba9b5370f22e7943c9cb84b78e1686e79823e 100644 >--- a/Source/WebCore/layout/displaytree/DisplayBox.h >+++ b/Source/WebCore/layout/displaytree/DisplayBox.h >@@ -33,12 +33,17 @@ > #include <wtf/IsoMalloc.h> > > namespace WebCore { >+ >+namespace Layout { >+class LayoutContext; >+} >+ > namespace Display { > > class Box { > WTF_MAKE_ISO_ALLOCATED(Box); > public: >- friend class FormattingContext; >+ friend class Layout::LayoutContext; > > ~Box(); > >@@ -66,11 +71,11 @@ public: > LayoutRect paddingBox() const; > LayoutRect contentBox() const; > >- const Box* parent() const { return m_parent; } >- const Box* nextSibling() const { return m_parent; } >- const Box* previousSibling() const { return m_parent; } >- const Box* firstChild() const { return m_firstChild; } >- const Box* lastChild() const { return m_lastChild; } >+ Box* parent() const { return m_parent; } >+ Box* nextSibling() const { return m_parent; } >+ Box* previousSibling() const { return m_parent; } >+ Box* firstChild() const { return m_firstChild; } >+ Box* lastChild() const { return m_lastChild; } > > private: > Box(); >@@ -120,11 +125,11 @@ private: > LayoutUnit m_paddingBottom; > LayoutUnit m_paddingRight; > >- const Box* m_parent { nullptr }; >- const Box* m_nextSibling { nullptr }; >- const Box* m_previousSibling { nullptr }; >- const Box* m_firstChild { nullptr }; >- const Box* m_lastChild { nullptr }; >+ Box* m_parent { nullptr }; >+ Box* m_nextSibling { nullptr }; >+ Box* m_previousSibling { nullptr }; >+ Box* m_firstChild { nullptr }; >+ Box* m_lastChild { nullptr }; > > }; > >diff --git a/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp b/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp >index 50aa1c904f97b987b488b6d4f2ca76fde78e7b29..964841dddc885a41f6e52ea1c88b22f46255d856 100644 >--- a/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp >+++ b/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp >@@ -66,11 +66,11 @@ Ref<FloatingState> InlineFormattingContext::createOrFindFloatingState() const > return formattingState.floatingState(); > } > >-void InlineFormattingContext::computeInFlowWidth(const Box&) const >+void InlineFormattingContext::computeInFlowWidth(LayoutPair&) const > { > } > >-void InlineFormattingContext::computeInFlowHeight(const Box&) const >+void InlineFormattingContext::computeInFlowHeight(LayoutPair&) const > { > } > >diff --git a/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h b/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h >index aa5c379d79a15c68465522ea8e8d468b6021d120..7fc7ce207195a4a7f05be94e18d29e780bb33dfb 100644 >--- a/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h >+++ b/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h >@@ -48,8 +48,8 @@ public: > Ref<FloatingState> createOrFindFloatingState() const override; > > private: >- void computeInFlowWidth(const Box&) const override; >- void computeInFlowHeight(const Box&) const override; >+ void computeInFlowWidth(LayoutPair&) const override; >+ void computeInFlowHeight(LayoutPair&) const override; > > }; >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 185158
:
339184
|
339380