2 * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
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.
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
30 #ifndef RenderFlowThread_h
31 #define RenderFlowThread_h
34 #include "RenderBlock.h"
35 #include <wtf/HashCountedSet.h>
36 #include <wtf/ListHashSet.h>
37 #include <wtf/PassRefPtr.h>
38 #include <wtf/UnusedParam.h>
42 class RenderFlowThread;
46 typedef ListHashSet<RenderRegion*> RenderRegionList;
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.
54 class RenderFlowThread: public RenderBlock {
56 RenderFlowThread(Node*);
57 virtual ~RenderFlowThread() { };
59 virtual bool isRenderFlowThread() const { return true; }
61 virtual void layout();
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; }
67 void removeFlowChildInfo(RenderObject*);
69 bool hasChildInfo(RenderObject* child) const { return child && child->isBox() && m_regionRangeMap.contains(toRenderBox(child)); }
72 virtual void addRegionToThread(RenderRegion*);
73 virtual void removeRegionFromThread(RenderRegion*);
74 const RenderRegionList& renderRegionList() const { return m_regionList; }
76 void computeLogicalWidth();
77 void computeLogicalHeight();
79 void paintIntoRegion(PaintInfo&, RenderRegion*, const LayoutPoint& paintOffset);
80 bool hitTestRegion(RenderRegion*, const HitTestRequest&, HitTestResult&, const HitTestPoint& pointInContainer, const LayoutPoint& accumulatedOffset);
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();
88 void invalidateRegions() { m_regionsInvalidated = true; setNeedsLayout(true); }
89 bool hasValidRegionInfo() const { return !m_regionsInvalidated && hasValidRegions(); }
91 static PassRefPtr<RenderStyle> createFlowThreadStyle(RenderStyle* parentStyle);
93 void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
95 void repaintRectangleInRegions(const LayoutRect&, bool immediate);
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;
103 bool regionsHaveUniformLogicalWidth() const { return m_regionsHaveUniformLogicalWidth; }
104 bool regionsHaveUniformLogicalHeight() const { return m_regionsHaveUniformLogicalHeight; }
106 RenderRegion* mapFromFlowToRegion(TransformState&) const;
108 void removeRenderBoxRegionInfo(RenderBox*);
109 bool logicalWidthChangedInRegions(const RenderBlock*, LayoutUnit offsetFromLogicalTopOfFirstPage);
111 LayoutUnit contentLogicalWidthOfFirstRegion() const;
112 LayoutUnit contentLogicalHeightOfFirstRegion() const;
113 LayoutUnit contentLogicalLeftOfFirstRegion() const;
115 RenderRegion* firstRegion() const;
116 RenderRegion* lastRegion() const;
118 void setRegionRangeForBox(const RenderBox*, LayoutUnit offsetFromLogicalTopOfFirstPage);
119 void getRegionRangeForBox(const RenderBox*, RenderRegion*& startRegion, RenderRegion*& endRegion) const;
121 void clearRenderObjectCustomStyle(const RenderObject*,
122 const RenderRegion* oldStartRegion = 0, const RenderRegion* oldEndRegion = 0,
123 const RenderRegion* newStartRegion = 0, const RenderRegion* newEndRegion = 0);
125 void computeOverflowStateForRegions(LayoutUnit oldClientAfterEdge);
127 bool overset() const { return m_overset; }
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;
133 virtual const char* renderName() const = 0;
135 bool shouldRepaint(const LayoutRect&) const;
136 void regionLayoutUpdateEventTimerFired(Timer<RenderFlowThread>*);
137 bool regionInRange(const RenderRegion* targetRegion, const RenderRegion* startRegion, const RenderRegion* endRegion) const;
139 RenderRegionList m_regionList;
141 class RenderRegionRange {
148 RenderRegionRange(RenderRegion* start, RenderRegion* end)
150 setRange(start, end);
153 void setRange(RenderRegion* start, RenderRegion* end)
155 m_startRegion = start;
159 RenderRegion* startRegion() const { return m_startRegion; }
160 RenderRegion* endRegion() const { return m_endRegion; }
163 RenderRegion* m_startRegion;
164 RenderRegion* m_endRegion;
167 // A maps from RenderBox
168 typedef HashMap<const RenderBox*, RenderRegionRange> RenderRegionRangeMap;
169 RenderRegionRangeMap m_regionRangeMap;
171 bool m_hasValidRegions;
172 bool m_regionsInvalidated;
173 bool m_regionsHaveUniformLogicalWidth;
174 bool m_regionsHaveUniformLogicalHeight;
176 bool m_hasRegionsWithStyling;
177 Timer<RenderFlowThread> m_regionLayoutUpdateEventTimer;
180 inline RenderFlowThread* toRenderFlowThread(RenderObject* object)
182 ASSERT(!object || object->isRenderFlowThread());
183 return static_cast<RenderFlowThread*>(object);
186 inline const RenderFlowThread* toRenderFlowThread(const RenderObject* object)
188 ASSERT(!object || object->isRenderFlowThread());
189 return static_cast<const RenderFlowThread*>(object);
192 // This will catch anyone doing an unnecessary cast.
193 void toRenderFlowThread(const RenderFlowThread*);
195 } // namespace WebCore
197 #endif // RenderFlowThread_h