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

Side by Side Diff: ui/compositor/scoped_layer_animation_settings.cc

Issue 2215043002: Removing unused functionality from ScopedLayerAnimationSettings: inverse animations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « ui/compositor/scoped_layer_animation_settings.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/compositor/scoped_layer_animation_settings.h" 5 #include "ui/compositor/scoped_layer_animation_settings.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "ui/compositor/layer.h" 9 #include "ui/compositor/layer.h"
10 #include "ui/compositor/layer_animation_observer.h" 10 #include "ui/compositor/layer_animation_observer.h"
11 #include "ui/compositor/layer_animation_sequence.h" 11 #include "ui/compositor/layer_animation_sequence.h"
12 #include "ui/compositor/layer_animator.h" 12 #include "ui/compositor/layer_animator.h"
13 13
14 namespace { 14 namespace {
15 15
16 const int kDefaultTransitionDurationMs = 200; 16 const int kDefaultTransitionDurationMs = 200;
17 17
18 } // namespace 18 } // namespace
19 19
20 namespace ui { 20 namespace ui {
21 21
22 // InvertingObserver -----------------------------------------------------------
23 class InvertingObserver : public ImplicitAnimationObserver {
24 public:
25 InvertingObserver()
26 : base_layer_(NULL) {
27 }
28
29 ~InvertingObserver() override {}
30
31 void SetLayer(Layer* base_layer) { base_layer_ = base_layer; }
32
33 Layer* layer() { return base_layer_; }
34
35 void AddInverselyAnimatedLayer(Layer* inverse_layer) {
36 inverse_layers_.push_back(inverse_layer);
37 }
38
39 void OnImplicitAnimationsCompleted() override {}
40
41 void OnLayerAnimationScheduled(LayerAnimationSequence* sequence) override {
42 DCHECK(base_layer_ != NULL)
43 << "Must set base layer with ScopedLayerAnimationSettings::"
44 << "SetInverslyAnimatedBaseLayer";
45 gfx::Transform base_transform = base_layer_->transform();
46 std::unique_ptr<LayerAnimationElement> inverse =
47 GetInverseElement(sequence, base_transform);
48
49 for (std::vector<Layer*>::const_iterator i =
50 inverse_layers_.begin(); i != inverse_layers_.end(); ++i) {
51 (*i)->GetAnimator()->StartAnimation(new LayerAnimationSequence(
52 LayerAnimationElement::CloneInverseTransformElement(
53 inverse.get())));
54 }
55 }
56 private:
57 std::unique_ptr<LayerAnimationElement> GetInverseElement(
58 LayerAnimationSequence* sequence,
59 gfx::Transform base) const {
60 const size_t expected_size = 1;
61 DCHECK_EQ(expected_size, sequence->size())
62 << "Inverse supported only for single element sequences.";
63
64 LayerAnimationElement* element = sequence->FirstElement();
65 DCHECK_EQ(static_cast<LayerAnimationElement::AnimatableProperties>(
66 LayerAnimationElement::TRANSFORM),
67 element->properties())
68 << "Only transform animations are currently invertible.";
69
70 std::unique_ptr<LayerAnimationElement> to_return(
71 LayerAnimationElement::CreateInverseTransformElement(base, element));
72 return to_return;
73 }
74
75 Layer* base_layer_;
76 // child layers
77 std::vector<Layer*> inverse_layers_;
78 };
79
80
81 // ScopedLayerAnimationSettings ------------------------------------------------ 22 // ScopedLayerAnimationSettings ------------------------------------------------
82 ScopedLayerAnimationSettings::ScopedLayerAnimationSettings( 23 ScopedLayerAnimationSettings::ScopedLayerAnimationSettings(
83 scoped_refptr<LayerAnimator> animator) 24 scoped_refptr<LayerAnimator> animator)
84 : animator_(animator), 25 : animator_(animator),
85 old_is_transition_duration_locked_( 26 old_is_transition_duration_locked_(
86 animator->is_transition_duration_locked_), 27 animator->is_transition_duration_locked_),
87 old_transition_duration_(animator->GetTransitionDuration()), 28 old_transition_duration_(animator->GetTransitionDuration()),
88 old_tween_type_(animator->tween_type()), 29 old_tween_type_(animator->tween_type()),
89 old_preemption_strategy_(animator->preemption_strategy()), 30 old_preemption_strategy_(animator->preemption_strategy()) {
90 inverse_observer_(new InvertingObserver()) {
91 SetTransitionDuration( 31 SetTransitionDuration(
92 base::TimeDelta::FromMilliseconds(kDefaultTransitionDurationMs)); 32 base::TimeDelta::FromMilliseconds(kDefaultTransitionDurationMs));
93 } 33 }
94 34
95 ScopedLayerAnimationSettings::~ScopedLayerAnimationSettings() { 35 ScopedLayerAnimationSettings::~ScopedLayerAnimationSettings() {
96 animator_->is_transition_duration_locked_ = 36 animator_->is_transition_duration_locked_ =
97 old_is_transition_duration_locked_; 37 old_is_transition_duration_locked_;
98 animator_->SetTransitionDuration(old_transition_duration_); 38 animator_->SetTransitionDuration(old_transition_duration_);
99 animator_->set_tween_type(old_tween_type_); 39 animator_->set_tween_type(old_tween_type_);
100 animator_->set_preemption_strategy(old_preemption_strategy_); 40 animator_->set_preemption_strategy(old_preemption_strategy_);
101 41
102 for (std::set<ImplicitAnimationObserver*>::const_iterator i = 42 for (std::set<ImplicitAnimationObserver*>::const_iterator i =
103 observers_.begin(); i != observers_.end(); ++i) { 43 observers_.begin(); i != observers_.end(); ++i) {
104 animator_->observers_.RemoveObserver(*i); 44 animator_->observers_.RemoveObserver(*i);
105 (*i)->SetActive(true); 45 (*i)->SetActive(true);
106 } 46 }
107
108 if (inverse_observer_->layer()) {
109 animator_->observers_.RemoveObserver(inverse_observer_.get());
110 }
111 } 47 }
112 48
113 void ScopedLayerAnimationSettings::AddObserver( 49 void ScopedLayerAnimationSettings::AddObserver(
114 ImplicitAnimationObserver* observer) { 50 ImplicitAnimationObserver* observer) {
115 observers_.insert(observer); 51 observers_.insert(observer);
116 animator_->AddObserver(observer); 52 animator_->AddObserver(observer);
117 } 53 }
118 54
119 void ScopedLayerAnimationSettings::SetTransitionDuration( 55 void ScopedLayerAnimationSettings::SetTransitionDuration(
120 base::TimeDelta duration) { 56 base::TimeDelta duration) {
(...skipping 19 matching lines...) Expand all
140 void ScopedLayerAnimationSettings::SetPreemptionStrategy( 76 void ScopedLayerAnimationSettings::SetPreemptionStrategy(
141 LayerAnimator::PreemptionStrategy strategy) { 77 LayerAnimator::PreemptionStrategy strategy) {
142 animator_->set_preemption_strategy(strategy); 78 animator_->set_preemption_strategy(strategy);
143 } 79 }
144 80
145 LayerAnimator::PreemptionStrategy 81 LayerAnimator::PreemptionStrategy
146 ScopedLayerAnimationSettings::GetPreemptionStrategy() const { 82 ScopedLayerAnimationSettings::GetPreemptionStrategy() const {
147 return animator_->preemption_strategy(); 83 return animator_->preemption_strategy();
148 } 84 }
149 85
150 void ScopedLayerAnimationSettings::SetInverselyAnimatedBaseLayer(Layer* base) {
151 if (inverse_observer_->layer() && !base) {
152 animator_->RemoveObserver(inverse_observer_.get());
153 } else if (base && !(inverse_observer_->layer())) {
154 animator_->AddObserver(inverse_observer_.get());
155 }
156 inverse_observer_->SetLayer(base);
157 }
158
159 void ScopedLayerAnimationSettings::AddInverselyAnimatedLayer(
160 Layer* inverse_layer) {
161 inverse_observer_->AddInverselyAnimatedLayer(inverse_layer);
162 }
163
164 } // namespace ui 86 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/scoped_layer_animation_settings.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698