author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 03 May 2010 13:17:34 +0300 | |
changeset 19 | fcece45ef507 |
parent 18 | 2f34d5167611 |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* Copyright (C) 2004, 2006, 2007, 2008 Apple Inc. All rights reserved. |
|
3 |
* Copyright (C) 2009 Holger Hans Peter Freyther |
|
4 |
* |
|
5 |
* Redistribution and use in source and binary forms, with or without |
|
6 |
* modification, are permitted provided that the following conditions |
|
7 |
* are met: |
|
8 |
* 1. Redistributions of source code must retain the above copyright |
|
9 |
* notice, this list of conditions and the following disclaimer. |
|
10 |
* 2. Redistributions in binary form must reproduce the above copyright |
|
11 |
* notice, this list of conditions and the following disclaimer in the |
|
12 |
* documentation and/or other materials provided with the distribution. |
|
13 |
* |
|
14 |
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
|
15 |
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
16 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
17 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
|
18 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
19 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
20 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
21 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
22 |
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
23 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
24 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
25 |
*/ |
|
26 |
||
27 |
#ifndef ScrollView_h |
|
28 |
#define ScrollView_h |
|
29 |
||
30 |
#include "IntRect.h" |
|
31 |
#include "Scrollbar.h" |
|
32 |
#include "ScrollbarClient.h" |
|
33 |
#include "ScrollTypes.h" |
|
34 |
#include "Widget.h" |
|
35 |
||
36 |
#include <wtf/HashSet.h> |
|
37 |
||
38 |
#if PLATFORM(MAC) && defined __OBJC__ |
|
39 |
@protocol WebCoreFrameScrollView; |
|
40 |
#endif |
|
41 |
||
42 |
#if PLATFORM(GTK) |
|
43 |
typedef struct _GtkAdjustment GtkAdjustment; |
|
44 |
#endif |
|
45 |
||
46 |
#if PLATFORM(WX) |
|
47 |
class wxScrollWinEvent; |
|
48 |
#endif |
|
49 |
||
50 |
namespace WebCore { |
|
51 |
||
52 |
class HostWindow; |
|
53 |
class PlatformWheelEvent; |
|
54 |
class Scrollbar; |
|
55 |
||
56 |
class ScrollView : public Widget, public ScrollbarClient { |
|
57 |
public: |
|
58 |
~ScrollView(); |
|
59 |
||
60 |
// ScrollbarClient method. FrameView overrides the other two. |
|
61 |
virtual void valueChanged(Scrollbar*); |
|
62 |
||
63 |
// The window thats hosts the ScrollView. The ScrollView will communicate scrolls and repaints to the |
|
64 |
// host window in the window's coordinate space. |
|
65 |
virtual HostWindow* hostWindow() const = 0; |
|
66 |
||
67 |
// Returns a clip rect in host window coordinates. Used to clip the blit on a scroll. |
|
68 |
virtual IntRect windowClipRect(bool clipToContents = true) const = 0; |
|
69 |
||
70 |
// Methods for child manipulation and inspection. |
|
71 |
const HashSet<RefPtr<Widget> >* children() const { return &m_children; } |
|
72 |
void addChild(PassRefPtr<Widget>); |
|
73 |
void removeChild(Widget*); |
|
74 |
||
75 |
// If the scroll view does not use a native widget, then it will have cross-platform Scrollbars. These methods |
|
76 |
// can be used to obtain those scrollbars. |
|
77 |
Scrollbar* horizontalScrollbar() const { return m_horizontalScrollbar.get(); } |
|
78 |
Scrollbar* verticalScrollbar() const { return m_verticalScrollbar.get(); } |
|
79 |
bool isScrollViewScrollbar(const Widget* child) const { return horizontalScrollbar() == child || verticalScrollbar() == child; } |
|
80 |
||
81 |
// Methods for setting and retrieving the scrolling mode in each axis (horizontal/vertical). The mode has values of |
|
82 |
// AlwaysOff, AlwaysOn, and Auto. AlwaysOff means never show a scrollbar, AlwaysOn means always show a scrollbar. |
|
83 |
// Auto means show a scrollbar only when one is needed. |
|
84 |
// Note that for platforms with native widgets, these modes are considered advisory. In other words the underlying native |
|
85 |
// widget may choose not to honor the requested modes. |
|
86 |
void setScrollbarModes(ScrollbarMode horizontalMode, ScrollbarMode verticalMode); |
|
87 |
void setHorizontalScrollbarMode(ScrollbarMode mode) { setScrollbarModes(mode, verticalScrollbarMode()); } |
|
88 |
void setVerticalScrollbarMode(ScrollbarMode mode) { setScrollbarModes(horizontalScrollbarMode(), mode); } |
|
89 |
void scrollbarModes(ScrollbarMode& horizontalMode, ScrollbarMode& verticalMode) const; |
|
90 |
ScrollbarMode horizontalScrollbarMode() const { ScrollbarMode horizontal, vertical; scrollbarModes(horizontal, vertical); return horizontal; } |
|
91 |
ScrollbarMode verticalScrollbarMode() const { ScrollbarMode horizontal, vertical; scrollbarModes(horizontal, vertical); return vertical; } |
|
92 |
void setCanHaveScrollbars(bool flag); |
|
93 |
bool canHaveScrollbars() const { return horizontalScrollbarMode() != ScrollbarAlwaysOff || verticalScrollbarMode() != ScrollbarAlwaysOff; } |
|
94 |
||
95 |
// Overridden by FrameView to create custom CSS scrollbars if applicable. |
|
96 |
virtual PassRefPtr<Scrollbar> createScrollbar(ScrollbarOrientation); |
|
97 |
||
98 |
// If the prohibits scrolling flag is set, then all scrolling in the view (even programmatic scrolling) is turned off. |
|
99 |
void setProhibitsScrolling(bool b) { m_prohibitsScrolling = b; } |
|
100 |
bool prohibitsScrolling() const { return m_prohibitsScrolling; } |
|
101 |
||
102 |
// Whether or not a scroll view will blit visible contents when it is scrolled. Blitting is disabled in situations |
|
103 |
// where it would cause rendering glitches (such as with fixed backgrounds or when the view is partially transparent). |
|
104 |
void setCanBlitOnScroll(bool); |
|
105 |
bool canBlitOnScroll() const; |
|
106 |
||
107 |
// The visible content rect has a location that is the scrolled offset of the document. The width and height are the viewport width |
|
108 |
// and height. By default the scrollbars themselves are excluded from this rectangle, but an optional boolean argument allows them to be |
|
109 |
// included. |
|
110 |
IntRect visibleContentRect(bool includeScrollbars = false) const; |
|
111 |
int visibleWidth() const { return visibleContentRect().width(); } |
|
112 |
int visibleHeight() const { return visibleContentRect().height(); } |
|
113 |
||
114 |
// Methods for getting/setting the size webkit should use to layout the contents. By default this is the same as the visible |
|
115 |
// content size. Explicitly setting a layout size value will cause webkit to layout the contents using this size instead. |
|
116 |
int layoutWidth() const; |
|
117 |
int layoutHeight() const; |
|
118 |
IntSize fixedLayoutSize() const; |
|
119 |
void setFixedLayoutSize(const IntSize&); |
|
120 |
bool useFixedLayout() const; |
|
121 |
void setUseFixedLayout(bool enable); |
|
122 |
||
123 |
// Methods for getting/setting the size of the document contained inside the ScrollView (as an IntSize or as individual width and height |
|
124 |
// values). |
|
125 |
IntSize contentsSize() const; // Always at least as big as the visibleWidth()/visibleHeight(). |
|
126 |
int contentsWidth() const { return contentsSize().width(); } |
|
127 |
int contentsHeight() const { return contentsSize().height(); } |
|
128 |
virtual void setContentsSize(const IntSize&); |
|
129 |
||
130 |
// Methods for querying the current scrolled position (both as a point, a size, or as individual X and Y values). |
|
131 |
IntPoint scrollPosition() const { return visibleContentRect().location(); } |
|
132 |
IntSize scrollOffset() const { return visibleContentRect().location() - IntPoint(); } // Gets the scrolled position as an IntSize. Convenient for adding to other sizes. |
|
133 |
IntPoint maximumScrollPosition() const; // The maximum position we can be scrolled to. |
|
134 |
int scrollX() const { return scrollPosition().x(); } |
|
135 |
int scrollY() const { return scrollPosition().y(); } |
|
136 |
||
137 |
// Methods for scrolling the view. setScrollPosition is the only method that really scrolls the view. The other two methods are helper functions |
|
138 |
// that ultimately end up calling setScrollPosition. |
|
139 |
void setScrollPosition(const IntPoint&); |
|
140 |
void scrollBy(const IntSize& s) { return setScrollPosition(scrollPosition() + s); } |
|
141 |
void scrollRectIntoViewRecursively(const IntRect&); |
|
142 |
||
143 |
// This method scrolls by lines, pages or pixels. |
|
144 |
bool scroll(ScrollDirection, ScrollGranularity); |
|
145 |
||
146 |
// Scroll the actual contents of the view (either blitting or invalidating as needed). |
|
147 |
void scrollContents(const IntSize& scrollDelta); |
|
148 |
||
149 |
// This gives us a means of blocking painting on our scrollbars until the first layout has occurred. |
|
150 |
void setScrollbarsSuppressed(bool suppressed, bool repaintOnUnsuppress = false); |
|
151 |
bool scrollbarsSuppressed() const { return m_scrollbarsSuppressed; } |
|
152 |
||
153 |
// Event coordinates are assumed to be in the coordinate space of a window that contains |
|
154 |
// the entire widget hierarchy. It is up to the platform to decide what the precise definition |
|
155 |
// of containing window is. (For example on Mac it is the containing NSWindow.) |
|
156 |
IntPoint windowToContents(const IntPoint&) const; |
|
157 |
IntPoint contentsToWindow(const IntPoint&) const; |
|
158 |
IntRect windowToContents(const IntRect&) const; |
|
159 |
IntRect contentsToWindow(const IntRect&) const; |
|
160 |
||
161 |
// Methods for converting to and from screen coordinates. |
|
162 |
IntRect contentsToScreen(const IntRect&) const; |
|
163 |
IntPoint screenToContents(const IntPoint&) const; |
|
164 |
||
165 |
// The purpose of this method is to answer whether or not the scroll view is currently visible. Animations and painting updates can be suspended if |
|
166 |
// we know that we are either not in a window right now or if that window is not visible. |
|
167 |
bool isOffscreen() const; |
|
168 |
||
169 |
// These methods are used to enable scrollbars to avoid window resizer controls that overlap the scroll view. This happens on Mac |
|
170 |
// for example. |
|
171 |
virtual IntRect windowResizerRect() const { return IntRect(); } |
|
172 |
bool containsScrollbarsAvoidingResizer() const; |
|
173 |
void adjustScrollbarsAvoidingResizerCount(int overlapDelta); |
|
174 |
virtual void setParent(ScrollView*); // Overridden to update the overlapping scrollbar count. |
|
175 |
||
176 |
// Called when our frame rect changes (or the rect/scroll position of an ancestor changes). |
|
177 |
virtual void frameRectsChanged(); |
|
178 |
||
179 |
// Widget override to update our scrollbars and notify our contents of the resize. |
|
180 |
virtual void setFrameRect(const IntRect&); |
|
181 |
||
182 |
// For platforms that need to hit test scrollbars from within the engine's event handlers (like Win32). |
|
183 |
Scrollbar* scrollbarAtPoint(const IntPoint& windowPoint); |
|
184 |
||
185 |
// This method exists for scrollviews that need to handle wheel events manually. |
|
186 |
// On Mac the underlying NSScrollView just does the scrolling, but on other platforms |
|
187 |
// (like Windows), we need this method in order to do the scroll ourselves. |
|
188 |
void wheelEvent(PlatformWheelEvent&); |
|
189 |
||
190 |
IntPoint convertChildToSelf(const Widget* child, const IntPoint& point) const |
|
191 |
{ |
|
192 |
IntPoint newPoint = point; |
|
193 |
if (!isScrollViewScrollbar(child)) |
|
194 |
newPoint = point - scrollOffset(); |
|
195 |
newPoint.move(child->x(), child->y()); |
|
196 |
return newPoint; |
|
197 |
} |
|
198 |
||
199 |
IntPoint convertSelfToChild(const Widget* child, const IntPoint& point) const |
|
200 |
{ |
|
201 |
IntPoint newPoint = point; |
|
202 |
if (!isScrollViewScrollbar(child)) |
|
203 |
newPoint = point + scrollOffset(); |
|
204 |
newPoint.move(-child->x(), -child->y()); |
|
205 |
return newPoint; |
|
206 |
} |
|
207 |
||
208 |
// Widget override. Handles painting of the contents of the view as well as the scrollbars. |
|
209 |
virtual void paint(GraphicsContext*, const IntRect&); |
|
210 |
void paintScrollbars(GraphicsContext*, const IntRect&); |
|
211 |
||
212 |
// Widget overrides to ensure that our children's visibility status is kept up to date when we get shown and hidden. |
|
213 |
virtual void show(); |
|
214 |
virtual void hide(); |
|
215 |
virtual void setParentVisible(bool); |
|
216 |
||
217 |
// Pan scrolling. |
|
218 |
static const int noPanScrollRadius = 15; |
|
219 |
void addPanScrollIcon(const IntPoint&); |
|
220 |
void removePanScrollIcon(); |
|
221 |
void paintPanScrollIcon(GraphicsContext*); |
|
222 |
||
223 |
virtual bool isPointInScrollbarCorner(const IntPoint&); |
|
224 |
virtual bool scrollbarCornerPresent() const; |
|
225 |
||
226 |
virtual IntRect convertFromScrollbarToContainingView(const Scrollbar*, const IntRect&) const; |
|
227 |
virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar*, const IntRect&) const; |
|
228 |
virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar*, const IntPoint&) const; |
|
229 |
virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar*, const IntPoint&) const; |
|
230 |
||
231 |
protected: |
|
232 |
ScrollView(); |
|
233 |
||
234 |
virtual void repaintContentRectangle(const IntRect&, bool now = false); |
|
235 |
virtual void paintContents(GraphicsContext*, const IntRect& damageRect) = 0; |
|
236 |
||
237 |
virtual void contentsResized() = 0; |
|
238 |
virtual void visibleContentsResized() = 0; |
|
239 |
||
240 |
// These methods are used to create/destroy scrollbars. |
|
241 |
void setHasHorizontalScrollbar(bool); |
|
242 |
void setHasVerticalScrollbar(bool); |
|
243 |
||
244 |
IntRect scrollCornerRect() const; |
|
245 |
virtual void updateScrollCorner(); |
|
246 |
virtual void paintScrollCorner(GraphicsContext*, const IntRect& cornerRect); |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
247 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
248 |
// Scroll the content by blitting the pixels |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
249 |
virtual void scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect); |
0 | 250 |
|
251 |
private: |
|
252 |
RefPtr<Scrollbar> m_horizontalScrollbar; |
|
253 |
RefPtr<Scrollbar> m_verticalScrollbar; |
|
254 |
ScrollbarMode m_horizontalScrollbarMode; |
|
255 |
ScrollbarMode m_verticalScrollbarMode; |
|
256 |
bool m_prohibitsScrolling; |
|
257 |
||
258 |
HashSet<RefPtr<Widget> > m_children; |
|
259 |
||
260 |
// This bool is unused on Mac OS because we directly ask the platform widget |
|
261 |
// whether it is safe to blit on scroll. |
|
262 |
bool m_canBlitOnScroll; |
|
263 |
||
264 |
IntSize m_scrollOffset; // FIXME: Would rather store this as a position, but we will wait to make this change until more code is shared. |
|
265 |
IntSize m_fixedLayoutSize; |
|
266 |
IntSize m_contentsSize; |
|
267 |
||
268 |
int m_scrollbarsAvoidingResizer; |
|
269 |
bool m_scrollbarsSuppressed; |
|
270 |
||
271 |
bool m_inUpdateScrollbars; |
|
272 |
unsigned m_updateScrollbarsPass; |
|
273 |
||
274 |
IntPoint m_panScrollIconPoint; |
|
275 |
bool m_drawPanScrollIcon; |
|
276 |
bool m_useFixedLayout; |
|
277 |
||
278 |
void init(); |
|
279 |
void destroy(); |
|
280 |
||
281 |
// Called to update the scrollbars to accurately reflect the state of the view. |
|
282 |
void updateScrollbars(const IntSize& desiredOffset); |
|
283 |
||
284 |
void platformInit(); |
|
285 |
void platformDestroy(); |
|
286 |
void platformAddChild(Widget*); |
|
287 |
void platformRemoveChild(Widget*); |
|
288 |
void platformSetScrollbarModes(); |
|
289 |
void platformScrollbarModes(ScrollbarMode& horizontal, ScrollbarMode& vertical) const; |
|
290 |
void platformSetCanBlitOnScroll(bool); |
|
291 |
bool platformCanBlitOnScroll() const; |
|
292 |
IntRect platformVisibleContentRect(bool includeScrollbars) const; |
|
293 |
IntSize platformContentsSize() const; |
|
294 |
void platformSetContentsSize(); |
|
295 |
IntRect platformContentsToScreen(const IntRect&) const; |
|
296 |
IntPoint platformScreenToContents(const IntPoint&) const; |
|
297 |
void platformSetScrollPosition(const IntPoint&); |
|
298 |
bool platformScroll(ScrollDirection, ScrollGranularity); |
|
299 |
void platformSetScrollbarsSuppressed(bool repaintOnUnsuppress); |
|
300 |
void platformRepaintContentRectangle(const IntRect&, bool now); |
|
301 |
bool platformIsOffscreen() const; |
|
302 |
||
303 |
#if PLATFORM(MAC) && defined __OBJC__ |
|
304 |
public: |
|
305 |
NSView* documentView() const; |
|
306 |
||
307 |
private: |
|
308 |
NSScrollView<WebCoreFrameScrollView>* scrollView() const; |
|
309 |
#endif |
|
310 |
||
311 |
#if PLATFORM(GTK) |
|
312 |
public: |
|
313 |
void setGtkAdjustments(GtkAdjustment* hadj, GtkAdjustment* vadj); |
|
314 |
GtkAdjustment* m_horizontalAdjustment; |
|
315 |
GtkAdjustment* m_verticalAdjustment; |
|
316 |
void setScrollOffset(const IntSize& offset) { m_scrollOffset = offset; } |
|
317 |
#endif |
|
318 |
||
319 |
#if PLATFORM(WX) |
|
320 |
public: |
|
321 |
virtual void setPlatformWidget(wxWindow*); |
|
322 |
void adjustScrollbars(int x = -1, int y = -1, bool refresh = true); |
|
323 |
private: |
|
324 |
class ScrollViewPrivate; |
|
325 |
ScrollViewPrivate* m_data; |
|
326 |
#endif |
|
327 |
||
328 |
}; // class ScrollView |
|
329 |
||
330 |
} // namespace WebCore |
|
331 |
||
332 |
#endif // ScrollView_h |