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 "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/wm/window_properties.h" | 9 #include "ash/wm/window_properties.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 231 |
232 void ImmersiveModeControllerAsh::AnchoredWidgetManager::UpdateRevealedLock() { | 232 void ImmersiveModeControllerAsh::AnchoredWidgetManager::UpdateRevealedLock() { |
233 if (visible_.empty()) { | 233 if (visible_.empty()) { |
234 revealed_lock_.reset(); | 234 revealed_lock_.reset(); |
235 } else if (controller_->IsRevealed()) { | 235 } else if (controller_->IsRevealed()) { |
236 // It is hard to determine the required initial transforms and the required | 236 // It is hard to determine the required initial transforms and the required |
237 // durations of the animations of |visible_| such that they appear to be | 237 // durations of the animations of |visible_| such that they appear to be |
238 // anchored to the top-of-window views while the top-of-window views are | 238 // anchored to the top-of-window views while the top-of-window views are |
239 // animating. Skip to the end of the reveal animation instead. | 239 // animating. Skip to the end of the reveal animation instead. |
240 // We do not query the controller's reveal state because we may be called | 240 // We do not query the controller's reveal state because we may be called |
241 // as a result of LayoutBrowserView() in MaybeStartReveal() when | 241 // as a result of LayoutBrowserRootView() in MaybeStartReveal() when |
242 // |reveal_state_| is SLIDING_OPEN but no animation is running yet. | 242 // |reveal_state_| is SLIDING_OPEN but no animation is running yet. |
243 ui::Layer* top_container_layer = | 243 ui::Layer* top_container_layer = |
244 controller_->browser_view_->top_container()->layer(); | 244 controller_->browser_view_->top_container()->layer(); |
245 if (top_container_layer && | 245 if (top_container_layer && |
246 top_container_layer->GetAnimator()->is_animating()) { | 246 top_container_layer->GetAnimator()->is_animating()) { |
247 controller_->MaybeRevealWithoutAnimation(); | 247 controller_->MaybeRevealWithoutAnimation(); |
248 } | 248 } |
249 | 249 |
250 if (!revealed_lock_.get()) { | 250 if (!revealed_lock_.get()) { |
251 revealed_lock_.reset(controller_->GetRevealedLock( | 251 revealed_lock_.reset(controller_->GetRevealedLock( |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 DCHECK(browser_view_) << "Must initialize before enabling"; | 412 DCHECK(browser_view_) << "Must initialize before enabling"; |
413 if (enabled_ == enabled) | 413 if (enabled_ == enabled) |
414 return; | 414 return; |
415 enabled_ = enabled; | 415 enabled_ = enabled; |
416 | 416 |
417 // Delay the initialization of the window observers till the first call to | 417 // Delay the initialization of the window observers till the first call to |
418 // SetEnabled(true) because FullscreenController is not yet initialized when | 418 // SetEnabled(true) because FullscreenController is not yet initialized when |
419 // Init() is called. | 419 // Init() is called. |
420 EnableWindowObservers(true); | 420 EnableWindowObservers(true); |
421 | 421 |
| 422 UpdateUseMinimalChrome(LAYOUT_NO); |
| 423 |
422 if (enabled_) { | 424 if (enabled_) { |
423 // Animate enabling immersive mode by sliding out the top-of-window views. | 425 // Animate enabling immersive mode by sliding out the top-of-window views. |
424 // No animation occurs if a lock is holding the top-of-window views open. | 426 // No animation occurs if a lock is holding the top-of-window views open. |
425 | 427 |
426 // Do a reveal to set the initial state for the animation. (And any | 428 // Do a reveal to set the initial state for the animation. (And any |
427 // required state in case the animation cannot run because of a lock holding | 429 // required state in case the animation cannot run because of a lock holding |
428 // the top-of-window views open.) | 430 // the top-of-window views open.) This call has the side effect of relaying |
| 431 // out |browser_view_|'s root view. |
429 MaybeStartReveal(ANIMATE_NO); | 432 MaybeStartReveal(ANIMATE_NO); |
430 | 433 |
431 // Reset the mouse and the focus revealed locks so that they do not affect | 434 // Reset the mouse and the focus revealed locks so that they do not affect |
432 // whether the top-of-window views are hidden. | 435 // whether the top-of-window views are hidden. |
433 mouse_revealed_lock_.reset(); | 436 mouse_revealed_lock_.reset(); |
434 focus_revealed_lock_.reset(); | 437 focus_revealed_lock_.reset(); |
435 | 438 |
436 // Try doing the animation. | 439 // Try doing the animation. |
437 MaybeEndReveal(ANIMATE_SLOW); | 440 MaybeEndReveal(ANIMATE_SLOW); |
438 | 441 |
439 if (reveal_state_ == REVEALED) { | 442 if (reveal_state_ == REVEALED) { |
440 // Reveal was unsuccessful. Reacquire the revealed locks if appropriate. | 443 // Reveal was unsuccessful. Reacquire the revealed locks if appropriate. |
441 UpdateMouseRevealedLock(true); | 444 UpdateMouseRevealedLock(true); |
442 UpdateFocusRevealedLock(); | 445 UpdateFocusRevealedLock(); |
443 } | 446 } |
444 anchored_widget_manager_->OnImmersiveModeEnabled(); | 447 anchored_widget_manager_->OnImmersiveModeEnabled(); |
445 } else { | 448 } else { |
446 // Stop cursor-at-top tracking. | 449 // Stop cursor-at-top tracking. |
447 top_timer_.Stop(); | 450 top_timer_.Stop(); |
448 // Snap immediately to the closed state. | 451 // Snap immediately to the closed state. |
449 reveal_state_ = CLOSED; | 452 reveal_state_ = CLOSED; |
450 EnablePaintToLayer(false); | 453 EnablePaintToLayer(false); |
451 browser_view_->GetWidget()->non_client_view()->frame_view()-> | |
452 ResetWindowControls(); | |
453 browser_view_->tabstrip()->SetImmersiveStyle(false); | 454 browser_view_->tabstrip()->SetImmersiveStyle(false); |
| 455 |
| 456 // Relayout the root view because disabling immersive fullscreen may have |
| 457 // changed the result of NonClientFrameView::GetBoundsForClientView(). |
| 458 LayoutBrowserRootView(); |
454 } | 459 } |
455 // Don't need explicit layout because we're inside a fullscreen transition | |
456 // and it blocks layout calls. | |
457 | |
458 UpdateUseMinimalChrome(LAYOUT_NO); | |
459 } | 460 } |
460 | 461 |
461 bool ImmersiveModeControllerAsh::IsEnabled() const { | 462 bool ImmersiveModeControllerAsh::IsEnabled() const { |
462 return enabled_; | 463 return enabled_; |
463 } | 464 } |
464 | 465 |
465 bool ImmersiveModeControllerAsh::ShouldHideTabIndicators() const { | 466 bool ImmersiveModeControllerAsh::ShouldHideTabIndicators() const { |
466 return tab_indicator_visibility_ != TAB_INDICATORS_SHOW; | 467 return tab_indicator_visibility_ != TAB_INDICATORS_SHOW; |
467 } | 468 } |
468 | 469 |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 if (ash::Shell::HasInstance()) { | 757 if (ash::Shell::HasInstance()) { |
757 // When using minimal chrome, the shelf is auto-hidden. The auto-hidden | 758 // When using minimal chrome, the shelf is auto-hidden. The auto-hidden |
758 // shelf displays a 3px 'light bar' when it is closed. | 759 // shelf displays a 3px 'light bar' when it is closed. |
759 ash::Shell::GetInstance()->UpdateShelfVisibility(); | 760 ash::Shell::GetInstance()->UpdateShelfVisibility(); |
760 } | 761 } |
761 | 762 |
762 if (tab_indicator_visibility_ != previous_tab_indicator_visibility) { | 763 if (tab_indicator_visibility_ != previous_tab_indicator_visibility) { |
763 // If the top-of-window views are revealed or animating, the change will | 764 // If the top-of-window views are revealed or animating, the change will |
764 // take effect with the layout once the top-of-window views are closed. | 765 // take effect with the layout once the top-of-window views are closed. |
765 if (layout == LAYOUT_YES && reveal_state_ == CLOSED) | 766 if (layout == LAYOUT_YES && reveal_state_ == CLOSED) |
766 LayoutBrowserView(true); | 767 LayoutBrowserRootView(); |
767 } | 768 } |
768 } | 769 } |
769 | 770 |
770 int ImmersiveModeControllerAsh::GetAnimationDuration(Animate animate) const { | 771 int ImmersiveModeControllerAsh::GetAnimationDuration(Animate animate) const { |
771 switch (animate) { | 772 switch (animate) { |
772 case ANIMATE_NO: | 773 case ANIMATE_NO: |
773 return 0; | 774 return 0; |
774 case ANIMATE_SLOW: | 775 case ANIMATE_SLOW: |
775 return kRevealSlowAnimationDurationMs; | 776 return kRevealSlowAnimationDurationMs; |
776 case ANIMATE_FAST: | 777 case ANIMATE_FAST: |
(...skipping 17 matching lines...) Expand all Loading... |
794 } | 795 } |
795 | 796 |
796 RevealState previous_reveal_state = reveal_state_; | 797 RevealState previous_reveal_state = reveal_state_; |
797 reveal_state_ = SLIDING_OPEN; | 798 reveal_state_ = SLIDING_OPEN; |
798 if (previous_reveal_state == CLOSED) { | 799 if (previous_reveal_state == CLOSED) { |
799 // Turn on layer painting so we can smoothly animate. | 800 // Turn on layer painting so we can smoothly animate. |
800 EnablePaintToLayer(true); | 801 EnablePaintToLayer(true); |
801 | 802 |
802 // Ensure window caption buttons are updated and the view bounds are | 803 // Ensure window caption buttons are updated and the view bounds are |
803 // computed at normal (non-immersive-style) size. | 804 // computed at normal (non-immersive-style) size. |
804 LayoutBrowserView(false); | 805 browser_view_->tabstrip()->SetImmersiveStyle(false); |
| 806 LayoutBrowserRootView(); |
805 | 807 |
806 // Do not do any more processing if LayoutBrowserView() changed | 808 // Do not do any more processing if LayoutBrowserView() changed |
807 // |reveal_state_|. | 809 // |reveal_state_|. |
808 if (reveal_state_ != SLIDING_OPEN) | 810 if (reveal_state_ != SLIDING_OPEN) |
809 return; | 811 return; |
810 | 812 |
811 if (animate != ANIMATE_NO) { | 813 if (animate != ANIMATE_NO) { |
812 // Now that we have a layer, move it to the initial offscreen position. | 814 // Now that we have a layer, move it to the initial offscreen position. |
813 ui::Layer* layer = browser_view_->top_container()->layer(); | 815 ui::Layer* layer = browser_view_->top_container()->layer(); |
814 gfx::Transform transform; | 816 gfx::Transform transform; |
(...skipping 25 matching lines...) Expand all Loading... |
840 // BrowserView::PaintChildren() always draws it last when it is visible. | 842 // BrowserView::PaintChildren() always draws it last when it is visible. |
841 BookmarkBarView* bookmark_bar = browser_view_->bookmark_bar(); | 843 BookmarkBarView* bookmark_bar = browser_view_->bookmark_bar(); |
842 if (!bookmark_bar) | 844 if (!bookmark_bar) |
843 return; | 845 return; |
844 if (enable && bookmark_bar->IsDetached()) | 846 if (enable && bookmark_bar->IsDetached()) |
845 bookmark_bar->SetPaintToLayer(true); | 847 bookmark_bar->SetPaintToLayer(true); |
846 else | 848 else |
847 bookmark_bar->SetPaintToLayer(false); | 849 bookmark_bar->SetPaintToLayer(false); |
848 } | 850 } |
849 | 851 |
850 void ImmersiveModeControllerAsh::LayoutBrowserView(bool immersive_style) { | 852 void ImmersiveModeControllerAsh::LayoutBrowserRootView() { |
851 // Update the window caption buttons. | 853 // Update the window caption buttons. |
852 browser_view_->GetWidget()->non_client_view()->frame_view()-> | 854 browser_view_->GetWidget()->non_client_view()->frame_view()-> |
853 ResetWindowControls(); | 855 ResetWindowControls(); |
854 browser_view_->tabstrip()->SetImmersiveStyle(immersive_style); | |
855 browser_view_->frame()->GetRootView()->Layout(); | 856 browser_view_->frame()->GetRootView()->Layout(); |
856 } | 857 } |
857 | 858 |
858 void ImmersiveModeControllerAsh::OnSlideOpenAnimationCompleted() { | 859 void ImmersiveModeControllerAsh::OnSlideOpenAnimationCompleted() { |
859 DCHECK_EQ(SLIDING_OPEN, reveal_state_); | 860 DCHECK_EQ(SLIDING_OPEN, reveal_state_); |
860 reveal_state_ = REVEALED; | 861 reveal_state_ = REVEALED; |
861 | 862 |
862 // The user may not have moved the mouse since the reveal was initiated. | 863 // The user may not have moved the mouse since the reveal was initiated. |
863 // Update the revealed lock to reflect the mouse's current state. | 864 // Update the revealed lock to reflect the mouse's current state. |
864 UpdateMouseRevealedLock(true); | 865 UpdateMouseRevealedLock(true); |
(...skipping 30 matching lines...) Expand all Loading... |
895 OnSlideClosedAnimationCompleted(); | 896 OnSlideClosedAnimationCompleted(); |
896 } | 897 } |
897 } | 898 } |
898 | 899 |
899 void ImmersiveModeControllerAsh::OnSlideClosedAnimationCompleted() { | 900 void ImmersiveModeControllerAsh::OnSlideClosedAnimationCompleted() { |
900 DCHECK_EQ(SLIDING_CLOSED, reveal_state_); | 901 DCHECK_EQ(SLIDING_CLOSED, reveal_state_); |
901 reveal_state_ = CLOSED; | 902 reveal_state_ = CLOSED; |
902 // Layers aren't needed after animation completes. | 903 // Layers aren't needed after animation completes. |
903 EnablePaintToLayer(false); | 904 EnablePaintToLayer(false); |
904 // Update tabstrip for closed state. | 905 // Update tabstrip for closed state. |
905 LayoutBrowserView(true); | 906 browser_view_->tabstrip()->SetImmersiveStyle(true); |
| 907 LayoutBrowserRootView(); |
906 } | 908 } |
907 | 909 |
908 void ImmersiveModeControllerAsh::DoAnimation( | 910 void ImmersiveModeControllerAsh::DoAnimation( |
909 const gfx::Transform& target_transform, | 911 const gfx::Transform& target_transform, |
910 int duration_ms) { | 912 int duration_ms) { |
911 StopObservingImplicitAnimations(); | 913 StopObservingImplicitAnimations(); |
912 DoLayerAnimation(browser_view_->top_container()->layer(), target_transform, | 914 DoLayerAnimation(browser_view_->top_container()->layer(), target_transform, |
913 duration_ms, this); | 915 duration_ms, this); |
914 | 916 |
915 typedef std::set<views::Widget*> WidgetSet; | 917 typedef std::set<views::Widget*> WidgetSet; |
(...skipping 20 matching lines...) Expand all Loading... |
936 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); | 938 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); |
937 settings.SetTweenType(ui::Tween::EASE_OUT); | 939 settings.SetTweenType(ui::Tween::EASE_OUT); |
938 settings.SetTransitionDuration( | 940 settings.SetTransitionDuration( |
939 base::TimeDelta::FromMilliseconds(duration_ms)); | 941 base::TimeDelta::FromMilliseconds(duration_ms)); |
940 settings.SetPreemptionStrategy( | 942 settings.SetPreemptionStrategy( |
941 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 943 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
942 if (observer) | 944 if (observer) |
943 settings.AddObserver(observer); | 945 settings.AddObserver(observer); |
944 layer->SetTransform(target_transform); | 946 layer->SetTransform(target_transform); |
945 } | 947 } |
OLD | NEW |