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 |
11 #include "athena/common/closure_animation_observer.h" | 11 #include "athena/common/closure_animation_observer.h" |
| 12 #include "athena/wm/overview_toolbar.h" |
12 #include "athena/wm/public/window_list_provider.h" | 13 #include "athena/wm/public/window_list_provider.h" |
13 #include "base/bind.h" | 14 #include "base/bind.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "ui/aura/scoped_window_targeter.h" | 16 #include "ui/aura/scoped_window_targeter.h" |
16 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
17 #include "ui/aura/window_delegate.h" | 18 #include "ui/aura/window_delegate.h" |
18 #include "ui/aura/window_property.h" | 19 #include "ui/aura/window_property.h" |
19 #include "ui/aura/window_targeter.h" | 20 #include "ui/aura/window_targeter.h" |
20 #include "ui/aura/window_tree_host.h" | 21 #include "ui/aura/window_tree_host.h" |
21 #include "ui/compositor/compositor.h" | 22 #include "ui/compositor/compositor.h" |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 | 284 |
284 void RemoveAnimationObserver() { | 285 void RemoveAnimationObserver() { |
285 ui::Compositor* compositor = container_->GetHost()->compositor(); | 286 ui::Compositor* compositor = container_->GetHost()->compositor(); |
286 if (compositor->HasAnimationObserver(this)) | 287 if (compositor->HasAnimationObserver(this)) |
287 compositor->RemoveAnimationObserver(this); | 288 compositor->RemoveAnimationObserver(this); |
288 } | 289 } |
289 | 290 |
290 void DragWindow(const ui::GestureEvent& event) { | 291 void DragWindow(const ui::GestureEvent& event) { |
291 CHECK(dragged_window_); | 292 CHECK(dragged_window_); |
292 CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, event.type()); | 293 CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, event.type()); |
| 294 CHECK(overview_toolbar_); |
293 gfx::Vector2dF dragged_distance = | 295 gfx::Vector2dF dragged_distance = |
294 dragged_start_location_ - event.location(); | 296 dragged_start_location_ - event.location(); |
295 WindowOverviewState* dragged_state = | 297 WindowOverviewState* dragged_state = |
296 dragged_window_->GetProperty(kWindowOverviewState); | 298 dragged_window_->GetProperty(kWindowOverviewState); |
297 CHECK(dragged_state); | 299 CHECK(dragged_state); |
298 gfx::Transform transform = GetTransformForState(dragged_state); | 300 gfx::Transform transform = GetTransformForState(dragged_state); |
299 transform.Translate(-dragged_distance.x(), 0); | 301 transform.Translate(-dragged_distance.x(), 0); |
300 dragged_window_->SetTransform(transform); | 302 dragged_window_->SetTransform(transform); |
301 | 303 |
| 304 // Update the toolbar. |
| 305 const int kMinDistanceForActionButtons = 20; |
| 306 if (fabs(dragged_distance.x()) > kMinDistanceForActionButtons) |
| 307 overview_toolbar_->ShowActionButtons(); |
| 308 else |
| 309 overview_toolbar_->HideActionButtons(); |
| 310 |
| 311 // See if the touch-point is above one of the action-buttons. |
| 312 OverviewToolbar::ActionType new_action = |
| 313 overview_toolbar_->GetHighlightAction(event); |
| 314 |
| 315 // If the touch-point is not above any of the action buttons, then highlight |
| 316 // the close-button by default, if the user has dragged enough to close the |
| 317 // window. |
| 318 if (new_action == OverviewToolbar::ACTION_TYPE_NONE) { |
| 319 if (fabs(dragged_distance.x()) > kMinDistanceForDismissal) |
| 320 new_action = OverviewToolbar::ACTION_TYPE_CLOSE; |
| 321 else |
| 322 new_action = OverviewToolbar::ACTION_TYPE_NONE; |
| 323 } |
| 324 OverviewToolbar::ActionType previous_action = |
| 325 overview_toolbar_->current_action(); |
| 326 overview_toolbar_->SetHighlightAction(new_action); |
| 327 |
| 328 // If the user has selected to get into split-view mode, then show the |
| 329 // window with full opacity. Otherwise, fade it out as it closes. Animate |
| 330 // the opacity if transitioning to/from the split-view button. |
| 331 bool animate_opacity = |
| 332 (new_action != previous_action) && |
| 333 ((new_action == OverviewToolbar::ACTION_TYPE_SPLIT) || |
| 334 (previous_action == OverviewToolbar::ACTION_TYPE_SPLIT)); |
302 float ratio = std::min( | 335 float ratio = std::min( |
303 1.f, std::abs(dragged_distance.x()) / kMinDistanceForDismissal); | 336 1.f, std::abs(dragged_distance.x()) / kMinDistanceForDismissal); |
304 float opacity = | 337 float opacity = |
305 gfx::Tween::FloatValueBetween(ratio, kMaxOpacity, kMinOpacity); | 338 (new_action == OverviewToolbar::ACTION_TYPE_SPLIT) |
306 dragged_window_->layer()->SetOpacity(opacity); | 339 ? 1 |
| 340 : gfx::Tween::FloatValueBetween(ratio, kMaxOpacity, kMinOpacity); |
| 341 if (animate_opacity) { |
| 342 ui::ScopedLayerAnimationSettings settings( |
| 343 dragged_window_->layer()->GetAnimator()); |
| 344 dragged_window_->layer()->SetOpacity(opacity); |
| 345 } else { |
| 346 dragged_window_->layer()->SetOpacity(opacity); |
| 347 } |
307 } | 348 } |
308 | 349 |
309 bool ShouldCloseDragWindow(const ui::GestureEvent& event) const { | 350 bool ShouldCloseDragWindow(const ui::GestureEvent& event) const { |
310 gfx::Vector2dF dragged_distance = | 351 gfx::Vector2dF dragged_distance = |
311 dragged_start_location_ - event.location(); | 352 dragged_start_location_ - event.location(); |
312 if (event.type() == ui::ET_GESTURE_SCROLL_END) | 353 if (event.type() == ui::ET_GESTURE_SCROLL_END) |
313 return std::abs(dragged_distance.x()) >= kMinDistanceForDismissal; | 354 return std::abs(dragged_distance.x()) >= kMinDistanceForDismissal; |
314 CHECK_EQ(ui::ET_SCROLL_FLING_START, event.type()); | 355 CHECK_EQ(ui::ET_SCROLL_FLING_START, event.type()); |
315 const bool dragging_towards_right = dragged_distance.x() < 0; | 356 const bool dragging_towards_right = dragged_distance.x() < 0; |
316 const bool swipe_towards_right = event.details().velocity_x() > 0; | 357 const bool swipe_towards_right = event.details().velocity_x() > 0; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 | 416 |
376 ui::ScopedLayerAnimationSettings settings( | 417 ui::ScopedLayerAnimationSettings settings( |
377 dragged_window_->layer()->GetAnimator()); | 418 dragged_window_->layer()->GetAnimator()); |
378 settings.SetPreemptionStrategy( | 419 settings.SetPreemptionStrategy( |
379 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 420 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
380 dragged_window_->SetTransform(GetTransformForState(dragged_state)); | 421 dragged_window_->SetTransform(GetTransformForState(dragged_state)); |
381 dragged_window_->layer()->SetOpacity(1.f); | 422 dragged_window_->layer()->SetOpacity(1.f); |
382 dragged_window_ = NULL; | 423 dragged_window_ = NULL; |
383 } | 424 } |
384 | 425 |
| 426 void EndDragWindow(const ui::GestureEvent& gesture) { |
| 427 CHECK(dragged_window_); |
| 428 CHECK(overview_toolbar_); |
| 429 OverviewToolbar::ActionType action = overview_toolbar_->current_action(); |
| 430 overview_toolbar_.reset(); |
| 431 if (action == OverviewToolbar::ACTION_TYPE_SPLIT) |
| 432 delegate_->OnSplitViewMode(NULL, dragged_window_); |
| 433 else if (ShouldCloseDragWindow(gesture)) |
| 434 CloseDragWindow(gesture); |
| 435 else |
| 436 RestoreDragWindow(); |
| 437 } |
| 438 |
385 // ui::EventHandler: | 439 // ui::EventHandler: |
386 virtual void OnMouseEvent(ui::MouseEvent* mouse) OVERRIDE { | 440 virtual void OnMouseEvent(ui::MouseEvent* mouse) OVERRIDE { |
387 if (mouse->type() == ui::ET_MOUSE_PRESSED) { | 441 if (mouse->type() == ui::ET_MOUSE_PRESSED) { |
388 aura::Window* select = SelectWindowAt(mouse); | 442 aura::Window* select = SelectWindowAt(mouse); |
389 if (select) { | 443 if (select) { |
390 mouse->SetHandled(); | 444 mouse->SetHandled(); |
391 delegate_->OnSelectWindow(select); | 445 delegate_->OnSelectWindow(select); |
392 } | 446 } |
393 } else if (mouse->type() == ui::ET_MOUSEWHEEL) { | 447 } else if (mouse->type() == ui::ET_MOUSEWHEEL) { |
394 DoScroll(static_cast<ui::MouseWheelEvent*>(mouse)->y_offset()); | 448 DoScroll(static_cast<ui::MouseWheelEvent*>(mouse)->y_offset()); |
(...skipping 10 matching lines...) Expand all Loading... |
405 aura::Window* select = SelectWindowAt(gesture); | 459 aura::Window* select = SelectWindowAt(gesture); |
406 if (select) { | 460 if (select) { |
407 gesture->SetHandled(); | 461 gesture->SetHandled(); |
408 delegate_->OnSelectWindow(select); | 462 delegate_->OnSelectWindow(select); |
409 } | 463 } |
410 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_BEGIN) { | 464 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_BEGIN) { |
411 if (std::abs(gesture->details().scroll_x_hint()) > | 465 if (std::abs(gesture->details().scroll_x_hint()) > |
412 std::abs(gesture->details().scroll_y_hint()) * 2) { | 466 std::abs(gesture->details().scroll_y_hint()) * 2) { |
413 dragged_start_location_ = gesture->location(); | 467 dragged_start_location_ = gesture->location(); |
414 dragged_window_ = SelectWindowAt(gesture); | 468 dragged_window_ = SelectWindowAt(gesture); |
| 469 if (dragged_window_) |
| 470 overview_toolbar_.reset(new OverviewToolbar(container_)); |
415 } | 471 } |
416 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) { | 472 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) { |
417 if (dragged_window_) | 473 if (dragged_window_) |
418 DragWindow(*gesture); | 474 DragWindow(*gesture); |
419 else | 475 else |
420 DoScroll(gesture->details().scroll_y()); | 476 DoScroll(gesture->details().scroll_y()); |
421 gesture->SetHandled(); | 477 gesture->SetHandled(); |
422 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_END) { | 478 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_END) { |
423 if (dragged_window_) { | 479 if (dragged_window_) |
424 if (ShouldCloseDragWindow(*gesture)) | 480 EndDragWindow(*gesture); |
425 CloseDragWindow(*gesture); | |
426 else | |
427 RestoreDragWindow(); | |
428 } | |
429 gesture->SetHandled(); | 481 gesture->SetHandled(); |
430 } else if (gesture->type() == ui::ET_SCROLL_FLING_START) { | 482 } else if (gesture->type() == ui::ET_SCROLL_FLING_START) { |
431 if (dragged_window_) { | 483 if (dragged_window_) { |
432 if (ShouldCloseDragWindow(*gesture)) | 484 EndDragWindow(*gesture); |
433 CloseDragWindow(*gesture); | |
434 else | |
435 RestoreDragWindow(); | |
436 } else { | 485 } else { |
437 CreateFlingerFor(*gesture); | 486 CreateFlingerFor(*gesture); |
438 AddAnimationObserver(); | 487 AddAnimationObserver(); |
439 } | 488 } |
440 gesture->SetHandled(); | 489 gesture->SetHandled(); |
441 } else if (gesture->type() == ui::ET_GESTURE_TAP_DOWN) { | 490 } else if (gesture->type() == ui::ET_GESTURE_TAP_DOWN) { |
442 if (fling_) { | 491 if (fling_) { |
443 fling_.reset(); | 492 fling_.reset(); |
444 RemoveAnimationObserver(); | 493 RemoveAnimationObserver(); |
445 gesture->SetHandled(); | 494 gesture->SetHandled(); |
(...skipping 24 matching lines...) Expand all Loading... |
470 | 519 |
471 aura::Window* container_; | 520 aura::Window* container_; |
472 // Provider of the stack of windows to show in the overview mode. Not owned. | 521 // Provider of the stack of windows to show in the overview mode. Not owned. |
473 const WindowListProvider* window_list_provider_; | 522 const WindowListProvider* window_list_provider_; |
474 WindowOverviewModeDelegate* delegate_; | 523 WindowOverviewModeDelegate* delegate_; |
475 scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_; | 524 scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_; |
476 scoped_ptr<ui::FlingCurve> fling_; | 525 scoped_ptr<ui::FlingCurve> fling_; |
477 | 526 |
478 aura::Window* dragged_window_; | 527 aura::Window* dragged_window_; |
479 gfx::Point dragged_start_location_; | 528 gfx::Point dragged_start_location_; |
| 529 scoped_ptr<OverviewToolbar> overview_toolbar_; |
480 | 530 |
481 DISALLOW_COPY_AND_ASSIGN(WindowOverviewModeImpl); | 531 DISALLOW_COPY_AND_ASSIGN(WindowOverviewModeImpl); |
482 }; | 532 }; |
483 | 533 |
484 } // namespace | 534 } // namespace |
485 | 535 |
486 // static | 536 // static |
487 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create( | 537 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create( |
488 aura::Window* container, | 538 aura::Window* container, |
489 const WindowListProvider* window_list_provider, | 539 const WindowListProvider* window_list_provider, |
490 WindowOverviewModeDelegate* delegate) { | 540 WindowOverviewModeDelegate* delegate) { |
491 return scoped_ptr<WindowOverviewMode>( | 541 return scoped_ptr<WindowOverviewMode>( |
492 new WindowOverviewModeImpl(container, window_list_provider, delegate)); | 542 new WindowOverviewModeImpl(container, window_list_provider, delegate)); |
493 } | 543 } |
494 | 544 |
495 } // namespace athena | 545 } // namespace athena |
OLD | NEW |