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

Unified Diff: third_party/WebKit/Source/platform/scroll/ProgrammaticScrollAnimator.cpp

Issue 2650343008: Implement Element.scrollIntoView for scroll-behavior: smooth. (Closed)
Patch Set: Fixed nits. 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/scroll/ProgrammaticScrollAnimator.cpp
diff --git a/third_party/WebKit/Source/platform/scroll/ProgrammaticScrollAnimator.cpp b/third_party/WebKit/Source/platform/scroll/ProgrammaticScrollAnimator.cpp
index b717e08a653fad1d135766e18a01070cddfca373..45a04d81d4c90f5e70452ef940f0964d63f1ac18 100644
--- a/third_party/WebKit/Source/platform/scroll/ProgrammaticScrollAnimator.cpp
+++ b/third_party/WebKit/Source/platform/scroll/ProgrammaticScrollAnimator.cpp
@@ -10,6 +10,7 @@
#include "platform/geometry/IntSize.h"
#include "platform/graphics/GraphicsLayer.h"
#include "platform/scroll/ScrollableArea.h"
+#include "platform/scroll/SmoothScrollSequencer.h"
#include "platform/wtf/PtrUtil.h"
#include "public/platform/Platform.h"
#include "public/platform/WebCompositorSupport.h"
@@ -30,7 +31,9 @@ void ProgrammaticScrollAnimator::ResetAnimationState() {
void ProgrammaticScrollAnimator::NotifyOffsetChanged(
const ScrollOffset& offset) {
- ScrollOffsetChanged(offset, kProgrammaticScroll);
+ ScrollType scroll_type = sequenced_for_smooth_scroll_ ? kSequencedSmoothScroll
+ : kProgrammaticScroll;
+ ScrollOffsetChanged(offset, scroll_type);
}
void ProgrammaticScrollAnimator::ScrollToOffsetWithoutAnimation(
@@ -39,12 +42,15 @@ void ProgrammaticScrollAnimator::ScrollToOffsetWithoutAnimation(
NotifyOffsetChanged(offset);
}
-void ProgrammaticScrollAnimator::AnimateToOffset(const ScrollOffset& offset) {
+void ProgrammaticScrollAnimator::AnimateToOffset(
+ const ScrollOffset& offset,
+ bool sequenced_for_smooth_scroll) {
if (run_state_ == RunState::kPostAnimationCleanup)
ResetAnimationState();
start_time_ = 0.0;
target_offset_ = offset;
+ sequenced_for_smooth_scroll_ = sequenced_for_smooth_scroll;
animation_curve_ = CompositorScrollOffsetAnimationCurve::Create(
CompositorOffsetFromBlinkOffset(target_offset_),
CompositorScrollOffsetAnimationCurve::kScrollDurationDeltaBased);
@@ -76,6 +82,7 @@ void ProgrammaticScrollAnimator::TickAnimation(double monotonic_time) {
if (is_finished) {
run_state_ = RunState::kPostAnimationCleanup;
+ AnimationFinished();
} else if (!scrollable_area_->ScheduleAnimation()) {
NotifyOffsetChanged(offset);
ResetAnimationState();
@@ -116,7 +123,12 @@ void ProgrammaticScrollAnimator::UpdateCompositorAnimations() {
bool sent_to_compositor = false;
- if (!scrollable_area_->ShouldScrollOnMainThread()) {
+ // TODO(sunyunjia): Sequenced Smooth Scroll should also be able to
+ // scroll on the compositor thread. We should send the ScrollType
+ // information to the compositor thread.
+ // crbug.com/730705
+ if (!scrollable_area_->ShouldScrollOnMainThread() &&
+ !sequenced_for_smooth_scroll_) {
std::unique_ptr<CompositorAnimation> animation =
CompositorAnimation::Create(
*animation_curve_, CompositorTargetProperty::SCROLL_OFFSET, 0, 0);
@@ -169,6 +181,16 @@ void ProgrammaticScrollAnimator::NotifyCompositorAnimationFinished(
int group_id) {
DCHECK_NE(run_state_, RunState::kRunningOnCompositorButNeedsUpdate);
ScrollAnimatorCompositorCoordinator::CompositorAnimationFinished(group_id);
+ AnimationFinished();
+}
+
+void ProgrammaticScrollAnimator::AnimationFinished() {
+ if (sequenced_for_smooth_scroll_) {
+ sequenced_for_smooth_scroll_ = false;
+ if (SmoothScrollSequencer* sequencer =
+ GetScrollableArea()->GetSmoothScrollSequencer())
+ sequencer->RunQueuedAnimations();
+ }
}
DEFINE_TRACE(ProgrammaticScrollAnimator) {

Powered by Google App Engine
This is Rietveld 408576698