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

Side by Side Diff: cc/animation/scroll_offset_animations_impl.cc

Issue 1952563002: Rename and refactor ScrollOffsetAnimations to ScrollOffsetAnimationsImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/ScrollOffsetAnimationsHostImpl/ScrollOffsetAnimationsImpl Created 4 years, 7 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
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "cc/animation/scroll_offset_animations_impl.h"
6
7 #include "cc/animation/animation_events.h"
8 #include "cc/animation/animation_host.h"
9 #include "cc/animation/animation_id_provider.h"
10 #include "cc/animation/animation_player.h"
11 #include "cc/animation/animation_timeline.h"
12 #include "cc/animation/element_animations.h"
13 #include "cc/animation/timing_function.h"
14
15 namespace cc {
16
17 ScrollOffsetAnimationsImpl::ScrollOffsetAnimationsImpl(
18 AnimationHost* animation_host)
19 : animation_host_(animation_host),
20 scroll_offset_timeline_(
21 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId())),
22 scroll_offset_animation_player_(
23 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId())) {
24 scroll_offset_timeline_->set_is_impl_only(true);
25 scroll_offset_animation_player_->set_animation_delegate(this);
26
27 animation_host_->AddAnimationTimeline(scroll_offset_timeline_.get());
28 scroll_offset_timeline_->AttachPlayer(scroll_offset_animation_player_.get());
29 }
30
31 ScrollOffsetAnimationsImpl::~ScrollOffsetAnimationsImpl() {
32 scroll_offset_timeline_->DetachPlayer(scroll_offset_animation_player_.get());
33 animation_host_->RemoveAnimationTimeline(scroll_offset_timeline_.get());
34 }
35
36 void ScrollOffsetAnimationsImpl::ScrollAnimationCreate(
37 ElementId element_id,
38 const gfx::ScrollOffset& target_offset,
39 const gfx::ScrollOffset& current_offset) {
40 std::unique_ptr<ScrollOffsetAnimationCurve> curve =
41 ScrollOffsetAnimationCurve::Create(
42 target_offset, EaseInOutTimingFunction::Create(),
43 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA);
44 curve->SetInitialValue(current_offset);
45
46 std::unique_ptr<Animation> animation = Animation::Create(
47 std::move(curve), AnimationIdProvider::NextAnimationId(),
48 AnimationIdProvider::NextGroupId(), TargetProperty::SCROLL_OFFSET);
49 animation->set_is_impl_only(true);
50
51 DCHECK(scroll_offset_animation_player_);
52 DCHECK(scroll_offset_animation_player_->animation_timeline());
53
54 ReattachScrollOffsetPlayerIfNeeded(element_id);
55
56 scroll_offset_animation_player_->AddAnimation(std::move(animation));
57 }
58
59 bool ScrollOffsetAnimationsImpl::ScrollAnimationUpdateTarget(
60 ElementId element_id,
61 const gfx::Vector2dF& scroll_delta,
62 const gfx::ScrollOffset& max_scroll_offset,
63 base::TimeTicks frame_monotonic_time) {
64 DCHECK(scroll_offset_animation_player_);
65 if (!scroll_offset_animation_player_->element_animations())
66 return false;
67
68 DCHECK_EQ(element_id, scroll_offset_animation_player_->element_id());
69
70 Animation* animation =
71 scroll_offset_animation_player_->element_animations()->GetAnimation(
72 TargetProperty::SCROLL_OFFSET);
73 if (!animation) {
74 scroll_offset_animation_player_->DetachElement();
75 return false;
76 }
77
78 ScrollOffsetAnimationCurve* curve =
79 animation->curve()->ToScrollOffsetAnimationCurve();
80
81 gfx::ScrollOffset new_target =
82 gfx::ScrollOffsetWithDelta(curve->target_value(), scroll_delta);
83 new_target.SetToMax(gfx::ScrollOffset());
84 new_target.SetToMin(max_scroll_offset);
85
86 curve->UpdateTarget(
87 animation->TrimTimeToCurrentIteration(frame_monotonic_time).InSecondsF(),
88 new_target);
89
90 return true;
91 }
92
93 void ScrollOffsetAnimationsImpl::ScrollAnimationAbort(bool needs_completion) {
94 DCHECK(scroll_offset_animation_player_);
95 scroll_offset_animation_player_->AbortAnimations(
96 TargetProperty::SCROLL_OFFSET, needs_completion);
97 }
98
99 void ScrollOffsetAnimationsImpl::NotifyAnimationFinished(
100 base::TimeTicks monotonic_time,
101 TargetProperty::Type target_property,
102 int group) {
103 DCHECK_EQ(target_property, TargetProperty::SCROLL_OFFSET);
104 DCHECK(animation_host_->mutator_host_client());
105 animation_host_->mutator_host_client()->ScrollOffsetAnimationFinished();
106 }
107
108 void ScrollOffsetAnimationsImpl::ReattachScrollOffsetPlayerIfNeeded(
109 ElementId element_id) {
110 if (scroll_offset_animation_player_->element_id() != element_id) {
111 if (scroll_offset_animation_player_->element_id())
112 scroll_offset_animation_player_->DetachElement();
113 if (element_id)
114 scroll_offset_animation_player_->AttachElement(element_id);
115 }
116 }
117
118 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698