Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: ui/views/animation/ink_drop_host_view.cc

Issue 2001843002: Use ink drop hover for focus states on toolbar buttons and location (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: format Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 destroying_ = true;
38 }
36 39
37 void InkDropHostView::AddInkDropLayer(ui::Layer* ink_drop_layer) { 40 void InkDropHostView::AddInkDropLayer(ui::Layer* ink_drop_layer) {
38 SetPaintToLayer(true); 41 SetPaintToLayer(true);
39 layer()->SetFillsBoundsOpaquely(false); 42 layer()->SetFillsBoundsOpaquely(false);
40 layer()->Add(ink_drop_layer); 43 layer()->Add(ink_drop_layer);
41 layer()->StackAtBottom(ink_drop_layer); 44 layer()->StackAtBottom(ink_drop_layer);
42 } 45 }
43 46
44 void InkDropHostView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { 47 void InkDropHostView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) {
48 // No need to do anything when called during shutdown, and if a derived
bruthig 2016/05/26 00:40:52 Can add the following TODO here? TODO(bruthig): F
Evan Stade 2016/05/26 18:45:01 Done.
49 // class has overridden Add/RemoveInkDropLayer, running this implementation
50 // would be wrong.
51 if (destroying_)
52 return;
45 layer()->Remove(ink_drop_layer); 53 layer()->Remove(ink_drop_layer);
46 SetPaintToLayer(false); 54 SetPaintToLayer(false);
47 } 55 }
48 56
49 std::unique_ptr<InkDropRipple> InkDropHostView::CreateInkDropRipple() const { 57 std::unique_ptr<InkDropRipple> InkDropHostView::CreateInkDropRipple() const {
50 std::unique_ptr<InkDropRipple> ripple(new SquareInkDropRipple( 58 std::unique_ptr<InkDropRipple> ripple(new SquareInkDropRipple(
51 CalculateLargeInkDropSize(ink_drop_size_), kInkDropLargeCornerRadius, 59 CalculateLargeInkDropSize(ink_drop_size_), kInkDropLargeCornerRadius,
52 ink_drop_size_, kInkDropSmallCornerRadius, GetInkDropCenter(), 60 ink_drop_size_, kInkDropSmallCornerRadius, GetInkDropCenter(),
53 GetInkDropBaseColor())); 61 GetInkDropBaseColor()));
54 return ripple; 62 return ripple;
55 } 63 }
56 64
57 std::unique_ptr<InkDropHover> InkDropHostView::CreateInkDropHover() const { 65 std::unique_ptr<InkDropHover> InkDropHostView::CreateInkDropHover() const {
58 std::unique_ptr<InkDropHover> hover( 66 std::unique_ptr<InkDropHover> hover(
59 new InkDropHover(ink_drop_size_, kInkDropSmallCornerRadius, 67 new InkDropHover(ink_drop_size_, kInkDropSmallCornerRadius,
60 GetInkDropCenter(), GetInkDropBaseColor())); 68 GetInkDropCenter(), GetInkDropBaseColor()));
61 hover->set_explode_size(CalculateLargeInkDropSize(ink_drop_size_)); 69 hover->set_explode_size(CalculateLargeInkDropSize(ink_drop_size_));
62 return hover; 70 return hover;
63 } 71 }
64 72
73 void InkDropHostView::OnFocus() {
74 views::View::OnFocus();
75 if (ink_drop_delegate() && ShouldShowInkDropForFocus())
76 ink_drop_delegate()->GetInkDrop()->SetFocused(true);
77 }
78
79 void InkDropHostView::OnBlur() {
80 views::View::OnBlur();
81 if (ink_drop_delegate() && ShouldShowInkDropForFocus())
82 ink_drop_delegate()->GetInkDrop()->SetFocused(false);
83 }
84
65 gfx::Point InkDropHostView::GetInkDropCenter() const { 85 gfx::Point InkDropHostView::GetInkDropCenter() const {
66 return GetLocalBounds().CenterPoint(); 86 return GetLocalBounds().CenterPoint();
67 } 87 }
68 88
69 SkColor InkDropHostView::GetInkDropBaseColor() const { 89 SkColor InkDropHostView::GetInkDropBaseColor() const {
70 NOTREACHED(); 90 NOTREACHED();
71 return gfx::kPlaceholderColor; 91 return gfx::kPlaceholderColor;
72 } 92 }
73 93
94 bool InkDropHostView::ShouldShowInkDropForFocus() const {
95 return false;
96 }
97
74 } // namespace views 98 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698