Diff
Modified: trunk/Source/WebCore/ChangeLog (231479 => 231480)
--- trunk/Source/WebCore/ChangeLog 2018-05-08 05:02:52 UTC (rev 231479)
+++ trunk/Source/WebCore/ChangeLog 2018-05-08 05:26:39 UTC (rev 231480)
@@ -1,3 +1,26 @@
+2018-05-07 Zalan Bujtas <[email protected]>
+
+ [LFC] Add FormattingContext::layoutOutOfFlowDescendants implementation
+ https://bugs.webkit.org/show_bug.cgi?id=185377
+
+ Reviewed by Antti Koivisto.
+
+ Also, remove FormattingContext's m_layoutContext member and pass it in to ::layout() instead.
+ In theory LayoutContext is needed only during ::layout() call.
+
+ * layout/FormattingContext.cpp:
+ (WebCore::Layout::FormattingContext::layoutOutOfFlowDescendants const):
+ * layout/FormattingContext.h:
+ (WebCore::Layout::FormattingContext::layoutContext const):
+ * layout/LayoutContext.cpp:
+ (WebCore::Layout::LayoutContext::updateLayout):
+ * layout/blockformatting/BlockFormattingContext.cpp:
+ (WebCore::Layout::BlockFormattingContext::layout const):
+ * layout/blockformatting/BlockFormattingContext.h:
+ * layout/inlineformatting/InlineFormattingContext.cpp:
+ (WebCore::Layout::InlineFormattingContext::layout const):
+ * layout/inlineformatting/InlineFormattingContext.h:
+
2018-05-07 Daniel Bates <[email protected]>
Check X-Frame-Options and CSP frame-ancestors in network process
Modified: trunk/Source/WebCore/layout/FormattingContext.cpp (231479 => 231480)
--- trunk/Source/WebCore/layout/FormattingContext.cpp 2018-05-08 05:02:52 UTC (rev 231479)
+++ trunk/Source/WebCore/layout/FormattingContext.cpp 2018-05-08 05:26:39 UTC (rev 231480)
@@ -29,6 +29,8 @@
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
#include "LayoutBox.h"
+#include "LayoutContainer.h"
+#include "LayoutContext.h"
#include <wtf/IsoMallocInlines.h>
namespace WebCore {
@@ -36,9 +38,8 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(FormattingContext);
-FormattingContext::FormattingContext(const Box& formattingContextRoot, LayoutContext& layoutContext)
+FormattingContext::FormattingContext(const Box& formattingContextRoot)
: m_root(makeWeakPtr(const_cast<Box&>(formattingContextRoot)))
- , m_layoutContext(layoutContext)
{
}
@@ -46,7 +47,7 @@
{
}
-void FormattingContext::computeStaticPosition(const Box&, Display::Box&) const
+void FormattingContext::computeStaticPosition(LayoutContext&, const Box&, Display::Box&) const
{
}
@@ -116,8 +117,23 @@
{
}
-void FormattingContext::layoutOutOfFlowDescendants() const
+void FormattingContext::layoutOutOfFlowDescendants(LayoutContext& layoutContext) const
{
+ if (!is<Container>(m_root.get()))
+ return;
+ for (auto& outOfFlowBox : downcast<Container>(*m_root).outOfFlowDescendants()) {
+ auto& layoutBox = *outOfFlowBox;
+ auto& displayBox = layoutContext.createDisplayBox(layoutBox);
+
+ computeOutOfFlowPosition(layoutBox, displayBox);
+ computeOutOfFlowWidth(layoutBox, displayBox);
+
+ ASSERT(layoutBox.establishesFormattingContext());
+ auto formattingContext = layoutContext.formattingContext(layoutBox);
+ formattingContext->layout(layoutContext, layoutContext.establishedFormattingState(layoutBox, *formattingContext));
+
+ computeOutOfFlowHeight(layoutBox, displayBox);
+ }
}
}
Modified: trunk/Source/WebCore/layout/FormattingContext.h (231479 => 231480)
--- trunk/Source/WebCore/layout/FormattingContext.h 2018-05-08 05:02:52 UTC (rev 231479)
+++ trunk/Source/WebCore/layout/FormattingContext.h 2018-05-08 05:26:39 UTC (rev 231480)
@@ -48,12 +48,12 @@
class FormattingContext {
WTF_MAKE_ISO_ALLOCATED(FormattingContext);
public:
- FormattingContext(const Box& formattingContextRoot, LayoutContext&);
+ FormattingContext(const Box& formattingContextRoot);
virtual ~FormattingContext();
virtual void layout(LayoutContext&, FormattingState&) const = 0;
virtual std::unique_ptr<FormattingState> createFormattingState(Ref<FloatingState>&&) const = 0;
- virtual Ref<FloatingState> createOrFindFloatingState() const = 0;
+ virtual Ref<FloatingState> createOrFindFloatingState(LayoutContext&) const = 0;
protected:
struct LayoutPair {
@@ -63,9 +63,8 @@
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&, Display::Box&) const;
+ virtual void computeStaticPosition(LayoutContext&, const Box&, Display::Box&) const;
virtual void computeInFlowPositionedPosition(const Box&, Display::Box&) const;
virtual void computeOutOfFlowPosition(const Box&, Display::Box&) const;
@@ -86,11 +85,10 @@
virtual LayoutUnit marginRight(const Box&) const;
void placeInFlowPositionedChildren(const Container&) const;
- void layoutOutOfFlowDescendants() const;
+ void layoutOutOfFlowDescendants(LayoutContext&s) const;
private:
WeakPtr<Box> m_root;
- LayoutContext& m_layoutContext;
};
}
Modified: trunk/Source/WebCore/layout/LayoutContext.cpp (231479 => 231480)
--- trunk/Source/WebCore/layout/LayoutContext.cpp 2018-05-08 05:02:52 UTC (rev 231479)
+++ trunk/Source/WebCore/layout/LayoutContext.cpp 2018-05-08 05:26:39 UTC (rev 231480)
@@ -98,7 +98,7 @@
FormattingState& LayoutContext::establishedFormattingState(const Box& formattingContextRoot, const FormattingContext& context)
{
return *m_formattingStates.ensure(&formattingContextRoot, [this, &context] {
- return context.createFormattingState(context.createOrFindFloatingState());
+ return context.createFormattingState(context.createOrFindFloatingState(*this));
}).iterator->value;
}
@@ -105,10 +105,10 @@
std::unique_ptr<FormattingContext> LayoutContext::formattingContext(const Box& formattingContextRoot)
{
if (formattingContextRoot.establishesBlockFormattingContext())
- return std::make_unique<BlockFormattingContext>(formattingContextRoot, *this);
+ return std::make_unique<BlockFormattingContext>(formattingContextRoot);
if (formattingContextRoot.establishesInlineFormattingContext())
- return std::make_unique<InlineFormattingContext>(formattingContextRoot, *this);
+ return std::make_unique<InlineFormattingContext>(formattingContextRoot);
ASSERT_NOT_REACHED();
return nullptr;
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp (231479 => 231480)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp 2018-05-08 05:02:52 UTC (rev 231479)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp 2018-05-08 05:26:39 UTC (rev 231480)
@@ -42,8 +42,8 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(BlockFormattingContext);
-BlockFormattingContext::BlockFormattingContext(const Box& formattingContextRoot, LayoutContext& layoutContext)
- : FormattingContext(formattingContextRoot, layoutContext)
+BlockFormattingContext::BlockFormattingContext(const Box& formattingContextRoot)
+ : FormattingContext(formattingContextRoot)
{
}
@@ -74,7 +74,7 @@
auto& displayBox = layoutPair.displayBox;
computeWidth(layoutBox, displayBox);
- computeStaticPosition(layoutBox, layoutPair.displayBox);
+ computeStaticPosition(layoutContext, layoutBox, layoutPair.displayBox);
if (layoutBox.establishesFormattingContext()) {
auto formattingContext = layoutContext.formattingContext(layoutBox);
formattingContext->layout(layoutContext, layoutContext.establishedFormattingState(layoutBox, *formattingContext));
@@ -110,7 +110,7 @@
// Place the inflow positioned children.
placeInFlowPositionedChildren(formattingRoot);
// And take care of out-of-flow boxes as the final step.
- layoutOutOfFlowDescendants();
+ layoutOutOfFlowDescendants(layoutContext);
}
std::unique_ptr<FormattingState> BlockFormattingContext::createFormattingState(Ref<FloatingState>&& floatingState) const
@@ -118,13 +118,13 @@
return std::make_unique<BlockFormattingState>(WTFMove(floatingState));
}
-Ref<FloatingState> BlockFormattingContext::createOrFindFloatingState() const
+Ref<FloatingState> BlockFormattingContext::createOrFindFloatingState(LayoutContext&) const
{
// Block formatting context always establishes a new floating state.
return FloatingState::create();
}
-void BlockFormattingContext::computeStaticPosition(const Box& layoutBox, Display::Box& displayBox) const
+void BlockFormattingContext::computeStaticPosition(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
{
// https://www.w3.org/TR/CSS22/visuren.html#block-formatting
// In a block formatting context, boxes are laid out one after the other, vertically, beginning at the top of a containing block.
@@ -131,12 +131,12 @@
// The vertical distance between two sibling boxes is determined by the 'margin' properties.
// Vertical margins between adjacent block-level boxes in a block formatting context collapse.
// In a block formatting context, each box's left outer edge touches the left edge of the containing block (for right-to-left formatting, right edges touch).
- auto containingBlockContentBox = layoutContext().displayBoxForLayoutBox(*layoutBox.containingBlock())->contentBox();
+ auto containingBlockContentBox = layoutContext.displayBoxForLayoutBox(*layoutBox.containingBlock())->contentBox();
// Start from the top of the container's content box.
auto top = containingBlockContentBox.y();
auto left = containingBlockContentBox.x();
if (auto* previousInFlowSibling = layoutBox.previousInFlowSibling())
- top = layoutContext().displayBoxForLayoutBox(*previousInFlowSibling)->bottom() + marginBottom(*previousInFlowSibling);
+ top = layoutContext.displayBoxForLayoutBox(*previousInFlowSibling)->bottom() + marginBottom(*previousInFlowSibling);
LayoutPoint topLeft = { top, left };
topLeft.moveBy({ marginLeft(layoutBox), marginTop(layoutBox) });
displayBox.setTopLeft(topLeft);
Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h (231479 => 231480)
--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h 2018-05-08 05:02:52 UTC (rev 231479)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h 2018-05-08 05:26:39 UTC (rev 231480)
@@ -43,14 +43,14 @@
class BlockFormattingContext : public FormattingContext {
WTF_MAKE_ISO_ALLOCATED(BlockFormattingContext);
public:
- BlockFormattingContext(const Box& formattingContextRoot, LayoutContext&);
+ BlockFormattingContext(const Box& formattingContextRoot);
void layout(LayoutContext&, FormattingState&) const override;
std::unique_ptr<FormattingState> createFormattingState(Ref<FloatingState>&&) const override;
- Ref<FloatingState> createOrFindFloatingState() const override;
+ Ref<FloatingState> createOrFindFloatingState(LayoutContext&) const override;
protected:
- void computeStaticPosition(const Box&, Display::Box&) const override;
+ void computeStaticPosition(LayoutContext&, const Box&, Display::Box&) const override;
void computeInFlowWidth(const Box&, Display::Box&) const override;
void computeInFlowHeight(const Box&, Display::Box&) const override;
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp (231479 => 231480)
--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp 2018-05-08 05:02:52 UTC (rev 231479)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp 2018-05-08 05:26:39 UTC (rev 231480)
@@ -39,8 +39,8 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(InlineFormattingContext);
-InlineFormattingContext::InlineFormattingContext(const Box& formattingContextRoot, LayoutContext& layoutContext)
- : FormattingContext(formattingContextRoot, layoutContext)
+InlineFormattingContext::InlineFormattingContext(const Box& formattingContextRoot)
+ : FormattingContext(formattingContextRoot)
{
}
@@ -53,7 +53,7 @@
return std::make_unique<InlineFormattingState>(WTFMove(floatingState));
}
-Ref<FloatingState> InlineFormattingContext::createOrFindFloatingState() const
+Ref<FloatingState> InlineFormattingContext::createOrFindFloatingState(LayoutContext& layoutContext) const
{
// If the block container box that initiates this inline formatting context also establishes a block context, the floats outside of the formatting root
// should not interfere with the content inside.
@@ -62,7 +62,7 @@
return FloatingState::create();
// 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 (this) and use its floating state.
- auto& formattingState = layoutContext().formattingStateForBox(root());
+ auto& formattingState = layoutContext.formattingStateForBox(root());
return formattingState.floatingState();
}
Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h (231479 => 231480)
--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h 2018-05-08 05:02:52 UTC (rev 231479)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h 2018-05-08 05:26:39 UTC (rev 231480)
@@ -41,11 +41,11 @@
class InlineFormattingContext : public FormattingContext {
WTF_MAKE_ISO_ALLOCATED(InlineFormattingContext);
public:
- InlineFormattingContext(const Box& formattingContextRoot, LayoutContext&);
+ InlineFormattingContext(const Box& formattingContextRoot);
void layout(LayoutContext&, FormattingState&) const override;
std::unique_ptr<FormattingState> createFormattingState(Ref<FloatingState>&&) const override;
- Ref<FloatingState> createOrFindFloatingState() const override;
+ Ref<FloatingState> createOrFindFloatingState(LayoutContext&) const override;
private:
void computeInFlowWidth(const Box&, Display::Box&) const override;