OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "athena/wm/split_view_controller.h" | 5 #include "athena/wm/split_view_controller.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "athena/wm/public/window_list_provider.h" | 9 #include "athena/wm/public/window_list_provider.h" |
10 #include "athena/wm/public/window_manager.h" | 10 #include "athena/wm/public/window_manager.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 WindowManager* window_manager) | 25 WindowManager* window_manager) |
26 : state_(INACTIVE), | 26 : state_(INACTIVE), |
27 container_(container), | 27 container_(container), |
28 window_manager_(window_manager), | 28 window_manager_(window_manager), |
29 window_list_provider_(window_list_provider), | 29 window_list_provider_(window_list_provider), |
30 current_activity_window_(NULL), | 30 current_activity_window_(NULL), |
31 left_window_(NULL), | 31 left_window_(NULL), |
32 right_window_(NULL), | 32 right_window_(NULL), |
33 separator_position_(0), | 33 separator_position_(0), |
34 weak_factory_(this) { | 34 weak_factory_(this) { |
35 window_manager->AddObserver(this); | 35 if (window_manager_) |
| 36 window_manager_->AddObserver(this); |
36 } | 37 } |
37 | 38 |
38 SplitViewController::~SplitViewController() { | 39 SplitViewController::~SplitViewController() { |
39 window_manager_->RemoveObserver(this); | 40 if (window_manager_) |
| 41 window_manager_->RemoveObserver(this); |
40 } | 42 } |
41 | 43 |
42 bool SplitViewController::IsSplitViewModeActive() const { | 44 bool SplitViewController::IsSplitViewModeActive() const { |
43 return state_ == ACTIVE; | 45 return state_ == ACTIVE; |
44 } | 46 } |
45 | 47 |
46 void SplitViewController::ActivateSplitMode(aura::Window* left, | 48 void SplitViewController::ActivateSplitMode(aura::Window* left, |
47 aura::Window* right) { | 49 aura::Window* right) { |
48 aura::Window::Windows windows = window_list_provider_->GetWindowList(); | 50 aura::Window::Windows windows = window_list_provider_->GetWindowList(); |
49 aura::Window::Windows::reverse_iterator iter = windows.rbegin(); | 51 aura::Window::Windows::reverse_iterator iter = windows.rbegin(); |
50 if (state_ == ACTIVE) { | 52 if (state_ == ACTIVE) { |
| 53 if (left_window_ == right) |
| 54 left_window_ = left; |
| 55 if (right_window_ == left) |
| 56 right_window_ = right; |
| 57 |
51 if (!left) | 58 if (!left) |
52 left = left_window_; | 59 left = left_window_; |
53 if (!right) | 60 if (!right) |
54 right = right_window_; | 61 right = right_window_; |
55 } | 62 } |
56 | 63 |
57 if (!left && iter != windows.rend()) { | 64 if (!left && iter != windows.rend()) { |
58 left = *iter; | 65 left = *iter; |
59 iter++; | 66 iter++; |
60 if (left == right && iter != windows.rend()) { | 67 if (left == right && iter != windows.rend()) { |
61 left = *iter; | 68 left = *iter; |
62 iter++; | 69 iter++; |
63 } | 70 } |
64 } | 71 } |
65 | 72 |
66 if (!right && iter != windows.rend()) { | 73 if (!right && iter != windows.rend()) { |
67 right = *iter; | 74 right = *iter; |
68 iter++; | 75 iter++; |
69 if (right == left && iter != windows.rend()) { | 76 if (right == left && iter != windows.rend()) { |
70 right = *iter; | 77 right = *iter; |
71 iter++; | 78 iter++; |
72 } | 79 } |
73 } | 80 } |
74 | 81 |
75 state_ = ACTIVE; | 82 state_ = ACTIVE; |
76 left_window_ = left; | 83 if (right_window_ != right) { |
77 right_window_ = right; | 84 right_window_ = right; |
78 container_->StackChildAtTop(right_window_); | 85 container_->StackChildAtTop(right_window_); |
79 container_->StackChildAtTop(left_window_); | 86 } |
| 87 if (left_window_ != left) { |
| 88 left_window_ = left; |
| 89 container_->StackChildAtTop(left_window_); |
| 90 } |
80 UpdateLayout(true); | 91 UpdateLayout(true); |
81 } | 92 } |
82 | 93 |
83 void SplitViewController::UpdateLayout(bool animate) { | 94 void SplitViewController::UpdateLayout(bool animate) { |
84 if (!left_window_) | 95 if (!left_window_) |
85 return; | 96 return; |
86 CHECK(right_window_); | 97 CHECK(right_window_); |
87 gfx::Transform left_transform; | 98 gfx::Transform left_transform; |
88 gfx::Transform right_transform; | 99 gfx::Transform right_transform; |
89 int container_width = container_->GetBoundsInScreen().width(); | 100 int container_width = container_->GetBoundsInScreen().width(); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 | 260 |
250 void SplitViewController::ScrollUpdate(float delta) { | 261 void SplitViewController::ScrollUpdate(float delta) { |
251 if (state_ != SCROLLING) | 262 if (state_ != SCROLLING) |
252 return; | 263 return; |
253 UpdateSeparatorPositionFromScrollDelta(delta); | 264 UpdateSeparatorPositionFromScrollDelta(delta); |
254 UpdateLayout(false); | 265 UpdateLayout(false); |
255 } | 266 } |
256 | 267 |
257 bool SplitViewController::CanScroll() { | 268 bool SplitViewController::CanScroll() { |
258 // TODO(mfomitchev): return false in vertical orientation, in full screen. | 269 // TODO(mfomitchev): return false in vertical orientation, in full screen. |
259 bool result = (!window_manager_->IsOverviewModeActive() && | 270 bool result = (window_manager_ && !window_manager_->IsOverviewModeActive() && |
260 !IsSplitViewModeActive() && | 271 !IsSplitViewModeActive() && |
261 window_list_provider_->GetWindowList().size() >= 2); | 272 window_list_provider_->GetWindowList().size() >= 2); |
262 return result; | 273 return result; |
263 } | 274 } |
264 | 275 |
265 /////////////////////////////////////////////////////////////////////////////// | 276 /////////////////////////////////////////////////////////////////////////////// |
266 // WindowManagerObserver overrides | 277 // WindowManagerObserver overrides |
267 void SplitViewController::OnOverviewModeEnter() { | 278 void SplitViewController::OnOverviewModeEnter() { |
268 if (state_ == ACTIVE) { | 279 if (state_ == ACTIVE) { |
269 CHECK(left_window_); | 280 CHECK(left_window_); |
(...skipping 10 matching lines...) Expand all Loading... |
280 state_ = INACTIVE; | 291 state_ = INACTIVE; |
281 left_window_ = NULL; | 292 left_window_ = NULL; |
282 right_window_ = NULL; | 293 right_window_ = NULL; |
283 current_activity_window_ = NULL; | 294 current_activity_window_ = NULL; |
284 } | 295 } |
285 | 296 |
286 void SplitViewController::OnOverviewModeExit() { | 297 void SplitViewController::OnOverviewModeExit() { |
287 } | 298 } |
288 | 299 |
289 } // namespace athena | 300 } // namespace athena |
OLD | NEW |