OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/wm/window_util.h" | 5 #include "ash/wm/window_util.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/ash_constants.h" | 9 #include "ash/ash_constants.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 bool CanMaximizeWindow(const aura::Window* window) { | 79 bool CanMaximizeWindow(const aura::Window* window) { |
80 return window->GetProperty(aura::client::kCanMaximizeKey); | 80 return window->GetProperty(aura::client::kCanMaximizeKey); |
81 } | 81 } |
82 | 82 |
83 bool CanResizeWindow(const aura::Window* window) { | 83 bool CanResizeWindow(const aura::Window* window) { |
84 return window->GetProperty(aura::client::kCanResizeKey); | 84 return window->GetProperty(aura::client::kCanResizeKey); |
85 } | 85 } |
86 | 86 |
87 bool CanSnapWindow(aura::Window* window) { | 87 bool CanSnapWindow(aura::Window* window) { |
88 // If a window has a maximum size defined, snapping may make it too big. | 88 // If a window has a maximum size defined, snapping may make it too big. |
89 return window->delegate()->GetMaximumSize().IsEmpty(); | 89 return window->delegate() ? window->delegate()->GetMaximumSize().IsEmpty() : |
| 90 true; |
90 } | 91 } |
91 | 92 |
92 bool IsWindowNormal(const aura::Window* window) { | 93 bool IsWindowNormal(const aura::Window* window) { |
93 return IsWindowStateNormal(window->GetProperty(aura::client::kShowStateKey)); | 94 return IsWindowStateNormal(window->GetProperty(aura::client::kShowStateKey)); |
94 } | 95 } |
95 | 96 |
96 bool IsWindowStateNormal(ui::WindowShowState state) { | 97 bool IsWindowStateNormal(ui::WindowShowState state) { |
97 return state == ui::SHOW_STATE_NORMAL || state == ui::SHOW_STATE_DEFAULT; | 98 return state == ui::SHOW_STATE_NORMAL || state == ui::SHOW_STATE_DEFAULT; |
98 } | 99 } |
99 | 100 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 } | 133 } |
133 | 134 |
134 void CenterWindow(aura::Window* window) { | 135 void CenterWindow(aura::Window* window) { |
135 const gfx::Display display = | 136 const gfx::Display display = |
136 Shell::GetScreen()->GetDisplayNearestWindow(window); | 137 Shell::GetScreen()->GetDisplayNearestWindow(window); |
137 gfx::Rect center = display.work_area(); | 138 gfx::Rect center = display.work_area(); |
138 center.ClampToCenteredSize(window->bounds().size()); | 139 center.ClampToCenteredSize(window->bounds().size()); |
139 window->SetBounds(center); | 140 window->SetBounds(center); |
140 } | 141 } |
141 | 142 |
| 143 void SnapWindow(aura::Window* window, internal::SnapSizer::Edge edge) { |
| 144 if (!CanSnapWindow(window)) |
| 145 return; |
| 146 internal::SnapSizer sizer(window, gfx::Point(), edge, |
| 147 internal::SnapSizer::OTHER_INPUT); |
| 148 if (wm::IsWindowFullscreen(window) || wm::IsWindowMaximized(window)) { |
| 149 // Before we can set the bounds we need to restore the window. |
| 150 // Restoring the window will set the window to its restored bounds. |
| 151 // To avoid an unnecessary bounds changes (which may have side effects) |
| 152 // we set the restore bounds to the bounds we want, restore the window, |
| 153 // then reset the restore bounds. This way no unnecessary bounds |
| 154 // changes occurs and the original restore bounds is remembered. |
| 155 gfx::Rect restore = *GetRestoreBoundsInScreen(window); |
| 156 SetRestoreBoundsInParent(window, sizer.GetSnapBounds(window->bounds())); |
| 157 wm::RestoreWindow(window); |
| 158 SetRestoreBoundsInScreen(window, restore); |
| 159 } else { |
| 160 window->SetBounds(sizer.GetSnapBounds(window->bounds())); |
| 161 } |
| 162 } |
| 163 |
142 ui::Layer* RecreateWindowLayers(aura::Window* window, bool set_bounds) { | 164 ui::Layer* RecreateWindowLayers(aura::Window* window, bool set_bounds) { |
143 const gfx::Rect bounds = window->bounds(); | 165 const gfx::Rect bounds = window->bounds(); |
144 ui::Layer* old_layer = window->RecreateLayer(); | 166 ui::Layer* old_layer = window->RecreateLayer(); |
145 DCHECK(old_layer); | 167 DCHECK(old_layer); |
146 for (aura::Window::Windows::const_iterator it = window->children().begin(); | 168 for (aura::Window::Windows::const_iterator it = window->children().begin(); |
147 it != window->children().end(); | 169 it != window->children().end(); |
148 ++it) { | 170 ++it) { |
149 // Maintain the hierarchy of the detached layers. | 171 // Maintain the hierarchy of the detached layers. |
150 old_layer->Add(RecreateWindowLayers(*it, set_bounds)); | 172 old_layer->Add(RecreateWindowLayers(*it, set_bounds)); |
151 } | 173 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 x_offset = work_area.right() - bounds->x() - kMinimumOnScreenArea; | 232 x_offset = work_area.right() - bounds->x() - kMinimumOnScreenArea; |
211 } else if (bounds->right() < work_area.x()) { | 233 } else if (bounds->right() < work_area.x()) { |
212 x_offset = work_area.x() - bounds->right() + kMinimumOnScreenArea; | 234 x_offset = work_area.x() - bounds->right() + kMinimumOnScreenArea; |
213 } | 235 } |
214 bounds->Offset(x_offset, y_offset); | 236 bounds->Offset(x_offset, y_offset); |
215 } | 237 } |
216 } | 238 } |
217 | 239 |
218 } // namespace wm | 240 } // namespace wm |
219 } // namespace ash | 241 } // namespace ash |
OLD | NEW |