Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(770)

Side by Side Diff: sky/engine/platform/scroll/ScrollView.h

Issue 646273006: Get rid of ScrollView. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: merge to ToT Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 "platform/PlatformExport.h"
31 #include "platform/Widget.h"
32 #include "platform/geometry/IntRect.h"
33 #include "platform/scroll/ScrollTypes.h"
34 #include "platform/scroll/ScrollableArea.h"
35 #include "platform/scroll/Scrollbar.h"
36
37 #include "wtf/HashSet.h"
38 #include "wtf/TemporaryChange.h"
39
40 namespace blink {
41
42 class Scrollbar;
43
44 class PLATFORM_EXPORT ScrollView : public Widget, public ScrollableArea {
45 public:
46 virtual ~ScrollView();
47
48 // ScrollableArea functions.
49 virtual int scrollSize(ScrollbarOrientation) const OVERRIDE;
50 virtual void setScrollOffset(const IntPoint&) OVERRIDE;
51 virtual bool isScrollCornerVisible() const OVERRIDE;
52 virtual bool userInputScrollable(ScrollbarOrientation) const OVERRIDE;
53 virtual bool shouldPlaceVerticalScrollbarOnLeft() const OVERRIDE;
54
55 virtual void notifyPageThatContentAreaWillPaint() const;
56
57 // NOTE: This should only be called by the overriden setScrollOffset from Sc rollableArea.
58 virtual void scrollTo(const IntSize& newOffset);
59
60 // The window that hosts the ScrollView. The ScrollView will communicate scr olls and repaints to the
61 // host window in the window's coordinate space.
62 virtual HostWindow* hostWindow() const = 0;
63
64 // Returns a clip rect in host window coordinates. Used to clip the blit on a scroll.
65 virtual IntRect windowClipRect(IncludeScrollbarsInRect = ExcludeScrollbars) const = 0;
66
67 // Functions for child manipulation and inspection.
68 const HashSet<RefPtr<Widget> >* children() const { return &m_children; }
69 virtual void addChild(PassRefPtr<Widget>);
70 virtual void removeChild(Widget*);
71
72 // If the scroll view does not use a native widget, then it will have cross- platform Scrollbars. These functions
73 // can be used to obtain those scrollbars.
74 virtual Scrollbar* horizontalScrollbar() const OVERRIDE { return m_horizonta lScrollbar.get(); }
75 virtual Scrollbar* verticalScrollbar() const OVERRIDE { return m_verticalScr ollbar.get(); }
76 bool isScrollViewScrollbar(const Widget* child) const { return horizontalScr ollbar() == child || verticalScrollbar() == child; }
77
78 void positionScrollbarLayers();
79
80 // Functions for setting and retrieving the scrolling mode in each axis (hor izontal/vertical). The mode has values of
81 // AlwaysOff, AlwaysOn, and Auto. AlwaysOff means never show a scrollbar, Al waysOn means always show a scrollbar.
82 // Auto means show a scrollbar only when one is needed.
83 // Note that for platforms with native widgets, these modes are considered a dvisory. In other words the underlying native
84 // widget may choose not to honor the requested modes.
85 void setScrollbarModes(ScrollbarMode horizontalMode, ScrollbarMode verticalM ode, bool horizontalLock = false, bool verticalLock = false);
86 void setHorizontalScrollbarMode(ScrollbarMode mode, bool lock = false) { set ScrollbarModes(mode, verticalScrollbarMode(), lock, verticalScrollbarLock()); }
87 void setVerticalScrollbarMode(ScrollbarMode mode, bool lock = false) { setSc rollbarModes(horizontalScrollbarMode(), mode, horizontalScrollbarLock(), lock); };
88 void scrollbarModes(ScrollbarMode& horizontalMode, ScrollbarMode& verticalMo de) const;
89 ScrollbarMode horizontalScrollbarMode() const { ScrollbarMode horizontal, ve rtical; scrollbarModes(horizontal, vertical); return horizontal; }
90 ScrollbarMode verticalScrollbarMode() const { ScrollbarMode horizontal, vert ical; scrollbarModes(horizontal, vertical); return vertical; }
91
92 void setHorizontalScrollbarLock(bool lock = true) { m_horizontalScrollbarLoc k = lock; }
93 bool horizontalScrollbarLock() const { return m_horizontalScrollbarLock; }
94 void setVerticalScrollbarLock(bool lock = true) { m_verticalScrollbarLock = lock; }
95 bool verticalScrollbarLock() const { return m_verticalScrollbarLock; }
96
97 void setScrollingModesLock(bool lock = true) { m_horizontalScrollbarLock = m _verticalScrollbarLock = lock; }
98
99 virtual void setCanHaveScrollbars(bool);
100 bool canHaveScrollbars() const { return horizontalScrollbarMode() != Scrollb arAlwaysOff || verticalScrollbarMode() != ScrollbarAlwaysOff; }
101
102 // By default you only receive paint events for the area that is visible. In the case of using a
103 // tiled backing store, this function can be set, so that the view paints th e entire contents.
104 bool paintsEntireContents() const { return m_paintsEntireContents; }
105 void setPaintsEntireContents(bool);
106
107 // By default, paint events are clipped to the visible area. If set to
108 // false, paint events are no longer clipped. paintsEntireContents() implie s !clipsRepaints().
109 bool clipsPaintInvalidations() const { return m_clipsRepaints; }
110 void setClipsRepaints(bool);
111
112 // Overridden by FrameView to create custom CSS scrollbars if applicable.
113 virtual PassRefPtr<Scrollbar> createScrollbar(ScrollbarOrientation);
114
115 // The visible content rect has a location that is the scrolled offset of th e document. The width and height are the viewport width
116 // and height. By default the scrollbars themselves are excluded from this r ectangle, but an optional boolean argument allows them to be
117 // included.
118 virtual IntRect visibleContentRect(IncludeScrollbarsInRect = ExcludeScrollba rs) const OVERRIDE;
119 IntSize visibleSize() const { return visibleContentRect().size(); }
120 virtual int visibleWidth() const OVERRIDE FINAL { return visibleContentRect( ).width(); }
121 virtual int visibleHeight() const OVERRIDE FINAL { return visibleContentRect ().height(); }
122
123 // visibleContentRect().size() is computed from unscaledVisibleContentSize() divided by the value of visibleContentScaleFactor.
124 // For the main frame, visibleContentScaleFactor is equal to the page's page ScaleFactor; it's 1 otherwise.
125 IntSize unscaledVisibleContentSize(IncludeScrollbarsInRect = ExcludeScrollba rs) const;
126 virtual float visibleContentScaleFactor() const { return 1; }
127
128 // Offset used to convert incoming input events while emulating device metic s.
129 virtual IntSize inputEventsOffsetForEmulation() const { return IntSize(); }
130
131 // Scale used to convert incoming input events. Usually the same as visibleC ontentScaleFactor(), unless specifically changed.
132 virtual float inputEventsScaleFactor() const { return visibleContentScaleFac tor(); }
133
134 // Functions for getting/setting the size of the document contained inside t he ScrollView (as an IntSize or as individual width and height
135 // values).
136 virtual IntSize contentsSize() const OVERRIDE; // Always at least as big as the visibleWidth()/visibleHeight().
137 int contentsWidth() const { return contentsSize().width(); }
138 int contentsHeight() const { return contentsSize().height(); }
139 virtual void setContentsSize(const IntSize&);
140
141 // Functions for querying the current scrolled position (both as a point, a size, or as individual X and Y values).
142 virtual IntPoint scrollPosition() const OVERRIDE { return visibleContentRect ().location(); }
143 IntSize scrollOffset() const { return toIntSize(visibleContentRect().locatio n()); } // Gets the scrolled position as an IntSize. Convenient for adding to ot her sizes.
144 IntSize pendingScrollDelta() const { return m_pendingScrollDelta; }
145 virtual IntPoint maximumScrollPosition() const OVERRIDE; // The maximum posi tion we can be scrolled to.
146 virtual IntPoint minimumScrollPosition() const OVERRIDE; // The minimum posi tion we can be scrolled to.
147 // Adjust the passed in scroll position to keep it between the minimum and m aximum positions.
148 IntPoint adjustScrollPositionWithinRange(const IntPoint&) const;
149 int scrollX() const { return scrollPosition().x(); }
150 int scrollY() const { return scrollPosition().y(); }
151
152 virtual IntSize overhangAmount() const OVERRIDE;
153
154 void cacheCurrentScrollPosition() { m_cachedScrollPosition = scrollPosition( ); }
155 IntPoint cachedScrollPosition() const { return m_cachedScrollPosition; }
156
157 // Functions for scrolling the view.
158 virtual void setScrollPosition(const IntPoint&, ScrollBehavior = ScrollBehav iorInstant);
159 void scrollBy(const IntSize& s, ScrollBehavior behavior = ScrollBehaviorInst ant)
160 {
161 return setScrollPosition(scrollPosition() + s, behavior);
162 }
163
164 bool scroll(ScrollDirection, ScrollGranularity);
165
166 // Scroll the actual contents of the view (either blitting or invalidating a s needed).
167 void scrollContents(const IntSize& scrollDelta);
168
169 // This gives us a means of blocking painting on our scrollbars until the fi rst layout has occurred.
170 void setScrollbarsSuppressed(bool suppressed, bool repaintOnUnsuppress = fal se);
171 bool scrollbarsSuppressed() const { return m_scrollbarsSuppressed; }
172
173 IntPoint rootViewToContents(const IntPoint&) const;
174 IntPoint contentsToRootView(const IntPoint&) const;
175 IntRect rootViewToContents(const IntRect&) const;
176 IntRect contentsToRootView(const IntRect&) const;
177
178 // Event coordinates are assumed to be in the coordinate space of a window t hat contains
179 // the entire widget hierarchy. It is up to the platform to decide what the precise definition
180 // of containing window is. (For example on Mac it is the containing NSWindo w.)
181 IntPoint windowToContents(const IntPoint&) const;
182 FloatPoint windowToContents(const FloatPoint&) const;
183 IntPoint contentsToWindow(const IntPoint&) const;
184 IntRect windowToContents(const IntRect&) const;
185 IntRect contentsToWindow(const IntRect&) const;
186
187 // Functions for converting to screen coordinates.
188 IntRect contentsToScreen(const IntRect&) const;
189
190 // Called when our frame rect changes (or the rect/scroll position of an anc estor changes).
191 virtual void frameRectsChanged() OVERRIDE;
192
193 // Widget override to update our scrollbars and notify our contents of the r esize.
194 virtual void setFrameRect(const IntRect&) OVERRIDE;
195
196 // For platforms that need to hit test scrollbars from within the engine's e vent handlers (like Win32).
197 Scrollbar* scrollbarAtPoint(const IntPoint& windowPoint);
198
199 virtual IntPoint convertChildToSelf(const Widget* child, const IntPoint& poi nt) const OVERRIDE
200 {
201 IntPoint newPoint = point;
202 if (!isScrollViewScrollbar(child))
203 newPoint = point - scrollOffset();
204 newPoint.moveBy(child->location());
205 return newPoint;
206 }
207
208 virtual IntPoint convertSelfToChild(const Widget* child, const IntPoint& poi nt) const OVERRIDE
209 {
210 IntPoint newPoint = point;
211 if (!isScrollViewScrollbar(child))
212 newPoint = point + scrollOffset();
213 newPoint.moveBy(-child->location());
214 return newPoint;
215 }
216
217 // Widget override. Handles painting of the contents of the view as well as the scrollbars.
218 virtual void paint(GraphicsContext*, const IntRect&) OVERRIDE;
219 void paintScrollbars(GraphicsContext*, const IntRect&);
220
221 // Widget overrides to ensure that our children's visibility status is kept up to date when we get shown and hidden.
222 virtual void show() OVERRIDE;
223 virtual void hide() OVERRIDE;
224 virtual void setParentVisible(bool) OVERRIDE;
225
226 virtual bool isPointInScrollbarCorner(const IntPoint&);
227 virtual bool scrollbarCornerPresent() const;
228 virtual IntRect scrollCornerRect() const OVERRIDE;
229 virtual void paintScrollCorner(GraphicsContext*, const IntRect& cornerRect);
230 virtual void paintScrollbar(GraphicsContext*, Scrollbar*, const IntRect&);
231
232 virtual IntRect convertFromScrollbarToContainingView(const Scrollbar*, const IntRect&) const OVERRIDE;
233 virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar*, const IntRect&) const OVERRIDE;
234 virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar*, cons t IntPoint&) const OVERRIDE;
235 virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar*, cons t IntPoint&) const OVERRIDE;
236
237 void calculateAndPaintOverhangAreas(GraphicsContext*, const IntRect& dirtyRe ct);
238 void calculateAndPaintOverhangBackground(GraphicsContext*, const IntRect& di rtyRect);
239
240 virtual bool isScrollView() const OVERRIDE FINAL { return true; }
241
242 protected:
243 ScrollView();
244
245 virtual void contentRectangleForPaintInvalidation(const IntRect&);
246 virtual void paintContents(GraphicsContext*, const IntRect& damageRect) = 0;
247
248 virtual void paintOverhangAreas(GraphicsContext*, const IntRect& horizontalO verhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect);
249
250 virtual void scrollbarExistenceDidChange() = 0;
251 // These functions are used to create/destroy scrollbars.
252 void setHasHorizontalScrollbar(bool);
253 void setHasVerticalScrollbar(bool);
254
255 virtual void updateScrollCorner();
256 virtual void invalidateScrollCornerRect(const IntRect&) OVERRIDE;
257
258 virtual void scrollContentsIfNeeded();
259 // Scroll the content by via the compositor.
260 virtual bool scrollContentsFastPath(const IntSize& scrollDelta) { return tru e; }
261 // Scroll the content by invalidating everything.
262 virtual void scrollContentsSlowPath(const IntRect& updateRect);
263
264 void setScrollOrigin(const IntPoint&, bool updatePositionAtAll, bool updateP ositionSynchronously);
265
266 // Subclassed by FrameView to check the writing-mode of the document.
267 virtual bool isVerticalDocument() const { return true; }
268 virtual bool isFlippedDocument() const { return false; }
269
270 enum ComputeScrollbarExistenceOption {
271 FirstPass,
272 Incremental
273 };
274 void computeScrollbarExistence(bool& newHasHorizontalScrollbar, bool& newHas VerticalScrollbar, const IntSize& docSize, ComputeScrollbarExistenceOption = Fir stPass) const;
275 void updateScrollbarGeometry();
276
277 // Called to update the scrollbars to accurately reflect the state of the vi ew.
278 void updateScrollbars(const IntSize& desiredOffset);
279
280 IntSize excludeScrollbars(const IntSize&) const;
281
282 class InUpdateScrollbarsScope {
283 public:
284 explicit InUpdateScrollbarsScope(ScrollView* view)
285 : m_scope(view->m_inUpdateScrollbars, true)
286 { }
287 private:
288 TemporaryChange<bool> m_scope;
289 };
290
291 private:
292 bool adjustScrollbarExistence(ComputeScrollbarExistenceOption = FirstPass);
293 void adjustScrollbarOpacity();
294
295 RefPtr<Scrollbar> m_horizontalScrollbar;
296 RefPtr<Scrollbar> m_verticalScrollbar;
297 ScrollbarMode m_horizontalScrollbarMode;
298 ScrollbarMode m_verticalScrollbarMode;
299
300 bool m_horizontalScrollbarLock;
301 bool m_verticalScrollbarLock;
302
303 HashSet<RefPtr<Widget> > m_children;
304
305 IntSize m_pendingScrollDelta;
306 IntSize m_scrollOffset; // FIXME: Would rather store this as a position, but we will wait to make this change until more code is shared.
307 IntPoint m_cachedScrollPosition;
308 IntSize m_contentsSize;
309
310 bool m_scrollbarsSuppressed;
311
312 bool m_inUpdateScrollbars;
313
314 bool m_paintsEntireContents;
315 bool m_clipsRepaints;
316
317 void init();
318 void destroy();
319
320 IntRect rectToCopyOnScroll() const;
321
322 void calculateOverhangAreasForPainting(IntRect& horizontalOverhangRect, IntR ect& verticalOverhangRect);
323 void updateOverhangAreas();
324 }; // class ScrollView
325
326 DEFINE_TYPE_CASTS(ScrollView, Widget, widget, widget->isScrollView(), widget.isS crollView());
327
328 } // namespace blink
329
330 #endif // ScrollView_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698