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 "core/rendering/RenderBlockFlow.h"
35 #include "wtf/HashCountedSet.h"
36 #include "wtf/ListHashSet.h"
37 #include "wtf/PassRefPtr.h"
42 typedef Vector<LayerFragment, 1> LayerFragments;
43 class RenderFlowThread;
47 typedef ListHashSet<RenderRegion*> RenderRegionList;
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.
55 class RenderFlowThread: public RenderBlockFlow {
58 virtual ~RenderFlowThread() { };
60 virtual bool isRenderFlowThread() const OVERRIDE FINAL { return true; }
61 virtual bool isRenderMultiColumnFlowThread() const { return false; }
63 virtual void layout() OVERRIDE;
65 // Always create a RenderLayer for the RenderFlowThread so that we
66 // can easily avoid drawing the children directly.
67 virtual LayerType layerTypeRequired() const OVERRIDE FINAL { return NormalLayer; }
69 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE FINAL;
71 virtual void addRegionToThread(RenderRegion*) = 0;
72 virtual void removeRegionFromThread(RenderRegion*);
73 const RenderRegionList& renderRegionList() const { return m_regionList; }
75 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const OVERRIDE;
77 bool hasRegions() const { return m_regionList.size(); }
79 void validateRegions();
80 void invalidateRegions();
81 bool hasValidRegionInfo() const { return !m_regionsInvalidated && !m_regionList.isEmpty(); }
83 void repaintRectangleInRegions(const LayoutRect&) const;
85 LayoutPoint adjustedPositionRelativeToOffsetParent(const RenderBoxModelObject&, const LayoutPoint&);
87 LayoutUnit pageLogicalTopForOffset(LayoutUnit);
88 LayoutUnit pageLogicalHeightForOffset(LayoutUnit);
89 LayoutUnit pageRemainingLogicalHeightForOffset(LayoutUnit, PageBoundaryRule = IncludePageBoundary);
91 virtual void setPageBreak(LayoutUnit /*offset*/, LayoutUnit /*spaceShortage*/) { }
92 virtual void updateMinimumPageHeight(LayoutUnit /*offset*/, LayoutUnit /*minHeight*/) { }
94 virtual RenderRegion* regionAtBlockOffset(LayoutUnit) const;
96 bool regionsHaveUniformLogicalHeight() const { return m_regionsHaveUniformLogicalHeight; }
98 RenderRegion* firstRegion() const;
99 RenderRegion* lastRegion() const;
101 void setRegionRangeForBox(const RenderBox*, LayoutUnit offsetFromLogicalTopOfFirstPage);
102 void getRegionRangeForBox(const RenderBox*, RenderRegion*& startRegion, RenderRegion*& endRegion) const;
104 virtual bool addForcedRegionBreak(LayoutUnit, RenderObject* breakChild, bool isBefore, LayoutUnit* offsetBreakAdjustment = 0) { return false; }
106 virtual bool isPageLogicalHeightKnown() const { return true; }
107 bool pageLogicalSizeChanged() const { return m_pageLogicalSizeChanged; }
109 void collectLayerFragments(LayerFragments&, const LayoutRect& layerBoundingBox, const LayoutRect& dirtyRect);
110 LayoutRect fragmentsBoundingBox(const LayoutRect& layerBoundingBox);
112 void pushFlowThreadLayoutState(const RenderObject&);
113 void popFlowThreadLayoutState();
114 LayoutUnit offsetFromLogicalTopOfFirstRegion(const RenderBlock*) const;
116 // Used to estimate the maximum height of the flow thread.
117 static LayoutUnit maxLogicalHeight() { return LayoutUnit::max() / 2; }
120 virtual const char* renderName() const = 0;
122 void updateRegionsFlowThreadPortionRect();
123 bool shouldRepaint(const LayoutRect&) const;
125 bool cachedOffsetFromLogicalTopOfFirstRegion(const RenderBox*, LayoutUnit&) const;
126 void setOffsetFromLogicalTopOfFirstRegion(const RenderBox*, LayoutUnit);
127 void clearOffsetFromLogicalTopOfFirstRegion(const RenderBox*);
129 const RenderBox* currentStatePusherRenderBox() const;
131 RenderRegionList m_regionList;
133 class RenderRegionRange {
140 RenderRegionRange(RenderRegion* start, RenderRegion* end)
142 setRange(start, end);
145 void setRange(RenderRegion* start, RenderRegion* end)
147 m_startRegion = start;
151 RenderRegion* startRegion() const { return m_startRegion; }
152 RenderRegion* endRegion() const { return m_endRegion; }
155 RenderRegion* m_startRegion;
156 RenderRegion* m_endRegion;
159 typedef PODInterval<LayoutUnit, RenderRegion*> RegionInterval;
160 typedef PODIntervalTree<LayoutUnit, RenderRegion*> RegionIntervalTree;
162 class RegionSearchAdapter {
164 RegionSearchAdapter(LayoutUnit offset)
170 const LayoutUnit& lowValue() const { return m_offset; }
171 const LayoutUnit& highValue() const { return m_offset; }
172 void collectIfNeeded(const RegionInterval&);
174 RenderRegion* result() const { return m_result; }
178 RenderRegion* m_result;
181 // A maps from RenderBox
182 typedef HashMap<const RenderBox*, RenderRegionRange> RenderRegionRangeMap;
183 RenderRegionRangeMap m_regionRangeMap;
185 // Stack of objects that pushed a LayoutState object on the RenderView. The
186 // objects on the stack are the ones that are curently in the process of being
188 ListHashSet<const RenderObject*> m_statePusherObjectsStack;
189 typedef HashMap<const RenderBox*, LayoutUnit> RenderBoxToOffsetMap;
190 RenderBoxToOffsetMap m_boxesToOffsetMap;
192 RegionIntervalTree m_regionIntervalTree;
194 bool m_regionsInvalidated : 1;
195 bool m_regionsHaveUniformLogicalHeight : 1;
196 bool m_pageLogicalSizeChanged : 1;
199 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderFlowThread, isRenderFlowThread());
201 class CurrentRenderFlowThreadMaintainer {
202 WTF_MAKE_NONCOPYABLE(CurrentRenderFlowThreadMaintainer);
204 CurrentRenderFlowThreadMaintainer(RenderFlowThread*);
205 ~CurrentRenderFlowThreadMaintainer();
207 RenderFlowThread* m_renderFlowThread;
208 RenderFlowThread* m_previousRenderFlowThread;
211 // These structures are used by PODIntervalTree for debugging.
213 template <> struct ValueToString<LayoutUnit> {
214 static String string(const LayoutUnit value) { return String::number(value.toFloat()); }
217 template <> struct ValueToString<RenderRegion*> {
218 static String string(const RenderRegion* value) { return String::format("%p", value); }
222 } // namespace WebCore
224 #endif // RenderFlowThread_h