summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-07 21:04:58 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-07 21:04:58 +0000
commita61fc173798260db50a32a4e3d52ae74e2e52814 (patch)
treed55e49cdbd06847b444317a541a4d9d274692f1a /ash
parent6eb71f482fea112c767208b4338a387d9461f1ab (diff)
downloadchromium_src-a61fc173798260db50a32a4e3d52ae74e2e52814.zip
chromium_src-a61fc173798260db50a32a4e3d52ae74e2e52814.tar.gz
chromium_src-a61fc173798260db50a32a4e3d52ae74e2e52814.tar.bz2
ash: Allow snapping/minimizing a fullscreen/maximized window using accelerators.
Includes some refactoring to make it simpler to test specific accelerator actions without sending the accelerator keys. BUG=131114 TEST=aura_shell_unittests Review URL: https://chromiumcodereview.appspot.com/10541058 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141078 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/accelerators/accelerator_controller.cc83
-rw-r--r--ash/accelerators/accelerator_controller.h6
-rw-r--r--ash/accelerators/accelerator_controller_unittest.cc67
3 files changed, 119 insertions, 37 deletions
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc
index f5354fa..d3ea484 100644
--- a/ash/accelerators/accelerator_controller.cc
+++ b/ash/accelerators/accelerator_controller.cc
@@ -261,41 +261,8 @@ bool AcceleratorController::IsRegistered(
return accelerator_manager_->GetCurrentTarget(accelerator) != NULL;
}
-void AcceleratorController::SetBrightnessControlDelegate(
- scoped_ptr<BrightnessControlDelegate> brightness_control_delegate) {
- brightness_control_delegate_.swap(brightness_control_delegate);
-}
-
-void AcceleratorController::SetCapsLockDelegate(
- scoped_ptr<CapsLockDelegate> caps_lock_delegate) {
- caps_lock_delegate_.swap(caps_lock_delegate);
-}
-
-void AcceleratorController::SetImeControlDelegate(
- scoped_ptr<ImeControlDelegate> ime_control_delegate) {
- ime_control_delegate_.swap(ime_control_delegate);
-}
-
-void AcceleratorController::SetScreenshotDelegate(
- scoped_ptr<ScreenshotDelegate> screenshot_delegate) {
- screenshot_delegate_.swap(screenshot_delegate);
-}
-
-void AcceleratorController::SetVolumeControlDelegate(
- scoped_ptr<VolumeControlDelegate> volume_control_delegate) {
- volume_control_delegate_.swap(volume_control_delegate);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// AcceleratorController, ui::AcceleratorTarget implementation:
-
-bool AcceleratorController::AcceleratorPressed(
- const ui::Accelerator& accelerator) {
- std::map<ui::Accelerator, int>::const_iterator it =
- accelerators_.find(accelerator);
- DCHECK(it != accelerators_.end());
- AcceleratorAction action = static_cast<AcceleratorAction>(it->second);
-
+bool AcceleratorController::PerformAction(int action,
+ const ui::Accelerator& accelerator) {
ash::Shell* shell = ash::Shell::GetInstance();
bool at_login_screen = false;
#if defined(OS_CHROMEOS)
@@ -467,7 +434,13 @@ bool AcceleratorController::AcceleratorPressed(
action == WINDOW_SNAP_LEFT ? internal::SnapSizer::LEFT_EDGE :
internal::SnapSizer::RIGHT_EDGE,
shell->GetGridSize());
- window->SetBounds(sizer.GetSnapBounds(window->bounds()));
+ if (wm::IsWindowFullscreen(window) ||
+ wm::IsWindowMaximized(window)) {
+ SetRestoreBounds(window, sizer.GetSnapBounds(window->bounds()));
+ wm::RestoreWindow(window);
+ } else {
+ window->SetBounds(sizer.GetSnapBounds(window->bounds()));
+ }
return true;
}
case WINDOW_MINIMIZE: {
@@ -521,11 +494,47 @@ bool AcceleratorController::AcceleratorPressed(
return true;
#endif
default:
- NOTREACHED() << "Unhandled action " << it->second;
+ NOTREACHED() << "Unhandled action " << action;
}
return false;
}
+void AcceleratorController::SetBrightnessControlDelegate(
+ scoped_ptr<BrightnessControlDelegate> brightness_control_delegate) {
+ brightness_control_delegate_.swap(brightness_control_delegate);
+}
+
+void AcceleratorController::SetCapsLockDelegate(
+ scoped_ptr<CapsLockDelegate> caps_lock_delegate) {
+ caps_lock_delegate_.swap(caps_lock_delegate);
+}
+
+void AcceleratorController::SetImeControlDelegate(
+ scoped_ptr<ImeControlDelegate> ime_control_delegate) {
+ ime_control_delegate_.swap(ime_control_delegate);
+}
+
+void AcceleratorController::SetScreenshotDelegate(
+ scoped_ptr<ScreenshotDelegate> screenshot_delegate) {
+ screenshot_delegate_.swap(screenshot_delegate);
+}
+
+void AcceleratorController::SetVolumeControlDelegate(
+ scoped_ptr<VolumeControlDelegate> volume_control_delegate) {
+ volume_control_delegate_.swap(volume_control_delegate);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// AcceleratorController, ui::AcceleratorTarget implementation:
+
+bool AcceleratorController::AcceleratorPressed(
+ const ui::Accelerator& accelerator) {
+ std::map<ui::Accelerator, int>::const_iterator it =
+ accelerators_.find(accelerator);
+ DCHECK(it != accelerators_.end());
+ return PerformAction(static_cast<AcceleratorAction>(it->second), accelerator);
+}
+
void AcceleratorController::SwitchToWindow(int window) {
const LauncherItems& items =
Shell::GetInstance()->launcher()->model()->items();
diff --git a/ash/accelerators/accelerator_controller.h b/ash/accelerators/accelerator_controller.h
index 9660107..11a0673 100644
--- a/ash/accelerators/accelerator_controller.h
+++ b/ash/accelerators/accelerator_controller.h
@@ -59,6 +59,12 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget {
// Returns true if the |accelerator| is registered.
bool IsRegistered(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);
+
// Overridden from ui::AcceleratorTarget:
virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
virtual bool CanHandleAccelerators() const OVERRIDE;
diff --git a/ash/accelerators/accelerator_controller_unittest.cc b/ash/accelerators/accelerator_controller_unittest.cc
index 91d3845..ff0e56b 100644
--- a/ash/accelerators/accelerator_controller_unittest.cc
+++ b/ash/accelerators/accelerator_controller_unittest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "ash/accelerators/accelerator_controller.h"
+#include "ash/accelerators/accelerator_table.h"
#include "ash/caps_lock_delegate.h"
#include "ash/ime_control_delegate.h"
#include "ash/screenshot_delegate.h"
@@ -377,6 +378,72 @@ TEST_F(AcceleratorControllerTest, IsRegistered) {
EXPECT_FALSE(GetController()->IsRegistered(accelerator_a));
}
+TEST_F(AcceleratorControllerTest, WindowSnap) {
+ scoped_ptr<aura::Window> window(
+ aura::test::CreateTestWindowWithBounds(gfx::Rect(5, 5, 20, 20), NULL));
+ const ui::Accelerator dummy;
+
+ wm::ActivateWindow(window.get());
+
+ {
+ GetController()->PerformAction(WINDOW_SNAP_LEFT, dummy);
+ gfx::Rect snap_left = window->bounds();
+ GetController()->PerformAction(WINDOW_SNAP_LEFT, dummy);
+ EXPECT_NE(window->bounds().ToString(), snap_left.ToString());
+
+ GetController()->PerformAction(WINDOW_SNAP_LEFT, dummy);
+ EXPECT_NE(window->bounds().ToString(), snap_left.ToString());
+
+ // It should cycle back to the first snapped position.
+ GetController()->PerformAction(WINDOW_SNAP_LEFT, dummy);
+ EXPECT_EQ(window->bounds().ToString(), snap_left.ToString());
+ }
+ {
+ GetController()->PerformAction(WINDOW_SNAP_RIGHT, dummy);
+ gfx::Rect snap_right = window->bounds();
+ GetController()->PerformAction(WINDOW_SNAP_RIGHT, dummy);
+ EXPECT_NE(window->bounds().ToString(), snap_right.ToString());
+
+ GetController()->PerformAction(WINDOW_SNAP_RIGHT, dummy);
+ EXPECT_NE(window->bounds().ToString(), snap_right.ToString());
+
+ // It should cycle back to the first snapped position.
+ GetController()->PerformAction(WINDOW_SNAP_RIGHT, dummy);
+ EXPECT_EQ(window->bounds().ToString(), snap_right.ToString());
+ }
+ {
+ gfx::Rect normal_bounds = window->bounds();
+
+ GetController()->PerformAction(WINDOW_MAXIMIZE_RESTORE, dummy);
+ EXPECT_TRUE(wm::IsWindowMaximized(window.get()));
+ EXPECT_NE(normal_bounds.ToString(), window->bounds().ToString());
+
+ GetController()->PerformAction(WINDOW_MAXIMIZE_RESTORE, dummy);
+ EXPECT_FALSE(wm::IsWindowMaximized(window.get()));
+ EXPECT_EQ(normal_bounds.ToString(), window->bounds().ToString());
+
+ GetController()->PerformAction(WINDOW_MAXIMIZE_RESTORE, dummy);
+ GetController()->PerformAction(WINDOW_SNAP_LEFT, dummy);
+ EXPECT_FALSE(wm::IsWindowMaximized(window.get()));
+
+ GetController()->PerformAction(WINDOW_MAXIMIZE_RESTORE, dummy);
+ GetController()->PerformAction(WINDOW_SNAP_RIGHT, dummy);
+ EXPECT_FALSE(wm::IsWindowMaximized(window.get()));
+
+ GetController()->PerformAction(WINDOW_MAXIMIZE_RESTORE, dummy);
+ EXPECT_TRUE(wm::IsWindowMaximized(window.get()));
+ GetController()->PerformAction(WINDOW_MINIMIZE, dummy);
+ EXPECT_FALSE(wm::IsWindowMaximized(window.get()));
+ EXPECT_TRUE(wm::IsWindowMinimized(window.get()));
+ wm::RestoreWindow(window.get());
+ wm::ActivateWindow(window.get());
+ }
+ {
+ GetController()->PerformAction(WINDOW_MINIMIZE, dummy);
+ EXPECT_TRUE(wm::IsWindowMinimized(window.get()));
+ }
+}
+
#if defined(OS_WIN) || defined(USE_X11)
TEST_F(AcceleratorControllerTest, ProcessOnce) {
ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);