Changeset 232350 in webkit
- Timestamp:
- May 31, 2018 9:43:52 AM (6 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r232349 r232350 1 2018-05-31 Zalan Bujtas <zalan@apple.com> 2 3 [LFC] Layout code needs to know the type of the Element associated with a Layout::Box 4 https://bugs.webkit.org/show_bug.cgi?id=186117 5 6 Reviewed by Antti Koivisto. 7 8 Since these attributes don't change during layout, we could just pass them in to Layout::Box instead 9 of keep querying the Element. 10 11 * layout/layouttree/LayoutBlockContainer.cpp: 12 (WebCore::Layout::BlockContainer::BlockContainer): 13 * layout/layouttree/LayoutBlockContainer.h: 14 * layout/layouttree/LayoutBox.cpp: 15 (WebCore::Layout::Box::Box): 16 (WebCore::Layout::Box::isPaddingApplicable const): 17 (WebCore::Layout::Box::isDocumentBox const): Deleted. 18 (WebCore::Layout::Box::isBodyBox const): Deleted. 19 * layout/layouttree/LayoutBox.h: 20 (WebCore::Layout::Box::isAnonymous const): 21 (WebCore::Layout::Box::isDocumentBox const): 22 (WebCore::Layout::Box::isBodyBox const): 23 (WebCore::Layout::Box::ElementAttributes::ElementAttributes): 24 (WebCore::Layout::Box::setPreviousSibling): 25 (WebCore::Layout::Box::setIsAnonymous): Deleted. 26 * layout/layouttree/LayoutContainer.cpp: 27 (WebCore::Layout::Container::Container): 28 * layout/layouttree/LayoutContainer.h: 29 * layout/layouttree/LayoutInlineBox.cpp: 30 (WebCore::Layout::InlineBox::InlineBox): 31 * layout/layouttree/LayoutInlineBox.h: 32 * layout/layouttree/LayoutInlineContainer.cpp: 33 (WebCore::Layout::InlineContainer::InlineContainer): 34 * layout/layouttree/LayoutInlineContainer.h: 35 * layout/layouttree/LayoutTreeBuilder.cpp: 36 (WebCore::Layout::TreeBuilder::createLayoutTree): 37 (WebCore::Layout::TreeBuilder::createSubTree): 38 1 39 2018-05-31 Chris Dumez <cdumez@apple.com> 2 40 -
trunk/Source/WebCore/layout/layouttree/LayoutBlockContainer.cpp
r231038 r232350 37 37 WTF_MAKE_ISO_ALLOCATED_IMPL(BlockContainer); 38 38 39 BlockContainer::BlockContainer( RenderStyle&& style, BaseTypeFlags baseTypeFlags)40 : Container( WTFMove(style), baseTypeFlags | BlockContainerFlag)39 BlockContainer::BlockContainer(std::optional<ElementAttributes> attributes, RenderStyle&& style, BaseTypeFlags baseTypeFlags) 40 : Container(attributes, WTFMove(style), baseTypeFlags | BlockContainerFlag) 41 41 { 42 42 } -
trunk/Source/WebCore/layout/layouttree/LayoutBlockContainer.h
r231141 r232350 45 45 46 46 protected: 47 BlockContainer( RenderStyle&&, BaseTypeFlags = BlockContainerFlag);47 BlockContainer(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags = BlockContainerFlag); 48 48 49 49 }; -
trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp
r232291 r232350 37 37 WTF_MAKE_ISO_ALLOCATED_IMPL(Box); 38 38 39 Box::Box( RenderStyle&& style, BaseTypeFlags baseTypeFlags)39 Box::Box(std::optional<ElementAttributes> attributes, RenderStyle&& style, BaseTypeFlags baseTypeFlags) 40 40 : m_style(WTFMove(style)) 41 , m_elementAttributes(attributes) 41 42 , m_baseTypeFlags(baseTypeFlags) 42 , m_isAnonymous(false)43 43 { 44 44 } … … 182 182 } 183 183 184 bool Box::isDocumentBox() const185 {186 // return document().documentElement() == &element();187 return false;188 }189 190 bool Box::isBodyBox() const191 {192 // return element().hasTagName(HTMLNames::bodyTag);193 return false;194 }195 196 184 const Box* Box::nextInFlowSibling() const 197 185 { … … 243 231 // 8.4 Padding properties: 244 232 // Applies to: all elements except table-row-group, table-header-group, table-footer-group, table-row, table-column-group and table-column 245 return true; 233 if (!m_elementAttributes) 234 return false; 235 auto elementType = m_elementAttributes.value().elementType; 236 return elementType != ElementType::TableRowGroup 237 && elementType != ElementType::TableHeaderGroup 238 && elementType != ElementType::TableFooterGroup 239 && elementType != ElementType::TableRow 240 && elementType != ElementType::TableColumnGroup 241 && elementType != ElementType::TableColumn; 246 242 } 247 243 -
trunk/Source/WebCore/layout/layouttree/LayoutBox.h
r232291 r232350 67 67 bool isDescendantOf(Container&) const; 68 68 69 bool isAnonymous() const { return m_isAnonymous; }69 bool isAnonymous() const { return !m_elementAttributes; } 70 70 71 71 bool isBlockLevelBox() const; … … 75 75 bool isInitialContainingBlock() const; 76 76 77 bool isDocumentBox() const ;78 bool isBodyBox() const ;77 bool isDocumentBox() const { return m_elementAttributes && m_elementAttributes.value().elementType == ElementType::Document; } 78 bool isBodyBox() const { return m_elementAttributes && m_elementAttributes.value().elementType == ElementType::Body; } 79 79 80 80 const Container* parent() const { return m_parent; } … … 100 100 101 101 protected: 102 enum class ElementType { 103 Document, 104 Body, 105 TableColumn, 106 TableRow, 107 TableColumnGroup, 108 TableRowGroup, 109 TableHeaderGroup, 110 TableFooterGroup 111 }; 112 113 struct ElementAttributes { 114 ElementType elementType; 115 }; 116 102 117 enum BaseTypeFlag { 103 118 ContainerFlag = 1 << 0, … … 106 121 InlineContainerFlag = 1 << 3 107 122 }; 108 Box( RenderStyle&&, BaseTypeFlags);123 Box(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags); 109 124 110 125 bool isOverflowVisible() const; … … 114 129 void setNextSibling(Box& nextSibling) { m_nextSibling = &nextSibling; } 115 130 void setPreviousSibling(Box& previousSibling) { m_previousSibling = &previousSibling; } 116 void setIsAnonymous() { m_isAnonymous = true; }117 131 118 132 WeakPtrFactory<Box> m_weakFactory; 119 133 RenderStyle m_style; 134 std::optional<ElementAttributes> m_elementAttributes; 120 135 121 136 Container* m_parent { nullptr }; … … 126 141 127 142 unsigned m_baseTypeFlags : 4; 128 unsigned m_isAnonymous : 1;129 130 143 }; 131 144 -
trunk/Source/WebCore/layout/layouttree/LayoutContainer.cpp
r231038 r232350 37 37 WTF_MAKE_ISO_ALLOCATED_IMPL(Container); 38 38 39 Container::Container( RenderStyle&& style, BaseTypeFlags baseTypeFlags)40 : Box( WTFMove(style), baseTypeFlags | ContainerFlag)39 Container::Container(std::optional<ElementAttributes> attributes, RenderStyle&& style, BaseTypeFlags baseTypeFlags) 40 : Box(attributes, WTFMove(style), baseTypeFlags | ContainerFlag) 41 41 { 42 42 } -
trunk/Source/WebCore/layout/layouttree/LayoutContainer.h
r231141 r232350 57 57 58 58 protected: 59 Container( RenderStyle&&, BaseTypeFlags);59 Container(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags); 60 60 61 61 private: -
trunk/Source/WebCore/layout/layouttree/LayoutInlineBox.cpp
r231038 r232350 37 37 WTF_MAKE_ISO_ALLOCATED_IMPL(InlineBox); 38 38 39 InlineBox::InlineBox( RenderStyle&& style, BaseTypeFlags baseTypeFlags)40 : Box( WTFMove(style), baseTypeFlags | InlineBoxFlag)39 InlineBox::InlineBox(std::optional<ElementAttributes> attributes, RenderStyle&& style, BaseTypeFlags baseTypeFlags) 40 : Box(attributes, WTFMove(style), baseTypeFlags | InlineBoxFlag) 41 41 { 42 42 } -
trunk/Source/WebCore/layout/layouttree/LayoutInlineBox.h
r231038 r232350 40 40 WTF_MAKE_ISO_ALLOCATED(InlineBox); 41 41 public: 42 InlineBox( RenderStyle&&, BaseTypeFlags);42 InlineBox(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags); 43 43 }; 44 44 -
trunk/Source/WebCore/layout/layouttree/LayoutInlineContainer.cpp
r231038 r232350 37 37 WTF_MAKE_ISO_ALLOCATED_IMPL(InlineContainer); 38 38 39 InlineContainer::InlineContainer( RenderStyle&& style, BaseTypeFlags baseTypeFlags)40 : Container( WTFMove(style), baseTypeFlags | InlineContainerFlag)39 InlineContainer::InlineContainer(std::optional<ElementAttributes> attributes, RenderStyle&& style, BaseTypeFlags baseTypeFlags) 40 : Container(attributes, WTFMove(style), baseTypeFlags | InlineContainerFlag) 41 41 { 42 42 } -
trunk/Source/WebCore/layout/layouttree/LayoutInlineContainer.h
r231141 r232350 43 43 44 44 protected: 45 InlineContainer( RenderStyle&&, BaseTypeFlags = InlineContainerFlag);45 InlineContainer(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags = InlineContainerFlag); 46 46 }; 47 47 -
trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp
r231897 r232350 30 30 31 31 #include "LayoutBlockContainer.h" 32 #include "LayoutBox.h" 32 33 #include "LayoutChildIterator.h" 33 34 #include "LayoutContainer.h" … … 47 48 std::unique_ptr<Container> TreeBuilder::createLayoutTree(const RenderView& renderView) 48 49 { 49 std::unique_ptr<Container> initialContainingBlock(new BlockContainer( RenderStyle::clone(renderView.style())));50 std::unique_ptr<Container> initialContainingBlock(new BlockContainer(std::nullopt, RenderStyle::clone(renderView.style()))); 50 51 TreeBuilder::createSubTree(renderView, *initialContainingBlock); 51 52 return initialContainingBlock; … … 54 55 void TreeBuilder::createSubTree(const RenderElement& rootRenderer, Container& rootContainer) 55 56 { 57 auto elementAttributes = [] (const RenderElement& renderer) -> std::optional<Box::ElementAttributes> { 58 if (renderer.isDocumentElementRenderer()) 59 return Box::ElementAttributes { Box::ElementType::Document }; 60 if (auto* element = renderer.element()) { 61 if (element->hasTagName(HTMLNames::bodyTag)) 62 return Box::ElementAttributes { Box::ElementType::Body }; 63 if (element->hasTagName(HTMLNames::colTag)) 64 return Box::ElementAttributes { Box::ElementType::TableColumn }; 65 if (element->hasTagName(HTMLNames::trTag)) 66 return Box::ElementAttributes { Box::ElementType::TableRow }; 67 if (element->hasTagName(HTMLNames::colgroupTag)) 68 return Box::ElementAttributes { Box::ElementType::TableColumnGroup }; 69 if (element->hasTagName(HTMLNames::tbodyTag)) 70 return Box::ElementAttributes { Box::ElementType::TableRowGroup }; 71 if (element->hasTagName(HTMLNames::theadTag)) 72 return Box::ElementAttributes { Box::ElementType::TableHeaderGroup }; 73 if (element->hasTagName(HTMLNames::tfootTag)) 74 return Box::ElementAttributes { Box::ElementType::TableFooterGroup }; 75 } 76 return std::nullopt; 77 }; 78 56 79 // Skip RenderText (and some others) for now. 57 80 for (auto& child : childrenOfType<RenderElement>(rootRenderer)) { 58 81 Box* box = nullptr; 82 59 83 if (is<RenderBlock>(child)) { 60 box = new BlockContainer( RenderStyle::clone(child.style()));84 box = new BlockContainer(elementAttributes(child), RenderStyle::clone(child.style())); 61 85 createSubTree(child, downcast<Container>(*box)); 62 86 } else if (is<RenderInline>(child)) { 63 box = new InlineContainer( RenderStyle::clone(child.style()));87 box = new InlineContainer(elementAttributes(child), RenderStyle::clone(child.style())); 64 88 createSubTree(child, downcast<Container>(*box)); 65 89 } else
Note: See TracChangeset
for help on using the changeset viewer.