Diff
Modified: trunk/Source/WebCore/ChangeLog (232349 => 232350)
--- trunk/Source/WebCore/ChangeLog 2018-05-31 16:24:59 UTC (rev 232349)
+++ trunk/Source/WebCore/ChangeLog 2018-05-31 16:43:52 UTC (rev 232350)
@@ -1,3 +1,41 @@
+2018-05-31 Zalan Bujtas <[email protected]>
+
+ [LFC] Layout code needs to know the type of the Element associated with a Layout::Box
+ https://bugs.webkit.org/show_bug.cgi?id=186117
+
+ Reviewed by Antti Koivisto.
+
+ Since these attributes don't change during layout, we could just pass them in to Layout::Box instead
+ of keep querying the Element.
+
+ * layout/layouttree/LayoutBlockContainer.cpp:
+ (WebCore::Layout::BlockContainer::BlockContainer):
+ * layout/layouttree/LayoutBlockContainer.h:
+ * layout/layouttree/LayoutBox.cpp:
+ (WebCore::Layout::Box::Box):
+ (WebCore::Layout::Box::isPaddingApplicable const):
+ (WebCore::Layout::Box::isDocumentBox const): Deleted.
+ (WebCore::Layout::Box::isBodyBox const): Deleted.
+ * layout/layouttree/LayoutBox.h:
+ (WebCore::Layout::Box::isAnonymous const):
+ (WebCore::Layout::Box::isDocumentBox const):
+ (WebCore::Layout::Box::isBodyBox const):
+ (WebCore::Layout::Box::ElementAttributes::ElementAttributes):
+ (WebCore::Layout::Box::setPreviousSibling):
+ (WebCore::Layout::Box::setIsAnonymous): Deleted.
+ * layout/layouttree/LayoutContainer.cpp:
+ (WebCore::Layout::Container::Container):
+ * layout/layouttree/LayoutContainer.h:
+ * layout/layouttree/LayoutInlineBox.cpp:
+ (WebCore::Layout::InlineBox::InlineBox):
+ * layout/layouttree/LayoutInlineBox.h:
+ * layout/layouttree/LayoutInlineContainer.cpp:
+ (WebCore::Layout::InlineContainer::InlineContainer):
+ * layout/layouttree/LayoutInlineContainer.h:
+ * layout/layouttree/LayoutTreeBuilder.cpp:
+ (WebCore::Layout::TreeBuilder::createLayoutTree):
+ (WebCore::Layout::TreeBuilder::createSubTree):
+
2018-05-31 Chris Dumez <[email protected]>
Unreviewed iOS build fix after r232335.
Modified: trunk/Source/WebCore/layout/layouttree/LayoutBlockContainer.cpp (232349 => 232350)
--- trunk/Source/WebCore/layout/layouttree/LayoutBlockContainer.cpp 2018-05-31 16:24:59 UTC (rev 232349)
+++ trunk/Source/WebCore/layout/layouttree/LayoutBlockContainer.cpp 2018-05-31 16:43:52 UTC (rev 232350)
@@ -36,8 +36,8 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(BlockContainer);
-BlockContainer::BlockContainer(RenderStyle&& style, BaseTypeFlags baseTypeFlags)
- : Container(WTFMove(style), baseTypeFlags | BlockContainerFlag)
+BlockContainer::BlockContainer(std::optional<ElementAttributes> attributes, RenderStyle&& style, BaseTypeFlags baseTypeFlags)
+ : Container(attributes, WTFMove(style), baseTypeFlags | BlockContainerFlag)
{
}
Modified: trunk/Source/WebCore/layout/layouttree/LayoutBlockContainer.h (232349 => 232350)
--- trunk/Source/WebCore/layout/layouttree/LayoutBlockContainer.h 2018-05-31 16:24:59 UTC (rev 232349)
+++ trunk/Source/WebCore/layout/layouttree/LayoutBlockContainer.h 2018-05-31 16:43:52 UTC (rev 232350)
@@ -44,7 +44,7 @@
bool establishesInlineFormattingContext() const final;
protected:
- BlockContainer(RenderStyle&&, BaseTypeFlags = BlockContainerFlag);
+ BlockContainer(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags = BlockContainerFlag);
};
Modified: trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp (232349 => 232350)
--- trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp 2018-05-31 16:24:59 UTC (rev 232349)
+++ trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp 2018-05-31 16:43:52 UTC (rev 232350)
@@ -36,10 +36,10 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(Box);
-Box::Box(RenderStyle&& style, BaseTypeFlags baseTypeFlags)
+Box::Box(std::optional<ElementAttributes> attributes, RenderStyle&& style, BaseTypeFlags baseTypeFlags)
: m_style(WTFMove(style))
+ , m_elementAttributes(attributes)
, m_baseTypeFlags(baseTypeFlags)
- , m_isAnonymous(false)
{
}
@@ -181,18 +181,6 @@
return !parent();
}
-bool Box::isDocumentBox() const
-{
- // return document().documentElement() == &element();
- return false;
-}
-
-bool Box::isBodyBox() const
-{
- // return element().hasTagName(HTMLNames::bodyTag);
- return false;
-}
-
const Box* Box::nextInFlowSibling() const
{
if (auto* nextSibling = this->nextSibling()) {
@@ -242,7 +230,15 @@
{
// 8.4 Padding properties:
// Applies to: all elements except table-row-group, table-header-group, table-footer-group, table-row, table-column-group and table-column
- return true;
+ if (!m_elementAttributes)
+ return false;
+ auto elementType = m_elementAttributes.value().elementType;
+ return elementType != ElementType::TableRowGroup
+ && elementType != ElementType::TableHeaderGroup
+ && elementType != ElementType::TableFooterGroup
+ && elementType != ElementType::TableRow
+ && elementType != ElementType::TableColumnGroup
+ && elementType != ElementType::TableColumn;
}
}
Modified: trunk/Source/WebCore/layout/layouttree/LayoutBox.h (232349 => 232350)
--- trunk/Source/WebCore/layout/layouttree/LayoutBox.h 2018-05-31 16:24:59 UTC (rev 232349)
+++ trunk/Source/WebCore/layout/layouttree/LayoutBox.h 2018-05-31 16:43:52 UTC (rev 232350)
@@ -66,7 +66,7 @@
const Container& formattingContextRoot() const;
bool isDescendantOf(Container&) const;
- bool isAnonymous() const { return m_isAnonymous; }
+ bool isAnonymous() const { return !m_elementAttributes; }
bool isBlockLevelBox() const;
bool isInlineLevelBox() const;
@@ -74,8 +74,8 @@
bool isBlockContainerBox() const;
bool isInitialContainingBlock() const;
- bool isDocumentBox() const;
- bool isBodyBox() const;
+ bool isDocumentBox() const { return m_elementAttributes && m_elementAttributes.value().elementType == ElementType::Document; }
+ bool isBodyBox() const { return m_elementAttributes && m_elementAttributes.value().elementType == ElementType::Body; }
const Container* parent() const { return m_parent; }
const Box* nextSibling() const { return m_nextSibling; }
@@ -99,6 +99,21 @@
std::optional<const Replaced> replaced() const { return m_replaced; }
protected:
+ enum class ElementType {
+ Document,
+ Body,
+ TableColumn,
+ TableRow,
+ TableColumnGroup,
+ TableRowGroup,
+ TableHeaderGroup,
+ TableFooterGroup
+ };
+
+ struct ElementAttributes {
+ ElementType elementType;
+ };
+
enum BaseTypeFlag {
ContainerFlag = 1 << 0,
BlockContainerFlag = 1 << 1,
@@ -105,7 +120,7 @@
InlineBoxFlag = 1 << 2,
InlineContainerFlag = 1 << 3
};
- Box(RenderStyle&&, BaseTypeFlags);
+ Box(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags);
bool isOverflowVisible() const;
@@ -113,10 +128,10 @@
void setParent(Container& parent) { m_parent = &parent; }
void setNextSibling(Box& nextSibling) { m_nextSibling = &nextSibling; }
void setPreviousSibling(Box& previousSibling) { m_previousSibling = &previousSibling; }
- void setIsAnonymous() { m_isAnonymous = true; }
WeakPtrFactory<Box> m_weakFactory;
RenderStyle m_style;
+ std::optional<ElementAttributes> m_elementAttributes;
Container* m_parent { nullptr };
Box* m_previousSibling { nullptr };
@@ -125,8 +140,6 @@
std::optional<const Replaced> m_replaced;
unsigned m_baseTypeFlags : 4;
- unsigned m_isAnonymous : 1;
-
};
}
Modified: trunk/Source/WebCore/layout/layouttree/LayoutContainer.cpp (232349 => 232350)
--- trunk/Source/WebCore/layout/layouttree/LayoutContainer.cpp 2018-05-31 16:24:59 UTC (rev 232349)
+++ trunk/Source/WebCore/layout/layouttree/LayoutContainer.cpp 2018-05-31 16:43:52 UTC (rev 232350)
@@ -36,8 +36,8 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(Container);
-Container::Container(RenderStyle&& style, BaseTypeFlags baseTypeFlags)
- : Box(WTFMove(style), baseTypeFlags | ContainerFlag)
+Container::Container(std::optional<ElementAttributes> attributes, RenderStyle&& style, BaseTypeFlags baseTypeFlags)
+ : Box(attributes, WTFMove(style), baseTypeFlags | ContainerFlag)
{
}
Modified: trunk/Source/WebCore/layout/layouttree/LayoutContainer.h (232349 => 232350)
--- trunk/Source/WebCore/layout/layouttree/LayoutContainer.h 2018-05-31 16:24:59 UTC (rev 232349)
+++ trunk/Source/WebCore/layout/layouttree/LayoutContainer.h 2018-05-31 16:43:52 UTC (rev 232350)
@@ -56,7 +56,7 @@
const Vector<WeakPtr<Box>>& outOfFlowDescendants() { return m_outOfFlowDescendants; }
protected:
- Container(RenderStyle&&, BaseTypeFlags);
+ Container(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags);
private:
void setFirstChild(Box&);
Modified: trunk/Source/WebCore/layout/layouttree/LayoutInlineBox.cpp (232349 => 232350)
--- trunk/Source/WebCore/layout/layouttree/LayoutInlineBox.cpp 2018-05-31 16:24:59 UTC (rev 232349)
+++ trunk/Source/WebCore/layout/layouttree/LayoutInlineBox.cpp 2018-05-31 16:43:52 UTC (rev 232350)
@@ -36,8 +36,8 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(InlineBox);
-InlineBox::InlineBox(RenderStyle&& style, BaseTypeFlags baseTypeFlags)
- : Box(WTFMove(style), baseTypeFlags | InlineBoxFlag)
+InlineBox::InlineBox(std::optional<ElementAttributes> attributes, RenderStyle&& style, BaseTypeFlags baseTypeFlags)
+ : Box(attributes, WTFMove(style), baseTypeFlags | InlineBoxFlag)
{
}
Modified: trunk/Source/WebCore/layout/layouttree/LayoutInlineBox.h (232349 => 232350)
--- trunk/Source/WebCore/layout/layouttree/LayoutInlineBox.h 2018-05-31 16:24:59 UTC (rev 232349)
+++ trunk/Source/WebCore/layout/layouttree/LayoutInlineBox.h 2018-05-31 16:43:52 UTC (rev 232350)
@@ -39,7 +39,7 @@
class InlineBox : public Box {
WTF_MAKE_ISO_ALLOCATED(InlineBox);
public:
- InlineBox(RenderStyle&&, BaseTypeFlags);
+ InlineBox(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags);
};
}
Modified: trunk/Source/WebCore/layout/layouttree/LayoutInlineContainer.cpp (232349 => 232350)
--- trunk/Source/WebCore/layout/layouttree/LayoutInlineContainer.cpp 2018-05-31 16:24:59 UTC (rev 232349)
+++ trunk/Source/WebCore/layout/layouttree/LayoutInlineContainer.cpp 2018-05-31 16:43:52 UTC (rev 232350)
@@ -36,8 +36,8 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(InlineContainer);
-InlineContainer::InlineContainer(RenderStyle&& style, BaseTypeFlags baseTypeFlags)
- : Container(WTFMove(style), baseTypeFlags | InlineContainerFlag)
+InlineContainer::InlineContainer(std::optional<ElementAttributes> attributes, RenderStyle&& style, BaseTypeFlags baseTypeFlags)
+ : Container(attributes, WTFMove(style), baseTypeFlags | InlineContainerFlag)
{
}
Modified: trunk/Source/WebCore/layout/layouttree/LayoutInlineContainer.h (232349 => 232350)
--- trunk/Source/WebCore/layout/layouttree/LayoutInlineContainer.h 2018-05-31 16:24:59 UTC (rev 232349)
+++ trunk/Source/WebCore/layout/layouttree/LayoutInlineContainer.h 2018-05-31 16:43:52 UTC (rev 232350)
@@ -42,7 +42,7 @@
friend class TreeBuilder;
protected:
- InlineContainer(RenderStyle&&, BaseTypeFlags = InlineContainerFlag);
+ InlineContainer(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags = InlineContainerFlag);
};
}
Modified: trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp (232349 => 232350)
--- trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp 2018-05-31 16:24:59 UTC (rev 232349)
+++ trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp 2018-05-31 16:43:52 UTC (rev 232350)
@@ -29,6 +29,7 @@
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
#include "LayoutBlockContainer.h"
+#include "LayoutBox.h"
#include "LayoutChildIterator.h"
#include "LayoutContainer.h"
#include "LayoutInlineBox.h"
@@ -46,7 +47,7 @@
std::unique_ptr<Container> TreeBuilder::createLayoutTree(const RenderView& renderView)
{
- std::unique_ptr<Container> initialContainingBlock(new BlockContainer(RenderStyle::clone(renderView.style())));
+ std::unique_ptr<Container> initialContainingBlock(new BlockContainer(std::nullopt, RenderStyle::clone(renderView.style())));
TreeBuilder::createSubTree(renderView, *initialContainingBlock);
return initialContainingBlock;
}
@@ -53,14 +54,37 @@
void TreeBuilder::createSubTree(const RenderElement& rootRenderer, Container& rootContainer)
{
+ auto elementAttributes = [] (const RenderElement& renderer) -> std::optional<Box::ElementAttributes> {
+ if (renderer.isDocumentElementRenderer())
+ return Box::ElementAttributes { Box::ElementType::Document };
+ if (auto* element = renderer.element()) {
+ if (element->hasTagName(HTMLNames::bodyTag))
+ return Box::ElementAttributes { Box::ElementType::Body };
+ if (element->hasTagName(HTMLNames::colTag))
+ return Box::ElementAttributes { Box::ElementType::TableColumn };
+ if (element->hasTagName(HTMLNames::trTag))
+ return Box::ElementAttributes { Box::ElementType::TableRow };
+ if (element->hasTagName(HTMLNames::colgroupTag))
+ return Box::ElementAttributes { Box::ElementType::TableColumnGroup };
+ if (element->hasTagName(HTMLNames::tbodyTag))
+ return Box::ElementAttributes { Box::ElementType::TableRowGroup };
+ if (element->hasTagName(HTMLNames::theadTag))
+ return Box::ElementAttributes { Box::ElementType::TableHeaderGroup };
+ if (element->hasTagName(HTMLNames::tfootTag))
+ return Box::ElementAttributes { Box::ElementType::TableFooterGroup };
+ }
+ return std::nullopt;
+ };
+
// Skip RenderText (and some others) for now.
for (auto& child : childrenOfType<RenderElement>(rootRenderer)) {
Box* box = nullptr;
+
if (is<RenderBlock>(child)) {
- box = new BlockContainer(RenderStyle::clone(child.style()));
+ box = new BlockContainer(elementAttributes(child), RenderStyle::clone(child.style()));
createSubTree(child, downcast<Container>(*box));
} else if (is<RenderInline>(child)) {
- box = new InlineContainer(RenderStyle::clone(child.style()));
+ box = new InlineContainer(elementAttributes(child), RenderStyle::clone(child.style()));
createSubTree(child, downcast<Container>(*box));
} else
ASSERT_NOT_IMPLEMENTED_YET();