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/screen/public/screen_manager.h" | 9 #include "athena/screen/public/screen_manager.h" |
| 10 #include "athena/wm/public/window_list_provider.h" | 10 #include "athena/wm/public/window_list_provider.h" |
| 11 #include "athena/wm/public/window_manager.h" | 11 #include "athena/wm/public/window_manager.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 14 #include "ui/compositor/closure_animation_observer.h" | 14 #include "ui/compositor/closure_animation_observer.h" |
| 15 #include "ui/compositor/layer_animation_observer.h" | 15 #include "ui/compositor/layer_animation_observer.h" |
| 16 #include "ui/compositor/scoped_layer_animation_settings.h" | 16 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 17 #include "ui/events/event_handler.h" | 17 #include "ui/events/event_handler.h" |
| 18 #include "ui/gfx/display.h" | 18 #include "ui/gfx/display.h" |
| 19 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
| 20 #include "ui/wm/core/window_util.h" | 20 #include "ui/wm/core/window_util.h" |
| 21 #include "ui/wm/public/activation_client.h" | |
| 21 | 22 |
| 22 namespace athena { | 23 namespace athena { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 // Returns a target transform which is suitable for animating a windows's | 27 // Returns a target transform which is suitable for animating a windows's |
| 27 // bounds. | 28 // bounds. |
| 28 gfx::Transform GetTargetTransformForBoundsAnimation(const gfx::Rect& from, | 29 gfx::Transform GetTargetTransformForBoundsAnimation(const gfx::Rect& from, |
| 29 const gfx::Rect& to) { | 30 const gfx::Rect& to) { |
| 30 gfx::Transform transform; | 31 gfx::Transform transform; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 window_list_provider_->GetWindowList().size() >= 2 && | 63 window_list_provider_->GetWindowList().size() >= 2 && |
| 63 IsLandscapeOrientation(gfx::Screen::GetNativeScreen()-> | 64 IsLandscapeOrientation(gfx::Screen::GetNativeScreen()-> |
| 64 GetDisplayNearestWindow(container_).rotation())); | 65 GetDisplayNearestWindow(container_).rotation())); |
| 65 } | 66 } |
| 66 | 67 |
| 67 bool SplitViewController::IsSplitViewModeActive() const { | 68 bool SplitViewController::IsSplitViewModeActive() const { |
| 68 return state_ == ACTIVE; | 69 return state_ == ACTIVE; |
| 69 } | 70 } |
| 70 | 71 |
| 71 void SplitViewController::ActivateSplitMode(aura::Window* left, | 72 void SplitViewController::ActivateSplitMode(aura::Window* left, |
| 72 aura::Window* right) { | 73 aura::Window* right, |
| 74 aura::Window* to_activate) { | |
| 73 const aura::Window::Windows& windows = window_list_provider_->GetWindowList(); | 75 const aura::Window::Windows& windows = window_list_provider_->GetWindowList(); |
| 74 aura::Window::Windows::const_reverse_iterator iter = windows.rbegin(); | 76 aura::Window::Windows::const_reverse_iterator iter = windows.rbegin(); |
| 75 if (state_ == ACTIVE) { | 77 if (state_ == ACTIVE) { |
| 76 if (!left && left_window_ != right) | 78 if (!left && left_window_ != right) |
| 77 left = left_window_; | 79 left = left_window_; |
| 78 if (!right && right_window_ != left) | 80 if (!right && right_window_ != left) |
| 79 right = right_window_; | 81 right = right_window_; |
| 80 } | 82 } |
| 81 | 83 |
| 82 if (!left && iter != windows.rend()) { | 84 if (!left && iter != windows.rend()) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 96 iter++; | 98 iter++; |
| 97 } | 99 } |
| 98 } | 100 } |
| 99 | 101 |
| 100 to_hide_.clear(); | 102 to_hide_.clear(); |
| 101 if (left_window_ && left_window_ != left && left_window_ != right) | 103 if (left_window_ && left_window_ != left && left_window_ != right) |
| 102 to_hide_.push_back(left_window_); | 104 to_hide_.push_back(left_window_); |
| 103 if (right_window_ && right_window_ != left && right_window_ != right) | 105 if (right_window_ && right_window_ != left && right_window_ != right) |
| 104 to_hide_.push_back(right_window_); | 106 to_hide_.push_back(right_window_); |
| 105 | 107 |
| 108 left_window_ = left; | |
| 109 right_window_ = right; | |
| 110 | |
| 106 SetState(ACTIVE); | 111 SetState(ACTIVE); |
| 107 right_window_ = right; | |
| 108 left_window_ = left; | |
| 109 UpdateLayout(true); | 112 UpdateLayout(true); |
| 113 | |
| 114 if (to_activate) | |
| 115 wm::ActivateWindow(to_activate); | |
|
sadrul
2014/09/23 16:18:32
Add a CHECK here that to_activate is one of left o
pkotwicz
2014/09/24 14:59:23
I have changed things around to make them clearer.
| |
| 116 | |
| 117 aura::client::ActivationClient* activation_client = | |
| 118 aura::client::GetActivationClient(container_->GetRootWindow()); | |
| 119 aura::Window* active_window = activation_client->GetActiveWindow(); | |
| 120 | |
| 121 if (active_window == left_window_) { | |
| 122 window_list_provider_->StackWindowBehindTo(right_window_, left_window_); | |
| 123 } else { | |
| 124 CHECK_EQ(active_window, right_window_); | |
| 125 window_list_provider_->StackWindowBehindTo(left_window_, right_window_); | |
| 126 } | |
| 110 } | 127 } |
| 111 | 128 |
| 112 void SplitViewController::ReplaceWindow(aura::Window* window, | 129 void SplitViewController::ReplaceWindow(aura::Window* window, |
| 113 aura::Window* replace_with) { | 130 aura::Window* replace_with) { |
| 114 CHECK(IsSplitViewModeActive()); | 131 CHECK(IsSplitViewModeActive()); |
| 115 CHECK(replace_with); | 132 CHECK(replace_with); |
| 116 CHECK(window == left_window_ || window == right_window_); | 133 CHECK(window == left_window_ || window == right_window_); |
| 117 CHECK(replace_with != left_window_ && replace_with != right_window_); | 134 CHECK(replace_with != left_window_ && replace_with != right_window_); |
| 118 DCHECK(window_list_provider_->IsWindowInList(replace_with)); | 135 DCHECK(window_list_provider_->IsWindowInList(replace_with)); |
| 119 | 136 |
| 120 if (window == left_window_) | 137 aura::Window* not_replaced = NULL; |
| 138 if (window == left_window_) { | |
| 121 left_window_ = replace_with; | 139 left_window_ = replace_with; |
| 122 else | 140 not_replaced = right_window_; |
| 141 } else { | |
| 123 right_window_ = replace_with; | 142 right_window_ = replace_with; |
| 143 not_replaced = left_window_; | |
| 144 } | |
| 145 UpdateLayout(false); | |
| 146 | |
| 124 wm::ActivateWindow(replace_with); | 147 wm::ActivateWindow(replace_with); |
| 125 UpdateLayout(false); | 148 window_list_provider_->StackWindowBehindTo(not_replaced, replace_with); |
| 149 | |
| 126 window->SetTransform(gfx::Transform()); | 150 window->SetTransform(gfx::Transform()); |
| 127 window->Hide(); | 151 window->Hide(); |
| 128 } | 152 } |
| 129 | 153 |
| 130 void SplitViewController::DeactivateSplitMode() { | 154 void SplitViewController::DeactivateSplitMode() { |
| 131 CHECK_EQ(ACTIVE, state_); | 155 CHECK_EQ(ACTIVE, state_); |
| 132 SetState(INACTIVE); | 156 SetState(INACTIVE); |
| 133 UpdateLayout(false); | 157 UpdateLayout(false); |
| 134 left_window_ = right_window_ = NULL; | 158 left_window_ = right_window_ = NULL; |
| 135 } | 159 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 if (!wm::IsActiveWindow(left_window_)) | 191 if (!wm::IsActiveWindow(left_window_)) |
| 168 left_window_->Hide(); | 192 left_window_->Hide(); |
| 169 if (!wm::IsActiveWindow(right_window_)) | 193 if (!wm::IsActiveWindow(right_window_)) |
| 170 right_window_->Hide(); | 194 right_window_->Hide(); |
| 171 SetWindowTransforms(gfx::Transform(), gfx::Transform(), false); | 195 SetWindowTransforms(gfx::Transform(), gfx::Transform(), false); |
| 172 return; | 196 return; |
| 173 } | 197 } |
| 174 | 198 |
| 175 left_window_->Show(); | 199 left_window_->Show(); |
| 176 right_window_->Show(); | 200 right_window_->Show(); |
| 177 window_list_provider_->MoveToFront(right_window_); | |
| 178 window_list_provider_->MoveToFront(left_window_); | |
| 179 | 201 |
| 180 if (state_ == ACTIVE) { | 202 if (state_ == ACTIVE) { |
| 181 if (animate) { | 203 if (animate) { |
| 182 gfx::Transform left_transform = GetTargetTransformForBoundsAnimation( | 204 gfx::Transform left_transform = GetTargetTransformForBoundsAnimation( |
| 183 left_window_->bounds(), GetLeftTargetBounds()); | 205 left_window_->bounds(), GetLeftTargetBounds()); |
| 184 gfx::Transform right_transform = GetTargetTransformForBoundsAnimation( | 206 gfx::Transform right_transform = GetTargetTransformForBoundsAnimation( |
| 185 right_window_->bounds(), GetRightTargetBounds()); | 207 right_window_->bounds(), GetRightTargetBounds()); |
| 186 SetWindowTransforms(left_transform, right_transform, true); | 208 SetWindowTransforms(left_transform, right_transform, true); |
| 187 } else { | 209 } else { |
| 188 left_window_->SetBounds(GetLeftTargetBounds()); | 210 left_window_->SetBounds(GetLeftTargetBounds()); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 return; | 335 return; |
| 314 UpdateSeparatorPositionFromScrollDelta(delta); | 336 UpdateSeparatorPositionFromScrollDelta(delta); |
| 315 UpdateLayout(false); | 337 UpdateLayout(false); |
| 316 } | 338 } |
| 317 | 339 |
| 318 bool SplitViewController::CanScroll() { | 340 bool SplitViewController::CanScroll() { |
| 319 return CanActivateSplitViewMode(); | 341 return CanActivateSplitViewMode(); |
| 320 } | 342 } |
| 321 | 343 |
| 322 } // namespace athena | 344 } // namespace athena |
| OLD | NEW |