| 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/gfx/geometry/size_conversions.h" | 
|  | 9 #include "ui/views/animation/ink_drop.h" | 
| 9 #include "ui/views/animation/ink_drop_hover.h" | 10 #include "ui/views/animation/ink_drop_hover.h" | 
| 10 #include "ui/views/animation/square_ink_drop_ripple.h" | 11 #include "ui/views/animation/square_ink_drop_ripple.h" | 
| 11 | 12 | 
| 12 namespace views { | 13 namespace views { | 
| 13 | 14 | 
| 14 // Default sizes for ink drop effects. | 15 // Default sizes for ink drop effects. | 
| 15 const int kInkDropSize = 24; | 16 const int kInkDropSize = 24; | 
| 16 const int kInkDropLargeCornerRadius = 4; | 17 const int kInkDropLargeCornerRadius = 4; | 
| 17 | 18 | 
| 18 // The scale factor to compute the large ink drop size. | 19 // The scale factor to compute the large ink drop size. | 
| 19 const float kLargeInkDropScale = 1.333f; | 20 const float kLargeInkDropScale = 1.333f; | 
| 20 | 21 | 
| 21 namespace { | 22 namespace { | 
| 22 | 23 | 
| 23 gfx::Size CalculateLargeInkDropSize(const gfx::Size small_size) { | 24 gfx::Size CalculateLargeInkDropSize(const gfx::Size small_size) { | 
| 24   return gfx::ScaleToCeiledSize(gfx::Size(small_size), kLargeInkDropScale); | 25   return gfx::ScaleToCeiledSize(gfx::Size(small_size), kLargeInkDropScale); | 
| 25 } | 26 } | 
| 26 | 27 | 
| 27 }  // namespace | 28 }  // namespace | 
| 28 | 29 | 
| 29 // static | 30 // static | 
| 30 const int InkDropHostView::kInkDropSmallCornerRadius = 2; | 31 const int InkDropHostView::kInkDropSmallCornerRadius = 2; | 
| 31 | 32 | 
| 32 InkDropHostView::InkDropHostView() | 33 InkDropHostView::InkDropHostView() | 
| 33     : ink_drop_size_(kInkDropSize, kInkDropSize) {} | 34     : ink_drop_size_(kInkDropSize, kInkDropSize), destroying_(false) {} | 
| 34 | 35 | 
| 35 InkDropHostView::~InkDropHostView() {} | 36 InkDropHostView::~InkDropHostView() { | 
|  | 37   // TODO(bruthig): Improve InkDropImpl to be safer about calling back to | 
|  | 38   // potentially destroyed InkDropHosts and remove |destroying_|. | 
|  | 39   destroying_ = true; | 
|  | 40 } | 
| 36 | 41 | 
| 37 void InkDropHostView::AddInkDropLayer(ui::Layer* ink_drop_layer) { | 42 void InkDropHostView::AddInkDropLayer(ui::Layer* ink_drop_layer) { | 
| 38   SetPaintToLayer(true); | 43   SetPaintToLayer(true); | 
| 39   layer()->SetFillsBoundsOpaquely(false); | 44   layer()->SetFillsBoundsOpaquely(false); | 
| 40   layer()->Add(ink_drop_layer); | 45   layer()->Add(ink_drop_layer); | 
| 41   layer()->StackAtBottom(ink_drop_layer); | 46   layer()->StackAtBottom(ink_drop_layer); | 
| 42 } | 47 } | 
| 43 | 48 | 
| 44 void InkDropHostView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { | 49 void InkDropHostView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { | 
|  | 50   // No need to do anything when called during shutdown, and if a derived | 
|  | 51   // class has overridden Add/RemoveInkDropLayer, running this implementation | 
|  | 52   // would be wrong. | 
|  | 53   if (destroying_) | 
|  | 54     return; | 
| 45   layer()->Remove(ink_drop_layer); | 55   layer()->Remove(ink_drop_layer); | 
| 46   SetPaintToLayer(false); | 56   SetPaintToLayer(false); | 
| 47 } | 57 } | 
| 48 | 58 | 
| 49 std::unique_ptr<InkDropRipple> InkDropHostView::CreateInkDropRipple() const { | 59 std::unique_ptr<InkDropRipple> InkDropHostView::CreateInkDropRipple() const { | 
| 50   std::unique_ptr<InkDropRipple> ripple(new SquareInkDropRipple( | 60   std::unique_ptr<InkDropRipple> ripple(new SquareInkDropRipple( | 
| 51       CalculateLargeInkDropSize(ink_drop_size_), kInkDropLargeCornerRadius, | 61       CalculateLargeInkDropSize(ink_drop_size_), kInkDropLargeCornerRadius, | 
| 52       ink_drop_size_, kInkDropSmallCornerRadius, GetInkDropCenter(), | 62       ink_drop_size_, kInkDropSmallCornerRadius, GetInkDropCenter(), | 
| 53       GetInkDropBaseColor())); | 63       GetInkDropBaseColor())); | 
| 54   return ripple; | 64   return ripple; | 
| 55 } | 65 } | 
| 56 | 66 | 
| 57 std::unique_ptr<InkDropHover> InkDropHostView::CreateInkDropHover() const { | 67 std::unique_ptr<InkDropHover> InkDropHostView::CreateInkDropHover() const { | 
| 58   std::unique_ptr<InkDropHover> hover( | 68   std::unique_ptr<InkDropHover> hover( | 
| 59       new InkDropHover(ink_drop_size_, kInkDropSmallCornerRadius, | 69       new InkDropHover(ink_drop_size_, kInkDropSmallCornerRadius, | 
| 60                        GetInkDropCenter(), GetInkDropBaseColor())); | 70                        GetInkDropCenter(), GetInkDropBaseColor())); | 
| 61   hover->set_explode_size(CalculateLargeInkDropSize(ink_drop_size_)); | 71   hover->set_explode_size(CalculateLargeInkDropSize(ink_drop_size_)); | 
| 62   return hover; | 72   return hover; | 
| 63 } | 73 } | 
| 64 | 74 | 
|  | 75 void InkDropHostView::OnFocus() { | 
|  | 76   views::View::OnFocus(); | 
|  | 77   if (ink_drop_delegate() && ShouldShowInkDropForFocus()) | 
|  | 78     ink_drop_delegate()->GetInkDrop()->SetFocused(true); | 
|  | 79 } | 
|  | 80 | 
|  | 81 void InkDropHostView::OnBlur() { | 
|  | 82   views::View::OnBlur(); | 
|  | 83   if (ink_drop_delegate() && ShouldShowInkDropForFocus()) | 
|  | 84     ink_drop_delegate()->GetInkDrop()->SetFocused(false); | 
|  | 85 } | 
|  | 86 | 
| 65 gfx::Point InkDropHostView::GetInkDropCenter() const { | 87 gfx::Point InkDropHostView::GetInkDropCenter() const { | 
| 66   return GetLocalBounds().CenterPoint(); | 88   return GetLocalBounds().CenterPoint(); | 
| 67 } | 89 } | 
| 68 | 90 | 
| 69 SkColor InkDropHostView::GetInkDropBaseColor() const { | 91 SkColor InkDropHostView::GetInkDropBaseColor() const { | 
| 70   NOTREACHED(); | 92   NOTREACHED(); | 
| 71   return gfx::kPlaceholderColor; | 93   return gfx::kPlaceholderColor; | 
| 72 } | 94 } | 
| 73 | 95 | 
|  | 96 bool InkDropHostView::ShouldShowInkDropForFocus() const { | 
|  | 97   return false; | 
|  | 98 } | 
|  | 99 | 
| 74 }  // namespace views | 100 }  // namespace views | 
| OLD | NEW | 
|---|