| OLD | NEW | 
|---|
| 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       ink_drop_animation_(new InkDropAnimation()) { | 15 | 
| 16   // TODO(bruthig): Change this to only be called before the ink drop becomes | 16 InkDropAnimationControllerImpl::~InkDropAnimationControllerImpl() { | 
| 17   // active. See www.crbug.com/522175. | 17   if (ink_drop_animation_) { | 
|  | 18     // TODO(bruthig): Change this to be called when the ink drop becomes hidden. | 
|  | 19     // See www.crbug.com/522175. | 
|  | 20     ink_drop_host_->RemoveInkDropLayer(ink_drop_animation_->GetRootLayer()); | 
|  | 21   } | 
|  | 22 } | 
|  | 23 | 
|  | 24 InkDropState InkDropAnimationControllerImpl::GetInkDropState() const { | 
|  | 25   if (!ink_drop_animation_) | 
|  | 26     return InkDropState::HIDDEN; | 
|  | 27   return ink_drop_animation_->ink_drop_state(); | 
|  | 28 } | 
|  | 29 | 
|  | 30 void InkDropAnimationControllerImpl::AnimateToState(InkDropState state) { | 
|  | 31   if (!ink_drop_animation_) | 
|  | 32     CreateInkDropAnimation(); | 
|  | 33   ink_drop_animation_->AnimateToState(state); | 
|  | 34 } | 
|  | 35 | 
|  | 36 gfx::Size InkDropAnimationControllerImpl::GetInkDropLargeSize() const { | 
|  | 37   return ink_drop_large_size_; | 
|  | 38 } | 
|  | 39 | 
|  | 40 void InkDropAnimationControllerImpl::SetInkDropSize(const gfx::Size& large_size, | 
|  | 41                                                     int large_corner_radius, | 
|  | 42                                                     const gfx::Size& small_size, | 
|  | 43                                                     int small_corner_radius) { | 
|  | 44   // TODO(bruthig): Fix the ink drop animations to work for non-square sizes. | 
|  | 45   DCHECK_EQ(large_size.width(), large_size.height()) | 
|  | 46       << "The ink drop animation does not currently support non-square sizes."; | 
|  | 47   DCHECK_EQ(small_size.width(), small_size.height()) | 
|  | 48       << "The ink drop animation does not currently support non-square sizes."; | 
|  | 49   ink_drop_large_size_ = large_size; | 
|  | 50   ink_drop_large_corner_radius_ = large_corner_radius; | 
|  | 51   ink_drop_small_size_ = small_size; | 
|  | 52   ink_drop_small_corner_radius_ = small_corner_radius; | 
|  | 53   ink_drop_animation_.reset(); | 
|  | 54 } | 
|  | 55 | 
|  | 56 gfx::Point InkDropAnimationControllerImpl::GetInkDropOrigin() const { | 
|  | 57   return ink_drop_origin_; | 
|  | 58 } | 
|  | 59 | 
|  | 60 void InkDropAnimationControllerImpl::SetInkDropOrigin( | 
|  | 61     const gfx::Point& origin) { | 
|  | 62   ink_drop_origin_ = origin; | 
|  | 63   if (ink_drop_animation_) | 
|  | 64     ink_drop_animation_->SetOrigin(ink_drop_origin_); | 
|  | 65 } | 
|  | 66 | 
|  | 67 void InkDropAnimationControllerImpl::CreateInkDropAnimation() { | 
|  | 68   if (ink_drop_animation_) | 
|  | 69     ink_drop_host_->RemoveInkDropLayer(ink_drop_animation_->GetRootLayer()); | 
|  | 70 | 
|  | 71   // TODO(bruthig): It will be expensive to maintain InkDropAnimation instances | 
|  | 72   // when they are not actually being used. Consider creating InkDropAnimations | 
|  | 73   // on an as-needed basis and if construction is also expensive then consider | 
|  | 74   // creating an InkDropAnimationPool. See www.crbug.com/522175. | 
|  | 75   ink_drop_animation_.reset(new InkDropAnimation( | 
|  | 76       ink_drop_large_size_, ink_drop_large_corner_radius_, ink_drop_small_size_, | 
|  | 77       ink_drop_small_corner_radius_)); | 
|  | 78 | 
|  | 79   ink_drop_animation_->SetOrigin(ink_drop_origin_); | 
| 18   ink_drop_host_->AddInkDropLayer(ink_drop_animation_->GetRootLayer()); | 80   ink_drop_host_->AddInkDropLayer(ink_drop_animation_->GetRootLayer()); | 
| 19 } | 81 } | 
| 20 | 82 | 
| 21 InkDropAnimationControllerImpl::~InkDropAnimationControllerImpl() { |  | 
| 22   // TODO(bruthig): Change this to be called when the ink drop becomes hidden. |  | 
| 23   // See www.crbug.com/522175. |  | 
| 24   ink_drop_host_->RemoveInkDropLayer(ink_drop_animation_->GetRootLayer()); |  | 
| 25 } |  | 
| 26 |  | 
| 27 void InkDropAnimationControllerImpl::AnimateToState(InkDropState state) { |  | 
| 28   ink_drop_animation_->AnimateToState(state); |  | 
| 29 } |  | 
| 30 |  | 
| 31 void InkDropAnimationControllerImpl::SetInkDropSize(const gfx::Size& size) { |  | 
| 32   ink_drop_animation_->SetInkDropSize(size); |  | 
| 33 } |  | 
| 34 |  | 
| 35 gfx::Rect InkDropAnimationControllerImpl::GetInkDropBounds() const { |  | 
| 36   return ink_drop_animation_->GetInkDropBounds(); |  | 
| 37 } |  | 
| 38 |  | 
| 39 void InkDropAnimationControllerImpl::SetInkDropBounds(const gfx::Rect& bounds) { |  | 
| 40   ink_drop_animation_->SetInkDropBounds(bounds); |  | 
| 41 } |  | 
| 42 |  | 
| 43 }  // namespace views | 83 }  // namespace views | 
| OLD | NEW | 
|---|