Chromium Code Reviews| Index: chrome/browser/ui/views/frame/immersive_mode_controller_ash.cc |
| diff --git a/chrome/browser/ui/views/frame/immersive_mode_controller_ash.cc b/chrome/browser/ui/views/frame/immersive_mode_controller_ash.cc |
| index 40f4c01aa769dfda99049b72bd9bb2891b1bfb01..9a2895e8a5fba26b808b8881781d76aa06118063 100644 |
| --- a/chrome/browser/ui/views/frame/immersive_mode_controller_ash.cc |
| +++ b/chrome/browser/ui/views/frame/immersive_mode_controller_ash.cc |
| @@ -8,10 +8,13 @@ |
| #include "ash/shell.h" |
| #include "ash/wm/window_properties.h" |
| #include "base/command_line.h" |
| +#include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
| #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" |
| #include "chrome/browser/ui/views/frame/browser_view.h" |
| #include "chrome/browser/ui/views/frame/top_container_view.h" |
| #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| +#include "chrome/common/chrome_notification_types.h" |
| +#include "content/public/browser/notification_service.h" |
| #include "ui/aura/client/activation_client.h" |
| #include "ui/aura/client/aura_constants.h" |
| #include "ui/aura/client/capture_client.h" |
| @@ -314,8 +317,15 @@ class ImmersiveModeControllerAsh::WindowObserver : public aura::WindowObserver { |
| } |
| using ash::internal::kImmersiveModeKey; |
| if (key == kImmersiveModeKey) { |
| - // Another component has toggled immersive mode. |
| - controller_->SetEnabled(window->GetProperty(kImmersiveModeKey)); |
| + bool should_enable = window->GetProperty(kImmersiveModeKey); |
|
James Cook
2013/04/22 18:14:16
Do we still need kImmersiveModeKey? I don't think
|
| + if (controller_->IsEnabled() != should_enable) { |
| + // The user may be in tab fullscreen when a client sets |
| + // kImmersiveModeKey. Entering browser / immersive fullscreen while the |
| + // user is already in tab fullscreen is unsupported. Crash if a client |
| + // uses kImmersiveModeKey to enter fullscreen. |
| + CHECK(!should_enable); |
| + controller_->browser_view_->ExitFullscreen(); |
| + } |
| return; |
| } |
| } |
| @@ -333,7 +343,7 @@ ImmersiveModeControllerAsh::ImmersiveModeControllerAsh() |
| enabled_(false), |
| reveal_state_(CLOSED), |
| revealed_lock_count_(0), |
| - hide_tab_indicators_(false), |
| + tab_indicator_visibility_(TAB_INDICATORS_SHOW), |
| native_window_(NULL), |
| weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| } |
| @@ -371,8 +381,10 @@ void ImmersiveModeControllerAsh::Init(BrowserView* browser_view) { |
| EnableWindowObservers(true); |
| // Optionally allow the tab indicators to be hidden. |
| - hide_tab_indicators_ = CommandLine::ForCurrentProcess()-> |
| - HasSwitch(ash::switches::kAshImmersiveHideTabIndicators); |
| + if (CommandLine::ForCurrentProcess()-> |
| + HasSwitch(ash::switches::kAshImmersiveHideTabIndicators)) { |
| + tab_indicator_visibility_ = TAB_INDICATORS_FORCE_HIDE; |
| + } |
| anchored_widget_manager_.reset(new AnchoredWidgetManager(this)); |
| } |
| @@ -421,11 +433,8 @@ void ImmersiveModeControllerAsh::SetEnabled(bool enabled) { |
| // This causes a no-op call to SetEnabled() since enabled_ is already set. |
| native_window_->SetProperty(ash::internal::kImmersiveModeKey, enabled_); |
| - // Ash on Windows may not have a shell. |
| - if (ash::Shell::HasInstance()) { |
| - // Shelf auto-hides in immersive mode. |
| - ash::Shell::GetInstance()->UpdateShelfVisibility(); |
| - } |
| + |
| + UpdateUseMinimalChrome(true); |
| } |
| bool ImmersiveModeControllerAsh::IsEnabled() const { |
| @@ -433,7 +442,7 @@ bool ImmersiveModeControllerAsh::IsEnabled() const { |
| } |
| bool ImmersiveModeControllerAsh::ShouldHideTabIndicators() const { |
| - return hide_tab_indicators_; |
| + return tab_indicator_visibility_ != TAB_INDICATORS_SHOW; |
| } |
| bool ImmersiveModeControllerAsh::ShouldHideTopViews() const { |
| @@ -475,6 +484,14 @@ void ImmersiveModeControllerAsh::OnTopContainerBoundsChanged() { |
| //////////////////////////////////////////////////////////////////////////////// |
| // Observers: |
| +void ImmersiveModeControllerAsh::Observe( |
| + int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); |
| + UpdateUseMinimalChrome(false); |
| +} |
| + |
| void ImmersiveModeControllerAsh::OnMouseEvent(ui::MouseEvent* event) { |
| if (!enabled_) |
| return; |
| @@ -558,8 +575,12 @@ void ImmersiveModeControllerAsh::OnImplicitAnimationsCompleted() { |
| //////////////////////////////////////////////////////////////////////////////// |
| // Testing interface: |
| -void ImmersiveModeControllerAsh::SetHideTabIndicatorsForTest(bool hide) { |
| - hide_tab_indicators_ = hide; |
| +void ImmersiveModeControllerAsh::SetForceHideTabIndicatorsForTest(bool force) { |
| + if (force) |
| + tab_indicator_visibility_ = TAB_INDICATORS_FORCE_HIDE; |
| + else if (tab_indicator_visibility_ == TAB_INDICATORS_FORCE_HIDE) |
| + tab_indicator_visibility_ = TAB_INDICATORS_HIDE; |
| + UpdateUseMinimalChrome(false); |
| } |
| void ImmersiveModeControllerAsh::StartRevealForTest(bool hovered) { |
| @@ -601,6 +622,20 @@ void ImmersiveModeControllerAsh::EnableWindowObservers(bool enable) { |
| // The window observer adds and removes itself from the native window. |
| window_observer_.reset(enable ? new WindowObserver(this) : NULL); |
| + if (enable) { |
| + registrar_.Add( |
| + this, |
| + chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
| + content::Source<FullscreenController>( |
| + browser_view_->browser()->fullscreen_controller())); |
| + } else { |
| + registrar_.Remove( |
| + this, |
| + chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
| + content::Source<FullscreenController>( |
| + browser_view_->browser()->fullscreen_controller())); |
| + } |
| + |
| if (!enable) |
| StopObservingImplicitAnimations(); |
| } |
| @@ -677,6 +712,37 @@ void ImmersiveModeControllerAsh::UpdateFocusRevealedLock() { |
| } |
| } |
| +void ImmersiveModeControllerAsh::UpdateUseMinimalChrome(bool skip_layout) { |
| + bool use_minimal_chrome = !browser_view_->browser()->fullscreen_controller()-> |
| + IsFullscreenForTabOrPending(); |
| + native_window_->SetProperty(ash::internal::kFullscreenUsesMinimalChromeKey, |
| + use_minimal_chrome); |
| + |
| + TabIndicatorVisibility previous_tab_indicator_visibility = |
| + tab_indicator_visibility_; |
| + if (tab_indicator_visibility_ != TAB_INDICATORS_FORCE_HIDE) { |
| + tab_indicator_visibility_ = use_minimal_chrome ? |
| + TAB_INDICATORS_SHOW : TAB_INDICATORS_HIDE; |
| + } |
| + |
| + if (!enabled_) |
| + return; |
| + |
| + // Ash on Windows may not have a shell. |
| + if (ash::Shell::HasInstance()) { |
| + // When using minimal chrome, the shelf is auto-hidden. The auto-hidden |
| + // shelf displays a 3px 'light bar' when it is closed. |
| + ash::Shell::GetInstance()->UpdateShelfVisibility(); |
| + } |
| + |
| + if (tab_indicator_visibility_ != previous_tab_indicator_visibility) { |
| + // If the top-of-window views are revealed or animating, the change will |
| + // take effect with the layout once the top-of-window views are closed. |
| + if (!skip_layout && reveal_state_ == CLOSED) |
| + LayoutBrowserView(true); |
| + } |
| +} |
| + |
| int ImmersiveModeControllerAsh::GetAnimationDuration(Animate animate) const { |
| switch (animate) { |
| case ANIMATE_NO: |