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" |
| 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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 DISALLOW_COPY_AND_ASSIGN(WindowObserver); | 329 DISALLOW_COPY_AND_ASSIGN(WindowObserver); |
327 }; | 330 }; |
328 | 331 |
329 //////////////////////////////////////////////////////////////////////////////// | 332 //////////////////////////////////////////////////////////////////////////////// |
330 | 333 |
331 ImmersiveModeControllerAsh::ImmersiveModeControllerAsh() | 334 ImmersiveModeControllerAsh::ImmersiveModeControllerAsh() |
332 : browser_view_(NULL), | 335 : browser_view_(NULL), |
333 enabled_(false), | 336 enabled_(false), |
334 reveal_state_(CLOSED), | 337 reveal_state_(CLOSED), |
335 revealed_lock_count_(0), | 338 revealed_lock_count_(0), |
336 hide_tab_indicators_(false), | 339 tab_indicator_visibility_(TAB_INDICATORS_HIDE), |
337 native_window_(NULL), | 340 native_window_(NULL), |
338 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 341 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
339 } | 342 } |
340 | 343 |
341 ImmersiveModeControllerAsh::~ImmersiveModeControllerAsh() { | 344 ImmersiveModeControllerAsh::~ImmersiveModeControllerAsh() { |
342 // The browser view is being destroyed so there's no need to update its | 345 // 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 | 346 // layout or layers, even if the top views are revealed. But the window |
344 // observers still need to be removed. | 347 // observers still need to be removed. |
345 EnableWindowObservers(false); | 348 EnableWindowObservers(false); |
346 } | 349 } |
(...skipping 17 matching lines...) Expand all Loading... |
364 | 367 |
365 void ImmersiveModeControllerAsh::Init(BrowserView* browser_view) { | 368 void ImmersiveModeControllerAsh::Init(BrowserView* browser_view) { |
366 browser_view_ = browser_view; | 369 browser_view_ = browser_view; |
367 // Browser view is detached from its widget during destruction. Cache the | 370 // Browser view is detached from its widget during destruction. Cache the |
368 // window pointer so |this| can stop observing during destruction. | 371 // window pointer so |this| can stop observing during destruction. |
369 native_window_ = browser_view_->GetNativeWindow(); | 372 native_window_ = browser_view_->GetNativeWindow(); |
370 DCHECK(native_window_); | 373 DCHECK(native_window_); |
371 EnableWindowObservers(true); | 374 EnableWindowObservers(true); |
372 | 375 |
373 // Optionally allow the tab indicators to be hidden. | 376 // Optionally allow the tab indicators to be hidden. |
374 hide_tab_indicators_ = CommandLine::ForCurrentProcess()-> | 377 if (CommandLine::ForCurrentProcess()-> |
375 HasSwitch(ash::switches::kAshImmersiveHideTabIndicators); | 378 HasSwitch(ash::switches::kAshImmersiveHideTabIndicators)) { |
| 379 tab_indicator_visibility_ = TAB_INDICATORS_FORCE_HIDE; |
| 380 } |
376 | 381 |
377 anchored_widget_manager_.reset(new AnchoredWidgetManager(this)); | 382 anchored_widget_manager_.reset(new AnchoredWidgetManager(this)); |
378 } | 383 } |
379 | 384 |
380 void ImmersiveModeControllerAsh::SetEnabled(bool enabled) { | 385 void ImmersiveModeControllerAsh::SetEnabled(bool enabled) { |
381 DCHECK(browser_view_) << "Must initialize before enabling"; | 386 DCHECK(browser_view_) << "Must initialize before enabling"; |
382 if (enabled_ == enabled) | 387 if (enabled_ == enabled) |
383 return; | 388 return; |
384 enabled_ = enabled; | 389 enabled_ = enabled; |
385 | 390 |
(...skipping 28 matching lines...) Expand all Loading... |
414 EnablePaintToLayer(false); | 419 EnablePaintToLayer(false); |
415 browser_view_->GetWidget()->non_client_view()->frame_view()-> | 420 browser_view_->GetWidget()->non_client_view()->frame_view()-> |
416 ResetWindowControls(); | 421 ResetWindowControls(); |
417 browser_view_->tabstrip()->SetImmersiveStyle(false); | 422 browser_view_->tabstrip()->SetImmersiveStyle(false); |
418 } | 423 } |
419 // Don't need explicit layout because we're inside a fullscreen transition | 424 // Don't need explicit layout because we're inside a fullscreen transition |
420 // and it blocks layout calls. | 425 // and it blocks layout calls. |
421 | 426 |
422 // This causes a no-op call to SetEnabled() since enabled_ is already set. | 427 // This causes a no-op call to SetEnabled() since enabled_ is already set. |
423 native_window_->SetProperty(ash::internal::kImmersiveModeKey, enabled_); | 428 native_window_->SetProperty(ash::internal::kImmersiveModeKey, enabled_); |
424 // Ash on Windows may not have a shell. | 429 |
425 if (ash::Shell::HasInstance()) { | 430 UpdateUseMinimalChrome(LAYOUT_NO); |
426 // Shelf auto-hides in immersive mode. | |
427 ash::Shell::GetInstance()->UpdateShelfVisibility(); | |
428 } | |
429 } | 431 } |
430 | 432 |
431 bool ImmersiveModeControllerAsh::IsEnabled() const { | 433 bool ImmersiveModeControllerAsh::IsEnabled() const { |
432 return enabled_; | 434 return enabled_; |
433 } | 435 } |
434 | 436 |
435 bool ImmersiveModeControllerAsh::ShouldHideTabIndicators() const { | 437 bool ImmersiveModeControllerAsh::ShouldHideTabIndicators() const { |
436 return hide_tab_indicators_; | 438 return tab_indicator_visibility_ != TAB_INDICATORS_SHOW; |
437 } | 439 } |
438 | 440 |
439 bool ImmersiveModeControllerAsh::ShouldHideTopViews() const { | 441 bool ImmersiveModeControllerAsh::ShouldHideTopViews() const { |
440 return enabled_ && reveal_state_ == CLOSED; | 442 return enabled_ && reveal_state_ == CLOSED; |
441 } | 443 } |
442 | 444 |
443 bool ImmersiveModeControllerAsh::IsRevealed() const { | 445 bool ImmersiveModeControllerAsh::IsRevealed() const { |
444 return enabled_ && reveal_state_ != CLOSED; | 446 return enabled_ && reveal_state_ != CLOSED; |
445 } | 447 } |
446 | 448 |
(...skipping 21 matching lines...) Expand all Loading... |
468 anchored_widget_manager_->RemoveAnchoredWidget(widget); | 470 anchored_widget_manager_->RemoveAnchoredWidget(widget); |
469 } | 471 } |
470 | 472 |
471 void ImmersiveModeControllerAsh::OnTopContainerBoundsChanged() { | 473 void ImmersiveModeControllerAsh::OnTopContainerBoundsChanged() { |
472 anchored_widget_manager_->MaybeRepositionAnchoredWidgets(); | 474 anchored_widget_manager_->MaybeRepositionAnchoredWidgets(); |
473 } | 475 } |
474 | 476 |
475 //////////////////////////////////////////////////////////////////////////////// | 477 //////////////////////////////////////////////////////////////////////////////// |
476 // Observers: | 478 // Observers: |
477 | 479 |
| 480 void ImmersiveModeControllerAsh::Observe( |
| 481 int type, |
| 482 const content::NotificationSource& source, |
| 483 const content::NotificationDetails& details) { |
| 484 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); |
| 485 if (enabled_) |
| 486 UpdateUseMinimalChrome(LAYOUT_YES); |
| 487 } |
| 488 |
478 void ImmersiveModeControllerAsh::OnMouseEvent(ui::MouseEvent* event) { | 489 void ImmersiveModeControllerAsh::OnMouseEvent(ui::MouseEvent* event) { |
479 if (!enabled_) | 490 if (!enabled_) |
480 return; | 491 return; |
481 | 492 |
482 if (event->flags() & ui::EF_IS_SYNTHESIZED) | 493 if (event->flags() & ui::EF_IS_SYNTHESIZED) |
483 return; | 494 return; |
484 | 495 |
485 // Handle ET_MOUSE_PRESSED and ET_MOUSE_RELEASED so that we get the updated | 496 // 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. | 497 // mouse position ASAP once a nested message loop finishes running. |
487 if (event->type() != ui::ET_MOUSE_MOVED && | 498 if (event->type() != ui::ET_MOUSE_MOVED && |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 void ImmersiveModeControllerAsh::OnImplicitAnimationsCompleted() { | 562 void ImmersiveModeControllerAsh::OnImplicitAnimationsCompleted() { |
552 if (reveal_state_ == SLIDING_OPEN) | 563 if (reveal_state_ == SLIDING_OPEN) |
553 OnSlideOpenAnimationCompleted(); | 564 OnSlideOpenAnimationCompleted(); |
554 else if (reveal_state_ == SLIDING_CLOSED) | 565 else if (reveal_state_ == SLIDING_CLOSED) |
555 OnSlideClosedAnimationCompleted(); | 566 OnSlideClosedAnimationCompleted(); |
556 } | 567 } |
557 | 568 |
558 //////////////////////////////////////////////////////////////////////////////// | 569 //////////////////////////////////////////////////////////////////////////////// |
559 // Testing interface: | 570 // Testing interface: |
560 | 571 |
561 void ImmersiveModeControllerAsh::SetHideTabIndicatorsForTest(bool hide) { | 572 void ImmersiveModeControllerAsh::SetForceHideTabIndicatorsForTest(bool force) { |
562 hide_tab_indicators_ = hide; | 573 if (force) |
| 574 tab_indicator_visibility_ = TAB_INDICATORS_FORCE_HIDE; |
| 575 else if (tab_indicator_visibility_ == TAB_INDICATORS_FORCE_HIDE) |
| 576 tab_indicator_visibility_ = TAB_INDICATORS_HIDE; |
| 577 UpdateUseMinimalChrome(LAYOUT_YES); |
563 } | 578 } |
564 | 579 |
565 void ImmersiveModeControllerAsh::StartRevealForTest(bool hovered) { | 580 void ImmersiveModeControllerAsh::StartRevealForTest(bool hovered) { |
566 MaybeStartReveal(ANIMATE_NO); | 581 MaybeStartReveal(ANIMATE_NO); |
567 MoveMouse(browser_view_->top_container(), hovered); | 582 MoveMouse(browser_view_->top_container(), hovered); |
568 UpdateMouseRevealedLock(false); | 583 UpdateMouseRevealedLock(false); |
569 } | 584 } |
570 | 585 |
571 void ImmersiveModeControllerAsh::SetMouseHoveredForTest(bool hovered) { | 586 void ImmersiveModeControllerAsh::SetMouseHoveredForTest(bool hovered) { |
572 MoveMouse(browser_view_->top_container(), hovered); | 587 MoveMouse(browser_view_->top_container(), hovered); |
(...skipping 21 matching lines...) Expand all Loading... |
594 } | 609 } |
595 | 610 |
596 if (enable) | 611 if (enable) |
597 native_window_->AddPreTargetHandler(this); | 612 native_window_->AddPreTargetHandler(this); |
598 else | 613 else |
599 native_window_->RemovePreTargetHandler(this); | 614 native_window_->RemovePreTargetHandler(this); |
600 | 615 |
601 // The window observer adds and removes itself from the native window. | 616 // The window observer adds and removes itself from the native window. |
602 window_observer_.reset(enable ? new WindowObserver(this) : NULL); | 617 window_observer_.reset(enable ? new WindowObserver(this) : NULL); |
603 | 618 |
| 619 if (enable) { |
| 620 registrar_.Add( |
| 621 this, |
| 622 chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
| 623 content::Source<FullscreenController>( |
| 624 browser_view_->browser()->fullscreen_controller())); |
| 625 } else { |
| 626 registrar_.Remove( |
| 627 this, |
| 628 chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
| 629 content::Source<FullscreenController>( |
| 630 browser_view_->browser()->fullscreen_controller())); |
| 631 } |
| 632 |
604 if (!enable) | 633 if (!enable) |
605 StopObservingImplicitAnimations(); | 634 StopObservingImplicitAnimations(); |
606 } | 635 } |
607 | 636 |
608 void ImmersiveModeControllerAsh::UpdateMouseRevealedLock(bool maybe_drag) { | 637 void ImmersiveModeControllerAsh::UpdateMouseRevealedLock(bool maybe_drag) { |
609 if (!enabled_) | 638 if (!enabled_) |
610 return; | 639 return; |
611 | 640 |
612 // Hover cannot initiate a reveal when the top-of-window views are sliding | 641 // 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 | 642 // 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 Loading... |
670 } | 699 } |
671 | 700 |
672 if (hold_lock) { | 701 if (hold_lock) { |
673 if (!focus_revealed_lock_.get()) | 702 if (!focus_revealed_lock_.get()) |
674 focus_revealed_lock_.reset(GetRevealedLock()); | 703 focus_revealed_lock_.reset(GetRevealedLock()); |
675 } else { | 704 } else { |
676 focus_revealed_lock_.reset(); | 705 focus_revealed_lock_.reset(); |
677 } | 706 } |
678 } | 707 } |
679 | 708 |
| 709 void ImmersiveModeControllerAsh::UpdateUseMinimalChrome(Layout layout) { |
| 710 bool in_tab_fullscreen = browser_view_->browser()->fullscreen_controller()-> |
| 711 IsFullscreenForTabOrPending(); |
| 712 bool use_minimal_chrome = !in_tab_fullscreen && enabled_; |
| 713 native_window_->SetProperty(ash::internal::kFullscreenUsesMinimalChromeKey, |
| 714 use_minimal_chrome); |
| 715 |
| 716 TabIndicatorVisibility previous_tab_indicator_visibility = |
| 717 tab_indicator_visibility_; |
| 718 if (tab_indicator_visibility_ != TAB_INDICATORS_FORCE_HIDE) { |
| 719 tab_indicator_visibility_ = use_minimal_chrome ? |
| 720 TAB_INDICATORS_SHOW : TAB_INDICATORS_HIDE; |
| 721 } |
| 722 |
| 723 // Ash on Windows may not have a shell. |
| 724 if (ash::Shell::HasInstance()) { |
| 725 // When using minimal chrome, the shelf is auto-hidden. The auto-hidden |
| 726 // shelf displays a 3px 'light bar' when it is closed. |
| 727 ash::Shell::GetInstance()->UpdateShelfVisibility(); |
| 728 } |
| 729 |
| 730 if (tab_indicator_visibility_ != previous_tab_indicator_visibility) { |
| 731 // If the top-of-window views are revealed or animating, the change will |
| 732 // take effect with the layout once the top-of-window views are closed. |
| 733 if (layout == LAYOUT_YES && reveal_state_ == CLOSED) |
| 734 LayoutBrowserView(true); |
| 735 } |
| 736 } |
| 737 |
680 int ImmersiveModeControllerAsh::GetAnimationDuration(Animate animate) const { | 738 int ImmersiveModeControllerAsh::GetAnimationDuration(Animate animate) const { |
681 switch (animate) { | 739 switch (animate) { |
682 case ANIMATE_NO: | 740 case ANIMATE_NO: |
683 return 0; | 741 return 0; |
684 case ANIMATE_SLOW: | 742 case ANIMATE_SLOW: |
685 return kRevealSlowAnimationDurationMs; | 743 return kRevealSlowAnimationDurationMs; |
686 case ANIMATE_FAST: | 744 case ANIMATE_FAST: |
687 return kRevealFastAnimationDurationMs; | 745 return kRevealFastAnimationDurationMs; |
688 } | 746 } |
689 NOTREACHED(); | 747 NOTREACHED(); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); | 904 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); |
847 settings.SetTweenType(ui::Tween::EASE_OUT); | 905 settings.SetTweenType(ui::Tween::EASE_OUT); |
848 settings.SetTransitionDuration( | 906 settings.SetTransitionDuration( |
849 base::TimeDelta::FromMilliseconds(duration_ms)); | 907 base::TimeDelta::FromMilliseconds(duration_ms)); |
850 settings.SetPreemptionStrategy( | 908 settings.SetPreemptionStrategy( |
851 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 909 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
852 if (observer) | 910 if (observer) |
853 settings.AddObserver(observer); | 911 settings.AddObserver(observer); |
854 layer->SetTransform(target_transform); | 912 layer->SetTransform(target_transform); |
855 } | 913 } |
OLD | NEW |