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 void UpdateTerminalStateForWindowAtIndex(aura::Window* window, | 192 void UpdateTerminalStateForWindowAtIndex(aura::Window* window, |
oshima
2014/09/03 19:50:35
can you document this method?
sadrul
2014/09/03 20:24:36
Done.
| |
193 size_t index, | 193 size_t index, |
194 size_t window_count) { | 194 size_t window_count) { |
195 const int kGapBetweenWindowsBottom = 10; | 195 const int kGapBetweenWindowsBottom = 10; |
196 const int kGapBetweenWindowsTop = 5; | 196 const int kGapBetweenWindowsTop = 5; |
197 | 197 |
198 const int container_width = container_->bounds().width(); | 198 const int container_width = container_->bounds().width(); |
199 const int window_width = window->bounds().width(); | 199 const int window_width = window->bounds().width(); |
200 const int window_x = window->bounds().x(); | 200 const int window_x = window->bounds().x(); |
201 gfx::Transform top_transform; | 201 gfx::Transform top_transform; |
202 int top = (window_count - index - 1) * kGapBetweenWindowsTop; | 202 int top = (window_count - index - 1) * kGapBetweenWindowsTop; |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 const bool dragging_towards_right = dragged_distance.x() < 0; | 411 const bool dragging_towards_right = dragged_distance.x() < 0; |
412 const bool swipe_towards_right = event.details().velocity_x() > 0; | 412 const bool swipe_towards_right = event.details().velocity_x() > 0; |
413 if (dragging_towards_right != swipe_towards_right) | 413 if (dragging_towards_right != swipe_towards_right) |
414 return false; | 414 return false; |
415 const float kMinVelocityForDismissal = 500.f; | 415 const float kMinVelocityForDismissal = 500.f; |
416 return std::abs(event.details().velocity_x()) > kMinVelocityForDismissal; | 416 return std::abs(event.details().velocity_x()) > kMinVelocityForDismissal; |
417 } | 417 } |
418 | 418 |
419 void CloseDragWindow(const ui::GestureEvent& gesture) { | 419 void CloseDragWindow(const ui::GestureEvent& gesture) { |
420 // Animate |dragged_window_| offscreen first, then destroy it. | 420 // Animate |dragged_window_| offscreen first, then destroy it. |
421 ui::ScopedLayerAnimationSettings settings( | 421 ui::ScopedLayerAnimationSettings settings( |
oshima
2014/09/03 19:50:35
optional:
the scope of this object out lives othe
sadrul
2014/09/03 20:24:36
Done.
| |
422 dragged_window_->layer()->GetAnimator()); | 422 dragged_window_->layer()->GetAnimator()); |
423 settings.SetPreemptionStrategy( | 423 settings.SetPreemptionStrategy( |
424 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 424 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
425 settings.AddObserver(new ui::ClosureAnimationObserver( | 425 settings.AddObserver(new ui::ClosureAnimationObserver( |
426 base::Bind(&base::DeletePointer<aura::Window>, dragged_window_))); | 426 base::Bind(&base::DeletePointer<aura::Window>, dragged_window_))); |
427 | 427 |
428 WindowOverviewState* dragged_state = | 428 WindowOverviewState* dragged_state = |
429 dragged_window_->GetProperty(kWindowOverviewState); | 429 dragged_window_->GetProperty(kWindowOverviewState); |
430 CHECK(dragged_state); | 430 CHECK(dragged_state); |
431 gfx::Transform transform = dragged_window_->layer()->transform(); | 431 gfx::Transform transform = dragged_window_->layer()->transform(); |
432 gfx::RectF transformed_bounds = dragged_window_->bounds(); | 432 gfx::RectF transformed_bounds = dragged_window_->bounds(); |
433 transform.TransformRect(&transformed_bounds); | 433 transform.TransformRect(&transformed_bounds); |
434 float transform_x = 0.f; | 434 float transform_x = 0.f; |
435 if (gesture.location().x() > dragged_start_location_.x()) | 435 if (gesture.location().x() > dragged_start_location_.x()) |
436 transform_x = container_->bounds().right() - transformed_bounds.x(); | 436 transform_x = container_->bounds().right() - transformed_bounds.x(); |
437 else | 437 else |
438 transform_x = -(transformed_bounds.x() + transformed_bounds.width()); | 438 transform_x = -(transformed_bounds.x() + transformed_bounds.width()); |
439 float scale = gfx::Tween::FloatValueBetween( | 439 float scale = gfx::Tween::FloatValueBetween( |
440 dragged_state->progress, kMinScale, kMaxScale); | 440 dragged_state->progress, kMinScale, kMaxScale); |
441 transform.Translate(transform_x / scale, 0); | 441 transform.Translate(transform_x / scale, 0); |
442 dragged_window_->SetTransform(transform); | 442 dragged_window_->SetTransform(transform); |
443 dragged_window_->layer()->SetOpacity(kMinOpacity); | 443 dragged_window_->layer()->SetOpacity(kMinOpacity); |
444 | 444 |
445 // Move the windows behind |dragged_window_| in the stack forward one step. | 445 const aura::Window::Windows list = window_list_provider_->GetWindowList(); |
446 const aura::Window::Windows& list = container_->children(); | 446 if (list.empty()) |
oshima
2014/09/03 19:50:35
CHECK? (if you have dragged_window_, this shouldn'
sadrul
2014/09/03 20:24:36
Good point. Done.
| |
447 for (aura::Window::Windows::const_iterator iter = list.begin(); | 447 return; |
448 iter != list.end() && *iter != dragged_window_; | 448 if (list.front() == dragged_window_) { |
449 ++iter) { | 449 // There's no window behind |dragged_window_|. So move the windows in |
450 aura::Window* window = *iter; | 450 // front take a step back. |
451 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 451 for (aura::Window::Windows::const_reverse_iterator iter = list.rbegin(); |
452 settings.SetPreemptionStrategy( | 452 iter != list.rend() && *iter != dragged_window_; |
453 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 453 ++iter) { |
454 aura::Window* window = *iter; | |
455 ui::ScopedLayerAnimationSettings settings( | |
456 window->layer()->GetAnimator()); | |
457 settings.SetPreemptionStrategy( | |
458 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
454 | 459 |
455 aura::Window* next = *(iter + 1); | 460 aura::Window* next = *(iter + 1); |
456 WindowOverviewState* next_state = next->GetProperty(kWindowOverviewState); | 461 WindowOverviewState* next_state = |
457 UpdateTerminalStateForWindowAtIndex(window, list.end() - iter, | 462 next->GetProperty(kWindowOverviewState); |
458 list.size()); | 463 UpdateTerminalStateForWindowAtIndex( |
459 SetWindowProgress(window, next_state->progress); | 464 window, iter - list.rbegin(), list.size()); |
465 SetWindowProgress(window, next_state->progress); | |
466 } | |
467 } else { | |
468 // Move the windows behind |dragged_window_| in the stack forward one | |
469 // step. | |
470 for (aura::Window::Windows::const_iterator iter = list.begin(); | |
471 iter != list.end() && *iter != dragged_window_; | |
472 ++iter) { | |
473 aura::Window* window = *iter; | |
474 ui::ScopedLayerAnimationSettings settings( | |
475 window->layer()->GetAnimator()); | |
476 settings.SetPreemptionStrategy( | |
477 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
478 | |
479 aura::Window* next = *(iter + 1); | |
480 WindowOverviewState* next_state = | |
481 next->GetProperty(kWindowOverviewState); | |
482 UpdateTerminalStateForWindowAtIndex( | |
483 window, list.end() - iter, list.size()); | |
484 SetWindowProgress(window, next_state->progress); | |
485 } | |
460 } | 486 } |
461 | 487 |
462 dragged_window_ = NULL; | 488 dragged_window_ = NULL; |
463 } | 489 } |
464 | 490 |
465 void RestoreDragWindow() { | 491 void RestoreDragWindow() { |
466 CHECK(dragged_window_); | 492 CHECK(dragged_window_); |
467 WindowOverviewState* dragged_state = | 493 WindowOverviewState* dragged_state = |
468 dragged_window_->GetProperty(kWindowOverviewState); | 494 dragged_window_->GetProperty(kWindowOverviewState); |
469 CHECK(dragged_state); | 495 CHECK(dragged_state); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
610 aura::Window* container, | 636 aura::Window* container, |
611 const WindowListProvider* window_list_provider, | 637 const WindowListProvider* window_list_provider, |
612 SplitViewController* split_view_controller, | 638 SplitViewController* split_view_controller, |
613 WindowOverviewModeDelegate* delegate) { | 639 WindowOverviewModeDelegate* delegate) { |
614 return scoped_ptr<WindowOverviewMode>( | 640 return scoped_ptr<WindowOverviewMode>( |
615 new WindowOverviewModeImpl(container, window_list_provider, | 641 new WindowOverviewModeImpl(container, window_list_provider, |
616 split_view_controller, delegate)); | 642 split_view_controller, delegate)); |
617 } | 643 } |
618 | 644 |
619 } // namespace athena | 645 } // namespace athena |
OLD | NEW |