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

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

Issue 23654011: ash: Clean up window cycling accelerator code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | ash/accelerators/accelerator_controller_unittest.cc » ('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 #else 85 #else
86 return true; 86 return true;
87 #endif 87 #endif
88 } 88 }
89 89
90 bool OverviewEnabled() { 90 bool OverviewEnabled() {
91 return !CommandLine::ForCurrentProcess()->HasSwitch( 91 return !CommandLine::ForCurrentProcess()->HasSwitch(
92 switches::kAshDisableOverviewMode); 92 switches::kAshDisableOverviewMode);
93 } 93 }
94 94
95 bool HandleCycleWindowMRU(WindowCycleController::Direction direction, 95 void HandleCycleBackwardMRU(const ui::Accelerator& accelerator) {
96 bool is_alt_down) { 96 Shell* shell = Shell::GetInstance();
97 Shell::GetInstance()-> 97
98 window_cycle_controller()->HandleCycleWindow(direction, is_alt_down); 98 if (accelerator.key_code() == ui::VKEY_TAB)
99 // Always report we handled the key, even if the window didn't change. 99 shell->delegate()->RecordUserMetricsAction(UMA_ACCEL_PREVWINDOW_TAB);
100 return true; 100
101 if (OverviewEnabled()) {
102 shell->window_selector_controller()->HandleCycleWindow(
103 WindowSelector::BACKWARD);
104 return;
105 }
106 shell->window_cycle_controller()->HandleCycleWindow(
107 WindowCycleController::BACKWARD, accelerator.IsAltDown());
101 } 108 }
102 109
103 bool HandleCycleWindowOverviewMRU(WindowSelector::Direction direction) { 110 void HandleCycleForwardMRU(const ui::Accelerator& accelerator) {
104 Shell::GetInstance()-> 111 Shell* shell = Shell::GetInstance();
105 window_selector_controller()->HandleCycleWindow(direction); 112
106 return true; 113 if (accelerator.key_code() == ui::VKEY_TAB)
114 shell->delegate()->RecordUserMetricsAction(UMA_ACCEL_NEXTWINDOW_TAB);
115
116 if (OverviewEnabled()) {
117 shell->window_selector_controller()->HandleCycleWindow(
118 WindowSelector::FORWARD);
119 return;
120 }
121 shell->window_cycle_controller()->HandleCycleWindow(
122 WindowCycleController::FORWARD, accelerator.IsAltDown());
107 } 123 }
108 124
109 void HandleCycleWindowLinear(CycleDirection direction) { 125 void HandleCycleLinear(const ui::Accelerator& accelerator) {
110 Shell::GetInstance()-> 126 Shell* shell = Shell::GetInstance();
111 window_cycle_controller()->HandleLinearCycleWindow();
112 }
113 127
114 void ToggleOverviewMode() { 128 // TODO(jamescook): When overview becomes the default the AcceleratorAction
115 Shell::GetInstance()->window_selector_controller()->ToggleOverview(); 129 // should be renamed from CYCLE_LINEAR to TOGGLE_OVERVIEW.
130 if (OverviewEnabled()) {
131 shell->delegate()->RecordUserMetricsAction(UMA_ACCEL_OVERVIEW_F5);
132 shell->window_selector_controller()->ToggleOverview();
133 return;
134 }
135 if (accelerator.key_code() == ui::VKEY_MEDIA_LAUNCH_APP1)
136 shell->delegate()->RecordUserMetricsAction(UMA_ACCEL_NEXTWINDOW_F5);
137 shell->window_cycle_controller()->HandleLinearCycleWindow();
116 } 138 }
117 139
118 bool HandleAccessibleFocusCycle(bool reverse) { 140 bool HandleAccessibleFocusCycle(bool reverse) {
119 if (!Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled()) 141 if (!Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled())
120 return false; 142 return false;
121 aura::Window* active_window = ash::wm::GetActiveWindow(); 143 aura::Window* active_window = ash::wm::GetActiveWindow();
122 if (!active_window) 144 if (!active_window)
123 return false; 145 return false;
124 views::Widget* widget = 146 views::Widget* widget =
125 views::Widget::GetWidgetForNativeWindow(active_window); 147 views::Widget::GetWidgetForNativeWindow(active_window);
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 } 537 }
516 // Type of the previous accelerator. Used by NEXT_IME and DISABLE_CAPS_LOCK. 538 // Type of the previous accelerator. Used by NEXT_IME and DISABLE_CAPS_LOCK.
517 const ui::EventType previous_event_type = 539 const ui::EventType previous_event_type =
518 context_.previous_accelerator().type(); 540 context_.previous_accelerator().type();
519 const ui::KeyboardCode previous_key_code = 541 const ui::KeyboardCode previous_key_code =
520 context_.previous_accelerator().key_code(); 542 context_.previous_accelerator().key_code();
521 543
522 // You *MUST* return true when some action is performed. Otherwise, this 544 // You *MUST* return true when some action is performed. Otherwise, this
523 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent 545 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent
524 // and BrowserView::HandleKeyboardEvent, for a single accelerator press. 546 // and BrowserView::HandleKeyboardEvent, for a single accelerator press.
547 //
548 // If your accelerator invokes more than one line of code, please either
549 // implement it in your module's controller code (like TOGGLE_MIRROR_MODE
550 // below) or pull it into a HandleFoo() function above.
525 switch (action) { 551 switch (action) {
526 case ACCESSIBLE_FOCUS_NEXT: 552 case ACCESSIBLE_FOCUS_NEXT:
527 return HandleAccessibleFocusCycle(false); 553 return HandleAccessibleFocusCycle(false);
528 case ACCESSIBLE_FOCUS_PREVIOUS: 554 case ACCESSIBLE_FOCUS_PREVIOUS:
529 return HandleAccessibleFocusCycle(true); 555 return HandleAccessibleFocusCycle(true);
530 case CYCLE_BACKWARD_MRU: 556 case CYCLE_BACKWARD_MRU:
531 if (key_code == ui::VKEY_TAB) 557 HandleCycleBackwardMRU(accelerator);
532 shell->delegate()->RecordUserMetricsAction(UMA_ACCEL_PREVWINDOW_TAB); 558 return true;
533 if (OverviewEnabled())
534 return HandleCycleWindowOverviewMRU(WindowSelector::BACKWARD);
535 return HandleCycleWindowMRU(WindowCycleController::BACKWARD,
536 accelerator.IsAltDown());
537 case CYCLE_FORWARD_MRU: 559 case CYCLE_FORWARD_MRU:
538 if (key_code == ui::VKEY_TAB) 560 HandleCycleForwardMRU(accelerator);
539 shell->delegate()->RecordUserMetricsAction(UMA_ACCEL_NEXTWINDOW_TAB);
540 if (OverviewEnabled())
541 return HandleCycleWindowOverviewMRU(WindowSelector::FORWARD);
542 return HandleCycleWindowMRU(WindowCycleController::FORWARD,
543 accelerator.IsAltDown());
544 case CYCLE_BACKWARD_LINEAR:
545 if (OverviewEnabled()) {
546 shell->delegate()->RecordUserMetricsAction(UMA_ACCEL_OVERVIEW_F5);
547 ToggleOverviewMode();
548 return true;
549 }
550 if (key_code == ui::VKEY_MEDIA_LAUNCH_APP1)
551 shell->delegate()->RecordUserMetricsAction(UMA_ACCEL_PREVWINDOW_F5);
552 HandleCycleWindowLinear(CYCLE_BACKWARD);
553 return true; 561 return true;
554 case CYCLE_FORWARD_LINEAR: 562 case CYCLE_LINEAR:
555 if (OverviewEnabled()) { 563 HandleCycleLinear(accelerator);
556 shell->delegate()->RecordUserMetricsAction(UMA_ACCEL_OVERVIEW_F5);
557 ToggleOverviewMode();
558 return true;
559 }
560 if (key_code == ui::VKEY_MEDIA_LAUNCH_APP1)
561 shell->delegate()->RecordUserMetricsAction(UMA_ACCEL_NEXTWINDOW_F5);
562 HandleCycleWindowLinear(CYCLE_FORWARD);
563 return true; 564 return true;
564 #if defined(OS_CHROMEOS) 565 #if defined(OS_CHROMEOS)
565 case ADD_REMOVE_DISPLAY: 566 case ADD_REMOVE_DISPLAY:
566 Shell::GetInstance()->display_manager()->AddRemoveDisplay(); 567 Shell::GetInstance()->display_manager()->AddRemoveDisplay();
567 return true; 568 return true;
568 case TOGGLE_MIRROR_MODE: 569 case TOGGLE_MIRROR_MODE:
569 Shell::GetInstance()->display_controller()->ToggleMirrorMode(); 570 Shell::GetInstance()->display_controller()->ToggleMirrorMode();
570 return true; 571 return true;
571 case LOCK_SCREEN: 572 case LOCK_SCREEN:
572 if (key_code == ui::VKEY_L) 573 if (key_code == ui::VKEY_L)
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 HandleKeyboardBrightnessDown(accelerator); 711 HandleKeyboardBrightnessDown(accelerator);
711 break; 712 break;
712 case KEYBOARD_BRIGHTNESS_UP: 713 case KEYBOARD_BRIGHTNESS_UP:
713 if (keyboard_brightness_control_delegate_) 714 if (keyboard_brightness_control_delegate_)
714 return keyboard_brightness_control_delegate_-> 715 return keyboard_brightness_control_delegate_->
715 HandleKeyboardBrightnessUp(accelerator); 716 HandleKeyboardBrightnessUp(accelerator);
716 break; 717 break;
717 case VOLUME_MUTE: 718 case VOLUME_MUTE:
718 return shell->system_tray_delegate()->GetVolumeControlDelegate()-> 719 return shell->system_tray_delegate()->GetVolumeControlDelegate()->
719 HandleVolumeMute(accelerator); 720 HandleVolumeMute(accelerator);
720 break;
721 case VOLUME_DOWN: 721 case VOLUME_DOWN:
722 return shell->system_tray_delegate()->GetVolumeControlDelegate()-> 722 return shell->system_tray_delegate()->GetVolumeControlDelegate()->
723 HandleVolumeDown(accelerator); 723 HandleVolumeDown(accelerator);
724 break;
725 case VOLUME_UP: 724 case VOLUME_UP:
726 return shell->system_tray_delegate()->GetVolumeControlDelegate()-> 725 return shell->system_tray_delegate()->GetVolumeControlDelegate()->
727 HandleVolumeUp(accelerator); 726 HandleVolumeUp(accelerator);
728 break;
729 case FOCUS_LAUNCHER: 727 case FOCUS_LAUNCHER:
730 return shell->focus_cycler()->FocusWidget( 728 return shell->focus_cycler()->FocusWidget(
731 Launcher::ForPrimaryDisplay()->shelf_widget()); 729 Launcher::ForPrimaryDisplay()->shelf_widget());
732 break;
733 case FOCUS_NEXT_PANE: 730 case FOCUS_NEXT_PANE:
734 return HandleRotatePaneFocus(Shell::FORWARD); 731 return HandleRotatePaneFocus(Shell::FORWARD);
735 case FOCUS_PREVIOUS_PANE: 732 case FOCUS_PREVIOUS_PANE:
736 return HandleRotatePaneFocus(Shell::BACKWARD); 733 return HandleRotatePaneFocus(Shell::BACKWARD);
737 case SHOW_KEYBOARD_OVERLAY: 734 case SHOW_KEYBOARD_OVERLAY:
738 ash::Shell::GetInstance()->delegate()->ShowKeyboardOverlay(); 735 ash::Shell::GetInstance()->delegate()->ShowKeyboardOverlay();
739 return true; 736 return true;
740 case SHOW_OAK: 737 case SHOW_OAK:
741 if (CommandLine::ForCurrentProcess()->HasSwitch( 738 if (CommandLine::ForCurrentProcess()->HasSwitch(
742 switches::kAshEnableOak)) { 739 switches::kAshEnableOak)) {
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 keyboard_brightness_control_delegate) { 981 keyboard_brightness_control_delegate) {
985 keyboard_brightness_control_delegate_ = 982 keyboard_brightness_control_delegate_ =
986 keyboard_brightness_control_delegate.Pass(); 983 keyboard_brightness_control_delegate.Pass();
987 } 984 }
988 985
989 bool AcceleratorController::CanHandleAccelerators() const { 986 bool AcceleratorController::CanHandleAccelerators() const {
990 return true; 987 return true;
991 } 988 }
992 989
993 } // namespace ash 990 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/accelerators/accelerator_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698