Changeset 271133 in webkit


Ignore:
Timestamp:
Jan 4, 2021 10:13:04 AM (3 years ago)
Author:
Simon Fraser
Message:

[LFC Display] Give display boxes a back reference to the tree
https://bugs.webkit.org/show_bug.cgi?id=220205

Reviewed by Zalan Bujtas.

Display box code will need a back pointer to the display tree for things
like paint invalidation. Pass a Tree& to box constructors, which requires
that the Tree has been constructed before we make any boxes.

  • display/DisplayTree.cpp:

(WebCore::Display::Tree::setRootStackingItem):
(WebCore::Display::Tree::Tree): Deleted.

  • display/DisplayTree.h:

(WebCore::Display::Tree::view const):
(WebCore::Display::Tree::setView):

  • display/DisplayTreeBuilder.cpp:

(WebCore::Display::TreeBuilder::TreeBuilder):
(WebCore::Display::TreeBuilder::build):

  • display/DisplayTreeBuilder.h:

(WebCore::Display::TreeBuilder::tree const):

  • display/css/DisplayBox.cpp:

(WebCore::Display::Box::Box):

  • display/css/DisplayBox.h:

(WebCore::Display::Box::Box):

  • display/css/DisplayBoxFactory.cpp:

(WebCore::Display::BoxFactory::BoxFactory):
(WebCore::Display::BoxFactory::displayBoxForRootBox const):
(WebCore::Display::BoxFactory::displayBoxForLayoutBox const):
(WebCore::Display::BoxFactory::displayBoxForTextRun const):

  • display/css/DisplayBoxFactory.h:
  • display/css/DisplayBoxModelBox.cpp:

(WebCore::Display::BoxModelBox::BoxModelBox):

  • display/css/DisplayBoxModelBox.h:

(WebCore::Display::BoxModelBox::BoxModelBox):

  • display/css/DisplayContainerBox.cpp:

(WebCore::Display::ContainerBox::ContainerBox):

  • display/css/DisplayContainerBox.h:
  • display/css/DisplayImageBox.cpp:

(WebCore::Display::ImageBox::ImageBox):

  • display/css/DisplayImageBox.h:
  • display/css/DisplayReplacedBox.cpp:

(WebCore::Display::ReplacedBox::ReplacedBox):

  • display/css/DisplayReplacedBox.h:
  • display/css/DisplayTextBox.cpp:

(WebCore::Display::TextBox::TextBox):

  • display/css/DisplayTextBox.h:
Location:
trunk/Source/WebCore
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r271131 r271133  
     12020-12-30  Simon Fraser  <simon.fraser@apple.com>
     2
     3        [LFC Display] Give display boxes a back reference to the tree
     4        https://bugs.webkit.org/show_bug.cgi?id=220205
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        Display box code will need a back pointer to the display tree for things
     9        like paint invalidation. Pass a Tree& to box constructors, which requires
     10        that the Tree has been constructed before we make any boxes.
     11
     12        * display/DisplayTree.cpp:
     13        (WebCore::Display::Tree::setRootStackingItem):
     14        (WebCore::Display::Tree::Tree): Deleted.
     15        * display/DisplayTree.h:
     16        (WebCore::Display::Tree::view const):
     17        (WebCore::Display::Tree::setView):
     18        * display/DisplayTreeBuilder.cpp:
     19        (WebCore::Display::TreeBuilder::TreeBuilder):
     20        (WebCore::Display::TreeBuilder::build):
     21        * display/DisplayTreeBuilder.h:
     22        (WebCore::Display::TreeBuilder::tree const):
     23        * display/css/DisplayBox.cpp:
     24        (WebCore::Display::Box::Box):
     25        * display/css/DisplayBox.h:
     26        (WebCore::Display::Box::Box):
     27        * display/css/DisplayBoxFactory.cpp:
     28        (WebCore::Display::BoxFactory::BoxFactory):
     29        (WebCore::Display::BoxFactory::displayBoxForRootBox const):
     30        (WebCore::Display::BoxFactory::displayBoxForLayoutBox const):
     31        (WebCore::Display::BoxFactory::displayBoxForTextRun const):
     32        * display/css/DisplayBoxFactory.h:
     33        * display/css/DisplayBoxModelBox.cpp:
     34        (WebCore::Display::BoxModelBox::BoxModelBox):
     35        * display/css/DisplayBoxModelBox.h:
     36        (WebCore::Display::BoxModelBox::BoxModelBox):
     37        * display/css/DisplayContainerBox.cpp:
     38        (WebCore::Display::ContainerBox::ContainerBox):
     39        * display/css/DisplayContainerBox.h:
     40        * display/css/DisplayImageBox.cpp:
     41        (WebCore::Display::ImageBox::ImageBox):
     42        * display/css/DisplayImageBox.h:
     43        * display/css/DisplayReplacedBox.cpp:
     44        (WebCore::Display::ReplacedBox::ReplacedBox):
     45        * display/css/DisplayReplacedBox.h:
     46        * display/css/DisplayTextBox.cpp:
     47        (WebCore::Display::TextBox::TextBox):
     48        * display/css/DisplayTextBox.h:
     49
    1502021-01-04  Jeff Miller  <jeffm@apple.com>
    251
  • trunk/Source/WebCore/display/DisplayTree.cpp

    r270474 r271133  
    3131#include "DisplayContainerBox.h"
    3232#include "DisplayStackingItem.h"
     33#include "DisplayView.h"
    3334#include <wtf/IsoMallocInlines.h>
    3435
     
    3637namespace Display {
    3738
    38 Tree::Tree(std::unique_ptr<StackingItem>&& rootStackingItem)
    39     : m_rootStackingItem(WTFMove(rootStackingItem))
     39Tree::Tree() = default;
     40Tree::~Tree() = default;
     41
     42void Tree::setRootStackingItem(std::unique_ptr<StackingItem>&& rootItem)
    4043{
    41     ASSERT(m_rootStackingItem);
     44    m_rootStackingItem = WTFMove(rootItem);
    4245}
    43 
    44 Tree::~Tree() = default;
    4546
    4647const ContainerBox& Tree::rootBox() const
  • trunk/Source/WebCore/display/DisplayTree.h

    r270474 r271133  
    3535class ContainerBox;
    3636class StackingItem;
     37class View;
    3738
    3839class Tree {
    3940    WTF_MAKE_FAST_ALLOCATED(Tree);
     41    friend class TreeBuilder;
    4042public:
    41     explicit Tree(std::unique_ptr<StackingItem>&&);
     43    Tree();
    4244    ~Tree();
     45   
     46    View* view() const { return m_view; }
     47    void setView(View* view) { m_view = view; }
    4348
    4449    const StackingItem& rootStackingItem() const { return *m_rootStackingItem; }
    45     const ContainerBox& rootBox() const;
     50     const ContainerBox& rootBox() const;
    4651
    4752private:
     53    void setRootStackingItem(std::unique_ptr<StackingItem>&&);
     54
    4855    std::unique_ptr<StackingItem> m_rootStackingItem;
     56    View* m_view { nullptr };
    4957};
    5058
  • trunk/Source/WebCore/display/DisplayTreeBuilder.cpp

    r271109 r271133  
    110110
    111111TreeBuilder::TreeBuilder(float pixelSnappingFactor)
    112     : m_boxFactory(pixelSnappingFactor)
     112    : m_boxFactory(*this, pixelSnappingFactor)
    113113    , m_stateStack(makeUnique<Vector<BuildingState>>())
    114114{
     
    127127    LOG_WITH_STREAM(FormattingContextLayout, stream << "Building display tree for:\n" << layoutTreeAsText(rootLayoutBox, &layoutState));
    128128#endif
     129
     130    ASSERT(!m_tree);
     131    m_tree = makeUnique<Tree>();
    129132
    130133    m_rootBackgroundPropgation = BoxFactory::determineRootBackgroundPropagation(rootLayoutBox);
     
    145148    LOG_WITH_STREAM(FormattingContextLayout, stream << "Display tree:\n" << displayTreeAsText(*rootStackingItem));
    146149#endif
    147     return makeUnique<Tree>(WTFMove(rootStackingItem));
     150    m_tree->setRootStackingItem(WTFMove(rootStackingItem));
     151    return WTFMove(m_tree);
    148152}
    149153
  • trunk/Source/WebCore/display/DisplayTreeBuilder.h

    r271109 r271133  
    5656
    5757class TreeBuilder {
     58    friend class BoxFactory;
    5859public:
    5960    explicit TreeBuilder(float pixelSnappingFactor);
     
    8283    void didAppendNonContainerStackingItem(StackingItem&);
    8384
     85    Tree& tree() const { return *m_tree; }
     86
    8487    BuildingState& currentState();
    8588    const PositioningContext& positioningContext();
     
    8891    RootBackgroundPropagation m_rootBackgroundPropgation { RootBackgroundPropagation::None };
    8992
     93    std::unique_ptr<Tree> m_tree;
    9094    std::unique_ptr<Vector<BuildingState>> m_stateStack;
    9195};
  • trunk/Source/WebCore/display/css/DisplayBox.cpp

    r271123 r271133  
    2929#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
    3030
     31#include "DisplayTree.h"
    3132#include "FillLayer.h"
    3233#include "ShadowData.h"
     
    3738namespace Display {
    3839
    39 Box::Box(AbsoluteFloatRect absoluteRect, Style&& displayStyle, OptionSet<TypeFlags> flags)
    40     : m_absoluteBoxRect(absoluteRect)
     40Box::Box(Tree& tree, AbsoluteFloatRect absoluteRect, Style&& displayStyle, OptionSet<TypeFlags> flags)
     41    : m_tree(tree)
     42    , m_absoluteBoxRect(absoluteRect)
    4143    , m_style(WTFMove(displayStyle))
    4244    , m_typeFlags(flags)
    4345{
     46    UNUSED_PARAM(m_tree);
    4447}
    4548
  • trunk/Source/WebCore/display/css/DisplayBox.h

    r271123 r271133  
    3636namespace Display {
    3737
     38class Tree;
     39
    3840// FIXME: Make this a strong type.
    3941using AbsoluteFloatRect = FloatRect;
     
    5052    };
    5153
    52     Box(AbsoluteFloatRect, Style&&, OptionSet<TypeFlags> = { });
     54    Box(Tree&, AbsoluteFloatRect, Style&&, OptionSet<TypeFlags> = { });
    5355    virtual ~Box();
    5456
     
    7678    virtual const char* boxName() const;
    7779
     80    const Tree& m_tree;
    7881    AbsoluteFloatRect m_absoluteBoxRect;
    7982    Style m_style;
  • trunk/Source/WebCore/display/css/DisplayBoxFactory.cpp

    r271123 r271133  
    3737#include "DisplayImageBox.h"
    3838#include "DisplayTextBox.h"
     39#include "DisplayTree.h"
     40#include "DisplayTreeBuilder.h"
    3941#include "FloatPoint3D.h"
    4042#include "InlineLineGeometry.h"
     
    4951namespace Display {
    5052
    51 BoxFactory::BoxFactory(float pixelSnappingFactor)
    52     : m_pixelSnappingFactor(pixelSnappingFactor)
     53BoxFactory::BoxFactory(TreeBuilder& builder, float pixelSnappingFactor)
     54    : m_treeBuilder(builder)
     55    , m_pixelSnappingFactor(pixelSnappingFactor)
    5356{
    5457}
     
    8689    auto style = Style { rootLayoutBox.style(), styleForBackground };
    8790
    88     auto rootBox = makeUnique<ContainerBox>(snapRectToDevicePixels(borderBoxRect, m_pixelSnappingFactor), WTFMove(style));
     91    auto rootBox = makeUnique<ContainerBox>(m_treeBuilder.tree(), snapRectToDevicePixels(borderBoxRect, m_pixelSnappingFactor), WTFMove(style));
    8992    // We pass rootBox as its own containingBlockBox here to allow it to be a reference everywhere else.
    9093    setupBoxModelBox(*rootBox, rootLayoutBox, geometry, { *rootBox, { 0, 0 } }, styleForBackground);
     
    124127            image = cachedImage->image();
    125128
    126         auto imageBox = makeUnique<ImageBox>(pixelSnappedBorderBoxRect, WTFMove(style), WTFMove(image));
     129        auto imageBox = makeUnique<ImageBox>(m_treeBuilder.tree(), pixelSnappedBorderBoxRect, WTFMove(style), WTFMove(image));
    127130        setupBoxModelBox(*imageBox, layoutBox, geometry, containingBlockContext, styleForBackground);
    128131        return imageBox;
     
    131134    if (is<Layout::ContainerBox>(layoutBox)) {
    132135        // FIXME: The decision to make a ContainerBox should be made based on whether this Display::Box will have children.
    133         auto containerBox = makeUnique<ContainerBox>(pixelSnappedBorderBoxRect, WTFMove(style));
     136        auto containerBox = makeUnique<ContainerBox>(m_treeBuilder.tree(), pixelSnappedBorderBoxRect, WTFMove(style));
    134137        setupBoxModelBox(*containerBox, layoutBox, geometry, containingBlockContext, styleForBackground);
    135138        return containerBox;
     
    141144        flags.add(Box::TypeFlags::LineBreakBox);
    142145
    143     return makeUnique<Box>(snapRectToDevicePixels(borderBoxRect, m_pixelSnappingFactor), WTFMove(style), flags);
     146    return makeUnique<Box>(m_treeBuilder.tree(), snapRectToDevicePixels(borderBoxRect, m_pixelSnappingFactor), WTFMove(style), flags);
    144147}
    145148
     
    155158
    156159    auto style = Style { run.layoutBox().style() };
    157     return makeUnique<TextBox>(snapRectToDevicePixels(runRect, m_pixelSnappingFactor), WTFMove(style), run);
     160    return makeUnique<TextBox>(m_treeBuilder.tree(), snapRectToDevicePixels(runRect, m_pixelSnappingFactor), WTFMove(style), run);
    158161}
    159162
  • trunk/Source/WebCore/display/css/DisplayBoxFactory.h

    r270474 r271133  
    5353class ContainerBox;
    5454class Style;
     55class TreeBuilder;
    5556
    5657enum class RootBackgroundPropagation : uint8_t {
     
    6667class BoxFactory {
    6768public:
    68     explicit BoxFactory(float pixelSnappingFactor);
    69 
     69    BoxFactory(TreeBuilder&, float pixelSnappingFactor);
     70   
    7071    static RootBackgroundPropagation determineRootBackgroundPropagation(const Layout::ContainerBox& rootLayoutBox);
    7172
     
    9293    static const Layout::Box* bodyBoxFromRootBox(const Layout::ContainerBox& rootLayoutBox);
    9394
     95    TreeBuilder& m_treeBuilder;
    9496    float m_pixelSnappingFactor { 1 };
    9597};
  • trunk/Source/WebCore/display/css/DisplayBoxModelBox.cpp

    r271123 r271133  
    3939namespace Display {
    4040
    41 BoxModelBox::BoxModelBox(AbsoluteFloatRect borderBox, Style&& displayStyle, OptionSet<TypeFlags> flags)
    42     : Box(borderBox, WTFMove(displayStyle), flags | TypeFlags::BoxModelBox)
     41BoxModelBox::BoxModelBox(Tree& tree, AbsoluteFloatRect borderBox, Style&& displayStyle, OptionSet<TypeFlags> flags)
     42    : Box(tree, borderBox, WTFMove(displayStyle), flags | TypeFlags::BoxModelBox)
    4343{
    4444}
  • trunk/Source/WebCore/display/css/DisplayBoxModelBox.h

    r271123 r271133  
    4444    friend class BoxFactory;
    4545public:
    46     BoxModelBox(AbsoluteFloatRect borderBox, Style&&, OptionSet<TypeFlags> = { });
     46    BoxModelBox(Tree&, AbsoluteFloatRect borderBox, Style&&, OptionSet<TypeFlags> = { });
    4747    virtual ~BoxModelBox();
    4848
  • trunk/Source/WebCore/display/css/DisplayContainerBox.cpp

    r271123 r271133  
    3636namespace Display {
    3737
    38 ContainerBox::ContainerBox(AbsoluteFloatRect borderBox, Style&& displayStyle)
    39     : BoxModelBox(borderBox, WTFMove(displayStyle), { TypeFlags::ContainerBox })
     38ContainerBox::ContainerBox(Tree& tree, AbsoluteFloatRect borderBox, Style&& displayStyle)
     39    : BoxModelBox(tree, borderBox, WTFMove(displayStyle), { TypeFlags::ContainerBox })
    4040{
    4141}
  • trunk/Source/WebCore/display/css/DisplayContainerBox.h

    r271108 r271133  
    3636    WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(ContainerBox);
    3737public:
    38     ContainerBox(AbsoluteFloatRect borderBox, Style&&);
     38    ContainerBox(Tree&, AbsoluteFloatRect borderBox, Style&&);
    3939   
    4040    const Box* firstChild() const { return m_firstChild.get(); }
  • trunk/Source/WebCore/display/css/DisplayImageBox.cpp

    r271123 r271133  
    3535namespace Display {
    3636
    37 ImageBox::ImageBox(AbsoluteFloatRect borderBox, Style&& displayStyle, RefPtr<Image>&& image)
    38     : ReplacedBox(borderBox, WTFMove(displayStyle), { TypeFlags::ImageBox })
     37ImageBox::ImageBox(Tree& tree, AbsoluteFloatRect borderBox, Style&& displayStyle, RefPtr<Image>&& image)
     38    : ReplacedBox(tree, borderBox, WTFMove(displayStyle), { TypeFlags::ImageBox })
    3939    , m_image(WTFMove(image))
    4040{
  • trunk/Source/WebCore/display/css/DisplayImageBox.h

    r271108 r271133  
    4141    WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(ImageBox);
    4242public:
    43     ImageBox(AbsoluteFloatRect borderBox, Style&&, RefPtr<Image>&&);
     43    ImageBox(Tree&, AbsoluteFloatRect borderBox, Style&&, RefPtr<Image>&&);
    4444
    4545    Image* image() const { return m_image.get(); }
  • trunk/Source/WebCore/display/css/DisplayReplacedBox.cpp

    r271123 r271133  
    3434namespace Display {
    3535
    36 ReplacedBox::ReplacedBox(AbsoluteFloatRect borderBox, Style&& displayStyle, OptionSet<TypeFlags> flags)
    37     : BoxModelBox(borderBox, WTFMove(displayStyle), flags)
     36ReplacedBox::ReplacedBox(Tree& tree, AbsoluteFloatRect borderBox, Style&& displayStyle, OptionSet<TypeFlags> flags)
     37    : BoxModelBox(tree, borderBox, WTFMove(displayStyle), flags)
    3838{
    3939}
  • trunk/Source/WebCore/display/css/DisplayReplacedBox.h

    r271123 r271133  
    3737    friend class BoxFactory;
    3838public:
    39     ReplacedBox(AbsoluteFloatRect borderBox, Style&&, OptionSet<TypeFlags>);
     39    ReplacedBox(Tree&, AbsoluteFloatRect borderBox, Style&&, OptionSet<TypeFlags>);
    4040   
    4141    AbsoluteFloatRect replacedContentRect() const { return m_replacedContentRect; }
  • trunk/Source/WebCore/display/css/DisplayTextBox.cpp

    r271123 r271133  
    3535namespace Display {
    3636
    37 TextBox::TextBox(AbsoluteFloatRect borderBox, Style&& displayStyle, const Layout::LineRun& lineRun)
    38     : Box(borderBox, WTFMove(displayStyle), { TypeFlags::TextBox })
     37TextBox::TextBox(Tree& tree, AbsoluteFloatRect borderBox, Style&& displayStyle, const Layout::LineRun& lineRun)
     38    : Box(tree, borderBox, WTFMove(displayStyle), { TypeFlags::TextBox })
    3939    , m_expansion(lineRun.expansion())
    4040    , m_text(lineRun.text().value())
  • trunk/Source/WebCore/display/css/DisplayTextBox.h

    r271108 r271133  
    3737    WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(TextBox);
    3838public:
    39 
    40     TextBox(AbsoluteFloatRect borderBox, Style&&, const Layout::LineRun&);
     39    TextBox(Tree&, AbsoluteFloatRect borderBox, Style&&, const Layout::LineRun&);
    4140
    4241    Layout::LineRun::Expansion expansion() const { return m_expansion; }
Note: See TracChangeset for help on using the changeset viewer.