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/ListHashSet.h>
30 #include <wtf/OwnPtr.h>
34 class RenderNamedFlowThread;
37 #if USE(ACCELERATED_COMPOSITING)
38 class RenderLayerCompositor;
41 typedef ListHashSet<RenderNamedFlowThread*> RenderNamedFlowThreadList;
43 class RenderView : public RenderBlock {
45 RenderView(Node*, FrameView*);
46 virtual ~RenderView();
48 virtual const char* renderName() const { return "RenderView"; }
50 virtual bool isRenderView() const { return true; }
52 virtual bool requiresLayer() const { return true; }
54 virtual bool isChildAllowed(RenderObject*, RenderStyle*) const;
56 virtual void layout();
57 virtual void computeLogicalWidth();
58 virtual void computeLogicalHeight();
59 virtual void computePreferredLogicalWidths();
61 // The same as the FrameView's layoutHeight/layoutWidth but with null check guards.
62 int viewHeight() const;
63 int viewWidth() const;
64 int viewLogicalWidth() const { return style()->isHorizontalWritingMode() ? viewWidth() : viewHeight(); }
65 int viewLogicalHeight() const;
67 float zoomFactor() const;
69 FrameView* frameView() const { return m_frameView; }
71 virtual void computeRectForRepaint(RenderBoxModelObject* repaintContainer, LayoutRect&, bool fixed = false) const;
72 virtual void repaintViewRectangle(const LayoutRect&, bool immediate = false);
73 // Repaint the view, and all composited layers that intersect the given absolute rectangle.
74 // FIXME: ideally we'd never have to do this, if all repaints are container-relative.
75 virtual void repaintRectangleInViewAndCompositedLayers(const LayoutRect&, bool immediate = false);
77 virtual void paint(PaintInfo&, const LayoutPoint&);
78 virtual void paintBoxDecorations(PaintInfo&, const LayoutPoint&) OVERRIDE;
80 enum SelectionRepaintMode { RepaintNewXOROld, RepaintNewMinusOld, RepaintNothing };
81 void setSelection(RenderObject* start, int startPos, RenderObject* end, int endPos, SelectionRepaintMode = RepaintNewXOROld);
82 void getSelection(RenderObject*& startRenderer, int& startOffset, RenderObject*& endRenderer, int& endOffset) const;
83 void clearSelection();
84 RenderObject* selectionStart() const { return m_selectionStart; }
85 RenderObject* selectionEnd() const { return m_selectionEnd; }
86 IntRect selectionBounds(bool clipToVisibleContent = true) const;
87 void selectionStartEnd(int& startPos, int& endPos) const;
89 bool printing() const;
91 virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const;
92 virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const;
94 #if USE(ACCELERATED_COMPOSITING)
95 void setMaximalOutlineSize(int o);
97 void setMaximalOutlineSize(int o) { m_maximalOutlineSize = o; }
99 int maximalOutlineSize() const { return m_maximalOutlineSize; }
101 virtual LayoutRect viewRect() const OVERRIDE;
103 void updateWidgetPositions();
104 void addWidget(RenderWidget*);
105 void removeWidget(RenderWidget*);
107 void notifyWidgets(WidgetNotification);
109 // layoutDelta is used transiently during layout to store how far an object has moved from its
110 // last layout location, in order to repaint correctly.
111 // If we're doing a full repaint m_layoutState will be 0, but in that case layoutDelta doesn't matter.
112 LayoutSize layoutDelta() const
114 return m_layoutState ? m_layoutState->m_layoutDelta : LayoutSize();
116 void addLayoutDelta(const LayoutSize& delta)
119 m_layoutState->m_layoutDelta += delta;
122 bool doingFullRepaint() const { return m_frameView->needsFullRepaint(); }
125 void pushLayoutState(RenderObject*);
126 void popLayoutState(RenderObject*) { return popLayoutState(); } // Just doing this to keep popLayoutState() private and to make the subtree calls symmetrical.
128 bool shouldDisableLayoutStateForSubtree(RenderObject*) const;
130 // Returns true if layoutState should be used for its cached offset and clip.
131 bool layoutStateEnabled() const { return m_layoutStateDisableCount == 0 && m_layoutState; }
132 LayoutState* layoutState() const { return m_layoutState; }
134 virtual void updateHitTestResult(HitTestResult&, const LayoutPoint&);
136 unsigned pageLogicalHeight() const { return m_pageLogicalHeight; }
137 void setPageLogicalHeight(unsigned height)
139 if (m_pageLogicalHeight != height) {
140 m_pageLogicalHeight = height;
141 m_pageLogicalHeightChanged = true;
145 // FIXME: These functions are deprecated. No code should be added that uses these.
146 int bestTruncatedAt() const { return m_legacyPrinting.m_bestTruncatedAt; }
147 void setBestTruncatedAt(int y, RenderBoxModelObject* forRenderer, bool forcedBreak = false);
148 int truncatedAt() const { return m_legacyPrinting.m_truncatedAt; }
149 void setTruncatedAt(int y)
151 m_legacyPrinting.m_truncatedAt = y;
152 m_legacyPrinting.m_bestTruncatedAt = 0;
153 m_legacyPrinting.m_truncatorWidth = 0;
154 m_legacyPrinting.m_forcedPageBreak = false;
156 const IntRect& printRect() const { return m_legacyPrinting.m_printRect; }
157 void setPrintRect(const IntRect& r) { m_legacyPrinting.m_printRect = r; }
158 // End deprecated functions.
160 // Notifications that this view became visible in a window, or will be
161 // removed from the window.
162 void didMoveOnscreen();
163 void willMoveOffscreen();
165 #if USE(ACCELERATED_COMPOSITING)
166 RenderLayerCompositor* compositor();
167 bool usesCompositing() const;
170 IntRect unscaledDocumentRect() const;
171 LayoutRect backgroundRect(RenderBox* backgroundRenderer) const;
173 IntRect documentRect() const;
175 RenderNamedFlowThread* ensureRenderFlowThreadWithName(const AtomicString&);
176 bool hasRenderNamedFlowThreads() const { return m_renderNamedFlowThreadList && !m_renderNamedFlowThreadList->isEmpty(); }
177 void layoutRenderNamedFlowThreads();
178 bool isRenderNamedFlowThreadOrderDirty() const { return m_isRenderNamedFlowThreadOrderDirty; }
179 void setIsRenderNamedFlowThreadOrderDirty(bool dirty)
181 m_isRenderNamedFlowThreadOrderDirty = dirty;
183 setNeedsLayout(true);
185 const RenderNamedFlowThreadList* renderNamedFlowThreadList() const { return m_renderNamedFlowThreadList.get(); }
187 RenderFlowThread* currentRenderFlowThread() const { return m_currentRenderFlowThread; }
188 void setCurrentRenderFlowThread(RenderFlowThread* flowThread) { m_currentRenderFlowThread = flowThread; }
190 void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
192 IntervalArena* intervalArena();
194 IntSize viewportSize() const { return document()->viewportSize(); }
196 virtual void mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool useTransforms, bool fixed, TransformState&, bool* wasFixed = 0) const;
197 virtual void mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState&) const;
198 virtual bool requiresColumns(int desiredColumnCount) const OVERRIDE;
201 virtual void calcColumnWidth() OVERRIDE;
202 virtual ColumnInfo::PaginationUnit paginationUnit() const OVERRIDE;
204 bool shouldRepaint(const LayoutRect&) const;
206 // These functions may only be accessed by LayoutStateMaintainer.
207 void pushLayoutState(RenderFlowThread*, bool regionsChanged);
208 bool pushLayoutState(RenderBox* renderer, const LayoutSize& offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
210 // We push LayoutState even if layoutState is disabled because it stores layoutDelta too.
211 if (!doingFullRepaint() || m_layoutState->isPaginated() || renderer->hasColumns() || renderer->inRenderFlowThread()
212 || m_layoutState->lineGrid() || (renderer->style()->lineGrid() != RenderStyle::initialLineGrid() && renderer->isBlockFlow())) {
213 m_layoutState = new (renderArena()) LayoutState(m_layoutState, renderer, offset, pageHeight, pageHeightChanged, colInfo);
219 void popLayoutState()
221 LayoutState* state = m_layoutState;
222 m_layoutState = state->m_next;
223 state->destroy(renderArena());
226 // Suspends the LayoutState optimization. Used under transforms that cannot be represented by
227 // LayoutState (common in SVG) and when manipulating the render tree during layout in ways
228 // that can trigger repaint of a non-child (e.g. when a list item moves its list marker around).
229 // Note that even when disabled, LayoutState is still used to store layoutDelta.
230 // These functions may only be accessed by LayoutStateMaintainer or LayoutStateDisabler.
231 void disableLayoutState() { m_layoutStateDisableCount++; }
232 void enableLayoutState() { ASSERT(m_layoutStateDisableCount > 0); m_layoutStateDisableCount--; }
234 size_t getRetainedWidgets(Vector<RenderWidget*>&);
235 void releaseWidgets(Vector<RenderWidget*>&);
237 friend class LayoutStateMaintainer;
238 friend class LayoutStateDisabler;
241 FrameView* m_frameView;
243 RenderObject* m_selectionStart;
244 RenderObject* m_selectionEnd;
245 int m_selectionStartPos;
246 int m_selectionEndPos;
248 // FIXME: Only used by embedded WebViews inside AppKit NSViews. Find a way to remove.
249 struct LegacyPrinting {
251 : m_bestTruncatedAt(0)
253 , m_truncatorWidth(0)
254 , m_forcedPageBreak(false)
257 int m_bestTruncatedAt;
259 int m_truncatorWidth;
261 bool m_forcedPageBreak;
263 LegacyPrinting m_legacyPrinting;
264 // End deprecated members.
266 int m_maximalOutlineSize; // Used to apply a fudge factor to dirty-rect checks on blocks/tables.
268 typedef HashSet<RenderWidget*> RenderWidgetSet;
269 RenderWidgetSet m_widgets;
272 unsigned m_pageLogicalHeight;
273 bool m_pageLogicalHeightChanged;
274 bool m_isRenderNamedFlowThreadOrderDirty;
275 LayoutState* m_layoutState;
276 unsigned m_layoutStateDisableCount;
277 #if USE(ACCELERATED_COMPOSITING)
278 OwnPtr<RenderLayerCompositor> m_compositor;
280 OwnPtr<RenderNamedFlowThreadList> m_renderNamedFlowThreadList;
281 RenderFlowThread* m_currentRenderFlowThread;
282 RefPtr<IntervalArena> m_intervalArena;
285 inline RenderView* toRenderView(RenderObject* object)
287 ASSERT(!object || object->isRenderView());
288 return static_cast<RenderView*>(object);
291 inline const RenderView* toRenderView(const RenderObject* object)
293 ASSERT(!object || object->isRenderView());
294 return static_cast<const RenderView*>(object);
297 // This will catch anyone doing an unnecessary cast.
298 void toRenderView(const RenderView*);
301 ALWAYS_INLINE RenderView* RenderObject::view() const
303 return toRenderView(document()->renderer());
306 // Stack-based class to assist with LayoutState push/pop
307 class LayoutStateMaintainer {
308 WTF_MAKE_NONCOPYABLE(LayoutStateMaintainer);
311 LayoutStateMaintainer(RenderView* view, RenderBox* root, LayoutSize offset, bool disableState = false, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
313 , m_disabled(disableState)
316 , m_didCreateLayoutState(false)
318 push(root, offset, pageHeight, pageHeightChanged, colInfo);
321 // ctor to maybe push later
322 LayoutStateMaintainer(RenderView* view)
327 , m_didCreateLayoutState(false)
331 LayoutStateMaintainer(RenderView* view, RenderFlowThread* flowThread, bool regionsChanged)
336 , m_didCreateLayoutState(false)
338 push(flowThread, regionsChanged);
341 ~LayoutStateMaintainer()
343 ASSERT(m_didStart == m_didEnd); // if this fires, it means that someone did a push(), but forgot to pop().
346 void push(RenderBox* root, LayoutSize offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
349 // We push state even if disabled, because we still need to store layoutDelta
350 m_didCreateLayoutState = m_view->pushLayoutState(root, offset, pageHeight, pageHeightChanged, colInfo);
351 if (m_disabled && m_didCreateLayoutState)
352 m_view->disableLayoutState();
356 void push(RenderFlowThread* flowThread, bool regionsChanged)
359 m_view->pushLayoutState(flowThread, regionsChanged);
360 m_didCreateLayoutState = true;
368 if (m_didCreateLayoutState) {
369 m_view->popLayoutState();
371 m_view->enableLayoutState();
378 bool didPush() const { return m_didStart; }
382 bool m_disabled : 1; // true if the offset and clip part of layoutState is disabled
383 bool m_didStart : 1; // true if we did a push or disable
384 bool m_didEnd : 1; // true if we popped or re-enabled
385 bool m_didCreateLayoutState : 1; // true if we actually made a layout state.
388 class LayoutStateDisabler {
389 WTF_MAKE_NONCOPYABLE(LayoutStateDisabler);
391 LayoutStateDisabler(RenderView* view)
395 m_view->disableLayoutState();
398 ~LayoutStateDisabler()
401 m_view->enableLayoutState();
407 } // namespace WebCore
409 #endif // RenderView_h