• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is part of the HTML widget for KDE.
3  *
4  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
5  * Copyright (C) 2006 Apple Computer, Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  */
23 
24 #ifndef RenderView_h
25 #define RenderView_h
26 
27 #include "FrameView.h"
28 #include "LayoutState.h"
29 #include "RenderBlock.h"
30 #include <wtf/OwnPtr.h>
31 
32 namespace WebCore {
33 
34 class RenderWidget;
35 
36 #if USE(ACCELERATED_COMPOSITING)
37 class RenderLayerCompositor;
38 #endif
39 
40 class RenderView : public RenderBlock {
41 public:
42     RenderView(Node*, FrameView*);
43     virtual ~RenderView();
44 
renderName()45     virtual const char* renderName() const { return "RenderView"; }
46 
isRenderView()47     virtual bool isRenderView() const { return true; }
48 
49     virtual void layout();
50     virtual void calcWidth();
51     virtual void calcHeight();
52     virtual void calcPrefWidths();
53 
54     // The same as the FrameView's layoutHeight/layoutWidth but with null check guards.
55     int viewHeight() const;
56     int viewWidth() const;
57 
58     float zoomFactor() const;
59 
frameView()60     FrameView* frameView() const { return m_frameView; }
61 
62     virtual void computeRectForRepaint(RenderBoxModelObject* repaintContainer, IntRect&, bool fixed = false);
63     virtual void repaintViewRectangle(const IntRect&, bool immediate = false);
64     // Repaint the view, and all composited layers that intersect the given absolute rectangle.
65     // FIXME: ideally we'd never have to do this, if all repaints are container-relative.
66     virtual void repaintRectangleInViewAndCompositedLayers(const IntRect&, bool immediate = false);
67 
68     virtual void paint(PaintInfo&, int tx, int ty);
69     virtual void paintBoxDecorations(PaintInfo&, int tx, int ty);
70 
71     enum SelectionRepaintMode { RepaintNewXOROld, RepaintNewMinusOld };
72     void setSelection(RenderObject* start, int startPos, RenderObject* end, int endPos, SelectionRepaintMode = RepaintNewXOROld);
73     void clearSelection();
selectionStart()74     virtual RenderObject* selectionStart() const { return m_selectionStart; }
selectionEnd()75     virtual RenderObject* selectionEnd() const { return m_selectionEnd; }
76 
77     bool printing() const;
setPrintImages(bool enable)78     void setPrintImages(bool enable) { m_printImages = enable; }
printImages()79     bool printImages() const { return m_printImages; }
setTruncatedAt(int y)80     void setTruncatedAt(int y) { m_truncatedAt = y; m_bestTruncatedAt = m_truncatorWidth = 0; m_forcedPageBreak = false; }
81     void setBestTruncatedAt(int y, RenderBoxModelObject* forRenderer, bool forcedBreak = false);
bestTruncatedAt()82     int bestTruncatedAt() const { return m_bestTruncatedAt; }
83 
truncatedAt()84     int truncatedAt() const { return m_truncatedAt; }
85 
86     virtual void absoluteRects(Vector<IntRect>&, int tx, int ty);
87     virtual void absoluteQuads(Vector<FloatQuad>&);
88 
89     IntRect selectionBounds(bool clipToVisibleContent = true) const;
90 
91 #if USE(ACCELERATED_COMPOSITING)
92     void setMaximalOutlineSize(int o);
93 #else
setMaximalOutlineSize(int o)94     void setMaximalOutlineSize(int o) { m_maximalOutlineSize = o; }
95 #endif
maximalOutlineSize()96     int maximalOutlineSize() const { return m_maximalOutlineSize; }
97 
98     virtual IntRect viewRect() const;
99 
100     void selectionStartEnd(int& startPos, int& endPos) const;
101 
printRect()102     IntRect printRect() const { return m_printRect; }
setPrintRect(const IntRect & r)103     void setPrintRect(const IntRect& r) { m_printRect = r; }
104 
105     void updateWidgetPositions();
106     void addWidget(RenderWidget*);
107     void removeWidget(RenderWidget*);
108 
109     // layoutDelta is used transiently during layout to store how far an object has moved from its
110     // last layout location, in order to repaint correctly.
111     // If we're doing a full repaint m_layoutState will be 0, but in that case layoutDelta doesn't matter.
layoutDelta()112     IntSize layoutDelta() const
113     {
114         return m_layoutState ? m_layoutState->m_layoutDelta : IntSize();
115     }
addLayoutDelta(const IntSize & delta)116     void addLayoutDelta(const IntSize& delta)
117     {
118         if (m_layoutState)
119             m_layoutState->m_layoutDelta += delta;
120     }
121 
doingFullRepaint()122     bool doingFullRepaint() const { return m_frameView->needsFullRepaint(); }
123 
pushLayoutState(RenderBox * renderer,const IntSize & offset)124     void pushLayoutState(RenderBox* renderer, const IntSize& offset)
125     {
126         if (doingFullRepaint())
127             return;
128         // We push LayoutState even if layoutState is disabled because it stores layoutDelta too.
129         m_layoutState = new (renderArena()) LayoutState(m_layoutState, renderer, offset);
130     }
131 
132     void pushLayoutState(RenderObject*);
133 
popLayoutState()134     void popLayoutState()
135     {
136         if (doingFullRepaint())
137             return;
138         LayoutState* state = m_layoutState;
139         m_layoutState = state->m_next;
140         state->destroy(renderArena());
141     }
142 
143     // Returns true if layoutState should be used for its cached offset and clip.
layoutStateEnabled()144     bool layoutStateEnabled() const { return m_layoutStateDisableCount == 0 && m_layoutState; }
layoutState()145     LayoutState* layoutState() const { return m_layoutState; }
146 
147     // Suspends the LayoutState optimization. Used under transforms that cannot be represented by
148     // LayoutState (common in SVG) and when manipulating the render tree during layout in ways
149     // that can trigger repaint of a non-child (e.g. when a list item moves its list marker around).
150     // Note that even when disabled, LayoutState is still used to store layoutDelta.
disableLayoutState()151     void disableLayoutState() { m_layoutStateDisableCount++; }
enableLayoutState()152     void enableLayoutState() { ASSERT(m_layoutStateDisableCount > 0); m_layoutStateDisableCount--; }
153 
154     virtual void updateHitTestResult(HitTestResult&, const IntPoint&);
155 
156     // Notifications that this view became visible in a window, or will be
157     // removed from the window.
158     void didMoveOnscreen();
159     void willMoveOffscreen();
160 
161 #if USE(ACCELERATED_COMPOSITING)
162     RenderLayerCompositor* compositor();
163     bool usesCompositing() const;
164 #endif
165 
166 protected:
167     virtual void mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool useTransforms, bool fixed, TransformState&) const;
168     virtual void mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState&) const;
169 
170 private:
171     bool shouldRepaint(const IntRect& r) const;
172 
173 #ifdef FLATTEN_FRAMESET
174 public: // used by layout function
175 #endif
176     int docHeight() const;
177     int docWidth() const;
178 
179 protected:
180     FrameView* m_frameView;
181 
182     RenderObject* m_selectionStart;
183     RenderObject* m_selectionEnd;
184     int m_selectionStartPos;
185     int m_selectionEndPos;
186 
187     // used to ignore viewport width when printing to the printer
188     bool m_printImages;
189     int m_truncatedAt;
190 
191     int m_maximalOutlineSize; // Used to apply a fudge factor to dirty-rect checks on blocks/tables.
192     IntRect m_printRect; // Used when printing.
193 
194     typedef HashSet<RenderWidget*> RenderWidgetSet;
195 
196     RenderWidgetSet m_widgets;
197 
198 private:
199     IntRect m_cachedSelectionBounds;
200 
201     int m_bestTruncatedAt;
202     int m_truncatorWidth;
203     bool m_forcedPageBreak;
204     LayoutState* m_layoutState;
205     unsigned m_layoutStateDisableCount;
206 #if USE(ACCELERATED_COMPOSITING)
207     OwnPtr<RenderLayerCompositor> m_compositor;
208 #endif
209 };
210 
toRenderView(RenderObject * object)211 inline RenderView* toRenderView(RenderObject* object)
212 {
213     ASSERT(!object || object->isRenderView());
214     return static_cast<RenderView*>(object);
215 }
216 
toRenderView(const RenderObject * object)217 inline const RenderView* toRenderView(const RenderObject* object)
218 {
219     ASSERT(!object || object->isRenderView());
220     return static_cast<const RenderView*>(object);
221 }
222 
223 // This will catch anyone doing an unnecessary cast.
224 void toRenderView(const RenderView*);
225 
226 
227 // Stack-based class to assist with LayoutState push/pop
228 class LayoutStateMaintainer : public Noncopyable {
229 public:
230     // ctor to push now
231     LayoutStateMaintainer(RenderView* view, RenderBox* root, IntSize offset, bool disableState = false)
m_view(view)232         : m_view(view)
233         , m_disabled(disableState)
234         , m_didStart(false)
235         , m_didEnd(false)
236     {
237         push(root, offset);
238     }
239 
240     // ctor to maybe push later
LayoutStateMaintainer(RenderView * view)241     LayoutStateMaintainer(RenderView* view)
242         : m_view(view)
243         , m_disabled(false)
244         , m_didStart(false)
245         , m_didEnd(false)
246     {
247     }
248 
~LayoutStateMaintainer()249     ~LayoutStateMaintainer()
250     {
251         ASSERT(m_didStart == m_didEnd);   // if this fires, it means that someone did a push(), but forgot to pop().
252     }
253 
push(RenderBox * root,IntSize offset)254     void push(RenderBox* root, IntSize offset)
255     {
256         ASSERT(!m_didStart);
257         // We push state even if disabled, because we still need to store layoutDelta
258         m_view->pushLayoutState(root, offset);
259         if (m_disabled)
260             m_view->disableLayoutState();
261         m_didStart = true;
262     }
263 
pop()264     void pop()
265     {
266         if (m_didStart) {
267             ASSERT(!m_didEnd);
268             m_view->popLayoutState();
269             if (m_disabled)
270                 m_view->enableLayoutState();
271             m_didEnd = true;
272         }
273     }
274 
didPush()275     bool didPush() const { return m_didStart; }
276 
277 private:
278     RenderView* m_view;
279     bool m_disabled : 1;        // true if the offset and clip part of layoutState is disabled
280     bool m_didStart : 1;        // true if we did a push or disable
281     bool m_didEnd : 1;          // true if we popped or re-enabled
282 };
283 
284 } // namespace WebCore
285 
286 #endif // RenderView_h
287