| 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/screen/public/screen_manager.h" |
| 9 #include "athena/wm/public/window_list_provider.h" | 10 #include "athena/wm/public/window_list_provider.h" |
| 10 #include "athena/wm/public/window_manager.h" | 11 #include "athena/wm/public/window_manager.h" |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 13 #include "ui/compositor/closure_animation_observer.h" | 14 #include "ui/compositor/closure_animation_observer.h" |
| 14 #include "ui/compositor/layer_animation_observer.h" | 15 #include "ui/compositor/layer_animation_observer.h" |
| 15 #include "ui/compositor/scoped_layer_animation_settings.h" | 16 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 16 #include "ui/events/event_handler.h" | 17 #include "ui/events/event_handler.h" |
| 17 #include "ui/gfx/display.h" | 18 #include "ui/gfx/display.h" |
| 18 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
| 19 #include "ui/wm/core/window_util.h" | 20 #include "ui/wm/core/window_util.h" |
| 20 | 21 |
| 21 namespace athena { | 22 namespace athena { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 // Returns a target transform which is suitable for animating a windows's | 26 // Returns a target transform which is suitable for animating a windows's |
| 26 // bounds. | 27 // bounds. |
| 27 gfx::Transform GetTargetTransformForBoundsAnimation(const gfx::Rect& from, | 28 gfx::Transform GetTargetTransformForBoundsAnimation(const gfx::Rect& from, |
| 28 const gfx::Rect& to) { | 29 const gfx::Rect& to) { |
| 29 gfx::Transform transform; | 30 gfx::Transform transform; |
| 30 transform.Translate(to.x() - from.x(), to.y() - from.y()); | 31 transform.Translate(to.x() - from.x(), to.y() - from.y()); |
| 31 transform.Scale(to.width() / static_cast<float>(from.width()), | 32 transform.Scale(to.width() / static_cast<float>(from.width()), |
| 32 to.height() / static_cast<float>(from.height())); | 33 to.height() / static_cast<float>(from.height())); |
| 33 return transform; | 34 return transform; |
| 34 } | 35 } |
| 35 | 36 |
| 37 bool IsLandscapeOrientation(gfx::Display::Rotation rotation) { |
| 38 return rotation == gfx::Display::ROTATE_0 || |
| 39 rotation == gfx::Display::ROTATE_180; |
| 40 } |
| 41 |
| 36 } // namespace | 42 } // namespace |
| 37 | 43 |
| 38 SplitViewController::SplitViewController( | 44 SplitViewController::SplitViewController( |
| 39 aura::Window* container, | 45 aura::Window* container, |
| 40 WindowListProvider* window_list_provider) | 46 WindowListProvider* window_list_provider) |
| 41 : state_(INACTIVE), | 47 : state_(INACTIVE), |
| 42 container_(container), | 48 container_(container), |
| 43 window_list_provider_(window_list_provider), | 49 window_list_provider_(window_list_provider), |
| 44 left_window_(NULL), | 50 left_window_(NULL), |
| 45 right_window_(NULL), | 51 right_window_(NULL), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 87 |
| 82 if (!right && iter != windows.rend()) { | 88 if (!right && iter != windows.rend()) { |
| 83 right = *iter; | 89 right = *iter; |
| 84 iter++; | 90 iter++; |
| 85 if (right == left && iter != windows.rend()) { | 91 if (right == left && iter != windows.rend()) { |
| 86 right = *iter; | 92 right = *iter; |
| 87 iter++; | 93 iter++; |
| 88 } | 94 } |
| 89 } | 95 } |
| 90 | 96 |
| 91 state_ = ACTIVE; | 97 SetState(ACTIVE); |
| 92 if (right_window_ != right) { | 98 if (right_window_ != right) { |
| 93 right_window_ = right; | 99 right_window_ = right; |
| 94 container_->StackChildAtTop(right_window_); | 100 container_->StackChildAtTop(right_window_); |
| 95 } | 101 } |
| 96 if (left_window_ != left) { | 102 if (left_window_ != left) { |
| 97 left_window_ = left; | 103 left_window_ = left; |
| 98 container_->StackChildAtTop(left_window_); | 104 container_->StackChildAtTop(left_window_); |
| 99 } | 105 } |
| 100 UpdateLayout(true); | 106 UpdateLayout(true); |
| 101 } | 107 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 117 else | 123 else |
| 118 right_window_ = replace_with; | 124 right_window_ = replace_with; |
| 119 wm::ActivateWindow(replace_with); | 125 wm::ActivateWindow(replace_with); |
| 120 UpdateLayout(false); | 126 UpdateLayout(false); |
| 121 window->SetTransform(gfx::Transform()); | 127 window->SetTransform(gfx::Transform()); |
| 122 window->Hide(); | 128 window->Hide(); |
| 123 } | 129 } |
| 124 | 130 |
| 125 void SplitViewController::DeactivateSplitMode() { | 131 void SplitViewController::DeactivateSplitMode() { |
| 126 CHECK_EQ(ACTIVE, state_); | 132 CHECK_EQ(ACTIVE, state_); |
| 127 state_ = INACTIVE; | 133 SetState(INACTIVE); |
| 128 UpdateLayout(false); | 134 UpdateLayout(false); |
| 129 left_window_ = right_window_ = NULL; | 135 left_window_ = right_window_ = NULL; |
| 130 } | 136 } |
| 131 | 137 |
| 132 gfx::Rect SplitViewController::GetLeftTargetBounds() { | 138 gfx::Rect SplitViewController::GetLeftTargetBounds() { |
| 133 gfx::Rect work_area = | 139 gfx::Rect work_area = |
| 134 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area(); | 140 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area(); |
| 135 return gfx::Rect(0, 0, container_->bounds().width() / 2, work_area.height()); | 141 return gfx::Rect(0, 0, container_->bounds().width() / 2, work_area.height()); |
| 136 } | 142 } |
| 137 | 143 |
| 138 gfx::Rect SplitViewController::GetRightTargetBounds() { | 144 gfx::Rect SplitViewController::GetRightTargetBounds() { |
| 139 gfx::Rect work_area = | 145 gfx::Rect work_area = |
| 140 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area(); | 146 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area(); |
| 141 int container_width = container_->bounds().width(); | 147 int container_width = container_->bounds().width(); |
| 142 return gfx::Rect( | 148 return gfx::Rect( |
| 143 container_width / 2, 0, container_width / 2, work_area.height()); | 149 container_width / 2, 0, container_width / 2, work_area.height()); |
| 144 } | 150 } |
| 145 | 151 |
| 152 void SplitViewController::SetState(SplitViewController::State state) { |
| 153 if (state_ == state) |
| 154 return; |
| 155 |
| 156 state_ = state; |
| 157 ScreenManager::Get()->SetRotationLocked(state_ != INACTIVE); |
| 158 } |
| 159 |
| 146 void SplitViewController::UpdateLayout(bool animate) { | 160 void SplitViewController::UpdateLayout(bool animate) { |
| 147 CHECK(left_window_); | 161 CHECK(left_window_); |
| 148 CHECK(right_window_); | 162 CHECK(right_window_); |
| 149 | 163 |
| 164 // Splitview can be activated from SplitViewController::ActivateSplitMode or |
| 165 // SplitViewController::ScrollEnd. Additionally we don't want to rotate the |
| 166 // screen while engaging splitview (i.e. state_ == SCROLLING). |
| 150 if (state_ == INACTIVE && !animate) { | 167 if (state_ == INACTIVE && !animate) { |
| 151 if (!wm::IsActiveWindow(left_window_)) | 168 if (!wm::IsActiveWindow(left_window_)) |
| 152 left_window_->Hide(); | 169 left_window_->Hide(); |
| 153 if (!wm::IsActiveWindow(right_window_)) | 170 if (!wm::IsActiveWindow(right_window_)) |
| 154 right_window_->Hide(); | 171 right_window_->Hide(); |
| 155 SetWindowTransforms(gfx::Transform(), gfx::Transform(), false); | 172 SetWindowTransforms(gfx::Transform(), gfx::Transform(), false); |
| 156 return; | 173 return; |
| 157 } | 174 } |
| 158 | 175 |
| 159 left_window_->Show(); | 176 left_window_->Show(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 : display_bounds.right() - container_bounds.x() + delta; | 248 : display_bounds.right() - container_bounds.x() + delta; |
| 232 } | 249 } |
| 233 | 250 |
| 234 /////////////////////////////////////////////////////////////////////////////// | 251 /////////////////////////////////////////////////////////////////////////////// |
| 235 // BezelController::ScrollDelegate: | 252 // BezelController::ScrollDelegate: |
| 236 | 253 |
| 237 void SplitViewController::ScrollBegin(BezelController::Bezel bezel, | 254 void SplitViewController::ScrollBegin(BezelController::Bezel bezel, |
| 238 float delta) { | 255 float delta) { |
| 239 if (!CanScroll()) | 256 if (!CanScroll()) |
| 240 return; | 257 return; |
| 241 state_ = SCROLLING; | 258 SetState(SCROLLING); |
| 242 | 259 |
| 243 aura::Window::Windows windows = window_list_provider_->GetWindowList(); | 260 aura::Window::Windows windows = window_list_provider_->GetWindowList(); |
| 244 CHECK(windows.size() >= 2); | 261 CHECK(windows.size() >= 2); |
| 245 aura::Window::Windows::const_reverse_iterator iter = windows.rbegin(); | 262 aura::Window::Windows::const_reverse_iterator iter = windows.rbegin(); |
| 246 aura::Window* current_window = *(iter); | 263 aura::Window* current_window = *(iter); |
| 247 CHECK(wm::IsActiveWindow(current_window)); | 264 CHECK(wm::IsActiveWindow(current_window)); |
| 248 | 265 |
| 249 if (delta > 0) { | 266 if (delta > 0) { |
| 250 right_window_ = current_window; | 267 right_window_ = current_window; |
| 251 left_window_ = *(iter + 1); | 268 left_window_ = *(iter + 1); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 264 void SplitViewController::ScrollEnd() { | 281 void SplitViewController::ScrollEnd() { |
| 265 if (state_ != SCROLLING) | 282 if (state_ != SCROLLING) |
| 266 return; | 283 return; |
| 267 | 284 |
| 268 // Max distance from the scroll end position to the middle of the screen where | 285 // Max distance from the scroll end position to the middle of the screen where |
| 269 // we would go into the split view mode. | 286 // we would go into the split view mode. |
| 270 const int kMaxDistanceFromMiddle = 120; | 287 const int kMaxDistanceFromMiddle = 120; |
| 271 int container_width = container_->GetBoundsInScreen().width(); | 288 int container_width = container_->GetBoundsInScreen().width(); |
| 272 if (std::abs(container_width / 2 - separator_position_) <= | 289 if (std::abs(container_width / 2 - separator_position_) <= |
| 273 kMaxDistanceFromMiddle) { | 290 kMaxDistanceFromMiddle) { |
| 274 state_ = ACTIVE; | 291 SetState(ACTIVE); |
| 275 separator_position_ = container_width / 2; | 292 separator_position_ = container_width / 2; |
| 276 } else if (separator_position_ < container_width / 2) { | 293 } else if (separator_position_ < container_width / 2) { |
| 277 separator_position_ = 0; | 294 separator_position_ = 0; |
| 278 state_ = INACTIVE; | 295 SetState(INACTIVE); |
| 279 wm::ActivateWindow(right_window_); | 296 wm::ActivateWindow(right_window_); |
| 280 } else { | 297 } else { |
| 281 separator_position_ = container_width; | 298 separator_position_ = container_width; |
| 282 state_ = INACTIVE; | 299 SetState(INACTIVE); |
| 283 wm::ActivateWindow(left_window_); | 300 wm::ActivateWindow(left_window_); |
| 284 } | 301 } |
| 285 UpdateLayout(true); | 302 UpdateLayout(true); |
| 286 } | 303 } |
| 287 | 304 |
| 288 void SplitViewController::ScrollUpdate(float delta) { | 305 void SplitViewController::ScrollUpdate(float delta) { |
| 289 if (state_ != SCROLLING) | 306 if (state_ != SCROLLING) |
| 290 return; | 307 return; |
| 291 UpdateSeparatorPositionFromScrollDelta(delta); | 308 UpdateSeparatorPositionFromScrollDelta(delta); |
| 292 UpdateLayout(false); | 309 UpdateLayout(false); |
| 293 } | 310 } |
| 294 | 311 |
| 295 bool SplitViewController::CanScroll() { | 312 bool SplitViewController::CanScroll() { |
| 296 // TODO(mfomitchev): return false in vertical orientation, in full screen. | 313 // TODO(mfomitchev): return false in full screen. |
| 297 bool result = (!IsSplitViewModeActive() && | 314 bool result = (!IsSplitViewModeActive() && |
| 298 window_list_provider_->GetWindowList().size() >= 2); | 315 window_list_provider_->GetWindowList().size() >= 2 && |
| 316 IsLandscapeOrientation(gfx::Screen::GetNativeScreen()-> |
| 317 GetDisplayNearestWindow(container_).rotation())); |
| 299 return result; | 318 return result; |
| 300 } | 319 } |
| 301 | 320 |
| 302 } // namespace athena | 321 } // namespace athena |
| OLD | NEW |