| 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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 // Reset the located event and the focus revealed locks so that they do not | 346 // Reset the located event and the focus revealed locks so that they do not |
| 347 // affect whether the top-of-window views are hidden. | 347 // affect whether the top-of-window views are hidden. |
| 348 located_event_revealed_lock_.reset(); | 348 located_event_revealed_lock_.reset(); |
| 349 focus_revealed_lock_.reset(); | 349 focus_revealed_lock_.reset(); |
| 350 | 350 |
| 351 // Try doing the animation. | 351 // Try doing the animation. |
| 352 MaybeEndReveal(ANIMATE_SLOW); | 352 MaybeEndReveal(ANIMATE_SLOW); |
| 353 | 353 |
| 354 if (reveal_state_ == REVEALED) { | 354 if (reveal_state_ == REVEALED) { |
| 355 // Reveal was unsuccessful. Reacquire the revealed locks if appropriate. | 355 // Reveal was unsuccessful. Reacquire the revealed locks if appropriate. |
| 356 UpdateLocatedEventRevealedLock(NULL); | 356 UpdateLocatedEventRevealedLock(NULL, ALLOW_REVEAL_WHILE_CLOSING_NO); |
| 357 UpdateFocusRevealedLock(); | 357 UpdateFocusRevealedLock(); |
| 358 } | 358 } |
| 359 } else { | 359 } else { |
| 360 // Stop cursor-at-top tracking. | 360 // Stop cursor-at-top tracking. |
| 361 top_edge_hover_timer_.Stop(); | 361 top_edge_hover_timer_.Stop(); |
| 362 // Snap immediately to the closed state. | 362 // Snap immediately to the closed state. |
| 363 reveal_state_ = CLOSED; | 363 reveal_state_ = CLOSED; |
| 364 EnablePaintToLayer(false); | 364 EnablePaintToLayer(false); |
| 365 delegate_->SetImmersiveStyle(false); | 365 delegate_->SetImmersiveStyle(false); |
| 366 SetRenderWindowTopInsetsForTouch(0); | 366 SetRenderWindowTopInsetsForTouch(0); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 // |native_window_| is inactive. | 433 // |native_window_| is inactive. |
| 434 if (!views::Widget::GetWidgetForNativeWindow(native_window_)->IsActive()) | 434 if (!views::Widget::GetWidgetForNativeWindow(native_window_)->IsActive()) |
| 435 return; | 435 return; |
| 436 | 436 |
| 437 // Mouse hover should not initiate revealing the top-of-window views while | 437 // Mouse hover should not initiate revealing the top-of-window views while |
| 438 // a window has mouse capture. | 438 // a window has mouse capture. |
| 439 if (aura::client::GetCaptureWindow(native_window_)) | 439 if (aura::client::GetCaptureWindow(native_window_)) |
| 440 return; | 440 return; |
| 441 | 441 |
| 442 if (IsRevealed()) | 442 if (IsRevealed()) |
| 443 UpdateLocatedEventRevealedLock(event); | 443 UpdateLocatedEventRevealedLock(event, ALLOW_REVEAL_WHILE_CLOSING_NO); |
| 444 | 444 |
| 445 // Trigger a reveal if the cursor pauses at the top of the screen for a | 445 // Trigger a reveal if the cursor pauses at the top of the screen for a |
| 446 // while. | 446 // while. |
| 447 if (event->type() != ui::ET_MOUSE_CAPTURE_CHANGED) | 447 if (event->type() != ui::ET_MOUSE_CAPTURE_CHANGED) |
| 448 UpdateTopEdgeHoverTimer(event); | 448 UpdateTopEdgeHoverTimer(event); |
| 449 } | 449 } |
| 450 | 450 |
| 451 void ImmersiveModeControllerAsh::OnTouchEvent(ui::TouchEvent* event) { | 451 void ImmersiveModeControllerAsh::OnTouchEvent(ui::TouchEvent* event) { |
| 452 if (!enabled_ || event->type() != ui::ET_TOUCH_PRESSED) | 452 if (!enabled_ || event->type() != ui::ET_TOUCH_PRESSED) |
| 453 return; | 453 return; |
| 454 | 454 |
| 455 UpdateLocatedEventRevealedLock(event); | 455 UpdateLocatedEventRevealedLock(event, ALLOW_REVEAL_WHILE_CLOSING_NO); |
| 456 } | 456 } |
| 457 | 457 |
| 458 void ImmersiveModeControllerAsh::OnGestureEvent(ui::GestureEvent* event) { | 458 void ImmersiveModeControllerAsh::OnGestureEvent(ui::GestureEvent* event) { |
| 459 if (!enabled_) | 459 if (!enabled_) |
| 460 return; | 460 return; |
| 461 | 461 |
| 462 // Touch gestures should not initiate revealing the top-of-window views while | 462 // Touch gestures should not initiate revealing the top-of-window views while |
| 463 // |native_window_| is inactive. | 463 // |native_window_| is inactive. |
| 464 if (!views::Widget::GetWidgetForNativeWindow(native_window_)->IsActive()) | 464 if (!views::Widget::GetWidgetForNativeWindow(native_window_)->IsActive()) |
| 465 return; | 465 return; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 486 break; | 486 break; |
| 487 } | 487 } |
| 488 } | 488 } |
| 489 | 489 |
| 490 void ImmersiveModeControllerAsh::OnWillChangeFocus(views::View* focused_before, | 490 void ImmersiveModeControllerAsh::OnWillChangeFocus(views::View* focused_before, |
| 491 views::View* focused_now) { | 491 views::View* focused_now) { |
| 492 } | 492 } |
| 493 | 493 |
| 494 void ImmersiveModeControllerAsh::OnDidChangeFocus(views::View* focused_before, | 494 void ImmersiveModeControllerAsh::OnDidChangeFocus(views::View* focused_before, |
| 495 views::View* focused_now) { | 495 views::View* focused_now) { |
| 496 scoped_ptr<ImmersiveRevealedLock> lock; | |
| 497 if (reveal_state_ == REVEALED || reveal_state_ == SLIDING_OPEN) { | |
| 498 // Acquire a lock so that if UpdateLocatedEventRevealedLock() or | |
| 499 // UpdateFocusRevealedLock() ends the reveal, it occurs after the | |
| 500 // function terminates. This is useful in tests. | |
| 501 lock.reset(GetRevealedLock(ANIMATE_REVEAL_YES)); | |
| 502 } | |
| 503 | |
| 504 UpdateLocatedEventRevealedLock(NULL); | |
| 505 UpdateFocusRevealedLock(); | 496 UpdateFocusRevealedLock(); |
| 506 } | 497 } |
| 507 | 498 |
| 508 void ImmersiveModeControllerAsh::OnWidgetDestroying(views::Widget* widget) { | 499 void ImmersiveModeControllerAsh::OnWidgetDestroying(views::Widget* widget) { |
| 509 EnableWindowObservers(false); | 500 EnableWindowObservers(false); |
| 510 native_window_ = NULL; | 501 native_window_ = NULL; |
| 511 | 502 |
| 512 // Set |enabled_| to false such that any calls to MaybeStartReveal() and | 503 // Set |enabled_| to false such that any calls to MaybeStartReveal() and |
| 513 // MaybeEndReveal() have no effect. | 504 // MaybeEndReveal() have no effect. |
| 514 enabled_ = false; | 505 enabled_ = false; |
| 515 } | 506 } |
| 516 | 507 |
| 517 void ImmersiveModeControllerAsh::OnWidgetActivationChanged( | 508 void ImmersiveModeControllerAsh::OnWidgetActivationChanged( |
| 518 views::Widget* widget, | 509 views::Widget* widget, |
| 519 bool active) { | 510 bool active) { |
| 520 scoped_ptr<ImmersiveRevealedLock> lock; | |
| 521 if (reveal_state_ == REVEALED || reveal_state_ == SLIDING_OPEN) { | |
| 522 // Acquire a lock so that if UpdateLocatedEventRevealedLock() or | |
| 523 // UpdateFocusRevealedLock() ends the reveal, it occurs after the | |
| 524 // function terminates. This is useful in tests. | |
| 525 lock.reset(GetRevealedLock(ANIMATE_REVEAL_YES)); | |
| 526 } | |
| 527 | |
| 528 // Mouse hover should not initiate revealing the top-of-window views while | 511 // Mouse hover should not initiate revealing the top-of-window views while |
| 529 // |native_window_| is inactive. | 512 // |native_window_| is inactive. |
| 530 top_edge_hover_timer_.Stop(); | 513 top_edge_hover_timer_.Stop(); |
| 531 | 514 |
| 532 UpdateLocatedEventRevealedLock(NULL); | |
| 533 UpdateFocusRevealedLock(); | 515 UpdateFocusRevealedLock(); |
| 516 |
| 517 // Allow the top-of-window views to stay revealed if all of the revealed locks |
| 518 // were released in the process of activating |widget| but the mouse is still |
| 519 // hovered above the top-of-window views. For instance, if the bubble which |
| 520 // has been keeping the top-of-window views revealed is hidden but the mouse |
| 521 // is hovered above the top-of-window views, the top-of-window views should |
| 522 // stay revealed. We cannot call UpdateLocatedEventRevealedLock() from |
| 523 // BubbleManager::UpdateRevealedLock() because |widget| is not yet active |
| 524 // at that time. |
| 525 UpdateLocatedEventRevealedLock(NULL, ALLOW_REVEAL_WHILE_CLOSING_YES); |
| 534 } | 526 } |
| 535 | 527 |
| 536 //////////////////////////////////////////////////////////////////////////////// | 528 //////////////////////////////////////////////////////////////////////////////// |
| 537 // Animation delegate: | 529 // Animation delegate: |
| 538 | 530 |
| 539 void ImmersiveModeControllerAsh::AnimationEnded( | 531 void ImmersiveModeControllerAsh::AnimationEnded( |
| 540 const ui::Animation* animation) { | 532 const ui::Animation* animation) { |
| 541 if (reveal_state_ == SLIDING_OPEN) { | 533 if (reveal_state_ == SLIDING_OPEN) { |
| 542 // AnimationProgressed() is called immediately before AnimationEnded() | 534 // AnimationProgressed() is called immediately before AnimationEnded() |
| 543 // and does a layout. | 535 // and does a layout. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 if (force) | 608 if (force) |
| 617 tab_indicator_visibility_ = TAB_INDICATORS_FORCE_HIDE; | 609 tab_indicator_visibility_ = TAB_INDICATORS_FORCE_HIDE; |
| 618 else if (tab_indicator_visibility_ == TAB_INDICATORS_FORCE_HIDE) | 610 else if (tab_indicator_visibility_ == TAB_INDICATORS_FORCE_HIDE) |
| 619 tab_indicator_visibility_ = TAB_INDICATORS_HIDE; | 611 tab_indicator_visibility_ = TAB_INDICATORS_HIDE; |
| 620 UpdateUseMinimalChrome(LAYOUT_YES); | 612 UpdateUseMinimalChrome(LAYOUT_YES); |
| 621 } | 613 } |
| 622 | 614 |
| 623 void ImmersiveModeControllerAsh::StartRevealForTest(bool hovered) { | 615 void ImmersiveModeControllerAsh::StartRevealForTest(bool hovered) { |
| 624 MaybeStartReveal(ANIMATE_NO); | 616 MaybeStartReveal(ANIMATE_NO); |
| 625 MoveMouse(top_container_, hovered); | 617 MoveMouse(top_container_, hovered); |
| 626 UpdateLocatedEventRevealedLock(NULL); | 618 UpdateLocatedEventRevealedLock(NULL, ALLOW_REVEAL_WHILE_CLOSING_NO); |
| 627 } | 619 } |
| 628 | 620 |
| 629 void ImmersiveModeControllerAsh::SetMouseHoveredForTest(bool hovered) { | 621 void ImmersiveModeControllerAsh::SetMouseHoveredForTest(bool hovered) { |
| 630 MoveMouse(top_container_, hovered); | 622 MoveMouse(top_container_, hovered); |
| 631 UpdateLocatedEventRevealedLock(NULL); | 623 UpdateLocatedEventRevealedLock(NULL, ALLOW_REVEAL_WHILE_CLOSING_NO); |
| 632 } | 624 } |
| 633 | 625 |
| 634 void ImmersiveModeControllerAsh::DisableAnimationsForTest() { | 626 void ImmersiveModeControllerAsh::DisableAnimationsForTest() { |
| 635 animations_disabled_for_test_ = true; | 627 animations_disabled_for_test_ = true; |
| 636 } | 628 } |
| 637 | 629 |
| 638 //////////////////////////////////////////////////////////////////////////////// | 630 //////////////////////////////////////////////////////////////////////////////// |
| 639 // private: | 631 // private: |
| 640 | 632 |
| 641 void ImmersiveModeControllerAsh::EnableWindowObservers(bool enable) { | 633 void ImmersiveModeControllerAsh::EnableWindowObservers(bool enable) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 // Timer is stopped when |this| is destroyed, hence Unretained() is safe. | 731 // Timer is stopped when |this| is destroyed, hence Unretained() is safe. |
| 740 top_edge_hover_timer_.Start( | 732 top_edge_hover_timer_.Start( |
| 741 FROM_HERE, | 733 FROM_HERE, |
| 742 base::TimeDelta::FromMilliseconds( | 734 base::TimeDelta::FromMilliseconds( |
| 743 ImmersiveFullscreenConfiguration::immersive_mode_reveal_delay_ms()), | 735 ImmersiveFullscreenConfiguration::immersive_mode_reveal_delay_ms()), |
| 744 base::Bind(&ImmersiveModeControllerAsh::AcquireLocatedEventRevealedLock, | 736 base::Bind(&ImmersiveModeControllerAsh::AcquireLocatedEventRevealedLock, |
| 745 base::Unretained(this))); | 737 base::Unretained(this))); |
| 746 } | 738 } |
| 747 | 739 |
| 748 void ImmersiveModeControllerAsh::UpdateLocatedEventRevealedLock( | 740 void ImmersiveModeControllerAsh::UpdateLocatedEventRevealedLock( |
| 749 ui::LocatedEvent* event) { | 741 ui::LocatedEvent* event, |
| 742 AllowRevealWhileClosing allow_reveal_while_closing) { |
| 750 if (!enabled_) | 743 if (!enabled_) |
| 751 return; | 744 return; |
| 752 DCHECK(!event || event->IsMouseEvent() || event->IsTouchEvent()); | 745 DCHECK(!event || event->IsMouseEvent() || event->IsTouchEvent()); |
| 753 | 746 |
| 754 // Neither the mouse nor touch can initiate a reveal when the top-of-window | 747 // Neither the mouse nor touch can initiate a reveal when the top-of-window |
| 755 // views are sliding closed or are closed with the following exceptions: | 748 // views are sliding closed or are closed with the following exceptions: |
| 756 // - Hovering at y = 0 which is handled in OnMouseEvent(). | 749 // - Hovering at y = 0 which is handled in OnMouseEvent(). |
| 757 // - Doing a SWIPE_OPEN edge gesture which is handled in OnGestureEvent(). | 750 // - Doing a SWIPE_OPEN edge gesture which is handled in OnGestureEvent(). |
| 758 if (reveal_state_ == SLIDING_CLOSED || reveal_state_ == CLOSED) | 751 if (reveal_state_ == CLOSED || |
| 752 (reveal_state_ == SLIDING_CLOSED && |
| 753 allow_reveal_while_closing == ALLOW_REVEAL_WHILE_CLOSING_NO)) { |
| 759 return; | 754 return; |
| 755 } |
| 760 | 756 |
| 761 // Neither the mouse nor touch should keep the top-of-window views revealed if | 757 // Neither the mouse nor touch should keep the top-of-window views revealed if |
| 762 // |native_window_| is not active. | 758 // |native_window_| is not active. |
| 763 if (!views::Widget::GetWidgetForNativeWindow(native_window_)->IsActive()) { | 759 if (!views::Widget::GetWidgetForNativeWindow(native_window_)->IsActive()) { |
| 764 located_event_revealed_lock_.reset(); | 760 located_event_revealed_lock_.reset(); |
| 765 return; | 761 return; |
| 766 } | 762 } |
| 767 | 763 |
| 768 // Ignore all events while a window has capture. This keeps the top-of-window | 764 // Ignore all events while a window has capture. This keeps the top-of-window |
| 769 // views revealed during a drag. | 765 // views revealed during a drag. |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 if (swipe_type == SWIPE_CLOSE) { | 884 if (swipe_type == SWIPE_CLOSE) { |
| 889 // Attempt to end the reveal. If other code is holding onto a lock, the | 885 // Attempt to end the reveal. If other code is holding onto a lock, the |
| 890 // attempt will be unsuccessful. | 886 // attempt will be unsuccessful. |
| 891 located_event_revealed_lock_.reset(); | 887 located_event_revealed_lock_.reset(); |
| 892 focus_revealed_lock_.reset(); | 888 focus_revealed_lock_.reset(); |
| 893 | 889 |
| 894 if (reveal_state_ == SLIDING_CLOSED || reveal_state_ == CLOSED) | 890 if (reveal_state_ == SLIDING_CLOSED || reveal_state_ == CLOSED) |
| 895 return true; | 891 return true; |
| 896 | 892 |
| 897 // Ending the reveal was unsuccessful. Reaquire the locks if appropriate. | 893 // Ending the reveal was unsuccessful. Reaquire the locks if appropriate. |
| 898 UpdateLocatedEventRevealedLock(NULL); | 894 UpdateLocatedEventRevealedLock(NULL, ALLOW_REVEAL_WHILE_CLOSING_NO); |
| 899 UpdateFocusRevealedLock(); | 895 UpdateFocusRevealedLock(); |
| 900 } | 896 } |
| 901 } | 897 } |
| 902 return false; | 898 return false; |
| 903 } | 899 } |
| 904 | 900 |
| 905 void ImmersiveModeControllerAsh::UpdateUseMinimalChrome(Layout layout) { | 901 void ImmersiveModeControllerAsh::UpdateUseMinimalChrome(Layout layout) { |
| 906 // May be NULL in tests. | 902 // May be NULL in tests. |
| 907 FullscreenController* fullscreen_controller = | 903 FullscreenController* fullscreen_controller = |
| 908 delegate_->GetFullscreenController(); | 904 delegate_->GetFullscreenController(); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 | 1020 |
| 1025 void ImmersiveModeControllerAsh::OnSlideOpenAnimationCompleted(Layout layout) { | 1021 void ImmersiveModeControllerAsh::OnSlideOpenAnimationCompleted(Layout layout) { |
| 1026 DCHECK_EQ(SLIDING_OPEN, reveal_state_); | 1022 DCHECK_EQ(SLIDING_OPEN, reveal_state_); |
| 1027 reveal_state_ = REVEALED; | 1023 reveal_state_ = REVEALED; |
| 1028 | 1024 |
| 1029 if (layout == LAYOUT_YES) | 1025 if (layout == LAYOUT_YES) |
| 1030 top_container_->parent()->Layout(); | 1026 top_container_->parent()->Layout(); |
| 1031 | 1027 |
| 1032 // The user may not have moved the mouse since the reveal was initiated. | 1028 // The user may not have moved the mouse since the reveal was initiated. |
| 1033 // Update the revealed lock to reflect the mouse's current state. | 1029 // Update the revealed lock to reflect the mouse's current state. |
| 1034 UpdateLocatedEventRevealedLock(NULL); | 1030 UpdateLocatedEventRevealedLock(NULL, ALLOW_REVEAL_WHILE_CLOSING_NO); |
| 1035 } | 1031 } |
| 1036 | 1032 |
| 1037 void ImmersiveModeControllerAsh::MaybeEndReveal(Animate animate) { | 1033 void ImmersiveModeControllerAsh::MaybeEndReveal(Animate animate) { |
| 1038 if (!enabled_ || revealed_lock_count_ != 0) | 1034 if (!enabled_ || revealed_lock_count_ != 0) |
| 1039 return; | 1035 return; |
| 1040 | 1036 |
| 1041 if (animations_disabled_for_test_) | 1037 if (animations_disabled_for_test_) |
| 1042 animate = ANIMATE_NO; | 1038 animate = ANIMATE_NO; |
| 1043 | 1039 |
| 1044 // Callers with ANIMATE_NO expect this function to synchronously close the | 1040 // Callers with ANIMATE_NO expect this function to synchronously close the |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 aura::Window* transient_child = transient_children[i]; | 1169 aura::Window* transient_child = transient_children[i]; |
| 1174 views::BubbleDelegateView* bubble_delegate = | 1170 views::BubbleDelegateView* bubble_delegate = |
| 1175 AsBubbleDelegate(transient_child); | 1171 AsBubbleDelegate(transient_child); |
| 1176 if (bubble_delegate && | 1172 if (bubble_delegate && |
| 1177 bubble_delegate->anchor_view() && | 1173 bubble_delegate->anchor_view() && |
| 1178 top_container_->Contains(bubble_delegate->anchor_view())) { | 1174 top_container_->Contains(bubble_delegate->anchor_view())) { |
| 1179 bubble_manager_->StartObserving(transient_child); | 1175 bubble_manager_->StartObserving(transient_child); |
| 1180 } | 1176 } |
| 1181 } | 1177 } |
| 1182 } | 1178 } |
| OLD | NEW |