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 RenderRegion_h
31 #define RenderRegion_h
33 #include "RenderBlock.h"
34 #include "StyleInheritedData.h"
39 typedef Vector<LayerFragment, 1> LayerFragments;
41 class RenderBoxRegionInfo;
42 class RenderFlowThread;
43 class RenderNamedFlowThread;
45 class RenderRegion : public RenderBlock {
47 explicit RenderRegion(Element*, RenderFlowThread*);
49 virtual bool isRenderRegion() const { return true; }
51 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
53 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
55 void setFlowThreadPortionRect(const LayoutRect& rect) { m_flowThreadPortionRect = rect; }
56 LayoutRect flowThreadPortionRect() const { return m_flowThreadPortionRect; }
57 LayoutRect flowThreadPortionOverflowRect() const;
62 RenderNamedFlowThread* parentNamedFlowThread() const { return m_parentNamedFlowThread; }
63 RenderFlowThread* flowThread() const { return m_flowThread; }
65 // Valid regions do not create circular dependencies with other flows.
66 bool isValid() const { return m_isValid; }
67 void setIsValid(bool valid) { m_isValid = valid; }
69 bool hasCustomRegionStyle() const { return m_hasCustomRegionStyle; }
70 void setHasCustomRegionStyle(bool hasCustomRegionStyle) { m_hasCustomRegionStyle = hasCustomRegionStyle; }
72 RenderBoxRegionInfo* renderBoxRegionInfo(const RenderBox*) const;
73 RenderBoxRegionInfo* setRenderBoxRegionInfo(const RenderBox*, LayoutUnit logicalLeftInset, LayoutUnit logicalRightInset,
74 bool containingBlockChainIsInset);
75 PassOwnPtr<RenderBoxRegionInfo> takeRenderBoxRegionInfo(const RenderBox*);
76 void removeRenderBoxRegionInfo(const RenderBox*);
78 void deleteAllRenderBoxRegionInfo();
80 bool isFirstRegion() const;
81 bool isLastRegion() const;
83 void clearObjectStyleInRegion(const RenderObject*);
92 RegionState regionState() const { return isValid() ? m_regionState : RegionUndefined; }
93 void setRegionState(RegionState regionState) { m_regionState = regionState; }
95 // These methods represent the width and height of a "page" and for a RenderRegion they are just the
96 // content width and content height of a region. For RenderRegionSets, however, they will be the width and
97 // height of a single column or page in the set.
98 virtual LayoutUnit pageLogicalWidth() const;
99 virtual LayoutUnit pageLogicalHeight() const;
100 LayoutUnit maxPageLogicalHeight() const;
102 virtual void computePreferredLogicalWidths() OVERRIDE;
104 LayoutUnit logicalTopOfFlowThreadContentRect(const LayoutRect&) const;
105 LayoutUnit logicalBottomOfFlowThreadContentRect(const LayoutRect&) const;
106 LayoutUnit logicalTopForFlowThreadContent() const { return logicalTopOfFlowThreadContentRect(flowThreadPortionRect()); };
107 LayoutUnit logicalBottomForFlowThreadContent() const { return logicalBottomOfFlowThreadContentRect(flowThreadPortionRect()); };
109 void getRanges(Vector<RefPtr<Range> >&) const;
111 // This method represents the logical height of the entire flow thread portion used by the region or set.
112 // For RenderRegions it matches logicalPaginationHeight(), but for sets it is the height of all the pages
113 // or columns added together.
114 virtual LayoutUnit logicalHeightOfAllFlowThreadContent() const;
116 bool hasAutoLogicalHeight() const { return m_hasAutoLogicalHeight; }
118 virtual void updateLogicalHeight() OVERRIDE;
120 // The top of the nearest page inside the region. For RenderRegions, this is just the logical top of the
121 // flow thread portion we contain. For sets, we have to figure out the top of the nearest column or
123 virtual LayoutUnit pageLogicalTopForOffset(LayoutUnit offset) const;
125 virtual void expandToEncompassFlowThreadContentsIfNeeded() { };
127 // Whether or not this region is a set.
128 virtual bool isRenderRegionSet() const { return false; }
130 virtual void repaintFlowThreadContent(const LayoutRect& repaintRect, bool immediate) const;
132 virtual void collectLayerFragments(LayerFragments&, const LayoutRect&, const LayoutRect&) { }
135 void setRegionObjectsRegionStyle();
136 void restoreRegionObjectsOriginalStyle();
138 LayoutRect overflowRectForFlowThreadPortion(LayoutRect flowThreadPortionRect, bool isFirstPortion, bool isLastPortion) const;
139 void repaintFlowThreadContentRectangle(const LayoutRect& repaintRect, bool immediate, const LayoutRect& flowThreadPortionRect,
140 const LayoutRect& flowThreadPortionOverflowRect, const LayoutPoint& regionLocation) const;
142 virtual bool shouldHaveAutoLogicalHeight() const;
145 virtual const char* renderName() const { return "RenderRegion"; }
147 virtual bool canHaveChildren() const OVERRIDE { return false; }
148 virtual bool canDOMChildrenHaveRenderParent() const OVERRIDE { return true; }
150 virtual void insertedIntoTree() OVERRIDE;
151 virtual void willBeRemovedFromTree() OVERRIDE;
153 virtual void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0) OVERRIDE;
154 virtual void paintObject(PaintInfo&, const LayoutPoint&) OVERRIDE;
156 virtual void installFlowThread();
158 PassRefPtr<RenderStyle> computeStyleInRegion(const RenderObject*);
159 void computeChildrenStyleInRegion(const RenderObject*);
160 void setObjectStyleInRegion(RenderObject*, PassRefPtr<RenderStyle>, bool objectRegionStyleCached);
162 void checkRegionStyle();
163 void updateRegionHasAutoLogicalHeightFlag();
165 void incrementAutoLogicalHeightCount();
166 void decrementAutoLogicalHeightCount();
169 RenderFlowThread* m_flowThread;
172 // If this RenderRegion is displayed as part of another named flow,
173 // we need to create a dependency tree, so that layout of the
174 // regions is always done before the regions themselves.
175 RenderNamedFlowThread* m_parentNamedFlowThread;
176 LayoutRect m_flowThreadPortionRect;
178 // This map holds unique information about a block that is split across regions.
179 // A RenderBoxRegionInfo* tells us about any layout information for a RenderBox that
180 // is unique to the region. For now it just holds logical width information for RenderBlocks, but eventually
181 // it will also hold a custom style for any box (for region styling).
182 typedef HashMap<const RenderBox*, OwnPtr<RenderBoxRegionInfo> > RenderBoxRegionInfoMap;
183 RenderBoxRegionInfoMap m_renderBoxRegionInfo;
185 struct ObjectRegionStyleInfo {
186 // Used to store the original style of the object in region
187 // so that the original style is properly restored after paint.
188 // Also used to store computed style of the object in region between
189 // region paintings, so that the style in region is computed only
191 RefPtr<RenderStyle> style;
192 // True if the computed style in region is cached.
195 typedef HashMap<const RenderObject*, ObjectRegionStyleInfo > RenderObjectRegionStyleMap;
196 RenderObjectRegionStyleMap m_renderObjectRegionStyle;
199 bool m_hasCustomRegionStyle : 1;
200 bool m_hasAutoLogicalHeight : 1;
201 RegionState m_regionState;
204 inline RenderRegion* toRenderRegion(RenderObject* object)
206 ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isRenderRegion());
207 return static_cast<RenderRegion*>(object);
210 inline const RenderRegion* toRenderRegion(const RenderObject* object)
212 ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isRenderRegion());
213 return static_cast<const RenderRegion*>(object);
216 // This will catch anyone doing an unnecessary cast.
217 void toRenderRegion(const RenderRegion*);
219 } // namespace WebCore
221 #endif // RenderRegion_h