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/scoped_window_targeter.h" | 13 #include "ui/aura/scoped_window_targeter.h" |
| 14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 15 #include "ui/aura/window_targeter.h" | 15 #include "ui/aura/window_targeter.h" |
| 16 #include "ui/compositor/closure_animation_observer.h" | 16 #include "ui/compositor/closure_animation_observer.h" |
| 17 #include "ui/compositor/layer.h" | 17 #include "ui/compositor/layer.h" |
| 18 #include "ui/compositor/scoped_layer_animation_settings.h" | 18 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 19 #include "ui/events/event_handler.h" | 19 #include "ui/events/event_handler.h" |
| 20 #include "ui/gfx/display.h" | 20 #include "ui/gfx/display.h" |
| 21 #include "ui/gfx/screen.h" | 21 #include "ui/gfx/screen.h" |
| 22 #include "ui/views/background.h" | 22 #include "ui/views/background.h" |
| 23 #include "ui/views/layout/box_layout.h" | 23 #include "ui/views/layout/box_layout.h" |
| 24 #include "ui/views/widget/root_view.h" | 24 #include "ui/views/widget/root_view.h" |
| 25 #include "ui/views/widget/root_view_targeter.h" | 25 #include "ui/views/widget/root_view_targeter.h" |
| 26 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
| 27 #include "ui/wm/core/window_util.h" | 27 #include "ui/wm/core/window_util.h" |
| 28 #include "ui/wm/public/activation_client.h" | |
| 28 | 29 |
| 29 namespace athena { | 30 namespace athena { |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 const int kDragHandleWidth = 4; | 34 const int kDragHandleWidth = 4; |
| 34 const int kDragHandleHeight = 80; | 35 const int kDragHandleHeight = 80; |
| 35 const int kDragHandleMargin = 1; | 36 const int kDragHandleMargin = 1; |
| 36 const int kDividerWidth = kDragHandleWidth + 2 * kDragHandleMargin; | 37 const int kDividerWidth = kDragHandleWidth + 2 * kDragHandleMargin; |
| 37 | 38 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 window_list_provider_->GetWindowList().size() >= 2 && | 171 window_list_provider_->GetWindowList().size() >= 2 && |
| 171 IsLandscapeOrientation(gfx::Screen::GetNativeScreen()-> | 172 IsLandscapeOrientation(gfx::Screen::GetNativeScreen()-> |
| 172 GetDisplayNearestWindow(container_).rotation())); | 173 GetDisplayNearestWindow(container_).rotation())); |
| 173 } | 174 } |
| 174 | 175 |
| 175 bool SplitViewController::IsSplitViewModeActive() const { | 176 bool SplitViewController::IsSplitViewModeActive() const { |
| 176 return state_ == ACTIVE; | 177 return state_ == ACTIVE; |
| 177 } | 178 } |
| 178 | 179 |
| 179 void SplitViewController::ActivateSplitMode(aura::Window* left, | 180 void SplitViewController::ActivateSplitMode(aura::Window* left, |
| 180 aura::Window* right) { | 181 aura::Window* right, |
| 182 aura::Window* to_activate) { | |
| 181 const aura::Window::Windows& windows = window_list_provider_->GetWindowList(); | 183 const aura::Window::Windows& windows = window_list_provider_->GetWindowList(); |
| 182 aura::Window::Windows::const_reverse_iterator iter = windows.rbegin(); | 184 aura::Window::Windows::const_reverse_iterator iter = windows.rbegin(); |
| 183 if (state_ == ACTIVE) { | 185 if (state_ == ACTIVE) { |
| 184 if (!left && left_window_ != right) | 186 if (!left && left_window_ != right) |
| 185 left = left_window_; | 187 left = left_window_; |
| 186 if (!right && right_window_ != left) | 188 if (!right && right_window_ != left) |
| 187 right = right_window_; | 189 right = right_window_; |
| 188 } | 190 } |
| 189 | 191 |
| 190 if (!left && iter != windows.rend()) { | 192 if (!left && iter != windows.rend()) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 204 iter++; | 206 iter++; |
| 205 } | 207 } |
| 206 } | 208 } |
| 207 | 209 |
| 208 to_hide_.clear(); | 210 to_hide_.clear(); |
| 209 if (left_window_ && left_window_ != left && left_window_ != right) | 211 if (left_window_ && left_window_ != left && left_window_ != right) |
| 210 to_hide_.push_back(left_window_); | 212 to_hide_.push_back(left_window_); |
| 211 if (right_window_ && right_window_ != left && right_window_ != right) | 213 if (right_window_ && right_window_ != left && right_window_ != right) |
| 212 to_hide_.push_back(right_window_); | 214 to_hide_.push_back(right_window_); |
| 213 | 215 |
| 216 left_window_ = left; | |
| 217 right_window_ = right; | |
| 218 | |
| 214 divider_position_ = GetDefaultDividerPosition(); | 219 divider_position_ = GetDefaultDividerPosition(); |
| 215 SetState(ACTIVE); | 220 SetState(ACTIVE); |
| 216 right_window_ = right; | |
| 217 left_window_ = left; | |
| 218 UpdateLayout(true); | 221 UpdateLayout(true); |
| 222 | |
| 223 aura::client::ActivationClient* activation_client = | |
| 224 aura::client::GetActivationClient(container_->GetRootWindow()); | |
| 225 aura::Window* active_window = activation_client->GetActiveWindow(); | |
| 226 if (to_activate) { | |
| 227 CHECK(to_activate == left_window_ || to_activate == right_window_); | |
| 228 wm::ActivateWindow(to_activate); | |
| 229 } else if (active_window != left_window_ && | |
| 230 active_window != right_window_) { | |
|
oshima
2014/09/24 19:42:32
can you document when this can happen?
pkotwicz
2014/09/24 21:05:12
I've made this happen by pressing Ctrl+F6 while to
| |
| 231 wm::ActivateWindow(left_window_); | |
| 232 } | |
| 233 active_window = activation_client->GetActiveWindow(); | |
| 234 | |
| 235 if (active_window == left_window_) | |
| 236 window_list_provider_->StackWindowBehindTo(right_window_, left_window_); | |
| 237 else | |
| 238 window_list_provider_->StackWindowBehindTo(left_window_, right_window_); | |
| 219 } | 239 } |
| 220 | 240 |
| 221 void SplitViewController::ReplaceWindow(aura::Window* window, | 241 void SplitViewController::ReplaceWindow(aura::Window* window, |
| 222 aura::Window* replace_with) { | 242 aura::Window* replace_with) { |
| 223 CHECK(IsSplitViewModeActive()); | 243 CHECK(IsSplitViewModeActive()); |
| 224 CHECK(replace_with); | 244 CHECK(replace_with); |
| 225 CHECK(window == left_window_ || window == right_window_); | 245 CHECK(window == left_window_ || window == right_window_); |
| 226 CHECK(replace_with != left_window_ && replace_with != right_window_); | 246 CHECK(replace_with != left_window_ && replace_with != right_window_); |
| 227 DCHECK(window_list_provider_->IsWindowInList(replace_with)); | 247 DCHECK(window_list_provider_->IsWindowInList(replace_with)); |
| 228 | 248 |
| 229 if (window == left_window_) | 249 aura::Window* not_replaced = NULL; |
| 250 if (window == left_window_) { | |
| 230 left_window_ = replace_with; | 251 left_window_ = replace_with; |
| 231 else | 252 not_replaced = right_window_; |
| 253 } else { | |
| 232 right_window_ = replace_with; | 254 right_window_ = replace_with; |
| 255 not_replaced = left_window_; | |
| 256 } | |
| 257 UpdateLayout(false); | |
| 258 | |
| 233 wm::ActivateWindow(replace_with); | 259 wm::ActivateWindow(replace_with); |
| 234 UpdateLayout(false); | 260 window_list_provider_->StackWindowBehindTo(not_replaced, replace_with); |
| 261 | |
| 235 window->SetTransform(gfx::Transform()); | 262 window->SetTransform(gfx::Transform()); |
| 236 window->Hide(); | 263 window->Hide(); |
| 237 } | 264 } |
| 238 | 265 |
| 239 void SplitViewController::DeactivateSplitMode() { | 266 void SplitViewController::DeactivateSplitMode() { |
| 240 CHECK_EQ(ACTIVE, state_); | 267 CHECK_EQ(ACTIVE, state_); |
| 241 SetState(INACTIVE); | 268 SetState(INACTIVE); |
| 242 UpdateLayout(false); | 269 UpdateLayout(false); |
| 243 left_window_ = right_window_ = NULL; | 270 left_window_ = right_window_ = NULL; |
| 244 } | 271 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 // TODO(mfomitchev): Use to_hide_ instead | 387 // TODO(mfomitchev): Use to_hide_ instead |
| 361 right_window_->Hide(); | 388 right_window_->Hide(); |
| 362 } | 389 } |
| 363 SetWindowTransforms( | 390 SetWindowTransforms( |
| 364 gfx::Transform(), gfx::Transform(), gfx::Transform(), false); | 391 gfx::Transform(), gfx::Transform(), gfx::Transform(), false); |
| 365 return; | 392 return; |
| 366 } | 393 } |
| 367 | 394 |
| 368 left_window_->Show(); | 395 left_window_->Show(); |
| 369 right_window_->Show(); | 396 right_window_->Show(); |
| 370 window_list_provider_->MoveToFront(right_window_); | |
| 371 window_list_provider_->MoveToFront(left_window_); | |
| 372 | 397 |
| 373 gfx::Transform divider_transform; | 398 gfx::Transform divider_transform; |
| 374 divider_transform.Translate(divider_position_, 0); | 399 divider_transform.Translate(divider_position_, 0); |
| 375 if (state_ == ACTIVE) { | 400 if (state_ == ACTIVE) { |
| 376 if (animate) { | 401 if (animate) { |
| 377 gfx::Transform left_transform = | 402 gfx::Transform left_transform = |
| 378 GetTransformForBounds(left_window_->bounds(), GetLeftAreaBounds()); | 403 GetTransformForBounds(left_window_->bounds(), GetLeftAreaBounds()); |
| 379 gfx::Transform right_transform = | 404 gfx::Transform right_transform = |
| 380 GetTransformForBounds(right_window_->bounds(), GetRightAreaBounds()); | 405 GetTransformForBounds(right_window_->bounds(), GetRightAreaBounds()); |
| 381 SetWindowTransforms( | 406 SetWindowTransforms( |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 576 ShowDivider(); | 601 ShowDivider(); |
| 577 } | 602 } |
| 578 | 603 |
| 579 void SplitViewController::OnSplitViewModeEnter() { | 604 void SplitViewController::OnSplitViewModeEnter() { |
| 580 } | 605 } |
| 581 | 606 |
| 582 void SplitViewController::OnSplitViewModeExit() { | 607 void SplitViewController::OnSplitViewModeExit() { |
| 583 } | 608 } |
| 584 | 609 |
| 585 } // namespace athena | 610 } // namespace athena |
| OLD | NEW |