]> git.saurik.com Git - iphone-api.git/blob - WebCore/RenderView.h
Add support for new WinterBoard Settings features.
[iphone-api.git] / WebCore / RenderView.h
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 "Frame.h"
29 #include "LayoutState.h"
30 #include "RenderBlock.h"
31 #include <wtf/OwnPtr.h>
32
33 namespace WebCore {
34
35 #if USE(ACCELERATED_COMPOSITING)
36 class RenderLayerCompositor;
37 #endif
38
39 class RenderView : public RenderBlock {
40 public:
41 RenderView(Node*, FrameView*);
42 virtual ~RenderView();
43
44 virtual const char* renderName() const { return "RenderView"; }
45
46 virtual bool isRenderView() const { return true; }
47
48 virtual void layout();
49 virtual void calcWidth();
50 virtual void calcHeight();
51 virtual void calcPrefWidths();
52
53 int docHeight() const;
54 int docWidth() const;
55
56 // The same as the FrameView's layoutHeight/layoutWidth but with null check guards.
57 int viewHeight() const;
58 int viewWidth() const;
59
60 float zoomFactor() const { return m_frameView->frame() && m_frameView->frame()->shouldApplyPageZoom() ? m_frameView->frame()->zoomFactor() : 1.0f; }
61
62 FrameView* frameView() const { return m_frameView; }
63
64 virtual bool hasOverhangingFloats() { return false; }
65
66 virtual void computeRectForRepaint(RenderBox* repaintContainer, IntRect&, bool fixed = false);
67 virtual void repaintViewRectangle(const IntRect&, bool immediate = false);
68 // Repaint the view, and all composited layers that intersect the given absolute rectangle.
69 // FIXME: ideally we'd never have to do this, if all repaints are container-relative.
70 virtual void repaintRectangleInViewAndCompositedLayers(const IntRect&, bool immediate = false);
71
72 virtual void paint(PaintInfo&, int tx, int ty);
73 virtual void paintBoxDecorations(PaintInfo&, int tx, int ty);
74
75 void setSelection(RenderObject* start, int startPos, RenderObject* end, int endPos);
76 void clearSelection();
77 virtual RenderObject* selectionStart() const { return m_selectionStart; }
78 virtual RenderObject* selectionEnd() const { return m_selectionEnd; }
79
80 bool printing() const;
81 void setPrintImages(bool enable) { m_printImages = enable; }
82 bool printImages() const { return m_printImages; }
83 void setTruncatedAt(int y) { m_truncatedAt = y; m_bestTruncatedAt = m_truncatorWidth = 0; m_forcedPageBreak = false; }
84 void setBestTruncatedAt(int y, RenderBox* forRenderer, bool forcedBreak = false);
85 int bestTruncatedAt() const { return m_bestTruncatedAt; }
86
87 int truncatedAt() const { return m_truncatedAt; }
88
89 virtual void absoluteRects(Vector<IntRect>&, int tx, int ty, bool topLevel = true);
90 virtual void absoluteQuads(Vector<FloatQuad>&, bool topLevel = true);
91
92 IntRect selectionBounds(bool clipToVisibleContent = true) const;
93
94 #if USE(ACCELERATED_COMPOSITING)
95 void setMaximalOutlineSize(int o);
96 #else
97 void setMaximalOutlineSize(int o) { m_maximalOutlineSize = o; }
98 #endif
99 int maximalOutlineSize() const { return m_maximalOutlineSize; }
100
101 virtual IntRect viewRect() const;
102
103 virtual void selectionStartEnd(int& startPos, int& endPos) const;
104
105 IntRect printRect() const { return m_printRect; }
106 void setPrintRect(const IntRect& r) { m_printRect = r; }
107
108 void updateWidgetPositions();
109 void addWidget(RenderObject*);
110 void removeWidget(RenderObject*);
111
112 // layoutDelta is used transiently during layout to store how far an object has moved from its
113 // last layout location, in order to repaint correctly.
114 // If we're doing a full repaint m_layoutState will be 0, but in that case layoutDelta doesn't matter.
115 IntSize layoutDelta() const
116 {
117 return m_layoutState ? m_layoutState->m_layoutDelta : IntSize();
118 }
119 void addLayoutDelta(const IntSize& delta)
120 {
121 if (m_layoutState)
122 m_layoutState->m_layoutDelta += delta;
123 }
124
125 bool doingFullRepaint() const { return m_frameView->needsFullRepaint(); }
126
127 void pushLayoutState(RenderBox* renderer, const IntSize& offset)
128 {
129 if (doingFullRepaint())
130 return;
131 // We push LayoutState even if layoutState is disabled because it stores layoutDelta too.
132 m_layoutState = new (renderArena()) LayoutState(m_layoutState, renderer, offset);
133 }
134
135 void pushLayoutState(RenderObject*);
136
137 void popLayoutState()
138 {
139 if (doingFullRepaint())
140 return;
141 LayoutState* state = m_layoutState;
142 m_layoutState = state->m_next;
143 state->destroy(renderArena());
144 }
145
146 // Returns true if layoutState should be used for its cached offset and clip.
147 bool layoutStateEnabled() const { return m_layoutStateDisableCount == 0 && m_layoutState; }
148 LayoutState* layoutState() const { return m_layoutState; }
149
150 // Suspends the LayoutState optimization. Used under transforms that cannot be represented by
151 // LayoutState (common in SVG) and when manipulating the render tree during layout in ways
152 // that can trigger repaint of a non-child (e.g. when a list item moves its list marker around).
153 // Note that even when disabled, LayoutState is still used to store layoutDelta.
154 void disableLayoutState() { m_layoutStateDisableCount++; }
155 void enableLayoutState() { ASSERT(m_layoutStateDisableCount > 0); m_layoutStateDisableCount--; }
156
157 virtual void updateHitTestResult(HitTestResult&, const IntPoint&);
158
159 // Notifications that this view became visible in a window, or will be
160 // removed from the window.
161 void didMoveOnscreen();
162 void willMoveOffscreen();
163
164 #if USE(ACCELERATED_COMPOSITING)
165 RenderLayerCompositor* compositor();
166 bool usesCompositing() const;
167 #endif
168
169 protected:
170 virtual void mapLocalToContainer(RenderBox* repaintContainer, bool useTransforms, bool fixed, TransformState&) const;
171 virtual void mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState&) const;
172
173 private:
174 bool shouldRepaint(const IntRect& r) const;
175
176 protected:
177 FrameView* m_frameView;
178
179 RenderObject* m_selectionStart;
180 RenderObject* m_selectionEnd;
181 int m_selectionStartPos;
182 int m_selectionEndPos;
183
184 // used to ignore viewport width when printing to the printer
185 bool m_printImages;
186 int m_truncatedAt;
187
188 int m_maximalOutlineSize; // Used to apply a fudge factor to dirty-rect checks on blocks/tables.
189 IntRect m_printRect; // Used when printing.
190
191 typedef HashSet<RenderObject*> RenderObjectSet;
192
193 RenderObjectSet m_widgets;
194
195 private:
196 int m_bestTruncatedAt;
197 int m_truncatorWidth;
198 bool m_forcedPageBreak;
199 LayoutState* m_layoutState;
200 unsigned m_layoutStateDisableCount;
201 #if USE(ACCELERATED_COMPOSITING)
202 OwnPtr<RenderLayerCompositor> m_compositor;
203 #endif
204 };
205
206 // Stack-based class to assist with LayoutState push/pop
207 class LayoutStateMaintainer : Noncopyable {
208 public:
209 // ctor to push now
210 LayoutStateMaintainer(RenderView* view, RenderBox* root, IntSize offset, bool disableState = false)
211 : m_view(view)
212 , m_disabled(disableState)
213 , m_didStart(false)
214 , m_didEnd(false)
215 {
216 push(root, offset);
217 }
218
219 // ctor to maybe push later
220 LayoutStateMaintainer(RenderView* view)
221 : m_view(view)
222 , m_disabled(false)
223 , m_didStart(false)
224 , m_didEnd(false)
225 {
226 }
227
228 ~LayoutStateMaintainer()
229 {
230 ASSERT(m_didStart == m_didEnd); // if this fires, it means that someone did a push(), but forgot to pop().
231 }
232
233 void push(RenderBox* root, IntSize offset)
234 {
235 ASSERT(!m_didStart);
236 // We push state even if disabled, because we still need to store layoutDelta
237 m_view->pushLayoutState(root, offset);
238 if (m_disabled)
239 m_view->disableLayoutState();
240 m_didStart = true;
241 }
242
243 void pop()
244 {
245 if (m_didStart) {
246 ASSERT(!m_didEnd);
247 m_view->popLayoutState();
248 if (m_disabled)
249 m_view->enableLayoutState();
250 m_didEnd = true;
251 }
252 }
253
254 bool didPush() const { return m_didStart; }
255
256 private:
257 RenderView* m_view;
258 bool m_disabled : 1; // true if the offset and clip part of layoutState is disabled
259 bool m_didStart : 1; // true if we did a push or disable
260 bool m_didEnd : 1; // true if we popped or re-enabled
261 };
262
263 } // namespace WebCore
264
265 #endif // RenderView_h