summaryrefslogtreecommitdiff
path: root/Source/WebCore/rendering/RenderNamedFlowThread.h
blob: 41aaaf4c270eeac84e99a76751bb7044b08fd138 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
 * Copyright (C) 2012 Apple Inc.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


#ifndef RenderNamedFlowThread_h
#define RenderNamedFlowThread_h

#include "RenderFlowThread.h"
#include "SelectionSubtreeRoot.h"
#include "Timer.h"
#include <wtf/HashCountedSet.h>
#include <wtf/ListHashSet.h>
#include <wtf/text/AtomicString.h>

namespace WebCore {

class Node;
class RenderNamedFlowThread;
class WebKitNamedFlow;

typedef ListHashSet<RenderNamedFlowThread*> RenderNamedFlowThreadList;
typedef HashCountedSet<RenderNamedFlowThread*> RenderNamedFlowThreadCountedSet;
typedef ListHashSet<Element*> NamedFlowContentElements;

class RenderNamedFlowThread final : public RenderFlowThread, public SelectionSubtreeRoot {
public:
    RenderNamedFlowThread(Document&, Ref<RenderStyle>&&, Ref<WebKitNamedFlow>&&);
    virtual ~RenderNamedFlowThread();

    const AtomicString& flowThreadName() const;

    const RenderRegionList& invalidRenderRegionList() const { return m_invalidRegionList; }

    RenderElement* nextRendererForElement(Element&) const;

    void addFlowChild(RenderElement&);
    void removeFlowChild(RenderElement&);
    bool hasChildren() const { return !m_flowThreadChildList.isEmpty(); }
#ifndef NDEBUG
    bool hasChild(RenderElement& child) const { return m_flowThreadChildList.contains(&child); }
#endif

    static RenderBlock* fragmentFromRenderBoxAsRenderBlock(RenderBox*, const IntPoint& absolutePoint, const RenderBox& flowedBox);

    void pushDependencies(RenderNamedFlowThreadList&);

    virtual void addRegionToThread(RenderRegion*) override;
    virtual void removeRegionFromThread(RenderRegion*) override;

    virtual void regionChangedWritingMode(RenderRegion*) override;

    LayoutRect decorationsClipRectForBoxInNamedFlowFragment(const RenderBox&, RenderNamedFlowFragment&) const;

    RenderNamedFlowFragment* fragmentFromAbsolutePointAndBox(const IntPoint&, const RenderBox& flowedBox);

    void registerNamedFlowContentElement(Element&);
    void unregisterNamedFlowContentElement(Element&);
    const NamedFlowContentElements& contentElements() const { return m_contentElements; }
    bool hasContentElement(Element&) const;

    bool isMarkedForDestruction() const;
    void getRanges(Vector<RefPtr<Range>>&, const RenderNamedFlowFragment*) const;

    virtual void applyBreakAfterContent(LayoutUnit) override;

    virtual bool collectsGraphicsLayersUnderRegions() const override;

    // Check if the content is flown into at least a region with region styling rules.
    bool hasRegionsWithStyling() const { return m_hasRegionsWithStyling; }
    void checkRegionsWithStyling();

    void clearRenderObjectCustomStyle(const RenderObject*);

    virtual void removeFlowChildInfo(RenderObject*) override;

    LayoutUnit flowContentBottom() const { return m_flowContentBottom; }
    void dispatchNamedFlowEvents();

    void setDispatchRegionOversetChangeEvent(bool value) { m_dispatchRegionOversetChangeEvent = value; }

    virtual bool absoluteQuadsForBox(Vector<FloatQuad>&, bool*, const RenderBox*, float, float) const override;

protected:
    void setMarkForDestruction();
    void resetMarkForDestruction();

private:
    virtual const char* renderName() const override;
    virtual bool isRenderNamedFlowThread() const override { return true; }
    virtual bool isChildAllowed(const RenderObject&, const RenderStyle&) const override;
    virtual void computeOverflow(LayoutUnit, bool = false) override;
    virtual void layout() override;

    void dispatchRegionOversetChangeEventIfNeeded();

    bool dependsOn(RenderNamedFlowThread* otherRenderFlowThread) const;
    void addDependencyOnFlowThread(RenderNamedFlowThread*);
    void removeDependencyOnFlowThread(RenderNamedFlowThread*);

    void addFragmentToNamedFlowThread(RenderNamedFlowFragment*);

    void checkInvalidRegions();

    bool canBeDestroyed() const { return m_invalidRegionList.isEmpty() && m_regionList.isEmpty() && m_contentElements.isEmpty(); }
    void regionOversetChangeEventTimerFired();
    void clearContentElements();
    void updateWritingMode();

    WebKitNamedFlow& namedFlow() { return m_namedFlow; }
    const WebKitNamedFlow& namedFlow() const { return m_namedFlow; }

    // Observer flow threads have invalid regions that depend on the state of this thread
    // to re-validate their regions. Keeping a set of observer threads make it easy
    // to notify them when a region was removed from this flow.
    RenderNamedFlowThreadCountedSet m_observerThreadsSet;

    // Some threads need to have a complete layout before we layout this flow.
    // That's because they contain a RenderRegion that should display this thread. The set makes it
    // easy to sort the order of threads layout.
    RenderNamedFlowThreadCountedSet m_layoutBeforeThreadsSet;

    // Holds the sorted children of a named flow. This is the only way we can get the ordering right.
    ListHashSet<RenderElement*> m_flowThreadChildList;

    NamedFlowContentElements m_contentElements;

    RenderRegionList m_invalidRegionList;

    bool m_hasRegionsWithStyling : 1;
    bool m_dispatchRegionOversetChangeEvent : 1;

    // The DOM Object that represents a named flow.
    Ref<WebKitNamedFlow> m_namedFlow;

    Timer m_regionOversetChangeEventTimer;

    LayoutUnit m_flowContentBottom;
};

} // namespace WebCore

SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderNamedFlowThread, isRenderNamedFlowThread())

#endif // RenderNamedFlowThread_h