Commit df99bbce authored by pkotwicz's avatar pkotwicz Committed by Commit bot

This CL:

- Alphabetises the switch statement in AcceleratorController::PerformAction()
- Removes "default" from switch statement in
  AcceleratorController::PerformAction()
- Makes several methods in AcceleratorController take AcceleratorAction instead
  of int as input
- Rearranges methods in accelerator_controller.cc to match order in .h file

BUG=404473
TEST=None
R=oshima
TBR=sky (For trivial addition of ifdef to chrome/browser/ui/views/accelerator_table.cc)

Review URL: https://codereview.chromium.org/729993002

Cr-Commit-Position: refs/heads/master@{#305066}
parent 03cbc9db
This diff is collapsed.
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <map> #include <map>
#include <set> #include <set>
#include "ash/accelerators/accelerator_table.h"
#include "ash/accelerators/exit_warning_handler.h" #include "ash/accelerators/exit_warning_handler.h"
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "base/basictypes.h" #include "base/basictypes.h"
...@@ -88,15 +89,11 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget { ...@@ -88,15 +89,11 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget {
// Performs the specified action if it is enabled. Returns whether the action // Performs the specified action if it is enabled. Returns whether the action
// was performed successfully. // was performed successfully.
bool PerformActionIfEnabled(int action); bool PerformActionIfEnabled(AcceleratorAction action);
// Returns the restriction for the current context. // Returns the restriction for the current context.
AcceleratorProcessingRestriction GetCurrentAcceleratorRestriction(); AcceleratorProcessingRestriction GetCurrentAcceleratorRestriction();
// Overridden from ui::AcceleratorTarget:
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
bool CanHandleAccelerators() const override;
void SetBrightnessControlDelegate( void SetBrightnessControlDelegate(
scoped_ptr<BrightnessControlDelegate> brightness_control_delegate); scoped_ptr<BrightnessControlDelegate> brightness_control_delegate);
void SetImeControlDelegate( void SetImeControlDelegate(
...@@ -119,6 +116,10 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget { ...@@ -119,6 +116,10 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget {
return previous_accelerator_; return previous_accelerator_;
} }
// Overridden from ui::AcceleratorTarget:
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
bool CanHandleAccelerators() const override;
private: private:
FRIEND_TEST_ALL_PREFIXES(AcceleratorControllerTest, GlobalAccelerators); FRIEND_TEST_ALL_PREFIXES(AcceleratorControllerTest, GlobalAccelerators);
FRIEND_TEST_ALL_PREFIXES(AcceleratorControllerTest, FRIEND_TEST_ALL_PREFIXES(AcceleratorControllerTest,
...@@ -134,7 +135,7 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget { ...@@ -134,7 +135,7 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget {
// Performs the specified action. The |accelerator| may provide additional // Performs the specified action. The |accelerator| may provide additional
// data the action needs. Returns whether an action was performed // data the action needs. Returns whether an action was performed
// successfully. // successfully.
bool PerformAction(int action, bool PerformAction(AcceleratorAction action,
const ui::Accelerator& accelerator); const ui::Accelerator& accelerator);
// Get the accelerator restriction for the given action. Supply an |action| // Get the accelerator restriction for the given action. Supply an |action|
...@@ -166,7 +167,7 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget { ...@@ -166,7 +167,7 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget {
// A map from accelerators to the AcceleratorAction values, which are used in // A map from accelerators to the AcceleratorAction values, which are used in
// the implementation. // the implementation.
std::map<ui::Accelerator, int> accelerators_; std::map<ui::Accelerator, AcceleratorAction> accelerators_;
// Actions allowed when the user is not signed in. // Actions allowed when the user is not signed in.
std::set<int> actions_allowed_at_login_screen_; std::set<int> actions_allowed_at_login_screen_;
......
...@@ -254,9 +254,6 @@ const AcceleratorAction kActionsAllowedAtLoginOrLockScreen[] = { ...@@ -254,9 +254,6 @@ const AcceleratorAction kActionsAllowedAtLoginOrLockScreen[] = {
DEBUG_PRINT_LAYER_HIERARCHY, DEBUG_PRINT_LAYER_HIERARCHY,
DEBUG_PRINT_VIEW_HIERARCHY, DEBUG_PRINT_VIEW_HIERARCHY,
DEBUG_PRINT_WINDOW_HIERARCHY, DEBUG_PRINT_WINDOW_HIERARCHY,
DISABLE_CAPS_LOCK,
KEYBOARD_BRIGHTNESS_DOWN,
KEYBOARD_BRIGHTNESS_UP,
MAGNIFY_SCREEN_ZOOM_IN, // Control+F7 MAGNIFY_SCREEN_ZOOM_IN, // Control+F7
MAGNIFY_SCREEN_ZOOM_OUT, // Control+F6 MAGNIFY_SCREEN_ZOOM_OUT, // Control+F6
NEXT_IME, NEXT_IME,
...@@ -267,18 +264,21 @@ const AcceleratorAction kActionsAllowedAtLoginOrLockScreen[] = { ...@@ -267,18 +264,21 @@ const AcceleratorAction kActionsAllowedAtLoginOrLockScreen[] = {
SWITCH_IME, // Switch to another IME depending on the accelerator. SWITCH_IME, // Switch to another IME depending on the accelerator.
TAKE_PARTIAL_SCREENSHOT, TAKE_PARTIAL_SCREENSHOT,
TAKE_SCREENSHOT, TAKE_SCREENSHOT,
TOGGLE_CAPS_LOCK,
TOGGLE_WIFI,
TOUCH_HUD_CLEAR,
VOLUME_DOWN, VOLUME_DOWN,
VOLUME_MUTE, VOLUME_MUTE,
VOLUME_UP, VOLUME_UP,
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
DEBUG_ADD_REMOVE_DISPLAY, DEBUG_ADD_REMOVE_DISPLAY,
DISABLE_CAPS_LOCK,
DISABLE_GPU_WATCHDOG, DISABLE_GPU_WATCHDOG,
KEYBOARD_BRIGHTNESS_DOWN,
KEYBOARD_BRIGHTNESS_UP,
TOGGLE_CAPS_LOCK,
TOGGLE_SPOKEN_FEEDBACK, TOGGLE_SPOKEN_FEEDBACK,
TOGGLE_TOUCH_VIEW_TESTING, TOGGLE_TOUCH_VIEW_TESTING,
TOGGLE_MIRROR_MODE, TOGGLE_MIRROR_MODE,
TOGGLE_WIFI,
TOUCH_HUD_CLEAR,
#endif #endif
#if defined(OS_CHROMEOS) && !defined(NDEBUG) #if defined(OS_CHROMEOS) && !defined(NDEBUG)
POWER_PRESSED, POWER_PRESSED,
...@@ -299,10 +299,7 @@ const size_t kActionsAllowedAtLockScreenLength = ...@@ -299,10 +299,7 @@ const size_t kActionsAllowedAtLockScreenLength =
const AcceleratorAction kActionsAllowedAtModalWindow[] = { const AcceleratorAction kActionsAllowedAtModalWindow[] = {
BRIGHTNESS_DOWN, BRIGHTNESS_DOWN,
BRIGHTNESS_UP, BRIGHTNESS_UP,
DISABLE_CAPS_LOCK,
EXIT, EXIT,
KEYBOARD_BRIGHTNESS_DOWN,
KEYBOARD_BRIGHTNESS_UP,
MAGNIFY_SCREEN_ZOOM_IN, MAGNIFY_SCREEN_ZOOM_IN,
MAGNIFY_SCREEN_ZOOM_OUT, MAGNIFY_SCREEN_ZOOM_OUT,
MEDIA_NEXT_TRACK, MEDIA_NEXT_TRACK,
...@@ -310,8 +307,6 @@ const AcceleratorAction kActionsAllowedAtModalWindow[] = { ...@@ -310,8 +307,6 @@ const AcceleratorAction kActionsAllowedAtModalWindow[] = {
MEDIA_PREV_TRACK, MEDIA_PREV_TRACK,
NEXT_IME, NEXT_IME,
OPEN_FEEDBACK_PAGE, OPEN_FEEDBACK_PAGE,
POWER_PRESSED,
POWER_RELEASED,
PREVIOUS_IME, PREVIOUS_IME,
PRINT_UI_HIERARCHIES, PRINT_UI_HIERARCHIES,
ROTATE_SCREEN, ROTATE_SCREEN,
...@@ -322,17 +317,22 @@ const AcceleratorAction kActionsAllowedAtModalWindow[] = { ...@@ -322,17 +317,22 @@ const AcceleratorAction kActionsAllowedAtModalWindow[] = {
SWITCH_IME, SWITCH_IME,
TAKE_PARTIAL_SCREENSHOT, TAKE_PARTIAL_SCREENSHOT,
TAKE_SCREENSHOT, TAKE_SCREENSHOT,
TOGGLE_CAPS_LOCK,
TOGGLE_WIFI,
VOLUME_DOWN, VOLUME_DOWN,
VOLUME_MUTE, VOLUME_MUTE,
VOLUME_UP, VOLUME_UP,
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
DEBUG_ADD_REMOVE_DISPLAY, DEBUG_ADD_REMOVE_DISPLAY,
DISABLE_CAPS_LOCK,
KEYBOARD_BRIGHTNESS_DOWN,
KEYBOARD_BRIGHTNESS_UP,
LOCK_SCREEN, LOCK_SCREEN,
POWER_PRESSED,
POWER_RELEASED,
SWAP_PRIMARY_DISPLAY, SWAP_PRIMARY_DISPLAY,
TOGGLE_CAPS_LOCK,
TOGGLE_MIRROR_MODE, TOGGLE_MIRROR_MODE,
TOGGLE_SPOKEN_FEEDBACK, TOGGLE_SPOKEN_FEEDBACK,
TOGGLE_WIFI,
#endif #endif
}; };
...@@ -365,17 +365,12 @@ const AcceleratorAction kActionsAllowedInAppMode[] = { ...@@ -365,17 +365,12 @@ const AcceleratorAction kActionsAllowedInAppMode[] = {
DEBUG_PRINT_LAYER_HIERARCHY, DEBUG_PRINT_LAYER_HIERARCHY,
DEBUG_PRINT_VIEW_HIERARCHY, DEBUG_PRINT_VIEW_HIERARCHY,
DEBUG_PRINT_WINDOW_HIERARCHY, DEBUG_PRINT_WINDOW_HIERARCHY,
DISABLE_CAPS_LOCK,
KEYBOARD_BRIGHTNESS_DOWN,
KEYBOARD_BRIGHTNESS_UP,
MAGNIFY_SCREEN_ZOOM_IN, // Control+F7 MAGNIFY_SCREEN_ZOOM_IN, // Control+F7
MAGNIFY_SCREEN_ZOOM_OUT, // Control+F6 MAGNIFY_SCREEN_ZOOM_OUT, // Control+F6
MEDIA_NEXT_TRACK, MEDIA_NEXT_TRACK,
MEDIA_PLAY_PAUSE, MEDIA_PLAY_PAUSE,
MEDIA_PREV_TRACK, MEDIA_PREV_TRACK,
NEXT_IME, NEXT_IME,
POWER_PRESSED,
POWER_RELEASED,
PREVIOUS_IME, PREVIOUS_IME,
PRINT_UI_HIERARCHIES, PRINT_UI_HIERARCHIES,
ROTATE_SCREEN, ROTATE_SCREEN,
...@@ -383,18 +378,23 @@ const AcceleratorAction kActionsAllowedInAppMode[] = { ...@@ -383,18 +378,23 @@ const AcceleratorAction kActionsAllowedInAppMode[] = {
SCALE_UI_RESET, SCALE_UI_RESET,
SCALE_UI_UP, SCALE_UI_UP,
SWITCH_IME, // Switch to another IME depending on the accelerator. SWITCH_IME, // Switch to another IME depending on the accelerator.
TOGGLE_CAPS_LOCK,
TOGGLE_WIFI,
TOUCH_HUD_CLEAR,
VOLUME_DOWN, VOLUME_DOWN,
VOLUME_MUTE, VOLUME_MUTE,
VOLUME_UP, VOLUME_UP,
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
DEBUG_ADD_REMOVE_DISPLAY, DEBUG_ADD_REMOVE_DISPLAY,
DISABLE_CAPS_LOCK,
DISABLE_GPU_WATCHDOG, DISABLE_GPU_WATCHDOG,
KEYBOARD_BRIGHTNESS_DOWN,
KEYBOARD_BRIGHTNESS_UP,
POWER_PRESSED,
POWER_RELEASED,
SWAP_PRIMARY_DISPLAY, SWAP_PRIMARY_DISPLAY,
TOGGLE_CAPS_LOCK,
TOGGLE_MIRROR_MODE, TOGGLE_MIRROR_MODE,
TOGGLE_SPOKEN_FEEDBACK, TOGGLE_SPOKEN_FEEDBACK,
TOGGLE_WIFI,
TOUCH_HUD_CLEAR,
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
}; };
......
...@@ -66,13 +66,10 @@ enum AcceleratorAction { ...@@ -66,13 +66,10 @@ enum AcceleratorAction {
DEBUG_TOGGLE_SHOW_DEBUG_BORDERS, DEBUG_TOGGLE_SHOW_DEBUG_BORDERS,
DEBUG_TOGGLE_SHOW_FPS_COUNTER, DEBUG_TOGGLE_SHOW_FPS_COUNTER,
DEBUG_TOGGLE_SHOW_PAINT_RECTS, DEBUG_TOGGLE_SHOW_PAINT_RECTS,
DISABLE_CAPS_LOCK,
EXIT, EXIT,
FOCUS_NEXT_PANE, FOCUS_NEXT_PANE,
FOCUS_PREVIOUS_PANE, FOCUS_PREVIOUS_PANE,
FOCUS_SHELF, FOCUS_SHELF,
KEYBOARD_BRIGHTNESS_DOWN,
KEYBOARD_BRIGHTNESS_UP,
LAUNCH_APP_0, LAUNCH_APP_0,
LAUNCH_APP_1, LAUNCH_APP_1,
LAUNCH_APP_2, LAUNCH_APP_2,
...@@ -82,8 +79,6 @@ enum AcceleratorAction { ...@@ -82,8 +79,6 @@ enum AcceleratorAction {
LAUNCH_APP_6, LAUNCH_APP_6,
LAUNCH_APP_7, LAUNCH_APP_7,
LAUNCH_LAST_APP, LAUNCH_LAST_APP,
LOCK_PRESSED,
LOCK_RELEASED,
MAGNIFY_SCREEN_ZOOM_IN, MAGNIFY_SCREEN_ZOOM_IN,
MAGNIFY_SCREEN_ZOOM_OUT, MAGNIFY_SCREEN_ZOOM_OUT,
MEDIA_NEXT_TRACK, MEDIA_NEXT_TRACK,
...@@ -94,8 +89,6 @@ enum AcceleratorAction { ...@@ -94,8 +89,6 @@ enum AcceleratorAction {
NEW_WINDOW, NEW_WINDOW,
NEXT_IME, NEXT_IME,
OPEN_FEEDBACK_PAGE, OPEN_FEEDBACK_PAGE,
POWER_PRESSED,
POWER_RELEASED,
PREVIOUS_IME, PREVIOUS_IME,
PRINT_UI_HIERARCHIES, PRINT_UI_HIERARCHIES,
RESTORE_TAB, RESTORE_TAB,
...@@ -108,23 +101,13 @@ enum AcceleratorAction { ...@@ -108,23 +101,13 @@ enum AcceleratorAction {
SHOW_MESSAGE_CENTER_BUBBLE, SHOW_MESSAGE_CENTER_BUBBLE,
SHOW_SYSTEM_TRAY_BUBBLE, SHOW_SYSTEM_TRAY_BUBBLE,
SHOW_TASK_MANAGER, SHOW_TASK_MANAGER,
SILENCE_SPOKEN_FEEDBACK,
SWAP_PRIMARY_DISPLAY,
SWITCH_IME, // Switch to another IME depending on the accelerator. SWITCH_IME, // Switch to another IME depending on the accelerator.
TAKE_PARTIAL_SCREENSHOT, TAKE_PARTIAL_SCREENSHOT,
TAKE_SCREENSHOT, TAKE_SCREENSHOT,
TOGGLE_APP_LIST, TOGGLE_APP_LIST,
TOGGLE_CAPS_LOCK,
TOGGLE_CAPS_LOCK_BY_ALT_LWIN,
TOGGLE_FULLSCREEN, TOGGLE_FULLSCREEN,
TOGGLE_MAXIMIZED, TOGGLE_MAXIMIZED,
TOGGLE_OVERVIEW, TOGGLE_OVERVIEW,
TOGGLE_SPOKEN_FEEDBACK,
TOGGLE_TOUCH_VIEW_TESTING,
TOGGLE_WIFI,
TOUCH_HUD_CLEAR,
TOUCH_HUD_MODE_CHANGE,
TOUCH_HUD_PROJECTION_TOGGLE,
VOLUME_DOWN, VOLUME_DOWN,
VOLUME_MUTE, VOLUME_MUTE,
VOLUME_UP, VOLUME_UP,
...@@ -134,13 +117,29 @@ enum AcceleratorAction { ...@@ -134,13 +117,29 @@ enum AcceleratorAction {
WINDOW_CYCLE_SNAP_DOCK_RIGHT, WINDOW_CYCLE_SNAP_DOCK_RIGHT,
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
DEBUG_ADD_REMOVE_DISPLAY, DEBUG_ADD_REMOVE_DISPLAY,
DISABLE_CAPS_LOCK,
DISABLE_GPU_WATCHDOG, DISABLE_GPU_WATCHDOG,
KEYBOARD_BRIGHTNESS_DOWN,
KEYBOARD_BRIGHTNESS_UP,
LOCK_PRESSED,
LOCK_RELEASED,
LOCK_SCREEN, LOCK_SCREEN,
OPEN_CROSH, OPEN_CROSH,
OPEN_FILE_MANAGER, OPEN_FILE_MANAGER,
POWER_PRESSED,
POWER_RELEASED,
SILENCE_SPOKEN_FEEDBACK,
SWAP_PRIMARY_DISPLAY,
SWITCH_TO_NEXT_USER, SWITCH_TO_NEXT_USER,
SWITCH_TO_PREVIOUS_USER, SWITCH_TO_PREVIOUS_USER,
TOGGLE_CAPS_LOCK,
TOGGLE_MIRROR_MODE, TOGGLE_MIRROR_MODE,
TOGGLE_SPOKEN_FEEDBACK,
TOGGLE_TOUCH_VIEW_TESTING,
TOGGLE_WIFI,
TOUCH_HUD_CLEAR,
TOUCH_HUD_MODE_CHANGE,
TOUCH_HUD_PROJECTION_TOGGLE,
#else #else
DUMMY_FOR_RESERVED, DUMMY_FOR_RESERVED,
#endif #endif
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ash/accelerators/accelerator_commands.h" #include "ash/accelerators/debug_commands.h"
#include "ash/accelerators/accelerator_table.h" #include "ash/accelerators/accelerator_commands.h"
#include "ash/ash_switches.h" #include "ash/ash_switches.h"
#include "ash/debug.h" #include "ash/debug.h"
#include "ash/desktop_background/desktop_background_controller.h" #include "ash/desktop_background/desktop_background_controller.h"
...@@ -139,7 +139,7 @@ bool DebugAcceleratorsEnabled() { ...@@ -139,7 +139,7 @@ bool DebugAcceleratorsEnabled() {
switches::kAshDebugShortcuts); switches::kAshDebugShortcuts);
} }
bool PerformDebugAction(int action) { bool PerformDebugAction(AcceleratorAction action) {
if (!DebugAcceleratorsEnabled()) if (!DebugAcceleratorsEnabled())
return false; return false;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef ASH_ACCELERATORS_DEBUG_COMMANDS_H_ #ifndef ASH_ACCELERATORS_DEBUG_COMMANDS_H_
#define ASH_ACCELERATORS_DEBUG_COMMANDS_H_ #define ASH_ACCELERATORS_DEBUG_COMMANDS_H_
#include "ash/accelerators/accelerator_table.h"
#include "ash/ash_export.h" #include "ash/ash_export.h"
// This file contains implementations of commands that are used only // This file contains implementations of commands that are used only
...@@ -21,7 +22,7 @@ ASH_EXPORT bool DebugAcceleratorsEnabled(); ...@@ -21,7 +22,7 @@ ASH_EXPORT bool DebugAcceleratorsEnabled();
// Performs |action| and returns true if |action| belongs to a // Performs |action| and returns true if |action| belongs to a
// debug-only accelerator and debug accelerators are enabled. // debug-only accelerator and debug accelerators are enabled.
ASH_EXPORT bool PerformDebugAction(int action); ASH_EXPORT bool PerformDebugAction(AcceleratorAction action);
} // namespace debug } // namespace debug
} // namespace ash } // namespace ash
......
...@@ -99,7 +99,7 @@ class LoggedInSpokenFeedbackTest : public InProcessBrowserTest { ...@@ -99,7 +99,7 @@ class LoggedInSpokenFeedbackTest : public InProcessBrowserTest {
"window.ontouchstart = function() {};"); "window.ontouchstart = function() {};");
} }
bool PerformAcceleratorAction(int action) { bool PerformAcceleratorAction(ash::AcceleratorAction action) {
ash::AcceleratorController* controller = ash::AcceleratorController* controller =
ash::Shell::GetInstance()->accelerator_controller(); ash::Shell::GetInstance()->accelerator_controller();
return controller->PerformActionIfEnabled(action); return controller->PerformActionIfEnabled(action);
......
...@@ -205,7 +205,9 @@ const ChromeCmdId2AshActionId kChromeCmdId2AshActionId[] = { ...@@ -205,7 +205,9 @@ const ChromeCmdId2AshActionId kChromeCmdId2AshActionId[] = {
{ IDC_NEW_WINDOW, ash::NEW_WINDOW }, { IDC_NEW_WINDOW, ash::NEW_WINDOW },
{ IDC_RESTORE_TAB, ash::RESTORE_TAB }, { IDC_RESTORE_TAB, ash::RESTORE_TAB },
{ IDC_TASK_MANAGER, ash::SHOW_TASK_MANAGER }, { IDC_TASK_MANAGER, ash::SHOW_TASK_MANAGER },
#if defined(OS_CHROMEOS)
{ IDC_TOUCH_HUD_PROJECTION_TOGGLE, ash::TOUCH_HUD_PROJECTION_TOGGLE }, { IDC_TOUCH_HUD_PROJECTION_TOGGLE, ash::TOUCH_HUD_PROJECTION_TOGGLE },
#endif
}; };
const size_t kChromeCmdId2AshActionIdLength = const size_t kChromeCmdId2AshActionIdLength =
arraysize(kChromeCmdId2AshActionId); arraysize(kChromeCmdId2AshActionId);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment