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

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

Issue 1408223008: [MD] Share button code between find bar and download shelf (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: one more place Created 5 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/bar_control_button.h"
6
7 #include "ui/gfx/color_utils.h"
8 #include "ui/gfx/paint_vector_icon.h"
9 #include "ui/gfx/vector_icons_public.h"
10 #include "ui/views/animation/ink_drop_animation_controller.h"
11 #include "ui/views/animation/ink_drop_animation_controller_factory.h"
12 #include "ui/views/border.h"
13
14 namespace {
15
16 // Extra space around the buttons to increase their event target size.
17 const int kButtonExtraTouchSize = 4;
18
19 } // namespace
20
21 BarControlButton::BarControlButton(views::ButtonListener* listener)
22 : views::ImageButton(listener),
23 id_(gfx::VectorIconId::VECTOR_ICON_NONE),
24 ink_drop_animation_controller_(
25 views::InkDropAnimationControllerFactory::
26 CreateInkDropAnimationController(this)) {
27 const int kInkDropLargeSize = 32;
28 const int kInkDropLargeCornerRadius = 4;
29 const int kInkDropSmallSize = 24;
30 const int kInkDropSmallCornerRadius = 2;
sky 2015/11/03 23:46:43 Are these constants really specific to buttons and
Evan Stade 2015/11/03 23:51:17 I don't know, this code is just moved from FindBar
31 ink_drop_animation_controller_->SetInkDropSize(
32 gfx::Size(kInkDropLargeSize, kInkDropLargeSize),
33 kInkDropLargeCornerRadius,
34 gfx::Size(kInkDropSmallSize, kInkDropSmallSize),
35 kInkDropSmallCornerRadius);
36 }
37
38 BarControlButton::~BarControlButton() {}
39
40 void BarControlButton::SetIcon(
41 gfx::VectorIconId id,
42 const base::Callback<SkColor(void)>& get_text_color_callback) {
43 id_ = id;
44 get_text_color_callback_ = get_text_color_callback;
45
46 SetBorder(views::Border::CreateEmptyBorder(
47 kButtonExtraTouchSize, kButtonExtraTouchSize, kButtonExtraTouchSize,
48 kButtonExtraTouchSize));
49 SetImageAlignment(views::ImageButton::ALIGN_CENTER,
50 views::ImageButton::ALIGN_MIDDLE);
51 }
52
53 void BarControlButton::OnThemeChanged() {
54 SkColor icon_color =
55 color_utils::DeriveDefaultIconColor(get_text_color_callback_.Run());
56 gfx::ImageSkia image = gfx::CreateVectorIcon(id_, 16, icon_color);
57 SetImage(views::CustomButton::STATE_NORMAL, &image);
58 image = gfx::CreateVectorIcon(id_, 16, SkColorSetA(icon_color, 0xff / 2));
sky 2015/11/03 23:46:43 Do we not have 16 defined some where?
Evan Stade 2015/11/03 23:51:17 If we landed https://codereview.chromium.org/14066
59 SetImage(views::CustomButton::STATE_DISABLED, &image);
60 }
61
62 void BarControlButton::OnNativeThemeChanged(const ui::NativeTheme* theme) {
63 OnThemeChanged();
64 }
65
66 void BarControlButton::Layout() {
67 ImageButton::Layout();
68
69 ink_drop_animation_controller_->SetInkDropCenter(
70 GetLocalBounds().CenterPoint());
71 }
72
73 void BarControlButton::AddInkDropLayer(ui::Layer* ink_drop_layer) {
74 SetPaintToLayer(true);
75 SetFillsBoundsOpaquely(false);
76 layer()->Add(ink_drop_layer);
77 layer()->StackAtBottom(ink_drop_layer);
sky 2015/11/03 23:46:43 Is this really necessary?
Evan Stade 2015/11/03 23:51:17 I don't know, this code is just moved from FindBar
78 }
79
80 void BarControlButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) {
sky 2015/11/03 23:46:43 I'm not familiar with the ink drop layer. What is
Evan Stade 2015/11/03 23:51:17 I don't know, this code is just moved from FindBar
81 layer()->Remove(ink_drop_layer);
82 SetFillsBoundsOpaquely(true);
83 SetPaintToLayer(false);
84 }
85
86 bool BarControlButton::OnMousePressed(const ui::MouseEvent& event) {
87 if (IsTriggerableEvent(event)) {
88 ink_drop_animation_controller_->AnimateToState(
89 views::InkDropState::ACTION_PENDING);
90 }
91
92 return ImageButton::OnMousePressed(event);
93 }
94
95 void BarControlButton::OnGestureEvent(ui::GestureEvent* event) {
96 views::InkDropState ink_drop_state = views::InkDropState::HIDDEN;
97 switch (event->type()) {
98 case ui::ET_GESTURE_TAP_DOWN:
99 ink_drop_state = views::InkDropState::ACTION_PENDING;
100 // The ui::ET_GESTURE_TAP_DOWN event needs to be marked as handled so
101 // that subsequent events for the gesture are sent to |this|.
102 event->SetHandled();
103 break;
104 case ui::ET_GESTURE_LONG_PRESS:
105 ink_drop_state = views::InkDropState::SLOW_ACTION_PENDING;
106 break;
107 case ui::ET_GESTURE_TAP:
108 ink_drop_state = views::InkDropState::QUICK_ACTION;
109 break;
110 case ui::ET_GESTURE_LONG_TAP:
111 ink_drop_state = views::InkDropState::SLOW_ACTION;
112 break;
113 case ui::ET_GESTURE_END:
114 case ui::ET_GESTURE_TAP_CANCEL:
115 ink_drop_state = views::InkDropState::HIDDEN;
116 break;
117 default:
118 return;
119 }
120 ink_drop_animation_controller_->AnimateToState(ink_drop_state);
121
122 ImageButton::OnGestureEvent(event);
123 }
124
125 void BarControlButton::OnMouseReleased(const ui::MouseEvent& event) {
126 if (!HitTestPoint(event.location()))
127 ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN);
128
129 ImageButton::OnMouseReleased(event);
130 }
131
132 void BarControlButton::NotifyClick(const ui::Event& event) {
133 ink_drop_animation_controller_->AnimateToState(
134 views::InkDropState::QUICK_ACTION);
135
136 ImageButton::NotifyClick(event);
137 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698