Index: ash/wm/window_util.cc |
diff --git a/ash/wm/window_util.cc b/ash/wm/window_util.cc |
index c3101c75e8dfe0af7a7d7904aff1047692d1d2a7..b1b9484463725668c3f43c1ad697893454d9c84c 100644 |
--- a/ash/wm/window_util.cc |
+++ b/ash/wm/window_util.cc |
@@ -8,9 +8,11 @@ |
#include "ash/ash_constants.h" |
#include "ash/root_window_controller.h" |
+#include "ash/screen_ash.h" |
#include "ash/shell.h" |
#include "ash/shell_window_ids.h" |
#include "ash/wm/activation_controller.h" |
+#include "ash/wm/property_util.h" |
#include "ash/wm/window_properties.h" |
#include "ui/aura/client/activation_client.h" |
#include "ui/aura/client/aura_constants.h" |
@@ -27,6 +29,12 @@ |
namespace ash { |
namespace wm { |
+namespace { |
+ |
+// The percent of the screen's width that a snapped window takes up. |
+const int kSnappedWindowScreenWidthPercent = 50; |
+ |
+} // namespace |
// TODO(beng): replace many of these functions with the corewm versions. |
void ActivateWindow(aura::Window* window) { |
@@ -78,9 +86,24 @@ bool CanResizeWindow(const aura::Window* window) { |
bool CanSnapWindow(aura::Window* window) { |
if (!CanResizeWindow(window)) |
return false; |
- // If a window has a maximum size defined, snapping may make it too big. |
- return window->delegate() ? window->delegate()->GetMaximumSize().IsEmpty() : |
- true; |
+ |
+ if (window->delegate()) { |
+ // The size of a snapped window is not affected by the edge it is snapped |
+ // to. |
+ gfx::Size snapped_size = |
+ GetSnappedWindowBoundsInParent(window, SNAP_LEFT_EDGE).size(); |
+ |
+ gfx::Size minimum_size = window->delegate()->GetMinimumSize(); |
+ if (minimum_size.width() > snapped_size.width()) |
Mr4D (OOO till 08-26)
2013/08/29 01:03:15
Hmm. Does this mean that if you have a window whic
|
+ return false; |
+ gfx::Size maximum_size = window->delegate()->GetMaximumSize(); |
+ if (!maximum_size.IsEmpty() && |
+ (maximum_size.width() < snapped_size.width() || |
+ maximum_size.height() < snapped_size.height())) { |
+ return false; |
+ } |
+ } |
+ return true; |
} |
bool IsWindowNormal(const aura::Window* window) { |
@@ -119,10 +142,37 @@ void RestoreWindow(aura::Window* window) { |
} |
void ToggleMaximizedWindow(aura::Window* window) { |
- if (ash::wm::IsWindowMaximized(window)) |
- ash::wm::RestoreWindow(window); |
- else if (ash::wm::CanMaximizeWindow(window)) |
- ash::wm::MaximizeWindow(window); |
+ if (IsWindowMaximized(window)) |
+ RestoreWindow(window); |
+ else if (CanMaximizeWindow(window)) |
+ MaximizeWindow(window); |
+} |
+ |
+gfx::Rect GetSnappedWindowBoundsInParent(aura::Window* window, SnapEdge edge) { |
+ gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window)); |
+ int width = work_area.width() * kSnappedWindowScreenWidthPercent / 100; |
+ int x = (edge == SNAP_LEFT_EDGE) ? work_area.x() : work_area.right() - width; |
+ |
+ return gfx::Rect(x, work_area.y(), width, work_area.height()); |
+} |
+ |
+void SnapWindowToEdge(aura::Window* window, SnapEdge edge) { |
+ gfx::Rect bounds(GetSnappedWindowBoundsInParent(window, edge)); |
+ |
+ if (IsWindowFullscreen(window) || IsWindowMaximized(window)) { |
+ // Before we can set the bounds we need to restore the window. |
+ // Restoring the window will set the window to its restored bounds. |
+ // To avoid an unnecessary bounds changes (which may have side effects) |
+ // we set the restore bounds to the bounds we want, restore the window, |
+ // then reset the restore bounds. This way no unnecessary bounds |
+ // changes occurs and the original restore bounds is remembered. |
+ gfx::Rect restore = *GetRestoreBoundsInScreen(window); |
+ SetRestoreBoundsInParent(window, bounds); |
+ RestoreWindow(window); |
+ SetRestoreBoundsInScreen(window, restore); |
+ } else { |
+ window->SetBounds(bounds); |
+ } |
} |
void CenterWindow(aura::Window* window) { |