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;
44 class RenderMultiColumnSet;
47 typedef ListHashSet<RenderMultiColumnSet*> RenderMultiColumnSetList;
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; }
62 virtual bool isRenderPagedFlowThread() const { return false; }
64 virtual void layout() override;
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; }
70 virtual void flowThreadDescendantWasInserted(RenderObject*) { }
72 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) override final;
74 virtual void addRegionToThread(RenderMultiColumnSet*) = 0;
75 virtual void removeRegionFromThread(RenderMultiColumnSet*);
77 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const override;
79 bool hasRegions() const { return m_multiColumnSetList.size(); }
81 void validateRegions();
82 void invalidateRegions();
83 bool hasValidRegionInfo() const { return !m_regionsInvalidated && !m_multiColumnSetList.isEmpty(); }
85 void paintInvalidationRectangleInRegions(const LayoutRect&) const;
87 LayoutUnit pageLogicalHeightForOffset(LayoutUnit);
88 LayoutUnit pageRemainingLogicalHeightForOffset(LayoutUnit, PageBoundaryRule = IncludePageBoundary);
90 virtual void setPageBreak(LayoutUnit /*offset*/, LayoutUnit /*spaceShortage*/) { }
91 virtual void updateMinimumPageHeight(LayoutUnit /*offset*/, LayoutUnit /*minHeight*/) { }
93 bool regionsHaveUniformLogicalHeight() const { return m_regionsHaveUniformLogicalHeight; }
95 // FIXME: These 2 functions should return a RenderMultiColumnSet.
96 RenderRegion* firstRegion() const;
97 RenderRegion* lastRegion() const;
99 virtual bool addForcedRegionBreak(LayoutUnit, RenderObject* breakChild, bool isBefore, LayoutUnit* offsetBreakAdjustment = 0) { return false; }
101 virtual bool isPageLogicalHeightKnown() const { return true; }
102 bool pageLogicalSizeChanged() const { return m_pageLogicalSizeChanged; }
104 void collectLayerFragments(LayerFragments&, const LayoutRect& layerBoundingBox, const LayoutRect& dirtyRect);
105 LayoutRect fragmentsBoundingBox(const LayoutRect& layerBoundingBox);
107 LayoutPoint flowThreadPointToVisualPoint(const LayoutPoint& flowThreadPoint) const
109 return flowThreadPoint + columnOffset(flowThreadPoint);
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 shouldIssuePaintInvalidations(const LayoutRect&) const;
125 virtual RenderMultiColumnSet* columnSetAtBlockOffset(LayoutUnit) const = 0;
127 bool cachedOffsetFromLogicalTopOfFirstRegion(const RenderBox*, LayoutUnit&) const;
128 void setOffsetFromLogicalTopOfFirstRegion(const RenderBox*, LayoutUnit);
129 void clearOffsetFromLogicalTopOfFirstRegion(const RenderBox*);
131 const RenderBox* currentStatePusherRenderBox() const;
133 RenderMultiColumnSetList m_multiColumnSetList;
135 typedef PODInterval<LayoutUnit, RenderMultiColumnSet*> MultiColumnSetInterval;
136 typedef PODIntervalTree<LayoutUnit, RenderMultiColumnSet*> MultiColumnSetIntervalTree;
138 class RegionSearchAdapter {
140 RegionSearchAdapter(LayoutUnit offset)
146 const LayoutUnit& lowValue() const { return m_offset; }
147 const LayoutUnit& highValue() const { return m_offset; }
148 void collectIfNeeded(const MultiColumnSetInterval&);
150 RenderRegion* result() const { return m_result; }
154 RenderRegion* m_result;
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
160 ListHashSet<const RenderObject*> m_statePusherObjectsStack;
161 typedef HashMap<const RenderBox*, LayoutUnit> RenderBoxToOffsetMap;
162 RenderBoxToOffsetMap m_boxesToOffsetMap;
164 MultiColumnSetIntervalTree m_multiColumnSetIntervalTree;
166 bool m_regionsInvalidated : 1;
167 bool m_regionsHaveUniformLogicalHeight : 1;
168 bool m_pageLogicalSizeChanged : 1;
171 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderFlowThread, isRenderFlowThread());
173 class CurrentRenderFlowThreadMaintainer {
174 WTF_MAKE_NONCOPYABLE(CurrentRenderFlowThreadMaintainer);
176 CurrentRenderFlowThreadMaintainer(RenderFlowThread*);
177 ~CurrentRenderFlowThreadMaintainer();
179 RenderFlowThread* m_renderFlowThread;
180 RenderFlowThread* m_previousRenderFlowThread;
183 // These structures are used by PODIntervalTree for debugging.
185 template <> struct ValueToString<LayoutUnit> {
186 static String string(const LayoutUnit value) { return String::number(value.toFloat()); }
189 template <> struct ValueToString<RenderMultiColumnSet*> {
190 static String string(const RenderMultiColumnSet* value) { return String::format("%p", value); }
196 #endif // RenderFlowThread_h