OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "chrome/browser/ui/views/frame/immersive_mode_controller_ash.h" | 5 #include "chrome/browser/ui/views/frame/immersive_mode_controller_ash.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 // Reset the located event and the focus revealed locks so that they do not | 333 // Reset the located event and the focus revealed locks so that they do not |
334 // affect whether the top-of-window views are hidden. | 334 // affect whether the top-of-window views are hidden. |
335 located_event_revealed_lock_.reset(); | 335 located_event_revealed_lock_.reset(); |
336 focus_revealed_lock_.reset(); | 336 focus_revealed_lock_.reset(); |
337 | 337 |
338 // Try doing the animation. | 338 // Try doing the animation. |
339 MaybeEndReveal(ANIMATE_SLOW); | 339 MaybeEndReveal(ANIMATE_SLOW); |
340 | 340 |
341 if (reveal_state_ == REVEALED) { | 341 if (reveal_state_ == REVEALED) { |
342 // Reveal was unsuccessful. Reacquire the revealed locks if appropriate. | 342 // Reveal was unsuccessful. Reacquire the revealed locks if appropriate. |
343 UpdateLocatedEventRevealedLock(NULL); | 343 UpdateLocatedEventRevealedLock(NULL, REVEAL_WHILE_CLOSING_NO); |
344 UpdateFocusRevealedLock(); | 344 UpdateFocusRevealedLock(); |
345 } | 345 } |
346 } else { | 346 } else { |
347 // Stop cursor-at-top tracking. | 347 // Stop cursor-at-top tracking. |
348 top_edge_hover_timer_.Stop(); | 348 top_edge_hover_timer_.Stop(); |
349 // Snap immediately to the closed state. | 349 // Snap immediately to the closed state. |
350 reveal_state_ = CLOSED; | 350 reveal_state_ = CLOSED; |
351 EnablePaintToLayer(false); | 351 EnablePaintToLayer(false); |
352 delegate_->SetImmersiveStyle(false); | 352 delegate_->SetImmersiveStyle(false); |
353 SetRenderWindowTopInsetsForTouch(0); | 353 SetRenderWindowTopInsetsForTouch(0); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
420 // |native_window_| is inactive. | 420 // |native_window_| is inactive. |
421 if (!views::Widget::GetWidgetForNativeWindow(native_window_)->IsActive()) | 421 if (!views::Widget::GetWidgetForNativeWindow(native_window_)->IsActive()) |
422 return; | 422 return; |
423 | 423 |
424 // Mouse hover should not initiate revealing the top-of-window views while | 424 // Mouse hover should not initiate revealing the top-of-window views while |
425 // a window has mouse capture. | 425 // a window has mouse capture. |
426 if (aura::client::GetCaptureWindow(native_window_)) | 426 if (aura::client::GetCaptureWindow(native_window_)) |
427 return; | 427 return; |
428 | 428 |
429 if (IsRevealed()) | 429 if (IsRevealed()) |
430 UpdateLocatedEventRevealedLock(event); | 430 UpdateLocatedEventRevealedLock(event, REVEAL_WHILE_CLOSING_NO); |
431 | 431 |
432 // Trigger a reveal if the cursor pauses at the top of the screen for a | 432 // Trigger a reveal if the cursor pauses at the top of the screen for a |
433 // while. | 433 // while. |
434 if (event->type() != ui::ET_MOUSE_CAPTURE_CHANGED) | 434 if (event->type() != ui::ET_MOUSE_CAPTURE_CHANGED) |
435 UpdateTopEdgeHoverTimer(event); | 435 UpdateTopEdgeHoverTimer(event); |
436 } | 436 } |
437 | 437 |
438 void ImmersiveModeControllerAsh::OnTouchEvent(ui::TouchEvent* event) { | 438 void ImmersiveModeControllerAsh::OnTouchEvent(ui::TouchEvent* event) { |
439 if (!enabled_ || event->type() != ui::ET_TOUCH_PRESSED) | 439 if (!enabled_ || event->type() != ui::ET_TOUCH_PRESSED) |
440 return; | 440 return; |
441 | 441 |
442 UpdateLocatedEventRevealedLock(event); | 442 UpdateLocatedEventRevealedLock(event, REVEAL_WHILE_CLOSING_NO); |
443 } | 443 } |
444 | 444 |
445 void ImmersiveModeControllerAsh::OnGestureEvent(ui::GestureEvent* event) { | 445 void ImmersiveModeControllerAsh::OnGestureEvent(ui::GestureEvent* event) { |
446 if (!enabled_) | 446 if (!enabled_) |
447 return; | 447 return; |
448 | 448 |
449 // Touch gestures should not initiate revealing the top-of-window views while | 449 // Touch gestures should not initiate revealing the top-of-window views while |
450 // |native_window_| is inactive. | 450 // |native_window_| is inactive. |
451 if (!views::Widget::GetWidgetForNativeWindow(native_window_)->IsActive()) | 451 if (!views::Widget::GetWidgetForNativeWindow(native_window_)->IsActive()) |
452 return; | 452 return; |
(...skipping 20 matching lines...) Expand all Loading... | |
473 break; | 473 break; |
474 } | 474 } |
475 } | 475 } |
476 | 476 |
477 void ImmersiveModeControllerAsh::OnWillChangeFocus(views::View* focused_before, | 477 void ImmersiveModeControllerAsh::OnWillChangeFocus(views::View* focused_before, |
478 views::View* focused_now) { | 478 views::View* focused_now) { |
479 } | 479 } |
480 | 480 |
481 void ImmersiveModeControllerAsh::OnDidChangeFocus(views::View* focused_before, | 481 void ImmersiveModeControllerAsh::OnDidChangeFocus(views::View* focused_before, |
482 views::View* focused_now) { | 482 views::View* focused_now) { |
483 scoped_ptr<ImmersiveRevealedLock> lock; | |
484 if (reveal_state_ == REVEALED || reveal_state_ == SLIDING_OPEN) { | |
485 // Acquire a lock so that if UpdateLocatedEventRevealedLock() or | |
486 // UpdateFocusRevealedLock() ends the reveal, it occurs after the | |
487 // function terminates. This is useful in tests. | |
488 lock.reset(GetRevealedLock(ANIMATE_REVEAL_YES)); | |
489 } | |
490 | |
491 UpdateLocatedEventRevealedLock(NULL); | |
pkotwicz
2013/08/05 19:14:07
This is no longer necessary given that it is now o
| |
492 UpdateFocusRevealedLock(); | 483 UpdateFocusRevealedLock(); |
493 } | 484 } |
494 | 485 |
495 void ImmersiveModeControllerAsh::OnWidgetDestroying(views::Widget* widget) { | 486 void ImmersiveModeControllerAsh::OnWidgetDestroying(views::Widget* widget) { |
496 EnableWindowObservers(false); | 487 EnableWindowObservers(false); |
497 native_window_ = NULL; | 488 native_window_ = NULL; |
498 | 489 |
499 // Set |enabled_| to false such that any calls to MaybeStartReveal() and | 490 // Set |enabled_| to false such that any calls to MaybeStartReveal() and |
500 // MaybeEndReveal() have no effect. | 491 // MaybeEndReveal() have no effect. |
501 enabled_ = false; | 492 enabled_ = false; |
502 } | 493 } |
503 | 494 |
504 void ImmersiveModeControllerAsh::OnWidgetActivationChanged( | 495 void ImmersiveModeControllerAsh::OnWidgetActivationChanged( |
505 views::Widget* widget, | 496 views::Widget* widget, |
506 bool active) { | 497 bool active) { |
507 scoped_ptr<ImmersiveRevealedLock> lock; | |
508 if (reveal_state_ == REVEALED || reveal_state_ == SLIDING_OPEN) { | |
509 // Acquire a lock so that if UpdateLocatedEventRevealedLock() or | |
510 // UpdateFocusRevealedLock() ends the reveal, it occurs after the | |
511 // function terminates. This is useful in tests. | |
512 lock.reset(GetRevealedLock(ANIMATE_REVEAL_YES)); | |
513 } | |
514 | |
515 // Mouse hover should not initiate revealing the top-of-window views while | 498 // Mouse hover should not initiate revealing the top-of-window views while |
516 // |native_window_| is inactive. | 499 // |native_window_| is inactive. |
517 top_edge_hover_timer_.Stop(); | 500 top_edge_hover_timer_.Stop(); |
518 | 501 |
519 UpdateLocatedEventRevealedLock(NULL); | |
520 UpdateFocusRevealedLock(); | 502 UpdateFocusRevealedLock(); |
503 | |
504 // Allow the top-of-window views to stay revealed if all of the revealed locks | |
505 // were released in the process of activating |widget| but the mouse is still | |
506 // hovered above the top-of-window views. For instance, if the bubble which | |
507 // has been keeping the top-of-window views revealed is hidden but the mouse | |
508 // is hovered above the top-of-window views, the top-of-window views should | |
509 // stay revealed. We cannot call UpdateLocatedEventRevealedLock() from | |
510 // BubbleManager::UpdateRevealedLock() because |widget| is not yet activate | |
James Cook
2013/08/06 23:32:42
activate -> activated
| |
511 // at that time. | |
512 UpdateLocatedEventRevealedLock(NULL, REVEAL_WHILE_CLOSING_YES); | |
521 } | 513 } |
522 | 514 |
523 //////////////////////////////////////////////////////////////////////////////// | 515 //////////////////////////////////////////////////////////////////////////////// |
524 // Animation delegate: | 516 // Animation delegate: |
525 | 517 |
526 void ImmersiveModeControllerAsh::AnimationEnded( | 518 void ImmersiveModeControllerAsh::AnimationEnded( |
527 const ui::Animation* animation) { | 519 const ui::Animation* animation) { |
528 if (reveal_state_ == SLIDING_OPEN) { | 520 if (reveal_state_ == SLIDING_OPEN) { |
529 // AnimationProgressed() is called immediately before AnimationEnded() | 521 // AnimationProgressed() is called immediately before AnimationEnded() |
530 // and does a layout. | 522 // and does a layout. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
603 if (force) | 595 if (force) |
604 tab_indicator_visibility_ = TAB_INDICATORS_FORCE_HIDE; | 596 tab_indicator_visibility_ = TAB_INDICATORS_FORCE_HIDE; |
605 else if (tab_indicator_visibility_ == TAB_INDICATORS_FORCE_HIDE) | 597 else if (tab_indicator_visibility_ == TAB_INDICATORS_FORCE_HIDE) |
606 tab_indicator_visibility_ = TAB_INDICATORS_HIDE; | 598 tab_indicator_visibility_ = TAB_INDICATORS_HIDE; |
607 UpdateUseMinimalChrome(LAYOUT_YES); | 599 UpdateUseMinimalChrome(LAYOUT_YES); |
608 } | 600 } |
609 | 601 |
610 void ImmersiveModeControllerAsh::StartRevealForTest(bool hovered) { | 602 void ImmersiveModeControllerAsh::StartRevealForTest(bool hovered) { |
611 MaybeStartReveal(ANIMATE_NO); | 603 MaybeStartReveal(ANIMATE_NO); |
612 MoveMouse(top_container_, hovered); | 604 MoveMouse(top_container_, hovered); |
613 UpdateLocatedEventRevealedLock(NULL); | 605 UpdateLocatedEventRevealedLock(NULL, REVEAL_WHILE_CLOSING_NO); |
614 } | 606 } |
615 | 607 |
616 void ImmersiveModeControllerAsh::SetMouseHoveredForTest(bool hovered) { | 608 void ImmersiveModeControllerAsh::SetMouseHoveredForTest(bool hovered) { |
617 MoveMouse(top_container_, hovered); | 609 MoveMouse(top_container_, hovered); |
618 UpdateLocatedEventRevealedLock(NULL); | 610 UpdateLocatedEventRevealedLock(NULL, REVEAL_WHILE_CLOSING_NO); |
619 } | 611 } |
620 | 612 |
621 void ImmersiveModeControllerAsh::DisableAnimationsForTest() { | 613 void ImmersiveModeControllerAsh::DisableAnimationsForTest() { |
622 animations_disabled_for_test_ = true; | 614 animations_disabled_for_test_ = true; |
623 } | 615 } |
624 | 616 |
625 //////////////////////////////////////////////////////////////////////////////// | 617 //////////////////////////////////////////////////////////////////////////////// |
626 // private: | 618 // private: |
627 | 619 |
628 void ImmersiveModeControllerAsh::EnableWindowObservers(bool enable) { | 620 void ImmersiveModeControllerAsh::EnableWindowObservers(bool enable) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
723 // Timer is stopped when |this| is destroyed, hence Unretained() is safe. | 715 // Timer is stopped when |this| is destroyed, hence Unretained() is safe. |
724 top_edge_hover_timer_.Start( | 716 top_edge_hover_timer_.Start( |
725 FROM_HERE, | 717 FROM_HERE, |
726 base::TimeDelta::FromMilliseconds( | 718 base::TimeDelta::FromMilliseconds( |
727 ImmersiveFullscreenConfiguration::immersive_mode_reveal_delay_ms()), | 719 ImmersiveFullscreenConfiguration::immersive_mode_reveal_delay_ms()), |
728 base::Bind(&ImmersiveModeControllerAsh::AcquireLocatedEventRevealedLock, | 720 base::Bind(&ImmersiveModeControllerAsh::AcquireLocatedEventRevealedLock, |
729 base::Unretained(this))); | 721 base::Unretained(this))); |
730 } | 722 } |
731 | 723 |
732 void ImmersiveModeControllerAsh::UpdateLocatedEventRevealedLock( | 724 void ImmersiveModeControllerAsh::UpdateLocatedEventRevealedLock( |
733 ui::LocatedEvent* event) { | 725 ui::LocatedEvent* event, |
726 RevealWhileClosing reveal_while_closing) { | |
734 if (!enabled_) | 727 if (!enabled_) |
735 return; | 728 return; |
736 DCHECK(!event || event->IsMouseEvent() || event->IsTouchEvent()); | 729 DCHECK(!event || event->IsMouseEvent() || event->IsTouchEvent()); |
737 | 730 |
738 // Neither the mouse nor touch can initiate a reveal when the top-of-window | 731 // Neither the mouse nor touch can initiate a reveal when the top-of-window |
739 // views are sliding closed or are closed with the following exceptions: | 732 // views are sliding closed or are closed with the following exceptions: |
740 // - Hovering at y = 0 which is handled in OnMouseEvent(). | 733 // - Hovering at y = 0 which is handled in OnMouseEvent(). |
741 // - Doing a SWIPE_OPEN edge gesture which is handled in OnGestureEvent(). | 734 // - Doing a SWIPE_OPEN edge gesture which is handled in OnGestureEvent(). |
742 if (reveal_state_ == SLIDING_CLOSED || reveal_state_ == CLOSED) | 735 if (reveal_state_ == CLOSED || |
736 (reveal_state_ == SLIDING_CLOSED && | |
737 reveal_while_closing == REVEAL_WHILE_CLOSING_NO)) { | |
743 return; | 738 return; |
739 } | |
744 | 740 |
745 // Neither the mouse nor touch should keep the top-of-window views revealed if | 741 // Neither the mouse nor touch should keep the top-of-window views revealed if |
746 // |native_window_| is not active. | 742 // |native_window_| is not active. |
747 if (!views::Widget::GetWidgetForNativeWindow(native_window_)->IsActive()) { | 743 if (!views::Widget::GetWidgetForNativeWindow(native_window_)->IsActive()) { |
748 located_event_revealed_lock_.reset(); | 744 located_event_revealed_lock_.reset(); |
749 return; | 745 return; |
750 } | 746 } |
751 | 747 |
752 // Ignore all events while a window has capture. This keeps the top-of-window | 748 // Ignore all events while a window has capture. This keeps the top-of-window |
753 // views revealed during a drag. | 749 // views revealed during a drag. |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
860 if (swipe_type == SWIPE_CLOSE) { | 856 if (swipe_type == SWIPE_CLOSE) { |
861 // Attempt to end the reveal. If other code is holding onto a lock, the | 857 // Attempt to end the reveal. If other code is holding onto a lock, the |
862 // attempt will be unsuccessful. | 858 // attempt will be unsuccessful. |
863 located_event_revealed_lock_.reset(); | 859 located_event_revealed_lock_.reset(); |
864 focus_revealed_lock_.reset(); | 860 focus_revealed_lock_.reset(); |
865 | 861 |
866 if (reveal_state_ == SLIDING_CLOSED || reveal_state_ == CLOSED) | 862 if (reveal_state_ == SLIDING_CLOSED || reveal_state_ == CLOSED) |
867 return true; | 863 return true; |
868 | 864 |
869 // Ending the reveal was unsuccessful. Reaquire the locks if appropriate. | 865 // Ending the reveal was unsuccessful. Reaquire the locks if appropriate. |
870 UpdateLocatedEventRevealedLock(NULL); | 866 UpdateLocatedEventRevealedLock(NULL, REVEAL_WHILE_CLOSING_NO); |
871 UpdateFocusRevealedLock(); | 867 UpdateFocusRevealedLock(); |
872 } | 868 } |
873 } | 869 } |
874 return false; | 870 return false; |
875 } | 871 } |
876 | 872 |
877 void ImmersiveModeControllerAsh::UpdateUseMinimalChrome(Layout layout) { | 873 void ImmersiveModeControllerAsh::UpdateUseMinimalChrome(Layout layout) { |
878 // May be NULL in tests. | 874 // May be NULL in tests. |
879 FullscreenController* fullscreen_controller = | 875 FullscreenController* fullscreen_controller = |
880 delegate_->GetFullscreenController(); | 876 delegate_->GetFullscreenController(); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
996 | 992 |
997 void ImmersiveModeControllerAsh::OnSlideOpenAnimationCompleted(Layout layout) { | 993 void ImmersiveModeControllerAsh::OnSlideOpenAnimationCompleted(Layout layout) { |
998 DCHECK_EQ(SLIDING_OPEN, reveal_state_); | 994 DCHECK_EQ(SLIDING_OPEN, reveal_state_); |
999 reveal_state_ = REVEALED; | 995 reveal_state_ = REVEALED; |
1000 | 996 |
1001 if (layout == LAYOUT_YES) | 997 if (layout == LAYOUT_YES) |
1002 top_container_->parent()->Layout(); | 998 top_container_->parent()->Layout(); |
1003 | 999 |
1004 // The user may not have moved the mouse since the reveal was initiated. | 1000 // The user may not have moved the mouse since the reveal was initiated. |
1005 // Update the revealed lock to reflect the mouse's current state. | 1001 // Update the revealed lock to reflect the mouse's current state. |
1006 UpdateLocatedEventRevealedLock(NULL); | 1002 UpdateLocatedEventRevealedLock(NULL, REVEAL_WHILE_CLOSING_NO); |
1007 } | 1003 } |
1008 | 1004 |
1009 void ImmersiveModeControllerAsh::MaybeEndReveal(Animate animate) { | 1005 void ImmersiveModeControllerAsh::MaybeEndReveal(Animate animate) { |
1010 if (!enabled_ || revealed_lock_count_ != 0) | 1006 if (!enabled_ || revealed_lock_count_ != 0) |
1011 return; | 1007 return; |
1012 | 1008 |
1013 if (animations_disabled_for_test_) | 1009 if (animations_disabled_for_test_) |
1014 animate = ANIMATE_NO; | 1010 animate = ANIMATE_NO; |
1015 | 1011 |
1016 // Callers with ANIMATE_NO expect this function to synchronously close the | 1012 // Callers with ANIMATE_NO expect this function to synchronously close the |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1109 aura::Window* transient_child = transient_children[i]; | 1105 aura::Window* transient_child = transient_children[i]; |
1110 views::BubbleDelegateView* bubble_delegate = | 1106 views::BubbleDelegateView* bubble_delegate = |
1111 AsBubbleDelegate(transient_child); | 1107 AsBubbleDelegate(transient_child); |
1112 if (bubble_delegate && | 1108 if (bubble_delegate && |
1113 bubble_delegate->anchor_view() && | 1109 bubble_delegate->anchor_view() && |
1114 top_container_->Contains(bubble_delegate->anchor_view())) { | 1110 top_container_->Contains(bubble_delegate->anchor_view())) { |
1115 bubble_manager_->StartObserving(transient_child); | 1111 bubble_manager_->StartObserving(transient_child); |
1116 } | 1112 } |
1117 } | 1113 } |
1118 } | 1114 } |
OLD | NEW |