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