Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: athena/wm/split_view_controller.cc

Issue 470083004: athena: A simpler implementation of WindowListProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "ui/aura/window.h" 12 #include "ui/aura/window.h"
13 #include "ui/compositor/closure_animation_observer.h" 13 #include "ui/compositor/closure_animation_observer.h"
14 #include "ui/compositor/layer_animation_observer.h" 14 #include "ui/compositor/layer_animation_observer.h"
15 #include "ui/compositor/scoped_layer_animation_settings.h" 15 #include "ui/compositor/scoped_layer_animation_settings.h"
16 #include "ui/events/event_handler.h" 16 #include "ui/events/event_handler.h"
17 #include "ui/gfx/display.h" 17 #include "ui/gfx/display.h"
18 #include "ui/gfx/screen.h" 18 #include "ui/gfx/screen.h"
19 #include "ui/wm/core/window_util.h"
19 20
20 namespace athena { 21 namespace athena {
21 22
22 SplitViewController::SplitViewController( 23 SplitViewController::SplitViewController(
23 aura::Window* container, 24 aura::Window* container,
24 WindowListProvider* window_list_provider, 25 WindowListProvider* window_list_provider)
25 WindowManager* window_manager)
26 : state_(INACTIVE), 26 : state_(INACTIVE),
27 container_(container), 27 container_(container),
28 window_manager_(window_manager),
29 window_list_provider_(window_list_provider), 28 window_list_provider_(window_list_provider),
30 current_activity_window_(NULL),
31 left_window_(NULL), 29 left_window_(NULL),
32 right_window_(NULL), 30 right_window_(NULL),
33 separator_position_(0), 31 separator_position_(0),
34 weak_factory_(this) { 32 weak_factory_(this) {
35 if (window_manager_)
36 window_manager_->AddObserver(this);
37 } 33 }
38 34
39 SplitViewController::~SplitViewController() { 35 SplitViewController::~SplitViewController() {
40 if (window_manager_)
41 window_manager_->RemoveObserver(this);
42 } 36 }
43 37
44 bool SplitViewController::IsSplitViewModeActive() const { 38 bool SplitViewController::IsSplitViewModeActive() const {
45 return state_ == ACTIVE; 39 return state_ == ACTIVE;
46 } 40 }
47 41
48 void SplitViewController::ActivateSplitMode(aura::Window* left, 42 void SplitViewController::ActivateSplitMode(aura::Window* left,
49 aura::Window* right) { 43 aura::Window* right) {
50 aura::Window::Windows windows = window_list_provider_->GetWindowList(); 44 aura::Window::Windows windows = window_list_provider_->GetWindowList();
51 aura::Window::Windows::reverse_iterator iter = windows.rbegin(); 45 aura::Window::Windows::reverse_iterator iter = windows.rbegin();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 right_window_ = right; 78 right_window_ = right;
85 container_->StackChildAtTop(right_window_); 79 container_->StackChildAtTop(right_window_);
86 } 80 }
87 if (left_window_ != left) { 81 if (left_window_ != left) {
88 left_window_ = left; 82 left_window_ = left;
89 container_->StackChildAtTop(left_window_); 83 container_->StackChildAtTop(left_window_);
90 } 84 }
91 UpdateLayout(true); 85 UpdateLayout(true);
92 } 86 }
93 87
88 void SplitViewController::DeactivateSplitMode() {
89 CHECK_NE(SCROLLING, state_);
90 state_ = INACTIVE;
mfomitchev 2014/08/15 18:30:51 Set left/right window to NULL here to be safe.
sadrul 2014/08/15 18:44:18 Done.
91 }
92
94 void SplitViewController::UpdateLayout(bool animate) { 93 void SplitViewController::UpdateLayout(bool animate) {
95 if (!left_window_) 94 if (!left_window_)
96 return; 95 return;
97 CHECK(right_window_); 96 CHECK(right_window_);
98 gfx::Transform left_transform; 97 gfx::Transform left_transform;
99 gfx::Transform right_transform; 98 gfx::Transform right_transform;
100 int container_width = container_->GetBoundsInScreen().width(); 99 int container_width = container_->GetBoundsInScreen().width();
101 if (state_ == ACTIVE) { 100 if (state_ == ACTIVE) {
102 // This method should only be called once in ACTIVE state when 101 // This method should only be called once in ACTIVE state when
103 // the left and rightwindows are still full screen and need to be resized. 102 // the left and rightwindows are still full screen and need to be resized.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 void SplitViewController::UpdateSeparatorPositionFromScrollDelta(float delta) { 172 void SplitViewController::UpdateSeparatorPositionFromScrollDelta(float delta) {
174 gfx::Screen* screen = gfx::Screen::GetScreenFor(container_); 173 gfx::Screen* screen = gfx::Screen::GetScreenFor(container_);
175 const gfx::Rect& display_bounds = 174 const gfx::Rect& display_bounds =
176 screen->GetDisplayNearestWindow(container_).bounds(); 175 screen->GetDisplayNearestWindow(container_).bounds();
177 gfx::Rect container_bounds = container_->GetBoundsInScreen(); 176 gfx::Rect container_bounds = container_->GetBoundsInScreen();
178 separator_position_ = 177 separator_position_ =
179 delta > 0 ? ((int)delta) + display_bounds.x() - container_bounds.x() 178 delta > 0 ? ((int)delta) + display_bounds.x() - container_bounds.x()
180 : display_bounds.right() - container_bounds.x() + delta; 179 : display_bounds.right() - container_bounds.x() + delta;
181 } 180 }
182 181
183 aura::Window* SplitViewController::GetCurrentActivityWindow() { 182 ///////////////////////////////////////////////////////////////////////////////
184 if (!current_activity_window_) { 183 // BezelController::ScrollDelegate:
185 aura::Window::Windows windows = window_list_provider_->GetWindowList();
186 if (windows.empty())
187 return NULL;
188 current_activity_window_ = windows.back();
189 }
190 return current_activity_window_;
191 }
192 184
193 ///////////////////////////////////////////////////////////////////////////////
194 // Begin BezelController::ScrollDelegate overrides.
195 void SplitViewController::ScrollBegin(BezelController::Bezel bezel, 185 void SplitViewController::ScrollBegin(BezelController::Bezel bezel,
196 float delta) { 186 float delta) {
197 if (!CanScroll()) 187 if (!CanScroll())
198 return; 188 return;
199 state_ = SCROLLING; 189 state_ = SCROLLING;
200 aura::Window* current_window = GetCurrentActivityWindow();
201 CHECK(current_window);
202 190
203 aura::Window::Windows windows = window_list_provider_->GetWindowList(); 191 aura::Window::Windows windows = window_list_provider_->GetWindowList();
204 CHECK(windows.size() >= 2); 192 CHECK(windows.size() >= 2);
205 aura::Window::Windows::const_iterator it = 193 aura::Window::Windows::const_reverse_iterator iter = windows.rbegin();
206 std::find(windows.begin(), windows.end(), current_window); 194 aura::Window* current_window = *(iter);
207 CHECK(it != windows.end()); 195 CHECK(wm::IsActiveWindow(current_window));
208 196
209 if (delta > 0) { 197 if (delta > 0) {
210 right_window_ = current_window; 198 right_window_ = current_window;
211 // reverse iterator points to the position before normal iterator |it| 199 left_window_ = *(iter + 1);
212 aura::Window::Windows::const_reverse_iterator rev_it(it);
213 // circle to end if needed.
214 left_window_ = rev_it == windows.rend() ? windows.back() : *(rev_it);
215 } else { 200 } else {
216 left_window_ = current_window; 201 left_window_ = current_window;
217 ++it; 202 right_window_ = *(iter + 1);
218 // circle to front if needed.
219 right_window_ = it == windows.end() ? windows.front() : *it;
220 } 203 }
221 204
222 CHECK(left_window_); 205 CHECK(left_window_);
223 CHECK(right_window_); 206 CHECK(right_window_);
224 207
225 // TODO(oshima|mfomitchev): crbug.com/388362
226 // Until we are properly hiding off-screen windows in window manager:
227 // Loop through all windows and hide them
228 for (it = windows.begin(); it != windows.end(); ++it) {
229 if (*it != left_window_ && *it != right_window_)
230 (*it)->Hide();
231 }
232
233 UpdateSeparatorPositionFromScrollDelta(delta); 208 UpdateSeparatorPositionFromScrollDelta(delta);
234 UpdateLayout(false); 209 UpdateLayout(false);
235 } 210 }
236 211
237 // Max distance from the scroll end position to the middle of the screen where
238 // we would go into the split view mode.
239 const int kMaxDistanceFromMiddle = 120;
240 void SplitViewController::ScrollEnd() { 212 void SplitViewController::ScrollEnd() {
241 if (state_ != SCROLLING) 213 if (state_ != SCROLLING)
242 return; 214 return;
243 215
216 // Max distance from the scroll end position to the middle of the screen where
217 // we would go into the split view mode.
218 const int kMaxDistanceFromMiddle = 120;
244 int container_width = container_->GetBoundsInScreen().width(); 219 int container_width = container_->GetBoundsInScreen().width();
245 if (std::abs(container_width / 2 - separator_position_) <= 220 if (std::abs(container_width / 2 - separator_position_) <=
246 kMaxDistanceFromMiddle) { 221 kMaxDistanceFromMiddle) {
247 state_ = ACTIVE; 222 state_ = ACTIVE;
248 separator_position_ = container_width / 2; 223 separator_position_ = container_width / 2;
249 } else if (separator_position_ < container_width / 2) { 224 } else if (separator_position_ < container_width / 2) {
250 separator_position_ = 0; 225 separator_position_ = 0;
251 current_activity_window_ = right_window_;
252 state_ = INACTIVE; 226 state_ = INACTIVE;
227 wm::ActivateWindow(right_window_);
253 } else { 228 } else {
254 separator_position_ = container_width; 229 separator_position_ = container_width;
255 current_activity_window_ = left_window_;
256 state_ = INACTIVE; 230 state_ = INACTIVE;
231 wm::ActivateWindow(left_window_);
257 } 232 }
258 UpdateLayout(true); 233 UpdateLayout(true);
259 } 234 }
260 235
261 void SplitViewController::ScrollUpdate(float delta) { 236 void SplitViewController::ScrollUpdate(float delta) {
262 if (state_ != SCROLLING) 237 if (state_ != SCROLLING)
263 return; 238 return;
264 UpdateSeparatorPositionFromScrollDelta(delta); 239 UpdateSeparatorPositionFromScrollDelta(delta);
265 UpdateLayout(false); 240 UpdateLayout(false);
266 } 241 }
267 242
268 bool SplitViewController::CanScroll() { 243 bool SplitViewController::CanScroll() {
269 // TODO(mfomitchev): return false in vertical orientation, in full screen. 244 // TODO(mfomitchev): return false in vertical orientation, in full screen.
270 bool result = (window_manager_ && !window_manager_->IsOverviewModeActive() && 245 bool result = (!IsSplitViewModeActive() &&
271 !IsSplitViewModeActive() &&
272 window_list_provider_->GetWindowList().size() >= 2); 246 window_list_provider_->GetWindowList().size() >= 2);
273 return result; 247 return result;
274 } 248 }
275 249
276 ///////////////////////////////////////////////////////////////////////////////
277 // WindowManagerObserver overrides
278 void SplitViewController::OnOverviewModeEnter() {
279 if (state_ == ACTIVE) {
280 CHECK(left_window_);
281 CHECK(right_window_);
282 window_list_provider_->MoveToFront(right_window_);
283 window_list_provider_->MoveToFront(left_window_);
284 // TODO(mfomitchev): This shouldn't be done here, but the overview mode's
285 // transition animation currently looks bad if the starting transform of
286 // any window is not gfx::Transform().
287 right_window_->SetTransform(gfx::Transform());
288 } else if (current_activity_window_) {
289 window_list_provider_->MoveToFront(current_activity_window_);
290 }
291 state_ = INACTIVE;
292 left_window_ = NULL;
293 right_window_ = NULL;
294 current_activity_window_ = NULL;
295 }
296
297 void SplitViewController::OnOverviewModeExit() {
298 }
299
300 } // namespace athena 250 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698