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

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

Issue 1158673006: Replace various ScrollableArea scroll methods with setScrollPosition (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Build fix Created 5 years, 6 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
« no previous file with comments | « Source/platform/scroll/ScrollTypes.h ('k') | Source/platform/scroll/ScrollableArea.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 // Convert a non-finite scroll value (Infinity, -Infinity, NaN) to 0 as 67 // Convert a non-finite scroll value (Infinity, -Infinity, NaN) to 0 as
68 // per http://dev.w3.org/csswg/cssom-view/#normalize-non_finite-values. 68 // per http://dev.w3.org/csswg/cssom-view/#normalize-non_finite-values.
69 static double normalizeNonFiniteScroll(double value) { return std::isfinite( value) ? value : 0.0; } 69 static double normalizeNonFiniteScroll(double value) { return std::isfinite( value) ? value : 0.0; }
70 70
71 // The window that hosts the ScrollableArea. The ScrollableArea will communi cate scrolls and repaints to the 71 // The window that hosts the ScrollableArea. The ScrollableArea will communi cate scrolls and repaints to the
72 // host window in the window's coordinate space. 72 // host window in the window's coordinate space.
73 virtual HostWindow* hostWindow() const { return 0; }; 73 virtual HostWindow* hostWindow() const { return 0; };
74 74
75 virtual ScrollResultOneDimensional userScroll(ScrollDirectionPhysical, Scrol lGranularity, float delta = 1); 75 virtual ScrollResultOneDimensional userScroll(ScrollDirectionPhysical, Scrol lGranularity, float delta = 1);
76 virtual void setScrollPosition(const DoublePoint&, ScrollBehavior = ScrollBe haviorInstant);
77 76
78 void scrollToOffsetWithoutAnimation(const FloatPoint&, bool cancelProgrammat icAnimations = true); 77 virtual void setScrollPosition(const DoublePoint&, ScrollType, ScrollBehavio r = ScrollBehaviorInstant);
79 void scrollToOffsetWithoutAnimation(ScrollbarOrientation, float offset); 78 virtual void scrollBy(const DoubleSize&, ScrollType, ScrollBehavior = Scroll BehaviorInstant);
79 void setScrollPositionSingleAxis(ScrollbarOrientation, double, ScrollType, S crollBehavior = ScrollBehaviorInstant);
80 80
81 // Scrolls the area so that the given rect, given in the document's content coordinates, such that it's 81 // Scrolls the area so that the given rect, given in the document's content coordinates, such that it's
82 // visible in the area. Returns the new location of the input rect relative once again to the document. 82 // visible in the area. Returns the new location of the input rect relative once again to the document.
83 // Note, in the case of a Document container, such as FrameView, the output will always be the input rect 83 // Note, in the case of a Document container, such as FrameView, the output will always be the input rect
84 // since scrolling it can't change the location of content relative to the d ocument, unlike an overflowing 84 // since scrolling it can't change the location of content relative to the d ocument, unlike an overflowing
85 // element. 85 // element.
86 virtual LayoutRect scrollIntoView(const LayoutRect& rectInContent, const Scr ollAlignment& alignX, const ScrollAlignment& alignY); 86 virtual LayoutRect scrollIntoView(const LayoutRect& rectInContent, const Scr ollAlignment& alignX, const ScrollAlignment& alignY);
87 87
88 // Scrolls the area so that the given rect, given in the area's content coor dinates, such that it's 88 // Scrolls the area so that the given rect, given in the area's content coor dinates, such that it's
89 // cenetered in the second rect, which is given relative to the area's origi n. 89 // cenetered in the second rect, which is given relative to the area's origi n.
90 void scrollIntoRect(const LayoutRect& rectInContent, const FloatRect& target RectInFrame); 90 void scrollIntoRect(const LayoutRect& rectInContent, const FloatRect& target RectInFrame);
91 91
92 void programmaticallyScrollSmoothlyToOffset(const FloatPoint&);
93
94 // Should be called when the scroll position changes externally, for example if the scroll layer position 92 // Should be called when the scroll position changes externally, for example if the scroll layer position
95 // is updated on the scrolling thread and we need to notify the main thread. 93 // is updated on the scrolling thread and we need to notify the main thread.
96 void notifyScrollPositionChanged(const DoublePoint&); 94 void notifyScrollPositionChanged(const DoublePoint&);
97 95
98 static bool scrollBehaviorFromString(const String&, ScrollBehavior&); 96 static bool scrollBehaviorFromString(const String&, ScrollBehavior&);
99 97
100 virtual ScrollResult handleWheel(const PlatformWheelEvent&); 98 virtual ScrollResult handleWheel(const PlatformWheelEvent&);
101 99
102 // Functions for controlling if you can scroll past the end of the document. 100 // Functions for controlling if you can scroll past the end of the document.
103 bool constrainsScrollingToContentEdge() const { return m_constrainsScrolling ToContentEdge; } 101 bool constrainsScrollingToContentEdge() const { return m_constrainsScrolling ToContentEdge; }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 bool scrollOriginChanged() const { return m_scrollOriginChanged; } 145 bool scrollOriginChanged() const { return m_scrollOriginChanged; }
148 146
149 147
150 // This is used to determine whether the incoming fractional scroll offset s hould 148 // This is used to determine whether the incoming fractional scroll offset s hould
151 // be truncated to integer. Current rule is that if preferCompositingToLCDTe xtEnabled() 149 // be truncated to integer. Current rule is that if preferCompositingToLCDTe xtEnabled()
152 // is disabled (which is true on low-dpi device by default) we should do the truncation. 150 // is disabled (which is true on low-dpi device by default) we should do the truncation.
153 // The justification is that non-composited elements using fractional scroll offsets 151 // The justification is that non-composited elements using fractional scroll offsets
154 // is causing too much nasty bugs but does not add too benefit on low-dpi de vices. 152 // is causing too much nasty bugs but does not add too benefit on low-dpi de vices.
155 virtual bool shouldUseIntegerScrollOffset() const { return !RuntimeEnabledFe atures::fractionalScrollOffsetsEnabled(); } 153 virtual bool shouldUseIntegerScrollOffset() const { return !RuntimeEnabledFe atures::fractionalScrollOffsetsEnabled(); }
156 154
157 // FIXME(bokan): Meaningless name, rename to isActiveFocus
158 virtual bool isActive() const = 0; 155 virtual bool isActive() const = 0;
159 virtual int scrollSize(ScrollbarOrientation) const = 0; 156 virtual int scrollSize(ScrollbarOrientation) const = 0;
160 virtual void invalidateScrollbar(Scrollbar*, const IntRect&); 157 virtual void invalidateScrollbar(Scrollbar*, const IntRect&);
161 virtual bool isScrollCornerVisible() const = 0; 158 virtual bool isScrollCornerVisible() const = 0;
162 virtual IntRect scrollCornerRect() const = 0; 159 virtual IntRect scrollCornerRect() const = 0;
163 virtual void invalidateScrollCorner(const IntRect&); 160 virtual void invalidateScrollCorner(const IntRect&);
164 virtual void getTickmarks(Vector<IntRect>&) const { } 161 virtual void getTickmarks(Vector<IntRect>&) const { }
165 162
166 // Convert points and rects between the scrollbar and its containing view. 163 // Convert points and rects between the scrollbar and its containing view.
167 // The client needs to implement these in order to be aware of layout effect s 164 // The client needs to implement these in order to be aware of layout effect s
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 // TODO(bokan): FrameView::setScrollPosition uses updateScrollbars to scroll 293 // TODO(bokan): FrameView::setScrollPosition uses updateScrollbars to scroll
297 // which bails out early if its already in updateScrollbars, the effect bein g 294 // which bails out early if its already in updateScrollbars, the effect bein g
298 // that programmatic scrolls (i.e. setScrollPosition) are disabled when in 295 // that programmatic scrolls (i.e. setScrollPosition) are disabled when in
299 // updateScrollbars. Expose this here to allow RootFrameViewport to match th e 296 // updateScrollbars. Expose this here to allow RootFrameViewport to match th e
300 // semantics for now but it should be cleaned up at the source. 297 // semantics for now but it should be cleaned up at the source.
301 virtual bool isProgrammaticallyScrollable() { return true; } 298 virtual bool isProgrammaticallyScrollable() { return true; }
302 299
303 // Subtracts space occupied by this ScrollableArea's scrollbars. 300 // Subtracts space occupied by this ScrollableArea's scrollbars.
304 // Does nothing if overlay scrollbars are enabled. 301 // Does nothing if overlay scrollbars are enabled.
305 IntSize excludeScrollbars(const IntSize&) const; 302 IntSize excludeScrollbars(const IntSize&) const;
306
307 protected: 303 protected:
308 ScrollableArea(); 304 ScrollableArea();
309 305
310 void setScrollOrigin(const IntPoint&); 306 void setScrollOrigin(const IntPoint&);
311 void resetScrollOriginChanged() { m_scrollOriginChanged = false; } 307 void resetScrollOriginChanged() { m_scrollOriginChanged = false; }
312 308
313 private: 309 private:
314 void scrollPositionChanged(const DoublePoint&); 310 void scrollPositionChanged(const DoublePoint&, ScrollType);
315 311
316 // NOTE: Only called from the ScrollAnimator. 312 // NOTE: Only called from the ScrollAnimator.
317 friend class ScrollAnimator; 313 friend class ScrollAnimator;
318 void setScrollOffsetFromAnimation(const DoublePoint&); 314 void setScrollOffsetFromAnimation(const DoublePoint&, ScrollType);
315
316 void programmaticScrollHelper(const DoublePoint&, ScrollBehavior);
317 void userScrollHelper(const DoublePoint&, ScrollBehavior);
319 318
320 // This function should be overriden by subclasses to perform the actual 319 // This function should be overriden by subclasses to perform the actual
321 // scroll of the content. By default the DoublePoint version will just 320 // scroll of the content. By default the DoublePoint version will just
322 // call into the IntPoint version. If fractional scroll is needed, one 321 // call into the IntPoint version. If fractional scroll is needed, one
323 // can override the DoublePoint version to take advantage of the double 322 // can override the DoublePoint version to take advantage of the double
324 // precision scroll offset. 323 // precision scroll offset.
325 // FIXME: Remove the IntPoint version. And change the function to 324 // FIXME: Remove the IntPoint version. And change the function to
326 // take DoubleSize. crbug.com/414283. 325 // take DoubleSize. crbug.com/414283.
327 virtual void setScrollOffset(const IntPoint&) = 0; 326 virtual void setScrollOffset(const IntPoint&, ScrollType) = 0;
328 virtual void setScrollOffset(const DoublePoint& offset) 327 virtual void setScrollOffset(const DoublePoint& offset, ScrollType scrollTyp e)
329 { 328 {
330 setScrollOffset(flooredIntPoint(offset)); 329 setScrollOffset(flooredIntPoint(offset), scrollType);
331 } 330 }
332 331
333 virtual int lineStep(ScrollbarOrientation) const; 332 virtual int lineStep(ScrollbarOrientation) const;
334 virtual int pageStep(ScrollbarOrientation) const; 333 virtual int pageStep(ScrollbarOrientation) const;
335 virtual int documentStep(ScrollbarOrientation) const; 334 virtual int documentStep(ScrollbarOrientation) const;
336 virtual float pixelStep(ScrollbarOrientation) const; 335 virtual float pixelStep(ScrollbarOrientation) const;
337 336
338 // Stores the paint invalidations for the scrollbars during layout. 337 // Stores the paint invalidations for the scrollbars during layout.
339 IntRect m_horizontalBarDamage; 338 IntRect m_horizontalBarDamage;
340 IntRect m_verticalBarDamage; 339 IntRect m_verticalBarDamage;
(...skipping 22 matching lines...) Expand all
363 // vertical-lr / ltr NO NO 362 // vertical-lr / ltr NO NO
364 // vertical-lr / rtl NO YES 363 // vertical-lr / rtl NO YES
365 // vertical-rl / ltr YES NO 364 // vertical-rl / ltr YES NO
366 // vertical-rl / rtl YES YES 365 // vertical-rl / rtl YES YES
367 IntPoint m_scrollOrigin; 366 IntPoint m_scrollOrigin;
368 }; 367 };
369 368
370 } // namespace blink 369 } // namespace blink
371 370
372 #endif // ScrollableArea_h 371 #endif // ScrollableArea_h
OLDNEW
« no previous file with comments | « Source/platform/scroll/ScrollTypes.h ('k') | Source/platform/scroll/ScrollableArea.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698