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

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: Rebaseline. 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
« no previous file with comments | « Source/platform/mac/ThemeMac.mm ('k') | Source/platform/scroll/ScrollView.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // FIXME: Remove scrollOffset(). crbug.com/414283.
138 IntSize scrollOffset() const { return toIntSize(visibleContentRect().locatio n()); } // Gets the scrolled position as an IntSize. Convenient for adding to ot her sizes.
139 DoubleSize scrollOffsetDouble() const { return DoubleSize(m_scrollPosition.x (), m_scrollPosition.y()); }
140 DoubleSize pendingScrollDelta() const { return m_pendingScrollDelta; }
141 virtual IntPoint maximumScrollPosition() const override; // The maximum posi tion we can be scrolled to.
142 virtual IntPoint minimumScrollPosition() const override; // The minimum posi tion we can be scrolled to.
143 // Adjust the passed in scroll position to keep it between the minimum and m aximum positions.
144 IntPoint adjustScrollPositionWithinRange(const IntPoint&) const;
145 DoublePoint adjustScrollPositionWithinRange(const DoublePoint&) const;
146 double scrollX() const { return scrollPositionDouble().x(); }
147 double scrollY() const { return scrollPositionDouble().y(); }
148
149 virtual IntSize overhangAmount() const override;
150
151 void cacheCurrentScrollPosition() { m_cachedScrollPosition = scrollPositionD ouble(); }
152 DoublePoint cachedScrollPosition() const { return m_cachedScrollPosition; }
153
154 // Functions for scrolling the view.
155 virtual void setScrollPosition(const DoublePoint&, ScrollBehavior = ScrollBe haviorInstant);
156 void scrollBy(const DoubleSize& s, ScrollBehavior behavior = ScrollBehaviorI nstant)
157 {
158 return setScrollPosition(scrollPositionDouble() + s, behavior);
159 }
160
161 bool scroll(ScrollDirection, ScrollGranularity);
162
163 // Scroll the actual contents of the view (either blitting or invalidating a s needed).
164 void scrollContents(const IntSize& scrollDelta);
165
166 // This gives us a means of blocking painting on our scrollbars until the fi rst layout has occurred.
167 void setScrollbarsSuppressed(bool suppressed, bool repaintOnUnsuppress = fal se);
168 bool scrollbarsSuppressed() const { return m_scrollbarsSuppressed; }
169
170 IntPoint rootViewToContents(const IntPoint&) const;
171 IntPoint contentsToRootView(const IntPoint&) const;
172 IntRect rootViewToContents(const IntRect&) const;
173 IntRect contentsToRootView(const IntRect&) const;
174
175 // Event coordinates are assumed to be in the coordinate space of a window t hat contains
176 // the entire widget hierarchy. It is up to the platform to decide what the precise definition
177 // of containing window is. (For example on Mac it is the containing NSWindo w.)
178 IntPoint windowToContents(const IntPoint&) const;
179 FloatPoint windowToContents(const FloatPoint&) const;
180 IntPoint contentsToWindow(const IntPoint&) const;
181 IntRect windowToContents(const IntRect&) const;
182 IntRect contentsToWindow(const IntRect&) const;
183
184 // Functions for converting to screen coordinates.
185 IntRect contentsToScreen(const IntRect&) const;
186
187 // These functions are used to enable scrollbars to avoid window resizer con trols that overlap the scroll view. This happens on Mac
188 // for example.
189 virtual IntRect windowResizerRect() const { return IntRect(); }
190 bool containsScrollbarsAvoidingResizer() const;
191 void adjustScrollbarsAvoidingResizerCount(int overlapDelta);
192 void windowResizerRectChanged();
193
194 virtual void setParent(Widget*) override; // Overridden to update the overla pping scrollbar count.
195
196 // Called when our frame rect changes (or the rect/scroll position of an anc estor changes).
197 virtual void frameRectsChanged() override;
198
199 // Widget override to update our scrollbars and notify our contents of the r esize.
200 virtual void setFrameRect(const IntRect&) override;
201
202 // For platforms that need to hit test scrollbars from within the engine's e vent handlers (like Win32).
203 Scrollbar* scrollbarAtWindowPoint(const IntPoint& windowPoint);
204 Scrollbar* scrollbarAtViewPoint(const IntPoint& viewPoint);
205
206 virtual IntPoint convertChildToSelf(const Widget* child, const IntPoint& poi nt) const override
207 {
208 IntPoint newPoint = point;
209 if (!isScrollViewScrollbar(child))
210 newPoint = point - scrollOffset();
211 newPoint.moveBy(child->location());
212 return newPoint;
213 }
214
215 virtual IntPoint convertSelfToChild(const Widget* child, const IntPoint& poi nt) const override
216 {
217 IntPoint newPoint = point;
218 if (!isScrollViewScrollbar(child))
219 newPoint = point + scrollOffset();
220 newPoint.moveBy(-child->location());
221 return newPoint;
222 }
223
224 // Widget override. Handles painting of the contents of the view as well as the scrollbars.
225 virtual void paint(GraphicsContext*, const IntRect&) override;
226 void paintScrollbars(GraphicsContext*, const IntRect&);
227
228 // Widget overrides to ensure that our children's visibility status is kept up to date when we get shown and hidden.
229 virtual void show() override;
230 virtual void hide() override;
231 virtual void setParentVisible(bool) override;
232
233 // Pan scrolling.
234 static const int noPanScrollRadius = 15;
235 void addPanScrollIcon(const IntPoint&);
236 void removePanScrollIcon();
237 void paintPanScrollIcon(GraphicsContext*);
238
239 virtual bool isPointInScrollbarCorner(const IntPoint&);
240 virtual bool scrollbarCornerPresent() const;
241 virtual IntRect scrollCornerRect() const override;
242 virtual void paintScrollCorner(GraphicsContext*, const IntRect& cornerRect);
243 virtual void paintScrollbar(GraphicsContext*, Scrollbar*, const IntRect&);
244
245 virtual IntRect convertFromScrollbarToContainingView(const Scrollbar*, const IntRect&) const override;
246 virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar*, const IntRect&) const override;
247 virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar*, cons t IntPoint&) const override;
248 virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar*, cons t IntPoint&) const override;
249
250 void calculateAndPaintOverhangAreas(GraphicsContext*, const IntRect& dirtyRe ct);
251 void calculateAndPaintOverhangBackground(GraphicsContext*, const IntRect& di rtyRect);
252
253 virtual bool isScrollView() const override final { return true; }
254
255 protected:
256 ScrollView();
257
258 // NOTE: This should only be called by the overriden setScrollOffset from Sc rollableArea.
259 virtual void scrollTo(const DoublePoint& newPosition);
260
261 virtual void contentRectangleForPaintInvalidation(const IntRect&);
262 virtual void paintContents(GraphicsContext*, const IntRect& damageRect) = 0;
263
264 virtual void paintOverhangAreas(GraphicsContext*, const IntRect& horizontalO verhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect);
265
266 virtual void scrollbarExistenceDidChange() = 0;
267 // These functions are used to create/destroy scrollbars.
268 void setHasHorizontalScrollbar(bool);
269 void setHasVerticalScrollbar(bool);
270
271 virtual void updateScrollCorner();
272 virtual void invalidateScrollCornerRect(const IntRect&) override;
273
274 void scrollContentsIfNeeded();
275 // Scroll the content by via the compositor.
276 virtual bool scrollContentsFastPath(const IntSize& scrollDelta) { return tru e; }
277 // Scroll the content by invalidating everything.
278 virtual void scrollContentsSlowPath(const IntRect& updateRect);
279
280 void setScrollOrigin(const IntPoint&, bool updatePositionAtAll, bool updateP ositionSynchronously);
281
282 // Subclassed by FrameView to check the writing-mode of the document.
283 virtual bool isVerticalDocument() const { return true; }
284 virtual bool isFlippedDocument() const { return false; }
285
286 enum ComputeScrollbarExistenceOption {
287 FirstPass,
288 Incremental
289 };
290 void computeScrollbarExistence(bool& newHasHorizontalScrollbar, bool& newHas VerticalScrollbar, const IntSize& docSize, ComputeScrollbarExistenceOption = Fir stPass) const;
291 void updateScrollbarGeometry();
292 IntRect adjustScrollbarRectForResizer(const IntRect&, Scrollbar*);
293
294 // Called to update the scrollbars to accurately reflect the state of the vi ew.
295 void updateScrollbars(const DoubleSize& desiredOffset);
296
297 IntSize excludeScrollbars(const IntSize&) const;
298
299 class InUpdateScrollbarsScope {
300 public:
301 explicit InUpdateScrollbarsScope(ScrollView* view)
302 : m_scope(view->m_inUpdateScrollbars, true)
303 { }
304 private:
305 TemporaryChange<bool> m_scope;
306 };
307
308 virtual bool scrollbarsDisabled() const { return false; }
309
310 private:
311 bool adjustScrollbarExistence(ComputeScrollbarExistenceOption = FirstPass);
312 void adjustScrollbarOpacity();
313 // FIXME(bokan): setScrollOffset, setScrollPosition, scrollTo, scrollToOffse tWithoutAnimation,
314 // notifyScrollPositionChanged...there's too many ways to scroll this class. This needs
315 // some cleanup.
316 void setScrollOffsetFromUpdateScrollbars(const DoubleSize&);
317
318 RefPtr<Scrollbar> m_horizontalScrollbar;
319 RefPtr<Scrollbar> m_verticalScrollbar;
320 ScrollbarMode m_horizontalScrollbarMode;
321 ScrollbarMode m_verticalScrollbarMode;
322
323 bool m_horizontalScrollbarLock;
324 bool m_verticalScrollbarLock;
325
326 HashSet<RefPtr<Widget> > m_children;
327
328 DoubleSize m_pendingScrollDelta;
329 DoublePoint m_scrollPosition;
330 DoublePoint m_cachedScrollPosition;
331 IntSize m_contentsSize;
332
333 int m_scrollbarsAvoidingResizer;
334 bool m_scrollbarsSuppressed;
335
336 bool m_inUpdateScrollbars;
337
338 IntPoint m_panScrollIconPoint;
339 bool m_drawPanScrollIcon;
340
341 bool m_clipsRepaints;
342
343 void init();
344 void destroy();
345
346 IntRect rectToCopyOnScroll() const;
347
348 void calculateOverhangAreasForPainting(IntRect& horizontalOverhangRect, IntR ect& verticalOverhangRect);
349 void updateOverhangAreas();
350 }; // class ScrollView
351
352 DEFINE_TYPE_CASTS(ScrollView, Widget, widget, widget->isScrollView(), widget.isS crollView());
353
354 } // namespace blink
355
356 #endif // ScrollView_h
OLDNEW
« no previous file with comments | « Source/platform/mac/ThemeMac.mm ('k') | Source/platform/scroll/ScrollView.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698