Chromium Code Reviews| Index: third_party/WebKit/Source/platform/scroll/SmoothScrollSequencer.cpp |
| diff --git a/third_party/WebKit/Source/platform/scroll/SmoothScrollSequencer.cpp b/third_party/WebKit/Source/platform/scroll/SmoothScrollSequencer.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9afc8388b4bd9fd90491e44c6396d823f9ec5d36 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/platform/scroll/SmoothScrollSequencer.cpp |
| @@ -0,0 +1,50 @@ |
| +// Copyright (c) 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| +#include "platform/scroll/SmoothScrollSequencer.h" |
| + |
| +#include "platform/scroll/ProgrammaticScrollAnimator.h" |
| +#include "platform/scroll/ScrollableArea.h" |
| + |
| +namespace blink { |
| + |
| +SmoothScrollSequencer* SmoothScrollSequencer::Create() { |
| + return new SmoothScrollSequencer(); |
| +} |
| + |
| +SmoothScrollSequencer::SmoothScrollSequencer() {} |
| + |
| +SmoothScrollSequencer::~SmoothScrollSequencer() {} |
| + |
| +void SmoothScrollSequencer::QueueAnimation(ScrollableArea* scrollable, |
| + ScrollOffset offset) { |
| + ScrollerAndOffsetPair scroller_offset(scrollable, offset); |
| + queue_.push_back(scroller_offset); |
| +} |
| + |
| +void SmoothScrollSequencer::RunQueuedAnimations() { |
| + if (queue_.empty()) { |
| + current_scrollable_ = nullptr; |
| + return; |
| + } |
| + ScrollerAndOffsetPair scroller_offset = queue_.back(); |
| + ScrollableArea* scrollable = scroller_offset.first; |
| + current_scrollable_ = scrollable; |
| + ScrollOffset offset = scroller_offset.second; |
| + scrollable->GetProgrammaticScrollAnimator().AnimateToOffset(offset, true); |
| + queue_.pop_back(); |
|
bokan
2017/05/15 17:15:28
nit: this should happen right after reading queue_
sunyunjia
2017/05/19 16:24:29
Done.
|
| +} |
| + |
| +void SmoothScrollSequencer::AbortAnimations() { |
| + if (current_scrollable_) { |
| + current_scrollable_->GetProgrammaticScrollAnimator().CancelAnimation(); |
| + current_scrollable_ = nullptr; |
| + } |
| + queue_.clear(); |
| +} |
| + |
| +DEFINE_TRACE(SmoothScrollSequencer) { |
| + visitor->Trace(current_scrollable_); |
| +} |
| + |
| +} // namespace blink |