Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / views / animation / ink_drop_animation_controller_impl.cc
blob0b014bd8b5caf3cd853f0a190cde8323dc713873
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
3 // found in the LICENSE file.
5 #include "ui/views/animation/ink_drop_animation_controller_impl.h"
7 #include "ui/views/animation/ink_drop_animation.h"
8 #include "ui/views/animation/ink_drop_host.h"
10 namespace views {
12 InkDropAnimationControllerImpl::InkDropAnimationControllerImpl(
13 InkDropHost* ink_drop_host)
14 : ink_drop_host_(ink_drop_host) {}
16 InkDropAnimationControllerImpl::~InkDropAnimationControllerImpl() {
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_->root_layer());
24 InkDropState InkDropAnimationControllerImpl::GetInkDropState() const {
25 if (!ink_drop_animation_)
26 return InkDropState::HIDDEN;
27 return ink_drop_animation_->ink_drop_state();
30 void InkDropAnimationControllerImpl::AnimateToState(InkDropState state) {
31 if (!ink_drop_animation_)
32 CreateInkDropAnimation();
33 ink_drop_animation_->AnimateToState(state);
36 gfx::Size InkDropAnimationControllerImpl::GetInkDropLargeSize() const {
37 return ink_drop_large_size_;
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();
56 void InkDropAnimationControllerImpl::SetInkDropCenter(
57 const gfx::Point& center_point) {
58 ink_drop_center_ = center_point;
59 if (ink_drop_animation_)
60 ink_drop_animation_->SetCenterPoint(ink_drop_center_);
63 void InkDropAnimationControllerImpl::CreateInkDropAnimation() {
64 if (ink_drop_animation_)
65 ink_drop_host_->RemoveInkDropLayer(ink_drop_animation_->root_layer());
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(
72 ink_drop_large_size_, ink_drop_large_corner_radius_, ink_drop_small_size_,
73 ink_drop_small_corner_radius_));
75 ink_drop_animation_->SetCenterPoint(ink_drop_center_);
76 ink_drop_host_->AddInkDropLayer(ink_drop_animation_->root_layer());
79 } // namespace views