OSDN Git Service

c287579e7f907a1fda33012973e99254a4eca535
[android-x86/external-webkit.git] / WebCore / rendering / RenderView.h
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 "FrameView.h"
26 #include "LayoutState.h"
27 #include "RenderBlock.h"
28 #include <wtf/OwnPtr.h>
29
30 namespace WebCore {
31
32 class RenderWidget;
33
34 #if USE(ACCELERATED_COMPOSITING)
35 class RenderLayerCompositor;
36 #endif
37
38 class RenderView : public RenderBlock {
39 public:
40     RenderView(Node*, FrameView*);
41     virtual ~RenderView();
42
43     virtual const char* renderName() const { return "RenderView"; }
44
45     virtual bool isRenderView() const { return true; }
46
47     virtual void layout();
48     virtual void calcWidth();
49     virtual void calcHeight();
50     virtual void calcPrefWidths();
51
52     // The same as the FrameView's layoutHeight/layoutWidth but with null check guards.
53     int viewHeight() const;
54     int viewWidth() const;
55
56     float zoomFactor() const;
57
58     FrameView* frameView() const { return m_frameView; }
59
60     virtual void computeRectForRepaint(RenderBoxModelObject* repaintContainer, IntRect&, bool fixed = false);
61     virtual void repaintViewRectangle(const IntRect&, bool immediate = false);
62     // Repaint the view, and all composited layers that intersect the given absolute rectangle.
63     // FIXME: ideally we'd never have to do this, if all repaints are container-relative.
64     virtual void repaintRectangleInViewAndCompositedLayers(const IntRect&, bool immediate = false);
65
66     virtual void paint(PaintInfo&, int tx, int ty);
67     virtual void paintBoxDecorations(PaintInfo&, int tx, int ty);
68
69     enum SelectionRepaintMode { RepaintNewXOROld, RepaintNewMinusOld };
70     void setSelection(RenderObject* start, int startPos, RenderObject* end, int endPos, SelectionRepaintMode = RepaintNewXOROld);
71     void clearSelection();
72     virtual RenderObject* selectionStart() const { return m_selectionStart; }
73     virtual RenderObject* selectionEnd() const { return m_selectionEnd; }
74
75     bool printing() const;
76     void setPrintImages(bool enable) { m_printImages = enable; }
77     bool printImages() const { return m_printImages; }
78     void setTruncatedAt(int y) { m_truncatedAt = y; m_bestTruncatedAt = m_truncatorWidth = 0; m_minimumColumnHeight = 0; m_forcedPageBreak = false; }
79     void setBestTruncatedAt(int y, RenderBoxModelObject* forRenderer, bool forcedBreak = false);
80     void setMinimumColumnHeight(int height) { m_minimumColumnHeight = height; }
81     int bestTruncatedAt() const { return m_bestTruncatedAt; }
82     int minimumColumnHeight() const { return m_minimumColumnHeight; }
83
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
94     void setMaximalOutlineSize(int o) { m_maximalOutlineSize = o; }
95 #endif
96     int maximalOutlineSize() const { return m_maximalOutlineSize; }
97
98     virtual IntRect viewRect() const;
99
100     void selectionStartEnd(int& startPos, int& endPos) const;
101
102     IntRect printRect() const { return m_printRect; }
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.
112     IntSize layoutDelta() const
113     {
114         return m_layoutState ? m_layoutState->m_layoutDelta : IntSize();
115     }
116     void addLayoutDelta(const IntSize& delta) 
117     {
118         if (m_layoutState)
119             m_layoutState->m_layoutDelta += delta;
120     }
121
122     bool doingFullRepaint() const { return m_frameView->needsFullRepaint(); }
123
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
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     bool shouldDisableLayoutStateForSubtree(RenderObject*) const;
144
145     // Returns true if layoutState should be used for its cached offset and clip.
146     bool layoutStateEnabled() const { return m_layoutStateDisableCount == 0 && m_layoutState; }
147     LayoutState* layoutState() const { return m_layoutState; }
148
149     // Suspends the LayoutState optimization. Used under transforms that cannot be represented by
150     // LayoutState (common in SVG) and when manipulating the render tree during layout in ways
151     // that can trigger repaint of a non-child (e.g. when a list item moves its list marker around).
152     // Note that even when disabled, LayoutState is still used to store layoutDelta.
153     void disableLayoutState() { m_layoutStateDisableCount++; }
154     void enableLayoutState() { ASSERT(m_layoutStateDisableCount > 0); m_layoutStateDisableCount--; }
155
156     virtual void updateHitTestResult(HitTestResult&, const IntPoint&);
157
158     // Notifications that this view became visible in a window, or will be
159     // removed from the window.
160     void didMoveOnscreen();
161     void willMoveOffscreen();
162
163 #if USE(ACCELERATED_COMPOSITING)
164     RenderLayerCompositor* compositor();
165     bool usesCompositing() const;
166 #endif
167
168 protected:
169     virtual void mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool useTransforms, bool fixed, TransformState&) const;
170     virtual void mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState&) const;
171
172 private:
173     bool shouldRepaint(const IntRect& r) const;
174         
175 #ifdef FLATTEN_FRAMESET
176 public: // used by layout function
177 #endif
178     int docHeight() const;
179     int docWidth() const;
180
181 protected:
182     FrameView* m_frameView;
183
184     RenderObject* m_selectionStart;
185     RenderObject* m_selectionEnd;
186     int m_selectionStartPos;
187     int m_selectionEndPos;
188
189     // used to ignore viewport width when printing to the printer
190     bool m_printImages;
191     int m_truncatedAt;
192
193     int m_maximalOutlineSize; // Used to apply a fudge factor to dirty-rect checks on blocks/tables.
194     IntRect m_printRect; // Used when printing.
195
196     typedef HashSet<RenderWidget*> RenderWidgetSet;
197
198     RenderWidgetSet m_widgets;
199
200 private:
201     int m_bestTruncatedAt;
202     int m_truncatorWidth;
203     int m_minimumColumnHeight;
204     bool m_forcedPageBreak;
205     LayoutState* m_layoutState;
206     unsigned m_layoutStateDisableCount;
207 #if USE(ACCELERATED_COMPOSITING)
208     OwnPtr<RenderLayerCompositor> m_compositor;
209 #endif
210 };
211
212 inline RenderView* toRenderView(RenderObject* object)
213 {
214     ASSERT(!object || object->isRenderView());
215     return static_cast<RenderView*>(object);
216 }
217
218 inline const RenderView* toRenderView(const RenderObject* object)
219 {
220     ASSERT(!object || object->isRenderView());
221     return static_cast<const RenderView*>(object);
222 }
223
224 // This will catch anyone doing an unnecessary cast.
225 void toRenderView(const RenderView*);
226
227
228 // Stack-based class to assist with LayoutState push/pop
229 class LayoutStateMaintainer : public Noncopyable {
230 public:
231     // ctor to push now
232     LayoutStateMaintainer(RenderView* view, RenderBox* root, IntSize offset, bool disableState = false)
233         : m_view(view)
234         , m_disabled(disableState)
235         , m_didStart(false)
236         , m_didEnd(false)
237     {
238         push(root, offset);
239     }
240     
241     // ctor to maybe push later
242     LayoutStateMaintainer(RenderView* view)
243         : m_view(view)
244         , m_disabled(false)
245         , m_didStart(false)
246         , m_didEnd(false)
247     {
248     }
249     
250     ~LayoutStateMaintainer()
251     {
252         ASSERT(m_didStart == m_didEnd);   // if this fires, it means that someone did a push(), but forgot to pop().
253     }
254
255     void push(RenderBox* root, IntSize offset)
256     {
257         ASSERT(!m_didStart);
258         // We push state even if disabled, because we still need to store layoutDelta
259         m_view->pushLayoutState(root, offset);
260         if (m_disabled)
261             m_view->disableLayoutState();
262         m_didStart = true;
263     }
264
265     void pop()
266     {
267         if (m_didStart) {
268             ASSERT(!m_didEnd);
269             m_view->popLayoutState();
270             if (m_disabled)
271                 m_view->enableLayoutState();
272             m_didEnd = true;
273         }
274     }
275
276     bool didPush() const { return m_didStart; }
277
278 private:
279     RenderView* m_view;
280     bool m_disabled : 1;        // true if the offset and clip part of layoutState is disabled
281     bool m_didStart : 1;        // true if we did a push or disable
282     bool m_didEnd : 1;          // true if we popped or re-enabled
283 };
284
285 } // namespace WebCore
286
287 #endif // RenderView_h