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/workspace/snap_sizer.h" | 5 #include "ash/wm/workspace/snap_sizer.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
10 #include "ash/screen_ash.h" | 10 #include "ash/screen_ash.h" |
11 #include "ash/wm/property_util.h" | |
12 #include "ash/wm/window_resizer.h" | 11 #include "ash/wm/window_resizer.h" |
12 #include "ash/wm/window_state.h" | |
13 #include "ash/wm/window_util.h" | 13 #include "ash/wm/window_util.h" |
14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
15 #include "ui/aura/window_delegate.h" | 15 #include "ui/aura/window_delegate.h" |
16 #include "ui/gfx/screen.h" | 16 #include "ui/gfx/screen.h" |
17 | 17 |
18 namespace ash { | 18 namespace ash { |
19 namespace internal { | 19 namespace internal { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 ideal_width_list.push_back(minimum_width); | 118 ideal_width_list.push_back(minimum_width); |
119 else | 119 else |
120 ideal_width_list.push_back(maximum_width); | 120 ideal_width_list.push_back(maximum_width); |
121 } | 121 } |
122 | 122 |
123 return ideal_width_list; | 123 return ideal_width_list; |
124 } | 124 } |
125 | 125 |
126 // Changes |window|'s bounds to |snap_bounds| while preserving the restore | 126 // Changes |window|'s bounds to |snap_bounds| while preserving the restore |
127 // bounds. | 127 // bounds. |
128 void SnapWindowToBounds(aura::Window* window, const gfx::Rect& snap_bounds) { | 128 void SnapWindowToBounds(wm::WindowState* window_state, |
129 if (wm::IsWindowMaximized(window) || wm::IsWindowFullscreen(window)) { | 129 const gfx::Rect& snap_bounds) { |
130 if (window_state->IsMaximizedOrFullscreen()) { | |
130 // Before we can set the bounds we need to restore the window. | 131 // Before we can set the bounds we need to restore the window. |
131 // Restoring the window will set the window to its restored bounds. | 132 // Restoring the window will set the window to its restored bounds. |
132 // To avoid an unnecessary bounds changes (which may have side effects) | 133 // To avoid an unnecessary bounds changes (which may have side effects) |
133 // we set the restore bounds to the bounds we want, restore the window, | 134 // we set the restore bounds to the bounds we want, restore the window, |
134 // then reset the restore bounds. This way no unnecessary bounds | 135 // then reset the restore bounds. This way no unnecessary bounds |
135 // changes occurs and the original restore bounds is remembered. | 136 // changes occurs and the original restore bounds is remembered. |
136 gfx::Rect restore_bounds_in_screen = *GetRestoreBoundsInScreen(window); | 137 gfx::Rect restore_bounds_in_screen = |
137 SetRestoreBoundsInParent(window, snap_bounds); | 138 window_state->GetRestoreBoundsInScreen(); |
138 wm::RestoreWindow(window); | 139 window_state->SetRestoreBoundsInParent(snap_bounds); |
139 SetRestoreBoundsInScreen(window, restore_bounds_in_screen); | 140 window_state->Restore(); |
141 window_state->SetRestoreBoundsInScreen(restore_bounds_in_screen); | |
140 } else { | 142 } else { |
141 window->SetBounds(snap_bounds); | 143 window_state->window()->SetBounds(snap_bounds); |
142 } | 144 } |
143 } | 145 } |
144 | 146 |
145 } // namespace | 147 } // namespace |
146 | 148 |
147 SnapSizer::SnapSizer(aura::Window* window, | 149 SnapSizer::SnapSizer(aura::Window* window, |
148 const gfx::Point& start, | 150 const gfx::Point& start, |
149 Edge edge, | 151 Edge edge, |
150 InputType input_type) | 152 InputType input_type) |
151 : window_(window), | 153 : window_(window), |
152 edge_(edge), | 154 edge_(edge), |
153 time_last_update_(base::TimeTicks::Now()), | 155 time_last_update_(base::TimeTicks::Now()), |
154 size_index_(0), | 156 size_index_(0), |
155 end_of_sequence_(false), | 157 end_of_sequence_(false), |
156 resize_disabled_(false), | 158 resize_disabled_(false), |
157 num_moves_since_adjust_(0), | 159 num_moves_since_adjust_(0), |
158 last_adjust_x_(start.x()), | 160 last_adjust_x_(start.x()), |
159 last_update_x_(start.x()), | 161 last_update_x_(start.x()), |
160 start_x_(start.x()), | 162 start_x_(start.x()), |
161 input_type_(input_type), | 163 input_type_(input_type), |
162 usable_width_(BuildIdealWidthList(window)) { | 164 usable_width_(BuildIdealWidthList(window)) { |
163 DCHECK(!usable_width_.empty()); | 165 DCHECK(!usable_width_.empty()); |
164 target_bounds_ = GetTargetBounds(); | 166 target_bounds_ = GetTargetBounds(); |
165 } | 167 } |
166 | 168 |
167 SnapSizer::~SnapSizer() { | 169 SnapSizer::~SnapSizer() { |
168 } | 170 } |
169 | 171 |
170 void SnapSizer::SnapWindow(aura::Window* window, SnapSizer::Edge edge) { | 172 void SnapSizer::SnapWindow(aura::Window* window, SnapSizer::Edge edge) { |
171 if (!wm::CanSnapWindow(window)) | 173 wm::WindowState* window_state = wm::GetWindowState(window); |
174 if (!window_state->CanSnap()) | |
172 return; | 175 return; |
173 internal::SnapSizer sizer(window, gfx::Point(), edge, | 176 internal::SnapSizer sizer(window_state->window(), gfx::Point(), edge, |
James Cook
2013/09/19 03:49:53
nit: Maybe just use |window|?
oshima
2013/09/19 17:44:05
Done.
| |
174 internal::SnapSizer::OTHER_INPUT); | 177 internal::SnapSizer::OTHER_INPUT); |
175 SnapWindowToBounds(window, sizer.GetSnapBounds(window->bounds())); | 178 SnapWindowToBounds(window_state, |
179 sizer.GetSnapBounds(window_state->window()->bounds())); | |
176 } | 180 } |
177 | 181 |
178 void SnapSizer::SnapWindowToTargetBounds() { | 182 void SnapSizer::SnapWindowToTargetBounds() { |
179 SnapWindowToBounds(window_, target_bounds()); | 183 SnapWindowToBounds(wm::GetWindowState(window_), target_bounds()); |
180 } | 184 } |
181 | 185 |
182 void SnapSizer::Update(const gfx::Point& location) { | 186 void SnapSizer::Update(const gfx::Point& location) { |
183 // See description above for details on this behavior. | 187 // See description above for details on this behavior. |
184 num_moves_since_adjust_++; | 188 num_moves_since_adjust_++; |
185 if ((base::TimeTicks::Now() - time_last_update_).InMilliseconds() > | 189 if ((base::TimeTicks::Now() - time_last_update_).InMilliseconds() > |
186 kDelayBeforeIncreaseMS) { | 190 kDelayBeforeIncreaseMS) { |
187 ChangeBounds(location.x(), | 191 ChangeBounds(location.x(), |
188 CalculateIncrement(location.x(), last_update_x_)); | 192 CalculateIncrement(location.x(), last_update_x_)); |
189 } else { | 193 } else { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 return GetTargetBoundsForSize(size_index_); | 292 return GetTargetBoundsForSize(size_index_); |
289 } | 293 } |
290 | 294 |
291 bool SnapSizer::AlongEdge(int x) const { | 295 bool SnapSizer::AlongEdge(int x) const { |
292 gfx::Rect area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_)); | 296 gfx::Rect area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_)); |
293 return (x <= area.x()) || (x >= area.right() - 1); | 297 return (x <= area.x()) || (x >= area.right() - 1); |
294 } | 298 } |
295 | 299 |
296 } // namespace internal | 300 } // namespace internal |
297 } // namespace ash | 301 } // namespace ash |
OLD | NEW |