OSDN Git Service

Merge WebKit at r71558: Initial merge by git.
[android-x86/external-webkit.git] / WebCore / page / FrameView.h
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 "RenderObject.h" // For PaintBehavior
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 FrameViewPrivate;
41 class IntRect;
42 class Node;
43 class PlatformMouseEvent;
44 class RenderLayer;
45 class RenderObject;
46 class RenderEmbeddedObject;
47 class RenderScrollbarPart;
48 struct ScheduledEvent;
49
50 template <typename T> class Timer;
51
52 class FrameView : public ScrollView {
53 public:
54     friend class RenderView;
55
56     static PassRefPtr<FrameView> create(Frame*);
57     static PassRefPtr<FrameView> create(Frame*, const IntSize& initialSize);
58
59     virtual ~FrameView();
60
61     virtual HostWindow* hostWindow() const;
62     
63     virtual void invalidateRect(const IntRect&);
64     virtual void setFrameRect(const IntRect&);
65
66     Frame* frame() const { return m_frame.get(); }
67     void clearFrame();
68
69     int marginWidth() const { return m_margins.width(); } // -1 means default
70     int marginHeight() const { return m_margins.height(); } // -1 means default
71     void setMarginWidth(int);
72     void setMarginHeight(int);
73
74     virtual void setCanHaveScrollbars(bool);
75     void updateCanHaveScrollbars();
76
77     virtual PassRefPtr<Scrollbar> createScrollbar(ScrollbarOrientation);
78
79     virtual bool delegatesScrolling();
80     virtual bool avoidScrollbarCreation();
81
82     virtual void setContentsSize(const IntSize&);
83
84     void layout(bool allowSubtree = true);
85     bool didFirstLayout() const;
86     void layoutTimerFired(Timer<FrameView>*);
87     void scheduleRelayout();
88     void scheduleRelayoutOfSubtree(RenderObject*);
89     void unscheduleRelayout();
90     bool layoutPending() const;
91     bool isInLayout() const { return m_inLayout; }
92
93     RenderObject* layoutRoot(bool onlyDuringLayout = false) const;
94     int layoutCount() const { return m_layoutCount; }
95
96     bool needsLayout() const;
97     void setNeedsLayout();
98
99     bool needsFullRepaint() const { return m_doFullRepaint; }
100
101 #if USE(ACCELERATED_COMPOSITING)
102     void updateCompositingLayers();
103
104     // Called when changes to the GraphicsLayer hierarchy have to be synchronized with
105     // content rendered via the normal painting path.
106     void setNeedsOneShotDrawingSynchronization();
107 #endif
108
109     bool hasCompositedContent() const;
110     bool hasCompositedContentIncludingDescendants() const;
111     bool hasCompositingAncestor() const;
112     void enterCompositingMode();
113     bool isEnclosedInCompositingLayer() const;
114
115     // Only used with accelerated compositing, but outside the #ifdef to make linkage easier.
116     // Returns true if the sync was completed.
117     bool syncCompositingStateRecursive();
118
119     // Returns true when a paint with the PaintBehaviorFlattenCompositingLayers flag set gives
120     // a faithful representation of the content.
121     bool isSoftwareRenderable() const;
122
123     void didMoveOnscreen();
124     void willMoveOffscreen();
125
126     void resetScrollbars();
127     void detachCustomScrollbars();
128
129     void clear();
130
131     bool isTransparent() const;
132     void setTransparent(bool isTransparent);
133
134     Color baseBackgroundColor() const;
135     void setBaseBackgroundColor(Color);
136     void updateBackgroundRecursively(const Color&, bool);
137
138     bool shouldUpdateWhileOffscreen() const;
139     void setShouldUpdateWhileOffscreen(bool);
140
141     void adjustViewSize();
142     
143     virtual IntRect windowClipRect(bool clipToContents = true) const;
144     IntRect windowClipRectForLayer(const RenderLayer*, bool clipToLayerContents) const;
145
146     virtual IntRect windowResizerRect() const;
147
148     void setScrollPosition(const IntPoint&);
149     void scrollPositionChangedViaPlatformWidget();
150     virtual void repaintFixedElementsAfterScrolling();
151
152     String mediaType() const;
153     void setMediaType(const String&);
154     void adjustMediaTypeForPrinting(bool printing);
155
156     void setUseSlowRepaints();
157     void setIsOverlapped(bool);
158     bool isOverlapped() const { return m_isOverlapped; }
159     bool isOverlappedIncludingAncestors() const;
160     void setContentIsOpaque(bool);
161
162     void addSlowRepaintObject();
163     void removeSlowRepaintObject();
164
165     void addFixedObject();
166     void removeFixedObject();
167
168     void beginDeferredRepaints();
169     void endDeferredRepaints();
170     void checkStopDelayingDeferredRepaints();
171     void resetDeferredRepaintDelay();
172
173 #if ENABLE(DASHBOARD_SUPPORT)
174     void updateDashboardRegions();
175 #endif
176     void updateControlTints();
177
178     void restoreScrollbar();
179
180     void scheduleEvent(PassRefPtr<Event>, PassRefPtr<Node>);
181     void pauseScheduledEvents();
182     void resumeScheduledEvents();
183     void postLayoutTimerFired(Timer<FrameView>*);
184
185     bool wasScrolledByUser() const;
186     void setWasScrolledByUser(bool);
187
188     void addWidgetToUpdate(RenderEmbeddedObject*);
189     void removeWidgetToUpdate(RenderEmbeddedObject*);
190
191     virtual void paintContents(GraphicsContext*, const IntRect& damageRect);
192     void setPaintBehavior(PaintBehavior);
193     PaintBehavior paintBehavior() const;
194     bool isPainting() const;
195     void setNodeToDraw(Node*);
196
197     static double currentPaintTimeStamp() { return sCurrentPaintTimeStamp; } // returns 0 if not painting
198     
199     void updateLayoutAndStyleIfNeededRecursive();
200     void flushDeferredRepaints();
201
202     void setIsVisuallyNonEmpty() { m_isVisuallyNonEmpty = true; }
203
204     void forceLayout(bool allowSubtree = false);
205     void forceLayoutForPagination(const FloatSize& pageSize, float maximumShrinkFactor, Frame::AdjustViewSizeOrNot);
206
207     // FIXME: This method is retained because of embedded WebViews in AppKit.  When a WebView is embedded inside
208     // some enclosing view with auto-pagination, no call happens to resize the view.  The new pagination model
209     // needs the view to resize as a result of the breaks, but that means that the enclosing view has to potentially
210     // resize around that view.  Auto-pagination uses the bounds of the actual view that's being printed to determine
211     // the edges of the print operation, so the resize is necessary if the enclosing view's bounds depend on the
212     // web document's bounds.
213     // 
214     // This is already a problem if the view needs to be a different size because of printer fonts or because of print stylesheets.
215     // Mail/Dictionary work around this problem by using the _layoutForPrinting SPI
216     // to at least get print stylesheets and printer fonts into play, but since WebKit doesn't know about the page offset or
217     // page size, it can't actually paginate correctly during _layoutForPrinting.
218     //
219     // We can eventually move Mail to a newer SPI that would let them opt in to the layout-time pagination model,
220     // but that doesn't solve the general problem of how other AppKit views could opt in to the better model.
221     //
222     // NO OTHER PLATFORM BESIDES MAC SHOULD USE THIS METHOD.
223     void adjustPageHeightDeprecated(float* newBottom, float oldTop, float oldBottom, float bottomLimit);
224
225     bool scrollToFragment(const KURL&);
226     bool scrollToAnchor(const String&);
227     void maintainScrollPositionAtAnchor(Node*);
228
229     // Methods to convert points and rects between the coordinate space of the renderer, and this view.
230     virtual IntRect convertFromRenderer(const RenderObject*, const IntRect&) const;
231     virtual IntRect convertToRenderer(const RenderObject*, const IntRect&) const;
232     virtual IntPoint convertFromRenderer(const RenderObject*, const IntPoint&) const;
233     virtual IntPoint convertToRenderer(const RenderObject*, const IntPoint&) const;
234
235     bool isFrameViewScrollCorner(RenderScrollbarPart* scrollCorner) const { return m_scrollCorner == scrollCorner; }
236     void invalidateScrollCorner();
237
238     // Normal delay
239     static void setRepaintThrottlingDeferredRepaintDelay(double p);
240     // Negative value would mean that first few repaints happen without a delay
241     static void setRepaintThrottlingnInitialDeferredRepaintDelayDuringLoading(double p);
242     // The delay grows on each repaint to this maximum value
243     static void setRepaintThrottlingMaxDeferredRepaintDelayDuringLoading(double p);
244     // On each repaint the delay increses by this amount
245     static void setRepaintThrottlingDeferredRepaintDelayIncrementDuringLoading(double p);
246
247 protected:
248     virtual bool scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect);
249     virtual void scrollContentsSlowPath(const IntRect& updateRect);
250
251 private:
252     FrameView(Frame*);
253
254     void reset();
255     void init();
256
257     virtual bool isFrameView() const;
258
259     friend class RenderWidget;
260     bool useSlowRepaints() const;
261     bool useSlowRepaintsIfNotOverlapped() const;
262     void updateCanBlitOnScrollRecursively();
263
264     bool hasFixedObjects() const { return m_fixedObjectCount > 0; }
265
266     void applyOverflowToViewport(RenderObject*, ScrollbarMode& hMode, ScrollbarMode& vMode);
267     void calculateScrollbarModesForLayout(ScrollbarMode& hMode, ScrollbarMode& vMode);
268
269     void updateOverflowStatus(bool horizontalOverflow, bool verticalOverflow);
270
271     void dispatchScheduledEvents();
272     void performPostLayoutTasks();
273
274     virtual void repaintContentRectangle(const IntRect&, bool immediate);
275     virtual void contentsResized() { setNeedsLayout(); }
276     virtual void visibleContentsResized();
277
278     // Override ScrollView methods to do point conversion via renderers, in order to
279     // take transforms into account.
280     virtual IntRect convertToContainingView(const IntRect&) const;
281     virtual IntRect convertFromContainingView(const IntRect&) const;
282     virtual IntPoint convertToContainingView(const IntPoint&) const;
283     virtual IntPoint convertFromContainingView(const IntPoint&) const;
284
285     // ScrollBarClient interface
286     virtual void valueChanged(Scrollbar*);
287     virtual void valueChanged(const IntSize&);
288     virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&);
289     virtual bool isActive() const;
290     virtual void getTickmarks(Vector<IntRect>&) const;
291
292     void deferredRepaintTimerFired(Timer<FrameView>*);
293     void doDeferredRepaints();
294     void updateDeferredRepaintDelay();
295     double adjustedDeferredRepaintDelay() const;
296
297     bool updateWidgets();
298     void updateWidget(RenderEmbeddedObject*);
299     void scrollToAnchor();
300     void scrollPositionChanged();
301
302     bool hasCustomScrollbars() const;
303
304     virtual void updateScrollCorner();
305     virtual void paintScrollCorner(GraphicsContext*, const IntRect& cornerRect);
306
307     static double sCurrentPaintTimeStamp; // used for detecting decoded resource thrash in the cache
308
309     IntSize m_size;
310     IntSize m_margins;
311     
312     typedef HashSet<RenderEmbeddedObject*> RenderEmbeddedObjectSet;
313     OwnPtr<RenderEmbeddedObjectSet> m_widgetUpdateSet;
314     RefPtr<Frame> m_frame;
315
316     bool m_doFullRepaint;
317     
318     bool m_canHaveScrollbars;
319     bool m_useSlowRepaints;
320     bool m_isOverlapped;
321     bool m_contentIsOpaque;
322     unsigned m_slowRepaintObjectCount;
323     unsigned m_fixedObjectCount;
324
325     int m_borderX;
326     int m_borderY;
327
328     Timer<FrameView> m_layoutTimer;
329     bool m_delayedLayout;
330     RenderObject* m_layoutRoot;
331     
332     bool m_layoutSchedulingEnabled;
333     bool m_inLayout;
334     bool m_hasPendingPostLayoutTasks;
335     bool m_inSynchronousPostLayout;
336     int m_layoutCount;
337     unsigned m_nestedLayoutCount;
338     Timer<FrameView> m_postLayoutTasksTimer;
339     bool m_firstLayoutCallbackPending;
340
341     bool m_firstLayout;
342     bool m_isTransparent;
343     Color m_baseBackgroundColor;
344     IntSize m_lastLayoutSize;
345     float m_lastZoomFactor;
346
347     String m_mediaType;
348     String m_mediaTypeWhenNotPrinting;
349
350     unsigned m_enqueueEvents;
351     Vector<ScheduledEvent*> m_scheduledEvents;
352     
353     bool m_overflowStatusDirty;
354     bool m_horizontalOverflow;
355     bool m_verticalOverflow;    
356     RenderObject* m_viewportRenderer;
357
358     bool m_wasScrolledByUser;
359     bool m_inProgrammaticScroll;
360     
361     unsigned m_deferringRepaints;
362     unsigned m_repaintCount;
363     Vector<IntRect> m_repaintRects;
364     Timer<FrameView> m_deferredRepaintTimer;
365     double m_deferredRepaintDelay;
366     double m_lastPaintTime;
367
368     bool m_shouldUpdateWhileOffscreen;
369
370     unsigned m_deferSetNeedsLayouts;
371     bool m_setNeedsLayoutWasDeferred;
372
373     RefPtr<Node> m_nodeToDraw;
374     PaintBehavior m_paintBehavior;
375     bool m_isPainting;
376
377     bool m_isVisuallyNonEmpty;
378     bool m_firstVisuallyNonEmptyLayoutCallbackPending;
379
380     RefPtr<Node> m_maintainScrollPositionAnchor;
381
382     // Renderer to hold our custom scroll corner.
383     RenderScrollbarPart* m_scrollCorner;
384
385     static double s_deferredRepaintDelay;
386     static double s_initialDeferredRepaintDelayDuringLoading;
387     static double s_maxDeferredRepaintDelayDuringLoading;
388     static double s_deferredRepaintDelayIncrementDuringLoading;
389 };
390
391 } // namespace WebCore
392
393 #endif // FrameView_h