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 "core/frame/FrameView.h"
26 #include "core/rendering/LayoutState.h"
27 #include "core/rendering/RenderBlockFlow.h"
28 #include "platform/PODFreeListArena.h"
29 #include "platform/scroll/ScrollableArea.h"
30 #include "wtf/OwnPtr.h"
34 class FlowThreadController;
35 class RenderLayerCompositor;
38 // The root of the render tree, corresponding to the CSS initial containing block.
39 // It's dimensions match that of the logical viewport (which may be different from
40 // the visible viewport in fixed-layout mode), and it is always at position (0,0)
41 // relative to the document (and so isn't necessarily in view).
42 class RenderView FINAL : public RenderBlockFlow {
44 explicit RenderView(Document*);
45 virtual ~RenderView();
47 bool hitTest(const HitTestRequest&, HitTestResult&);
48 bool hitTest(const HitTestRequest&, const HitTestLocation&, HitTestResult&);
50 virtual const char* renderName() const OVERRIDE { return "RenderView"; }
52 virtual bool isRenderView() const OVERRIDE { return true; }
54 virtual LayerType layerTypeRequired() const OVERRIDE { return NormalLayer; }
56 virtual bool isChildAllowed(RenderObject*, RenderStyle*) const OVERRIDE;
58 virtual void layout() OVERRIDE;
59 virtual void updateLogicalWidth() OVERRIDE;
60 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const OVERRIDE;
62 virtual LayoutUnit availableLogicalHeight(AvailableLogicalHeightType) const OVERRIDE;
64 // The same as the FrameView's layoutHeight/layoutWidth but with null check guards.
65 int viewHeight(IncludeScrollbarsInRect = ExcludeScrollbars) const;
66 int viewWidth(IncludeScrollbarsInRect = ExcludeScrollbars) const;
67 int viewLogicalWidth() const
69 return style()->isHorizontalWritingMode() ? viewWidth(ExcludeScrollbars) : viewHeight(ExcludeScrollbars);
71 int viewLogicalHeight() const;
73 float zoomFactor() const;
75 FrameView* frameView() const { return m_frameView; }
77 virtual void computeRectForRepaint(const RenderLayerModelObject* repaintContainer, LayoutRect&, bool fixed = false) const OVERRIDE;
78 void repaintViewRectangle(const LayoutRect&) const;
80 void repaintViewAndCompositedLayers();
82 virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE;
83 virtual void paintBoxDecorations(PaintInfo&, const LayoutPoint&) OVERRIDE;
85 enum SelectionRepaintMode { RepaintNewXOROld, RepaintNewMinusOld, RepaintNothing };
86 void setSelection(RenderObject* start, int startPos, RenderObject* end, int endPos, SelectionRepaintMode = RepaintNewXOROld);
87 void getSelection(RenderObject*& startRenderer, int& startOffset, RenderObject*& endRenderer, int& endOffset) const;
88 void clearSelection();
89 RenderObject* selectionStart() const { return m_selectionStart; }
90 RenderObject* selectionEnd() const { return m_selectionEnd; }
91 IntRect selectionBounds(bool clipToVisibleContent = true) const;
92 void selectionStartEnd(int& startPos, int& endPos) const;
93 void repaintSelection() const;
95 virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const OVERRIDE;
96 virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const OVERRIDE;
98 virtual LayoutRect viewRect() const OVERRIDE;
100 // layoutDelta is used transiently during layout to store how far an object has moved from its
101 // last layout location, in order to repaint correctly.
102 // If we're doing a full repaint m_layoutState will be 0, but in that case layoutDelta doesn't matter.
103 LayoutSize layoutDelta() const
105 ASSERT(!RuntimeEnabledFeatures::repaintAfterLayoutEnabled());
106 return m_layoutState ? m_layoutState->layoutDelta() : LayoutSize();
108 void addLayoutDelta(const LayoutSize& delta)
110 ASSERT(!RuntimeEnabledFeatures::repaintAfterLayoutEnabled());
112 m_layoutState->addLayoutDelta(delta);
116 bool layoutDeltaMatches(const LayoutSize& delta)
118 ASSERT(!RuntimeEnabledFeatures::repaintAfterLayoutEnabled());
121 return (delta.width() == m_layoutState->layoutDelta().width() || m_layoutState->layoutDeltaXSaturated()) && (delta.height() == m_layoutState->layoutDelta().height() || m_layoutState->layoutDeltaYSaturated());
125 bool doingFullRepaint() const { return m_frameView->needsFullRepaint(); }
128 void pushLayoutState(RenderObject&);
130 void popLayoutState()
132 LayoutState* state = m_layoutState;
133 m_layoutState = state->next();
135 popLayoutStateForCurrentFlowThread();
138 bool shouldDisableLayoutStateForSubtree(RenderObject&) const;
140 // Returns true if layoutState should be used for its cached offset and clip.
141 bool layoutStateEnabled() const { return m_layoutStateDisableCount == 0 && m_layoutState; }
142 LayoutState* layoutState() const { return m_layoutState; }
144 bool canUseLayoutStateForContainer(const RenderObject* repaintContainer) const
146 // FIXME: LayoutState should be enabled for other repaint containers than the RenderView. crbug.com/363834
147 return layoutStateEnabled() && (repaintContainer == this);
150 virtual void updateHitTestResult(HitTestResult&, const LayoutPoint&) OVERRIDE;
152 LayoutUnit pageLogicalHeight() const { return m_pageLogicalHeight; }
153 void setPageLogicalHeight(LayoutUnit height)
155 if (m_pageLogicalHeight != height) {
156 m_pageLogicalHeight = height;
157 m_pageLogicalHeightChanged = true;
160 bool pageLogicalHeightChanged() const { return m_pageLogicalHeightChanged; }
162 // Notification that this view moved into or out of a native window.
163 void setIsInWindow(bool);
165 RenderLayerCompositor* compositor();
166 bool usesCompositing() const;
168 IntRect unscaledDocumentRect() const;
169 LayoutRect backgroundRect(RenderBox* backgroundRenderer) const;
171 IntRect documentRect() const;
173 // Renderer that paints the root background has background-images which all have background-attachment: fixed.
174 bool rootBackgroundIsEntirelyFixed() const;
176 FlowThreadController* flowThreadController();
178 IntervalArena* intervalArena();
180 void setRenderQuoteHead(RenderQuote* head) { m_renderQuoteHead = head; }
181 RenderQuote* renderQuoteHead() const { return m_renderQuoteHead; }
183 // FIXME: This is a work around because the current implementation of counters
184 // requires walking the entire tree repeatedly and most pages don't actually use either
185 // feature so we shouldn't take the performance hit when not needed. Long term we should
186 // rewrite the counter and quotes code.
187 void addRenderCounter() { m_renderCounterCount++; }
188 void removeRenderCounter() { ASSERT(m_renderCounterCount > 0); m_renderCounterCount--; }
189 bool hasRenderCounters() { return m_renderCounterCount; }
191 virtual bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect) const OVERRIDE;
193 double layoutViewportWidth() const;
194 double layoutViewportHeight() const;
196 // Suspends the LayoutState optimization. Used under transforms that cannot be represented by
197 // LayoutState (common in SVG) and when manipulating the render tree during layout in ways
198 // that can trigger repaint of a non-child (e.g. when a list item moves its list marker around).
199 // Note that even when disabled, LayoutState is still used to store layoutDelta.
200 // These functions may only be accessed by LayoutStateMaintainer or LayoutStateDisabler.
201 void disableLayoutState() { m_layoutStateDisableCount++; }
202 void enableLayoutState() { ASSERT(m_layoutStateDisableCount > 0); m_layoutStateDisableCount--; }
205 virtual void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0) const OVERRIDE;
206 virtual const RenderObject* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&) const OVERRIDE;
207 virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const OVERRIDE;
208 virtual void computeSelfHitTestRects(Vector<LayoutRect>&, const LayoutPoint& layerOffset) const OVERRIDE;
210 bool shouldRepaint(const LayoutRect&) const;
212 bool rootFillsViewportBackground(RenderBox* rootBox) const;
214 // These functions may only be accessed by LayoutStateMaintainer.
215 bool pushLayoutState(RenderBox& renderer, const LayoutSize& offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
217 // We push LayoutState even if layoutState is disabled because it stores layoutDelta too.
218 if ((!doingFullRepaint() || RuntimeEnabledFeatures::repaintAfterLayoutEnabled()) || m_layoutState->isPaginated() || renderer.hasColumns() || renderer.flowThreadContainingBlock()
220 pushLayoutStateForCurrentFlowThread(renderer);
221 m_layoutState = new LayoutState(m_layoutState, renderer, offset, pageHeight, pageHeightChanged, colInfo);
227 void layoutContent();
229 void checkLayoutState();
232 void positionDialog(RenderBox*);
233 void positionDialogs();
235 void pushLayoutStateForCurrentFlowThread(const RenderObject&);
236 void popLayoutStateForCurrentFlowThread();
238 friend class LayoutStateMaintainer;
239 friend class LayoutStateDisabler;
240 friend class RootLayoutStateScope;
242 bool shouldUsePrintingLayout() const;
244 FrameView* m_frameView;
246 RenderObject* m_selectionStart;
247 RenderObject* m_selectionEnd;
249 int m_selectionStartPos;
250 int m_selectionEndPos;
252 LayoutUnit m_pageLogicalHeight;
253 bool m_pageLogicalHeightChanged;
254 LayoutState* m_layoutState;
255 unsigned m_layoutStateDisableCount;
256 OwnPtr<RenderLayerCompositor> m_compositor;
257 OwnPtr<FlowThreadController> m_flowThreadController;
258 RefPtr<IntervalArena> m_intervalArena;
260 RenderQuote* m_renderQuoteHead;
261 unsigned m_renderCounterCount;
264 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderView, isRenderView());
266 class RootLayoutStateScope {
268 explicit RootLayoutStateScope(RenderObject& obj)
269 : m_view(*obj.view())
270 , m_rootLayoutState(m_view.pageLogicalHeight(), m_view.pageLogicalHeightChanged())
271 , m_isRenderView(obj.isRenderView())
273 // If the invalidation root isn't the renderView we have to make sure it
274 // gets added correctly to LayoutState otherwise we'll lose the margins that
275 // are set in the ancestors of the roots.
276 if (m_isRenderView) {
277 ASSERT(!m_view.m_layoutState);
278 m_view.m_layoutState = &m_rootLayoutState;
280 m_view.pushLayoutState(obj);
284 ~RootLayoutStateScope()
286 if (m_isRenderView) {
287 ASSERT(m_view.m_layoutState == &m_rootLayoutState);
288 m_view.m_layoutState = 0;
290 m_view.popLayoutState();
295 LayoutState m_rootLayoutState;
299 // Stack-based class to assist with LayoutState push/pop
300 class LayoutStateMaintainer {
301 WTF_MAKE_NONCOPYABLE(LayoutStateMaintainer);
304 explicit LayoutStateMaintainer(RenderBox& root, const LayoutSize& offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
305 : m_view(*root.view())
306 , m_disabled(root.shouldDisableLayoutState())
309 , m_didCreateLayoutState(false)
311 push(root, offset, pageHeight, pageHeightChanged, colInfo);
314 // ctor to maybe push later
315 explicit LayoutStateMaintainer(RenderBox& root)
316 : m_view(*root.view())
320 , m_didCreateLayoutState(false)
324 ~LayoutStateMaintainer()
328 ASSERT(m_didStart == m_didEnd); // if this fires, it means that someone did a push(), but forgot to pop().
331 void push(RenderBox& root, const LayoutSize& offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
334 // We push state even if disabled, because we still need to store layoutDelta
335 m_didCreateLayoutState = m_view.pushLayoutState(root, offset, pageHeight, pageHeightChanged, colInfo);
336 if (m_disabled && m_didCreateLayoutState)
337 m_view.disableLayoutState();
341 bool didPush() const { return m_didStart; }
346 ASSERT(m_didStart && !m_didEnd);
347 if (m_didCreateLayoutState) {
348 m_view.popLayoutState();
350 m_view.enableLayoutState();
357 bool m_disabled : 1; // true if the offset and clip part of layoutState is disabled
358 bool m_didStart : 1; // true if we did a push or disable
359 bool m_didEnd : 1; // true if we popped or re-enabled
360 bool m_didCreateLayoutState : 1; // true if we actually made a layout state.
363 class LayoutStateDisabler {
364 WTF_MAKE_NONCOPYABLE(LayoutStateDisabler);
366 LayoutStateDisabler(const RenderObject& root)
367 : m_view(*root.view())
369 m_view.disableLayoutState();
372 ~LayoutStateDisabler()
374 m_view.enableLayoutState();
380 } // namespace WebCore
382 #endif // RenderView_h