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

Side by Side Diff: ash/accelerators/accelerator_controller.cc

Issue 78763003: Record user actions for Ash accelerators. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: missing return Created 7 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
« no previous file with comments | « ash/accelerators/accelerator_commands.cc ('k') | ash/shell_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/accelerators/accelerator_controller.h" 5 #include "ash/accelerators/accelerator_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <iostream> 9 #include <iostream>
10 #include <string> 10 #include <string>
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 85
86 bool DebugShortcutsEnabled() { 86 bool DebugShortcutsEnabled() {
87 #if defined(NDEBUG) 87 #if defined(NDEBUG)
88 return CommandLine::ForCurrentProcess()->HasSwitch( 88 return CommandLine::ForCurrentProcess()->HasSwitch(
89 switches::kAshDebugShortcuts); 89 switches::kAshDebugShortcuts);
90 #else 90 #else
91 return true; 91 return true;
92 #endif 92 #endif
93 } 93 }
94 94
95 void HandleCycleBackwardMRU(const ui::Accelerator& accelerator) { 95 bool HandleAccessibleFocusCycle(bool reverse) {
96 if (reverse) {
97 content::RecordAction(
98 content::UserMetricsAction("Accel_Accessible_Focus_Previous"));
99 } else {
100 content::RecordAction(
101 content::UserMetricsAction("Accel_Accessible_Focus_Next"));
102 }
103
104 if (!Shell::GetInstance()->accessibility_delegate()->
105 IsSpokenFeedbackEnabled()) {
106 return false;
107 }
108 aura::Window* active_window = ash::wm::GetActiveWindow();
109 if (!active_window)
110 return false;
111 views::Widget* widget =
112 views::Widget::GetWidgetForNativeWindow(active_window);
113 if (!widget)
114 return false;
115 views::FocusManager* focus_manager = widget->GetFocusManager();
116 if (!focus_manager)
117 return false;
118 views::View* view = focus_manager->GetFocusedView();
119 if (!view)
120 return false;
121 if (!strcmp(view->GetClassName(), views::WebView::kViewClassName))
122 return false;
123
124 focus_manager->AdvanceFocus(reverse);
125 return true;
126 }
127
128 bool HandleCycleBackwardMRU(const ui::Accelerator& accelerator) {
96 Shell* shell = Shell::GetInstance(); 129 Shell* shell = Shell::GetInstance();
97 130
98 if (accelerator.key_code() == ui::VKEY_TAB) 131 if (accelerator.key_code() == ui::VKEY_TAB)
99 content::RecordAction(content::UserMetricsAction("Accel_PrevWindow_Tab")); 132 content::RecordAction(content::UserMetricsAction("Accel_PrevWindow_Tab"));
100 133
101 if (switches::UseOverviewMode()) { 134 if (switches::UseOverviewMode()) {
102 shell->window_selector_controller()->HandleCycleWindow( 135 shell->window_selector_controller()->HandleCycleWindow(
103 WindowSelector::BACKWARD); 136 WindowSelector::BACKWARD);
104 return; 137 return true;
105 } 138 }
106 shell->window_cycle_controller()->HandleCycleWindow( 139 shell->window_cycle_controller()->HandleCycleWindow(
107 WindowCycleController::BACKWARD, accelerator.IsAltDown()); 140 WindowCycleController::BACKWARD, accelerator.IsAltDown());
141 return true;
108 } 142 }
109 143
110 void HandleCycleForwardMRU(const ui::Accelerator& accelerator) { 144 bool HandleCycleForwardMRU(const ui::Accelerator& accelerator) {
111 Shell* shell = Shell::GetInstance(); 145 Shell* shell = Shell::GetInstance();
112 146
113 if (accelerator.key_code() == ui::VKEY_TAB) 147 if (accelerator.key_code() == ui::VKEY_TAB)
114 content::RecordAction(content::UserMetricsAction("Accel_NextWindow_Tab")); 148 content::RecordAction(content::UserMetricsAction("Accel_NextWindow_Tab"));
115 149
116 if (switches::UseOverviewMode()) { 150 if (switches::UseOverviewMode()) {
117 shell->window_selector_controller()->HandleCycleWindow( 151 shell->window_selector_controller()->HandleCycleWindow(
118 WindowSelector::FORWARD); 152 WindowSelector::FORWARD);
119 return; 153 return true;
120 } 154 }
121 shell->window_cycle_controller()->HandleCycleWindow( 155 shell->window_cycle_controller()->HandleCycleWindow(
122 WindowCycleController::FORWARD, accelerator.IsAltDown()); 156 WindowCycleController::FORWARD, accelerator.IsAltDown());
157 return true;
123 } 158 }
124 159
125 void HandleCycleLinear(const ui::Accelerator& accelerator) { 160 bool HandleCycleLinear(const ui::Accelerator& accelerator) {
126 Shell* shell = Shell::GetInstance(); 161 Shell* shell = Shell::GetInstance();
127 162
128 // TODO(jamescook): When overview becomes the default the AcceleratorAction 163 // TODO(jamescook): When overview becomes the default the AcceleratorAction
129 // should be renamed from CYCLE_LINEAR to TOGGLE_OVERVIEW. 164 // should be renamed from CYCLE_LINEAR to TOGGLE_OVERVIEW.
130 if (switches::UseOverviewMode()) { 165 if (switches::UseOverviewMode()) {
131 content::RecordAction(content::UserMetricsAction("Accel_Overview_F5")); 166 content::RecordAction(content::UserMetricsAction("Accel_Overview_F5"));
132 shell->window_selector_controller()->ToggleOverview(); 167 shell->window_selector_controller()->ToggleOverview();
133 return; 168 return true;
134 } 169 }
135 if (accelerator.key_code() == ui::VKEY_MEDIA_LAUNCH_APP1) 170 if (accelerator.key_code() == ui::VKEY_MEDIA_LAUNCH_APP1)
136 content::RecordAction(content::UserMetricsAction("Accel_NextWindow_F5")); 171 content::RecordAction(content::UserMetricsAction("Accel_NextWindow_F5"));
137 shell->window_cycle_controller()->HandleLinearCycleWindow(); 172 shell->window_cycle_controller()->HandleLinearCycleWindow();
138 } 173 return true;
139 174 }
140 bool HandleAccessibleFocusCycle(bool reverse) { 175
141 if (!Shell::GetInstance()->accessibility_delegate()-> 176 bool HandleDisableCapsLock(ui::KeyboardCode key_code,
142 IsSpokenFeedbackEnabled()) { 177 ui::EventType previous_event_type,
178 ui::KeyboardCode previous_key_code) {
179 Shell* shell = Shell::GetInstance();
180
181 if (previous_event_type == ui::ET_KEY_RELEASED ||
182 (previous_key_code != ui::VKEY_LSHIFT &&
183 previous_key_code != ui::VKEY_SHIFT &&
184 previous_key_code != ui::VKEY_RSHIFT)) {
185 // If something else was pressed between the Shift key being pressed
186 // and released, then ignore the release of the Shift key.
143 return false; 187 return false;
144 } 188 }
145 aura::Window* active_window = ash::wm::GetActiveWindow(); 189 content::RecordAction(
146 if (!active_window) 190 content::UserMetricsAction("Accel_Disable_Caps_Lock"));
191 if (shell->caps_lock_delegate()->IsCapsLockEnabled()) {
192 shell->caps_lock_delegate()->SetCapsLockEnabled(false);
193 return true;
194 }
195 return false;
196 }
197
198 bool HandleFocusLauncher() {
199 Shell* shell = Shell::GetInstance();
200 content::RecordAction(content::UserMetricsAction("Accel_Focus_Launcher"));
201 return shell->focus_cycler()->FocusWidget(
202 Launcher::ForPrimaryDisplay()->shelf_widget());
203 }
204
205 bool HandleLaunchAppN(int n) {
206 content::RecordAction(
207 content::UserMetricsAction("Accel_Launch_App"));
208 Launcher::ForPrimaryDisplay()->LaunchAppIndexAt(n);
209 return true;
210 }
211
212 bool HandleLaunchLastApp() {
213 content::RecordAction(
214 content::UserMetricsAction("Accel_Launch_Last_App"));
215 Launcher::ForPrimaryDisplay()->LaunchAppIndexAt(-1);
216 return true;
217 }
218
219 // Magnify the screen
220 bool HandleMagnifyScreen(int delta_index) {
221 if (ash::Shell::GetInstance()->magnification_controller()->IsEnabled()) {
222 // TODO(yoshiki): Move the following logic to MagnificationController.
223 float scale =
224 ash::Shell::GetInstance()->magnification_controller()->GetScale();
225 // Calculate rounded logarithm (base kMagnificationScaleFactor) of scale.
226 int scale_index =
227 std::floor(std::log(scale) / std::log(kMagnificationScaleFactor) + 0.5);
228
229 int new_scale_index = std::max(0, std::min(8, scale_index + delta_index));
230
231 ash::Shell::GetInstance()->magnification_controller()->
232 SetScale(std::pow(kMagnificationScaleFactor, new_scale_index), true);
233 } else if (ash::Shell::GetInstance()->
234 partial_magnification_controller()->is_enabled()) {
235 float scale = delta_index > 0 ? kDefaultPartialMagnifiedScale : 1;
236 ash::Shell::GetInstance()->partial_magnification_controller()->
237 SetScale(scale);
238 }
239
240 return true;
241 }
242
243 bool HandleMediaNextTrack() {
244 Shell::GetInstance()->media_delegate()->HandleMediaNextTrack();
245 return true;
246 }
247
248 bool HandleMediaPlayPause() {
249 Shell::GetInstance()->media_delegate()->HandleMediaPlayPause();
250 return true;
251 }
252
253 bool HandleMediaPrevTrack() {
254 Shell::GetInstance()->media_delegate()->HandleMediaPrevTrack();
255 return true;
256 }
257
258 bool HandleNewIncognitoWindow() {
259 content::RecordAction(
260 content::UserMetricsAction("Accel_New_Incognito_Window"));
261 bool incognito_allowed =
262 Shell::GetInstance()->delegate()->IsIncognitoAllowed();
263 if (incognito_allowed)
264 Shell::GetInstance()->new_window_delegate()->NewWindow(
265 true /* is_incognito */);
266 return incognito_allowed;
267 }
268
269 bool HandleNewTab(ui::KeyboardCode key_code) {
270 if (key_code == ui::VKEY_T)
271 content::RecordAction(content::UserMetricsAction("Accel_NewTab_T"));
272 Shell::GetInstance()->new_window_delegate()->NewTab();
273 return true;
274 }
275
276 bool HandleNewWindow() {
277 content::RecordAction(content::UserMetricsAction("Accel_New_Window"));
278 Shell::GetInstance()->new_window_delegate()->NewWindow(
279 false /* is_incognito */);
280 return true;
281 }
282
283 bool HandleNextIme(ImeControlDelegate* ime_control_delegate,
284 ui::EventType previous_event_type,
285 ui::KeyboardCode previous_key_code) {
286 // This check is necessary e.g. not to process the Shift+Alt+
287 // ET_KEY_RELEASED accelerator for Chrome OS (see ash/accelerators/
288 // accelerator_controller.cc) when Shift+Alt+Tab is pressed and then Tab
289 // is released.
290 if (previous_event_type == ui::ET_KEY_RELEASED &&
291 // Workaround for crbug.com/139556. CJK IME users tend to press
292 // Enter (or Space) and Shift+Alt almost at the same time to commit
293 // an IME string and then switch from the IME to the English layout.
294 // This workaround allows the user to trigger NEXT_IME even if the
295 // user presses Shift+Alt before releasing Enter.
296 // TODO(nona|mazda): Fix crbug.com/139556 in a cleaner way.
297 previous_key_code != ui::VKEY_RETURN &&
298 previous_key_code != ui::VKEY_SPACE) {
299 // We totally ignore this accelerator.
300 // TODO(mazda): Fix crbug.com/158217
147 return false; 301 return false;
148 views::Widget* widget = 302 }
149 views::Widget::GetWidgetForNativeWindow(active_window); 303 content::RecordAction(
150 if (!widget) 304 content::UserMetricsAction("Accel_Next_Ime"));
151 return false; 305 if (ime_control_delegate)
152 views::FocusManager* focus_manager = widget->GetFocusManager(); 306 return ime_control_delegate->HandleNextIme();
153 if (!focus_manager) 307 return false;
154 return false; 308 }
155 views::View* view = focus_manager->GetFocusedView(); 309
156 if (!view) 310 bool HandleOpenFeedbackPage() {
157 return false; 311 content::RecordAction(
158 if (!strcmp(view->GetClassName(), views::WebView::kViewClassName)) 312 content::UserMetricsAction("Accel_Open_Feedback_Page"));
159 return false; 313 ash::Shell::GetInstance()->new_window_delegate()->OpenFeedbackPage();
160 314 return true;
161 focus_manager->AdvanceFocus(reverse); 315 }
162 return true; 316
163 } 317 bool HandlePositionCenter() {
164 318 content::RecordAction(
165 void HandleSilenceSpokenFeedback() { 319 content::UserMetricsAction("Accel_Window_Position_Center"));
166 AccessibilityDelegate* delegate = 320 aura::Window* window = wm::GetActiveWindow();
167 Shell::GetInstance()->accessibility_delegate(); 321 // Docked windows do not support centering and ignore accelerator.
168 if (!delegate->IsSpokenFeedbackEnabled()) 322 if (window && !wm::GetWindowState(window)->IsDocked()) {
169 return; 323 wm::CenterWindow(window);
170 delegate->SilenceSpokenFeedback(); 324 return true;
171 } 325 }
172 326 return false;
173 #if defined(OS_CHROMEOS) 327 }
174 bool HandleLock() { 328
175 Shell::GetInstance()->session_state_delegate()->LockScreen(); 329 bool HandlePreviousIme(ImeControlDelegate* ime_control_delegate,
176 return true; 330 const ui::Accelerator& accelerator) {
177 } 331 content::RecordAction(
178 332 content::UserMetricsAction("Accel_Previous_Ime"));
179 bool HandleFileManager() { 333 if (ime_control_delegate)
180 Shell::GetInstance()->new_window_delegate()->OpenFileManager(); 334 return ime_control_delegate->HandlePreviousIme(accelerator);
181 return true; 335 return false;
182 } 336 }
183 337
184 bool HandleCrosh() { 338 bool HandleRestoreTab() {
185 Shell::GetInstance()->new_window_delegate()->OpenCrosh(); 339 content::RecordAction(content::UserMetricsAction("Accel_Restore_Tab"));
186 return true; 340 Shell::GetInstance()->new_window_delegate()->RestoreTab();
187 } 341 return true;
188 342 }
189 bool HandleToggleSpokenFeedback() {
190 Shell::GetInstance()->accessibility_delegate()->
191 ToggleSpokenFeedback(A11Y_NOTIFICATION_SHOW);
192 return true;
193 }
194
195 bool SwitchToNextUser() {
196 if (!Shell::GetInstance()->delegate()->IsMultiProfilesEnabled())
197 return false;
198 ash::SessionStateDelegate* delegate =
199 ash::Shell::GetInstance()->session_state_delegate();
200 if (delegate->NumberOfLoggedInUsers() <= 1)
201 return false;
202 MultiProfileUMA::RecordSwitchActiveUser(
203 MultiProfileUMA::SWITCH_ACTIVE_USER_BY_ACCELERATOR);
204 delegate->SwitchActiveUserToNext();
205 return true;
206 }
207
208 #endif // defined(OS_CHROMEOS)
209 343
210 bool HandleRotatePaneFocus(Shell::Direction direction) { 344 bool HandleRotatePaneFocus(Shell::Direction direction) {
211 Shell* shell = Shell::GetInstance(); 345 Shell* shell = Shell::GetInstance();
212 switch (direction) { 346 switch (direction) {
213 case Shell::FORWARD: 347 // TODO(stevet): Not sure if this is the same as IDC_FOCUS_NEXT_PANE.
348 case Shell::FORWARD: {
349 content::RecordAction(
350 content::UserMetricsAction("Accel_Focus_Next_Pane"));
214 shell->focus_cycler()->RotateFocus(internal::FocusCycler::FORWARD); 351 shell->focus_cycler()->RotateFocus(internal::FocusCycler::FORWARD);
215 break; 352 break;
216 case Shell::BACKWARD: 353 }
354 case Shell::BACKWARD: {
355 content::RecordAction(
356 content::UserMetricsAction("Accel_Focus_Previous_Pane"));
217 shell->focus_cycler()->RotateFocus(internal::FocusCycler::BACKWARD); 357 shell->focus_cycler()->RotateFocus(internal::FocusCycler::BACKWARD);
218 break; 358 break;
359 }
219 } 360 }
220 return true; 361 return true;
221 } 362 }
222 363
223 // Rotate the active window. 364 // Rotate the active window.
224 bool HandleRotateActiveWindow() { 365 bool HandleRotateActiveWindow() {
366 content::RecordAction(
367 content::UserMetricsAction("Accel_Rotate_Window"));
225 aura::Window* active_window = wm::GetActiveWindow(); 368 aura::Window* active_window = wm::GetActiveWindow();
226 if (active_window) { 369 if (active_window) {
227 // The rotation animation bases its target transform on the current 370 // The rotation animation bases its target transform on the current
228 // rotation and position. Since there could be an animation in progress 371 // rotation and position. Since there could be an animation in progress
229 // right now, queue this animation so when it starts it picks up a neutral 372 // right now, queue this animation so when it starts it picks up a neutral
230 // rotation and position. Use replace so we only enqueue one at a time. 373 // rotation and position. Use replace so we only enqueue one at a time.
231 active_window->layer()->GetAnimator()-> 374 active_window->layer()->GetAnimator()->
232 set_preemption_strategy(ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); 375 set_preemption_strategy(ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
233 active_window->layer()->GetAnimator()->StartAnimation( 376 active_window->layer()->GetAnimator()->StartAnimation(
234 new ui::LayerAnimationSequence( 377 new ui::LayerAnimationSequence(
(...skipping 10 matching lines...) Expand all
245 return gfx::Display::ROTATE_180; 388 return gfx::Display::ROTATE_180;
246 case gfx::Display::ROTATE_180: 389 case gfx::Display::ROTATE_180:
247 return gfx::Display::ROTATE_270; 390 return gfx::Display::ROTATE_270;
248 case gfx::Display::ROTATE_270: 391 case gfx::Display::ROTATE_270:
249 return gfx::Display::ROTATE_0; 392 return gfx::Display::ROTATE_0;
250 } 393 }
251 NOTREACHED() << "Unknown rotation:" << current; 394 NOTREACHED() << "Unknown rotation:" << current;
252 return gfx::Display::ROTATE_0; 395 return gfx::Display::ROTATE_0;
253 } 396 }
254 397
398 // Rotates the screen.
399 bool HandleRotateScreen() {
400 content::RecordAction(
401 content::UserMetricsAction("Accel_Rotate_Window"));
402 gfx::Point point = Shell::GetScreen()->GetCursorScreenPoint();
403 gfx::Display display = Shell::GetScreen()->GetDisplayNearestPoint(point);
404 const DisplayInfo& display_info =
405 Shell::GetInstance()->display_manager()->GetDisplayInfo(display.id());
406 Shell::GetInstance()->display_manager()->SetDisplayRotation(
407 display.id(), GetNextRotation(display_info.rotation()));
408 return true;
409 }
410
411 bool HandleScaleReset() {
412 internal::DisplayManager* display_manager =
413 Shell::GetInstance()->display_manager();
414 int64 display_id = display_manager->GetDisplayIdForUIScaling();
415 if (display_id == gfx::Display::kInvalidDisplayID)
416 return false;
417
418 content::RecordAction(
419 content::UserMetricsAction("Accel_Scale_Ui_Reset"));
420
421 display_manager->SetDisplayUIScale(display_id, 1.0f);
422 return true;
423 }
424
255 bool HandleScaleUI(bool up) { 425 bool HandleScaleUI(bool up) {
256 internal::DisplayManager* display_manager = 426 internal::DisplayManager* display_manager =
257 Shell::GetInstance()->display_manager(); 427 Shell::GetInstance()->display_manager();
258 int64 display_id = display_manager->GetDisplayIdForUIScaling(); 428 int64 display_id = display_manager->GetDisplayIdForUIScaling();
259 if (display_id == gfx::Display::kInvalidDisplayID) 429 if (display_id == gfx::Display::kInvalidDisplayID)
260 return false; 430 return false;
431
432 if (up) {
433 content::RecordAction(
434 content::UserMetricsAction("Accel_Scale_Ui_Up"));
435 } else {
436 content::RecordAction(
437 content::UserMetricsAction("Accel_Scale_Ui_Down"));
438 }
439
261 const DisplayInfo& display_info = display_manager->GetDisplayInfo(display_id); 440 const DisplayInfo& display_info = display_manager->GetDisplayInfo(display_id);
262 float next_scale = 441 float next_scale =
263 internal::DisplayManager::GetNextUIScale(display_info, up); 442 internal::DisplayManager::GetNextUIScale(display_info, up);
264 display_manager->SetDisplayUIScale(display_id, next_scale); 443 display_manager->SetDisplayUIScale(display_id, next_scale);
265 return true; 444 return true;
266 } 445 }
267 446
268 bool HandleScaleReset() { 447 bool HandleSwapPrimaryDisplay() {
269 internal::DisplayManager* display_manager = 448 content::RecordAction(
270 Shell::GetInstance()->display_manager(); 449 content::UserMetricsAction("Accel_Swap_Primary_Display"));
271 int64 display_id = display_manager->GetDisplayIdForUIScaling(); 450 Shell::GetInstance()->display_controller()->SwapPrimaryDisplay();
272 if (display_id == gfx::Display::kInvalidDisplayID)
273 return false;
274 display_manager->SetDisplayUIScale(display_id, 1.0f);
275 return true; 451 return true;
276 } 452 }
277 453
278 // Rotates the screen. 454 bool HandleShowKeyboardOverlay() {
279 bool HandleRotateScreen() { 455 content::RecordAction(
280 gfx::Point point = Shell::GetScreen()->GetCursorScreenPoint(); 456 content::UserMetricsAction("Accel_Show_Keyboard_Overlay"));
281 gfx::Display display = Shell::GetScreen()->GetDisplayNearestPoint(point); 457 ash::Shell::GetInstance()->new_window_delegate()->ShowKeyboardOverlay();
282 const DisplayInfo& display_info = 458
283 Shell::GetInstance()->display_manager()->GetDisplayInfo(display.id());
284 Shell::GetInstance()->display_manager()->SetDisplayRotation(
285 display.id(), GetNextRotation(display_info.rotation()));
286 return true; 459 return true;
287 } 460 }
288 461
462 void HandleShowMessageCenterBubble() {
463 content::RecordAction(
464 content::UserMetricsAction("Accel_Show_Message_Center_Bubble"));
465 internal::RootWindowController* controller =
466 internal::RootWindowController::ForTargetRootWindow();
467 internal::StatusAreaWidget* status_area_widget =
468 controller->shelf()->status_area_widget();
469 if (status_area_widget) {
470 WebNotificationTray* notification_tray =
471 status_area_widget->web_notification_tray();
472 if (notification_tray->visible())
473 notification_tray->ShowMessageCenterBubble();
474 }
475 }
476
477 bool HandleShowOak() {
478 if (CommandLine::ForCurrentProcess()->HasSwitch(
479 switches::kAshEnableOak)) {
480 oak::ShowOakWindowWithContext(Shell::GetPrimaryRootWindow());
481 return true;
482 }
483 return false;
484 }
485
486 bool HandleShowSystemTrayBubble() {
487 content::RecordAction(
488 content::UserMetricsAction("Accel_Show_System_Tray_Bubble"));
489 internal::RootWindowController* controller =
490 internal::RootWindowController::ForTargetRootWindow();
491 if (!controller->GetSystemTray()->HasSystemBubble()) {
492 controller->GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW);
493 return true;
494 }
495 return false;
496 }
497
498 bool HandleShowTaskManager() {
499 content::RecordAction(
500 content::UserMetricsAction("Accel_Show_Task_Manager"));
501 Shell::GetInstance()->new_window_delegate()->ShowTaskManager();
502 return true;
503 }
504
505 void HandleSilenceSpokenFeedback() {
506 content::RecordAction(
507 content::UserMetricsAction("Accel_Silence_Spoken_Feedback"));
508
509 AccessibilityDelegate* delegate =
510 Shell::GetInstance()->accessibility_delegate();
511 if (!delegate->IsSpokenFeedbackEnabled())
512 return;
513 delegate->SilenceSpokenFeedback();
514 }
515
516 bool HandleSwitchIme(ImeControlDelegate* ime_control_delegate,
517 const ui::Accelerator& accelerator) {
518 content::RecordAction(
519 content::UserMetricsAction("Accel_Switch_Ime"));
520 if (ime_control_delegate)
521 return ime_control_delegate->HandleSwitchIme(accelerator);
522 return false;
523 }
524
525 bool HandleTakePartialScreenshot(ScreenshotDelegate* screenshot_delegate) {
526 content::RecordAction(
527 content::UserMetricsAction("Accel_Take_Partial_Screenshot"));
528 if (screenshot_delegate) {
529 ash::PartialScreenshotView::StartPartialScreenshot(
530 screenshot_delegate);
531 }
532 // Return true to prevent propagation of the key event because
533 // this key combination is reserved for partial screenshot.
534 return true;
535 }
536
537 bool HandleTakeScreenshot(ScreenshotDelegate* screenshot_delegate) {
538 content::RecordAction(
539 content::UserMetricsAction("Accel_Take_Screenshot"));
540 if (screenshot_delegate &&
541 screenshot_delegate->CanTakeScreenshot()) {
542 screenshot_delegate->HandleTakeScreenshotForAllRootWindows();
543 }
544 // Return true to prevent propagation of the key event.
545 return true;
546 }
547
548 bool HandleToggleAppList(ui::KeyboardCode key_code,
549 ui::EventType previous_event_type,
550 ui::KeyboardCode previous_key_code,
551 const ui::Accelerator& accelerator) {
552 // If something else was pressed between the Search key (LWIN)
553 // being pressed and released, then ignore the release of the
554 // Search key.
555 if (key_code == ui::VKEY_LWIN &&
556 (previous_event_type == ui::ET_KEY_RELEASED ||
557 previous_key_code != ui::VKEY_LWIN))
558 return false;
559 if (key_code == ui::VKEY_LWIN)
560 content::RecordAction(content::UserMetricsAction("Accel_Search_LWin"));
561 // When spoken feedback is enabled, we should neither toggle the list nor
562 // consume the key since Search+Shift is one of the shortcuts the a11y
563 // feature uses. crbug.com/132296
564 DCHECK_EQ(ui::VKEY_LWIN, accelerator.key_code());
565 if (Shell::GetInstance()->accessibility_delegate()->
566 IsSpokenFeedbackEnabled())
567 return false;
568 ash::Shell::GetInstance()->ToggleAppList(NULL);
569 return true;
570 }
571
572 bool HandleToggleCapsLock(ui::KeyboardCode key_code,
573 ui::EventType previous_event_type,
574 ui::KeyboardCode previous_key_code) {
575 Shell* shell = Shell::GetInstance();
576 if (key_code == ui::VKEY_LWIN) {
577 // If something else was pressed between the Search key (LWIN)
578 // being pressed and released, then ignore the release of the
579 // Search key.
580 // TODO(danakj): Releasing Alt first breaks this: crbug.com/166495
581 if (previous_event_type == ui::ET_KEY_RELEASED ||
582 previous_key_code != ui::VKEY_LWIN)
583 return false;
584 }
585 content::RecordAction(
586 content::UserMetricsAction("Accel_Toggle_Caps_Lock"));
587 shell->caps_lock_delegate()->ToggleCapsLock();
588 return true;
589 }
590
591 bool HandleToggleFullscreen(ui::KeyboardCode key_code) {
592 if (key_code == ui::VKEY_MEDIA_LAUNCH_APP2) {
593 content::RecordAction(
594 content::UserMetricsAction("Accel_Fullscreen_F4"));
595 }
596 accelerators::ToggleFullscreen();
597 return true;
598 }
599
289 bool HandleToggleRootWindowFullScreen() { 600 bool HandleToggleRootWindowFullScreen() {
290 Shell::GetPrimaryRootWindow()->GetDispatcher()->host()->ToggleFullScreen(); 601 Shell::GetPrimaryRootWindow()->GetDispatcher()->host()->ToggleFullScreen();
291 return true; 602 return true;
292 } 603 }
293 604
294 // Magnify the screen 605 bool HandleWindowSnap(int action) {
295 bool HandleMagnifyScreen(int delta_index) { 606 wm::WindowState* window_state = wm::GetActiveWindowState();
296 if (ash::Shell::GetInstance()->magnification_controller()->IsEnabled()) { 607 // Disable window snapping shortcut key for full screen window due to
297 // TODO(yoshiki): Move the following logic to MagnificationController. 608 // http://crbug.com/135487.
298 float scale = 609 if (!window_state ||
299 ash::Shell::GetInstance()->magnification_controller()->GetScale(); 610 window_state->window()->type() != aura::client::WINDOW_TYPE_NORMAL ||
300 // Calculate rounded logarithm (base kMagnificationScaleFactor) of scale. 611 window_state->IsFullscreen()) {
301 int scale_index = 612 return false;
302 std::floor(std::log(scale) / std::log(kMagnificationScaleFactor) + 0.5);
303
304 int new_scale_index = std::max(0, std::min(8, scale_index + delta_index));
305
306 ash::Shell::GetInstance()->magnification_controller()->
307 SetScale(std::pow(kMagnificationScaleFactor, new_scale_index), true);
308 } else if (ash::Shell::GetInstance()->
309 partial_magnification_controller()->is_enabled()) {
310 float scale = delta_index > 0 ? kDefaultPartialMagnifiedScale : 1;
311 ash::Shell::GetInstance()->partial_magnification_controller()->
312 SetScale(scale);
313 } 613 }
314 614
615 if (action == WINDOW_SNAP_LEFT) {
616 content::RecordAction(
617 content::UserMetricsAction("Accel_Window_Snap_Left"));
618 } else {
619 content::RecordAction(
620 content::UserMetricsAction("Accel_Window_Snap_Right"));
621 }
622
623 internal::SnapSizer::SnapWindow(window_state,
624 action == WINDOW_SNAP_LEFT ? internal::SnapSizer::LEFT_EDGE :
625 internal::SnapSizer::RIGHT_EDGE);
315 return true; 626 return true;
316 } 627 }
317 628
318 bool HandleMediaNextTrack() { 629 #if defined(OS_CHROMEOS)
319 Shell::GetInstance()->media_delegate()->HandleMediaNextTrack(); 630 bool HandleAddRemoveDisplay() {
631 content::RecordAction(
632 content::UserMetricsAction("Accel_Add_Remove_Display"));
633 Shell::GetInstance()->display_manager()->AddRemoveDisplay();
320 return true; 634 return true;
321 } 635 }
322 636
323 bool HandleMediaPlayPause() { 637 bool HandleCrosh() {
324 Shell::GetInstance()->media_delegate()->HandleMediaPlayPause(); 638 content::RecordAction(
639 content::UserMetricsAction("Accel_Open_Crosh"));
640
641 Shell::GetInstance()->new_window_delegate()->OpenCrosh();
325 return true; 642 return true;
326 } 643 }
327 644
328 bool HandleMediaPrevTrack() { 645 bool HandleFileManager() {
329 Shell::GetInstance()->media_delegate()->HandleMediaPrevTrack(); 646 content::RecordAction(
647 content::UserMetricsAction("Accel_Open_File_Manager"));
648
649 Shell::GetInstance()->new_window_delegate()->OpenFileManager();
330 return true; 650 return true;
331 } 651 }
332 652
653 bool HandleLock(ui::KeyboardCode key_code) {
654 content::RecordAction(
655 content::UserMetricsAction("Accel_LockScreen_L"));
656 Shell::GetInstance()->session_state_delegate()->LockScreen();
657 return true;
658 }
659
660 bool HandleSwitchToNextUser() {
661 content::RecordAction(
662 content::UserMetricsAction("Accel_Switch_To_Next_User"));
663
664 if (!Shell::GetInstance()->delegate()->IsMultiProfilesEnabled())
665 return false;
666 ash::SessionStateDelegate* delegate =
667 ash::Shell::GetInstance()->session_state_delegate();
668 if (delegate->NumberOfLoggedInUsers() <= 1)
669 return false;
670 MultiProfileUMA::RecordSwitchActiveUser(
671 MultiProfileUMA::SWITCH_ACTIVE_USER_BY_ACCELERATOR);
672 delegate->SwitchActiveUserToNext();
673 return true;
674 }
675
676 bool HandleToggleMirrorMode() {
677 content::RecordAction(
678 content::UserMetricsAction("Accel_Toggle_Mirror_Mode"));
679 Shell::GetInstance()->display_controller()->ToggleMirrorMode();
680 return true;
681 }
682
683 bool HandleToggleSpokenFeedback() {
684 content::RecordAction(
685 content::UserMetricsAction("Accel_Toggle_Spoken_Feedback"));
686
687 Shell::GetInstance()->accessibility_delegate()->
688 ToggleSpokenFeedback(A11Y_NOTIFICATION_SHOW);
689 return true;
690 }
691
692 bool HandleTouchHudClear() {
693 internal::RootWindowController* controller =
694 internal::RootWindowController::ForTargetRootWindow();
695 if (controller->touch_hud_debug()) {
696 controller->touch_hud_debug()->Clear();
697 return true;
698 }
699 return false;
700 }
701
702 bool HandleTouchHudModeChange() {
703 internal::RootWindowController* controller =
704 internal::RootWindowController::ForTargetRootWindow();
705 if (controller->touch_hud_debug()) {
706 controller->touch_hud_debug()->ChangeToNextMode();
707 return true;
708 }
709 return false;
710 }
711
712 bool HandleTouchHudProjectToggle() {
713 content::RecordAction(
714 content::UserMetricsAction("Accel_Touch_Hud_Clear"));
715 bool enabled = Shell::GetInstance()->is_touch_hud_projection_enabled();
716 Shell::GetInstance()->SetTouchHudProjectionEnabled(!enabled);
717 return true;
718 }
719
720 #endif // defined(OS_CHROMEOS)
721
722 // Debug print methods.
723
333 bool HandlePrintLayerHierarchy() { 724 bool HandlePrintLayerHierarchy() {
334 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 725 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
335 for (size_t i = 0; i < root_windows.size(); ++i) { 726 for (size_t i = 0; i < root_windows.size(); ++i) {
336 ui::PrintLayerHierarchy( 727 ui::PrintLayerHierarchy(
337 root_windows[i]->layer(), 728 root_windows[i]->layer(),
338 root_windows[i]->GetDispatcher()->GetLastMouseLocationInRoot()); 729 root_windows[i]->GetDispatcher()->GetLastMouseLocationInRoot());
339 } 730 }
340 return true; 731 return true;
341 } 732 }
342 733
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 // 949 //
559 // If your accelerator invokes more than one line of code, please either 950 // If your accelerator invokes more than one line of code, please either
560 // implement it in your module's controller code (like TOGGLE_MIRROR_MODE 951 // implement it in your module's controller code (like TOGGLE_MIRROR_MODE
561 // below) or pull it into a HandleFoo() function above. 952 // below) or pull it into a HandleFoo() function above.
562 switch (action) { 953 switch (action) {
563 case ACCESSIBLE_FOCUS_NEXT: 954 case ACCESSIBLE_FOCUS_NEXT:
564 return HandleAccessibleFocusCycle(false); 955 return HandleAccessibleFocusCycle(false);
565 case ACCESSIBLE_FOCUS_PREVIOUS: 956 case ACCESSIBLE_FOCUS_PREVIOUS:
566 return HandleAccessibleFocusCycle(true); 957 return HandleAccessibleFocusCycle(true);
567 case CYCLE_BACKWARD_MRU: 958 case CYCLE_BACKWARD_MRU:
568 HandleCycleBackwardMRU(accelerator); 959 return HandleCycleBackwardMRU(accelerator);
569 return true;
570 case CYCLE_FORWARD_MRU: 960 case CYCLE_FORWARD_MRU:
571 HandleCycleForwardMRU(accelerator); 961 return HandleCycleForwardMRU(accelerator);
572 return true;
573 case CYCLE_LINEAR: 962 case CYCLE_LINEAR:
574 HandleCycleLinear(accelerator); 963 return HandleCycleLinear(accelerator);
575 return true;
576 #if defined(OS_CHROMEOS) 964 #if defined(OS_CHROMEOS)
577 case ADD_REMOVE_DISPLAY: 965 case ADD_REMOVE_DISPLAY:
578 Shell::GetInstance()->display_manager()->AddRemoveDisplay(); 966 return HandleAddRemoveDisplay();
579 return true;
580 case TOGGLE_MIRROR_MODE: 967 case TOGGLE_MIRROR_MODE:
581 Shell::GetInstance()->display_controller()->ToggleMirrorMode(); 968 return HandleToggleMirrorMode();
582 return true;
583 case LOCK_SCREEN: 969 case LOCK_SCREEN:
584 if (key_code == ui::VKEY_L) 970 return HandleLock(key_code);
585 content::RecordAction(content::UserMetricsAction("Accel_LockScreen_L"));
586 return HandleLock();
587 case OPEN_FILE_MANAGER: 971 case OPEN_FILE_MANAGER:
588 return HandleFileManager(); 972 return HandleFileManager();
589 case OPEN_CROSH: 973 case OPEN_CROSH:
590 return HandleCrosh(); 974 return HandleCrosh();
591 case SILENCE_SPOKEN_FEEDBACK: 975 case SILENCE_SPOKEN_FEEDBACK:
592 HandleSilenceSpokenFeedback(); 976 HandleSilenceSpokenFeedback();
593 break; 977 break;
594 case SWAP_PRIMARY_DISPLAY: 978 case SWAP_PRIMARY_DISPLAY:
595 Shell::GetInstance()->display_controller()->SwapPrimaryDisplay(); 979 return HandleSwapPrimaryDisplay();
596 return true;
597 case SWITCH_TO_NEXT_USER: 980 case SWITCH_TO_NEXT_USER:
598 return SwitchToNextUser(); 981 return HandleSwitchToNextUser();
599 case TOGGLE_SPOKEN_FEEDBACK: 982 case TOGGLE_SPOKEN_FEEDBACK:
600 return HandleToggleSpokenFeedback(); 983 return HandleToggleSpokenFeedback();
601 case TOGGLE_WIFI: 984 case TOGGLE_WIFI:
602 Shell::GetInstance()->system_tray_notifier()->NotifyRequestToggleWifi(); 985 Shell::GetInstance()->system_tray_notifier()->NotifyRequestToggleWifi();
603 return true; 986 return true;
604 case TOUCH_HUD_CLEAR: { 987 case TOUCH_HUD_CLEAR:
605 internal::RootWindowController* controller = 988 return HandleTouchHudClear();
606 internal::RootWindowController::ForTargetRootWindow(); 989 case TOUCH_HUD_MODE_CHANGE:
607 if (controller->touch_hud_debug()) { 990 return HandleTouchHudModeChange();
608 controller->touch_hud_debug()->Clear(); 991 case TOUCH_HUD_PROJECTION_TOGGLE:
609 return true; 992 return HandleTouchHudProjectToggle();
610 }
611 return false;
612 }
613 case TOUCH_HUD_MODE_CHANGE: {
614 internal::RootWindowController* controller =
615 internal::RootWindowController::ForTargetRootWindow();
616 if (controller->touch_hud_debug()) {
617 controller->touch_hud_debug()->ChangeToNextMode();
618 return true;
619 }
620 return false;
621 }
622 case TOUCH_HUD_PROJECTION_TOGGLE: {
623 bool enabled = Shell::GetInstance()->is_touch_hud_projection_enabled();
624 Shell::GetInstance()->SetTouchHudProjectionEnabled(!enabled);
625 return true;
626 }
627 case DISABLE_GPU_WATCHDOG: 993 case DISABLE_GPU_WATCHDOG:
628 content::GpuDataManager::GetInstance()->DisableGpuWatchdog(); 994 content::GpuDataManager::GetInstance()->DisableGpuWatchdog();
629 return true; 995 return true;
630 #endif 996 #endif // OS_CHROMEOS
631 case OPEN_FEEDBACK_PAGE: 997 case OPEN_FEEDBACK_PAGE:
632 ash::Shell::GetInstance()->new_window_delegate()->OpenFeedbackPage(); 998 return HandleOpenFeedbackPage();
633 return true;
634 case EXIT: 999 case EXIT:
635 // UMA metrics are recorded in the handler. 1000 // UMA metrics are recorded in the handler.
636 exit_warning_handler_.HandleAccelerator(); 1001 exit_warning_handler_.HandleAccelerator();
637 return true; 1002 return true;
638 case NEW_INCOGNITO_WINDOW: { 1003 case NEW_INCOGNITO_WINDOW:
639 bool incognito_allowed = 1004 return HandleNewIncognitoWindow();
640 Shell::GetInstance()->delegate()->IsIncognitoAllowed();
641 if (incognito_allowed)
642 Shell::GetInstance()->new_window_delegate()->NewWindow(
643 true /* is_incognito */);
644 return incognito_allowed;
645 }
646 case NEW_TAB: 1005 case NEW_TAB:
647 if (key_code == ui::VKEY_T) 1006 return HandleNewTab(key_code);
648 content::RecordAction(content::UserMetricsAction("Accel_NewTab_T"));
649 Shell::GetInstance()->new_window_delegate()->NewTab();
650 return true;
651 case NEW_WINDOW: 1007 case NEW_WINDOW:
652 Shell::GetInstance()->new_window_delegate()->NewWindow( 1008 return HandleNewWindow();
653 false /* is_incognito */);
654 return true;
655 case RESTORE_TAB: 1009 case RESTORE_TAB:
656 Shell::GetInstance()->new_window_delegate()->RestoreTab(); 1010 return HandleRestoreTab();
657 return true;
658 case TAKE_SCREENSHOT: 1011 case TAKE_SCREENSHOT:
659 if (screenshot_delegate_.get() && 1012 return HandleTakeScreenshot(screenshot_delegate_.get());
660 screenshot_delegate_->CanTakeScreenshot()) {
661 screenshot_delegate_->HandleTakeScreenshotForAllRootWindows();
662 }
663 // Return true to prevent propagation of the key event.
664 return true;
665 case TAKE_PARTIAL_SCREENSHOT: 1013 case TAKE_PARTIAL_SCREENSHOT:
666 if (screenshot_delegate_) { 1014 return HandleTakePartialScreenshot(screenshot_delegate_.get());
667 ash::PartialScreenshotView::StartPartialScreenshot(
668 screenshot_delegate_.get());
669 }
670 // Return true to prevent propagation of the key event because
671 // this key combination is reserved for partial screenshot.
672 return true;
673 case TOGGLE_APP_LIST: 1015 case TOGGLE_APP_LIST:
674 // If something else was pressed between the Search key (LWIN) 1016 return HandleToggleAppList(
675 // being pressed and released, then ignore the release of the 1017 key_code, previous_event_type, previous_key_code, accelerator);
676 // Search key.
677 if (key_code == ui::VKEY_LWIN &&
678 (previous_event_type == ui::ET_KEY_RELEASED ||
679 previous_key_code != ui::VKEY_LWIN))
680 return false;
681 if (key_code == ui::VKEY_LWIN)
682 content::RecordAction(content::UserMetricsAction("Accel_Search_LWin"));
683 // When spoken feedback is enabled, we should neither toggle the list nor
684 // consume the key since Search+Shift is one of the shortcuts the a11y
685 // feature uses. crbug.com/132296
686 DCHECK_EQ(ui::VKEY_LWIN, accelerator.key_code());
687 if (Shell::GetInstance()->accessibility_delegate()->
688 IsSpokenFeedbackEnabled())
689 return false;
690 ash::Shell::GetInstance()->ToggleAppList(NULL);
691 return true;
692 case DISABLE_CAPS_LOCK: 1018 case DISABLE_CAPS_LOCK:
693 if (previous_event_type == ui::ET_KEY_RELEASED || 1019 return HandleDisableCapsLock(
694 (previous_key_code != ui::VKEY_LSHIFT && 1020 key_code, previous_event_type, previous_key_code);
695 previous_key_code != ui::VKEY_SHIFT &&
696 previous_key_code != ui::VKEY_RSHIFT)) {
697 // If something else was pressed between the Shift key being pressed
698 // and released, then ignore the release of the Shift key.
699 return false;
700 }
701 if (shell->caps_lock_delegate()->IsCapsLockEnabled()) {
702 shell->caps_lock_delegate()->SetCapsLockEnabled(false);
703 return true;
704 }
705 return false;
706 case TOGGLE_CAPS_LOCK: 1021 case TOGGLE_CAPS_LOCK:
707 if (key_code == ui::VKEY_LWIN) { 1022 return HandleToggleCapsLock(
708 // If something else was pressed between the Search key (LWIN) 1023 key_code, previous_event_type, previous_key_code);
709 // being pressed and released, then ignore the release of the
710 // Search key.
711 // TODO(danakj): Releasing Alt first breaks this: crbug.com/166495
712 if (previous_event_type == ui::ET_KEY_RELEASED ||
713 previous_key_code != ui::VKEY_LWIN)
714 return false;
715 }
716 shell->caps_lock_delegate()->ToggleCapsLock();
717 return true;
718 case BRIGHTNESS_DOWN: 1024 case BRIGHTNESS_DOWN:
719 if (brightness_control_delegate_) 1025 if (brightness_control_delegate_)
720 return brightness_control_delegate_->HandleBrightnessDown(accelerator); 1026 return brightness_control_delegate_->HandleBrightnessDown(accelerator);
721 break; 1027 break;
722 case BRIGHTNESS_UP: 1028 case BRIGHTNESS_UP:
723 if (brightness_control_delegate_) 1029 if (brightness_control_delegate_)
724 return brightness_control_delegate_->HandleBrightnessUp(accelerator); 1030 return brightness_control_delegate_->HandleBrightnessUp(accelerator);
725 break; 1031 break;
726 case KEYBOARD_BRIGHTNESS_DOWN: 1032 case KEYBOARD_BRIGHTNESS_DOWN:
727 if (keyboard_brightness_control_delegate_) 1033 if (keyboard_brightness_control_delegate_)
(...skipping 14 matching lines...) Expand all
742 ash::VolumeControlDelegate* volume_delegate = 1048 ash::VolumeControlDelegate* volume_delegate =
743 shell->system_tray_delegate()->GetVolumeControlDelegate(); 1049 shell->system_tray_delegate()->GetVolumeControlDelegate();
744 return volume_delegate && volume_delegate->HandleVolumeDown(accelerator); 1050 return volume_delegate && volume_delegate->HandleVolumeDown(accelerator);
745 } 1051 }
746 case VOLUME_UP: { 1052 case VOLUME_UP: {
747 ash::VolumeControlDelegate* volume_delegate = 1053 ash::VolumeControlDelegate* volume_delegate =
748 shell->system_tray_delegate()->GetVolumeControlDelegate(); 1054 shell->system_tray_delegate()->GetVolumeControlDelegate();
749 return volume_delegate && volume_delegate->HandleVolumeUp(accelerator); 1055 return volume_delegate && volume_delegate->HandleVolumeUp(accelerator);
750 } 1056 }
751 case FOCUS_LAUNCHER: 1057 case FOCUS_LAUNCHER:
752 return shell->focus_cycler()->FocusWidget( 1058 return HandleFocusLauncher();
753 Launcher::ForPrimaryDisplay()->shelf_widget());
754 case FOCUS_NEXT_PANE: 1059 case FOCUS_NEXT_PANE:
755 return HandleRotatePaneFocus(Shell::FORWARD); 1060 return HandleRotatePaneFocus(Shell::FORWARD);
756 case FOCUS_PREVIOUS_PANE: 1061 case FOCUS_PREVIOUS_PANE:
757 return HandleRotatePaneFocus(Shell::BACKWARD); 1062 return HandleRotatePaneFocus(Shell::BACKWARD);
758 case SHOW_KEYBOARD_OVERLAY: 1063 case SHOW_KEYBOARD_OVERLAY:
759 ash::Shell::GetInstance()->new_window_delegate()->ShowKeyboardOverlay(); 1064 return HandleShowKeyboardOverlay();
760 return true;
761 case SHOW_OAK: 1065 case SHOW_OAK:
762 if (CommandLine::ForCurrentProcess()->HasSwitch( 1066 return HandleShowOak();
763 switches::kAshEnableOak)) { 1067 case SHOW_SYSTEM_TRAY_BUBBLE:
764 oak::ShowOakWindowWithContext(Shell::GetPrimaryRootWindow()); 1068 return HandleShowSystemTrayBubble();
765 return true; 1069 case SHOW_MESSAGE_CENTER_BUBBLE:
766 } 1070 HandleShowMessageCenterBubble();
767 break; 1071 break;
768 case SHOW_SYSTEM_TRAY_BUBBLE: {
769 internal::RootWindowController* controller =
770 internal::RootWindowController::ForTargetRootWindow();
771 if (!controller->GetSystemTray()->HasSystemBubble()) {
772 controller->GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW);
773 return true;
774 }
775 break;
776 }
777 case SHOW_MESSAGE_CENTER_BUBBLE: {
778 internal::RootWindowController* controller =
779 internal::RootWindowController::ForTargetRootWindow();
780 internal::StatusAreaWidget* status_area_widget =
781 controller->shelf()->status_area_widget();
782 if (status_area_widget) {
783 WebNotificationTray* notification_tray =
784 status_area_widget->web_notification_tray();
785 if (notification_tray->visible())
786 notification_tray->ShowMessageCenterBubble();
787 }
788 break;
789 }
790 case SHOW_TASK_MANAGER: 1072 case SHOW_TASK_MANAGER:
791 Shell::GetInstance()->new_window_delegate()->ShowTaskManager(); 1073 return HandleShowTaskManager();
792 return true;
793 case NEXT_IME: 1074 case NEXT_IME:
794 // This check is necessary e.g. not to process the Shift+Alt+ 1075 return HandleNextIme(
795 // ET_KEY_RELEASED accelerator for Chrome OS (see ash/accelerators/ 1076 ime_control_delegate_.get(), previous_event_type, previous_key_code);
796 // accelerator_controller.cc) when Shift+Alt+Tab is pressed and then Tab
797 // is released.
798 if (previous_event_type == ui::ET_KEY_RELEASED &&
799 // Workaround for crbug.com/139556. CJK IME users tend to press
800 // Enter (or Space) and Shift+Alt almost at the same time to commit
801 // an IME string and then switch from the IME to the English layout.
802 // This workaround allows the user to trigger NEXT_IME even if the
803 // user presses Shift+Alt before releasing Enter.
804 // TODO(nona|mazda): Fix crbug.com/139556 in a cleaner way.
805 previous_key_code != ui::VKEY_RETURN &&
806 previous_key_code != ui::VKEY_SPACE) {
807 // We totally ignore this accelerator.
808 // TODO(mazda): Fix crbug.com/158217
809 return false;
810 }
811 if (ime_control_delegate_)
812 return ime_control_delegate_->HandleNextIme();
813 break;
814 case PREVIOUS_IME: 1077 case PREVIOUS_IME:
815 if (ime_control_delegate_) 1078 return HandlePreviousIme(ime_control_delegate_.get(), accelerator);
816 return ime_control_delegate_->HandlePreviousIme(accelerator);
817 break;
818 case PRINT_UI_HIERARCHIES: 1079 case PRINT_UI_HIERARCHIES:
819 return HandlePrintUIHierarchies(); 1080 return HandlePrintUIHierarchies();
820 case SWITCH_IME: 1081 case SWITCH_IME:
821 if (ime_control_delegate_) 1082 return HandleSwitchIme(ime_control_delegate_.get(), accelerator);
822 return ime_control_delegate_->HandleSwitchIme(accelerator);
823 break;
824 case LAUNCH_APP_0: 1083 case LAUNCH_APP_0:
825 Launcher::ForPrimaryDisplay()->LaunchAppIndexAt(0); 1084 return HandleLaunchAppN(0);
826 return true;
827 case LAUNCH_APP_1: 1085 case LAUNCH_APP_1:
828 Launcher::ForPrimaryDisplay()->LaunchAppIndexAt(1); 1086 return HandleLaunchAppN(1);
829 return true;
830 case LAUNCH_APP_2: 1087 case LAUNCH_APP_2:
831 Launcher::ForPrimaryDisplay()->LaunchAppIndexAt(2); 1088 return HandleLaunchAppN(2);
832 return true;
833 case LAUNCH_APP_3: 1089 case LAUNCH_APP_3:
834 Launcher::ForPrimaryDisplay()->LaunchAppIndexAt(3); 1090 return HandleLaunchAppN(3);
835 return true;
836 case LAUNCH_APP_4: 1091 case LAUNCH_APP_4:
837 Launcher::ForPrimaryDisplay()->LaunchAppIndexAt(4); 1092 return HandleLaunchAppN(4);
838 return true;
839 case LAUNCH_APP_5: 1093 case LAUNCH_APP_5:
840 Launcher::ForPrimaryDisplay()->LaunchAppIndexAt(5); 1094 return HandleLaunchAppN(5);
841 return true;
842 case LAUNCH_APP_6: 1095 case LAUNCH_APP_6:
843 Launcher::ForPrimaryDisplay()->LaunchAppIndexAt(6); 1096 return HandleLaunchAppN(6);
844 return true;
845 case LAUNCH_APP_7: 1097 case LAUNCH_APP_7:
846 Launcher::ForPrimaryDisplay()->LaunchAppIndexAt(7); 1098 return HandleLaunchAppN(7);
847 return true;
848 case LAUNCH_LAST_APP: 1099 case LAUNCH_LAST_APP:
849 Launcher::ForPrimaryDisplay()->LaunchAppIndexAt(-1); 1100 return HandleLaunchLastApp();
850 return true;
851 case WINDOW_SNAP_LEFT: 1101 case WINDOW_SNAP_LEFT:
852 case WINDOW_SNAP_RIGHT: { 1102 case WINDOW_SNAP_RIGHT:
853 wm::WindowState* window_state = wm::GetActiveWindowState(); 1103 return HandleWindowSnap(action);
854 // Disable window snapping shortcut key for full screen window due to
855 // http://crbug.com/135487.
856 if (!window_state ||
857 window_state->window()->type() != aura::client::WINDOW_TYPE_NORMAL ||
858 window_state->IsFullscreen()) {
859 break;
860 }
861
862 internal::SnapSizer::SnapWindow(window_state,
863 action == WINDOW_SNAP_LEFT ? internal::SnapSizer::LEFT_EDGE :
864 internal::SnapSizer::RIGHT_EDGE);
865 return true;
866 }
867 case WINDOW_MINIMIZE: 1104 case WINDOW_MINIMIZE:
868 return accelerators::ToggleMinimized(); 1105 return accelerators::ToggleMinimized();
869 case TOGGLE_FULLSCREEN: { 1106 case TOGGLE_FULLSCREEN:
870 if (key_code == ui::VKEY_MEDIA_LAUNCH_APP2) { 1107 return HandleToggleFullscreen(key_code);
871 content::RecordAction( 1108 case TOGGLE_MAXIMIZED:
872 content::UserMetricsAction("Accel_Fullscreen_F4"));
873 }
874 accelerators::ToggleFullscreen();
875 return true;
876 }
877 case TOGGLE_MAXIMIZED: {
878 accelerators::ToggleMaximized(); 1109 accelerators::ToggleMaximized();
879 return true; 1110 return true;
880 } 1111 case WINDOW_POSITION_CENTER:
881 case WINDOW_POSITION_CENTER: { 1112 return HandlePositionCenter();
882 content::RecordAction(content::UserMetricsAction("Accel_Center"));
883 aura::Window* window = wm::GetActiveWindow();
884 // Docked windows do not support centering and ignore accelerator.
885 if (window && !wm::GetWindowState(window)->IsDocked()) {
886 wm::CenterWindow(window);
887 return true;
888 }
889 break;
890 }
891 case SCALE_UI_UP: 1113 case SCALE_UI_UP:
892 return HandleScaleUI(true /* up */); 1114 return HandleScaleUI(true /* up */);
893 case SCALE_UI_DOWN: 1115 case SCALE_UI_DOWN:
894 return HandleScaleUI(false /* down */); 1116 return HandleScaleUI(false /* down */);
895 case SCALE_UI_RESET: 1117 case SCALE_UI_RESET:
896 return HandleScaleReset(); 1118 return HandleScaleReset();
897 case ROTATE_WINDOW: 1119 case ROTATE_WINDOW:
898 return HandleRotateActiveWindow(); 1120 return HandleRotateActiveWindow();
899 case ROTATE_SCREEN: 1121 case ROTATE_SCREEN:
900 return HandleRotateScreen(); 1122 return HandleRotateScreen();
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 keyboard_brightness_control_delegate) { 1229 keyboard_brightness_control_delegate) {
1008 keyboard_brightness_control_delegate_ = 1230 keyboard_brightness_control_delegate_ =
1009 keyboard_brightness_control_delegate.Pass(); 1231 keyboard_brightness_control_delegate.Pass();
1010 } 1232 }
1011 1233
1012 bool AcceleratorController::CanHandleAccelerators() const { 1234 bool AcceleratorController::CanHandleAccelerators() const {
1013 return true; 1235 return true;
1014 } 1236 }
1015 1237
1016 } // namespace ash 1238 } // namespace ash
OLDNEW
« no previous file with comments | « ash/accelerators/accelerator_commands.cc ('k') | ash/shell_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698