ash: Explicitly enumerate repeatable accelerators.
Instead of designating specific accelerators as
non-repeatable (which is prone to getting outdated), keep
track of the few accelerators that should be repeatable.
Also make many probably-inadvertently-repeatable
accelerators instead be non-repeatable.
BUG=626014
TEST=manual
Review-Url: https://codereview.chromium.org/2130603002
Cr-Commit-Position: refs/heads/master@{#404161}
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc
index 802ac8a..d2245475 100644
--- a/ash/accelerators/accelerator_controller.cc
+++ b/ash/accelerators/accelerator_controller.cc
@@ -903,8 +903,8 @@
preferred_actions_.insert(kPreferredActions[i]);
for (size_t i = 0; i < kReservedActionsLength; ++i)
reserved_actions_.insert(kReservedActions[i]);
- for (size_t i = 0; i < kNonrepeatableActionsLength; ++i)
- nonrepeatable_actions_.insert(kNonrepeatableActions[i]);
+ for (size_t i = 0; i < kRepeatableActionsLength; ++i)
+ repeatable_actions_.insert(kRepeatableActions[i]);
for (size_t i = 0; i < kActionsAllowedInAppModeOrPinnedModeLength; ++i) {
actions_allowed_in_app_mode_.insert(
kActionsAllowedInAppModeOrPinnedMode[i]);
@@ -970,10 +970,8 @@
bool AcceleratorController::CanPerformAction(
AcceleratorAction action,
const ui::Accelerator& accelerator) {
- if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() &&
- accelerator.IsRepeat()) {
+ if (accelerator.IsRepeat() && !repeatable_actions_.count(action))
return false;
- }
AcceleratorProcessingRestriction restriction =
GetAcceleratorProcessingRestriction(action);
diff --git a/ash/accelerators/accelerator_controller.h b/ash/accelerators/accelerator_controller.h
index 0e6b12e..2ed610d 100644
--- a/ash/accelerators/accelerator_controller.h
+++ b/ash/accelerators/accelerator_controller.h
@@ -205,8 +205,8 @@
std::set<int> preferred_actions_;
// Reserved actions. See accelerator_table.h for details.
std::set<int> reserved_actions_;
- // Actions which will not be repeated while holding the accelerator key.
- std::set<int> nonrepeatable_actions_;
+ // Actions which will be repeated while holding the accelerator key.
+ std::set<int> repeatable_actions_;
// Actions allowed in app mode.
std::set<int> actions_allowed_in_app_mode_;
// Actions allowed in pinned mode.
diff --git a/ash/accelerators/accelerator_table.cc b/ash/accelerators/accelerator_table.cc
index 73f26a0..642ceb7 100644
--- a/ash/accelerators/accelerator_table.cc
+++ b/ash/accelerators/accelerator_table.cc
@@ -403,36 +403,25 @@
const size_t kActionsAllowedAtModalWindowLength =
arraysize(kActionsAllowedAtModalWindow);
-const AcceleratorAction kNonrepeatableActions[] = {
- // TODO(mazda): Add other actions which should not be repeated.
- CYCLE_BACKWARD_MRU,
- CYCLE_FORWARD_MRU,
- EXIT,
- NEXT_IME,
- PREVIOUS_IME,
- OPEN_FEEDBACK_PAGE,
- PRINT_UI_HIERARCHIES, // Don't fill the logs if the key is held down.
- ROTATE_SCREEN,
- ROTATE_WINDOW,
- SCALE_UI_UP,
- SCALE_UI_DOWN,
- SCALE_UI_RESET,
- TAKE_WINDOW_SCREENSHOT,
- TAKE_PARTIAL_SCREENSHOT,
- TAKE_SCREENSHOT,
- TOGGLE_FULLSCREEN,
- TOGGLE_MAXIMIZED,
- TOGGLE_OVERVIEW,
- WINDOW_MINIMIZE,
+const AcceleratorAction kRepeatableActions[] = {
+ FOCUS_NEXT_PANE,
+ FOCUS_PREVIOUS_PANE,
+ MAGNIFY_SCREEN_ZOOM_IN,
+ MAGNIFY_SCREEN_ZOOM_OUT,
+ MEDIA_NEXT_TRACK,
+ MEDIA_PREV_TRACK,
+ RESTORE_TAB,
#if defined(OS_CHROMEOS)
- DEBUG_TOGGLE_TOUCH_PAD,
- DEBUG_TOGGLE_TOUCH_SCREEN,
- LOCK_SCREEN,
- SUSPEND,
-#endif
+ BRIGHTNESS_DOWN,
+ BRIGHTNESS_UP,
+ KEYBOARD_BRIGHTNESS_DOWN,
+ KEYBOARD_BRIGHTNESS_UP,
+ VOLUME_DOWN,
+ VOLUME_UP,
+#endif // defined(OS_CHROMEOS)
};
-const size_t kNonrepeatableActionsLength = arraysize(kNonrepeatableActions);
+const size_t kRepeatableActionsLength = arraysize(kRepeatableActions);
const AcceleratorAction kActionsAllowedInAppModeOrPinnedMode[] = {
DEBUG_PRINT_LAYER_HIERARCHY,
diff --git a/ash/accelerators/accelerator_table.h b/ash/accelerators/accelerator_table.h
index 6c4add763..7d40cf6 100644
--- a/ash/accelerators/accelerator_table.h
+++ b/ash/accelerators/accelerator_table.h
@@ -233,9 +233,9 @@
ASH_EXPORT extern const AcceleratorAction kActionsAllowedAtModalWindow[];
ASH_EXPORT extern const size_t kActionsAllowedAtModalWindowLength;
-// Actions which will not be repeated while holding an accelerator key.
-ASH_EXPORT extern const AcceleratorAction kNonrepeatableActions[];
-ASH_EXPORT extern const size_t kNonrepeatableActionsLength;
+// Actions which may be repeated by holding an accelerator key.
+ASH_EXPORT extern const AcceleratorAction kRepeatableActions[];
+ASH_EXPORT extern const size_t kRepeatableActionsLength;
// Actions allowed in app mode or pinned mode.
ASH_EXPORT extern const AcceleratorAction
diff --git a/ash/accelerators/accelerator_table_unittest.cc b/ash/accelerators/accelerator_table_unittest.cc
index 95329282..4bb8c86 100644
--- a/ash/accelerators/accelerator_table_unittest.cc
+++ b/ash/accelerators/accelerator_table_unittest.cc
@@ -66,12 +66,11 @@
}
}
-TEST(AcceleratorTableTest, CheckDuplicatedNonrepeatableActions) {
+TEST(AcceleratorTableTest, CheckDuplicatedRepeatableActions) {
std::set<AcceleratorAction> actions;
- for (size_t i = 0; i < kNonrepeatableActionsLength; ++i) {
- EXPECT_TRUE(actions.insert(kNonrepeatableActions[i]).second)
- << "Duplicated action: " << kNonrepeatableActions[i]
- << " at index: " << i;
+ for (size_t i = 0; i < kRepeatableActionsLength; ++i) {
+ EXPECT_TRUE(actions.insert(kRepeatableActions[i]).second)
+ << "Duplicated action: " << kRepeatableActions[i] << " at index: " << i;
}
}
diff --git a/ash/accelerators/exit_warning_handler.h b/ash/accelerators/exit_warning_handler.h
index 9a4c93f..c678f84d 100644
--- a/ash/accelerators/exit_warning_handler.h
+++ b/ash/accelerators/exit_warning_handler.h
@@ -18,16 +18,15 @@
namespace ash {
-// In order to avoid accidental exits when the user presses the exit
-// shortcut by mistake, we require the user press it twice within a
-// period of time. During that time we show a popup informing the
-// user of this.
+// In order to avoid accidental exits when the user presses the exit shortcut by
+// mistake, we require that the user press it twice within a short period of
+// time. During that time we show a popup informing the user of this.
//
// Notes:
//
-// The corresponding accelerator must be non-repeatable (see
-// kNonrepeatableActions in accelerator_table.cc). Otherwise the "Double Press
-// Exit" will be activated just by holding it down, i.e. probably every time.
+// The corresponding accelerator must not be repeatable (see kRepeatableActions
+// in accelerator_table.cc). Otherwise, the "Double Press Exit" will be
+// activated just by holding it down, i.e. probably every time.
//
// State Transition Diagrams:
//