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

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: Removed CustomButton::set_ink_drop_action_on_click() method. 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 set_has_ink_drop_action_on_click(true);
26
27 const int kInkDropLargeSize = 32; 27 const int kInkDropLargeSize = 32;
28 const int kInkDropLargeCornerRadius = 4; 28 const int kInkDropLargeCornerRadius = 4;
29 const int kInkDropSmallSize = 24; 29 const int kInkDropSmallSize = 24;
30 const int kInkDropSmallCornerRadius = 2; 30 const int kInkDropSmallCornerRadius = 2;
31 ink_drop_animation_controller_->SetInkDropSize( 31 ink_drop_delegate()->SetInkDropSize(
32 gfx::Size(kInkDropLargeSize, kInkDropLargeSize), 32 kInkDropLargeSize, kInkDropLargeCornerRadius, kInkDropSmallSize,
33 kInkDropLargeCornerRadius,
34 gfx::Size(kInkDropSmallSize, kInkDropSmallSize),
35 kInkDropSmallCornerRadius); 33 kInkDropSmallCornerRadius);
36 } 34 }
37 35
38 BarControlButton::~BarControlButton() {} 36 BarControlButton::~BarControlButton() {}
39 37
40 void BarControlButton::SetIcon( 38 void BarControlButton::SetIcon(
41 gfx::VectorIconId id, 39 gfx::VectorIconId id,
42 const base::Callback<SkColor(void)>& get_text_color_callback) { 40 const base::Callback<SkColor(void)>& get_text_color_callback) {
43 id_ = id; 41 id_ = id;
44 get_text_color_callback_ = get_text_color_callback; 42 get_text_color_callback_ = get_text_color_callback;
(...skipping 11 matching lines...) Expand all
56 gfx::ImageSkia image = gfx::CreateVectorIcon(id_, 16, icon_color); 54 gfx::ImageSkia image = gfx::CreateVectorIcon(id_, 16, icon_color);
57 SetImage(views::CustomButton::STATE_NORMAL, &image); 55 SetImage(views::CustomButton::STATE_NORMAL, &image);
58 image = gfx::CreateVectorIcon(id_, 16, SkColorSetA(icon_color, 0xff / 2)); 56 image = gfx::CreateVectorIcon(id_, 16, SkColorSetA(icon_color, 0xff / 2));
59 SetImage(views::CustomButton::STATE_DISABLED, &image); 57 SetImage(views::CustomButton::STATE_DISABLED, &image);
60 } 58 }
61 59
62 void BarControlButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { 60 void BarControlButton::OnNativeThemeChanged(const ui::NativeTheme* theme) {
63 OnThemeChanged(); 61 OnThemeChanged();
64 } 62 }
65 63
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) { 64 void BarControlButton::AddInkDropLayer(ui::Layer* ink_drop_layer) {
73 // TODO(estade|tdanderson): The ink drop layer should be positioned behind 65 // TODO(estade|tdanderson): The ink drop layer should be positioned behind
74 // the button's image. 66 // the button's image.
75 SetPaintToLayer(true); 67 SetPaintToLayer(true);
76 SetFillsBoundsOpaquely(false); 68 SetFillsBoundsOpaquely(false);
77 layer()->Add(ink_drop_layer); 69 layer()->Add(ink_drop_layer);
78 layer()->StackAtBottom(ink_drop_layer); 70 layer()->StackAtBottom(ink_drop_layer);
79 } 71 }
80 72
81 void BarControlButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { 73 void BarControlButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) {
82 layer()->Remove(ink_drop_layer); 74 layer()->Remove(ink_drop_layer);
83 SetFillsBoundsOpaquely(true); 75 SetFillsBoundsOpaquely(true);
84 SetPaintToLayer(false); 76 SetPaintToLayer(false);
85 } 77 }
86 78
87 gfx::Point BarControlButton::CalculateInkDropCenter() const { 79 gfx::Point BarControlButton::CalculateInkDropCenter() const {
88 return GetLocalBounds().CenterPoint(); 80 return GetLocalBounds().CenterPoint();
89 } 81 }
90 82
91 bool BarControlButton::OnMousePressed(const ui::MouseEvent& event) { 83 bool BarControlButton::OnMousePressed(const ui::MouseEvent& event) {
92 if (IsTriggerableEvent(event)) { 84 if (IsTriggerableEvent(event))
93 ink_drop_animation_controller_->AnimateToState( 85 ink_drop_delegate()->OnAction(views::InkDropState::ACTION_PENDING);
94 views::InkDropState::ACTION_PENDING);
95 }
96 86
97 return ImageButton::OnMousePressed(event); 87 return ImageButton::OnMousePressed(event);
98 } 88 }
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
« no previous file with comments | « chrome/browser/ui/views/bar_control_button.h ('k') | chrome/browser/ui/views/dropdown_bar_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698