| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_host_view.h" | 5 #include "ui/views/animation/ink_drop_host_view.h" |
| 6 | 6 |
| 7 #include "ui/gfx/color_palette.h" | 7 #include "ui/gfx/color_palette.h" |
| 8 #include "ui/gfx/geometry/size_conversions.h" |
| 8 #include "ui/views/animation/ink_drop_hover.h" | 9 #include "ui/views/animation/ink_drop_hover.h" |
| 9 #include "ui/views/animation/square_ink_drop_animation.h" | 10 #include "ui/views/animation/square_ink_drop_animation.h" |
| 10 | 11 |
| 11 namespace views { | 12 namespace views { |
| 12 | 13 |
| 13 // Default sizes for ink drop effects. | 14 // Default sizes for ink drop effects. |
| 14 const int kInkDropSize = 24; | 15 const int kInkDropSize = 24; |
| 15 const int kInkDropLargeCornerRadius = 4; | 16 const int kInkDropLargeCornerRadius = 4; |
| 16 | 17 |
| 18 // The scale factor to compute the large ink drop size. |
| 19 const float kLargeInkDropScale = 1.333f; |
| 20 |
| 21 namespace { |
| 22 |
| 23 gfx::Size CalculateLargeInkDropSize(const gfx::Size small_size) { |
| 24 return gfx::ScaleToCeiledSize(gfx::Size(small_size), kLargeInkDropScale); |
| 25 } |
| 26 |
| 27 } // namespace |
| 28 |
| 17 // static | 29 // static |
| 18 const int InkDropHostView::kInkDropSmallCornerRadius = 2; | 30 const int InkDropHostView::kInkDropSmallCornerRadius = 2; |
| 19 | 31 |
| 20 InkDropHostView::InkDropHostView() | 32 InkDropHostView::InkDropHostView() |
| 21 : ink_drop_size_(kInkDropSize, kInkDropSize) {} | 33 : ink_drop_size_(kInkDropSize, kInkDropSize) {} |
| 22 | 34 |
| 23 InkDropHostView::~InkDropHostView() {} | 35 InkDropHostView::~InkDropHostView() {} |
| 24 | 36 |
| 25 void InkDropHostView::AddInkDropLayer(ui::Layer* ink_drop_layer) { | 37 void InkDropHostView::AddInkDropLayer(ui::Layer* ink_drop_layer) { |
| 26 SetPaintToLayer(true); | 38 SetPaintToLayer(true); |
| 27 layer()->SetFillsBoundsOpaquely(false); | 39 layer()->SetFillsBoundsOpaquely(false); |
| 28 layer()->Add(ink_drop_layer); | 40 layer()->Add(ink_drop_layer); |
| 29 layer()->StackAtBottom(ink_drop_layer); | 41 layer()->StackAtBottom(ink_drop_layer); |
| 30 } | 42 } |
| 31 | 43 |
| 32 void InkDropHostView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { | 44 void InkDropHostView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { |
| 33 layer()->Remove(ink_drop_layer); | 45 layer()->Remove(ink_drop_layer); |
| 34 SetPaintToLayer(false); | 46 SetPaintToLayer(false); |
| 35 } | 47 } |
| 36 | 48 |
| 37 scoped_ptr<InkDropAnimation> InkDropHostView::CreateInkDropAnimation() const { | 49 scoped_ptr<InkDropAnimation> InkDropHostView::CreateInkDropAnimation() const { |
| 38 gfx::Size large_drop(ink_drop_size_.width() * 4 / 3, | |
| 39 ink_drop_size_.height() * 4 / 3); | |
| 40 | |
| 41 scoped_ptr<InkDropAnimation> animation(new SquareInkDropAnimation( | 50 scoped_ptr<InkDropAnimation> animation(new SquareInkDropAnimation( |
| 42 large_drop, kInkDropLargeCornerRadius, ink_drop_size_, | 51 CalculateLargeInkDropSize(ink_drop_size_), kInkDropLargeCornerRadius, |
| 43 kInkDropSmallCornerRadius, GetInkDropCenter(), GetInkDropBaseColor())); | 52 ink_drop_size_, kInkDropSmallCornerRadius, GetInkDropCenter(), |
| 53 GetInkDropBaseColor())); |
| 44 return animation; | 54 return animation; |
| 45 } | 55 } |
| 46 | 56 |
| 47 scoped_ptr<InkDropHover> InkDropHostView::CreateInkDropHover() const { | 57 scoped_ptr<InkDropHover> InkDropHostView::CreateInkDropHover() const { |
| 48 scoped_ptr<InkDropHover> hover( | 58 scoped_ptr<InkDropHover> hover( |
| 49 new InkDropHover(ink_drop_size_, kInkDropSmallCornerRadius, | 59 new InkDropHover(ink_drop_size_, kInkDropSmallCornerRadius, |
| 50 GetInkDropCenter(), GetInkDropBaseColor())); | 60 GetInkDropCenter(), GetInkDropBaseColor())); |
| 61 hover->set_explode_size(CalculateLargeInkDropSize(ink_drop_size_)); |
| 51 return hover; | 62 return hover; |
| 52 } | 63 } |
| 53 | 64 |
| 54 gfx::Point InkDropHostView::GetInkDropCenter() const { | 65 gfx::Point InkDropHostView::GetInkDropCenter() const { |
| 55 return GetLocalBounds().CenterPoint(); | 66 return GetLocalBounds().CenterPoint(); |
| 56 } | 67 } |
| 57 | 68 |
| 58 SkColor InkDropHostView::GetInkDropBaseColor() const { | 69 SkColor InkDropHostView::GetInkDropBaseColor() const { |
| 59 NOTREACHED(); | 70 NOTREACHED(); |
| 60 return gfx::kPlaceholderColor; | 71 return gfx::kPlaceholderColor; |
| 61 } | 72 } |
| 62 | 73 |
| 63 } // namespace views | 74 } // namespace views |
| OLD | NEW |