• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "IntSize.h"
29 #include "RenderLayer.h"
30 #include "ScrollView.h"
31 #include <wtf/Forward.h>
32 #include <wtf/OwnPtr.h>
33 
34 namespace WebCore {
35 
36 class Color;
37 class Event;
38 class Frame;
39 class FrameViewPrivate;
40 class IntRect;
41 class Node;
42 class PlatformMouseEvent;
43 class RenderLayer;
44 class RenderObject;
45 class RenderPartObject;
46 class ScheduledEvent;
47 class String;
48 
49 template <typename T> class Timer;
50 
51 class FrameView : public ScrollView {
52 public:
53     friend class RenderView;
54 
55     static PassRefPtr<FrameView> create(Frame*);
56     static PassRefPtr<FrameView> create(Frame*, const IntSize& initialSize);
57 
58     virtual ~FrameView();
59 
60     virtual HostWindow* hostWindow() const;
61 
62     virtual void invalidateRect(const IntRect&);
63 
frame()64     Frame* frame() const { return m_frame.get(); }
65     void clearFrame();
66 
marginWidth()67     int marginWidth() const { return m_margins.width(); } // -1 means default
marginHeight()68     int marginHeight() const { return m_margins.height(); } // -1 means default
69     void setMarginWidth(int);
70     void setMarginHeight(int);
71 
72     virtual void setCanHaveScrollbars(bool);
73 
74     virtual PassRefPtr<Scrollbar> createScrollbar(ScrollbarOrientation);
75 
76     virtual void setContentsSize(const IntSize&);
77 
78     void layout(bool allowSubtree = true);
79     bool didFirstLayout() const;
80     void layoutTimerFired(Timer<FrameView>*);
81     void scheduleRelayout();
82     void scheduleRelayoutOfSubtree(RenderObject*);
83     void unscheduleRelayout();
84     bool layoutPending() const;
85 
86     RenderObject* layoutRoot(bool onlyDuringLayout = false) const;
layoutCount()87     int layoutCount() const { return m_layoutCount; }
88 
89     // These two helper functions just pass through to the RenderView.
90     bool needsLayout() const;
91     void setNeedsLayout();
92 
needsFullRepaint()93     bool needsFullRepaint() const { return m_doFullRepaint; }
94 
95 #if USE(ACCELERATED_COMPOSITING)
96     void updateCompositingLayers();
97 
98     // Called when changes to the GraphicsLayer hierarchy have to be synchronized with
99     // content rendered via the normal painting path.
100     void setNeedsOneShotDrawingSynchronization();
101 #endif
102     // Only used with accelerated compositing, but outside the #ifdef to make linkage easier.
103     // Returns true if the sync was completed.
104     bool syncCompositingStateRecursive();
105 
106     void didMoveOnscreen();
107     void willMoveOffscreen();
108 
109     void resetScrollbars();
110     void detachCustomScrollbars();
111 
112     void clear();
113 
114     bool isTransparent() const;
115     void setTransparent(bool isTransparent);
116 
117     Color baseBackgroundColor() const;
118     void setBaseBackgroundColor(Color);
119     void updateBackgroundRecursively(const Color&, bool);
120 
121     bool shouldUpdateWhileOffscreen() const;
122     void setShouldUpdateWhileOffscreen(bool);
123 
124     void adjustViewSize();
125     void initScrollbars();
126     void updateDefaultScrollbarState();
127 
128     virtual IntRect windowClipRect(bool clipToContents = true) const;
129     IntRect windowClipRectForLayer(const RenderLayer*, bool clipToLayerContents) const;
130 
131     virtual IntRect windowResizerRect() const;
132 
133     virtual void scrollRectIntoViewRecursively(const IntRect&);
134     virtual void setScrollPosition(const IntPoint&);
135 
136     String mediaType() const;
137     void setMediaType(const String&);
138 
139     void setUseSlowRepaints();
140     void setIsOverlapped(bool);
141     void setContentIsOpaque(bool);
142 
143     void addSlowRepaintObject();
144     void removeSlowRepaintObject();
145 
146     void beginDeferredRepaints();
147     void endDeferredRepaints();
148     void checkStopDelayingDeferredRepaints();
149     void resetDeferredRepaintDelay();
150 
151 #if ENABLE(DASHBOARD_SUPPORT)
152     void updateDashboardRegions();
153 #endif
154     void updateControlTints();
155 
156     void restoreScrollbar();
157 
158     void scheduleEvent(PassRefPtr<Event>, PassRefPtr<Node>);
159     void pauseScheduledEvents();
160     void resumeScheduledEvents();
161     void postLayoutTimerFired(Timer<FrameView>*);
162 
163     bool wasScrolledByUser() const;
164     void setWasScrolledByUser(bool);
165 
166     void addWidgetToUpdate(RenderPartObject*);
167     void removeWidgetToUpdate(RenderPartObject*);
168 
169     virtual void paintContents(GraphicsContext*, const IntRect& damageRect);
170     void setPaintRestriction(PaintRestriction);
171     bool isPainting() const;
172     void setNodeToDraw(Node*);
173 
currentPaintTimeStamp()174     static double currentPaintTimeStamp() { return sCurrentPaintTimeStamp; } // returns 0 if not painting
175 
176     void layoutIfNeededRecursive();
177 
setIsVisuallyNonEmpty()178     void setIsVisuallyNonEmpty() { m_isVisuallyNonEmpty = true; }
179 
180     void forceLayout(bool allowSubtree = false);
181     void forceLayoutWithPageWidthRange(float minPageWidth, float maxPageWidth, bool adjustViewSize);
182 
183     void adjustPageHeight(float* newBottom, float oldTop, float oldBottom, float bottomLimit);
184 
185     void maintainScrollPositionAtAnchor(Node*);
186 
187     // Methods to convert points and rects between the coordinate space of the renderer, and this view.
188     virtual IntRect convertFromRenderer(const RenderObject*, const IntRect&) const;
189     virtual IntRect convertToRenderer(const RenderObject*, const IntRect&) const;
190     virtual IntPoint convertFromRenderer(const RenderObject*, const IntPoint&) const;
191     virtual IntPoint convertToRenderer(const RenderObject*, const IntPoint&) const;
192 
193 private:
194     FrameView(Frame*);
195 
196     void reset();
197     void init();
198 
199     virtual bool isFrameView() const;
200 
201     friend class RenderWidget;
202     bool useSlowRepaints() const;
203 
204     void applyOverflowToViewport(RenderObject*, ScrollbarMode& hMode, ScrollbarMode& vMode);
205 
206     void updateOverflowStatus(bool horizontalOverflow, bool verticalOverflow);
207 
208     void dispatchScheduledEvents();
209     void performPostLayoutTasks();
210 
211     virtual void repaintContentRectangle(const IntRect&, bool immediate);
contentsResized()212     virtual void contentsResized() { setNeedsLayout(); }
213     virtual void visibleContentsResized();
214 
215     // Override ScrollView methods to do point conversion via renderers, in order to
216     // take transforms into account.
217     virtual IntRect convertToContainingView(const IntRect&) const;
218     virtual IntRect convertFromContainingView(const IntRect&) const;
219     virtual IntPoint convertToContainingView(const IntPoint&) const;
220     virtual IntPoint convertFromContainingView(const IntPoint&) const;
221 
222     // ScrollBarClient interface
223     virtual void valueChanged(Scrollbar*);
224     virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&);
225     virtual bool isActive() const;
226     virtual void getTickmarks(Vector<IntRect>&) const;
227 
228     void deferredRepaintTimerFired(Timer<FrameView>*);
229     void doDeferredRepaints();
230     void updateDeferredRepaintDelay();
231     double adjustedDeferredRepaintDelay() const;
232 
233     bool updateWidgets();
234     void scrollToAnchor();
235 
236     static double sCurrentPaintTimeStamp; // used for detecting decoded resource thrash in the cache
237 
238     IntSize m_size;
239     IntSize m_margins;
240     OwnPtr<HashSet<RenderPartObject*> > m_widgetUpdateSet;
241     RefPtr<Frame> m_frame;
242 
243     bool m_doFullRepaint;
244 
245     ScrollbarMode m_vmode;
246     ScrollbarMode m_hmode;
247     bool m_useSlowRepaints;
248     bool m_isOverlapped;
249     bool m_contentIsOpaque;
250     unsigned m_slowRepaintObjectCount;
251 
252     int m_borderX, m_borderY;
253 
254     Timer<FrameView> m_layoutTimer;
255     bool m_delayedLayout;
256     RenderObject* m_layoutRoot;
257 
258     bool m_layoutSchedulingEnabled;
259     bool m_midLayout;
260     int m_layoutCount;
261     unsigned m_nestedLayoutCount;
262     Timer<FrameView> m_postLayoutTasksTimer;
263     bool m_firstLayoutCallbackPending;
264 
265     bool m_firstLayout;
266     bool m_needToInitScrollbars;
267     bool m_isTransparent;
268     Color m_baseBackgroundColor;
269     IntSize m_lastLayoutSize;
270     float m_lastZoomFactor;
271 
272     String m_mediaType;
273 
274     unsigned m_enqueueEvents;
275     Vector<ScheduledEvent*> m_scheduledEvents;
276 
277     bool m_overflowStatusDirty;
278     bool m_horizontalOverflow;
279     bool m_verticalOverflow;
280     RenderObject* m_viewportRenderer;
281 
282     bool m_wasScrolledByUser;
283     bool m_inProgrammaticScroll;
284 
285     unsigned m_deferringRepaints;
286     unsigned m_repaintCount;
287     Vector<IntRect> m_repaintRects;
288     Timer<FrameView> m_deferredRepaintTimer;
289     double m_deferredRepaintDelay;
290     double m_lastPaintTime;
291 
292     bool m_shouldUpdateWhileOffscreen;
293 
294     unsigned m_deferSetNeedsLayouts;
295     bool m_setNeedsLayoutWasDeferred;
296 
297     RefPtr<Node> m_nodeToDraw;
298     PaintRestriction m_paintRestriction;
299     bool m_isPainting;
300 
301     bool m_isVisuallyNonEmpty;
302     bool m_firstVisuallyNonEmptyLayoutCallbackPending;
303 
304     RefPtr<Node> m_maintainScrollPositionAnchor;
305 };
306 
307 } // namespace WebCore
308 
309 #endif // FrameView_h
310