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/PaintInvalidationState.h"
28 #include "core/rendering/RenderBlockFlow.h"
29 #include "platform/PODFreeListArena.h"
30 #include "platform/scroll/ScrollableArea.h"
31 #include "wtf/OwnPtr.h"
35 class FlowThreadController;
36 class RenderLayerCompositor;
39 // The root of the render tree, corresponding to the CSS initial containing block.
40 // It's dimensions match that of the logical viewport (which may be different from
41 // the visible viewport in fixed-layout mode), and it is always at position (0,0)
42 // relative to the document (and so isn't necessarily in view).
43 class RenderView FINAL : public RenderBlockFlow {
45 explicit RenderView(Document*);
46 virtual ~RenderView();
47 virtual void trace(Visitor*) OVERRIDE;
49 bool hitTest(const HitTestRequest&, HitTestResult&);
50 bool hitTest(const HitTestRequest&, const HitTestLocation&, HitTestResult&);
52 // Returns the total count of calls to HitTest, for testing.
53 unsigned hitTestCount() const { return m_hitTestCount; }
55 virtual const char* renderName() const OVERRIDE { return "RenderView"; }
57 virtual bool isRenderView() const OVERRIDE { return true; }
59 virtual LayerType layerTypeRequired() const OVERRIDE { return NormalLayer; }
61 virtual bool isChildAllowed(RenderObject*, RenderStyle*) const OVERRIDE;
63 virtual void layout() OVERRIDE;
64 virtual void updateLogicalWidth() OVERRIDE;
65 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const OVERRIDE;
67 virtual LayoutUnit availableLogicalHeight(AvailableLogicalHeightType) const OVERRIDE;
69 // The same as the FrameView's layoutHeight/layoutWidth but with null check guards.
70 int viewHeight(IncludeScrollbarsInRect = ExcludeScrollbars) const;
71 int viewWidth(IncludeScrollbarsInRect = ExcludeScrollbars) const;
72 int viewLogicalWidth() const
74 return style()->isHorizontalWritingMode() ? viewWidth(ExcludeScrollbars) : viewHeight(ExcludeScrollbars);
76 int viewLogicalHeight() const;
77 LayoutUnit viewLogicalHeightForPercentages() const;
79 float zoomFactor() const;
81 FrameView* frameView() const { return m_frameView; }
83 enum ViewportConstrainedPosition {
87 void mapRectToPaintInvalidationBacking(const RenderLayerModelObject* paintInvalidationContainer, LayoutRect&, ViewportConstrainedPosition, const PaintInvalidationState*) const;
88 virtual void mapRectToPaintInvalidationBacking(const RenderLayerModelObject* paintInvalidationContainer, LayoutRect&, const PaintInvalidationState*) const OVERRIDE;
90 void invalidatePaintForRectangle(const LayoutRect&) const;
92 void invalidatePaintForViewAndCompositedLayers();
94 virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE;
95 virtual void paintBoxDecorationBackground(PaintInfo&, const LayoutPoint&) OVERRIDE;
97 enum SelectionPaintInvalidationMode { PaintInvalidationNewXOROld, PaintInvalidationNewMinusOld, PaintInvalidationNothing };
98 void setSelection(RenderObject* start, int startPos, RenderObject*, int endPos, SelectionPaintInvalidationMode = PaintInvalidationNewXOROld);
99 void getSelection(RenderObject*& startRenderer, int& startOffset, RenderObject*& endRenderer, int& endOffset) const;
100 void clearSelection();
101 RenderObject* selectionStart() const { return m_selectionStart; }
102 RenderObject* selectionEnd() const { return m_selectionEnd; }
103 IntRect selectionBounds() const;
104 void selectionStartEnd(int& startPos, int& endPos) const;
105 void invalidatePaintForSelection() const;
107 virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const OVERRIDE;
108 virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const OVERRIDE;
110 virtual LayoutRect viewRect() const OVERRIDE;
112 bool shouldDoFullPaintInvalidationForNextLayout() const;
113 bool doingFullPaintInvalidation() const { return m_frameView->needsFullPaintInvalidation(); }
115 LayoutState* layoutState() const { return m_layoutState; }
117 virtual void updateHitTestResult(HitTestResult&, const LayoutPoint&) OVERRIDE;
119 LayoutUnit pageLogicalHeight() const { return m_pageLogicalHeight; }
120 void setPageLogicalHeight(LayoutUnit height)
122 if (m_pageLogicalHeight != height) {
123 m_pageLogicalHeight = height;
124 m_pageLogicalHeightChanged = true;
127 bool pageLogicalHeightChanged() const { return m_pageLogicalHeightChanged; }
129 // Notification that this view moved into or out of a native window.
130 void setIsInWindow(bool);
132 RenderLayerCompositor* compositor();
133 bool usesCompositing() const;
135 IntRect unscaledDocumentRect() const;
136 LayoutRect backgroundRect(RenderBox* backgroundRenderer) const;
138 IntRect documentRect() const;
140 // Renderer that paints the root background has background-images which all have background-attachment: fixed.
141 bool rootBackgroundIsEntirelyFixed() const;
143 FlowThreadController* flowThreadController();
145 IntervalArena* intervalArena();
147 void setRenderQuoteHead(RenderQuote* head) { m_renderQuoteHead = head; }
148 RenderQuote* renderQuoteHead() const { return m_renderQuoteHead; }
150 // FIXME: This is a work around because the current implementation of counters
151 // requires walking the entire tree repeatedly and most pages don't actually use either
152 // feature so we shouldn't take the performance hit when not needed. Long term we should
153 // rewrite the counter and quotes code.
154 void addRenderCounter() { m_renderCounterCount++; }
155 void removeRenderCounter() { ASSERT(m_renderCounterCount > 0); m_renderCounterCount--; }
156 bool hasRenderCounters() { return m_renderCounterCount; }
158 virtual bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect) const OVERRIDE;
160 double layoutViewportWidth() const;
161 double layoutViewportHeight() const;
163 void pushLayoutState(LayoutState&);
164 void popLayoutState();
165 virtual void invalidateTreeIfNeeded(const PaintInvalidationState&) OVERRIDE FINAL;
168 virtual void mapLocalToContainer(const RenderLayerModelObject* paintInvalidationContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0, const PaintInvalidationState* = 0) const OVERRIDE;
169 virtual const RenderObject* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&) const OVERRIDE;
170 virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const OVERRIDE;
171 virtual void computeSelfHitTestRects(Vector<LayoutRect>&, const LayoutPoint& layerOffset) const OVERRIDE;
173 bool shouldInvalidatePaint(const LayoutRect&) const;
175 void layoutContent();
177 void checkLayoutState();
180 friend class ForceHorriblySlowRectMapping;
182 bool shouldUsePrintingLayout() const;
184 RenderObject* backgroundRenderer() const;
186 FrameView* m_frameView;
188 RawPtrWillBeMember<RenderObject> m_selectionStart;
189 RawPtrWillBeMember<RenderObject> m_selectionEnd;
191 int m_selectionStartPos;
192 int m_selectionEndPos;
194 LayoutUnit m_pageLogicalHeight;
195 bool m_pageLogicalHeightChanged;
196 LayoutState* m_layoutState;
197 OwnPtr<RenderLayerCompositor> m_compositor;
198 OwnPtr<FlowThreadController> m_flowThreadController;
199 RefPtr<IntervalArena> m_intervalArena;
201 RawPtrWillBeMember<RenderQuote> m_renderQuoteHead;
202 unsigned m_renderCounterCount;
204 unsigned m_hitTestCount;
207 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderView, isRenderView());
209 // Suspends the LayoutState cached offset and clipRect optimization. Used under transforms
210 // that cannot be represented by LayoutState (common in SVG) and when manipulating the render
211 // tree during layout in ways that can trigger paint invalidation of a non-child (e.g. when a list item
212 // moves its list marker around). Note that even when disabled, LayoutState is still used to
213 // store layoutDelta.
214 class ForceHorriblySlowRectMapping {
215 WTF_MAKE_NONCOPYABLE(ForceHorriblySlowRectMapping);
217 ForceHorriblySlowRectMapping(const PaintInvalidationState* paintInvalidationState)
218 : m_paintInvalidationState(paintInvalidationState)
219 , m_didDisable(m_paintInvalidationState && m_paintInvalidationState->cachedOffsetsEnabled())
221 if (m_paintInvalidationState)
222 m_paintInvalidationState->m_cachedOffsetsEnabled = false;
225 ~ForceHorriblySlowRectMapping()
228 m_paintInvalidationState->m_cachedOffsetsEnabled = true;
231 const PaintInvalidationState* m_paintInvalidationState;
237 #endif // RenderView_h