Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1901)

Unified Diff: ash/wm/window_util.cc

Issue 11434004: ash: Refactor some code that snaps windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« ash/wm/window_util.h ('K') | « ash/wm/window_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/wm/window_util.cc
diff --git a/ash/wm/window_util.cc b/ash/wm/window_util.cc
index 3adb2968049eadccb5da5e65493634e3691b9d19..460b9c35f16acf15bb8015915f2e8fa6f4e3813e 100644
--- a/ash/wm/window_util.cc
+++ b/ash/wm/window_util.cc
@@ -86,7 +86,8 @@ bool CanResizeWindow(const aura::Window* window) {
bool CanSnapWindow(aura::Window* window) {
// If a window has a maximum size defined, snapping may make it too big.
- return window->delegate()->GetMaximumSize().IsEmpty();
+ return window->delegate() ? window->delegate()->GetMaximumSize().IsEmpty() :
+ true;
}
bool IsWindowNormal(const aura::Window* window) {
@@ -139,6 +140,27 @@ void CenterWindow(aura::Window* window) {
window->SetBounds(center);
}
+void SnapWindow(aura::Window* window, internal::SnapSizer::Edge edge) {
+ if (!CanSnapWindow(window))
+ return;
+ internal::SnapSizer sizer(window, gfx::Point(), edge,
+ internal::SnapSizer::OTHER_INPUT);
+ if (wm::IsWindowFullscreen(window) || wm::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, sizer.GetSnapBounds(window->bounds()));
+ wm::RestoreWindow(window);
+ SetRestoreBoundsInScreen(window, restore);
+ } else {
+ window->SetBounds(sizer.GetSnapBounds(window->bounds()));
+ }
+}
+
ui::Layer* RecreateWindowLayers(aura::Window* window, bool set_bounds) {
const gfx::Rect bounds = window->bounds();
ui::Layer* old_layer = window->RecreateLayer();
« ash/wm/window_util.h ('K') | « ash/wm/window_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698