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 };
80 void setSelection(RenderObject* start, int startPos, RenderObject* end, int endPos, SelectionRepaintMode = RepaintNewXOROld);
81 void clearSelection();
82 RenderObject* selectionStart() const { return m_selectionStart; }
83 RenderObject* selectionEnd() const { return m_selectionEnd; }
84 IntRect selectionBounds(bool clipToVisibleContent = true) const;
85 void selectionStartEnd(int& startPos, int& endPos) const;
87 bool printing() const;
89 virtual void absoluteRects(Vector<LayoutRect>&, const LayoutPoint& accumulatedOffset);
90 virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed);
92 #if USE(ACCELERATED_COMPOSITING)
93 void setMaximalOutlineSize(int o);
95 void setMaximalOutlineSize(int o) { m_maximalOutlineSize = o; }
97 int maximalOutlineSize() const { return m_maximalOutlineSize; }
99 virtual IntRect viewRect() const;
101 void updateWidgetPositions();
102 void addWidget(RenderWidget*);
103 void removeWidget(RenderWidget*);
105 void notifyWidgets(WidgetNotification);
107 // layoutDelta is used transiently during layout to store how far an object has moved from its
108 // last layout location, in order to repaint correctly.
109 // If we're doing a full repaint m_layoutState will be 0, but in that case layoutDelta doesn't matter.
110 LayoutSize layoutDelta() const
112 return m_layoutState ? m_layoutState->m_layoutDelta : LayoutSize();
114 void addLayoutDelta(const LayoutSize& delta)
117 m_layoutState->m_layoutDelta += delta;
120 bool doingFullRepaint() const { return m_frameView->needsFullRepaint(); }
123 void pushLayoutState(RenderObject*);
124 void popLayoutState(RenderObject*) { return popLayoutState(); } // Just doing this to keep popLayoutState() private and to make the subtree calls symmetrical.
126 bool shouldDisableLayoutStateForSubtree(RenderObject*) const;
128 // Returns true if layoutState should be used for its cached offset and clip.
129 bool layoutStateEnabled() const { return m_layoutStateDisableCount == 0 && m_layoutState; }
130 LayoutState* layoutState() const { return m_layoutState; }
132 virtual void updateHitTestResult(HitTestResult&, const LayoutPoint&);
134 unsigned pageLogicalHeight() const { return m_pageLogicalHeight; }
135 void setPageLogicalHeight(unsigned height)
137 if (m_pageLogicalHeight != height) {
138 m_pageLogicalHeight = height;
139 m_pageLogicalHeightChanged = true;
143 // FIXME: These functions are deprecated. No code should be added that uses these.
144 int bestTruncatedAt() const { return m_legacyPrinting.m_bestTruncatedAt; }
145 void setBestTruncatedAt(int y, RenderBoxModelObject* forRenderer, bool forcedBreak = false);
146 int truncatedAt() const { return m_legacyPrinting.m_truncatedAt; }
147 void setTruncatedAt(int y)
149 m_legacyPrinting.m_truncatedAt = y;
150 m_legacyPrinting.m_bestTruncatedAt = 0;
151 m_legacyPrinting.m_truncatorWidth = 0;
152 m_legacyPrinting.m_forcedPageBreak = false;
154 const IntRect& printRect() const { return m_legacyPrinting.m_printRect; }
155 void setPrintRect(const IntRect& r) { m_legacyPrinting.m_printRect = r; }
156 // End deprecated functions.
158 // Notifications that this view became visible in a window, or will be
159 // removed from the window.
160 void didMoveOnscreen();
161 void willMoveOffscreen();
163 #if USE(ACCELERATED_COMPOSITING)
164 RenderLayerCompositor* compositor();
165 bool usesCompositing() const;
168 IntRect unscaledDocumentRect() const;
170 IntRect documentRect() const;
172 RenderFlowThread* renderFlowThreadWithName(const AtomicString& flowThread);
173 bool hasRenderFlowThreads() const { return m_renderFlowThreadList && !m_renderFlowThreadList->isEmpty(); }
174 void layoutRenderFlowThreads();
175 bool isRenderFlowThreadOrderDirty() const { return m_isRenderFlowThreadOrderDirty; }
176 void setIsRenderFlowThreadOrderDirty(bool dirty)
178 m_isRenderFlowThreadOrderDirty = dirty;
180 setNeedsLayout(true);
182 const RenderFlowThreadList* renderFlowThreadList() const { return m_renderFlowThreadList.get(); }
184 bool hasRenderFlowThread() const { return m_currentRenderFlowThread; }
185 RenderFlowThread* currentRenderFlowThread() const { return m_currentRenderFlowThread; }
186 void setCurrentRenderFlowThread(RenderFlowThread* flowThread) { m_currentRenderFlowThread = flowThread; }
188 void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
191 virtual void mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool useTransforms, bool fixed, TransformState&, bool* wasFixed = 0) const;
192 virtual void mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState&) const;
195 bool shouldRepaint(const IntRect& r) const;
197 virtual RenderBlock* containingBlock() const;
199 // These functions may only be accessed by LayoutStateMaintainer.
200 bool pushLayoutState(RenderBox* renderer, const LayoutSize& offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
202 // We push LayoutState even if layoutState is disabled because it stores layoutDelta too.
203 if (!doingFullRepaint() || renderer->hasColumns() || m_layoutState->isPaginated() || hasRenderFlowThread()) {
204 m_layoutState = new (renderArena()) LayoutState(m_layoutState, renderer, offset, pageHeight, pageHeightChanged, colInfo);
210 void popLayoutState()
212 LayoutState* state = m_layoutState;
213 m_layoutState = state->m_next;
214 state->destroy(renderArena());
217 // Suspends the LayoutState optimization. Used under transforms that cannot be represented by
218 // LayoutState (common in SVG) and when manipulating the render tree during layout in ways
219 // that can trigger repaint of a non-child (e.g. when a list item moves its list marker around).
220 // Note that even when disabled, LayoutState is still used to store layoutDelta.
221 // These functions may only be accessed by LayoutStateMaintainer or LayoutStateDisabler.
222 void disableLayoutState() { m_layoutStateDisableCount++; }
223 void enableLayoutState() { ASSERT(m_layoutStateDisableCount > 0); m_layoutStateDisableCount--; }
225 size_t getRetainedWidgets(Vector<RenderWidget*>&);
226 void releaseWidgets(Vector<RenderWidget*>&);
228 friend class LayoutStateMaintainer;
229 friend class LayoutStateDisabler;
232 FrameView* m_frameView;
234 RenderObject* m_selectionStart;
235 RenderObject* m_selectionEnd;
236 int m_selectionStartPos;
237 int m_selectionEndPos;
239 // FIXME: Only used by embedded WebViews inside AppKit NSViews. Find a way to remove.
240 struct LegacyPrinting {
242 : m_bestTruncatedAt(0)
244 , m_truncatorWidth(0)
245 , m_forcedPageBreak(false)
248 int m_bestTruncatedAt;
250 int m_truncatorWidth;
252 bool m_forcedPageBreak;
254 LegacyPrinting m_legacyPrinting;
255 // End deprecated members.
257 int m_maximalOutlineSize; // Used to apply a fudge factor to dirty-rect checks on blocks/tables.
259 typedef HashSet<RenderWidget*> RenderWidgetSet;
260 RenderWidgetSet m_widgets;
263 unsigned m_pageLogicalHeight;
264 bool m_pageLogicalHeightChanged;
265 bool m_isRenderFlowThreadOrderDirty;
266 LayoutState* m_layoutState;
267 unsigned m_layoutStateDisableCount;
268 #if USE(ACCELERATED_COMPOSITING)
269 OwnPtr<RenderLayerCompositor> m_compositor;
271 OwnPtr<RenderFlowThreadList> m_renderFlowThreadList;
272 RenderFlowThread* m_currentRenderFlowThread;
275 inline RenderView* toRenderView(RenderObject* object)
277 ASSERT(!object || object->isRenderView());
278 return static_cast<RenderView*>(object);
281 inline const RenderView* toRenderView(const RenderObject* object)
283 ASSERT(!object || object->isRenderView());
284 return static_cast<const RenderView*>(object);
287 // This will catch anyone doing an unnecessary cast.
288 void toRenderView(const RenderView*);
291 // Stack-based class to assist with LayoutState push/pop
292 class LayoutStateMaintainer {
293 WTF_MAKE_NONCOPYABLE(LayoutStateMaintainer);
296 LayoutStateMaintainer(RenderView* view, RenderBox* root, LayoutSize offset, bool disableState = false, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
298 , m_disabled(disableState)
301 , m_didCreateLayoutState(false)
303 push(root, offset, pageHeight, pageHeightChanged, colInfo);
306 // ctor to maybe push later
307 LayoutStateMaintainer(RenderView* view)
312 , m_didCreateLayoutState(false)
316 ~LayoutStateMaintainer()
318 ASSERT(m_didStart == m_didEnd); // if this fires, it means that someone did a push(), but forgot to pop().
321 void push(RenderBox* root, LayoutSize offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
324 // We push state even if disabled, because we still need to store layoutDelta
325 m_didCreateLayoutState = m_view->pushLayoutState(root, offset, pageHeight, pageHeightChanged, colInfo);
326 if (m_disabled && m_didCreateLayoutState)
327 m_view->disableLayoutState();
335 if (m_didCreateLayoutState) {
336 m_view->popLayoutState();
338 m_view->enableLayoutState();
345 bool didPush() const { return m_didStart; }
349 bool m_disabled : 1; // true if the offset and clip part of layoutState is disabled
350 bool m_didStart : 1; // true if we did a push or disable
351 bool m_didEnd : 1; // true if we popped or re-enabled
352 bool m_didCreateLayoutState : 1; // true if we actually made a layout state.
355 class LayoutStateDisabler {
356 WTF_MAKE_NONCOPYABLE(LayoutStateDisabler);
358 LayoutStateDisabler(RenderView* view)
362 m_view->disableLayoutState();
365 ~LayoutStateDisabler()
368 m_view->enableLayoutState();
374 } // namespace WebCore
376 #endif // RenderView_h