Fix the issue that Web Audio test case fails on PR3.
[framework/web/webkit-efl.git] / Source / WebCore / 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 "RenderBlock.h"
35 #include <wtf/HashCountedSet.h>
36 #include <wtf/ListHashSet.h>
37 #include <wtf/PassRefPtr.h>
38 #include <wtf/UnusedParam.h>
39
40 namespace WebCore {
41
42 class RenderFlowThread;
43 class RenderStyle;
44 class RenderRegion;
45
46 typedef ListHashSet<RenderRegion*> RenderRegionList;
47
48 // RenderFlowThread is used to collect all the render objects that participate in a
49 // flow thread. It will also help in doing the layout. However, it will not render
50 // directly to screen. Instead, RenderRegion objects will redirect their paint 
51 // and nodeAtPoint methods to this object. Each RenderRegion will actually be a viewPort
52 // of the RenderFlowThread.
53
54 class RenderFlowThread: public RenderBlock {
55 public:
56     RenderFlowThread(Node*);
57     virtual ~RenderFlowThread() { };
58     
59     virtual bool isRenderFlowThread() const { return true; }
60
61     virtual void layout();
62
63     // Always create a RenderLayer for the RenderFlowThread so that we 
64     // can easily avoid drawing the children directly.
65     virtual bool requiresLayer() const { return true; }
66     
67     void removeFlowChildInfo(RenderObject*);
68 #ifndef NDEBUG
69     bool hasChildInfo(RenderObject* child) const { return child && child->isBox() && m_regionRangeMap.contains(toRenderBox(child)); }
70 #endif
71
72     virtual void addRegionToThread(RenderRegion*);
73     virtual void removeRegionFromThread(RenderRegion*);
74     const RenderRegionList& renderRegionList() const { return m_regionList; }
75
76     void computeLogicalWidth();
77     void computeLogicalHeight();
78
79     void paintIntoRegion(PaintInfo&, RenderRegion*, const LayoutPoint& paintOffset);
80     bool hitTestRegion(RenderRegion*, const HitTestRequest&, HitTestResult&, const HitTestPoint& pointInContainer, const LayoutPoint& accumulatedOffset);
81
82     bool hasRegions() const { return m_regionList.size(); }
83     bool hasValidRegions() const { ASSERT(!m_regionsInvalidated); return m_hasValidRegions; }
84     // Check if the content is flown into at least a region with region styling rules.
85     bool hasRegionsWithStyling() const { return m_hasRegionsWithStyling; }
86     void checkRegionsWithStyling();
87
88     void invalidateRegions() { m_regionsInvalidated = true; setNeedsLayout(true); }
89     bool hasValidRegionInfo() const { return !m_regionsInvalidated && hasValidRegions(); }
90
91     static PassRefPtr<RenderStyle> createFlowThreadStyle(RenderStyle* parentStyle);
92
93     void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
94
95     void repaintRectangleInRegions(const LayoutRect&, bool immediate);
96
97     LayoutUnit regionLogicalTopForLine(LayoutUnit position) const;
98     LayoutUnit regionLogicalWidthForLine(LayoutUnit position) const;
99     LayoutUnit regionLogicalHeightForLine(LayoutUnit position) const;
100     LayoutUnit regionRemainingLogicalHeightForLine(LayoutUnit position, PageBoundaryRule = IncludePageBoundary) const;
101     RenderRegion* renderRegionForLine(LayoutUnit position, bool extendLastRegion = false) const;
102
103     bool regionsHaveUniformLogicalWidth() const { return m_regionsHaveUniformLogicalWidth; }
104     bool regionsHaveUniformLogicalHeight() const { return m_regionsHaveUniformLogicalHeight; }
105
106     RenderRegion* mapFromFlowToRegion(TransformState&) const;
107
108     void removeRenderBoxRegionInfo(RenderBox*);
109     bool logicalWidthChangedInRegions(const RenderBlock*, LayoutUnit offsetFromLogicalTopOfFirstPage);
110
111     LayoutUnit contentLogicalWidthOfFirstRegion() const;
112     LayoutUnit contentLogicalHeightOfFirstRegion() const;
113     LayoutUnit contentLogicalLeftOfFirstRegion() const;
114     
115     RenderRegion* firstRegion() const;
116     RenderRegion* lastRegion() const;
117
118     void setRegionRangeForBox(const RenderBox*, LayoutUnit offsetFromLogicalTopOfFirstPage);
119     void getRegionRangeForBox(const RenderBox*, RenderRegion*& startRegion, RenderRegion*& endRegion) const;
120
121     void clearRenderObjectCustomStyle(const RenderObject*,
122                                       const RenderRegion* oldStartRegion = 0, const RenderRegion* oldEndRegion = 0,
123                                       const RenderRegion* newStartRegion = 0, const RenderRegion* newEndRegion = 0);
124     
125     void computeOverflowStateForRegions(LayoutUnit oldClientAfterEdge);
126
127     bool overset() const { return m_overset; }
128
129     // Check if the object is in region and the region is part of this flow thread.
130     bool objectInFlowRegion(const RenderObject*, const RenderRegion*) const;
131
132 protected:
133     virtual const char* renderName() const = 0;
134
135     bool shouldRepaint(const LayoutRect&) const;
136     void regionLayoutUpdateEventTimerFired(Timer<RenderFlowThread>*);
137     bool regionInRange(const RenderRegion* targetRegion, const RenderRegion* startRegion, const RenderRegion* endRegion) const;
138
139     RenderRegionList m_regionList;
140
141     class RenderRegionRange {
142     public:
143         RenderRegionRange()
144         {
145             setRange(0, 0);
146         }
147
148         RenderRegionRange(RenderRegion* start, RenderRegion* end)
149         {
150             setRange(start, end);
151         }
152         
153         void setRange(RenderRegion* start, RenderRegion* end)
154         {
155             m_startRegion = start;
156             m_endRegion = end;
157         }
158
159         RenderRegion* startRegion() const { return m_startRegion; }
160         RenderRegion* endRegion() const { return m_endRegion; }
161
162     private:
163         RenderRegion* m_startRegion;
164         RenderRegion* m_endRegion;
165     };
166
167     // A maps from RenderBox
168     typedef HashMap<const RenderBox*, RenderRegionRange> RenderRegionRangeMap;
169     RenderRegionRangeMap m_regionRangeMap;
170
171     bool m_hasValidRegions;
172     bool m_regionsInvalidated;
173     bool m_regionsHaveUniformLogicalWidth;
174     bool m_regionsHaveUniformLogicalHeight;
175     bool m_overset;
176     bool m_hasRegionsWithStyling;
177     Timer<RenderFlowThread> m_regionLayoutUpdateEventTimer;
178 };
179
180 inline RenderFlowThread* toRenderFlowThread(RenderObject* object)
181 {
182     ASSERT(!object || object->isRenderFlowThread());
183     return static_cast<RenderFlowThread*>(object);
184 }
185
186 inline const RenderFlowThread* toRenderFlowThread(const RenderObject* object)
187 {
188     ASSERT(!object || object->isRenderFlowThread());
189     return static_cast<const RenderFlowThread*>(object);
190 }
191
192 // This will catch anyone doing an unnecessary cast.
193 void toRenderFlowThread(const RenderFlowThread*);
194
195 } // namespace WebCore
196
197 #endif // RenderFlowThread_h