Changeset 232350 in webkit


Ignore:
Timestamp:
May 31, 2018 9:43:52 AM (6 years ago)
Author:
Alan Bujtas
Message:

[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):

Location:
trunk/Source/WebCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r232349 r232350  
     12018-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
    1392018-05-31  Chris Dumez  <cdumez@apple.com>
    240
  • trunk/Source/WebCore/layout/layouttree/LayoutBlockContainer.cpp

    r231038 r232350  
    3737WTF_MAKE_ISO_ALLOCATED_IMPL(BlockContainer);
    3838
    39 BlockContainer::BlockContainer(RenderStyle&& style, BaseTypeFlags baseTypeFlags)
    40     : Container(WTFMove(style), baseTypeFlags | BlockContainerFlag)
     39BlockContainer::BlockContainer(std::optional<ElementAttributes> attributes, RenderStyle&& style, BaseTypeFlags baseTypeFlags)
     40    : Container(attributes, WTFMove(style), baseTypeFlags | BlockContainerFlag)
    4141{
    4242}
  • trunk/Source/WebCore/layout/layouttree/LayoutBlockContainer.h

    r231141 r232350  
    4545
    4646protected:
    47     BlockContainer(RenderStyle&&, BaseTypeFlags = BlockContainerFlag);
     47    BlockContainer(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags = BlockContainerFlag);
    4848
    4949};
  • trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp

    r232291 r232350  
    3737WTF_MAKE_ISO_ALLOCATED_IMPL(Box);
    3838
    39 Box::Box(RenderStyle&& style, BaseTypeFlags baseTypeFlags)
     39Box::Box(std::optional<ElementAttributes> attributes, RenderStyle&& style, BaseTypeFlags baseTypeFlags)
    4040    : m_style(WTFMove(style))
     41    , m_elementAttributes(attributes)
    4142    , m_baseTypeFlags(baseTypeFlags)
    42     , m_isAnonymous(false)
    4343{
    4444}
     
    182182}
    183183
    184 bool Box::isDocumentBox() const
    185 {
    186     // return document().documentElement() == &element();
    187     return false;
    188 }
    189 
    190 bool Box::isBodyBox() const
    191 {
    192     // return element().hasTagName(HTMLNames::bodyTag);
    193     return false;
    194 }
    195 
    196184const Box* Box::nextInFlowSibling() const
    197185{
     
    243231    // 8.4 Padding properties:
    244232    // 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;
    246242}
    247243
  • trunk/Source/WebCore/layout/layouttree/LayoutBox.h

    r232291 r232350  
    6767    bool isDescendantOf(Container&) const;
    6868
    69     bool isAnonymous() const { return m_isAnonymous; }
     69    bool isAnonymous() const { return !m_elementAttributes; }
    7070
    7171    bool isBlockLevelBox() const;
     
    7575    bool isInitialContainingBlock() const;
    7676
    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; }
    7979
    8080    const Container* parent() const { return m_parent; }
     
    100100
    101101protected:
     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
    102117    enum BaseTypeFlag {
    103118        ContainerFlag         = 1 << 0,
     
    106121        InlineContainerFlag   = 1 << 3
    107122    };
    108     Box(RenderStyle&&, BaseTypeFlags);
     123    Box(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags);
    109124
    110125    bool isOverflowVisible() const;
     
    114129    void setNextSibling(Box& nextSibling) { m_nextSibling = &nextSibling; }
    115130    void setPreviousSibling(Box& previousSibling) { m_previousSibling = &previousSibling; }
    116     void setIsAnonymous() { m_isAnonymous = true; }
    117131
    118132    WeakPtrFactory<Box> m_weakFactory;
    119133    RenderStyle m_style;
     134    std::optional<ElementAttributes> m_elementAttributes;
    120135
    121136    Container* m_parent { nullptr };
     
    126141
    127142    unsigned m_baseTypeFlags : 4;
    128     unsigned m_isAnonymous : 1;
    129 
    130143};
    131144
  • trunk/Source/WebCore/layout/layouttree/LayoutContainer.cpp

    r231038 r232350  
    3737WTF_MAKE_ISO_ALLOCATED_IMPL(Container);
    3838
    39 Container::Container(RenderStyle&& style, BaseTypeFlags baseTypeFlags)
    40     : Box(WTFMove(style), baseTypeFlags | ContainerFlag)
     39Container::Container(std::optional<ElementAttributes> attributes, RenderStyle&& style, BaseTypeFlags baseTypeFlags)
     40    : Box(attributes, WTFMove(style), baseTypeFlags | ContainerFlag)
    4141{
    4242}
  • trunk/Source/WebCore/layout/layouttree/LayoutContainer.h

    r231141 r232350  
    5757
    5858protected:
    59     Container(RenderStyle&&, BaseTypeFlags);
     59    Container(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags);
    6060
    6161private:
  • trunk/Source/WebCore/layout/layouttree/LayoutInlineBox.cpp

    r231038 r232350  
    3737WTF_MAKE_ISO_ALLOCATED_IMPL(InlineBox);
    3838
    39 InlineBox::InlineBox(RenderStyle&& style, BaseTypeFlags baseTypeFlags)
    40     : Box(WTFMove(style), baseTypeFlags | InlineBoxFlag)
     39InlineBox::InlineBox(std::optional<ElementAttributes> attributes, RenderStyle&& style, BaseTypeFlags baseTypeFlags)
     40    : Box(attributes, WTFMove(style), baseTypeFlags | InlineBoxFlag)
    4141{
    4242}
  • trunk/Source/WebCore/layout/layouttree/LayoutInlineBox.h

    r231038 r232350  
    4040    WTF_MAKE_ISO_ALLOCATED(InlineBox);
    4141public:
    42     InlineBox(RenderStyle&&, BaseTypeFlags);
     42    InlineBox(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags);
    4343};
    4444
  • trunk/Source/WebCore/layout/layouttree/LayoutInlineContainer.cpp

    r231038 r232350  
    3737WTF_MAKE_ISO_ALLOCATED_IMPL(InlineContainer);
    3838
    39 InlineContainer::InlineContainer(RenderStyle&& style, BaseTypeFlags baseTypeFlags)
    40     : Container(WTFMove(style), baseTypeFlags | InlineContainerFlag)
     39InlineContainer::InlineContainer(std::optional<ElementAttributes> attributes, RenderStyle&& style, BaseTypeFlags baseTypeFlags)
     40    : Container(attributes, WTFMove(style), baseTypeFlags | InlineContainerFlag)
    4141{
    4242}
  • trunk/Source/WebCore/layout/layouttree/LayoutInlineContainer.h

    r231141 r232350  
    4343
    4444protected:
    45     InlineContainer(RenderStyle&&, BaseTypeFlags = InlineContainerFlag);
     45    InlineContainer(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags = InlineContainerFlag);
    4646};
    4747
  • trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp

    r231897 r232350  
    3030
    3131#include "LayoutBlockContainer.h"
     32#include "LayoutBox.h"
    3233#include "LayoutChildIterator.h"
    3334#include "LayoutContainer.h"
     
    4748std::unique_ptr<Container> TreeBuilder::createLayoutTree(const RenderView& renderView)
    4849{
    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())));
    5051    TreeBuilder::createSubTree(renderView, *initialContainingBlock);
    5152    return initialContainingBlock;
     
    5455void TreeBuilder::createSubTree(const RenderElement& rootRenderer, Container& rootContainer)
    5556{
     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
    5679    // Skip RenderText (and some others) for now.
    5780    for (auto& child : childrenOfType<RenderElement>(rootRenderer)) {
    5881        Box* box = nullptr;
     82
    5983        if (is<RenderBlock>(child)) {
    60             box = new BlockContainer(RenderStyle::clone(child.style()));
     84            box = new BlockContainer(elementAttributes(child), RenderStyle::clone(child.style()));
    6185            createSubTree(child, downcast<Container>(*box));
    6286        } else if (is<RenderInline>(child)) {
    63             box = new InlineContainer(RenderStyle::clone(child.style()));
     87            box = new InlineContainer(elementAttributes(child), RenderStyle::clone(child.style()));
    6488            createSubTree(child, downcast<Container>(*box));
    6589        } else
Note: See TracChangeset for help on using the changeset viewer.