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

Side by Side Diff: ash/shelf/app_list_button.cc

Issue 2070143003: Add MD ink drop ripple to app list button (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@b612539_shelf_button_ripple
Patch Set: Updated tests Created 4 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ash/shelf/app_list_button.h" 5 #include "ash/shelf/app_list_button.h"
6 6
7 #include "ash/common/ash_constants.h" 7 #include "ash/common/ash_constants.h"
8 #include "ash/common/material_design/material_design_controller.h" 8 #include "ash/common/material_design/material_design_controller.h"
9 #include "ash/common/shelf/shelf_constants.h" 9 #include "ash/common/shelf/shelf_constants.h"
10 #include "ash/common/shelf/shelf_item_types.h" 10 #include "ash/common/shelf/shelf_item_types.h"
11 #include "ash/common/shelf/shelf_types.h" 11 #include "ash/common/shelf/shelf_types.h"
12 #include "ash/common/shelf/wm_shelf_util.h" 12 #include "ash/common/shelf/wm_shelf_util.h"
13 #include "ash/shelf/ink_drop_button_listener.h" 13 #include "ash/shelf/ink_drop_button_listener.h"
14 #include "ash/shelf/shelf_layout_manager.h" 14 #include "ash/shelf/shelf_layout_manager.h"
15 #include "ash/shelf/shelf_view.h" 15 #include "ash/shelf/shelf_view.h"
16 #include "ash/shelf/shelf_widget.h" 16 #include "ash/shelf/shelf_widget.h"
17 #include "ash/shell.h" 17 #include "ash/shell.h"
18 #include "base/command_line.h" 18 #include "base/command_line.h"
19 #include "grit/ash_resources.h" 19 #include "grit/ash_resources.h"
20 #include "grit/ash_strings.h" 20 #include "grit/ash_strings.h"
21 #include "ui/accessibility/ax_view_state.h" 21 #include "ui/accessibility/ax_view_state.h"
22 #include "ui/app_list/app_list_switches.h" 22 #include "ui/app_list/app_list_switches.h"
23 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/base/ui_base_switches_util.h" 25 #include "ui/base/ui_base_switches_util.h"
26 #include "ui/gfx/canvas.h" 26 #include "ui/gfx/canvas.h"
27 #include "ui/gfx/paint_vector_icon.h" 27 #include "ui/gfx/paint_vector_icon.h"
28 #include "ui/gfx/vector_icons_public.h" 28 #include "ui/gfx/vector_icons_public.h"
29 #include "ui/views/animation/square_ink_drop_ripple.h"
29 #include "ui/views/painter.h" 30 #include "ui/views/painter.h"
30 31
31 namespace ash { 32 namespace ash {
32 33
33 // Radius of the app list button circular background. 34 // Radius of the app list button circular background.
34 const int kAppListButtonBackgroundRadius = 16; 35 const int kAppListButtonBackgroundRadius = 16;
35 36
36 AppListButton::AppListButton(InkDropButtonListener* listener, 37 AppListButton::AppListButton(InkDropButtonListener* listener,
37 ShelfView* shelf_view) 38 ShelfView* shelf_view)
38 : views::ImageButton(nullptr), 39 : views::ImageButton(nullptr),
39 draw_background_as_active_(false), 40 draw_background_as_active_(false),
40 listener_(listener), 41 listener_(listener),
41 shelf_view_(shelf_view) { 42 shelf_view_(shelf_view) {
43 if (ash::MaterialDesignController::IsShelfMaterial()) {
44 SetHasInkDrop(true, false);
45 set_ink_drop_base_color(kShelfInkDropBaseColor);
46 }
42 SetAccessibleName( 47 SetAccessibleName(
43 app_list::switches::IsExperimentalAppListEnabled() 48 app_list::switches::IsExperimentalAppListEnabled()
44 ? l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE) 49 ? l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE)
45 : l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE)); 50 : l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE));
46 SetSize( 51 SetSize(
47 gfx::Size(GetShelfConstant(SHELF_SIZE), GetShelfConstant(SHELF_SIZE))); 52 gfx::Size(GetShelfConstant(SHELF_SIZE), GetShelfConstant(SHELF_SIZE)));
48 SetFocusPainter(views::Painter::CreateSolidFocusPainter( 53 SetFocusPainter(views::Painter::CreateSolidFocusPainter(
49 kFocusBorderColor, gfx::Insets(1, 1, 1, 1))); 54 kFocusBorderColor, gfx::Insets(1, 1, 1, 1)));
50 set_notify_action(CustomButton::NOTIFY_ON_PRESS); 55 set_notify_action(CustomButton::NOTIFY_ON_PRESS);
51 } 56 }
52 57
53 AppListButton::~AppListButton() {} 58 AppListButton::~AppListButton() {}
54 59
60 void AppListButton::OnAppListShown() {
61 AnimateInkDrop(views::InkDropState::ACTIVATED);
62 }
63
64 void AppListButton::OnAppListDismissed() {
65 AnimateInkDrop(views::InkDropState::DEACTIVATED);
66 }
67
55 bool AppListButton::OnMousePressed(const ui::MouseEvent& event) { 68 bool AppListButton::OnMousePressed(const ui::MouseEvent& event) {
56 ImageButton::OnMousePressed(event); 69 ImageButton::OnMousePressed(event);
57 shelf_view_->PointerPressedOnButton(this, ShelfView::MOUSE, event); 70 shelf_view_->PointerPressedOnButton(this, ShelfView::MOUSE, event);
58 return true; 71 return true;
59 } 72 }
60 73
61 void AppListButton::OnMouseReleased(const ui::MouseEvent& event) { 74 void AppListButton::OnMouseReleased(const ui::MouseEvent& event) {
62 ImageButton::OnMouseReleased(event); 75 ImageButton::OnMouseReleased(event);
63 shelf_view_->PointerReleasedOnButton(this, ShelfView::MOUSE, false); 76 shelf_view_->PointerReleasedOnButton(this, ShelfView::MOUSE, false);
64 } 77 }
65 78
66 void AppListButton::OnMouseCaptureLost() { 79 void AppListButton::OnMouseCaptureLost() {
67 shelf_view_->PointerReleasedOnButton(this, ShelfView::MOUSE, true); 80 shelf_view_->PointerReleasedOnButton(this, ShelfView::MOUSE, true);
68 ImageButton::OnMouseCaptureLost(); 81 ImageButton::OnMouseCaptureLost();
69 } 82 }
70 83
71 bool AppListButton::OnMouseDragged(const ui::MouseEvent& event) { 84 bool AppListButton::OnMouseDragged(const ui::MouseEvent& event) {
72 ImageButton::OnMouseDragged(event); 85 ImageButton::OnMouseDragged(event);
73 shelf_view_->PointerDraggedOnButton(this, ShelfView::MOUSE, event); 86 shelf_view_->PointerDraggedOnButton(this, ShelfView::MOUSE, event);
74 return true; 87 return true;
75 } 88 }
76 89
77 void AppListButton::OnGestureEvent(ui::GestureEvent* event) { 90 void AppListButton::OnGestureEvent(ui::GestureEvent* event) {
91 const bool is_material = ash::MaterialDesignController::IsShelfMaterial();
92 const bool touch_feedback =
93 !is_material && switches::IsTouchFeedbackEnabled();
78 switch (event->type()) { 94 switch (event->type()) {
79 case ui::ET_GESTURE_SCROLL_BEGIN: 95 case ui::ET_GESTURE_SCROLL_BEGIN:
80 if (switches::IsTouchFeedbackEnabled()) 96 if (touch_feedback)
81 SetDrawBackgroundAsActive(false); 97 SetDrawBackgroundAsActive(false);
98 else if (is_material)
99 AnimateInkDrop(views::InkDropState::HIDDEN);
82 shelf_view_->PointerPressedOnButton(this, ShelfView::TOUCH, *event); 100 shelf_view_->PointerPressedOnButton(this, ShelfView::TOUCH, *event);
83 event->SetHandled(); 101 event->SetHandled();
84 return; 102 return;
85 case ui::ET_GESTURE_SCROLL_UPDATE: 103 case ui::ET_GESTURE_SCROLL_UPDATE:
86 shelf_view_->PointerDraggedOnButton(this, ShelfView::TOUCH, *event); 104 shelf_view_->PointerDraggedOnButton(this, ShelfView::TOUCH, *event);
87 event->SetHandled(); 105 event->SetHandled();
88 return; 106 return;
89 case ui::ET_GESTURE_SCROLL_END: 107 case ui::ET_GESTURE_SCROLL_END:
90 case ui::ET_SCROLL_FLING_START: 108 case ui::ET_SCROLL_FLING_START:
91 shelf_view_->PointerReleasedOnButton(this, ShelfView::TOUCH, false); 109 shelf_view_->PointerReleasedOnButton(this, ShelfView::TOUCH, false);
92 event->SetHandled(); 110 event->SetHandled();
93 return; 111 return;
94 case ui::ET_GESTURE_TAP_DOWN: 112 case ui::ET_GESTURE_TAP_DOWN:
95 if (switches::IsTouchFeedbackEnabled()) 113 if (touch_feedback)
96 SetDrawBackgroundAsActive(true); 114 SetDrawBackgroundAsActive(true);
115 else if (is_material && !Shell::GetInstance()->IsApplistVisible())
116 AnimateInkDrop(views::InkDropState::ACTION_PENDING);
97 ImageButton::OnGestureEvent(event); 117 ImageButton::OnGestureEvent(event);
98 break; 118 break;
99 case ui::ET_GESTURE_TAP_CANCEL: 119 case ui::ET_GESTURE_TAP_CANCEL:
100 case ui::ET_GESTURE_TAP: 120 case ui::ET_GESTURE_TAP:
101 if (switches::IsTouchFeedbackEnabled()) 121 if (touch_feedback)
102 SetDrawBackgroundAsActive(false); 122 SetDrawBackgroundAsActive(false);
103 ImageButton::OnGestureEvent(event); 123 ImageButton::OnGestureEvent(event);
104 break; 124 break;
105 default: 125 default:
106 ImageButton::OnGestureEvent(event); 126 ImageButton::OnGestureEvent(event);
107 return; 127 return;
108 } 128 }
109 } 129 }
110 130
111 void AppListButton::OnPaint(gfx::Canvas* canvas) { 131 void AppListButton::OnPaint(gfx::Canvas* canvas) {
(...skipping 30 matching lines...) Expand all
142 SkColorSetA(kShelfBaseColor, GetShelfConstant(SHELF_BACKGROUND_ALPHA))); 162 SkColorSetA(kShelfBaseColor, GetShelfConstant(SHELF_BACKGROUND_ALPHA)));
143 } 163 }
144 164
145 // Paint the circular background of AppList button. 165 // Paint the circular background of AppList button.
146 gfx::Point circle_center = GetContentsBounds().CenterPoint(); 166 gfx::Point circle_center = GetContentsBounds().CenterPoint();
147 if (!IsHorizontalAlignment(shelf_view_->shelf()->alignment())) 167 if (!IsHorizontalAlignment(shelf_view_->shelf()->alignment()))
148 circle_center = gfx::Point(circle_center.y(), circle_center.x()); 168 circle_center = gfx::Point(circle_center.y(), circle_center.x());
149 169
150 canvas->DrawCircle(circle_center, kAppListButtonBackgroundRadius, 170 canvas->DrawCircle(circle_center, kAppListButtonBackgroundRadius,
151 background_paint); 171 background_paint);
152
153 if (Shell::GetInstance()->GetAppListTargetVisibility() ||
154 draw_background_as_active_) {
155 SkPaint highlight_paint;
156 highlight_paint.setColor(kShelfButtonActivatedHighlightColor);
157 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag);
158 highlight_paint.setStyle(SkPaint::kFill_Style);
159
160 canvas->DrawCircle(circle_center, kAppListButtonBackgroundRadius,
161 highlight_paint);
162 }
163 } 172 }
164 173
165 void AppListButton::PaintForegroundMD(gfx::Canvas* canvas, 174 void AppListButton::PaintForegroundMD(gfx::Canvas* canvas,
166 const gfx::ImageSkia& foreground_image) { 175 const gfx::ImageSkia& foreground_image) {
167 gfx::Rect foreground_bounds(foreground_image.size()); 176 gfx::Rect foreground_bounds(foreground_image.size());
168 gfx::Rect contents_bounds = GetContentsBounds(); 177 gfx::Rect contents_bounds = GetContentsBounds();
169 178
170 if (IsHorizontalAlignment(shelf_view_->shelf()->alignment())) { 179 if (IsHorizontalAlignment(shelf_view_->shelf()->alignment())) {
171 foreground_bounds.set_x( 180 foreground_bounds.set_x(
172 (contents_bounds.width() - foreground_bounds.width()) / 2); 181 (contents_bounds.width() - foreground_bounds.width()) / 2);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 (background_bounds.height() - foreground_bounds.height()) / 2)); 243 (background_bounds.height() - foreground_bounds.height()) / 2));
235 canvas->DrawImageInt(foreground_image, foreground_bounds.x(), 244 canvas->DrawImageInt(foreground_image, foreground_bounds.x(),
236 foreground_bounds.y()); 245 foreground_bounds.y());
237 } 246 }
238 247
239 void AppListButton::GetAccessibleState(ui::AXViewState* state) { 248 void AppListButton::GetAccessibleState(ui::AXViewState* state) {
240 state->role = ui::AX_ROLE_BUTTON; 249 state->role = ui::AX_ROLE_BUTTON;
241 state->name = shelf_view_->GetTitleForView(this); 250 state->name = shelf_view_->GetTitleForView(this);
242 } 251 }
243 252
253 std::unique_ptr<views::InkDropRipple> AppListButton::CreateInkDropRipple()
254 const {
255 // TODO(mohsen): A circular SquareInkDropRipple is created with equal small
256 // and large sizes to mimic a circular flood fill. Replace with an actual
257 // flood fill when circular flood fills are implemented.
258 auto ink_drop_ripple = new views::SquareInkDropRipple(
259 gfx::Size(kAppListButtonBackgroundRadius * 2,
260 kAppListButtonBackgroundRadius * 2),
261 0, gfx::Size(2 * kAppListButtonBackgroundRadius,
262 2 * kAppListButtonBackgroundRadius),
263 0, GetInkDropCenter(), GetInkDropBaseColor());
264 ink_drop_ripple->set_activated_shape(views::SquareInkDropRipple::CIRCLE);
265 return base::WrapUnique(ink_drop_ripple);
266 }
267
244 void AppListButton::NotifyClick(const ui::Event& event) { 268 void AppListButton::NotifyClick(const ui::Event& event) {
245 ImageButton::NotifyClick(event); 269 ImageButton::NotifyClick(event);
246 if (listener_) 270 if (listener_)
247 listener_->ButtonPressed(this, event, ink_drop()); 271 listener_->ButtonPressed(this, event, ink_drop());
248 } 272 }
249 273
274 bool AppListButton::ShouldEnterPushedState(const ui::Event& event) {
275 return !Shell::GetInstance()->IsApplistVisible();
276 }
277
278 bool AppListButton::ShouldShowInkDropHighlight() const {
279 return false;
280 }
281
250 void AppListButton::SetDrawBackgroundAsActive( 282 void AppListButton::SetDrawBackgroundAsActive(
251 bool draw_background_as_active) { 283 bool draw_background_as_active) {
252 if (draw_background_as_active_ == draw_background_as_active) 284 if (draw_background_as_active_ == draw_background_as_active)
253 return; 285 return;
254 draw_background_as_active_ = draw_background_as_active; 286 draw_background_as_active_ = draw_background_as_active;
255 SchedulePaint(); 287 SchedulePaint();
256 } 288 }
257 289
258 } // namespace ash 290 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/app_list_button.h ('k') | ash/shelf/shelf.h » ('j') | ash/shelf/shelf_view_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698