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

Side by Side Diff: chrome/browser/ui/views/bar_control_button.cc

Issue 1478303003: Converted all Views to use an InkDropDelegate instead of a InkDropAnimationController. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merged with master / https://codereview.chromium.org/1494433003. Created 5 years 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 2015 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/ui/views/bar_control_button.h" 5 #include "chrome/browser/ui/views/bar_control_button.h"
6 6
7 #include "ui/gfx/color_utils.h" 7 #include "ui/gfx/color_utils.h"
8 #include "ui/gfx/paint_vector_icon.h" 8 #include "ui/gfx/paint_vector_icon.h"
9 #include "ui/gfx/vector_icons_public.h" 9 #include "ui/gfx/vector_icons_public.h"
10 #include "ui/views/animation/ink_drop_animation_controller.h" 10 #include "ui/views/animation/button_ink_drop_delegate.h"
11 #include "ui/views/animation/ink_drop_animation_controller_factory.h"
12 #include "ui/views/border.h" 11 #include "ui/views/border.h"
13 12
14 namespace { 13 namespace {
15 14
16 // Extra space around the buttons to increase their event target size. 15 // Extra space around the buttons to increase their event target size.
17 const int kButtonExtraTouchSize = 4; 16 const int kButtonExtraTouchSize = 4;
18 17
19 } // namespace 18 } // namespace
20 19
21 BarControlButton::BarControlButton(views::ButtonListener* listener) 20 BarControlButton::BarControlButton(views::ButtonListener* listener)
22 : views::ImageButton(listener), 21 : views::ImageButton(listener),
23 id_(gfx::VectorIconId::VECTOR_ICON_NONE), 22 id_(gfx::VectorIconId::VECTOR_ICON_NONE),
24 ink_drop_animation_controller_( 23 ink_drop_delegate_(new views::ButtonInkDropDelegate(this, this)) {
25 views::InkDropAnimationControllerFactory:: 24 set_ink_drop_delegate(ink_drop_delegate_.get());
26 CreateInkDropAnimationController(this)) { 25
27 const int kInkDropLargeSize = 32; 26 const int kInkDropLargeSize = 32;
28 const int kInkDropLargeCornerRadius = 4; 27 const int kInkDropLargeCornerRadius = 4;
29 const int kInkDropSmallSize = 24; 28 const int kInkDropSmallSize = 24;
30 const int kInkDropSmallCornerRadius = 2; 29 const int kInkDropSmallCornerRadius = 2;
31 ink_drop_animation_controller_->SetInkDropSize( 30 ink_drop_delegate()->SetInkDropSize(
32 gfx::Size(kInkDropLargeSize, kInkDropLargeSize), 31 kInkDropLargeSize, kInkDropLargeCornerRadius, kInkDropSmallSize,
33 kInkDropLargeCornerRadius,
34 gfx::Size(kInkDropSmallSize, kInkDropSmallSize),
35 kInkDropSmallCornerRadius); 32 kInkDropSmallCornerRadius);
36 } 33 }
37 34
38 BarControlButton::~BarControlButton() {} 35 BarControlButton::~BarControlButton() {
36 set_ink_drop_delegate(nullptr);
37 ink_drop_delegate_.reset();
38 }
39 39
40 void BarControlButton::SetIcon( 40 void BarControlButton::SetIcon(
41 gfx::VectorIconId id, 41 gfx::VectorIconId id,
42 const base::Callback<SkColor(void)>& get_text_color_callback) { 42 const base::Callback<SkColor(void)>& get_text_color_callback) {
43 id_ = id; 43 id_ = id;
44 get_text_color_callback_ = get_text_color_callback; 44 get_text_color_callback_ = get_text_color_callback;
45 45
46 SetBorder(views::Border::CreateEmptyBorder( 46 SetBorder(views::Border::CreateEmptyBorder(
47 kButtonExtraTouchSize, kButtonExtraTouchSize, kButtonExtraTouchSize, 47 kButtonExtraTouchSize, kButtonExtraTouchSize, kButtonExtraTouchSize,
48 kButtonExtraTouchSize)); 48 kButtonExtraTouchSize));
49 SetImageAlignment(views::ImageButton::ALIGN_CENTER, 49 SetImageAlignment(views::ImageButton::ALIGN_CENTER,
50 views::ImageButton::ALIGN_MIDDLE); 50 views::ImageButton::ALIGN_MIDDLE);
51 } 51 }
52 52
53 void BarControlButton::OnThemeChanged() { 53 void BarControlButton::OnThemeChanged() {
54 SkColor icon_color = 54 SkColor icon_color =
55 color_utils::DeriveDefaultIconColor(get_text_color_callback_.Run()); 55 color_utils::DeriveDefaultIconColor(get_text_color_callback_.Run());
56 gfx::ImageSkia image = gfx::CreateVectorIcon(id_, 16, icon_color); 56 gfx::ImageSkia image = gfx::CreateVectorIcon(id_, 16, icon_color);
57 SetImage(views::CustomButton::STATE_NORMAL, &image); 57 SetImage(views::CustomButton::STATE_NORMAL, &image);
58 image = gfx::CreateVectorIcon(id_, 16, SkColorSetA(icon_color, 0xff / 2)); 58 image = gfx::CreateVectorIcon(id_, 16, SkColorSetA(icon_color, 0xff / 2));
59 SetImage(views::CustomButton::STATE_DISABLED, &image); 59 SetImage(views::CustomButton::STATE_DISABLED, &image);
60 } 60 }
61 61
62 void BarControlButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { 62 void BarControlButton::OnNativeThemeChanged(const ui::NativeTheme* theme) {
63 OnThemeChanged(); 63 OnThemeChanged();
64 } 64 }
65 65
66 void BarControlButton::Layout() {
67 ImageButton::Layout();
68
69 ink_drop_animation_controller_->SetInkDropCenter(CalculateInkDropCenter());
70 }
71
72 void BarControlButton::AddInkDropLayer(ui::Layer* ink_drop_layer) { 66 void BarControlButton::AddInkDropLayer(ui::Layer* ink_drop_layer) {
73 // TODO(estade|tdanderson): The ink drop layer should be positioned behind 67 // TODO(estade|tdanderson): The ink drop layer should be positioned behind
74 // the button's image. 68 // the button's image.
75 SetPaintToLayer(true); 69 SetPaintToLayer(true);
76 SetFillsBoundsOpaquely(false); 70 SetFillsBoundsOpaquely(false);
77 layer()->Add(ink_drop_layer); 71 layer()->Add(ink_drop_layer);
78 layer()->StackAtBottom(ink_drop_layer); 72 layer()->StackAtBottom(ink_drop_layer);
79 } 73 }
80 74
81 void BarControlButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { 75 void BarControlButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) {
82 layer()->Remove(ink_drop_layer); 76 layer()->Remove(ink_drop_layer);
83 SetFillsBoundsOpaquely(true); 77 SetFillsBoundsOpaquely(true);
84 SetPaintToLayer(false); 78 SetPaintToLayer(false);
85 } 79 }
86 80
87 gfx::Point BarControlButton::CalculateInkDropCenter() const { 81 gfx::Point BarControlButton::CalculateInkDropCenter() const {
88 return GetLocalBounds().CenterPoint(); 82 return GetLocalBounds().CenterPoint();
89 } 83 }
90 84
91 bool BarControlButton::OnMousePressed(const ui::MouseEvent& event) { 85 bool BarControlButton::OnMousePressed(const ui::MouseEvent& event) {
92 if (IsTriggerableEvent(event)) { 86 if (IsTriggerableEvent(event))
93 ink_drop_animation_controller_->AnimateToState( 87 ink_drop_delegate()->OnAction(views::InkDropState::ACTION_PENDING);
94 views::InkDropState::ACTION_PENDING);
95 }
96 88
97 return ImageButton::OnMousePressed(event); 89 return ImageButton::OnMousePressed(event);
98 } 90 }
99
100 void BarControlButton::OnGestureEvent(ui::GestureEvent* event) {
101 views::InkDropState ink_drop_state = views::InkDropState::HIDDEN;
102 switch (event->type()) {
103 case ui::ET_GESTURE_TAP_DOWN:
104 ink_drop_state = views::InkDropState::ACTION_PENDING;
105 // The ui::ET_GESTURE_TAP_DOWN event needs to be marked as handled so
106 // that subsequent events for the gesture are sent to |this|.
107 event->SetHandled();
108 break;
109 case ui::ET_GESTURE_LONG_PRESS:
110 ink_drop_state = views::InkDropState::SLOW_ACTION_PENDING;
111 break;
112 case ui::ET_GESTURE_TAP:
113 ink_drop_state = views::InkDropState::QUICK_ACTION;
114 break;
115 case ui::ET_GESTURE_LONG_TAP:
116 ink_drop_state = views::InkDropState::SLOW_ACTION;
117 break;
118 case ui::ET_GESTURE_END:
119 case ui::ET_GESTURE_TAP_CANCEL:
120 ink_drop_state = views::InkDropState::HIDDEN;
121 break;
122 default:
123 return;
124 }
125 ink_drop_animation_controller_->AnimateToState(ink_drop_state);
126
127 ImageButton::OnGestureEvent(event);
128 }
129
130 void BarControlButton::OnMouseReleased(const ui::MouseEvent& event) {
131 if (!HitTestPoint(event.location()))
132 ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN);
133
134 ImageButton::OnMouseReleased(event);
135 }
136
137 void BarControlButton::NotifyClick(const ui::Event& event) {
138 ink_drop_animation_controller_->AnimateToState(
139 views::InkDropState::QUICK_ACTION);
140
141 ImageButton::NotifyClick(event);
142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698