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

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

Issue 2911103002: Revert of Implement Element.scrollIntoView for scroll-behavior: smooth. (Closed)
Patch Set: Created 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/scroll/ProgrammaticScrollAnimator.h" 5 #include "platform/scroll/ProgrammaticScrollAnimator.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include "platform/animation/CompositorAnimation.h" 8 #include "platform/animation/CompositorAnimation.h"
9 #include "platform/animation/CompositorScrollOffsetAnimationCurve.h" 9 #include "platform/animation/CompositorScrollOffsetAnimationCurve.h"
10 #include "platform/geometry/IntSize.h" 10 #include "platform/geometry/IntSize.h"
11 #include "platform/graphics/GraphicsLayer.h" 11 #include "platform/graphics/GraphicsLayer.h"
12 #include "platform/scroll/ScrollableArea.h" 12 #include "platform/scroll/ScrollableArea.h"
13 #include "platform/scroll/SmoothScrollSequencer.h"
14 #include "platform/wtf/PtrUtil.h" 13 #include "platform/wtf/PtrUtil.h"
15 #include "public/platform/Platform.h" 14 #include "public/platform/Platform.h"
16 #include "public/platform/WebCompositorSupport.h" 15 #include "public/platform/WebCompositorSupport.h"
17 16
18 namespace blink { 17 namespace blink {
19 18
20 ProgrammaticScrollAnimator::ProgrammaticScrollAnimator( 19 ProgrammaticScrollAnimator::ProgrammaticScrollAnimator(
21 ScrollableArea* scrollable_area) 20 ScrollableArea* scrollable_area)
22 : scrollable_area_(scrollable_area), start_time_(0.0) {} 21 : scrollable_area_(scrollable_area), start_time_(0.0) {}
23 22
24 ProgrammaticScrollAnimator::~ProgrammaticScrollAnimator() {} 23 ProgrammaticScrollAnimator::~ProgrammaticScrollAnimator() {}
25 24
26 void ProgrammaticScrollAnimator::ResetAnimationState() { 25 void ProgrammaticScrollAnimator::ResetAnimationState() {
27 ScrollAnimatorCompositorCoordinator::ResetAnimationState(); 26 ScrollAnimatorCompositorCoordinator::ResetAnimationState();
28 animation_curve_.reset(); 27 animation_curve_.reset();
29 start_time_ = 0.0; 28 start_time_ = 0.0;
30 } 29 }
31 30
32 void ProgrammaticScrollAnimator::NotifyOffsetChanged( 31 void ProgrammaticScrollAnimator::NotifyOffsetChanged(
33 const ScrollOffset& offset) { 32 const ScrollOffset& offset) {
34 ScrollOffsetChanged(offset, kProgrammaticScroll); 33 ScrollOffsetChanged(offset, kProgrammaticScroll);
35 } 34 }
36 35
37 void ProgrammaticScrollAnimator::ScrollToOffsetWithoutAnimation( 36 void ProgrammaticScrollAnimator::ScrollToOffsetWithoutAnimation(
38 const ScrollOffset& offset) { 37 const ScrollOffset& offset) {
39 CancelAnimation(); 38 CancelAnimation();
40 NotifyOffsetChanged(offset); 39 NotifyOffsetChanged(offset);
41 } 40 }
42 41
43 void ProgrammaticScrollAnimator::AnimateToOffset( 42 void ProgrammaticScrollAnimator::AnimateToOffset(const ScrollOffset& offset) {
44 const ScrollOffset& offset,
45 bool sequenced_for_smooth_scroll) {
46 if (run_state_ == RunState::kPostAnimationCleanup) 43 if (run_state_ == RunState::kPostAnimationCleanup)
47 ResetAnimationState(); 44 ResetAnimationState();
48 45
49 start_time_ = 0.0; 46 start_time_ = 0.0;
50 target_offset_ = offset; 47 target_offset_ = offset;
51 sequenced_for_smooth_scroll_ = sequenced_for_smooth_scroll;
52 animation_curve_ = CompositorScrollOffsetAnimationCurve::Create( 48 animation_curve_ = CompositorScrollOffsetAnimationCurve::Create(
53 CompositorOffsetFromBlinkOffset(target_offset_), 49 CompositorOffsetFromBlinkOffset(target_offset_),
54 CompositorScrollOffsetAnimationCurve::kScrollDurationDeltaBased); 50 CompositorScrollOffsetAnimationCurve::kScrollDurationDeltaBased);
55 51
56 scrollable_area_->RegisterForAnimation(); 52 scrollable_area_->RegisterForAnimation();
57 if (!scrollable_area_->ScheduleAnimation()) { 53 if (!scrollable_area_->ScheduleAnimation()) {
58 ResetAnimationState(); 54 ResetAnimationState();
59 NotifyOffsetChanged(offset); 55 NotifyOffsetChanged(offset);
60 } 56 }
61 run_state_ = RunState::kWaitingToSendToCompositor; 57 run_state_ = RunState::kWaitingToSendToCompositor;
(...skipping 11 matching lines...) Expand all
73 if (!start_time_) 69 if (!start_time_)
74 start_time_ = monotonic_time; 70 start_time_ = monotonic_time;
75 double elapsed_time = monotonic_time - start_time_; 71 double elapsed_time = monotonic_time - start_time_;
76 bool is_finished = (elapsed_time > animation_curve_->Duration()); 72 bool is_finished = (elapsed_time > animation_curve_->Duration());
77 ScrollOffset offset = 73 ScrollOffset offset =
78 BlinkOffsetFromCompositorOffset(animation_curve_->GetValue(elapsed_time)); 74 BlinkOffsetFromCompositorOffset(animation_curve_->GetValue(elapsed_time));
79 NotifyOffsetChanged(offset); 75 NotifyOffsetChanged(offset);
80 76
81 if (is_finished) { 77 if (is_finished) {
82 run_state_ = RunState::kPostAnimationCleanup; 78 run_state_ = RunState::kPostAnimationCleanup;
83 AnimationFinished();
84 } else if (!scrollable_area_->ScheduleAnimation()) { 79 } else if (!scrollable_area_->ScheduleAnimation()) {
85 NotifyOffsetChanged(offset); 80 NotifyOffsetChanged(offset);
86 ResetAnimationState(); 81 ResetAnimationState();
87 } 82 }
88 } 83 }
89 84
90 void ProgrammaticScrollAnimator::UpdateCompositorAnimations() { 85 void ProgrammaticScrollAnimator::UpdateCompositorAnimations() {
91 if (run_state_ == RunState::kPostAnimationCleanup) { 86 if (run_state_ == RunState::kPostAnimationCleanup) {
92 // No special cleanup, simply reset animation state. We have this state 87 // No special cleanup, simply reset animation state. We have this state
93 // here because the state machine is shared with ScrollAnimator which 88 // here because the state machine is shared with ScrollAnimator which
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 ResetAnimationState(); 162 ResetAnimationState();
168 NotifyOffsetChanged(target_offset_); 163 NotifyOffsetChanged(target_offset_);
169 } 164 }
170 } 165 }
171 } 166 }
172 167
173 void ProgrammaticScrollAnimator::NotifyCompositorAnimationFinished( 168 void ProgrammaticScrollAnimator::NotifyCompositorAnimationFinished(
174 int group_id) { 169 int group_id) {
175 DCHECK_NE(run_state_, RunState::kRunningOnCompositorButNeedsUpdate); 170 DCHECK_NE(run_state_, RunState::kRunningOnCompositorButNeedsUpdate);
176 ScrollAnimatorCompositorCoordinator::CompositorAnimationFinished(group_id); 171 ScrollAnimatorCompositorCoordinator::CompositorAnimationFinished(group_id);
177 AnimationFinished();
178 }
179
180 void ProgrammaticScrollAnimator::AnimationFinished() {
181 if (sequenced_for_smooth_scroll_) {
182 sequenced_for_smooth_scroll_ = false;
183 if (SmoothScrollSequencer* sequencer =
184 GetScrollableArea()->GetSmoothScrollSequencer())
185 sequencer->RunQueuedAnimations();
186 }
187 } 172 }
188 173
189 DEFINE_TRACE(ProgrammaticScrollAnimator) { 174 DEFINE_TRACE(ProgrammaticScrollAnimator) {
190 visitor->Trace(scrollable_area_); 175 visitor->Trace(scrollable_area_);
191 ScrollAnimatorCompositorCoordinator::Trace(visitor); 176 ScrollAnimatorCompositorCoordinator::Trace(visitor);
192 } 177 }
193 178
194 } // namespace blink 179 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698