summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ash/accelerators/accelerator_controller.cc6
-rw-r--r--ash/accelerators/accelerator_controller_unittest.cc32
-rw-r--r--ash/wm/window_util.cc12
3 files changed, 46 insertions, 4 deletions
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc
index 2e8d4b7..d9c2d79 100644
--- a/ash/accelerators/accelerator_controller.cc
+++ b/ash/accelerators/accelerator_controller.cc
@@ -851,7 +851,7 @@ bool AcceleratorController::PerformAction(int action,
case WINDOW_SNAP_LEFT:
case WINDOW_SNAP_RIGHT: {
wm::WindowState* window_state = wm::GetActiveWindowState();
- // Disable window docking shortcut key for full screen window due to
+ // Disable window snapping shortcut key for full screen window due to
// http://crbug.com/135487.
if (!window_state ||
window_state->window()->type() != aura::client::WINDOW_TYPE_NORMAL ||
@@ -879,8 +879,10 @@ bool AcceleratorController::PerformAction(int action,
return true;
}
case WINDOW_POSITION_CENTER: {
+ content::RecordAction(content::UserMetricsAction("Accel_Center"));
aura::Window* window = wm::GetActiveWindow();
- if (window) {
+ // Docked windows do not support centering and ignore accelerator.
+ if (window && !wm::GetWindowState(window)->IsDocked()) {
wm::CenterWindow(window);
return true;
}
diff --git a/ash/accelerators/accelerator_controller_unittest.cc b/ash/accelerators/accelerator_controller_unittest.cc
index 4a98b0e..278630c 100644
--- a/ash/accelerators/accelerator_controller_unittest.cc
+++ b/ash/accelerators/accelerator_controller_unittest.cc
@@ -9,6 +9,7 @@
#include "ash/caps_lock_delegate.h"
#include "ash/display/display_manager.h"
#include "ash/ime_control_delegate.h"
+#include "ash/screen_ash.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/system/brightness_control_delegate.h"
@@ -536,6 +537,37 @@ TEST_F(AcceleratorControllerTest, WindowSnap) {
}
}
+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);
+ gfx::Rect work_area =
+ Shell::GetScreen()->GetDisplayNearestWindow(window.get()).work_area();
+ gfx::Rect bounds = window->GetBoundsInScreen();
+ EXPECT_NEAR(bounds.x() - work_area.x(),
+ work_area.right() - bounds.right(),
+ 1);
+ EXPECT_NEAR(bounds.y() - work_area.y(),
+ work_area.bottom() - bounds.bottom(),
+ 1);
+
+ // Add the window to docked container and try to center it.
+ window->SetBounds(gfx::Rect(0, 0, 20, 20));
+ aura::Window* docked_container = Shell::GetContainer(
+ window->GetRootWindow(), internal::kShellWindowId_DockedContainer);
+ docked_container->AddChild(window.get());
+ gfx::Rect docked_bounds = window->GetBoundsInScreen();
+ GetController()->PerformAction(WINDOW_POSITION_CENTER, dummy);
+ // It should not get centered and should remain docked.
+ EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id());
+ EXPECT_EQ(docked_bounds.ToString(), window->GetBoundsInScreen().ToString());
+}
+
TEST_F(AcceleratorControllerTest, ControllerContext) {
ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
ui::Accelerator accelerator_a2(ui::VKEY_A, ui::EF_NONE);
diff --git a/ash/wm/window_util.cc b/ash/wm/window_util.cc
index 46a776a..8d320a9 100644
--- a/ash/wm/window_util.cc
+++ b/ash/wm/window_util.cc
@@ -9,6 +9,7 @@
#include "ash/ash_constants.h"
#include "ash/shell.h"
#include "ash/wm/window_properties.h"
+#include "ash/wm/window_state.h"
#include "ui/aura/client/activation_client.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/root_window.h"
@@ -55,11 +56,18 @@ bool IsWindowMinimized(aura::Window* window) {
}
void CenterWindow(aura::Window* window) {
+ wm::WindowState* window_state = wm::GetWindowState(window);
+ if (!window_state->IsNormalShowState())
+ return;
const gfx::Display display =
Shell::GetScreen()->GetDisplayNearestWindow(window);
gfx::Rect center = display.work_area();
- center.ClampToCenteredSize(window->bounds().size());
- window->SetBoundsInScreen(center, display);
+ gfx::Size size = window_state->HasRestoreBounds() ?
+ window_state->GetRestoreBoundsInScreen().size() :
+ window->bounds().size();
+ center.ClampToCenteredSize(size);
+ window_state->SetRestoreBoundsInScreen(center);
+ window_state->Restore();
}
void AdjustBoundsToEnsureMinimumWindowVisibility(const gfx::Rect& visible_area,