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 std::unique_ptr<InkDropAnimation> InkDropHostView::CreateInkDropAnimation() | 49 std::unique_ptr<InkDropAnimation> InkDropHostView::CreateInkDropAnimation() |
38 const { | 50 const { |
39 gfx::Size large_drop(ink_drop_size_.width() * 4 / 3, | |
40 ink_drop_size_.height() * 4 / 3); | |
41 | |
42 std::unique_ptr<InkDropAnimation> animation(new SquareInkDropAnimation( | 51 std::unique_ptr<InkDropAnimation> animation(new SquareInkDropAnimation( |
43 large_drop, kInkDropLargeCornerRadius, ink_drop_size_, | 52 CalculateLargeInkDropSize(ink_drop_size_), kInkDropLargeCornerRadius, |
44 kInkDropSmallCornerRadius, GetInkDropCenter(), GetInkDropBaseColor())); | 53 ink_drop_size_, kInkDropSmallCornerRadius, GetInkDropCenter(), |
| 54 GetInkDropBaseColor())); |
45 return animation; | 55 return animation; |
46 } | 56 } |
47 | 57 |
48 std::unique_ptr<InkDropHover> InkDropHostView::CreateInkDropHover() const { | 58 std::unique_ptr<InkDropHover> InkDropHostView::CreateInkDropHover() const { |
49 std::unique_ptr<InkDropHover> hover( | 59 std::unique_ptr<InkDropHover> hover( |
50 new InkDropHover(ink_drop_size_, kInkDropSmallCornerRadius, | 60 new InkDropHover(ink_drop_size_, kInkDropSmallCornerRadius, |
51 GetInkDropCenter(), GetInkDropBaseColor())); | 61 GetInkDropCenter(), GetInkDropBaseColor())); |
| 62 hover->set_explode_size(CalculateLargeInkDropSize(ink_drop_size_)); |
52 return hover; | 63 return hover; |
53 } | 64 } |
54 | 65 |
55 gfx::Point InkDropHostView::GetInkDropCenter() const { | 66 gfx::Point InkDropHostView::GetInkDropCenter() const { |
56 return GetLocalBounds().CenterPoint(); | 67 return GetLocalBounds().CenterPoint(); |
57 } | 68 } |
58 | 69 |
59 SkColor InkDropHostView::GetInkDropBaseColor() const { | 70 SkColor InkDropHostView::GetInkDropBaseColor() const { |
60 NOTREACHED(); | 71 NOTREACHED(); |
61 return gfx::kPlaceholderColor; | 72 return gfx::kPlaceholderColor; |
62 } | 73 } |
63 | 74 |
64 } // namespace views | 75 } // namespace views |
OLD | NEW |