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 "RenderBlock.h"
28 #include <wtf/ListHashSet.h>
29 #include <wtf/OwnPtr.h>
33 class RenderFlowThread;
36 #if USE(ACCELERATED_COMPOSITING)
37 class RenderLayerCompositor;
40 typedef ListHashSet<RenderFlowThread*> RenderFlowThreadList;
42 class RenderView : public RenderBlock {
44 RenderView(Node*, FrameView*);
45 virtual ~RenderView();
47 virtual const char* renderName() const { return "RenderView"; }
49 virtual bool isRenderView() const { return true; }
51 virtual bool requiresLayer() const { return true; }
53 virtual bool isChildAllowed(RenderObject*, RenderStyle*) const;
55 virtual void layout();
56 virtual void computeLogicalWidth();
57 virtual void computeLogicalHeight();
58 virtual void computePreferredLogicalWidths();
60 // The same as the FrameView's layoutHeight/layoutWidth but with null check guards.
61 int viewHeight() const;
62 int viewWidth() const;
63 int viewLogicalWidth() const { return style()->isHorizontalWritingMode() ? viewWidth() : viewHeight(); }
64 int viewLogicalHeight() const { return style()->isHorizontalWritingMode() ? viewHeight() : viewWidth(); }
66 float zoomFactor() const;
68 FrameView* frameView() const { return m_frameView; }
70 virtual void computeRectForRepaint(RenderBoxModelObject* repaintContainer, IntRect&, bool fixed = false) const;
71 virtual void repaintViewRectangle(const IntRect&, bool immediate = false);
72 // Repaint the view, and all composited layers that intersect the given absolute rectangle.
73 // FIXME: ideally we'd never have to do this, if all repaints are container-relative.
74 virtual void repaintRectangleInViewAndCompositedLayers(const IntRect&, bool immediate = false);
76 virtual void paint(PaintInfo&, const LayoutPoint&);
77 virtual void paintBoxDecorations(PaintInfo&, const IntPoint&);
79 enum SelectionRepaintMode { RepaintNewXOROld, RepaintNewMinusOld, RepaintNothing };
80 void setSelection(RenderObject* start, int startPos, RenderObject* end, int endPos, SelectionRepaintMode = RepaintNewXOROld);
81 void getSelection(RenderObject*& startRenderer, int& startOffset, RenderObject*& endRenderer, int& endOffset) const;
82 void clearSelection();
83 RenderObject* selectionStart() const { return m_selectionStart; }
84 RenderObject* selectionEnd() const { return m_selectionEnd; }
85 IntRect selectionBounds(bool clipToVisibleContent = true) const;
86 void selectionStartEnd(int& startPos, int& endPos) const;
88 bool printing() const;
90 virtual void absoluteRects(Vector<LayoutRect>&, const LayoutPoint& accumulatedOffset) const;
91 virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const;
93 #if USE(ACCELERATED_COMPOSITING)
94 void setMaximalOutlineSize(int o);
96 void setMaximalOutlineSize(int o) { m_maximalOutlineSize = o; }
98 int maximalOutlineSize() const { return m_maximalOutlineSize; }
100 virtual IntRect viewRect() const;
102 void updateWidgetPositions();
103 void addWidget(RenderWidget*);
104 void removeWidget(RenderWidget*);
106 void notifyWidgets(WidgetNotification);
108 // layoutDelta is used transiently during layout to store how far an object has moved from its
109 // last layout location, in order to repaint correctly.
110 // If we're doing a full repaint m_layoutState will be 0, but in that case layoutDelta doesn't matter.
111 LayoutSize layoutDelta() const
113 return m_layoutState ? m_layoutState->m_layoutDelta : LayoutSize();
115 void addLayoutDelta(const LayoutSize& delta)
118 m_layoutState->m_layoutDelta += delta;
121 bool doingFullRepaint() const { return m_frameView->needsFullRepaint(); }
124 void pushLayoutState(RenderObject*);
125 void popLayoutState(RenderObject*) { return popLayoutState(); } // Just doing this to keep popLayoutState() private and to make the subtree calls symmetrical.
127 bool shouldDisableLayoutStateForSubtree(RenderObject*) const;
129 // Returns true if layoutState should be used for its cached offset and clip.
130 bool layoutStateEnabled() const { return m_layoutStateDisableCount == 0 && m_layoutState; }
131 LayoutState* layoutState() const { return m_layoutState; }
133 virtual void updateHitTestResult(HitTestResult&, const LayoutPoint&);
135 unsigned pageLogicalHeight() const { return m_pageLogicalHeight; }
136 void setPageLogicalHeight(unsigned height)
138 if (m_pageLogicalHeight != height) {
139 m_pageLogicalHeight = height;
140 m_pageLogicalHeightChanged = true;
144 // FIXME: These functions are deprecated. No code should be added that uses these.
145 int bestTruncatedAt() const { return m_legacyPrinting.m_bestTruncatedAt; }
146 void setBestTruncatedAt(int y, RenderBoxModelObject* forRenderer, bool forcedBreak = false);
147 int truncatedAt() const { return m_legacyPrinting.m_truncatedAt; }
148 void setTruncatedAt(int y)
150 m_legacyPrinting.m_truncatedAt = y;
151 m_legacyPrinting.m_bestTruncatedAt = 0;
152 m_legacyPrinting.m_truncatorWidth = 0;
153 m_legacyPrinting.m_forcedPageBreak = false;
155 const IntRect& printRect() const { return m_legacyPrinting.m_printRect; }
156 void setPrintRect(const IntRect& r) { m_legacyPrinting.m_printRect = r; }
157 // End deprecated functions.
159 // Notifications that this view became visible in a window, or will be
160 // removed from the window.
161 void didMoveOnscreen();
162 void willMoveOffscreen();
164 #if USE(ACCELERATED_COMPOSITING)
165 RenderLayerCompositor* compositor();
166 bool usesCompositing() const;
169 IntRect unscaledDocumentRect() const;
170 LayoutRect backgroundRect() const;
172 IntRect documentRect() const;
174 RenderFlowThread* renderFlowThreadWithName(const AtomicString& flowThread);
175 bool hasRenderFlowThreads() const { return m_renderFlowThreadList && !m_renderFlowThreadList->isEmpty(); }
176 void layoutRenderFlowThreads();
177 bool isRenderFlowThreadOrderDirty() const { return m_isRenderFlowThreadOrderDirty; }
178 void setIsRenderFlowThreadOrderDirty(bool dirty)
180 m_isRenderFlowThreadOrderDirty = dirty;
182 setNeedsLayout(true);
184 const RenderFlowThreadList* renderFlowThreadList() const { return m_renderFlowThreadList.get(); }
186 RenderFlowThread* currentRenderFlowThread() const { return m_currentRenderFlowThread; }
187 void setCurrentRenderFlowThread(RenderFlowThread* flowThread) { m_currentRenderFlowThread = flowThread; }
189 void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
192 virtual void mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool useTransforms, bool fixed, TransformState&, bool* wasFixed = 0) const;
193 virtual void mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState&) const;
194 virtual bool requiresColumns(int desiredColumnCount) const OVERRIDE;
197 bool shouldRepaint(const IntRect& r) const;
199 // These functions may only be accessed by LayoutStateMaintainer.
200 void pushLayoutState(RenderFlowThread*, bool regionsChanged);
201 bool pushLayoutState(RenderBox* renderer, const LayoutSize& offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
203 // We push LayoutState even if layoutState is disabled because it stores layoutDelta too.
204 if (!doingFullRepaint() || m_layoutState->isPaginated() || renderer->hasColumns() || renderer->inRenderFlowThread()) {
205 m_layoutState = new (renderArena()) LayoutState(m_layoutState, renderer, offset, pageHeight, pageHeightChanged, colInfo);
211 void popLayoutState()
213 LayoutState* state = m_layoutState;
214 m_layoutState = state->m_next;
215 state->destroy(renderArena());
218 // Suspends the LayoutState optimization. Used under transforms that cannot be represented by
219 // LayoutState (common in SVG) and when manipulating the render tree during layout in ways
220 // that can trigger repaint of a non-child (e.g. when a list item moves its list marker around).
221 // Note that even when disabled, LayoutState is still used to store layoutDelta.
222 // These functions may only be accessed by LayoutStateMaintainer or LayoutStateDisabler.
223 void disableLayoutState() { m_layoutStateDisableCount++; }
224 void enableLayoutState() { ASSERT(m_layoutStateDisableCount > 0); m_layoutStateDisableCount--; }
226 size_t getRetainedWidgets(Vector<RenderWidget*>&);
227 void releaseWidgets(Vector<RenderWidget*>&);
229 friend class LayoutStateMaintainer;
230 friend class LayoutStateDisabler;
233 FrameView* m_frameView;
235 RenderObject* m_selectionStart;
236 RenderObject* m_selectionEnd;
237 int m_selectionStartPos;
238 int m_selectionEndPos;
240 // FIXME: Only used by embedded WebViews inside AppKit NSViews. Find a way to remove.
241 struct LegacyPrinting {
243 : m_bestTruncatedAt(0)
245 , m_truncatorWidth(0)
246 , m_forcedPageBreak(false)
249 int m_bestTruncatedAt;
251 int m_truncatorWidth;
253 bool m_forcedPageBreak;
255 LegacyPrinting m_legacyPrinting;
256 // End deprecated members.
258 int m_maximalOutlineSize; // Used to apply a fudge factor to dirty-rect checks on blocks/tables.
260 typedef HashSet<RenderWidget*> RenderWidgetSet;
261 RenderWidgetSet m_widgets;
264 unsigned m_pageLogicalHeight;
265 bool m_pageLogicalHeightChanged;
266 bool m_isRenderFlowThreadOrderDirty;
267 LayoutState* m_layoutState;
268 unsigned m_layoutStateDisableCount;
269 #if USE(ACCELERATED_COMPOSITING)
270 OwnPtr<RenderLayerCompositor> m_compositor;
272 OwnPtr<RenderFlowThreadList> m_renderFlowThreadList;
273 RenderFlowThread* m_currentRenderFlowThread;
276 inline RenderView* toRenderView(RenderObject* object)
278 ASSERT(!object || object->isRenderView());
279 return static_cast<RenderView*>(object);
282 inline const RenderView* toRenderView(const RenderObject* object)
284 ASSERT(!object || object->isRenderView());
285 return static_cast<const RenderView*>(object);
288 // This will catch anyone doing an unnecessary cast.
289 void toRenderView(const RenderView*);
292 // Stack-based class to assist with LayoutState push/pop
293 class LayoutStateMaintainer {
294 WTF_MAKE_NONCOPYABLE(LayoutStateMaintainer);
297 LayoutStateMaintainer(RenderView* view, RenderBox* root, LayoutSize offset, bool disableState = false, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
299 , m_disabled(disableState)
302 , m_didCreateLayoutState(false)
304 push(root, offset, pageHeight, pageHeightChanged, colInfo);
307 // ctor to maybe push later
308 LayoutStateMaintainer(RenderView* view)
313 , m_didCreateLayoutState(false)
317 LayoutStateMaintainer(RenderView* view, RenderFlowThread* flowThread, bool regionsChanged)
322 , m_didCreateLayoutState(false)
324 push(flowThread, regionsChanged);
327 ~LayoutStateMaintainer()
329 ASSERT(m_didStart == m_didEnd); // if this fires, it means that someone did a push(), but forgot to pop().
332 void push(RenderBox* root, LayoutSize offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
335 // We push state even if disabled, because we still need to store layoutDelta
336 m_didCreateLayoutState = m_view->pushLayoutState(root, offset, pageHeight, pageHeightChanged, colInfo);
337 if (m_disabled && m_didCreateLayoutState)
338 m_view->disableLayoutState();
342 void push(RenderFlowThread* flowThread, bool regionsChanged)
345 m_view->pushLayoutState(flowThread, regionsChanged);
346 m_didCreateLayoutState = true;
354 if (m_didCreateLayoutState) {
355 m_view->popLayoutState();
357 m_view->enableLayoutState();
364 bool didPush() const { return m_didStart; }
368 bool m_disabled : 1; // true if the offset and clip part of layoutState is disabled
369 bool m_didStart : 1; // true if we did a push or disable
370 bool m_didEnd : 1; // true if we popped or re-enabled
371 bool m_didCreateLayoutState : 1; // true if we actually made a layout state.
374 class LayoutStateDisabler {
375 WTF_MAKE_NONCOPYABLE(LayoutStateDisabler);
377 LayoutStateDisabler(RenderView* view)
381 m_view->disableLayoutState();
384 ~LayoutStateDisabler()
387 m_view->enableLayoutState();
393 } // namespace WebCore
395 #endif // RenderView_h