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

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
« no previous file with comments | « athena/wm/split_view_controller.h ('k') | athena/wm/split_view_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
91 left_window_ = right_window_ = NULL;
92 }
93
94 void SplitViewController::UpdateLayout(bool animate) { 94 void SplitViewController::UpdateLayout(bool animate) {
95 if (!left_window_) 95 if (!left_window_)
96 return; 96 return;
97 CHECK(right_window_); 97 CHECK(right_window_);
98 gfx::Transform left_transform; 98 gfx::Transform left_transform;
99 gfx::Transform right_transform; 99 gfx::Transform right_transform;
100 int container_width = container_->GetBoundsInScreen().width(); 100 int container_width = container_->GetBoundsInScreen().width();
101 if (state_ == ACTIVE) { 101 if (state_ == ACTIVE) {
102 // This method should only be called once in ACTIVE state when 102 // 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. 103 // 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) { 173 void SplitViewController::UpdateSeparatorPositionFromScrollDelta(float delta) {
174 gfx::Screen* screen = gfx::Screen::GetScreenFor(container_); 174 gfx::Screen* screen = gfx::Screen::GetScreenFor(container_);
175 const gfx::Rect& display_bounds = 175 const gfx::Rect& display_bounds =
176 screen->GetDisplayNearestWindow(container_).bounds(); 176 screen->GetDisplayNearestWindow(container_).bounds();
177 gfx::Rect container_bounds = container_->GetBoundsInScreen(); 177 gfx::Rect container_bounds = container_->GetBoundsInScreen();
178 separator_position_ = 178 separator_position_ =
179 delta > 0 ? ((int)delta) + display_bounds.x() - container_bounds.x() 179 delta > 0 ? ((int)delta) + display_bounds.x() - container_bounds.x()
180 : display_bounds.right() - container_bounds.x() + delta; 180 : display_bounds.right() - container_bounds.x() + delta;
181 } 181 }
182 182
183 aura::Window* SplitViewController::GetCurrentActivityWindow() { 183 ///////////////////////////////////////////////////////////////////////////////
184 if (!current_activity_window_) { 184 // 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 185
193 ///////////////////////////////////////////////////////////////////////////////
194 // Begin BezelController::ScrollDelegate overrides.
195 void SplitViewController::ScrollBegin(BezelController::Bezel bezel, 186 void SplitViewController::ScrollBegin(BezelController::Bezel bezel,
196 float delta) { 187 float delta) {
197 if (!CanScroll()) 188 if (!CanScroll())
198 return; 189 return;
199 state_ = SCROLLING; 190 state_ = SCROLLING;
200 aura::Window* current_window = GetCurrentActivityWindow();
201 CHECK(current_window);
202 191
203 aura::Window::Windows windows = window_list_provider_->GetWindowList(); 192 aura::Window::Windows windows = window_list_provider_->GetWindowList();
204 CHECK(windows.size() >= 2); 193 CHECK(windows.size() >= 2);
205 aura::Window::Windows::const_iterator it = 194 aura::Window::Windows::const_reverse_iterator iter = windows.rbegin();
206 std::find(windows.begin(), windows.end(), current_window); 195 aura::Window* current_window = *(iter);
207 CHECK(it != windows.end()); 196 CHECK(wm::IsActiveWindow(current_window));
208 197
209 if (delta > 0) { 198 if (delta > 0) {
210 right_window_ = current_window; 199 right_window_ = current_window;
211 // reverse iterator points to the position before normal iterator |it| 200 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 { 201 } else {
216 left_window_ = current_window; 202 left_window_ = current_window;
217 ++it; 203 right_window_ = *(iter + 1);
218 // circle to front if needed.
219 right_window_ = it == windows.end() ? windows.front() : *it;
220 } 204 }
221 205
222 CHECK(left_window_); 206 CHECK(left_window_);
223 CHECK(right_window_); 207 CHECK(right_window_);
224 208
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); 209 UpdateSeparatorPositionFromScrollDelta(delta);
234 UpdateLayout(false); 210 UpdateLayout(false);
235 } 211 }
236 212
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() { 213 void SplitViewController::ScrollEnd() {
241 if (state_ != SCROLLING) 214 if (state_ != SCROLLING)
242 return; 215 return;
243 216
217 // Max distance from the scroll end position to the middle of the screen where
218 // we would go into the split view mode.
219 const int kMaxDistanceFromMiddle = 120;
244 int container_width = container_->GetBoundsInScreen().width(); 220 int container_width = container_->GetBoundsInScreen().width();
245 if (std::abs(container_width / 2 - separator_position_) <= 221 if (std::abs(container_width / 2 - separator_position_) <=
246 kMaxDistanceFromMiddle) { 222 kMaxDistanceFromMiddle) {
247 state_ = ACTIVE; 223 state_ = ACTIVE;
248 separator_position_ = container_width / 2; 224 separator_position_ = container_width / 2;
249 } else if (separator_position_ < container_width / 2) { 225 } else if (separator_position_ < container_width / 2) {
250 separator_position_ = 0; 226 separator_position_ = 0;
251 current_activity_window_ = right_window_;
252 state_ = INACTIVE; 227 state_ = INACTIVE;
228 wm::ActivateWindow(right_window_);
253 } else { 229 } else {
254 separator_position_ = container_width; 230 separator_position_ = container_width;
255 current_activity_window_ = left_window_;
256 state_ = INACTIVE; 231 state_ = INACTIVE;
232 wm::ActivateWindow(left_window_);
257 } 233 }
258 UpdateLayout(true); 234 UpdateLayout(true);
259 } 235 }
260 236
261 void SplitViewController::ScrollUpdate(float delta) { 237 void SplitViewController::ScrollUpdate(float delta) {
262 if (state_ != SCROLLING) 238 if (state_ != SCROLLING)
263 return; 239 return;
264 UpdateSeparatorPositionFromScrollDelta(delta); 240 UpdateSeparatorPositionFromScrollDelta(delta);
265 UpdateLayout(false); 241 UpdateLayout(false);
266 } 242 }
267 243
268 bool SplitViewController::CanScroll() { 244 bool SplitViewController::CanScroll() {
269 // TODO(mfomitchev): return false in vertical orientation, in full screen. 245 // TODO(mfomitchev): return false in vertical orientation, in full screen.
270 bool result = (window_manager_ && !window_manager_->IsOverviewModeActive() && 246 bool result = (!IsSplitViewModeActive() &&
271 !IsSplitViewModeActive() &&
272 window_list_provider_->GetWindowList().size() >= 2); 247 window_list_provider_->GetWindowList().size() >= 2);
273 return result; 248 return result;
274 } 249 }
275 250
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 251 } // namespace athena
OLDNEW
« no previous file with comments | « athena/wm/split_view_controller.h ('k') | athena/wm/split_view_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698