OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/splitview/split_view_controller.h" | 5 #include "ash/wm/splitview/split_view_controller.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/public/cpp/shell_window_ids.h" | 8 #include "ash/public/cpp/shell_window_ids.h" |
9 #include "ash/screen_util.h" | 9 #include "ash/screen_util.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 aura::Window* SplitViewController::GetDefaultSnappedWindow() { | 121 aura::Window* SplitViewController::GetDefaultSnappedWindow() { |
122 if (default_snap_position_ == LEFT) | 122 if (default_snap_position_ == LEFT) |
123 return left_window_; | 123 return left_window_; |
124 if (default_snap_position_ == RIGHT) | 124 if (default_snap_position_ == RIGHT) |
125 return right_window_; | 125 return right_window_; |
126 return nullptr; | 126 return nullptr; |
127 } | 127 } |
128 | 128 |
129 gfx::Rect SplitViewController::GetSnappedWindowBoundsInParent( | 129 gfx::Rect SplitViewController::GetSnappedWindowBoundsInParent( |
130 aura::Window* window, | 130 aura::Window* window, |
131 State snap_state) { | 131 SnapPosition snap_position) { |
132 if (snap_state == LEFT_SNAPPED) | 132 if (snap_position == LEFT) |
133 return GetLeftWindowBoundsInParent(window); | 133 return GetLeftWindowBoundsInParent(window); |
134 else if (snap_state == RIGHT_SNAPPED) | 134 else if (snap_position == RIGHT) |
135 return GetRightWindowBoundsInParent(window); | 135 return GetRightWindowBoundsInParent(window); |
136 | 136 |
137 NOTREACHED(); | 137 NOTREACHED(); |
138 return gfx::Rect(); | 138 return gfx::Rect(); |
139 } | 139 } |
140 | 140 |
141 gfx::Rect SplitViewController::GetSnappedWindowBoundsInScreen( | 141 gfx::Rect SplitViewController::GetSnappedWindowBoundsInScreen( |
142 aura::Window* window, | 142 aura::Window* window, |
143 State snap_state) { | 143 SnapPosition snap_position) { |
144 if (snap_state == LEFT_SNAPPED) | 144 if (snap_position == LEFT) |
145 return GetLeftWindowBoundsInScreen(window); | 145 return GetLeftWindowBoundsInScreen(window); |
146 else if (snap_state == RIGHT_SNAPPED) | 146 else if (snap_position == RIGHT) |
147 return GetRightWindowBoundsInScreen(window); | 147 return GetRightWindowBoundsInScreen(window); |
148 | 148 |
149 NOTREACHED(); | 149 NOTREACHED(); |
150 return gfx::Rect(); | 150 return gfx::Rect(); |
151 } | 151 } |
152 | 152 |
153 gfx::Rect SplitViewController::GetDisplayWorkAreaBoundsInParent( | 153 gfx::Rect SplitViewController::GetDisplayWorkAreaBoundsInParent( |
154 aura::Window* window) { | 154 aura::Window* window) { |
155 aura::Window* root_window = window->GetRootWindow(); | 155 aura::Window* root_window = window->GetRootWindow(); |
156 return ScreenUtil::GetDisplayWorkAreaBoundsInParent( | 156 return ScreenUtil::GetDisplayWorkAreaBoundsInParent( |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 // Only window in MRU list can be snapped. | 213 // Only window in MRU list can be snapped. |
214 aura::Window::Windows windows = | 214 aura::Window::Windows windows = |
215 Shell::Get()->mru_window_tracker()->BuildMruWindowList(); | 215 Shell::Get()->mru_window_tracker()->BuildMruWindowList(); |
216 if (std::find(windows.begin(), windows.end(), gained_active) == windows.end()) | 216 if (std::find(windows.begin(), windows.end(), gained_active) == windows.end()) |
217 return; | 217 return; |
218 | 218 |
219 // Snap the window on the non-default side of the screen if split view mode | 219 // Snap the window on the non-default side of the screen if split view mode |
220 // is active. | 220 // is active. |
221 if (default_snap_position_ == LEFT) | 221 if (default_snap_position_ == LEFT) |
222 SnapWindow(gained_active, SplitViewController::RIGHT); | 222 SnapWindow(gained_active, SplitViewController::RIGHT); |
223 else | 223 else if (default_snap_position_ == RIGHT) |
224 SnapWindow(gained_active, SplitViewController::LEFT); | 224 SnapWindow(gained_active, SplitViewController::LEFT); |
225 } | 225 } |
226 | 226 |
227 void SplitViewController::OnOverviewModeStarting() { | 227 void SplitViewController::OnOverviewModeStarting() { |
228 // If split view mode is active, reset |state_| to make it be able to select | 228 // If split view mode is active, reset |state_| to make it be able to select |
229 // another window from overview window grid. | 229 // another window from overview window grid. |
230 if (IsSplitViewModeActive()) { | 230 if (IsSplitViewModeActive()) { |
231 State previous_state = state_; | 231 State previous_state = state_; |
232 if (default_snap_position_ == LEFT) { | 232 if (default_snap_position_ == LEFT) { |
233 StopObserving(right_window_); | 233 StopObserving(right_window_); |
234 state_ = LEFT_SNAPPED; | 234 state_ = LEFT_SNAPPED; |
235 } else { | 235 } else if (default_snap_position_ == RIGHT) { |
236 StopObserving(left_window_); | 236 StopObserving(left_window_); |
237 state_ = RIGHT_SNAPPED; | 237 state_ = RIGHT_SNAPPED; |
238 } | 238 } |
239 NotifySplitViewStateChanged(previous_state, state_); | 239 NotifySplitViewStateChanged(previous_state, state_); |
240 } | 240 } |
241 } | 241 } |
242 | 242 |
243 void SplitViewController::OnOverviewModeEnded() { | 243 void SplitViewController::OnOverviewModeEnded() { |
244 // If split view mode is active but only has one snapped window, use the MRU | 244 // If split view mode is active but only has one snapped window, use the MRU |
245 // window list to auto select another window to snap. | 245 // window list to auto select another window to snap. |
246 if (IsSplitViewModeActive() && state_ != BOTH_SNAPPED) { | 246 if (IsSplitViewModeActive() && state_ != BOTH_SNAPPED) { |
247 aura::Window::Windows windows = | 247 aura::Window::Windows windows = |
248 Shell::Get()->mru_window_tracker()->BuildMruWindowList(); | 248 Shell::Get()->mru_window_tracker()->BuildMruWindowList(); |
249 for (auto* window : windows) { | 249 for (auto* window : windows) { |
250 if (CanSnap(window) && window != GetDefaultSnappedWindow()) { | 250 if (CanSnap(window) && window != GetDefaultSnappedWindow()) { |
251 if (default_snap_position_ == LEFT) | 251 if (default_snap_position_ == LEFT) |
252 SnapWindow(window, SplitViewController::RIGHT); | 252 SnapWindow(window, SplitViewController::RIGHT); |
253 else | 253 else if (default_snap_position_ == RIGHT) |
254 SnapWindow(window, SplitViewController::LEFT); | 254 SnapWindow(window, SplitViewController::LEFT); |
255 break; | 255 break; |
256 } | 256 } |
257 } | 257 } |
258 } | 258 } |
259 } | 259 } |
260 | 260 |
261 void SplitViewController::EndSplitView() { | 261 void SplitViewController::EndSplitView() { |
262 StopObserving(left_window_); | 262 StopObserving(left_window_); |
263 StopObserving(right_window_); | 263 StopObserving(right_window_); |
264 left_window_ = nullptr; | 264 left_window_ = nullptr; |
265 right_window_ = nullptr; | 265 right_window_ = nullptr; |
266 default_snap_position_ = LEFT; | 266 default_snap_position_ = NONE; |
267 divider_position_ = -1; | 267 divider_position_ = -1; |
268 | 268 |
269 State previous_state = state_; | 269 State previous_state = state_; |
270 state_ = NO_SNAP; | 270 state_ = NO_SNAP; |
271 NotifySplitViewStateChanged(previous_state, state_); | 271 NotifySplitViewStateChanged(previous_state, state_); |
272 | 272 |
273 Shell::Get()->NotifySplitViewModeEnded(); | 273 Shell::Get()->NotifySplitViewModeEnded(); |
274 } | 274 } |
275 | 275 |
276 void SplitViewController::StartObserving(aura::Window* window) { | 276 void SplitViewController::StartObserving(aura::Window* window) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 divider_position_ = | 330 divider_position_ = |
331 display_bounds_in_screen.x() + display_bounds_in_screen.width() * 0.5f; | 331 display_bounds_in_screen.x() + display_bounds_in_screen.width() * 0.5f; |
332 } | 332 } |
333 return gfx::Rect(divider_position_, display_bounds_in_screen.y(), | 333 return gfx::Rect(divider_position_, display_bounds_in_screen.y(), |
334 display_bounds_in_screen.x() + | 334 display_bounds_in_screen.x() + |
335 display_bounds_in_screen.width() - divider_position_, | 335 display_bounds_in_screen.width() - divider_position_, |
336 display_bounds_in_screen.height()); | 336 display_bounds_in_screen.height()); |
337 } | 337 } |
338 | 338 |
339 } // namespace ash | 339 } // namespace ash |
OLD | NEW |