summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ash/accelerators/accelerator_controller.cc37
-rw-r--r--ash/accelerators/accelerator_table.cc7
-rw-r--r--ash/accelerators/accelerator_table.h5
-rw-r--r--ash/wm/window_util.cc7
-rw-r--r--ash/wm/window_util.h3
-rw-r--r--ash/wm/workspace/snap_sizer.cc18
-rw-r--r--ash/wm/workspace/snap_sizer.h6
7 files changed, 82 insertions, 1 deletions
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc
index d545511..2000159 100644
--- a/ash/accelerators/accelerator_controller.cc
+++ b/ash/accelerators/accelerator_controller.cc
@@ -21,8 +21,10 @@
#include "ash/system/brightness/brightness_control_delegate.h"
#include "ash/system/tray/system_tray.h"
#include "ash/volume_control_delegate.h"
+#include "ash/wm/property_util.h"
#include "ash/wm/window_cycle_controller.h"
#include "ash/wm/window_util.h"
+#include "ash/wm/workspace/snap_sizer.h"
#include "base/command_line.h"
#include "ui/aura/event.h"
#include "ui/aura/root_window.h"
@@ -452,6 +454,41 @@ bool AcceleratorController::AcceleratorPressed(
case SELECT_LAST_WIN:
SwitchToWindow(-1);
break;
+ case WINDOW_SNAP_LEFT:
+ case WINDOW_SNAP_RIGHT: {
+ aura::Window* window = wm::GetActiveWindow();
+ if (!window)
+ break;
+ internal::SnapSizer sizer(window,
+ gfx::Point(),
+ action == WINDOW_SNAP_LEFT ? internal::SnapSizer::LEFT_EDGE :
+ internal::SnapSizer::RIGHT_EDGE,
+ shell->GetGridSize());
+ window->SetBounds(sizer.GetSnapBounds(window->bounds()));
+ break;
+ }
+ case WINDOW_MINIMIZE: {
+ aura::Window* window = wm::GetActiveWindow();
+ if (window)
+ wm::MinimizeWindow(window);
+ break;
+ }
+ case WINDOW_MAXIMIZE_RESTORE: {
+ aura::Window* window = wm::GetActiveWindow();
+ if (window) {
+ if (wm::IsWindowMaximized(window))
+ wm::RestoreWindow(window);
+ else
+ wm::MaximizeWindow(window);
+ }
+ break;
+ }
+ case WINDOW_POSITION_CENTER: {
+ aura::Window* window = wm::GetActiveWindow();
+ if (window)
+ wm::CenterWindow(window);
+ break;
+ }
case ROTATE_WINDOWS:
return HandleRotateWindows();
#if !defined(NDEBUG)
diff --git a/ash/accelerators/accelerator_table.cc b/ash/accelerators/accelerator_table.cc
index ba4bc29..974a50e 100644
--- a/ash/accelerators/accelerator_table.cc
+++ b/ash/accelerators/accelerator_table.cc
@@ -85,6 +85,13 @@ const AcceleratorData kAcceleratorData[] = {
{ true, ui::VKEY_8, true, false, true, SELECT_WIN_7 },
{ true, ui::VKEY_9, true, false, true, SELECT_LAST_WIN },
+ // Window management shortcuts.
+ { true, ui::VKEY_OEM_4, false, false, true, WINDOW_SNAP_LEFT },
+ { true, ui::VKEY_OEM_6, false, false, true, WINDOW_SNAP_RIGHT },
+ { true, ui::VKEY_OEM_MINUS, false, false, true, WINDOW_MINIMIZE },
+ { true, ui::VKEY_OEM_PLUS, false, false, true, WINDOW_MAXIMIZE_RESTORE },
+ { true, ui::VKEY_OEM_PLUS, true, false, true, WINDOW_POSITION_CENTER },
+
{ true, ui::VKEY_F3, true, true, true, ROTATE_WINDOWS },
#if !defined(NDEBUG)
{ true, ui::VKEY_HOME, false, true, false, ROTATE_SCREEN },
diff --git a/ash/accelerators/accelerator_table.h b/ash/accelerators/accelerator_table.h
index dc1e413..82618d4 100644
--- a/ash/accelerators/accelerator_table.h
+++ b/ash/accelerators/accelerator_table.h
@@ -46,6 +46,11 @@ enum AcceleratorAction {
VOLUME_DOWN,
VOLUME_MUTE,
VOLUME_UP,
+ WINDOW_MAXIMIZE_RESTORE,
+ WINDOW_MINIMIZE,
+ WINDOW_POSITION_CENTER,
+ WINDOW_SNAP_LEFT,
+ WINDOW_SNAP_RIGHT,
#if defined(OS_CHROMEOS)
LOCK_SCREEN,
OPEN_CROSH,
diff --git a/ash/wm/window_util.cc b/ash/wm/window_util.cc
index b273cb6..4ad8dc9 100644
--- a/ash/wm/window_util.cc
+++ b/ash/wm/window_util.cc
@@ -12,6 +12,7 @@
#include "ui/aura/window.h"
#include "ui/aura/window_property.h"
#include "ui/base/ui_base_types.h"
+#include "ui/gfx/monitor.h"
#include "ui/gfx/screen.h"
DECLARE_WINDOW_PROPERTY_TYPE(bool);
@@ -96,5 +97,11 @@ void RestoreWindow(aura::Window* window) {
window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
}
+void CenterWindow(aura::Window* window) {
+ const gfx::Monitor monitor = gfx::Screen::GetMonitorNearestWindow(window);
+ gfx::Rect center = monitor.work_area().Center(window->bounds().size());
+ window->SetBounds(center);
+}
+
} // namespace wm
} // namespace ash
diff --git a/ash/wm/window_util.h b/ash/wm/window_util.h
index 1191daa..6cfc907 100644
--- a/ash/wm/window_util.h
+++ b/ash/wm/window_util.h
@@ -50,6 +50,9 @@ ASH_EXPORT void MinimizeWindow(aura::Window* window);
// Restores |window|, which must not be NULL.
ASH_EXPORT void RestoreWindow(aura::Window* window);
+// Moves the window to the center of the monitor.
+ASH_EXPORT void CenterWindow(aura::Window* window);
+
} // namespace wm
} // namespace ash
diff --git a/ash/wm/workspace/snap_sizer.cc b/ash/wm/workspace/snap_sizer.cc
index 158fa3a..0816ff0 100644
--- a/ash/wm/workspace/snap_sizer.cc
+++ b/ash/wm/workspace/snap_sizer.cc
@@ -66,6 +66,18 @@ void SnapSizer::Update(const gfx::Point& location) {
time_last_update_ = base::TimeTicks::Now();
}
+gfx::Rect SnapSizer::GetSnapBounds(const gfx::Rect& bounds) {
+ size_t current;
+ for (current = 0; current < arraysize(kPercents); ++current) {
+ gfx::Rect target = GetTargetBoundsForPercent(current);
+ if (target == bounds) {
+ ++current;
+ break;
+ }
+ }
+ return GetTargetBoundsForPercent(current % arraysize(kPercents));
+}
+
int SnapSizer::CalculateIncrement(int x, int reference_x) const {
if (AlongEdge(x))
return 1;
@@ -94,12 +106,16 @@ void SnapSizer::ChangeBounds(int x, int delta) {
}
gfx::Rect SnapSizer::GetTargetBounds() const {
+ return GetTargetBoundsForPercent(percent_index_);
+}
+
+gfx::Rect SnapSizer::GetTargetBoundsForPercent(int percent_index) const {
gfx::Rect work_area(ScreenAsh::GetUnmaximizedWorkAreaBounds(window_));
int y = WindowResizer::AlignToGridRoundUp(work_area.y(), grid_size_);
// We don't align to the bottom of the grid as the launcher may not
// necessarily align to the grid (happens when auto-hidden).
int max_y = work_area.bottom();
- int width = static_cast<float>(work_area.width()) * kPercents[percent_index_];
+ int width = static_cast<float>(work_area.width()) * kPercents[percent_index];
if (edge_ == LEFT_EDGE) {
int x = WindowResizer::AlignToGridRoundUp(work_area.x(), grid_size_);
int mid_x = WindowResizer::AlignToGridRoundUp(
diff --git a/ash/wm/workspace/snap_sizer.h b/ash/wm/workspace/snap_sizer.h
index e389de7..145e4e5 100644
--- a/ash/wm/workspace/snap_sizer.h
+++ b/ash/wm/workspace/snap_sizer.h
@@ -38,6 +38,10 @@ class ASH_EXPORT SnapSizer {
// Bounds to position the window at.
const gfx::Rect& target_bounds() const { return target_bounds_; }
+ // Returns the appropriate snap bounds (e.g. if a window is already snapped,
+ // then it returns the next snap-bounds).
+ gfx::Rect GetSnapBounds(const gfx::Rect& bounds);
+
private:
// Calculates the amount to increment by. This returns one of -1, 0 or 1 and
// is intended to by applied to |percent_index_|. |x| is the current
@@ -53,6 +57,8 @@ class ASH_EXPORT SnapSizer {
// Returns the target bounds based on the edge and |percent_index_|.
gfx::Rect GetTargetBounds() const;
+ gfx::Rect GetTargetBoundsForPercent(int percent_index) const;
+
// Returns true if the specified point is along the edge of the screen.
bool AlongEdge(int x) const;