Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / RenderFlowThread.h
1 /*
2  * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above
9  *    copyright notice, this list of conditions and the following
10  *    disclaimer.
11  * 2. Redistributions in binary form must reproduce the above
12  *    copyright notice, this list of conditions and the following
13  *    disclaimer in the documentation and/or other materials
14  *    provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
25  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
26  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29
30 #ifndef RenderFlowThread_h
31 #define RenderFlowThread_h
32
33
34 #include "core/rendering/RenderBlockFlow.h"
35 #include "wtf/HashCountedSet.h"
36 #include "wtf/ListHashSet.h"
37 #include "wtf/PassRefPtr.h"
38
39 namespace blink {
40
41 struct LayerFragment;
42 typedef Vector<LayerFragment, 1> LayerFragments;
43 class RenderFlowThread;
44 class RenderMultiColumnSet;
45 class RenderRegion;
46
47 typedef ListHashSet<RenderMultiColumnSet*> RenderMultiColumnSetList;
48
49 // RenderFlowThread is used to collect all the render objects that participate in a
50 // flow thread. It will also help in doing the layout. However, it will not render
51 // directly to screen. Instead, RenderRegion objects will redirect their paint
52 // and nodeAtPoint methods to this object. Each RenderRegion will actually be a viewPort
53 // of the RenderFlowThread.
54
55 class RenderFlowThread: public RenderBlockFlow {
56 public:
57     RenderFlowThread();
58     virtual ~RenderFlowThread() { };
59
60     virtual bool isRenderFlowThread() const override final { return true; }
61     virtual bool isRenderMultiColumnFlowThread() const { return false; }
62     virtual bool isRenderPagedFlowThread() const { return false; }
63
64     virtual void layout() override;
65
66     // Always create a RenderLayer for the RenderFlowThread so that we
67     // can easily avoid drawing the children directly.
68     virtual LayerType layerTypeRequired() const override final { return NormalLayer; }
69
70     virtual void flowThreadDescendantWasInserted(RenderObject*) { }
71
72     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) override final;
73
74     virtual void addRegionToThread(RenderMultiColumnSet*) = 0;
75     virtual void removeRegionFromThread(RenderMultiColumnSet*);
76
77     virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const override;
78
79     bool hasRegions() const { return m_multiColumnSetList.size(); }
80
81     void validateRegions();
82     void invalidateRegions();
83     bool hasValidRegionInfo() const { return !m_regionsInvalidated && !m_multiColumnSetList.isEmpty(); }
84
85     void paintInvalidationRectangleInRegions(const LayoutRect&) const;
86
87     LayoutUnit pageLogicalHeightForOffset(LayoutUnit);
88     LayoutUnit pageRemainingLogicalHeightForOffset(LayoutUnit, PageBoundaryRule = IncludePageBoundary);
89
90     virtual void setPageBreak(LayoutUnit /*offset*/, LayoutUnit /*spaceShortage*/) { }
91     virtual void updateMinimumPageHeight(LayoutUnit /*offset*/, LayoutUnit /*minHeight*/) { }
92
93     bool regionsHaveUniformLogicalHeight() const { return m_regionsHaveUniformLogicalHeight; }
94
95     // FIXME: These 2 functions should return a RenderMultiColumnSet.
96     RenderRegion* firstRegion() const;
97     RenderRegion* lastRegion() const;
98
99     virtual bool addForcedRegionBreak(LayoutUnit, RenderObject* breakChild, bool isBefore, LayoutUnit* offsetBreakAdjustment = 0) { return false; }
100
101     virtual bool isPageLogicalHeightKnown() const { return true; }
102     bool pageLogicalSizeChanged() const { return m_pageLogicalSizeChanged; }
103
104     void collectLayerFragments(LayerFragments&, const LayoutRect& layerBoundingBox, const LayoutRect& dirtyRect);
105     LayoutRect fragmentsBoundingBox(const LayoutRect& layerBoundingBox);
106
107     LayoutPoint flowThreadPointToVisualPoint(const LayoutPoint& flowThreadPoint) const
108     {
109         return flowThreadPoint + columnOffset(flowThreadPoint);
110     }
111
112     void pushFlowThreadLayoutState(const RenderObject&);
113     void popFlowThreadLayoutState();
114     LayoutUnit offsetFromLogicalTopOfFirstRegion(const RenderBlock*) const;
115
116     // Used to estimate the maximum height of the flow thread.
117     static LayoutUnit maxLogicalHeight() { return LayoutUnit::max() / 2; }
118
119 protected:
120     virtual const char* renderName() const = 0;
121
122     void updateRegionsFlowThreadPortionRect();
123     bool shouldIssuePaintInvalidations(const LayoutRect&) const;
124
125     virtual RenderMultiColumnSet* columnSetAtBlockOffset(LayoutUnit) const = 0;
126
127     bool cachedOffsetFromLogicalTopOfFirstRegion(const RenderBox*, LayoutUnit&) const;
128     void setOffsetFromLogicalTopOfFirstRegion(const RenderBox*, LayoutUnit);
129     void clearOffsetFromLogicalTopOfFirstRegion(const RenderBox*);
130
131     const RenderBox* currentStatePusherRenderBox() const;
132
133     RenderMultiColumnSetList m_multiColumnSetList;
134
135     typedef PODInterval<LayoutUnit, RenderMultiColumnSet*> MultiColumnSetInterval;
136     typedef PODIntervalTree<LayoutUnit, RenderMultiColumnSet*> MultiColumnSetIntervalTree;
137
138     class RegionSearchAdapter {
139     public:
140         RegionSearchAdapter(LayoutUnit offset)
141             : m_offset(offset)
142             , m_result(0)
143         {
144         }
145
146         const LayoutUnit& lowValue() const { return m_offset; }
147         const LayoutUnit& highValue() const { return m_offset; }
148         void collectIfNeeded(const MultiColumnSetInterval&);
149
150         RenderRegion* result() const { return m_result; }
151
152     private:
153         LayoutUnit m_offset;
154         RenderRegion* m_result;
155     };
156
157     // Stack of objects that pushed a LayoutState object on the RenderView. The
158     // objects on the stack are the ones that are curently in the process of being
159     // laid out.
160     ListHashSet<const RenderObject*> m_statePusherObjectsStack;
161     typedef HashMap<const RenderBox*, LayoutUnit> RenderBoxToOffsetMap;
162     RenderBoxToOffsetMap m_boxesToOffsetMap;
163
164     MultiColumnSetIntervalTree m_multiColumnSetIntervalTree;
165
166     bool m_regionsInvalidated : 1;
167     bool m_regionsHaveUniformLogicalHeight : 1;
168     bool m_pageLogicalSizeChanged : 1;
169 };
170
171 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderFlowThread, isRenderFlowThread());
172
173 class CurrentRenderFlowThreadMaintainer {
174     WTF_MAKE_NONCOPYABLE(CurrentRenderFlowThreadMaintainer);
175 public:
176     CurrentRenderFlowThreadMaintainer(RenderFlowThread*);
177     ~CurrentRenderFlowThreadMaintainer();
178 private:
179     RenderFlowThread* m_renderFlowThread;
180     RenderFlowThread* m_previousRenderFlowThread;
181 };
182
183 // These structures are used by PODIntervalTree for debugging.
184 #ifndef NDEBUG
185 template <> struct ValueToString<LayoutUnit> {
186     static String string(const LayoutUnit value) { return String::number(value.toFloat()); }
187 };
188
189 template <> struct ValueToString<RenderMultiColumnSet*> {
190     static String string(const RenderMultiColumnSet* value) { return String::format("%p", value); }
191 };
192 #endif
193
194 } // namespace blink
195
196 #endif // RenderFlowThread_h