| 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/window_overview_mode.h" | 5 #include "athena/wm/window_overview_mode.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 state->top.Translate(x_translate, window->bounds().height() * 0.65); | 182 state->top.Translate(x_translate, window->bounds().height() * 0.65); |
| 183 state->top.Scale(kMaxScale, kMaxScale); | 183 state->top.Scale(kMaxScale, kMaxScale); |
| 184 state->bottom = state->top; | 184 state->bottom = state->top; |
| 185 --index; | 185 --index; |
| 186 continue; | 186 continue; |
| 187 } | 187 } |
| 188 UpdateTerminalStateForWindowAtIndex(window, index, windows.size()); | 188 UpdateTerminalStateForWindowAtIndex(window, index, windows.size()); |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 | 191 |
| 192 // Computes the terminal states (i.e. the transforms for the top-most and |
| 193 // bottom-most position in the stack) for |window|. |window_count| is the |
| 194 // number of windows in the stack, and |index| is the position of the window |
| 195 // in the stack (0 being the front-most window). |
| 192 void UpdateTerminalStateForWindowAtIndex(aura::Window* window, | 196 void UpdateTerminalStateForWindowAtIndex(aura::Window* window, |
| 193 size_t index, | 197 size_t index, |
| 194 size_t window_count) { | 198 size_t window_count) { |
| 195 const int kGapBetweenWindowsBottom = 10; | 199 const int kGapBetweenWindowsBottom = 10; |
| 196 const int kGapBetweenWindowsTop = 5; | 200 const int kGapBetweenWindowsTop = 5; |
| 197 | 201 |
| 198 const int container_width = container_->bounds().width(); | 202 const int container_width = container_->bounds().width(); |
| 199 const int window_width = window->bounds().width(); | 203 const int window_width = window->bounds().width(); |
| 200 const int window_x = window->bounds().x(); | 204 const int window_x = window->bounds().x(); |
| 201 gfx::Transform top_transform; | 205 gfx::Transform top_transform; |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 const bool dragging_towards_right = dragged_distance.x() < 0; | 415 const bool dragging_towards_right = dragged_distance.x() < 0; |
| 412 const bool swipe_towards_right = event.details().velocity_x() > 0; | 416 const bool swipe_towards_right = event.details().velocity_x() > 0; |
| 413 if (dragging_towards_right != swipe_towards_right) | 417 if (dragging_towards_right != swipe_towards_right) |
| 414 return false; | 418 return false; |
| 415 const float kMinVelocityForDismissal = 500.f; | 419 const float kMinVelocityForDismissal = 500.f; |
| 416 return std::abs(event.details().velocity_x()) > kMinVelocityForDismissal; | 420 return std::abs(event.details().velocity_x()) > kMinVelocityForDismissal; |
| 417 } | 421 } |
| 418 | 422 |
| 419 void CloseDragWindow(const ui::GestureEvent& gesture) { | 423 void CloseDragWindow(const ui::GestureEvent& gesture) { |
| 420 // Animate |dragged_window_| offscreen first, then destroy it. | 424 // Animate |dragged_window_| offscreen first, then destroy it. |
| 421 ui::ScopedLayerAnimationSettings settings( | 425 { |
| 422 dragged_window_->layer()->GetAnimator()); | 426 ui::ScopedLayerAnimationSettings settings( |
| 423 settings.SetPreemptionStrategy( | 427 dragged_window_->layer()->GetAnimator()); |
| 424 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
| 425 settings.AddObserver(new ui::ClosureAnimationObserver( | |
| 426 base::Bind(&base::DeletePointer<aura::Window>, dragged_window_))); | |
| 427 | |
| 428 WindowOverviewState* dragged_state = | |
| 429 dragged_window_->GetProperty(kWindowOverviewState); | |
| 430 CHECK(dragged_state); | |
| 431 gfx::Transform transform = dragged_window_->layer()->transform(); | |
| 432 gfx::RectF transformed_bounds = dragged_window_->bounds(); | |
| 433 transform.TransformRect(&transformed_bounds); | |
| 434 float transform_x = 0.f; | |
| 435 if (gesture.location().x() > dragged_start_location_.x()) | |
| 436 transform_x = container_->bounds().right() - transformed_bounds.x(); | |
| 437 else | |
| 438 transform_x = -(transformed_bounds.x() + transformed_bounds.width()); | |
| 439 float scale = gfx::Tween::FloatValueBetween( | |
| 440 dragged_state->progress, kMinScale, kMaxScale); | |
| 441 transform.Translate(transform_x / scale, 0); | |
| 442 dragged_window_->SetTransform(transform); | |
| 443 dragged_window_->layer()->SetOpacity(kMinOpacity); | |
| 444 | |
| 445 // Move the windows behind |dragged_window_| in the stack forward one step. | |
| 446 const aura::Window::Windows& list = container_->children(); | |
| 447 for (aura::Window::Windows::const_iterator iter = list.begin(); | |
| 448 iter != list.end() && *iter != dragged_window_; | |
| 449 ++iter) { | |
| 450 aura::Window* window = *iter; | |
| 451 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | |
| 452 settings.SetPreemptionStrategy( | 428 settings.SetPreemptionStrategy( |
| 453 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 429 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 430 settings.AddObserver(new ui::ClosureAnimationObserver( |
| 431 base::Bind(&base::DeletePointer<aura::Window>, dragged_window_))); |
| 454 | 432 |
| 455 aura::Window* next = *(iter + 1); | 433 WindowOverviewState* dragged_state = |
| 456 WindowOverviewState* next_state = next->GetProperty(kWindowOverviewState); | 434 dragged_window_->GetProperty(kWindowOverviewState); |
| 457 UpdateTerminalStateForWindowAtIndex(window, list.end() - iter, | 435 CHECK(dragged_state); |
| 458 list.size()); | 436 gfx::Transform transform = dragged_window_->layer()->transform(); |
| 459 SetWindowProgress(window, next_state->progress); | 437 gfx::RectF transformed_bounds = dragged_window_->bounds(); |
| 438 transform.TransformRect(&transformed_bounds); |
| 439 float transform_x = 0.f; |
| 440 if (gesture.location().x() > dragged_start_location_.x()) |
| 441 transform_x = container_->bounds().right() - transformed_bounds.x(); |
| 442 else |
| 443 transform_x = -(transformed_bounds.x() + transformed_bounds.width()); |
| 444 float scale = gfx::Tween::FloatValueBetween( |
| 445 dragged_state->progress, kMinScale, kMaxScale); |
| 446 transform.Translate(transform_x / scale, 0); |
| 447 dragged_window_->SetTransform(transform); |
| 448 dragged_window_->layer()->SetOpacity(kMinOpacity); |
| 449 } |
| 450 |
| 451 const aura::Window::Windows list = window_list_provider_->GetWindowList(); |
| 452 CHECK(!list.empty()); |
| 453 if (list.front() == dragged_window_) { |
| 454 // There's no window behind |dragged_window_|. So move the windows in |
| 455 // front take a step back. |
| 456 for (aura::Window::Windows::const_reverse_iterator iter = list.rbegin(); |
| 457 iter != list.rend() && *iter != dragged_window_; |
| 458 ++iter) { |
| 459 aura::Window* window = *iter; |
| 460 ui::ScopedLayerAnimationSettings settings( |
| 461 window->layer()->GetAnimator()); |
| 462 settings.SetPreemptionStrategy( |
| 463 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 464 |
| 465 aura::Window* next = *(iter + 1); |
| 466 WindowOverviewState* next_state = |
| 467 next->GetProperty(kWindowOverviewState); |
| 468 UpdateTerminalStateForWindowAtIndex( |
| 469 window, iter - list.rbegin(), list.size()); |
| 470 SetWindowProgress(window, next_state->progress); |
| 471 } |
| 472 } else { |
| 473 // Move the windows behind |dragged_window_| in the stack forward one |
| 474 // step. |
| 475 for (aura::Window::Windows::const_iterator iter = list.begin(); |
| 476 iter != list.end() && *iter != dragged_window_; |
| 477 ++iter) { |
| 478 aura::Window* window = *iter; |
| 479 ui::ScopedLayerAnimationSettings settings( |
| 480 window->layer()->GetAnimator()); |
| 481 settings.SetPreemptionStrategy( |
| 482 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 483 |
| 484 aura::Window* next = *(iter + 1); |
| 485 WindowOverviewState* next_state = |
| 486 next->GetProperty(kWindowOverviewState); |
| 487 UpdateTerminalStateForWindowAtIndex( |
| 488 window, list.end() - iter, list.size()); |
| 489 SetWindowProgress(window, next_state->progress); |
| 490 } |
| 460 } | 491 } |
| 461 | 492 |
| 462 dragged_window_ = NULL; | 493 dragged_window_ = NULL; |
| 463 } | 494 } |
| 464 | 495 |
| 465 void RestoreDragWindow() { | 496 void RestoreDragWindow() { |
| 466 CHECK(dragged_window_); | 497 CHECK(dragged_window_); |
| 467 WindowOverviewState* dragged_state = | 498 WindowOverviewState* dragged_state = |
| 468 dragged_window_->GetProperty(kWindowOverviewState); | 499 dragged_window_->GetProperty(kWindowOverviewState); |
| 469 CHECK(dragged_state); | 500 CHECK(dragged_state); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 aura::Window* container, | 641 aura::Window* container, |
| 611 const WindowListProvider* window_list_provider, | 642 const WindowListProvider* window_list_provider, |
| 612 SplitViewController* split_view_controller, | 643 SplitViewController* split_view_controller, |
| 613 WindowOverviewModeDelegate* delegate) { | 644 WindowOverviewModeDelegate* delegate) { |
| 614 return scoped_ptr<WindowOverviewMode>( | 645 return scoped_ptr<WindowOverviewMode>( |
| 615 new WindowOverviewModeImpl(container, window_list_provider, | 646 new WindowOverviewModeImpl(container, window_list_provider, |
| 616 split_view_controller, delegate)); | 647 split_view_controller, delegate)); |
| 617 } | 648 } |
| 618 | 649 |
| 619 } // namespace athena | 650 } // namespace athena |
| OLD | NEW |