Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1520)

Side by Side Diff: chrome/browser/ui/views/frame/immersive_mode_controller_ash.cc

Issue 14340007: Hide the tab indicators and the shelf when in immersive + tab fullscreen (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed kImmersiveModeKey Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
11 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" 12 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
12 #include "chrome/browser/ui/views/frame/browser_view.h" 13 #include "chrome/browser/ui/views/frame/browser_view.h"
13 #include "chrome/browser/ui/views/frame/top_container_view.h" 14 #include "chrome/browser/ui/views/frame/top_container_view.h"
14 #include "chrome/browser/ui/views/tabs/tab_strip.h" 15 #include "chrome/browser/ui/views/tabs/tab_strip.h"
16 #include "chrome/common/chrome_notification_types.h"
17 #include "content/public/browser/notification_service.h"
15 #include "ui/aura/client/activation_client.h" 18 #include "ui/aura/client/activation_client.h"
16 #include "ui/aura/client/aura_constants.h" 19 #include "ui/aura/client/aura_constants.h"
17 #include "ui/aura/client/capture_client.h" 20 #include "ui/aura/client/capture_client.h"
18 #include "ui/aura/env.h" 21 #include "ui/aura/env.h"
19 #include "ui/aura/window.h" 22 #include "ui/aura/window.h"
20 #include "ui/aura/window_observer.h" 23 #include "ui/aura/window_observer.h"
21 #include "ui/compositor/layer_animation_observer.h" 24 #include "ui/compositor/layer_animation_observer.h"
22 #include "ui/compositor/scoped_layer_animation_settings.h" 25 #include "ui/compositor/scoped_layer_animation_settings.h"
23 #include "ui/gfx/screen.h" 26 #include "ui/gfx/screen.h"
24 #include "ui/gfx/transform.h" 27 #include "ui/gfx/transform.h"
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 // Disable immersive mode when leaving the fullscreen state. 308 // Disable immersive mode when leaving the fullscreen state.
306 ui::WindowShowState show_state = static_cast<ui::WindowShowState>( 309 ui::WindowShowState show_state = static_cast<ui::WindowShowState>(
307 window->GetProperty(kShowStateKey)); 310 window->GetProperty(kShowStateKey));
308 if (controller_->IsEnabled() && 311 if (controller_->IsEnabled() &&
309 show_state != ui::SHOW_STATE_FULLSCREEN && 312 show_state != ui::SHOW_STATE_FULLSCREEN &&
310 show_state != ui::SHOW_STATE_MINIMIZED) { 313 show_state != ui::SHOW_STATE_MINIMIZED) {
311 controller_->browser_view_->FullScreenStateChanged(); 314 controller_->browser_view_->FullScreenStateChanged();
312 } 315 }
313 return; 316 return;
314 } 317 }
315 using ash::internal::kImmersiveModeKey;
316 if (key == kImmersiveModeKey) {
317 // Another component has toggled immersive mode.
318 controller_->SetEnabled(window->GetProperty(kImmersiveModeKey));
319 return;
320 }
321 } 318 }
322 319
323 private: 320 private:
324 ImmersiveModeControllerAsh* controller_; // Not owned. 321 ImmersiveModeControllerAsh* controller_; // Not owned.
325 322
326 DISALLOW_COPY_AND_ASSIGN(WindowObserver); 323 DISALLOW_COPY_AND_ASSIGN(WindowObserver);
327 }; 324 };
328 325
329 //////////////////////////////////////////////////////////////////////////////// 326 ////////////////////////////////////////////////////////////////////////////////
330 327
331 ImmersiveModeControllerAsh::ImmersiveModeControllerAsh() 328 ImmersiveModeControllerAsh::ImmersiveModeControllerAsh()
332 : browser_view_(NULL), 329 : browser_view_(NULL),
333 enabled_(false), 330 enabled_(false),
334 reveal_state_(CLOSED), 331 reveal_state_(CLOSED),
335 revealed_lock_count_(0), 332 revealed_lock_count_(0),
336 hide_tab_indicators_(false), 333 tab_indicator_visibility_(TAB_INDICATORS_HIDE),
337 native_window_(NULL), 334 native_window_(NULL),
338 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 335 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
339 } 336 }
340 337
341 ImmersiveModeControllerAsh::~ImmersiveModeControllerAsh() { 338 ImmersiveModeControllerAsh::~ImmersiveModeControllerAsh() {
342 // The browser view is being destroyed so there's no need to update its 339 // The browser view is being destroyed so there's no need to update its
343 // layout or layers, even if the top views are revealed. But the window 340 // layout or layers, even if the top views are revealed. But the window
344 // observers still need to be removed. 341 // observers still need to be removed.
345 EnableWindowObservers(false); 342 EnableWindowObservers(false);
346 } 343 }
(...skipping 17 matching lines...) Expand all
364 361
365 void ImmersiveModeControllerAsh::Init(BrowserView* browser_view) { 362 void ImmersiveModeControllerAsh::Init(BrowserView* browser_view) {
366 browser_view_ = browser_view; 363 browser_view_ = browser_view;
367 // Browser view is detached from its widget during destruction. Cache the 364 // Browser view is detached from its widget during destruction. Cache the
368 // window pointer so |this| can stop observing during destruction. 365 // window pointer so |this| can stop observing during destruction.
369 native_window_ = browser_view_->GetNativeWindow(); 366 native_window_ = browser_view_->GetNativeWindow();
370 DCHECK(native_window_); 367 DCHECK(native_window_);
371 EnableWindowObservers(true); 368 EnableWindowObservers(true);
372 369
373 // Optionally allow the tab indicators to be hidden. 370 // Optionally allow the tab indicators to be hidden.
374 hide_tab_indicators_ = CommandLine::ForCurrentProcess()-> 371 if (CommandLine::ForCurrentProcess()->
375 HasSwitch(ash::switches::kAshImmersiveHideTabIndicators); 372 HasSwitch(ash::switches::kAshImmersiveHideTabIndicators)) {
373 tab_indicator_visibility_ = TAB_INDICATORS_FORCE_HIDE;
374 }
376 375
377 anchored_widget_manager_.reset(new AnchoredWidgetManager(this)); 376 anchored_widget_manager_.reset(new AnchoredWidgetManager(this));
378 } 377 }
379 378
380 void ImmersiveModeControllerAsh::SetEnabled(bool enabled) { 379 void ImmersiveModeControllerAsh::SetEnabled(bool enabled) {
381 DCHECK(browser_view_) << "Must initialize before enabling"; 380 DCHECK(browser_view_) << "Must initialize before enabling";
382 if (enabled_ == enabled) 381 if (enabled_ == enabled)
383 return; 382 return;
384 enabled_ = enabled; 383 enabled_ = enabled;
385 384
(...skipping 26 matching lines...) Expand all
412 // Snap immediately to the closed state. 411 // Snap immediately to the closed state.
413 reveal_state_ = CLOSED; 412 reveal_state_ = CLOSED;
414 EnablePaintToLayer(false); 413 EnablePaintToLayer(false);
415 browser_view_->GetWidget()->non_client_view()->frame_view()-> 414 browser_view_->GetWidget()->non_client_view()->frame_view()->
416 ResetWindowControls(); 415 ResetWindowControls();
417 browser_view_->tabstrip()->SetImmersiveStyle(false); 416 browser_view_->tabstrip()->SetImmersiveStyle(false);
418 } 417 }
419 // Don't need explicit layout because we're inside a fullscreen transition 418 // Don't need explicit layout because we're inside a fullscreen transition
420 // and it blocks layout calls. 419 // and it blocks layout calls.
421 420
422 // This causes a no-op call to SetEnabled() since enabled_ is already set. 421 UpdateUseMinimalChrome(LAYOUT_NO);
423 native_window_->SetProperty(ash::internal::kImmersiveModeKey, enabled_);
424 // Ash on Windows may not have a shell.
425 if (ash::Shell::HasInstance()) {
426 // Shelf auto-hides in immersive mode.
427 ash::Shell::GetInstance()->UpdateShelfVisibility();
428 }
429 } 422 }
430 423
431 bool ImmersiveModeControllerAsh::IsEnabled() const { 424 bool ImmersiveModeControllerAsh::IsEnabled() const {
432 return enabled_; 425 return enabled_;
433 } 426 }
434 427
435 bool ImmersiveModeControllerAsh::ShouldHideTabIndicators() const { 428 bool ImmersiveModeControllerAsh::ShouldHideTabIndicators() const {
436 return hide_tab_indicators_; 429 return tab_indicator_visibility_ != TAB_INDICATORS_SHOW;
437 } 430 }
438 431
439 bool ImmersiveModeControllerAsh::ShouldHideTopViews() const { 432 bool ImmersiveModeControllerAsh::ShouldHideTopViews() const {
440 return enabled_ && reveal_state_ == CLOSED; 433 return enabled_ && reveal_state_ == CLOSED;
441 } 434 }
442 435
443 bool ImmersiveModeControllerAsh::IsRevealed() const { 436 bool ImmersiveModeControllerAsh::IsRevealed() const {
444 return enabled_ && reveal_state_ != CLOSED; 437 return enabled_ && reveal_state_ != CLOSED;
445 } 438 }
446 439
(...skipping 21 matching lines...) Expand all
468 anchored_widget_manager_->RemoveAnchoredWidget(widget); 461 anchored_widget_manager_->RemoveAnchoredWidget(widget);
469 } 462 }
470 463
471 void ImmersiveModeControllerAsh::OnTopContainerBoundsChanged() { 464 void ImmersiveModeControllerAsh::OnTopContainerBoundsChanged() {
472 anchored_widget_manager_->MaybeRepositionAnchoredWidgets(); 465 anchored_widget_manager_->MaybeRepositionAnchoredWidgets();
473 } 466 }
474 467
475 //////////////////////////////////////////////////////////////////////////////// 468 ////////////////////////////////////////////////////////////////////////////////
476 // Observers: 469 // Observers:
477 470
471 void ImmersiveModeControllerAsh::Observe(
472 int type,
473 const content::NotificationSource& source,
474 const content::NotificationDetails& details) {
475 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type);
476 if (enabled_)
477 UpdateUseMinimalChrome(LAYOUT_YES);
478 }
479
478 void ImmersiveModeControllerAsh::OnMouseEvent(ui::MouseEvent* event) { 480 void ImmersiveModeControllerAsh::OnMouseEvent(ui::MouseEvent* event) {
479 if (!enabled_) 481 if (!enabled_)
480 return; 482 return;
481 483
482 if (event->flags() & ui::EF_IS_SYNTHESIZED) 484 if (event->flags() & ui::EF_IS_SYNTHESIZED)
483 return; 485 return;
484 486
485 // Handle ET_MOUSE_PRESSED and ET_MOUSE_RELEASED so that we get the updated 487 // Handle ET_MOUSE_PRESSED and ET_MOUSE_RELEASED so that we get the updated
486 // mouse position ASAP once a nested message loop finishes running. 488 // mouse position ASAP once a nested message loop finishes running.
487 if (event->type() != ui::ET_MOUSE_MOVED && 489 if (event->type() != ui::ET_MOUSE_MOVED &&
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 void ImmersiveModeControllerAsh::OnImplicitAnimationsCompleted() { 553 void ImmersiveModeControllerAsh::OnImplicitAnimationsCompleted() {
552 if (reveal_state_ == SLIDING_OPEN) 554 if (reveal_state_ == SLIDING_OPEN)
553 OnSlideOpenAnimationCompleted(); 555 OnSlideOpenAnimationCompleted();
554 else if (reveal_state_ == SLIDING_CLOSED) 556 else if (reveal_state_ == SLIDING_CLOSED)
555 OnSlideClosedAnimationCompleted(); 557 OnSlideClosedAnimationCompleted();
556 } 558 }
557 559
558 //////////////////////////////////////////////////////////////////////////////// 560 ////////////////////////////////////////////////////////////////////////////////
559 // Testing interface: 561 // Testing interface:
560 562
561 void ImmersiveModeControllerAsh::SetHideTabIndicatorsForTest(bool hide) { 563 void ImmersiveModeControllerAsh::SetForceHideTabIndicatorsForTest(bool force) {
562 hide_tab_indicators_ = hide; 564 if (force)
565 tab_indicator_visibility_ = TAB_INDICATORS_FORCE_HIDE;
566 else if (tab_indicator_visibility_ == TAB_INDICATORS_FORCE_HIDE)
567 tab_indicator_visibility_ = TAB_INDICATORS_HIDE;
568 UpdateUseMinimalChrome(LAYOUT_YES);
563 } 569 }
564 570
565 void ImmersiveModeControllerAsh::StartRevealForTest(bool hovered) { 571 void ImmersiveModeControllerAsh::StartRevealForTest(bool hovered) {
566 MaybeStartReveal(ANIMATE_NO); 572 MaybeStartReveal(ANIMATE_NO);
567 MoveMouse(browser_view_->top_container(), hovered); 573 MoveMouse(browser_view_->top_container(), hovered);
568 UpdateMouseRevealedLock(false); 574 UpdateMouseRevealedLock(false);
569 } 575 }
570 576
571 void ImmersiveModeControllerAsh::SetMouseHoveredForTest(bool hovered) { 577 void ImmersiveModeControllerAsh::SetMouseHoveredForTest(bool hovered) {
572 MoveMouse(browser_view_->top_container(), hovered); 578 MoveMouse(browser_view_->top_container(), hovered);
(...skipping 21 matching lines...) Expand all
594 } 600 }
595 601
596 if (enable) 602 if (enable)
597 native_window_->AddPreTargetHandler(this); 603 native_window_->AddPreTargetHandler(this);
598 else 604 else
599 native_window_->RemovePreTargetHandler(this); 605 native_window_->RemovePreTargetHandler(this);
600 606
601 // The window observer adds and removes itself from the native window. 607 // The window observer adds and removes itself from the native window.
602 window_observer_.reset(enable ? new WindowObserver(this) : NULL); 608 window_observer_.reset(enable ? new WindowObserver(this) : NULL);
603 609
610 if (enable) {
611 registrar_.Add(
612 this,
613 chrome::NOTIFICATION_FULLSCREEN_CHANGED,
614 content::Source<FullscreenController>(
615 browser_view_->browser()->fullscreen_controller()));
616 } else {
617 registrar_.Remove(
618 this,
619 chrome::NOTIFICATION_FULLSCREEN_CHANGED,
620 content::Source<FullscreenController>(
621 browser_view_->browser()->fullscreen_controller()));
622 }
623
604 if (!enable) 624 if (!enable)
605 StopObservingImplicitAnimations(); 625 StopObservingImplicitAnimations();
606 } 626 }
607 627
608 void ImmersiveModeControllerAsh::UpdateMouseRevealedLock(bool maybe_drag) { 628 void ImmersiveModeControllerAsh::UpdateMouseRevealedLock(bool maybe_drag) {
609 if (!enabled_) 629 if (!enabled_)
610 return; 630 return;
611 631
612 // Hover cannot initiate a reveal when the top-of-window views are sliding 632 // Hover cannot initiate a reveal when the top-of-window views are sliding
613 // closed or are closed. (With the exception of hovering at y = 0 which is 633 // closed or are closed. (With the exception of hovering at y = 0 which is
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 } 690 }
671 691
672 if (hold_lock) { 692 if (hold_lock) {
673 if (!focus_revealed_lock_.get()) 693 if (!focus_revealed_lock_.get())
674 focus_revealed_lock_.reset(GetRevealedLock()); 694 focus_revealed_lock_.reset(GetRevealedLock());
675 } else { 695 } else {
676 focus_revealed_lock_.reset(); 696 focus_revealed_lock_.reset();
677 } 697 }
678 } 698 }
679 699
700 void ImmersiveModeControllerAsh::UpdateUseMinimalChrome(Layout layout) {
701 bool in_tab_fullscreen = browser_view_->browser()->fullscreen_controller()->
702 IsFullscreenForTabOrPending();
703 bool use_minimal_chrome = !in_tab_fullscreen && enabled_;
704 native_window_->SetProperty(ash::internal::kFullscreenUsesMinimalChromeKey,
705 use_minimal_chrome);
706
707 TabIndicatorVisibility previous_tab_indicator_visibility =
708 tab_indicator_visibility_;
709 if (tab_indicator_visibility_ != TAB_INDICATORS_FORCE_HIDE) {
710 tab_indicator_visibility_ = use_minimal_chrome ?
711 TAB_INDICATORS_SHOW : TAB_INDICATORS_HIDE;
712 }
713
714 // Ash on Windows may not have a shell.
715 if (ash::Shell::HasInstance()) {
716 // When using minimal chrome, the shelf is auto-hidden. The auto-hidden
717 // shelf displays a 3px 'light bar' when it is closed.
718 ash::Shell::GetInstance()->UpdateShelfVisibility();
719 }
720
721 if (tab_indicator_visibility_ != previous_tab_indicator_visibility) {
722 // If the top-of-window views are revealed or animating, the change will
723 // take effect with the layout once the top-of-window views are closed.
724 if (layout == LAYOUT_YES && reveal_state_ == CLOSED)
725 LayoutBrowserView(true);
726 }
727 }
728
680 int ImmersiveModeControllerAsh::GetAnimationDuration(Animate animate) const { 729 int ImmersiveModeControllerAsh::GetAnimationDuration(Animate animate) const {
681 switch (animate) { 730 switch (animate) {
682 case ANIMATE_NO: 731 case ANIMATE_NO:
683 return 0; 732 return 0;
684 case ANIMATE_SLOW: 733 case ANIMATE_SLOW:
685 return kRevealSlowAnimationDurationMs; 734 return kRevealSlowAnimationDurationMs;
686 case ANIMATE_FAST: 735 case ANIMATE_FAST:
687 return kRevealFastAnimationDurationMs; 736 return kRevealFastAnimationDurationMs;
688 } 737 }
689 NOTREACHED(); 738 NOTREACHED();
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); 895 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator());
847 settings.SetTweenType(ui::Tween::EASE_OUT); 896 settings.SetTweenType(ui::Tween::EASE_OUT);
848 settings.SetTransitionDuration( 897 settings.SetTransitionDuration(
849 base::TimeDelta::FromMilliseconds(duration_ms)); 898 base::TimeDelta::FromMilliseconds(duration_ms));
850 settings.SetPreemptionStrategy( 899 settings.SetPreemptionStrategy(
851 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 900 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
852 if (observer) 901 if (observer)
853 settings.AddObserver(observer); 902 settings.AddObserver(observer);
854 layer->SetTransform(target_transform); 903 layer->SetTransform(target_transform);
855 } 904 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698