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 virtual void updateHitTestResult(HitTestResult&, const LayoutPoint&) OVERRIDE;
146 LayoutUnit pageLogicalHeight() const { return m_pageLogicalHeight; }
147 void setPageLogicalHeight(LayoutUnit height)
149 if (m_pageLogicalHeight != height) {
150 m_pageLogicalHeight = height;
151 m_pageLogicalHeightChanged = true;
154 bool pageLogicalHeightChanged() const { return m_pageLogicalHeightChanged; }
156 // Notification that this view moved into or out of a native window.
157 void setIsInWindow(bool);
159 RenderLayerCompositor* compositor();
160 bool usesCompositing() const;
162 IntRect unscaledDocumentRect() const;
163 LayoutRect backgroundRect(RenderBox* backgroundRenderer) const;
165 IntRect documentRect() const;
167 // Renderer that paints the root background has background-images which all have background-attachment: fixed.
168 bool rootBackgroundIsEntirelyFixed() const;
170 FlowThreadController* flowThreadController();
172 IntervalArena* intervalArena();
174 void setRenderQuoteHead(RenderQuote* head) { m_renderQuoteHead = head; }
175 RenderQuote* renderQuoteHead() const { return m_renderQuoteHead; }
177 // FIXME: This is a work around because the current implementation of counters
178 // requires walking the entire tree repeatedly and most pages don't actually use either
179 // feature so we shouldn't take the performance hit when not needed. Long term we should
180 // rewrite the counter and quotes code.
181 void addRenderCounter() { m_renderCounterCount++; }
182 void removeRenderCounter() { ASSERT(m_renderCounterCount > 0); m_renderCounterCount--; }
183 bool hasRenderCounters() { return m_renderCounterCount; }
185 virtual bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect) const OVERRIDE;
187 double layoutViewportWidth() const;
188 double layoutViewportHeight() const;
190 // Suspends the LayoutState optimization. Used under transforms that cannot be represented by
191 // LayoutState (common in SVG) and when manipulating the render tree during layout in ways
192 // that can trigger repaint of a non-child (e.g. when a list item moves its list marker around).
193 // Note that even when disabled, LayoutState is still used to store layoutDelta.
194 // These functions may only be accessed by LayoutStateMaintainer or LayoutStateDisabler.
195 void disableLayoutState() { m_layoutStateDisableCount++; }
196 void enableLayoutState() { ASSERT(m_layoutStateDisableCount > 0); m_layoutStateDisableCount--; }
199 virtual void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0) const OVERRIDE;
200 virtual const RenderObject* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&) const OVERRIDE;
201 virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const OVERRIDE;
202 virtual void computeSelfHitTestRects(Vector<LayoutRect>&, const LayoutPoint& layerOffset) const OVERRIDE;
204 bool shouldRepaint(const LayoutRect&) const;
206 bool rootFillsViewportBackground(RenderBox* rootBox) const;
208 // These functions may only be accessed by LayoutStateMaintainer.
209 bool pushLayoutState(RenderBox& renderer, const LayoutSize& offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
211 // We push LayoutState even if layoutState is disabled because it stores layoutDelta too.
212 if (!doingFullRepaint() || m_layoutState->isPaginated() || renderer.hasColumns() || renderer.flowThreadContainingBlock()
214 pushLayoutStateForCurrentFlowThread(renderer);
215 m_layoutState = new LayoutState(m_layoutState, renderer, offset, pageHeight, pageHeightChanged, colInfo);
221 void layoutContent();
223 void checkLayoutState();
226 void positionDialog(RenderBox*);
227 void positionDialogs();
229 void pushLayoutStateForCurrentFlowThread(const RenderObject&);
230 void popLayoutStateForCurrentFlowThread();
232 friend class LayoutStateMaintainer;
233 friend class LayoutStateDisabler;
234 friend class RootLayoutStateScope;
236 bool shouldUsePrintingLayout() const;
238 FrameView* m_frameView;
240 RenderObject* m_selectionStart;
241 RenderObject* m_selectionEnd;
243 int m_selectionStartPos;
244 int m_selectionEndPos;
246 LayoutUnit m_pageLogicalHeight;
247 bool m_pageLogicalHeightChanged;
248 LayoutState* m_layoutState;
249 unsigned m_layoutStateDisableCount;
250 OwnPtr<RenderLayerCompositor> m_compositor;
251 OwnPtr<FlowThreadController> m_flowThreadController;
252 RefPtr<IntervalArena> m_intervalArena;
254 RenderQuote* m_renderQuoteHead;
255 unsigned m_renderCounterCount;
258 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderView, isRenderView());
260 class RootLayoutStateScope {
262 explicit RootLayoutStateScope(RenderView& view)
264 , m_rootLayoutState(view.pageLogicalHeight(), view.pageLogicalHeightChanged())
266 ASSERT(!m_view.m_layoutState);
267 m_view.m_layoutState = &m_rootLayoutState;
270 ~RootLayoutStateScope()
272 ASSERT(m_view.m_layoutState == &m_rootLayoutState);
273 m_view.m_layoutState = 0;
277 LayoutState m_rootLayoutState;
280 // Stack-based class to assist with LayoutState push/pop
281 class LayoutStateMaintainer {
282 WTF_MAKE_NONCOPYABLE(LayoutStateMaintainer);
285 explicit LayoutStateMaintainer(RenderBox& root, const LayoutSize& offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
286 : m_view(*root.view())
287 , m_disabled(root.shouldDisableLayoutState())
290 , m_didCreateLayoutState(false)
292 push(root, offset, pageHeight, pageHeightChanged, colInfo);
295 // ctor to maybe push later
296 explicit LayoutStateMaintainer(RenderBox& root)
297 : m_view(*root.view())
301 , m_didCreateLayoutState(false)
305 ~LayoutStateMaintainer()
309 ASSERT(m_didStart == m_didEnd); // if this fires, it means that someone did a push(), but forgot to pop().
312 void push(RenderBox& root, const LayoutSize& offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
315 // We push state even if disabled, because we still need to store layoutDelta
316 m_didCreateLayoutState = m_view.pushLayoutState(root, offset, pageHeight, pageHeightChanged, colInfo);
317 if (m_disabled && m_didCreateLayoutState)
318 m_view.disableLayoutState();
322 bool didPush() const { return m_didStart; }
327 ASSERT(m_didStart && !m_didEnd);
328 if (m_didCreateLayoutState) {
329 m_view.popLayoutState();
331 m_view.enableLayoutState();
338 bool m_disabled : 1; // true if the offset and clip part of layoutState is disabled
339 bool m_didStart : 1; // true if we did a push or disable
340 bool m_didEnd : 1; // true if we popped or re-enabled
341 bool m_didCreateLayoutState : 1; // true if we actually made a layout state.
344 class LayoutStateDisabler {
345 WTF_MAKE_NONCOPYABLE(LayoutStateDisabler);
347 LayoutStateDisabler(const RenderBox& root)
348 : m_view(*root.view())
350 m_view.disableLayoutState();
353 ~LayoutStateDisabler()
355 m_view.enableLayoutState();
361 } // namespace WebCore
363 #endif // RenderView_h