2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2006 Apple Computer, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
25 #include "FrameView.h"
26 #include "LayoutState.h"
27 #include "PODFreeListArena.h"
28 #include "RenderBlock.h"
29 #include <wtf/OwnPtr.h>
33 class FlowThreadController;
36 #if USE(ACCELERATED_COMPOSITING)
37 class RenderLayerCompositor;
40 class RenderView : public RenderBlock {
42 RenderView(Node*, FrameView*);
43 virtual ~RenderView();
45 virtual const char* renderName() const { return "RenderView"; }
47 virtual bool isRenderView() const { return true; }
49 virtual bool requiresLayer() const { return true; }
51 virtual bool isChildAllowed(RenderObject*, RenderStyle*) const;
53 virtual void layout();
54 virtual void computeLogicalWidth();
55 virtual void computeLogicalHeight();
56 virtual void computePreferredLogicalWidths();
58 // The same as the FrameView's layoutHeight/layoutWidth but with null check guards.
59 int viewHeight() const;
60 int viewWidth() const;
61 int viewLogicalWidth() const { return style()->isHorizontalWritingMode() ? viewWidth() : viewHeight(); }
62 int viewLogicalHeight() const;
64 float zoomFactor() const;
66 FrameView* frameView() const { return m_frameView; }
68 virtual void computeRectForRepaint(RenderBoxModelObject* repaintContainer, LayoutRect&, bool fixed = false) const;
69 virtual void repaintViewRectangle(const LayoutRect&, bool immediate = false);
70 // Repaint the view, and all composited layers that intersect the given absolute rectangle.
71 // FIXME: ideally we'd never have to do this, if all repaints are container-relative.
72 virtual void repaintRectangleInViewAndCompositedLayers(const LayoutRect&, bool immediate = false);
74 virtual void paint(PaintInfo&, const LayoutPoint&);
75 virtual void paintBoxDecorations(PaintInfo&, const LayoutPoint&) OVERRIDE;
77 enum SelectionRepaintMode { RepaintNewXOROld, RepaintNewMinusOld, RepaintNothing };
78 void setSelection(RenderObject* start, int startPos, RenderObject* end, int endPos, SelectionRepaintMode = RepaintNewXOROld);
79 void getSelection(RenderObject*& startRenderer, int& startOffset, RenderObject*& endRenderer, int& endOffset) const;
80 void clearSelection();
81 RenderObject* selectionStart() const { return m_selectionStart; }
82 RenderObject* selectionEnd() const { return m_selectionEnd; }
83 IntRect selectionBounds(bool clipToVisibleContent = true) const;
84 void selectionStartEnd(int& startPos, int& endPos) const;
86 bool printing() const;
88 virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const;
89 virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const;
91 #if USE(ACCELERATED_COMPOSITING)
92 void setMaximalOutlineSize(int o);
94 void setMaximalOutlineSize(int o) { m_maximalOutlineSize = o; }
96 int maximalOutlineSize() const { return m_maximalOutlineSize; }
98 virtual LayoutRect viewRect() const OVERRIDE;
100 void updateWidgetPositions();
101 void addWidget(RenderWidget*);
102 void removeWidget(RenderWidget*);
104 void notifyWidgets(WidgetNotification);
106 // layoutDelta is used transiently during layout to store how far an object has moved from its
107 // last layout location, in order to repaint correctly.
108 // If we're doing a full repaint m_layoutState will be 0, but in that case layoutDelta doesn't matter.
109 LayoutSize layoutDelta() const
111 return m_layoutState ? m_layoutState->m_layoutDelta : LayoutSize();
113 void addLayoutDelta(const LayoutSize& delta)
116 m_layoutState->m_layoutDelta += delta;
119 bool doingFullRepaint() const { return m_frameView->needsFullRepaint(); }
122 void pushLayoutState(RenderObject*);
123 void popLayoutState(RenderObject*) { return popLayoutState(); } // Just doing this to keep popLayoutState() private and to make the subtree calls symmetrical.
125 bool shouldDisableLayoutStateForSubtree(RenderObject*) const;
127 // Returns true if layoutState should be used for its cached offset and clip.
128 bool layoutStateEnabled() const { return m_layoutStateDisableCount == 0 && m_layoutState; }
129 LayoutState* layoutState() const { return m_layoutState; }
131 virtual void updateHitTestResult(HitTestResult&, const LayoutPoint&);
133 unsigned pageLogicalHeight() const { return m_pageLogicalHeight; }
134 void setPageLogicalHeight(unsigned height)
136 if (m_pageLogicalHeight != height) {
137 m_pageLogicalHeight = height;
138 m_pageLogicalHeightChanged = true;
142 // FIXME: These functions are deprecated. No code should be added that uses these.
143 int bestTruncatedAt() const { return m_legacyPrinting.m_bestTruncatedAt; }
144 void setBestTruncatedAt(int y, RenderBoxModelObject* forRenderer, bool forcedBreak = false);
145 int truncatedAt() const { return m_legacyPrinting.m_truncatedAt; }
146 void setTruncatedAt(int y)
148 m_legacyPrinting.m_truncatedAt = y;
149 m_legacyPrinting.m_bestTruncatedAt = 0;
150 m_legacyPrinting.m_truncatorWidth = 0;
151 m_legacyPrinting.m_forcedPageBreak = false;
153 const IntRect& printRect() const { return m_legacyPrinting.m_printRect; }
154 void setPrintRect(const IntRect& r) { m_legacyPrinting.m_printRect = r; }
155 // End deprecated functions.
157 // Notifications that this view became visible in a window, or will be
158 // removed from the window.
159 void didMoveOnscreen();
160 void willMoveOffscreen();
162 #if USE(ACCELERATED_COMPOSITING)
163 RenderLayerCompositor* compositor();
164 bool usesCompositing() const;
167 IntRect unscaledDocumentRect() const;
168 LayoutRect backgroundRect(RenderBox* backgroundRenderer) const;
170 IntRect documentRect() const;
172 bool hasRenderNamedFlowThreads() const;
173 FlowThreadController* flowThreadController();
175 void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
177 IntervalArena* intervalArena();
179 IntSize viewportSize() const { return document()->viewportSize(); }
181 virtual void mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool useTransforms, bool fixed, TransformState&, bool* wasFixed = 0) const;
182 virtual void mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState&) const;
183 virtual bool requiresColumns(int desiredColumnCount) const OVERRIDE;
186 virtual void calcColumnWidth() OVERRIDE;
187 virtual ColumnInfo::PaginationUnit paginationUnit() const OVERRIDE;
189 bool shouldRepaint(const LayoutRect&) const;
191 // These functions may only be accessed by LayoutStateMaintainer.
192 void pushLayoutState(RenderFlowThread*, bool regionsChanged);
193 bool pushLayoutState(RenderBox* renderer, const LayoutSize& offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
195 // We push LayoutState even if layoutState is disabled because it stores layoutDelta too.
196 if (!doingFullRepaint() || m_layoutState->isPaginated() || renderer->hasColumns() || renderer->inRenderFlowThread()
197 || m_layoutState->lineGrid() || (renderer->style()->lineGrid() != RenderStyle::initialLineGrid() && renderer->isBlockFlow())) {
198 m_layoutState = new (renderArena()) LayoutState(m_layoutState, renderer, offset, pageHeight, pageHeightChanged, colInfo);
204 void popLayoutState()
206 LayoutState* state = m_layoutState;
207 m_layoutState = state->m_next;
208 state->destroy(renderArena());
211 // Suspends the LayoutState optimization. Used under transforms that cannot be represented by
212 // LayoutState (common in SVG) and when manipulating the render tree during layout in ways
213 // that can trigger repaint of a non-child (e.g. when a list item moves its list marker around).
214 // Note that even when disabled, LayoutState is still used to store layoutDelta.
215 // These functions may only be accessed by LayoutStateMaintainer or LayoutStateDisabler.
216 void disableLayoutState() { m_layoutStateDisableCount++; }
217 void enableLayoutState() { ASSERT(m_layoutStateDisableCount > 0); m_layoutStateDisableCount--; }
219 size_t getRetainedWidgets(Vector<RenderWidget*>&);
220 void releaseWidgets(Vector<RenderWidget*>&);
222 friend class LayoutStateMaintainer;
223 friend class LayoutStateDisabler;
226 FrameView* m_frameView;
228 RenderObject* m_selectionStart;
229 RenderObject* m_selectionEnd;
230 int m_selectionStartPos;
231 int m_selectionEndPos;
233 // FIXME: Only used by embedded WebViews inside AppKit NSViews. Find a way to remove.
234 struct LegacyPrinting {
236 : m_bestTruncatedAt(0)
238 , m_truncatorWidth(0)
239 , m_forcedPageBreak(false)
242 int m_bestTruncatedAt;
244 int m_truncatorWidth;
246 bool m_forcedPageBreak;
248 LegacyPrinting m_legacyPrinting;
249 // End deprecated members.
251 int m_maximalOutlineSize; // Used to apply a fudge factor to dirty-rect checks on blocks/tables.
253 typedef HashSet<RenderWidget*> RenderWidgetSet;
254 RenderWidgetSet m_widgets;
257 unsigned m_pageLogicalHeight;
258 bool m_pageLogicalHeightChanged;
259 LayoutState* m_layoutState;
260 unsigned m_layoutStateDisableCount;
261 #if USE(ACCELERATED_COMPOSITING)
262 OwnPtr<RenderLayerCompositor> m_compositor;
264 OwnPtr<FlowThreadController> m_flowThreadController;
265 RefPtr<IntervalArena> m_intervalArena;
268 inline RenderView* toRenderView(RenderObject* object)
270 ASSERT(!object || object->isRenderView());
271 return static_cast<RenderView*>(object);
274 inline const RenderView* toRenderView(const RenderObject* object)
276 ASSERT(!object || object->isRenderView());
277 return static_cast<const RenderView*>(object);
280 // This will catch anyone doing an unnecessary cast.
281 void toRenderView(const RenderView*);
284 ALWAYS_INLINE RenderView* RenderObject::view() const
286 return toRenderView(document()->renderer());
289 // Stack-based class to assist with LayoutState push/pop
290 class LayoutStateMaintainer {
291 WTF_MAKE_NONCOPYABLE(LayoutStateMaintainer);
294 LayoutStateMaintainer(RenderView* view, RenderBox* root, LayoutSize offset, bool disableState = false, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
296 , m_disabled(disableState)
299 , m_didCreateLayoutState(false)
301 push(root, offset, pageHeight, pageHeightChanged, colInfo);
304 // ctor to maybe push later
305 LayoutStateMaintainer(RenderView* view)
310 , m_didCreateLayoutState(false)
314 LayoutStateMaintainer(RenderView* view, RenderFlowThread* flowThread, bool regionsChanged)
319 , m_didCreateLayoutState(false)
321 push(flowThread, regionsChanged);
324 ~LayoutStateMaintainer()
326 ASSERT(m_didStart == m_didEnd); // if this fires, it means that someone did a push(), but forgot to pop().
329 void push(RenderBox* root, LayoutSize offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
332 // We push state even if disabled, because we still need to store layoutDelta
333 m_didCreateLayoutState = m_view->pushLayoutState(root, offset, pageHeight, pageHeightChanged, colInfo);
334 if (m_disabled && m_didCreateLayoutState)
335 m_view->disableLayoutState();
339 void push(RenderFlowThread* flowThread, bool regionsChanged)
342 m_view->pushLayoutState(flowThread, regionsChanged);
343 m_didCreateLayoutState = true;
351 if (m_didCreateLayoutState) {
352 m_view->popLayoutState();
354 m_view->enableLayoutState();
361 bool didPush() const { return m_didStart; }
365 bool m_disabled : 1; // true if the offset and clip part of layoutState is disabled
366 bool m_didStart : 1; // true if we did a push or disable
367 bool m_didEnd : 1; // true if we popped or re-enabled
368 bool m_didCreateLayoutState : 1; // true if we actually made a layout state.
371 class LayoutStateDisabler {
372 WTF_MAKE_NONCOPYABLE(LayoutStateDisabler);
374 LayoutStateDisabler(RenderView* view)
378 m_view->disableLayoutState();
381 ~LayoutStateDisabler()
384 m_view->enableLayoutState();
390 } // namespace WebCore
392 #endif // RenderView_h