diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-25 21:48:12 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-25 21:48:12 +0000 |
commit | bc6d23dc0d55aeda0be5ae9d799046ff6a43db14 (patch) | |
tree | 91b37fa8dcc3981bae4d46e9c17259837585df18 /ash/wm | |
parent | 02a5fe29729b8230764a17651ac646f96d680b74 (diff) | |
download | chromium_src-bc6d23dc0d55aeda0be5ae9d799046ff6a43db14.zip chromium_src-bc6d23dc0d55aeda0be5ae9d799046ff6a43db14.tar.gz chromium_src-bc6d23dc0d55aeda0be5ae9d799046ff6a43db14.tar.bz2 |
ash: Add accelerator for snapping windows left/right.
BUG=none
TEST=none
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=133982
Review URL: https://chromiumcodereview.appspot.com/9956056
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133989 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/wm')
-rw-r--r-- | ash/wm/window_util.cc | 7 | ||||
-rw-r--r-- | ash/wm/window_util.h | 3 | ||||
-rw-r--r-- | ash/wm/workspace/snap_sizer.cc | 18 | ||||
-rw-r--r-- | ash/wm/workspace/snap_sizer.h | 6 |
4 files changed, 33 insertions, 1 deletions
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; |