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

Side by Side Diff: Source/platform/scroll/ScrollView.h

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

Powered by Google App Engine
This is Rietveld 408576698