summaryrefslogtreecommitdiffstats
path: root/ash/accelerators
diff options
context:
space:
mode:
authorpkotwicz <pkotwicz@chromium.org>2014-11-19 08:08:30 -0800
committerCommit bot <commit-bot@chromium.org>2014-11-19 16:08:47 +0000
commit87c884400772f0f3023aef4755bd3045330e77a9 (patch)
tree44c17117d65274c46ec452af023c63461ed0f00e /ash/accelerators
parenta1409c477411b0467b4bc729d9a2c972e79347d1 (diff)
downloadchromium_src-87c884400772f0f3023aef4755bd3045330e77a9.zip
chromium_src-87c884400772f0f3023aef4755bd3045330e77a9.tar.gz
chromium_src-87c884400772f0f3023aef4755bd3045330e77a9.tar.bz2
Introduce AcceleratorController::ProcessCommandIfEnabled() and change some
callers of AcceleratorController::ProcessCommand() to use AcceleratorController::ProcessCommandIfEnabled() instead. This a step towards splitting AcceleratorController::ProcessCommand() into AcceleratorController::CanPerformAction() and AcceleratorController::PerformAction(). BUG=404473 TEST=None R=oshima TBR=sky (For trivial rename in chrome/browser/policy/policy_browsertest.cc) Review URL: https://codereview.chromium.org/731913003 Cr-Commit-Position: refs/heads/master@{#304821}
Diffstat (limited to 'ash/accelerators')
-rw-r--r--ash/accelerators/accelerator_controller.cc16
-rw-r--r--ash/accelerators/accelerator_controller.h14
-rw-r--r--ash/accelerators/accelerator_controller_unittest.cc87
3 files changed, 55 insertions, 62 deletions
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc
index aefbdbd..044d4e2 100644
--- a/ash/accelerators/accelerator_controller.cc
+++ b/ash/accelerators/accelerator_controller.cc
@@ -778,6 +778,10 @@ bool AcceleratorController::IsReserved(
return reserved_actions_.find(iter->second) != reserved_actions_.end();
}
+bool AcceleratorController::PerformActionIfEnabled(int action) {
+ return PerformAction(action, ui::Accelerator());
+}
+
bool AcceleratorController::PerformAction(int action,
const ui::Accelerator& accelerator) {
ash::Shell* shell = ash::Shell::GetInstance();
@@ -786,17 +790,13 @@ bool AcceleratorController::PerformAction(int action,
if (restriction != RESTRICTION_NONE)
return restriction == RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION;
- const ui::KeyboardCode key_code = accelerator.key_code();
- // PerformAction() is performed from gesture controllers and passes
- // empty Accelerator() instance as the second argument. Such events
- // should never be suspended.
- const bool gesture_event = key_code == ui::VKEY_UNKNOWN;
- // Ignore accelerators invoked as repeated (while holding a key for a long
- // time, if their handling is nonrepeatable.
if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() &&
- accelerator.IsRepeat() && !gesture_event) {
+ accelerator.IsRepeat()) {
return true;
}
+
+ const ui::KeyboardCode key_code = accelerator.key_code();
+
// Type of the previous accelerator. Used by NEXT_IME and DISABLE_CAPS_LOCK.
const ui::EventType previous_event_type = previous_accelerator_.type();
const ui::KeyboardCode previous_key_code = previous_accelerator_.key_code();
diff --git a/ash/accelerators/accelerator_controller.h b/ash/accelerators/accelerator_controller.h
index 9a7c579..79877ad 100644
--- a/ash/accelerators/accelerator_controller.h
+++ b/ash/accelerators/accelerator_controller.h
@@ -86,11 +86,9 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget {
// is always handled and will never be passed to an window/web contents.
bool IsReserved(const ui::Accelerator& accelerator) const;
- // Performs the specified action. The |accelerator| may provide additional
- // data the action needs. Returns whether an action was performed
- // successfully.
- bool PerformAction(int action,
- const ui::Accelerator& accelerator);
+ // Performs the specified action if it is enabled. Returns whether the action
+ // was performed successfully.
+ bool PerformActionIfEnabled(int action);
// Returns the restriction for the current context.
AcceleratorProcessingRestriction GetCurrentAcceleratorRestriction();
@@ -133,6 +131,12 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget {
void RegisterAccelerators(const AcceleratorData accelerators[],
size_t accelerators_length);
+ // Performs the specified action. The |accelerator| may provide additional
+ // data the action needs. Returns whether an action was performed
+ // successfully.
+ bool PerformAction(int action,
+ const ui::Accelerator& accelerator);
+
// Get the accelerator restriction for the given action. Supply an |action|
// of -1 to get restrictions that apply for the current context.
AcceleratorProcessingRestriction GetAcceleratorProcessingRestriction(
diff --git a/ash/accelerators/accelerator_controller_unittest.cc b/ash/accelerators/accelerator_controller_unittest.cc
index 141c5b2e3..c45c7d6 100644
--- a/ash/accelerators/accelerator_controller_unittest.cc
+++ b/ash/accelerators/accelerator_controller_unittest.cc
@@ -439,20 +439,18 @@ TEST_F(AcceleratorControllerTest, IsRegistered) {
TEST_F(AcceleratorControllerTest, WindowSnap) {
scoped_ptr<aura::Window> window(
CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
- const ui::Accelerator dummy;
-
wm::WindowState* window_state = wm::GetWindowState(window.get());
window_state->Activate();
{
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_LEFT, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT);
gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent(
window.get());
EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString());
}
{
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_RIGHT, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT);
gfx::Rect expected_bounds = wm::GetDefaultRightSnappedWindowBoundsInParent(
window.get());
EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString());
@@ -460,34 +458,34 @@ TEST_F(AcceleratorControllerTest, WindowSnap) {
{
gfx::Rect normal_bounds = window_state->GetRestoreBoundsInParent();
- GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy);
+ GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED);
EXPECT_TRUE(window_state->IsMaximized());
EXPECT_NE(normal_bounds.ToString(), window->bounds().ToString());
- GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy);
+ GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED);
EXPECT_FALSE(window_state->IsMaximized());
// Window gets restored to its restore bounds since side-maximized state
// is treated as a "maximized" state.
EXPECT_EQ(normal_bounds.ToString(), window->bounds().ToString());
- GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy);
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_LEFT, dummy);
+ GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT);
EXPECT_FALSE(window_state->IsMaximized());
- GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy);
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_RIGHT, dummy);
+ GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT);
EXPECT_FALSE(window_state->IsMaximized());
- GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy);
+ GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED);
EXPECT_TRUE(window_state->IsMaximized());
- GetController()->PerformAction(WINDOW_MINIMIZE, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_MINIMIZE);
EXPECT_FALSE(window_state->IsMaximized());
EXPECT_TRUE(window_state->IsMinimized());
window_state->Restore();
window_state->Activate();
}
{
- GetController()->PerformAction(WINDOW_MINIMIZE, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_MINIMIZE);
EXPECT_TRUE(window_state->IsMinimized());
}
}
@@ -497,21 +495,19 @@ TEST_F(AcceleratorControllerTest, WindowSnapLeftDockLeftRestore) {
CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
scoped_ptr<aura::Window> window1(
CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
- const ui::Accelerator dummy;
-
wm::WindowState* window1_state = wm::GetWindowState(window1.get());
window1_state->Activate();
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_LEFT, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT);
gfx::Rect normal_bounds = window1_state->GetRestoreBoundsInParent();
gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent(
window1.get());
EXPECT_EQ(expected_bounds.ToString(), window1->bounds().ToString());
EXPECT_TRUE(window1_state->IsSnapped());
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_LEFT, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT);
EXPECT_FALSE(window1_state->IsNormalOrSnapped());
EXPECT_TRUE(window1_state->IsDocked());
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_LEFT, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT);
EXPECT_FALSE(window1_state->IsDocked());
EXPECT_EQ(normal_bounds.ToString(), window1->bounds().ToString());
}
@@ -521,21 +517,20 @@ TEST_F(AcceleratorControllerTest, WindowSnapRightDockRightRestore) {
CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
scoped_ptr<aura::Window> window1(
CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
- const ui::Accelerator dummy;
wm::WindowState* window1_state = wm::GetWindowState(window1.get());
window1_state->Activate();
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_RIGHT, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT);
gfx::Rect normal_bounds = window1_state->GetRestoreBoundsInParent();
gfx::Rect expected_bounds =
wm::GetDefaultRightSnappedWindowBoundsInParent(window1.get());
EXPECT_EQ(expected_bounds.ToString(), window1->bounds().ToString());
EXPECT_TRUE(window1_state->IsSnapped());
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_RIGHT, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT);
EXPECT_FALSE(window1_state->IsNormalOrSnapped());
EXPECT_TRUE(window1_state->IsDocked());
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_RIGHT, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT);
EXPECT_FALSE(window1_state->IsDocked());
EXPECT_EQ(normal_bounds.ToString(), window1->bounds().ToString());
}
@@ -545,22 +540,21 @@ TEST_F(AcceleratorControllerTest, WindowSnapLeftDockLeftSnapRight) {
CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
scoped_ptr<aura::Window> window1(
CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
- const ui::Accelerator dummy;
wm::WindowState* window1_state = wm::GetWindowState(window1.get());
window1_state->Activate();
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_LEFT, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT);
gfx::Rect expected_bounds =
wm::GetDefaultLeftSnappedWindowBoundsInParent(window1.get());
gfx::Rect expected_bounds2 =
wm::GetDefaultRightSnappedWindowBoundsInParent(window1.get());
EXPECT_EQ(expected_bounds.ToString(), window1->bounds().ToString());
EXPECT_TRUE(window1_state->IsSnapped());
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_LEFT, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT);
EXPECT_FALSE(window1_state->IsNormalOrSnapped());
EXPECT_TRUE(window1_state->IsDocked());
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_RIGHT, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT);
EXPECT_FALSE(window1_state->IsDocked());
EXPECT_TRUE(window1_state->IsSnapped());
EXPECT_EQ(expected_bounds2.ToString(), window1->bounds().ToString());
@@ -571,7 +565,6 @@ TEST_F(AcceleratorControllerTest, WindowDockLeftMinimizeWindowWithRestore) {
CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
scoped_ptr<aura::Window> window1(
CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
- const ui::Accelerator dummy;
wm::WindowState* window1_state = wm::GetWindowState(window1.get());
window1_state->Activate();
@@ -587,16 +580,16 @@ TEST_F(AcceleratorControllerTest, WindowDockLeftMinimizeWindowWithRestore) {
wm::WindowState* window3_state = wm::GetWindowState(window3.get());
window3_state->Activate();
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_LEFT, dummy);
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_LEFT, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT);
gfx::Rect window3_docked_bounds = window3->bounds();
window2_state->Activate();
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_LEFT, dummy);
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_LEFT, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT);
window1_state->Activate();
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_LEFT, dummy);
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_LEFT, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT);
EXPECT_TRUE(window3_state->IsDocked());
EXPECT_TRUE(window2_state->IsDocked());
@@ -604,9 +597,9 @@ TEST_F(AcceleratorControllerTest, WindowDockLeftMinimizeWindowWithRestore) {
EXPECT_TRUE(window3_state->IsMinimized());
window1_state->Activate();
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_LEFT, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT);
window2_state->Activate();
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_LEFT, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT);
window3_state->Unminimize();
EXPECT_FALSE(window1_state->IsDocked());
EXPECT_FALSE(window2_state->IsDocked());
@@ -619,12 +612,11 @@ TEST_F(AcceleratorControllerTest, WindowPanelDockLeftDockRightRestore) {
CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
scoped_ptr<aura::Window> window(CreatePanel());
- const ui::Accelerator dummy;
wm::WindowState* window_state = wm::GetWindowState(window.get());
window_state->Activate();
gfx::Rect window_restore_bounds2 = window->bounds();
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_LEFT, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT);
gfx::Rect expected_bounds =
wm::GetDefaultLeftSnappedWindowBoundsInParent(window.get());
gfx::Rect window_restore_bounds =
@@ -634,9 +626,9 @@ TEST_F(AcceleratorControllerTest, WindowPanelDockLeftDockRightRestore) {
EXPECT_FALSE(window_state->IsNormalOrSnapped());
EXPECT_TRUE(window_state->IsDocked());
window_state->Restore();
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_RIGHT, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT);
EXPECT_TRUE(window_state->IsDocked());
- GetController()->PerformAction(WINDOW_CYCLE_SNAP_DOCK_RIGHT, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT);
EXPECT_FALSE(window_state->IsDocked());
EXPECT_EQ(window_restore_bounds.ToString(),
window_restore_bounds2.ToString());
@@ -646,12 +638,11 @@ TEST_F(AcceleratorControllerTest, WindowPanelDockLeftDockRightRestore) {
TEST_F(AcceleratorControllerTest, CenterWindowAccelerator) {
scoped_ptr<aura::Window> window(
CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
- const ui::Accelerator dummy;
wm::WindowState* window_state = wm::GetWindowState(window.get());
window_state->Activate();
// Center the window using accelerator.
- GetController()->PerformAction(WINDOW_POSITION_CENTER, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER);
gfx::Rect work_area =
Shell::GetScreen()->GetDisplayNearestWindow(window.get()).work_area();
gfx::Rect bounds = window->GetBoundsInScreen();
@@ -668,7 +659,7 @@ TEST_F(AcceleratorControllerTest, CenterWindowAccelerator) {
window->GetRootWindow(), kShellWindowId_DockedContainer);
docked_container->AddChild(window.get());
gfx::Rect docked_bounds = window->GetBoundsInScreen();
- GetController()->PerformAction(WINDOW_POSITION_CENTER, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER);
// It should not get centered and should remain docked.
EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
EXPECT_EQ(docked_bounds.ToString(), window->GetBoundsInScreen().ToString());
@@ -1329,14 +1320,13 @@ TEST_F(AcceleratorControllerTest, DisallowedAtModalWindow) {
}
scoped_ptr<aura::Window> window(
CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
- const ui::Accelerator dummy;
wm::ActivateWindow(window.get());
Shell::GetInstance()->SimulateModalWindowOpenForTesting(true);
for (std::set<AcceleratorAction>::const_iterator it = all_actions.begin();
it != all_actions.end(); ++it) {
if (actionsAllowedAtModalWindow.find(*it) ==
actionsAllowedAtModalWindow.end()) {
- EXPECT_TRUE(GetController()->PerformAction(*it, dummy))
+ EXPECT_TRUE(GetController()->PerformActionIfEnabled(*it))
<< " for action (disallowed at modal window): " << *it;
}
}
@@ -1442,14 +1432,13 @@ TEST_F(AcceleratorControllerTest, DisallowedAtModalWindow) {
#endif
TEST_F(AcceleratorControllerTest, DisallowedWithNoWindow) {
- const ui::Accelerator dummy;
AccessibilityDelegate* delegate =
ash::Shell::GetInstance()->accessibility_delegate();
for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) {
delegate->TriggerAccessibilityAlert(ui::A11Y_ALERT_NONE);
EXPECT_TRUE(
- GetController()->PerformAction(kActionsNeedingWindow[i], dummy));
+ GetController()->PerformActionIfEnabled(kActionsNeedingWindow[i]));
EXPECT_EQ(delegate->GetLastAccessibilityAlert(),
ui::A11Y_ALERT_WINDOW_NEEDED);
}
@@ -1460,7 +1449,7 @@ TEST_F(AcceleratorControllerTest, DisallowedWithNoWindow) {
window.reset(CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
wm::ActivateWindow(window.get());
delegate->TriggerAccessibilityAlert(ui::A11Y_ALERT_NONE);
- GetController()->PerformAction(kActionsNeedingWindow[i], dummy);
+ GetController()->PerformActionIfEnabled(kActionsNeedingWindow[i]);
EXPECT_NE(delegate->GetLastAccessibilityAlert(),
ui::A11Y_ALERT_WINDOW_NEEDED);
}
@@ -1469,9 +1458,9 @@ TEST_F(AcceleratorControllerTest, DisallowedWithNoWindow) {
for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) {
window.reset(CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
wm::ActivateWindow(window.get());
- GetController()->PerformAction(WINDOW_MINIMIZE, dummy);
+ GetController()->PerformActionIfEnabled(WINDOW_MINIMIZE);
delegate->TriggerAccessibilityAlert(ui::A11Y_ALERT_NONE);
- GetController()->PerformAction(kActionsNeedingWindow[i], dummy);
+ GetController()->PerformActionIfEnabled(kActionsNeedingWindow[i]);
EXPECT_NE(delegate->GetLastAccessibilityAlert(),
ui::A11Y_ALERT_WINDOW_NEEDED);
}