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.
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.
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.
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.
31 #include "RenderObject.h" // For PaintBehavior
32 #include "ScrollView.h"
33 #include <wtf/Forward.h>
34 #include <wtf/OwnPtr.h>
40 class FrameViewPrivate;
43 class PlatformMouseEvent;
46 class RenderEmbeddedObject;
47 class RenderScrollbarPart;
48 struct ScheduledEvent;
50 template <typename T> class Timer;
52 class FrameView : public ScrollView {
54 friend class RenderView;
56 static PassRefPtr<FrameView> create(Frame*);
57 static PassRefPtr<FrameView> create(Frame*, const IntSize& initialSize);
61 virtual HostWindow* hostWindow() const;
63 virtual void invalidateRect(const IntRect&);
64 virtual void setFrameRect(const IntRect&);
66 Frame* frame() const { return m_frame.get(); }
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);
74 virtual void setCanHaveScrollbars(bool);
75 void updateCanHaveScrollbars();
77 virtual PassRefPtr<Scrollbar> createScrollbar(ScrollbarOrientation);
79 virtual bool delegatesScrolling();
80 virtual bool avoidScrollbarCreation();
82 virtual void setContentsSize(const IntSize&);
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; }
93 RenderObject* layoutRoot(bool onlyDuringLayout = false) const;
94 int layoutCount() const { return m_layoutCount; }
96 bool needsLayout() const;
97 void setNeedsLayout();
99 bool needsFullRepaint() const { return m_doFullRepaint; }
101 #if USE(ACCELERATED_COMPOSITING)
102 void updateCompositingLayers();
104 // Called when changes to the GraphicsLayer hierarchy have to be synchronized with
105 // content rendered via the normal painting path.
106 void setNeedsOneShotDrawingSynchronization();
109 bool hasCompositedContent() const;
110 bool hasCompositedContentIncludingDescendants() const;
111 bool hasCompositingAncestor() const;
112 void enterCompositingMode();
113 bool isEnclosedInCompositingLayer() const;
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();
119 // Returns true when a paint with the PaintBehaviorFlattenCompositingLayers flag set gives
120 // a faithful representation of the content.
121 bool isSoftwareRenderable() const;
123 void didMoveOnscreen();
124 void willMoveOffscreen();
126 void resetScrollbars();
127 void detachCustomScrollbars();
131 bool isTransparent() const;
132 void setTransparent(bool isTransparent);
134 Color baseBackgroundColor() const;
135 void setBaseBackgroundColor(Color);
136 void updateBackgroundRecursively(const Color&, bool);
138 bool shouldUpdateWhileOffscreen() const;
139 void setShouldUpdateWhileOffscreen(bool);
141 void adjustViewSize();
143 virtual IntRect windowClipRect(bool clipToContents = true) const;
144 IntRect windowClipRectForLayer(const RenderLayer*, bool clipToLayerContents) const;
146 virtual IntRect windowResizerRect() const;
148 void setScrollPosition(const IntPoint&);
149 void scrollPositionChangedViaPlatformWidget();
150 virtual void repaintFixedElementsAfterScrolling();
152 String mediaType() const;
153 void setMediaType(const String&);
154 void adjustMediaTypeForPrinting(bool printing);
156 void setUseSlowRepaints();
157 void setIsOverlapped(bool);
158 bool isOverlapped() const { return m_isOverlapped; }
159 bool isOverlappedIncludingAncestors() const;
160 void setContentIsOpaque(bool);
162 void addSlowRepaintObject();
163 void removeSlowRepaintObject();
165 void addFixedObject();
166 void removeFixedObject();
168 void beginDeferredRepaints();
169 void endDeferredRepaints();
170 void checkStopDelayingDeferredRepaints();
171 void resetDeferredRepaintDelay();
173 #if ENABLE(DASHBOARD_SUPPORT)
174 void updateDashboardRegions();
176 void updateControlTints();
178 void restoreScrollbar();
180 void scheduleEvent(PassRefPtr<Event>, PassRefPtr<Node>);
181 void pauseScheduledEvents();
182 void resumeScheduledEvents();
183 void postLayoutTimerFired(Timer<FrameView>*);
185 bool wasScrolledByUser() const;
186 void setWasScrolledByUser(bool);
188 void addWidgetToUpdate(RenderEmbeddedObject*);
189 void removeWidgetToUpdate(RenderEmbeddedObject*);
191 virtual void paintContents(GraphicsContext*, const IntRect& damageRect);
192 void setPaintBehavior(PaintBehavior);
193 PaintBehavior paintBehavior() const;
194 bool isPainting() const;
195 void setNodeToDraw(Node*);
197 static double currentPaintTimeStamp() { return sCurrentPaintTimeStamp; } // returns 0 if not painting
199 void updateLayoutAndStyleIfNeededRecursive();
200 void flushDeferredRepaints();
202 void setIsVisuallyNonEmpty() { m_isVisuallyNonEmpty = true; }
204 void forceLayout(bool allowSubtree = false);
205 void forceLayoutForPagination(const FloatSize& pageSize, float maximumShrinkFactor, Frame::AdjustViewSizeOrNot);
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.
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.
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.
222 // NO OTHER PLATFORM BESIDES MAC SHOULD USE THIS METHOD.
223 void adjustPageHeightDeprecated(float* newBottom, float oldTop, float oldBottom, float bottomLimit);
225 bool scrollToFragment(const KURL&);
226 bool scrollToAnchor(const String&);
227 void maintainScrollPositionAtAnchor(Node*);
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;
235 bool isFrameViewScrollCorner(RenderScrollbarPart* scrollCorner) const { return m_scrollCorner == scrollCorner; }
236 void invalidateScrollCorner();
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);
248 virtual bool scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect);
249 virtual void scrollContentsSlowPath(const IntRect& updateRect);
257 virtual bool isFrameView() const;
259 friend class RenderWidget;
260 bool useSlowRepaints() const;
261 bool useSlowRepaintsIfNotOverlapped() const;
262 void updateCanBlitOnScrollRecursively();
264 bool hasFixedObjects() const { return m_fixedObjectCount > 0; }
266 void applyOverflowToViewport(RenderObject*, ScrollbarMode& hMode, ScrollbarMode& vMode);
267 void calculateScrollbarModesForLayout(ScrollbarMode& hMode, ScrollbarMode& vMode);
269 void updateOverflowStatus(bool horizontalOverflow, bool verticalOverflow);
271 void dispatchScheduledEvents();
272 void performPostLayoutTasks();
274 virtual void repaintContentRectangle(const IntRect&, bool immediate);
275 virtual void contentsResized() { setNeedsLayout(); }
276 virtual void visibleContentsResized();
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;
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;
292 void deferredRepaintTimerFired(Timer<FrameView>*);
293 void doDeferredRepaints();
294 void updateDeferredRepaintDelay();
295 double adjustedDeferredRepaintDelay() const;
297 bool updateWidgets();
298 void updateWidget(RenderEmbeddedObject*);
299 void scrollToAnchor();
300 void scrollPositionChanged();
302 bool hasCustomScrollbars() const;
304 virtual void updateScrollCorner();
305 virtual void paintScrollCorner(GraphicsContext*, const IntRect& cornerRect);
307 static double sCurrentPaintTimeStamp; // used for detecting decoded resource thrash in the cache
312 typedef HashSet<RenderEmbeddedObject*> RenderEmbeddedObjectSet;
313 OwnPtr<RenderEmbeddedObjectSet> m_widgetUpdateSet;
314 RefPtr<Frame> m_frame;
316 bool m_doFullRepaint;
318 bool m_canHaveScrollbars;
319 bool m_useSlowRepaints;
321 bool m_contentIsOpaque;
322 unsigned m_slowRepaintObjectCount;
323 unsigned m_fixedObjectCount;
328 Timer<FrameView> m_layoutTimer;
329 bool m_delayedLayout;
330 RenderObject* m_layoutRoot;
332 bool m_layoutSchedulingEnabled;
334 bool m_hasPendingPostLayoutTasks;
335 bool m_inSynchronousPostLayout;
337 unsigned m_nestedLayoutCount;
338 Timer<FrameView> m_postLayoutTasksTimer;
339 bool m_firstLayoutCallbackPending;
342 bool m_isTransparent;
343 Color m_baseBackgroundColor;
344 IntSize m_lastLayoutSize;
345 float m_lastZoomFactor;
348 String m_mediaTypeWhenNotPrinting;
350 unsigned m_enqueueEvents;
351 Vector<ScheduledEvent*> m_scheduledEvents;
353 bool m_overflowStatusDirty;
354 bool m_horizontalOverflow;
355 bool m_verticalOverflow;
356 RenderObject* m_viewportRenderer;
358 bool m_wasScrolledByUser;
359 bool m_inProgrammaticScroll;
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;
368 bool m_shouldUpdateWhileOffscreen;
370 unsigned m_deferSetNeedsLayouts;
371 bool m_setNeedsLayoutWasDeferred;
373 RefPtr<Node> m_nodeToDraw;
374 PaintBehavior m_paintBehavior;
377 bool m_isVisuallyNonEmpty;
378 bool m_firstVisuallyNonEmptyLayoutCallbackPending;
380 RefPtr<Node> m_maintainScrollPositionAnchor;
382 // Renderer to hold our custom scroll corner.
383 RenderScrollbarPart* m_scrollCorner;
385 static double s_deferredRepaintDelay;
386 static double s_initialDeferredRepaintDelayDuringLoading;
387 static double s_maxDeferredRepaintDelayDuringLoading;
388 static double s_deferredRepaintDelayIncrementDuringLoading;
391 } // namespace WebCore
393 #endif // FrameView_h