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

Side by Side Diff: third_party/WebKit/Source/platform/scroll/ScrollAnimator.cpp

Issue 1496693005: Update RootFrameViewport::userScroll to distribute scrolls between viewports. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
1 /* 1 /*
2 * Copyright (c) 2011, Google Inc. All rights reserved. 2 * Copyright (c) 2011, Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 : ScrollAnimatorBase(scrollableArea) 52 : ScrollAnimatorBase(scrollableArea)
53 , m_timeFunction(timeFunction) 53 , m_timeFunction(timeFunction)
54 { 54 {
55 } 55 }
56 56
57 ScrollAnimator::~ScrollAnimator() 57 ScrollAnimator::~ScrollAnimator()
58 { 58 {
59 cancelAnimations(); 59 cancelAnimations();
60 } 60 }
61 61
62 FloatPoint ScrollAnimator::desiredTargetPosition() const
63 {
64 return m_animationCurve ? FloatPoint(m_animationCurve->targetValue()) : curr entPosition();
65 }
66
67 float ScrollAnimator::computeDeltaToConsume(ScrollbarOrientation orientation, fl oat pixelDelta) const
68 {
69 FloatPoint pos = desiredTargetPosition();
70 float currentPos = (orientation == HorizontalScrollbar) ? pos.x() : pos.y();
71 float newPos = clampScrollPosition(orientation, currentPos + pixelDelta);
72 return (currentPos == newPos) ? 0.0f : (newPos - currentPos);
73 }
74
62 ScrollResultOneDimensional ScrollAnimator::userScroll(ScrollbarOrientation orien tation, ScrollGranularity granularity, float step, float delta) 75 ScrollResultOneDimensional ScrollAnimator::userScroll(ScrollbarOrientation orien tation, ScrollGranularity granularity, float step, float delta)
63 { 76 {
64 if (!m_scrollableArea->scrollAnimatorEnabled()) 77 if (!m_scrollableArea->scrollAnimatorEnabled())
65 return ScrollAnimatorBase::userScroll(orientation, granularity, step, de lta); 78 return ScrollAnimatorBase::userScroll(orientation, granularity, step, de lta);
66 79
67 TRACE_EVENT0("blink", "ScrollAnimator::scroll"); 80 TRACE_EVENT0("blink", "ScrollAnimator::scroll");
68 81
69 if (granularity == ScrollByPrecisePixel) 82 if (granularity == ScrollByPrecisePixel)
70 return ScrollAnimatorBase::userScroll(orientation, granularity, step, de lta); 83 return ScrollAnimatorBase::userScroll(orientation, granularity, step, de lta);
71 84
72 float pixelDelta = step * delta; 85 float usedPixelDelta = computeDeltaToConsume(orientation, step * delta);
73 FloatPoint desiredDelta = (orientation == VerticalScrollbar ? FloatPoint(0, pixelDelta) : FloatPoint(pixelDelta, 0)); 86 FloatPoint pixelDelta = (orientation == VerticalScrollbar ? FloatPoint(0, us edPixelDelta) : FloatPoint(usedPixelDelta, 0));
74 87
75 FloatPoint targetPos = m_animationCurve ? FloatPoint(m_animationCurve->targe tValue()) : currentPosition(); 88 FloatPoint targetPos = desiredTargetPosition();
76 targetPos.moveBy(desiredDelta); 89 targetPos.moveBy(pixelDelta);
77 targetPos = FloatPoint(m_scrollableArea->clampScrollPosition(targetPos));
78 90
79 if (m_animationCurve) { 91 if (m_animationCurve) {
80 if (!(targetPos - m_animationCurve->targetValue()).isZero()) 92 if (!(targetPos - m_animationCurve->targetValue()).isZero())
81 m_animationCurve->updateTarget(m_timeFunction() - m_startTime, targe tPos); 93 m_animationCurve->updateTarget(m_timeFunction() - m_startTime, targe tPos);
82 return ScrollResultOneDimensional(/* didScroll */ true, /* unusedScrollD elta */ 0); 94 return ScrollResultOneDimensional(/* didScroll */ true, /* unusedScrollD elta */ 0);
83 } 95 }
84 96
85 if ((targetPos - currentPosition()).isZero()) { 97 if ((targetPos - currentPosition()).isZero()) {
86 // Report unused delta only if there is no animation and we are not 98 // Report unused delta only if there is no animation and we are not
87 // starting one. This ensures we latch for the duration of the 99 // starting one. This ensures we latch for the duration of the
88 // animation rather than animating multiple scrollers at the same time. 100 // animation rather than animating multiple scrollers at the same time.
89 return ScrollResultOneDimensional(/* didScroll */ false, pixelDelta); 101 return ScrollResultOneDimensional(/* didScroll */ false, delta);
90 } 102 }
91 103
92 m_animationCurve = adoptPtr(Platform::current()->compositorSupport()->create ScrollOffsetAnimationCurve( 104 m_animationCurve = adoptPtr(Platform::current()->compositorSupport()->create ScrollOffsetAnimationCurve(
93 targetPos, 105 targetPos,
94 WebCompositorAnimationCurve::TimingFunctionTypeEaseInOut, 106 WebCompositorAnimationCurve::TimingFunctionTypeEaseInOut,
95 WebScrollOffsetAnimationCurve::ScrollDurationConstant)); 107 WebScrollOffsetAnimationCurve::ScrollDurationConstant));
96 108
97 m_animationCurve->setInitialValue(currentPosition()); 109 m_animationCurve->setInitialValue(currentPosition());
98 m_startTime = m_timeFunction(); 110 m_startTime = m_timeFunction();
99 111
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 TRACE_EVENT0("blink", "ScrollAnimator::notifyPositionChanged"); 161 TRACE_EVENT0("blink", "ScrollAnimator::notifyPositionChanged");
150 notifyPositionChanged(); 162 notifyPositionChanged();
151 } 163 }
152 164
153 DEFINE_TRACE(ScrollAnimator) 165 DEFINE_TRACE(ScrollAnimator)
154 { 166 {
155 ScrollAnimatorBase::trace(visitor); 167 ScrollAnimatorBase::trace(visitor);
156 } 168 }
157 169
158 } // namespace blink 170 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698