• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3  * Copyright (C) 2006 Apple Computer, Inc.
4  *
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.
9  *
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.
14  *
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.
19  *
20  */
21 
22 #ifndef RenderView_h
23 #define RenderView_h
24 
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"
32 
33 namespace blink {
34 
35 class FlowThreadController;
36 class RenderLayerCompositor;
37 class RenderQuote;
38 
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 {
44 public:
45     explicit RenderView(Document*);
46     virtual ~RenderView();
47     virtual void trace(Visitor*) OVERRIDE;
48 
49     bool hitTest(const HitTestRequest&, HitTestResult&);
50     bool hitTest(const HitTestRequest&, const HitTestLocation&, HitTestResult&);
51 
52     // Returns the total count of calls to HitTest, for testing.
hitTestCount()53     unsigned hitTestCount() const { return m_hitTestCount; }
54 
renderName()55     virtual const char* renderName() const OVERRIDE { return "RenderView"; }
56 
isRenderView()57     virtual bool isRenderView() const OVERRIDE { return true; }
58 
layerTypeRequired()59     virtual LayerType layerTypeRequired() const OVERRIDE { return NormalLayer; }
60 
61     virtual bool isChildAllowed(RenderObject*, RenderStyle*) const OVERRIDE;
62 
63     virtual void layout() OVERRIDE;
64     virtual void updateLogicalWidth() OVERRIDE;
65     virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const OVERRIDE;
66 
67     virtual LayoutUnit availableLogicalHeight(AvailableLogicalHeightType) const OVERRIDE;
68 
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;
viewLogicalWidth()72     int viewLogicalWidth() const
73     {
74         return style()->isHorizontalWritingMode() ? viewWidth(ExcludeScrollbars) : viewHeight(ExcludeScrollbars);
75     }
76     int viewLogicalHeight() const;
77     LayoutUnit viewLogicalHeightForPercentages() const;
78 
79     float zoomFactor() const;
80 
frameView()81     FrameView* frameView() const { return m_frameView; }
82 
83     enum ViewportConstrainedPosition {
84         IsNotFixedPosition,
85         IsFixedPosition,
86     };
87     void mapRectToPaintInvalidationBacking(const RenderLayerModelObject* paintInvalidationContainer, LayoutRect&, ViewportConstrainedPosition, const PaintInvalidationState*) const;
88     virtual void mapRectToPaintInvalidationBacking(const RenderLayerModelObject* paintInvalidationContainer, LayoutRect&, const PaintInvalidationState*) const OVERRIDE;
89 
90     void invalidatePaintForRectangle(const LayoutRect&) const;
91 
92     void invalidatePaintForViewAndCompositedLayers();
93 
94     virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE;
95     virtual void paintBoxDecorationBackground(PaintInfo&, const LayoutPoint&) OVERRIDE;
96 
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();
selectionStart()101     RenderObject* selectionStart() const { return m_selectionStart; }
selectionEnd()102     RenderObject* selectionEnd() const { return m_selectionEnd; }
103     IntRect selectionBounds() const;
104     void selectionStartEnd(int& startPos, int& endPos) const;
105     void invalidatePaintForSelection() const;
106 
107     virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const OVERRIDE;
108     virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const OVERRIDE;
109 
110     virtual LayoutRect viewRect() const OVERRIDE;
111 
112     bool shouldDoFullPaintInvalidationForNextLayout() const;
doingFullPaintInvalidation()113     bool doingFullPaintInvalidation() const { return m_frameView->needsFullPaintInvalidation(); }
114 
layoutState()115     LayoutState* layoutState() const { return m_layoutState; }
116 
117     virtual void updateHitTestResult(HitTestResult&, const LayoutPoint&) OVERRIDE;
118 
pageLogicalHeight()119     LayoutUnit pageLogicalHeight() const { return m_pageLogicalHeight; }
setPageLogicalHeight(LayoutUnit height)120     void setPageLogicalHeight(LayoutUnit height)
121     {
122         if (m_pageLogicalHeight != height) {
123             m_pageLogicalHeight = height;
124             m_pageLogicalHeightChanged = true;
125         }
126     }
pageLogicalHeightChanged()127     bool pageLogicalHeightChanged() const { return m_pageLogicalHeightChanged; }
128 
129     // Notification that this view moved into or out of a native window.
130     void setIsInWindow(bool);
131 
132     RenderLayerCompositor* compositor();
133     bool usesCompositing() const;
134 
135     IntRect unscaledDocumentRect() const;
136     LayoutRect backgroundRect(RenderBox* backgroundRenderer) const;
137 
138     IntRect documentRect() const;
139 
140     // Renderer that paints the root background has background-images which all have background-attachment: fixed.
141     bool rootBackgroundIsEntirelyFixed() const;
142 
143     FlowThreadController* flowThreadController();
144 
145     IntervalArena* intervalArena();
146 
setRenderQuoteHead(RenderQuote * head)147     void setRenderQuoteHead(RenderQuote* head) { m_renderQuoteHead = head; }
renderQuoteHead()148     RenderQuote* renderQuoteHead() const { return m_renderQuoteHead; }
149 
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.
addRenderCounter()154     void addRenderCounter() { m_renderCounterCount++; }
removeRenderCounter()155     void removeRenderCounter() { ASSERT(m_renderCounterCount > 0); m_renderCounterCount--; }
hasRenderCounters()156     bool hasRenderCounters() { return m_renderCounterCount; }
157 
158     virtual bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect) const OVERRIDE;
159 
160     double layoutViewportWidth() const;
161     double layoutViewportHeight() const;
162 
163     void pushLayoutState(LayoutState&);
164     void popLayoutState();
165     virtual void invalidateTreeIfNeeded(const PaintInvalidationState&) OVERRIDE FINAL;
166 
167 private:
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;
172 
173     bool shouldInvalidatePaint(const LayoutRect&) const;
174 
175     void layoutContent();
176 #if ENABLE(ASSERT)
177     void checkLayoutState();
178 #endif
179 
180     friend class ForceHorriblySlowRectMapping;
181 
182     bool shouldUsePrintingLayout() const;
183 
184     RenderObject* backgroundRenderer() const;
185 
186     FrameView* m_frameView;
187 
188     RawPtrWillBeMember<RenderObject> m_selectionStart;
189     RawPtrWillBeMember<RenderObject> m_selectionEnd;
190 
191     int m_selectionStartPos;
192     int m_selectionEndPos;
193 
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;
200 
201     RawPtrWillBeMember<RenderQuote> m_renderQuoteHead;
202     unsigned m_renderCounterCount;
203 
204     unsigned m_hitTestCount;
205 };
206 
207 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderView, isRenderView());
208 
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);
216 public:
ForceHorriblySlowRectMapping(const PaintInvalidationState * paintInvalidationState)217     ForceHorriblySlowRectMapping(const PaintInvalidationState* paintInvalidationState)
218         : m_paintInvalidationState(paintInvalidationState)
219         , m_didDisable(m_paintInvalidationState && m_paintInvalidationState->cachedOffsetsEnabled())
220     {
221         if (m_paintInvalidationState)
222             m_paintInvalidationState->m_cachedOffsetsEnabled = false;
223     }
224 
~ForceHorriblySlowRectMapping()225     ~ForceHorriblySlowRectMapping()
226     {
227         if (m_didDisable)
228             m_paintInvalidationState->m_cachedOffsetsEnabled = true;
229     }
230 private:
231     const PaintInvalidationState* m_paintInvalidationState;
232     bool m_didDisable;
233 };
234 
235 } // namespace blink
236 
237 #endif // RenderView_h
238