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

Side by Side Diff: ui/views/animation/ink_drop_animation_controller_impl.cc

Issue 1373983002: Enhanced the InkDropRippleImpl to create/destroy InkDropAnimations as needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed merge with master. Created 5 years, 2 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/views/animation/ink_drop_animation_controller_impl.h" 5 #include "ui/views/animation/ink_drop_animation_controller_impl.h"
6 6
7 #include "ui/views/animation/ink_drop_animation.h" 7 #include "ui/views/animation/ink_drop_animation.h"
8 #include "ui/views/animation/ink_drop_host.h" 8 #include "ui/views/animation/ink_drop_host.h"
9 9
10 namespace views { 10 namespace views {
11 11
12 InkDropAnimationControllerImpl::InkDropAnimationControllerImpl( 12 InkDropAnimationControllerImpl::InkDropAnimationControllerImpl(
13 InkDropHost* ink_drop_host) 13 InkDropHost* ink_drop_host)
14 : ink_drop_host_(ink_drop_host) {} 14 : ink_drop_host_(ink_drop_host) {}
15 15
16 InkDropAnimationControllerImpl::~InkDropAnimationControllerImpl() { 16 InkDropAnimationControllerImpl::~InkDropAnimationControllerImpl() {
17 if (ink_drop_animation_) { 17 // Explicitly destroy the InkDropAnimation so that this still exists if
18 // TODO(bruthig): Change this to be called when the ink drop becomes hidden. 18 // views::InkDropAnimationObserver methods are called on this.
19 // See www.crbug.com/522175. 19 DestroyInkDropAnimation();
20 ink_drop_host_->RemoveInkDropLayer(ink_drop_animation_->root_layer());
21 }
22 } 20 }
23 21
24 InkDropState InkDropAnimationControllerImpl::GetInkDropState() const { 22 InkDropState InkDropAnimationControllerImpl::GetInkDropState() const {
25 if (!ink_drop_animation_) 23 if (!ink_drop_animation_)
26 return InkDropState::HIDDEN; 24 return InkDropState::HIDDEN;
27 return ink_drop_animation_->ink_drop_state(); 25 return ink_drop_animation_->ink_drop_state();
28 } 26 }
29 27
30 void InkDropAnimationControllerImpl::AnimateToState(InkDropState state) { 28 void InkDropAnimationControllerImpl::AnimateToState(
29 InkDropState ink_drop_state) {
31 if (!ink_drop_animation_) 30 if (!ink_drop_animation_)
32 CreateInkDropAnimation(); 31 CreateInkDropAnimation();
33 ink_drop_animation_->AnimateToState(state); 32 ink_drop_animation_->AnimateToState(ink_drop_state);
34 } 33 }
35 34
36 gfx::Size InkDropAnimationControllerImpl::GetInkDropLargeSize() const { 35 gfx::Size InkDropAnimationControllerImpl::GetInkDropLargeSize() const {
37 return ink_drop_large_size_; 36 return ink_drop_large_size_;
38 } 37 }
39 38
40 void InkDropAnimationControllerImpl::SetInkDropSize(const gfx::Size& large_size, 39 void InkDropAnimationControllerImpl::SetInkDropSize(const gfx::Size& large_size,
41 int large_corner_radius, 40 int large_corner_radius,
42 const gfx::Size& small_size, 41 const gfx::Size& small_size,
43 int small_corner_radius) { 42 int small_corner_radius) {
(...skipping 10 matching lines...) Expand all
54 } 53 }
55 54
56 void InkDropAnimationControllerImpl::SetInkDropCenter( 55 void InkDropAnimationControllerImpl::SetInkDropCenter(
57 const gfx::Point& center_point) { 56 const gfx::Point& center_point) {
58 ink_drop_center_ = center_point; 57 ink_drop_center_ = center_point;
59 if (ink_drop_animation_) 58 if (ink_drop_animation_)
60 ink_drop_animation_->SetCenterPoint(ink_drop_center_); 59 ink_drop_animation_->SetCenterPoint(ink_drop_center_);
61 } 60 }
62 61
63 void InkDropAnimationControllerImpl::CreateInkDropAnimation() { 62 void InkDropAnimationControllerImpl::CreateInkDropAnimation() {
64 if (ink_drop_animation_) 63 DestroyInkDropAnimation();
65 ink_drop_host_->RemoveInkDropLayer(ink_drop_animation_->root_layer());
66 64
67 // TODO(bruthig): It will be expensive to maintain InkDropAnimation instances
68 // when they are not actually being used. Consider creating InkDropAnimations
69 // on an as-needed basis and if construction is also expensive then consider
70 // creating an InkDropAnimationPool. See www.crbug.com/522175.
71 ink_drop_animation_.reset(new InkDropAnimation( 65 ink_drop_animation_.reset(new InkDropAnimation(
72 ink_drop_large_size_, ink_drop_large_corner_radius_, ink_drop_small_size_, 66 ink_drop_large_size_, ink_drop_large_corner_radius_, ink_drop_small_size_,
73 ink_drop_small_corner_radius_)); 67 ink_drop_small_corner_radius_));
74 68
69 ink_drop_animation_->AddObserver(this);
75 ink_drop_animation_->SetCenterPoint(ink_drop_center_); 70 ink_drop_animation_->SetCenterPoint(ink_drop_center_);
76 ink_drop_host_->AddInkDropLayer(ink_drop_animation_->root_layer()); 71 ink_drop_host_->AddInkDropLayer(ink_drop_animation_->root_layer());
77 } 72 }
78 73
74 void InkDropAnimationControllerImpl::DestroyInkDropAnimation() {
75 if (!ink_drop_animation_)
76 return;
77 ink_drop_host_->RemoveInkDropLayer(ink_drop_animation_->root_layer());
78 ink_drop_animation_->RemoveObserver(this);
79 ink_drop_animation_.reset();
80 }
81
82 void InkDropAnimationControllerImpl::InkDropAnimationStarted(
83 InkDropState ink_drop_state) {}
84
85 void InkDropAnimationControllerImpl::InkDropAnimationEnded(
86 InkDropState ink_drop_state,
87 InkDropAnimationEndedReason reason) {
88 if (reason != SUCCESS)
89 return;
90 switch (ink_drop_state) {
91 case views::InkDropState::QUICK_ACTION:
92 case views::InkDropState::SLOW_ACTION:
93 case views::InkDropState::DEACTIVATED:
94 ink_drop_animation_->AnimateToState(views::InkDropState::HIDDEN);
95 break;
96 case views::InkDropState::HIDDEN:
97 // TODO(bruthig): Investigate whether creating and destroying
98 // InkDropAnimations is expensive and consider creating an
99 // InkDropAnimationPool. See www.crbug.com/522175.
100 DestroyInkDropAnimation();
101 break;
102 default:
103 break;
104 }
105 }
106
79 } // namespace views 107 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/animation/ink_drop_animation_controller_impl.h ('k') | ui/views/animation/ink_drop_animation_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698