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

Unified Diff: third_party/WebKit/Source/platform/scroll/ScrollableArea.h

Issue 2387883002: Use float for scroll offset. (Closed)
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/scroll/ScrollableArea.h
diff --git a/third_party/WebKit/Source/platform/scroll/ScrollableArea.h b/third_party/WebKit/Source/platform/scroll/ScrollableArea.h
index 222c5b34c8b4242128506525ae2a282b3fb92a38..81c1c5c65b3973177726ba74d69d8e8d97d58d88 100644
--- a/third_party/WebKit/Source/platform/scroll/ScrollableArea.h
+++ b/third_party/WebKit/Source/platform/scroll/ScrollableArea.h
@@ -28,7 +28,7 @@
#include "platform/PlatformExport.h"
#include "platform/RuntimeEnabledFeatures.h"
-#include "platform/geometry/DoublePoint.h"
+#include "platform/geometry/LayoutRect.h"
#include "platform/graphics/Color.h"
#include "platform/heap/Handle.h"
#include "platform/scroll/ScrollAnimatorBase.h"
@@ -40,18 +40,14 @@
namespace blink {
-class DoubleRect;
-class FloatPoint;
class GraphicsLayer;
class HostWindow;
class LayoutBox;
-class PlatformWheelEvent;
class ProgrammaticScrollAnimator;
struct ScrollAlignment;
class ScrollAnchor;
class ScrollAnimatorBase;
class CompositorAnimationTimeline;
-class Widget;
enum IncludeScrollbarsInRect {
ExcludeScrollbars,
@@ -68,7 +64,7 @@ class PLATFORM_EXPORT ScrollableArea : public GarbageCollectedMixin {
// Convert a non-finite scroll value (Infinity, -Infinity, NaN) to 0 as
// per http://dev.w3.org/csswg/cssom-view/#normalize-non_finite-values.
- static double normalizeNonFiniteScroll(double value) {
+ static float normalizeNonFiniteScroll(float value) {
return std::isfinite(value) ? value : 0.0;
}
@@ -76,18 +72,18 @@ class PLATFORM_EXPORT ScrollableArea : public GarbageCollectedMixin {
// host window in the window's coordinate space.
virtual HostWindow* getHostWindow() const { return 0; }
- virtual ScrollResult userScroll(ScrollGranularity, const FloatSize&);
+ virtual ScrollResult userScroll(ScrollGranularity, const ScrollOffset&);
- virtual void setScrollPosition(const DoublePoint&,
- ScrollType,
- ScrollBehavior = ScrollBehaviorInstant);
- virtual void scrollBy(const DoubleSize&,
+ virtual void setScrollOffset(const ScrollOffset&,
+ ScrollType,
+ ScrollBehavior = ScrollBehaviorInstant);
+ virtual void scrollBy(const ScrollOffset&,
ScrollType,
ScrollBehavior = ScrollBehaviorInstant);
- void setScrollPositionSingleAxis(ScrollbarOrientation,
- double,
- ScrollType,
- ScrollBehavior = ScrollBehaviorInstant);
+ void setScrollOffsetSingleAxis(ScrollbarOrientation,
+ float,
+ ScrollType,
+ ScrollBehavior = ScrollBehaviorInstant);
// Scrolls the area so that the given rect, given in the document's content coordinates, such that it's
// visible in the area. Returns the new location of the input rect relative once again to the document.
@@ -154,6 +150,7 @@ class PLATFORM_EXPORT ScrollableArea : public GarbageCollectedMixin {
// is disabled (which is true on low-dpi device by default) we should do the truncation.
// The justification is that non-composited elements using fractional scroll offsets
// is causing too much nasty bugs but does not add too benefit on low-dpi devices.
+ // TODO(szager): Now that scroll offsets are floats everywhere, can we get rid of this?
virtual bool shouldUseIntegerScrollOffset() const {
return !RuntimeEnabledFeatures::fractionalScrollOffsetsEnabled();
}
@@ -193,26 +190,24 @@ class PLATFORM_EXPORT ScrollableArea : public GarbageCollectedMixin {
virtual Scrollbar* horizontalScrollbar() const { return nullptr; }
virtual Scrollbar* verticalScrollbar() const { return nullptr; }
- // scrollPosition is relative to the scrollOrigin. i.e. If the page is RTL
- // then scrollPosition will be negative. By default, scrollPositionDouble()
- // just call into scrollPosition(). Subclass can override scrollPositionDouble()
- // to return floating point precision scrolloffset.
- // FIXME: Remove scrollPosition(). crbug.com/414283.
- virtual IntPoint scrollPosition() const = 0;
- virtual DoublePoint scrollPositionDouble() const {
- return DoublePoint(scrollPosition());
+ // scrollOffset is relative to the scrollOrigin. i.e. If the page is RTL
+ // then scrollOffset will be negative. By default, scrollOffset()
+ // just calls into scrollOffset(). Subclasses can override scrollOffset()
+ // to return floating point precision scroll offsets.
+ // FIXME: Remove scrollOffset(). crbug.com/414283.
+ virtual IntSize scrollOffsetInt() const = 0;
bokan 2016/10/02 19:47:51 Is there a reason this Position->Offset renaming i
szager1 2016/10/05 07:43:36 The other patch had functional changes, and it was
bokan 2016/10/06 22:32:17 Acknowledged.
+ virtual ScrollOffset scrollOffset() const {
+ return ScrollOffset(scrollOffsetInt());
}
- virtual IntPoint minimumScrollPosition() const = 0;
- virtual DoublePoint minimumScrollPositionDouble() const {
- return DoublePoint(minimumScrollPosition());
+ virtual IntSize minimumScrollOffsetInt() const = 0;
+ virtual ScrollOffset minimumScrollOffset() const {
+ return ScrollOffset(minimumScrollOffsetInt());
}
- virtual IntPoint maximumScrollPosition() const = 0;
- virtual DoublePoint maximumScrollPositionDouble() const {
- return DoublePoint(maximumScrollPosition());
+ virtual IntSize maximumScrollOffsetInt() const = 0;
+ virtual ScrollOffset maximumScrollOffset() const {
+ return ScrollOffset(maximumScrollOffsetInt());
}
- virtual DoubleRect visibleContentRectDouble(
- IncludeScrollbarsInRect = ExcludeScrollbars) const;
virtual IntRect visibleContentRect(
IncludeScrollbarsInRect = ExcludeScrollbars) const;
virtual int visibleHeight() const { return visibleContentRect().height(); }
@@ -231,10 +226,10 @@ class PLATFORM_EXPORT ScrollableArea : public GarbageCollectedMixin {
virtual bool scrollAnimatorEnabled() const { return false; }
// NOTE: Only called from Internals for testing.
- void updateScrollPositionFromInternals(const IntPoint&);
+ void updateScrollOffsetFromInternals(const IntSize&);
- IntPoint clampScrollPosition(const IntPoint&) const;
- DoublePoint clampScrollPosition(const DoublePoint&) const;
+ IntSize clampScrollOffset(const IntSize&) const;
+ ScrollOffset clampScrollOffset(const ScrollOffset&) const;
// Let subclasses provide a way of asking for and servicing scroll
// animations.
@@ -254,21 +249,21 @@ class PLATFORM_EXPORT ScrollableArea : public GarbageCollectedMixin {
virtual bool shouldPlaceVerticalScrollbarOnLeft() const = 0;
// Convenience functions
- int scrollPosition(ScrollbarOrientation orientation) {
- return orientation == HorizontalScrollbar ? scrollPosition().x()
- : scrollPosition().y();
+ float scrollOffset(ScrollbarOrientation orientation) {
+ return orientation == HorizontalScrollbar ? scrollOffsetInt().width()
+ : scrollOffsetInt().height();
}
- int minimumScrollPosition(ScrollbarOrientation orientation) {
- return orientation == HorizontalScrollbar ? minimumScrollPosition().x()
- : minimumScrollPosition().y();
+ float minimumScrollOffset(ScrollbarOrientation orientation) {
+ return orientation == HorizontalScrollbar ? minimumScrollOffset().width()
+ : minimumScrollOffset().height();
}
- int maximumScrollPosition(ScrollbarOrientation orientation) {
- return orientation == HorizontalScrollbar ? maximumScrollPosition().x()
- : maximumScrollPosition().y();
+ float maximumScrollOffset(ScrollbarOrientation orientation) {
+ return orientation == HorizontalScrollbar ? maximumScrollOffset().width()
+ : maximumScrollOffset().height();
}
- int clampScrollPosition(ScrollbarOrientation orientation, int pos) {
- return clampTo(pos, minimumScrollPosition(orientation),
- maximumScrollPosition(orientation));
+ float clampScrollOffset(ScrollbarOrientation orientation, float offset) {
+ return clampTo(offset, minimumScrollOffset(orientation),
+ maximumScrollOffset(orientation));
}
virtual GraphicsLayer* layerForContainer() const;
@@ -303,9 +298,9 @@ class PLATFORM_EXPORT ScrollableArea : public GarbageCollectedMixin {
// generalized to other types of ScrollableAreas.
virtual bool isScrollable() { return true; }
- // TODO(bokan): FrameView::setScrollPosition uses updateScrollbars to scroll
+ // TODO(bokan): FrameView::setScrollOffset uses updateScrollbars to scroll
// which bails out early if its already in updateScrollbars, the effect being
- // that programmatic scrolls (i.e. setScrollPosition) are disabled when in
+ // that programmatic scrolls (i.e. setScrollOffset) are disabled when in
// updateScrollbars. Expose this here to allow RootFrameViewport to match the
// semantics for now but it should be cleaned up at the source.
virtual bool isProgrammaticallyScrollable() { return true; }
@@ -327,7 +322,7 @@ class PLATFORM_EXPORT ScrollableArea : public GarbageCollectedMixin {
virtual bool isPaintLayerScrollableArea() const { return false; }
virtual bool isRootFrameViewport() const { return false; }
- // Returns true if the scroller adjusts the scroll position to compensate
+ // Returns true if the scroller adjusts the scroll offset to compensate
// for layout movements (bit.ly/scroll-anchoring).
virtual bool shouldPerformScrollAnchoring() const { return false; }
@@ -349,9 +344,9 @@ class PLATFORM_EXPORT ScrollableArea : public GarbageCollectedMixin {
void setScrollOrigin(const IntPoint&);
void resetScrollOriginChanged() { m_scrollOriginChanged = false; }
- // Needed to let the animators call scrollPositionChanged.
+ // Needed to let the animators call scrollOffsetChanged.
friend class ScrollAnimatorCompositorCoordinator;
- void scrollPositionChanged(const DoublePoint&, ScrollType);
+ void scrollOffsetChanged(const ScrollOffset&, ScrollType);
bool horizontalScrollbarNeedsPaintInvalidation() const {
return m_horizontalScrollbarNeedsPaintInvalidation;
@@ -369,11 +364,11 @@ class PLATFORM_EXPORT ScrollableArea : public GarbageCollectedMixin {
}
private:
- void programmaticScrollHelper(const DoublePoint&, ScrollBehavior);
- void userScrollHelper(const DoublePoint&, ScrollBehavior);
+ void programmaticScrollHelper(const ScrollOffset&, ScrollBehavior);
+ void userScrollHelper(const ScrollOffset&, ScrollBehavior);
// This function should be overriden by subclasses to perform the actual scroll of the content.
- virtual void updateScrollPosition(const DoublePoint&, ScrollType) = 0;
+ virtual void updateScrollOffset(const ScrollOffset&, ScrollType) = 0;
virtual int lineStep(ScrollbarOrientation) const;
virtual int pageStep(ScrollbarOrientation) const;

Powered by Google App Engine
This is Rietveld 408576698