1 /*
2 Copyright (C) 1997 Martin Jones (mjones@kde.org)
3 (C) 1998 Waldo Bastian (bastian@kde.org)
4 (C) 1998, 1999 Torben Weis (weis@kde.org)
5 (C) 1999 Lars Knoll (knoll@kde.org)
6 (C) 1999 Antti Koivisto (koivisto@kde.org)
7 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public
11 License as published by the Free Software Foundation; either
12 version 2 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with this library; see the file COPYING.LIB. If not, write to
21 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA.
23 */
24
25 #ifndef FrameView_h
26 #define FrameView_h
27
28 #include "Frame.h"
29 #include "IntSize.h"
30 #include "Page.h"
31 #include "RenderLayer.h"
32 #include "ScrollView.h"
33 #include <wtf/Forward.h>
34 #include <wtf/OwnPtr.h>
35
36 namespace WebCore {
37
38 class Color;
39 class Event;
40 class Frame;
41 class FrameViewPrivate;
42 class InspectorTimelineAgent;
43 class IntRect;
44 class Node;
45 class PlatformMouseEvent;
46 class RenderLayer;
47 class RenderObject;
48 class RenderEmbeddedObject;
49 class ScheduledEvent;
50 class String;
51
52 template <typename T> class Timer;
53
54 class FrameView : public ScrollView {
55 public:
56 friend class RenderView;
57
58 static PassRefPtr<FrameView> create(Frame*);
59 static PassRefPtr<FrameView> create(Frame*, const IntSize& initialSize);
60
61 virtual ~FrameView();
62
63 virtual HostWindow* hostWindow() const;
64
65 virtual void invalidateRect(const IntRect&);
66
frame()67 Frame* frame() const { return m_frame.get(); }
68 void clearFrame();
69
marginWidth()70 int marginWidth() const { return m_margins.width(); } // -1 means default
marginHeight()71 int marginHeight() const { return m_margins.height(); } // -1 means default
72 void setMarginWidth(int);
73 void setMarginHeight(int);
74
75 virtual void setCanHaveScrollbars(bool);
76 void updateCanHaveScrollbars();
77
78 virtual PassRefPtr<Scrollbar> createScrollbar(ScrollbarOrientation);
79
80 virtual void setContentsSize(const IntSize&);
81
82 void layout(bool allowSubtree = true);
83 bool didFirstLayout() const;
84 void layoutTimerFired(Timer<FrameView>*);
85 void scheduleRelayout();
86 void scheduleRelayoutOfSubtree(RenderObject*);
87 void unscheduleRelayout();
88 bool layoutPending() const;
89
90 RenderObject* layoutRoot(bool onlyDuringLayout = false) const;
layoutCount()91 int layoutCount() const { return m_layoutCount; }
92
93 bool needsLayout() const;
94 void setNeedsLayout();
95
needsFullRepaint()96 bool needsFullRepaint() const { return m_doFullRepaint; }
97
98 #if USE(ACCELERATED_COMPOSITING)
99 void updateCompositingLayers();
100
101 // Called when changes to the GraphicsLayer hierarchy have to be synchronized with
102 // content rendered via the normal painting path.
103 void setNeedsOneShotDrawingSynchronization();
104 #endif
105 // Only used with accelerated compositing, but outside the #ifdef to make linkage easier.
106 // Returns true if the sync was completed.
107 bool syncCompositingStateRecursive();
108
109 void didMoveOnscreen();
110 void willMoveOffscreen();
111
112 void resetScrollbars();
113 void detachCustomScrollbars();
114
115 void clear();
116
117 bool isTransparent() const;
118 void setTransparent(bool isTransparent);
119
120 Color baseBackgroundColor() const;
121 void setBaseBackgroundColor(Color);
122 void updateBackgroundRecursively(const Color&, bool);
123
124 bool shouldUpdateWhileOffscreen() const;
125 void setShouldUpdateWhileOffscreen(bool);
126
127 void adjustViewSize();
128
129 virtual IntRect windowClipRect(bool clipToContents = true) const;
130 IntRect windowClipRectForLayer(const RenderLayer*, bool clipToLayerContents) const;
131
132 virtual IntRect windowResizerRect() const;
133
134 virtual void scrollRectIntoViewRecursively(const IntRect&);
135 virtual void setScrollPosition(const IntPoint&);
136 void scrollPositionChanged();
137
138 String mediaType() const;
139 void setMediaType(const String&);
140
141 void setUseSlowRepaints();
142 void setIsOverlapped(bool);
143 void setContentIsOpaque(bool);
144
145 void addSlowRepaintObject();
146 void removeSlowRepaintObject();
147
148 void beginDeferredRepaints();
149 void endDeferredRepaints();
150 void checkStopDelayingDeferredRepaints();
151 void resetDeferredRepaintDelay();
152
153 #if ENABLE(DASHBOARD_SUPPORT)
154 void updateDashboardRegions();
155 #endif
156 void updateControlTints();
157
158 void restoreScrollbar();
159
160 void scheduleEvent(PassRefPtr<Event>, PassRefPtr<Node>);
161 void pauseScheduledEvents();
162 void resumeScheduledEvents();
163 void postLayoutTimerFired(Timer<FrameView>*);
164
165 bool wasScrolledByUser() const;
166 void setWasScrolledByUser(bool);
167
168 void addWidgetToUpdate(RenderEmbeddedObject*);
169 void removeWidgetToUpdate(RenderEmbeddedObject*);
170
171 virtual void paintContents(GraphicsContext*, const IntRect& damageRect);
172 void setPaintBehavior(PaintBehavior);
paintBehavior()173 PaintBehavior paintBehavior() const { return m_paintBehavior; }
174 bool isPainting() const;
175 void setNodeToDraw(Node*);
176
currentPaintTimeStamp()177 static double currentPaintTimeStamp() { return sCurrentPaintTimeStamp; } // returns 0 if not painting
178
179 void layoutIfNeededRecursive();
180 void flushDeferredRepaints();
181
setIsVisuallyNonEmpty()182 void setIsVisuallyNonEmpty() { m_isVisuallyNonEmpty = true; }
183
184 void forceLayout(bool allowSubtree = false);
185 void forceLayoutWithPageWidthRange(float minPageWidth, float maxPageWidth, bool adjustViewSize);
186
187 void adjustPageHeight(float* newBottom, float oldTop, float oldBottom, float bottomLimit);
188
189 bool scrollToFragment(const KURL&);
190 bool scrollToAnchor(const String&);
191 void maintainScrollPositionAtAnchor(Node*);
192
193 // Methods to convert points and rects between the coordinate space of the renderer, and this view.
194 virtual IntRect convertFromRenderer(const RenderObject*, const IntRect&) const;
195 virtual IntRect convertToRenderer(const RenderObject*, const IntRect&) const;
196 virtual IntPoint convertFromRenderer(const RenderObject*, const IntPoint&) const;
197 virtual IntPoint convertToRenderer(const RenderObject*, const IntPoint&) const;
198
isFrameViewScrollCorner(RenderScrollbarPart * scrollCorner)199 bool isFrameViewScrollCorner(RenderScrollbarPart* scrollCorner) const { return m_scrollCorner == scrollCorner; }
200 void invalidateScrollCorner();
201
202 private:
203 FrameView(Frame*);
204
205 void reset();
206 void init();
207
208 virtual bool isFrameView() const;
209
210 friend class RenderWidget;
211 bool useSlowRepaints() const;
212 bool useSlowRepaintsIfNotOverlapped() const;
213
214 void applyOverflowToViewport(RenderObject*, ScrollbarMode& hMode, ScrollbarMode& vMode);
215
216 void updateOverflowStatus(bool horizontalOverflow, bool verticalOverflow);
217
218 void dispatchScheduledEvents();
219 void performPostLayoutTasks();
220
221 virtual void repaintContentRectangle(const IntRect&, bool immediate);
contentsResized()222 virtual void contentsResized() { setNeedsLayout(); }
223 virtual void visibleContentsResized();
224
225 // Override ScrollView methods to do point conversion via renderers, in order to
226 // take transforms into account.
227 virtual IntRect convertToContainingView(const IntRect&) const;
228 virtual IntRect convertFromContainingView(const IntRect&) const;
229 virtual IntPoint convertToContainingView(const IntPoint&) const;
230 virtual IntPoint convertFromContainingView(const IntPoint&) const;
231
232 // ScrollBarClient interface
233 virtual void valueChanged(Scrollbar*);
234 virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&);
235 virtual bool isActive() const;
236 virtual void getTickmarks(Vector<IntRect>&) const;
237
238 void deferredRepaintTimerFired(Timer<FrameView>*);
239 void doDeferredRepaints();
240 void updateDeferredRepaintDelay();
241 double adjustedDeferredRepaintDelay() const;
242
243 bool updateWidgets();
244 void scrollToAnchor();
245
246 #if ENABLE(INSPECTOR)
247 InspectorTimelineAgent* inspectorTimelineAgent() const;
248 #endif
249
250 bool hasCustomScrollbars() const;
251
252 virtual void updateScrollCorner();
253 virtual void paintScrollCorner(GraphicsContext*, const IntRect& cornerRect);
254
255 static double sCurrentPaintTimeStamp; // used for detecting decoded resource thrash in the cache
256
257 IntSize m_size;
258 IntSize m_margins;
259
260 typedef HashSet<RenderEmbeddedObject*> RenderEmbeddedObjectSet;
261 OwnPtr<RenderEmbeddedObjectSet> m_widgetUpdateSet;
262 RefPtr<Frame> m_frame;
263
264 bool m_doFullRepaint;
265
266 bool m_canHaveScrollbars;
267 bool m_useSlowRepaints;
268 bool m_isOverlapped;
269 bool m_contentIsOpaque;
270 unsigned m_slowRepaintObjectCount;
271
272 int m_borderX, m_borderY;
273
274 Timer<FrameView> m_layoutTimer;
275 bool m_delayedLayout;
276 RenderObject* m_layoutRoot;
277
278 bool m_layoutSchedulingEnabled;
279 bool m_midLayout;
280 int m_layoutCount;
281 unsigned m_nestedLayoutCount;
282 Timer<FrameView> m_postLayoutTasksTimer;
283 bool m_firstLayoutCallbackPending;
284
285 bool m_firstLayout;
286 bool m_isTransparent;
287 Color m_baseBackgroundColor;
288 IntSize m_lastLayoutSize;
289 float m_lastZoomFactor;
290
291 String m_mediaType;
292
293 unsigned m_enqueueEvents;
294 Vector<ScheduledEvent*> m_scheduledEvents;
295
296 bool m_overflowStatusDirty;
297 bool m_horizontalOverflow;
298 bool m_verticalOverflow;
299 RenderObject* m_viewportRenderer;
300
301 bool m_wasScrolledByUser;
302 bool m_inProgrammaticScroll;
303
304 unsigned m_deferringRepaints;
305 unsigned m_repaintCount;
306 Vector<IntRect> m_repaintRects;
307 Timer<FrameView> m_deferredRepaintTimer;
308 double m_deferredRepaintDelay;
309 double m_lastPaintTime;
310
311 bool m_shouldUpdateWhileOffscreen;
312
313 unsigned m_deferSetNeedsLayouts;
314 bool m_setNeedsLayoutWasDeferred;
315
316 RefPtr<Node> m_nodeToDraw;
317 PaintBehavior m_paintBehavior;
318 bool m_isPainting;
319
320 bool m_isVisuallyNonEmpty;
321 bool m_firstVisuallyNonEmptyLayoutCallbackPending;
322
323 RefPtr<Node> m_maintainScrollPositionAnchor;
324
325 // Renderer to hold our custom scroll corner.
326 RenderScrollbarPart* m_scrollCorner;
327 };
328
329 #if ENABLE(INSPECTOR)
inspectorTimelineAgent()330 inline InspectorTimelineAgent* FrameView::inspectorTimelineAgent() const
331 {
332 return m_frame->page() ? m_frame->page()->inspectorTimelineAgent() : 0;
333 }
334 #endif
335
336 } // namespace WebCore
337
338 #endif // FrameView_h
339