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