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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 WindowManager* window_manager) | 49 WindowManager* window_manager) |
50 : state_(INACTIVE), | 50 : state_(INACTIVE), |
51 container_(container), | 51 container_(container), |
52 window_manager_(window_manager), | 52 window_manager_(window_manager), |
53 window_list_provider_(window_list_provider), | 53 window_list_provider_(window_list_provider), |
54 current_activity_window_(NULL), | 54 current_activity_window_(NULL), |
55 left_window_(NULL), | 55 left_window_(NULL), |
56 right_window_(NULL), | 56 right_window_(NULL), |
57 separator_position_(0), | 57 separator_position_(0), |
58 weak_factory_(this) { | 58 weak_factory_(this) { |
59 window_manager->AddObserver(this); | 59 if (window_manager_) |
| 60 window_manager_->AddObserver(this); |
60 } | 61 } |
61 | 62 |
62 SplitViewController::~SplitViewController() { | 63 SplitViewController::~SplitViewController() { |
63 window_manager_->RemoveObserver(this); | 64 if (window_manager_) |
| 65 window_manager_->RemoveObserver(this); |
64 } | 66 } |
65 | 67 |
66 bool SplitViewController::IsSplitViewModeActive() const { | 68 bool SplitViewController::IsSplitViewModeActive() const { |
67 return state_ == ACTIVE; | 69 return state_ == ACTIVE; |
68 } | 70 } |
69 | 71 |
70 void SplitViewController::ActivateSplitMode(aura::Window* left, | 72 void SplitViewController::ActivateSplitMode(aura::Window* left, |
71 aura::Window* right) { | 73 aura::Window* right) { |
72 aura::Window::Windows windows = window_list_provider_->GetWindowList(); | 74 aura::Window::Windows windows = window_list_provider_->GetWindowList(); |
73 aura::Window::Windows::reverse_iterator iter = windows.rbegin(); | 75 aura::Window::Windows::reverse_iterator iter = windows.rbegin(); |
74 if (state_ == ACTIVE) { | 76 if (state_ == ACTIVE) { |
| 77 if (left_window_ == right) |
| 78 left_window_ = left; |
| 79 if (right_window_ == left) |
| 80 right_window_ = right; |
| 81 |
75 if (!left) | 82 if (!left) |
76 left = left_window_; | 83 left = left_window_; |
77 if (!right) | 84 if (!right) |
78 right = right_window_; | 85 right = right_window_; |
79 } | 86 } |
80 | 87 |
81 if (!left && iter != windows.rend()) { | 88 if (!left && iter != windows.rend()) { |
82 left = *iter; | 89 left = *iter; |
83 iter++; | 90 iter++; |
84 if (left == right && iter != windows.rend()) { | 91 if (left == right && iter != windows.rend()) { |
85 left = *iter; | 92 left = *iter; |
86 iter++; | 93 iter++; |
87 } | 94 } |
88 } | 95 } |
89 | 96 |
90 if (!right && iter != windows.rend()) { | 97 if (!right && iter != windows.rend()) { |
91 right = *iter; | 98 right = *iter; |
92 iter++; | 99 iter++; |
93 if (right == left && iter != windows.rend()) { | 100 if (right == left && iter != windows.rend()) { |
94 right = *iter; | 101 right = *iter; |
95 iter++; | 102 iter++; |
96 } | 103 } |
97 } | 104 } |
98 | 105 |
99 state_ = ACTIVE; | 106 state_ = ACTIVE; |
100 left_window_ = left; | 107 if (right_window_ != right) { |
101 right_window_ = right; | 108 right_window_ = right; |
102 container_->StackChildAtTop(right_window_); | 109 container_->StackChildAtTop(right_window_); |
103 container_->StackChildAtTop(left_window_); | 110 } |
| 111 if (left_window_ != left) { |
| 112 left_window_ = left; |
| 113 container_->StackChildAtTop(left_window_); |
| 114 } |
104 UpdateLayout(true); | 115 UpdateLayout(true); |
105 } | 116 } |
106 | 117 |
107 void SplitViewController::UpdateLayout(bool animate) { | 118 void SplitViewController::UpdateLayout(bool animate) { |
108 if (!left_window_) | 119 if (!left_window_) |
109 return; | 120 return; |
110 CHECK(right_window_); | 121 CHECK(right_window_); |
111 gfx::Transform left_transform; | 122 gfx::Transform left_transform; |
112 gfx::Transform right_transform; | 123 gfx::Transform right_transform; |
113 int container_width = container_->GetBoundsInScreen().width(); | 124 int container_width = container_->GetBoundsInScreen().width(); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 284 |
274 void SplitViewController::ScrollUpdate(float delta) { | 285 void SplitViewController::ScrollUpdate(float delta) { |
275 if (state_ != SCROLLING) | 286 if (state_ != SCROLLING) |
276 return; | 287 return; |
277 UpdateSeparatorPositionFromScrollDelta(delta); | 288 UpdateSeparatorPositionFromScrollDelta(delta); |
278 UpdateLayout(false); | 289 UpdateLayout(false); |
279 } | 290 } |
280 | 291 |
281 bool SplitViewController::CanScroll() { | 292 bool SplitViewController::CanScroll() { |
282 // TODO(mfomitchev): return false in vertical orientation, in full screen. | 293 // TODO(mfomitchev): return false in vertical orientation, in full screen. |
283 bool result = (!window_manager_->IsOverviewModeActive() && | 294 bool result = (window_manager_ && !window_manager_->IsOverviewModeActive() && |
284 !IsSplitViewModeActive() && | 295 !IsSplitViewModeActive() && |
285 window_list_provider_->GetWindowList().size() >= 2); | 296 window_list_provider_->GetWindowList().size() >= 2); |
286 return result; | 297 return result; |
287 } | 298 } |
288 | 299 |
289 /////////////////////////////////////////////////////////////////////////////// | 300 /////////////////////////////////////////////////////////////////////////////// |
290 // WindowManagerObserver overrides | 301 // WindowManagerObserver overrides |
291 void SplitViewController::OnOverviewModeEnter() { | 302 void SplitViewController::OnOverviewModeEnter() { |
292 if (state_ == ACTIVE) { | 303 if (state_ == ACTIVE) { |
293 CHECK(left_window_); | 304 CHECK(left_window_); |
(...skipping 10 matching lines...) Expand all Loading... |
304 state_ = INACTIVE; | 315 state_ = INACTIVE; |
305 left_window_ = NULL; | 316 left_window_ = NULL; |
306 right_window_ = NULL; | 317 right_window_ = NULL; |
307 current_activity_window_ = NULL; | 318 current_activity_window_ = NULL; |
308 } | 319 } |
309 | 320 |
310 void SplitViewController::OnOverviewModeExit() { | 321 void SplitViewController::OnOverviewModeExit() { |
311 } | 322 } |
312 | 323 |
313 } // namespace athena | 324 } // namespace athena |
OLD | NEW |