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

Side by Side Diff: chrome/browser/ui/views/location_bar/bubble_icon_view.cc

Issue 1518543002: Adds MD ink ripple animations to buttons within location bar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adds MD ink ripple animations to buttons within location bar (split gesture support into a separate… 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/location_bar/bubble_icon_view.h" 5 #include "chrome/browser/ui/views/location_bar/bubble_icon_view.h"
6 6
7 #include "chrome/browser/command_updater.h" 7 #include "chrome/browser/command_updater.h"
8 #include "ui/accessibility/ax_view_state.h" 8 #include "ui/accessibility/ax_view_state.h"
9 #include "ui/base/resource/material_design/material_design_controller.h" 9 #include "ui/base/resource/material_design/material_design_controller.h"
10 #include "ui/events/event.h" 10 #include "ui/events/event.h"
11 #include "ui/gfx/color_palette.h" 11 #include "ui/gfx/color_palette.h"
12 #include "ui/gfx/color_utils.h" 12 #include "ui/gfx/color_utils.h"
13 #include "ui/gfx/paint_vector_icon.h" 13 #include "ui/gfx/paint_vector_icon.h"
14 #include "ui/native_theme/native_theme.h" 14 #include "ui/native_theme/native_theme.h"
15 #include "ui/views/animation/button_ink_drop_delegate.h"
15 #include "ui/views/bubble/bubble_delegate.h" 16 #include "ui/views/bubble/bubble_delegate.h"
16 17
17 BubbleIconView::BubbleIconView(CommandUpdater* command_updater, int command_id) 18 BubbleIconView::BubbleIconView(CommandUpdater* command_updater, int command_id)
18 : command_updater_(command_updater), 19 : command_updater_(command_updater),
19 command_id_(command_id), 20 command_id_(command_id),
20 active_(false), 21 active_(false),
21 suppress_mouse_released_action_(false) { 22 suppress_mouse_released_action_(false),
23 ink_drop_delegate_(new views::ButtonInkDropDelegate(this, this)) {
22 SetAccessibilityFocusable(true); 24 SetAccessibilityFocusable(true);
25
26 const int kInkDropLargeSize = 32;
27 const int kInkDropLargeCornerRadius = 5;
28 const int kInkDropSmallSize = 24;
29 const int kInkDropSmallCornerRadius = 2;
30 ink_drop_delegate_->SetInkDropSize(
31 kInkDropLargeSize, kInkDropLargeCornerRadius, kInkDropSmallSize,
32 kInkDropSmallCornerRadius);
23 } 33 }
24 34
25 BubbleIconView::~BubbleIconView() { 35 BubbleIconView::~BubbleIconView() {
26 } 36 }
27 37
28 bool BubbleIconView::IsBubbleShowing() const { 38 bool BubbleIconView::IsBubbleShowing() const {
29 // If the bubble is being destroyed, it's considered showing though it may be 39 // If the bubble is being destroyed, it's considered showing though it may be
30 // already invisible currently. 40 // already invisible currently.
31 return GetBubble() != NULL; 41 return GetBubble() != NULL;
32 } 42 }
33 43
34 void BubbleIconView::GetAccessibleState(ui::AXViewState* state) { 44 void BubbleIconView::GetAccessibleState(ui::AXViewState* state) {
35 views::ImageView::GetAccessibleState(state); 45 views::ImageView::GetAccessibleState(state);
36 state->role = ui::AX_ROLE_BUTTON; 46 state->role = ui::AX_ROLE_BUTTON;
37 } 47 }
38 48
39 bool BubbleIconView::GetTooltipText(const gfx::Point& p, 49 bool BubbleIconView::GetTooltipText(const gfx::Point& p,
40 base::string16* tooltip) const { 50 base::string16* tooltip) const {
41 if (IsBubbleShowing()) 51 if (IsBubbleShowing())
42 return false; 52 return false;
43 53
44 return views::ImageView::GetTooltipText(p, tooltip); 54 return views::ImageView::GetTooltipText(p, tooltip);
45 } 55 }
46 56
57 void BubbleIconView::Layout() {
58 ImageView::Layout();
59 if (ink_drop_delegate_)
60 ink_drop_delegate_->OnLayout();
61 }
62
47 bool BubbleIconView::OnMousePressed(const ui::MouseEvent& event) { 63 bool BubbleIconView::OnMousePressed(const ui::MouseEvent& event) {
48 // If the bubble is showing then don't reshow it when the mouse is released. 64 // If the bubble is showing then don't reshow it when the mouse is released.
49 suppress_mouse_released_action_ = IsBubbleShowing(); 65 suppress_mouse_released_action_ = IsBubbleShowing();
66 if (!suppress_mouse_released_action_ && event.IsOnlyLeftMouseButton())
67 ink_drop_delegate_->OnAction(views::InkDropState::ACTION_PENDING);
50 68
51 // We want to show the bubble on mouse release; that is the standard behavior 69 // We want to show the bubble on mouse release; that is the standard behavior
52 // for buttons. 70 // for buttons.
53 return true; 71 return true;
54 } 72 }
55 73
56 void BubbleIconView::OnMouseReleased(const ui::MouseEvent& event) { 74 void BubbleIconView::OnMouseReleased(const ui::MouseEvent& event) {
57 // If this is the second click on this view then the bubble was showing on the 75 // If this is the second click on this view then the bubble was showing on the
58 // mouse pressed event and is hidden now. Prevent the bubble from reshowing by 76 // mouse pressed event and is hidden now. Prevent the bubble from reshowing by
59 // doing nothing here. 77 // doing nothing here.
60 if (suppress_mouse_released_action_) { 78 if (suppress_mouse_released_action_) {
61 suppress_mouse_released_action_ = false; 79 suppress_mouse_released_action_ = false;
62 return; 80 return;
63 } 81 }
64 82
65 if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) 83 if (event.IsLeftMouseButton()) {
66 ExecuteCommand(EXECUTE_SOURCE_MOUSE); 84 if (HitTestPoint(event.location())) {
85 ink_drop_delegate_->OnAction(views::InkDropState::ACTIVATED);
86 ExecuteCommand(EXECUTE_SOURCE_MOUSE);
87 } else {
88 ink_drop_delegate_->OnAction(views::InkDropState::HIDDEN);
89 }
90 }
67 } 91 }
68 92
69 bool BubbleIconView::OnKeyPressed(const ui::KeyEvent& event) { 93 bool BubbleIconView::OnKeyPressed(const ui::KeyEvent& event) {
70 if (event.key_code() == ui::VKEY_SPACE || 94 if (event.key_code() == ui::VKEY_SPACE ||
71 event.key_code() == ui::VKEY_RETURN) { 95 event.key_code() == ui::VKEY_RETURN) {
72 ExecuteCommand(EXECUTE_SOURCE_KEYBOARD); 96 ExecuteCommand(EXECUTE_SOURCE_KEYBOARD);
73 return true; 97 return true;
74 } 98 }
75 return false; 99 return false;
76 } 100 }
77 101
102 void BubbleIconView::OnBubbleClosing() {
103 ink_drop_delegate_->OnAction(views::InkDropState::DEACTIVATED);
104 }
105
78 void BubbleIconView::ViewHierarchyChanged( 106 void BubbleIconView::ViewHierarchyChanged(
79 const ViewHierarchyChangedDetails& details) { 107 const ViewHierarchyChangedDetails& details) {
80 ImageView::ViewHierarchyChanged(details); 108 ImageView::ViewHierarchyChanged(details);
81 if (details.is_add && GetNativeTheme()) 109 if (details.is_add && GetNativeTheme())
82 UpdateIcon(); 110 UpdateIcon();
83 } 111 }
84 112
85 void BubbleIconView::OnNativeThemeChanged(const ui::NativeTheme* theme) { 113 void BubbleIconView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
86 UpdateIcon(); 114 UpdateIcon();
87 } 115 }
88 116
89 void BubbleIconView::OnGestureEvent(ui::GestureEvent* event) { 117 void BubbleIconView::OnGestureEvent(ui::GestureEvent* event) {
90 if (event->type() == ui::ET_GESTURE_TAP) { 118 if (event->type() == ui::ET_GESTURE_TAP) {
119 ink_drop_delegate_->OnAction(views::InkDropState::ACTIVATED);
91 ExecuteCommand(EXECUTE_SOURCE_GESTURE); 120 ExecuteCommand(EXECUTE_SOURCE_GESTURE);
92 event->SetHandled(); 121 event->SetHandled();
93 } 122 }
94 } 123 }
95 124
125 void BubbleIconView::AddInkDropLayer(ui::Layer* ink_drop_layer) {
126 SetPaintToLayer(true);
bruthig 2015/12/11 17:43:38 Does this configuration actually paint the ripple
varkha 2016/01/26 01:19:18 I have changed BubbleIconView to have ImageView as
127 SetFillsBoundsOpaquely(false);
128 SetPaintToLayer(true);
129 SetFillsBoundsOpaquely(false);
130
131 layer()->Add(ink_drop_layer);
132 layer()->StackAtBottom(ink_drop_layer);
133 }
134
135 void BubbleIconView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) {
136 layer()->Remove(ink_drop_layer);
137
138 SetFillsBoundsOpaquely(true);
139 SetPaintToLayer(false);
140 SetPaintToLayer(false);
141 }
142
96 void BubbleIconView::ExecuteCommand(ExecuteSource source) { 143 void BubbleIconView::ExecuteCommand(ExecuteSource source) {
97 OnExecuting(source); 144 OnExecuting(source);
98 if (command_updater_) 145 if (command_updater_)
99 command_updater_->ExecuteCommand(command_id_); 146 command_updater_->ExecuteCommand(command_id_);
100 } 147 }
101 148
102 bool BubbleIconView::SetRasterIcon() { 149 bool BubbleIconView::SetRasterIcon() {
103 return false; 150 return false;
104 } 151 }
105 152
106 void BubbleIconView::OnBoundsChanged(const gfx::Rect& previous_bounds) { 153 void BubbleIconView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
107 views::BubbleDelegateView* bubble = GetBubble(); 154 views::BubbleDelegateView* bubble = GetBubble();
108 if (bubble) 155 if (bubble)
109 bubble->OnAnchorBoundsChanged(); 156 bubble->OnAnchorBoundsChanged();
110 } 157 }
111 158
159 gfx::Point BubbleIconView::CalculateInkDropCenter() const {
160 return GetLocalBounds().CenterPoint();
161 }
162
112 void BubbleIconView::UpdateIcon() { 163 void BubbleIconView::UpdateIcon() {
113 if (SetRasterIcon()) 164 if (SetRasterIcon())
114 return; 165 return;
115 166
116 const int icon_size = 167 const int icon_size =
117 ui::MaterialDesignController::IsModeMaterial() ? 16 : 18; 168 ui::MaterialDesignController::IsModeMaterial() ? 16 : 18;
118 const ui::NativeTheme* theme = GetNativeTheme(); 169 const ui::NativeTheme* theme = GetNativeTheme();
119 SkColor icon_color = 170 SkColor icon_color =
120 active_ 171 active_
121 ? theme->GetSystemColor(ui::NativeTheme::kColorId_CallToActionColor) 172 ? theme->GetSystemColor(ui::NativeTheme::kColorId_CallToActionColor)
122 : color_utils::DeriveDefaultIconColor(theme->GetSystemColor( 173 : color_utils::DeriveDefaultIconColor(theme->GetSystemColor(
123 ui::NativeTheme::kColorId_TextfieldDefaultColor)); 174 ui::NativeTheme::kColorId_TextfieldDefaultColor));
124 SetImage(gfx::CreateVectorIcon(GetVectorIcon(), icon_size, icon_color)); 175 SetImage(gfx::CreateVectorIcon(GetVectorIcon(), icon_size, icon_color));
125 } 176 }
126 177
127 void BubbleIconView::SetActiveInternal(bool active) { 178 void BubbleIconView::SetActiveInternal(bool active) {
128 if (active_ == active) 179 if (active_ == active)
129 return; 180 return;
130 active_ = active; 181 active_ = active;
131 UpdateIcon(); 182 UpdateIcon();
132 } 183 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/bubble_icon_view.h ('k') | ui/views/bubble/bubble_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698