Chromium Code Reviews| 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" |
| 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/layer_animation_observer.h" | 13 #include "ui/compositor/layer_animation_observer.h" |
| 14 #include "ui/compositor/scoped_layer_animation_settings.h" | 14 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 15 #include "ui/events/event_handler.h" | 15 #include "ui/events/event_handler.h" |
| 16 #include "ui/gfx/display.h" | 16 #include "ui/gfx/display.h" |
| 17 #include "ui/gfx/screen.h" | 17 #include "ui/gfx/screen.h" |
| 18 #include "ui/wm/core/window_util.h" | |
| 18 | 19 |
| 19 namespace athena { | 20 namespace athena { |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 // An animation observer that runs a callback at the end of the animation, and | 23 // An animation observer that runs a callback at the end of the animation, and |
| 23 // destroys itself. | 24 // destroys itself. |
| 24 class CallbackAnimationObserver : public ui::ImplicitAnimationObserver { | 25 class CallbackAnimationObserver : public ui::ImplicitAnimationObserver { |
| 25 public: | 26 public: |
| 26 explicit CallbackAnimationObserver(const base::Closure& closure) | 27 explicit CallbackAnimationObserver(const base::Closure& closure) |
| 27 : closure_(closure) {} | 28 : closure_(closure) {} |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 38 | 39 |
| 39 const base::Closure closure_; | 40 const base::Closure closure_; |
| 40 | 41 |
| 41 DISALLOW_COPY_AND_ASSIGN(CallbackAnimationObserver); | 42 DISALLOW_COPY_AND_ASSIGN(CallbackAnimationObserver); |
| 42 }; | 43 }; |
| 43 | 44 |
| 44 } // namespace | 45 } // namespace |
| 45 | 46 |
| 46 SplitViewController::SplitViewController( | 47 SplitViewController::SplitViewController( |
| 47 aura::Window* container, | 48 aura::Window* container, |
| 48 WindowListProvider* window_list_provider, | 49 WindowListProvider* window_list_provider) |
| 49 WindowManager* window_manager) | |
| 50 : state_(INACTIVE), | 50 : state_(INACTIVE), |
| 51 container_(container), | 51 container_(container), |
| 52 window_manager_(window_manager), | |
| 53 window_list_provider_(window_list_provider), | 52 window_list_provider_(window_list_provider), |
| 54 current_activity_window_(NULL), | |
| 55 left_window_(NULL), | 53 left_window_(NULL), |
| 56 right_window_(NULL), | 54 right_window_(NULL), |
| 57 separator_position_(0), | 55 separator_position_(0), |
| 58 weak_factory_(this) { | 56 weak_factory_(this) { |
| 59 window_manager->AddObserver(this); | |
| 60 } | 57 } |
| 61 | 58 |
| 62 SplitViewController::~SplitViewController() { | 59 SplitViewController::~SplitViewController() { |
| 63 window_manager_->RemoveObserver(this); | |
| 64 } | 60 } |
| 65 | 61 |
| 66 bool SplitViewController::IsSplitViewModeActive() const { | 62 bool SplitViewController::IsSplitViewModeActive() const { |
| 67 return state_ == ACTIVE; | 63 return state_ == ACTIVE; |
| 68 } | 64 } |
| 69 | 65 |
| 70 void SplitViewController::ActivateSplitMode(aura::Window* left, | 66 void SplitViewController::ActivateSplitMode(aura::Window* left, |
| 71 aura::Window* right) { | 67 aura::Window* right) { |
| 72 aura::Window::Windows windows = window_list_provider_->GetWindowList(); | 68 aura::Window::Windows windows = window_list_provider_->GetWindowList(); |
| 73 aura::Window::Windows::reverse_iterator iter = windows.rbegin(); | 69 aura::Window::Windows::reverse_iterator iter = windows.rbegin(); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 void SplitViewController::UpdateSeparatorPositionFromScrollDelta(float delta) { | 182 void SplitViewController::UpdateSeparatorPositionFromScrollDelta(float delta) { |
| 187 gfx::Screen* screen = gfx::Screen::GetScreenFor(container_); | 183 gfx::Screen* screen = gfx::Screen::GetScreenFor(container_); |
| 188 const gfx::Rect& display_bounds = | 184 const gfx::Rect& display_bounds = |
| 189 screen->GetDisplayNearestWindow(container_).bounds(); | 185 screen->GetDisplayNearestWindow(container_).bounds(); |
| 190 gfx::Rect container_bounds = container_->GetBoundsInScreen(); | 186 gfx::Rect container_bounds = container_->GetBoundsInScreen(); |
| 191 separator_position_ = | 187 separator_position_ = |
| 192 delta > 0 ? ((int)delta) + display_bounds.x() - container_bounds.x() | 188 delta > 0 ? ((int)delta) + display_bounds.x() - container_bounds.x() |
| 193 : display_bounds.right() - container_bounds.x() + delta; | 189 : display_bounds.right() - container_bounds.x() + delta; |
| 194 } | 190 } |
| 195 | 191 |
| 196 aura::Window* SplitViewController::GetCurrentActivityWindow() { | 192 /////////////////////////////////////////////////////////////////////////////// |
| 197 if (!current_activity_window_) { | 193 // BezelController::ScrollDelegate: |
| 198 aura::Window::Windows windows = window_list_provider_->GetWindowList(); | |
| 199 if (windows.empty()) | |
| 200 return NULL; | |
| 201 current_activity_window_ = windows.back(); | |
| 202 } | |
| 203 return current_activity_window_; | |
| 204 } | |
| 205 | 194 |
| 206 /////////////////////////////////////////////////////////////////////////////// | |
| 207 // Begin BezelController::ScrollDelegate overrides. | |
| 208 void SplitViewController::ScrollBegin(BezelController::Bezel bezel, | 195 void SplitViewController::ScrollBegin(BezelController::Bezel bezel, |
| 209 float delta) { | 196 float delta) { |
| 210 if (!CanScroll()) | 197 if (!CanScroll()) |
| 211 return; | 198 return; |
| 212 state_ = SCROLLING; | 199 state_ = SCROLLING; |
| 213 aura::Window* current_window = GetCurrentActivityWindow(); | |
| 214 CHECK(current_window); | |
| 215 | 200 |
| 216 aura::Window::Windows windows = window_list_provider_->GetWindowList(); | 201 aura::Window::Windows windows = window_list_provider_->GetWindowList(); |
| 217 CHECK(windows.size() >= 2); | 202 CHECK(windows.size() >= 2); |
| 218 aura::Window::Windows::const_iterator it = | 203 aura::Window::Windows::const_reverse_iterator iter = windows.rbegin(); |
| 219 std::find(windows.begin(), windows.end(), current_window); | 204 aura::Window* current_window = *(iter); |
| 220 CHECK(it != windows.end()); | 205 CHECK(wm::IsActiveWindow(current_window)); |
| 221 | 206 |
| 222 if (delta > 0) { | 207 if (delta > 0) { |
| 223 right_window_ = current_window; | 208 right_window_ = current_window; |
| 224 // reverse iterator points to the position before normal iterator |it| | 209 left_window_ = *(iter + 1); |
| 225 aura::Window::Windows::const_reverse_iterator rev_it(it); | |
| 226 // circle to end if needed. | |
| 227 left_window_ = rev_it == windows.rend() ? windows.back() : *(rev_it); | |
| 228 } else { | 210 } else { |
| 229 left_window_ = current_window; | 211 left_window_ = current_window; |
| 230 ++it; | 212 right_window_ = *(iter + 1); |
| 231 // circle to front if needed. | |
| 232 right_window_ = it == windows.end() ? windows.front() : *it; | |
| 233 } | 213 } |
| 234 | 214 |
| 235 CHECK(left_window_); | 215 CHECK(left_window_); |
| 236 CHECK(right_window_); | 216 CHECK(right_window_); |
| 237 | 217 |
| 238 // TODO(oshima|mfomitchev): crbug.com/388362 | |
| 239 // Until we are properly hiding off-screen windows in window manager: | |
| 240 // Loop through all windows and hide them | |
| 241 for (it = windows.begin(); it != windows.end(); ++it) { | |
| 242 if (*it != left_window_ && *it != right_window_) | |
| 243 (*it)->Hide(); | |
| 244 } | |
| 245 | |
| 246 UpdateSeparatorPositionFromScrollDelta(delta); | 218 UpdateSeparatorPositionFromScrollDelta(delta); |
| 247 UpdateLayout(false); | 219 UpdateLayout(false); |
| 248 } | 220 } |
| 249 | 221 |
| 250 // Max distance from the scroll end position to the middle of the screen where | |
| 251 // we would go into the split view mode. | |
| 252 const int kMaxDistanceFromMiddle = 120; | |
| 253 void SplitViewController::ScrollEnd() { | 222 void SplitViewController::ScrollEnd() { |
| 254 if (state_ != SCROLLING) | 223 if (state_ != SCROLLING) |
| 255 return; | 224 return; |
| 256 | 225 |
| 226 // Max distance from the scroll end position to the middle of the screen where | |
| 227 // we would go into the split view mode. | |
| 228 const int kMaxDistanceFromMiddle = 120; | |
| 257 int container_width = container_->GetBoundsInScreen().width(); | 229 int container_width = container_->GetBoundsInScreen().width(); |
| 258 if (std::abs(container_width / 2 - separator_position_) <= | 230 if (std::abs(container_width / 2 - separator_position_) <= |
| 259 kMaxDistanceFromMiddle) { | 231 kMaxDistanceFromMiddle) { |
| 260 state_ = ACTIVE; | 232 state_ = ACTIVE; |
| 261 separator_position_ = container_width / 2; | 233 separator_position_ = container_width / 2; |
| 262 } else if (separator_position_ < container_width / 2) { | 234 } else if (separator_position_ < container_width / 2) { |
| 263 separator_position_ = 0; | 235 separator_position_ = 0; |
|
mfomitchev
2014/08/15 14:42:28
I think we need to call wm::ActiveWindow(right_win
sadrul
2014/08/15 16:07:12
Done.
| |
| 264 current_activity_window_ = right_window_; | |
| 265 state_ = INACTIVE; | 236 state_ = INACTIVE; |
| 266 } else { | 237 } else { |
| 267 separator_position_ = container_width; | 238 separator_position_ = container_width; |
|
mfomitchev
2014/08/15 14:42:28
Ditto for wm::ActiveWindow(left_window_)
sadrul
2014/08/15 16:07:12
Done.
| |
| 268 current_activity_window_ = left_window_; | |
| 269 state_ = INACTIVE; | 239 state_ = INACTIVE; |
| 270 } | 240 } |
| 271 UpdateLayout(true); | 241 UpdateLayout(true); |
| 272 } | 242 } |
| 273 | 243 |
| 274 void SplitViewController::ScrollUpdate(float delta) { | 244 void SplitViewController::ScrollUpdate(float delta) { |
| 275 if (state_ != SCROLLING) | 245 if (state_ != SCROLLING) |
| 276 return; | 246 return; |
| 277 UpdateSeparatorPositionFromScrollDelta(delta); | 247 UpdateSeparatorPositionFromScrollDelta(delta); |
| 278 UpdateLayout(false); | 248 UpdateLayout(false); |
| 279 } | 249 } |
| 280 | 250 |
| 281 bool SplitViewController::CanScroll() { | 251 bool SplitViewController::CanScroll() { |
| 282 // TODO(mfomitchev): return false in vertical orientation, in full screen. | 252 // TODO(mfomitchev): return false in vertical orientation, in full screen. |
| 283 bool result = (!window_manager_->IsOverviewModeActive() && | 253 bool result = (!IsSplitViewModeActive() && |
| 284 !IsSplitViewModeActive() && | |
| 285 window_list_provider_->GetWindowList().size() >= 2); | 254 window_list_provider_->GetWindowList().size() >= 2); |
| 286 return result; | 255 return result; |
| 287 } | 256 } |
| 288 | 257 |
| 289 /////////////////////////////////////////////////////////////////////////////// | |
| 290 // WindowManagerObserver overrides | |
| 291 void SplitViewController::OnOverviewModeEnter() { | |
| 292 if (state_ == ACTIVE) { | |
| 293 CHECK(left_window_); | |
| 294 CHECK(right_window_); | |
| 295 window_list_provider_->MoveToFront(right_window_); | |
| 296 window_list_provider_->MoveToFront(left_window_); | |
| 297 // TODO(mfomitchev): This shouldn't be done here, but the overview mode's | |
| 298 // transition animation currently looks bad if the starting transform of | |
| 299 // any window is not gfx::Transform(). | |
| 300 right_window_->SetTransform(gfx::Transform()); | |
| 301 } else if (current_activity_window_) { | |
| 302 window_list_provider_->MoveToFront(current_activity_window_); | |
| 303 } | |
| 304 state_ = INACTIVE; | |
|
mfomitchev
2014/08/15 14:42:28
Until split-overview is implemented, going to over
sadrul
2014/08/15 16:07:12
A good fix for this for now would be to explicitly
mfomitchev
2014/08/15 16:43:26
Sure. So what are you going to do now? Wait for os
| |
| 305 left_window_ = NULL; | |
| 306 right_window_ = NULL; | |
| 307 current_activity_window_ = NULL; | |
| 308 } | |
| 309 | |
| 310 void SplitViewController::OnOverviewModeExit() { | |
| 311 } | |
| 312 | |
| 313 } // namespace athena | 258 } // namespace athena |
| OLD | NEW |