| 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" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/wm/window_properties.h" | 12 #include "ash/wm/window_state.h" |
| 13 #include "base/command_line.h" | |
| 14 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | 14 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
| 16 #include "chrome/browser/ui/immersive_fullscreen_configuration.h" | 15 #include "chrome/browser/ui/immersive_fullscreen_configuration.h" |
| 17 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" | 16 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" |
| 18 #include "chrome/browser/ui/views/frame/top_container_view.h" | 17 #include "chrome/browser/ui/views/frame/top_container_view.h" |
| 19 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 20 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 21 #include "content/public/browser/web_contents_view.h" | 20 #include "content/public/browser/web_contents_view.h" |
| 22 #include "ui/aura/client/activation_client.h" | 21 #include "ui/aura/client/activation_client.h" |
| 23 #include "ui/aura/client/aura_constants.h" | 22 #include "ui/aura/client/aura_constants.h" |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 //////////////////////////////////////////////////////////////////////////////// | 259 //////////////////////////////////////////////////////////////////////////////// |
| 261 | 260 |
| 262 ImmersiveModeControllerAsh::ImmersiveModeControllerAsh() | 261 ImmersiveModeControllerAsh::ImmersiveModeControllerAsh() |
| 263 : delegate_(NULL), | 262 : delegate_(NULL), |
| 264 widget_(NULL), | 263 widget_(NULL), |
| 265 top_container_(NULL), | 264 top_container_(NULL), |
| 266 observers_enabled_(false), | 265 observers_enabled_(false), |
| 267 enabled_(false), | 266 enabled_(false), |
| 268 reveal_state_(CLOSED), | 267 reveal_state_(CLOSED), |
| 269 revealed_lock_count_(0), | 268 revealed_lock_count_(0), |
| 270 tab_indicator_visibility_(TAB_INDICATORS_HIDE), | |
| 271 mouse_x_when_hit_top_in_screen_(-1), | 269 mouse_x_when_hit_top_in_screen_(-1), |
| 272 gesture_begun_(false), | 270 gesture_begun_(false), |
| 273 native_window_(NULL), | 271 native_window_(NULL), |
| 274 animation_(new gfx::SlideAnimation(this)), | 272 animation_(new gfx::SlideAnimation(this)), |
| 275 animations_disabled_for_test_(false), | 273 animations_disabled_for_test_(false), |
| 276 weak_ptr_factory_(this) { | 274 weak_ptr_factory_(this) { |
| 277 } | 275 } |
| 278 | 276 |
| 279 ImmersiveModeControllerAsh::~ImmersiveModeControllerAsh() { | 277 ImmersiveModeControllerAsh::~ImmersiveModeControllerAsh() { |
| 280 // The browser view is being destroyed so there's no need to update its | 278 // The browser view is being destroyed so there's no need to update its |
| (...skipping 27 matching lines...) Expand all Loading... |
| 308 void ImmersiveModeControllerAsh::Init( | 306 void ImmersiveModeControllerAsh::Init( |
| 309 Delegate* delegate, | 307 Delegate* delegate, |
| 310 views::Widget* widget, | 308 views::Widget* widget, |
| 311 views::View* top_container) { | 309 views::View* top_container) { |
| 312 delegate_ = delegate; | 310 delegate_ = delegate; |
| 313 widget_ = widget; | 311 widget_ = widget; |
| 314 // Browser view is detached from its widget during destruction. Cache the | 312 // Browser view is detached from its widget during destruction. Cache the |
| 315 // window pointer so |this| can stop observing during destruction. | 313 // window pointer so |this| can stop observing during destruction. |
| 316 native_window_ = widget_->GetNativeWindow(); | 314 native_window_ = widget_->GetNativeWindow(); |
| 317 top_container_ = top_container; | 315 top_container_ = top_container; |
| 318 | |
| 319 // Optionally allow the tab indicators to be hidden. | |
| 320 if (CommandLine::ForCurrentProcess()-> | |
| 321 HasSwitch(ash::switches::kAshImmersiveHideTabIndicators)) { | |
| 322 tab_indicator_visibility_ = TAB_INDICATORS_FORCE_HIDE; | |
| 323 } | |
| 324 } | 316 } |
| 325 | 317 |
| 326 void ImmersiveModeControllerAsh::SetEnabled(bool enabled) { | 318 void ImmersiveModeControllerAsh::SetEnabled(bool enabled) { |
| 327 DCHECK(native_window_) << "Must initialize before enabling"; | 319 DCHECK(native_window_) << "Must initialize before enabling"; |
| 328 if (enabled_ == enabled) | 320 if (enabled_ == enabled) |
| 329 return; | 321 return; |
| 330 enabled_ = enabled; | 322 enabled_ = enabled; |
| 331 | 323 |
| 332 EnableWindowObservers(enabled_); | 324 EnableWindowObservers(enabled_); |
| 333 | 325 |
| 334 UpdateUseMinimalChrome(LAYOUT_NO); | 326 if (enabled_) { |
| 327 UpdateUseMinimalChrome(LAYOUT_NO); |
| 335 | 328 |
| 336 if (enabled_) { | |
| 337 // Animate enabling immersive mode by sliding out the top-of-window views. | 329 // Animate enabling immersive mode by sliding out the top-of-window views. |
| 338 // No animation occurs if a lock is holding the top-of-window views open. | 330 // No animation occurs if a lock is holding the top-of-window views open. |
| 339 | 331 |
| 340 // Do a reveal to set the initial state for the animation. (And any | 332 // Do a reveal to set the initial state for the animation. (And any |
| 341 // required state in case the animation cannot run because of a lock holding | 333 // required state in case the animation cannot run because of a lock holding |
| 342 // the top-of-window views open.) This call has the side effect of relaying | 334 // the top-of-window views open.) This call has the side effect of relaying |
| 343 // out |browser_view_|'s root view. | 335 // out |browser_view_|'s root view. |
| 344 MaybeStartReveal(ANIMATE_NO); | 336 MaybeStartReveal(ANIMATE_NO); |
| 345 | 337 |
| 346 // Reset the located event and the focus revealed locks so that they do not | 338 // Reset the located event and the focus revealed locks so that they do not |
| (...skipping 22 matching lines...) Expand all Loading... |
| 369 // out. | 361 // out. |
| 370 LayoutBrowserRootView(); | 362 LayoutBrowserRootView(); |
| 371 } | 363 } |
| 372 } | 364 } |
| 373 | 365 |
| 374 bool ImmersiveModeControllerAsh::IsEnabled() const { | 366 bool ImmersiveModeControllerAsh::IsEnabled() const { |
| 375 return enabled_; | 367 return enabled_; |
| 376 } | 368 } |
| 377 | 369 |
| 378 bool ImmersiveModeControllerAsh::ShouldHideTabIndicators() const { | 370 bool ImmersiveModeControllerAsh::ShouldHideTabIndicators() const { |
| 379 return tab_indicator_visibility_ != TAB_INDICATORS_SHOW; | 371 return ash::wm::GetWindowState(native_window_)->fullscreen_type() != |
| 372 ash::wm::FULLSCREEN_TYPE_IMMERSIVE_MINIMAL_CHROME; |
| 380 } | 373 } |
| 381 | 374 |
| 382 bool ImmersiveModeControllerAsh::ShouldHideTopViews() const { | 375 bool ImmersiveModeControllerAsh::ShouldHideTopViews() const { |
| 383 return enabled_ && reveal_state_ == CLOSED; | 376 return enabled_ && reveal_state_ == CLOSED; |
| 384 } | 377 } |
| 385 | 378 |
| 386 bool ImmersiveModeControllerAsh::IsRevealed() const { | 379 bool ImmersiveModeControllerAsh::IsRevealed() const { |
| 387 return enabled_ && reveal_state_ != CLOSED; | 380 return enabled_ && reveal_state_ != CLOSED; |
| 388 } | 381 } |
| 389 | 382 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 | 590 |
| 598 void ImmersiveModeControllerAsh::OnRemoveTransientChild( | 591 void ImmersiveModeControllerAsh::OnRemoveTransientChild( |
| 599 aura::Window* window, | 592 aura::Window* window, |
| 600 aura::Window* transient) { | 593 aura::Window* transient) { |
| 601 bubble_manager_->StopObserving(transient); | 594 bubble_manager_->StopObserving(transient); |
| 602 } | 595 } |
| 603 | 596 |
| 604 //////////////////////////////////////////////////////////////////////////////// | 597 //////////////////////////////////////////////////////////////////////////////// |
| 605 // Testing interface: | 598 // Testing interface: |
| 606 | 599 |
| 607 void ImmersiveModeControllerAsh::SetForceHideTabIndicatorsForTest(bool force) { | |
| 608 if (force) | |
| 609 tab_indicator_visibility_ = TAB_INDICATORS_FORCE_HIDE; | |
| 610 else if (tab_indicator_visibility_ == TAB_INDICATORS_FORCE_HIDE) | |
| 611 tab_indicator_visibility_ = TAB_INDICATORS_HIDE; | |
| 612 UpdateUseMinimalChrome(LAYOUT_YES); | |
| 613 } | |
| 614 | |
| 615 void ImmersiveModeControllerAsh::StartRevealForTest(bool hovered) { | 600 void ImmersiveModeControllerAsh::StartRevealForTest(bool hovered) { |
| 616 MaybeStartReveal(ANIMATE_NO); | 601 MaybeStartReveal(ANIMATE_NO); |
| 617 MoveMouse(top_container_, hovered); | 602 MoveMouse(top_container_, hovered); |
| 618 UpdateLocatedEventRevealedLock(NULL, ALLOW_REVEAL_WHILE_CLOSING_NO); | 603 UpdateLocatedEventRevealedLock(NULL, ALLOW_REVEAL_WHILE_CLOSING_NO); |
| 619 } | 604 } |
| 620 | 605 |
| 621 void ImmersiveModeControllerAsh::SetMouseHoveredForTest(bool hovered) { | 606 void ImmersiveModeControllerAsh::SetMouseHoveredForTest(bool hovered) { |
| 622 MoveMouse(top_container_, hovered); | 607 MoveMouse(top_container_, hovered); |
| 623 UpdateLocatedEventRevealedLock(NULL, ALLOW_REVEAL_WHILE_CLOSING_NO); | 608 UpdateLocatedEventRevealedLock(NULL, ALLOW_REVEAL_WHILE_CLOSING_NO); |
| 624 } | 609 } |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 | 880 |
| 896 // Ending the reveal was unsuccessful. Reaquire the locks if appropriate. | 881 // Ending the reveal was unsuccessful. Reaquire the locks if appropriate. |
| 897 UpdateLocatedEventRevealedLock(NULL, ALLOW_REVEAL_WHILE_CLOSING_NO); | 882 UpdateLocatedEventRevealedLock(NULL, ALLOW_REVEAL_WHILE_CLOSING_NO); |
| 898 UpdateFocusRevealedLock(); | 883 UpdateFocusRevealedLock(); |
| 899 } | 884 } |
| 900 } | 885 } |
| 901 return false; | 886 return false; |
| 902 } | 887 } |
| 903 | 888 |
| 904 void ImmersiveModeControllerAsh::UpdateUseMinimalChrome(Layout layout) { | 889 void ImmersiveModeControllerAsh::UpdateUseMinimalChrome(Layout layout) { |
| 890 if (!enabled_) |
| 891 return; |
| 892 |
| 893 ash::wm::FullscreenType previous_fullscreen_type = |
| 894 ash::wm::GetWindowState(native_window_)->fullscreen_type(); |
| 895 |
| 905 // May be NULL in tests. | 896 // May be NULL in tests. |
| 906 FullscreenController* fullscreen_controller = | 897 FullscreenController* fullscreen_controller = |
| 907 delegate_->GetFullscreenController(); | 898 delegate_->GetFullscreenController(); |
| 908 bool in_tab_fullscreen = fullscreen_controller ? | 899 bool in_tab_fullscreen = fullscreen_controller ? |
| 909 fullscreen_controller->IsFullscreenForTabOrPending() : false; | 900 fullscreen_controller->IsFullscreenForTabOrPending() : false; |
| 910 bool use_minimal_chrome = !in_tab_fullscreen && enabled_; | 901 ash::wm::FullscreenType fullscreen_type = in_tab_fullscreen ? |
| 911 native_window_->SetProperty(ash::internal::kFullscreenUsesMinimalChromeKey, | 902 ash::wm::FULLSCREEN_TYPE_IMMERSIVE_NO_CHROME : |
| 912 use_minimal_chrome); | 903 ash::wm::FULLSCREEN_TYPE_IMMERSIVE_MINIMAL_CHROME; |
| 913 | 904 |
| 914 TabIndicatorVisibility previous_tab_indicator_visibility = | 905 if (fullscreen_type == previous_fullscreen_type) |
| 915 tab_indicator_visibility_; | 906 return; |
| 916 if (tab_indicator_visibility_ != TAB_INDICATORS_FORCE_HIDE) { | 907 ash::wm::GetWindowState(native_window_)->SetFullscreenType(fullscreen_type); |
| 917 tab_indicator_visibility_ = use_minimal_chrome ? | |
| 918 TAB_INDICATORS_SHOW : TAB_INDICATORS_HIDE; | |
| 919 } | |
| 920 | 908 |
| 921 // Ash on Windows may not have a shell. | 909 // Ash on Windows may not have a shell. |
| 922 if (ash::Shell::HasInstance()) { | 910 if (ash::Shell::HasInstance()) { |
| 923 // When using minimal chrome, the shelf is auto-hidden. The auto-hidden | 911 // When using minimal chrome, the shelf is auto-hidden. The auto-hidden |
| 924 // shelf displays a 3px 'light bar' when it is closed. | 912 // shelf displays a 3px 'light bar' when it is closed. |
| 925 ash::Shell::GetInstance()->UpdateShelfVisibility(); | 913 ash::Shell::GetInstance()->UpdateShelfVisibility(); |
| 926 } | 914 } |
| 927 | 915 |
| 928 if (tab_indicator_visibility_ != previous_tab_indicator_visibility) { | 916 // If the top-of-window views are revealed or animating, the change will take |
| 929 // If the top-of-window views are revealed or animating, the change will | 917 // effect with the layout once the top-of-window views are closed. |
| 930 // take effect with the layout once the top-of-window views are closed. | 918 if (layout == LAYOUT_YES && reveal_state_ == CLOSED) |
| 931 if (layout == LAYOUT_YES && reveal_state_ == CLOSED) | 919 LayoutBrowserRootView(); |
| 932 LayoutBrowserRootView(); | |
| 933 } | |
| 934 } | 920 } |
| 935 | 921 |
| 936 int ImmersiveModeControllerAsh::GetAnimationDuration(Animate animate) const { | 922 int ImmersiveModeControllerAsh::GetAnimationDuration(Animate animate) const { |
| 937 switch (animate) { | 923 switch (animate) { |
| 938 case ANIMATE_NO: | 924 case ANIMATE_NO: |
| 939 return 0; | 925 return 0; |
| 940 case ANIMATE_SLOW: | 926 case ANIMATE_SLOW: |
| 941 return kRevealSlowAnimationDurationMs; | 927 return kRevealSlowAnimationDurationMs; |
| 942 case ANIMATE_FAST: | 928 case ANIMATE_FAST: |
| 943 return kRevealFastAnimationDurationMs; | 929 return kRevealFastAnimationDurationMs; |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 aura::Window* transient_child = transient_children[i]; | 1135 aura::Window* transient_child = transient_children[i]; |
| 1150 views::BubbleDelegateView* bubble_delegate = | 1136 views::BubbleDelegateView* bubble_delegate = |
| 1151 AsBubbleDelegate(transient_child); | 1137 AsBubbleDelegate(transient_child); |
| 1152 if (bubble_delegate && | 1138 if (bubble_delegate && |
| 1153 bubble_delegate->GetAnchorView() && | 1139 bubble_delegate->GetAnchorView() && |
| 1154 top_container_->Contains(bubble_delegate->GetAnchorView())) { | 1140 top_container_->Contains(bubble_delegate->GetAnchorView())) { |
| 1155 bubble_manager_->StartObserving(transient_child); | 1141 bubble_manager_->StartObserving(transient_child); |
| 1156 } | 1142 } |
| 1157 } | 1143 } |
| 1158 } | 1144 } |
| OLD | NEW |