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

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

Issue 558703002: AppLauncher Touch Feedback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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/ash_constants.h" 7 #include "ash/ash_constants.h"
8 #include "ash/ash_switches.h" 8 #include "ash/ash_switches.h"
9 #include "ash/shelf/shelf_button.h" 9 #include "ash/shelf/shelf_button.h"
10 #include "ash/shelf/shelf_button_host.h" 10 #include "ash/shelf/shelf_button_host.h"
11 #include "ash/shelf/shelf_item_types.h" 11 #include "ash/shelf/shelf_item_types.h"
12 #include "ash/shelf/shelf_layout_manager.h" 12 #include "ash/shelf/shelf_layout_manager.h"
13 #include "ash/shelf/shelf_widget.h" 13 #include "ash/shelf/shelf_widget.h"
14 #include "ash/shell.h" 14 #include "ash/shell.h"
15 #include "base/command_line.h"
15 #include "grit/ash_resources.h" 16 #include "grit/ash_resources.h"
16 #include "grit/ash_strings.h" 17 #include "grit/ash_strings.h"
17 #include "ui/accessibility/ax_view_state.h" 18 #include "ui/accessibility/ax_view_state.h"
18 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/compositor/layer.h" 21 #include "ui/compositor/layer.h"
21 #include "ui/compositor/layer_animation_element.h" 22 #include "ui/compositor/layer_animation_element.h"
22 #include "ui/compositor/layer_animation_sequence.h" 23 #include "ui/compositor/layer_animation_sequence.h"
23 #include "ui/compositor/scoped_layer_animation_settings.h" 24 #include "ui/compositor/scoped_layer_animation_settings.h"
24 #include "ui/gfx/canvas.h" 25 #include "ui/gfx/canvas.h"
25 #include "ui/gfx/image/image_skia_operations.h" 26 #include "ui/gfx/image/image_skia_operations.h"
26 #include "ui/views/controls/button/image_button.h" 27 #include "ui/views/controls/button/image_button.h"
27 #include "ui/views/painter.h" 28 #include "ui/views/painter.h"
28 29
29 namespace ash { 30 namespace ash {
30 // static 31 // static
31 const int AppListButton::kImageBoundsSize = 7; 32 const int AppListButton::kImageBoundsSize = 7;
32 33
33 34
34 AppListButton::AppListButton(views::ButtonListener* listener, 35 AppListButton::AppListButton(views::ButtonListener* listener,
35 ShelfButtonHost* host, 36 ShelfButtonHost* host,
36 ShelfWidget* shelf_widget) 37 ShelfWidget* shelf_widget)
37 : views::ImageButton(listener), 38 : views::ImageButton(listener),
39 set_draw_background_as_active_(false),
40 touch_feedback_enabled_(false),
38 host_(host), 41 host_(host),
39 shelf_widget_(shelf_widget) { 42 shelf_widget_(shelf_widget) {
40 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE)); 43 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE));
41 SetSize(gfx::Size(kShelfSize, kShelfSize)); 44 SetSize(gfx::Size(kShelfSize, kShelfSize));
42 SetFocusPainter(views::Painter::CreateSolidFocusPainter( 45 SetFocusPainter(views::Painter::CreateSolidFocusPainter(
43 kFocusBorderColor, gfx::Insets(1, 1, 1, 1))); 46 kFocusBorderColor, gfx::Insets(1, 1, 1, 1)));
47
48 if (CommandLine::ForCurrentProcess()->
49 HasSwitch(switches::kAshEnableTouchViewTouchFeedback)) {
50 touch_feedback_enabled_ = true;
51 }
44 } 52 }
45 53
46 AppListButton::~AppListButton() { 54 AppListButton::~AppListButton() {
47 } 55 }
48 56
49 bool AppListButton::OnMousePressed(const ui::MouseEvent& event) { 57 bool AppListButton::OnMousePressed(const ui::MouseEvent& event) {
50 ImageButton::OnMousePressed(event); 58 ImageButton::OnMousePressed(event);
51 host_->PointerPressedOnButton(this, ShelfButtonHost::MOUSE, event); 59 host_->PointerPressedOnButton(this, ShelfButtonHost::MOUSE, event);
52 return true; 60 return true;
53 } 61 }
(...skipping 25 matching lines...) Expand all
79 } 87 }
80 88
81 void AppListButton::OnMouseExited(const ui::MouseEvent& event) { 89 void AppListButton::OnMouseExited(const ui::MouseEvent& event) {
82 ImageButton::OnMouseExited(event); 90 ImageButton::OnMouseExited(event);
83 host_->MouseExitedButton(this); 91 host_->MouseExitedButton(this);
84 } 92 }
85 93
86 void AppListButton::OnGestureEvent(ui::GestureEvent* event) { 94 void AppListButton::OnGestureEvent(ui::GestureEvent* event) {
87 switch (event->type()) { 95 switch (event->type()) {
88 case ui::ET_GESTURE_SCROLL_BEGIN: 96 case ui::ET_GESTURE_SCROLL_BEGIN:
97 SetDrawBackgroundAsActive(false);
89 host_->PointerPressedOnButton(this, ShelfButtonHost::TOUCH, *event); 98 host_->PointerPressedOnButton(this, ShelfButtonHost::TOUCH, *event);
90 event->SetHandled(); 99 event->SetHandled();
91 return; 100 return;
92 case ui::ET_GESTURE_SCROLL_UPDATE: 101 case ui::ET_GESTURE_SCROLL_UPDATE:
93 host_->PointerDraggedOnButton(this, ShelfButtonHost::TOUCH, *event); 102 host_->PointerDraggedOnButton(this, ShelfButtonHost::TOUCH, *event);
94 event->SetHandled(); 103 event->SetHandled();
95 return; 104 return;
96 case ui::ET_GESTURE_SCROLL_END: 105 case ui::ET_GESTURE_SCROLL_END:
97 case ui::ET_SCROLL_FLING_START: 106 case ui::ET_SCROLL_FLING_START:
98 host_->PointerReleasedOnButton(this, ShelfButtonHost::TOUCH, false); 107 host_->PointerReleasedOnButton(this, ShelfButtonHost::TOUCH, false);
99 event->SetHandled(); 108 event->SetHandled();
100 return; 109 return;
110 case ui::ET_GESTURE_TAP_DOWN:
111 SetDrawBackgroundAsActive(true);
112 ImageButton::OnGestureEvent(event);
113 break;
114 case ui::ET_GESTURE_TAP_CANCEL:
115 case ui::ET_GESTURE_TAP:
116 SetDrawBackgroundAsActive(false);
117 ImageButton::OnGestureEvent(event);
118 break;
101 default: 119 default:
102 ImageButton::OnGestureEvent(event); 120 ImageButton::OnGestureEvent(event);
103 return; 121 return;
104 } 122 }
105 } 123 }
106 124
107 void AppListButton::OnPaint(gfx::Canvas* canvas) { 125 void AppListButton::OnPaint(gfx::Canvas* canvas) {
108 // Call the base class first to paint any background/borders. 126 // Call the base class first to paint any background/borders.
109 View::OnPaint(canvas); 127 View::OnPaint(canvas);
110 128
111 int background_image_id = 0; 129 int background_image_id = 0;
112 if (Shell::GetInstance()->GetAppListTargetVisibility()) { 130 if (Shell::GetInstance()->GetAppListTargetVisibility() ||
131 set_draw_background_as_active_) {
113 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; 132 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED;
114 } else { 133 } else {
115 if (shelf_widget_->GetDimsShelf()) 134 if (shelf_widget_->GetDimsShelf())
116 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; 135 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK;
117 else 136 else
118 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; 137 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL;
119 } 138 }
120 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 139 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
121 const gfx::ImageSkia* background_image = 140 const gfx::ImageSkia* background_image =
122 rb.GetImageNamed(background_image_id).ToImageSkia(); 141 rb.GetImageNamed(background_image_id).ToImageSkia();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 forground_bounds.y()); 178 forground_bounds.y());
160 179
161 views::Painter::PaintFocusPainter(this, canvas, focus_painter()); 180 views::Painter::PaintFocusPainter(this, canvas, focus_painter());
162 } 181 }
163 182
164 void AppListButton::GetAccessibleState(ui::AXViewState* state) { 183 void AppListButton::GetAccessibleState(ui::AXViewState* state) {
165 state->role = ui::AX_ROLE_BUTTON; 184 state->role = ui::AX_ROLE_BUTTON;
166 state->name = host_->GetAccessibleName(this); 185 state->name = host_->GetAccessibleName(this);
167 } 186 }
168 187
188 void AppListButton::SetDrawBackgroundAsActive(
189 bool set_draw_background_as_active) {
190 if (!touch_feedback_enabled_)
flackr 2014/09/10 20:04:41 nit: A little confusing that calling SetDrawBackgr
jonross 2014/09/11 15:06:52 Since we want to eventually eliminate the flag I'v
191 return;
192 if (set_draw_background_as_active_ == set_draw_background_as_active)
193 return;
194 set_draw_background_as_active_ = set_draw_background_as_active;
195 SchedulePaint();
196 }
197
169 } // namespace ash 198 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698