Chromium Code Reviews| Index: ash/wm/immersive_fullscreen_controller.cc |
| diff --git a/chrome/browser/ui/views/frame/immersive_mode_controller_ash.cc b/ash/wm/immersive_fullscreen_controller.cc |
| similarity index 63% |
| copy from chrome/browser/ui/views/frame/immersive_mode_controller_ash.cc |
| copy to ash/wm/immersive_fullscreen_controller.cc |
| index ea8475bf19ac70d4550bab24556f267ced20a16a..4e90ba7b955d97c0aad8e04ac653ee3f5a864d2f 100644 |
| --- a/chrome/browser/ui/views/frame/immersive_mode_controller_ash.cc |
| +++ b/ash/wm/immersive_fullscreen_controller.cc |
| @@ -2,20 +2,13 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "chrome/browser/ui/views/frame/immersive_mode_controller_ash.h" |
| +#include "ash/wm/immersive_fullscreen_controller.h" |
| #include <set> |
| -#include <vector> |
| #include "ash/shell.h" |
| +#include "ash/wm/immersive_revealed_lock.h" |
| #include "ash/wm/window_state.h" |
| -#include "chrome/browser/chrome_notification_types.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/top_container_view.h" |
| -#include "content/public/browser/notification_service.h" |
| -#include "content/public/browser/web_contents.h" |
| -#include "content/public/browser/web_contents_view.h" |
| #include "ui/aura/client/activation_client.h" |
| #include "ui/aura/client/aura_constants.h" |
| #include "ui/aura/client/capture_client.h" |
| @@ -25,19 +18,17 @@ |
| #include "ui/aura/root_window.h" |
| #include "ui/aura/window.h" |
| #include "ui/gfx/animation/slide_animation.h" |
| +#include "ui/gfx/display.h" |
| +#include "ui/gfx/screen.h" |
| #include "ui/views/bubble/bubble_delegate.h" |
| #include "ui/views/view.h" |
| #include "ui/views/widget/widget.h" |
| -#include "ui/views/window/non_client_view.h" |
| using views::View; |
| -namespace { |
| +namespace ash { |
| -// The slide open/closed animation looks better if it starts and ends just a |
| -// few pixels before the view goes completely off the screen, which reduces |
| -// the visual "pop" as the 2-pixel tall immersive-style tabs become visible. |
| -const int kAnimationOffsetY = 3; |
| +namespace { |
| // Duration for the reveal show/hide slide animation. The slower duration is |
| // used for the initial slide out to give the user more change to see what |
| @@ -112,27 +103,10 @@ gfx::Point GetEventLocationInScreen(const ui::LocatedEvent& event) { |
| return location_in_screen; |
| } |
| -//////////////////////////////////////////////////////////////////////////////// |
| - |
| -class RevealedLockAsh : public ImmersiveRevealedLock { |
| - public: |
| - RevealedLockAsh(const base::WeakPtr<ImmersiveModeControllerAsh>& controller, |
| - ImmersiveModeController::AnimateReveal animate_reveal) |
| - : controller_(controller) { |
| - DCHECK(controller_); |
| - controller_->LockRevealedState(animate_reveal); |
| - } |
| - |
| - virtual ~RevealedLockAsh() { |
| - if (controller_) |
| - controller_->UnlockRevealedState(); |
| - } |
| - |
| - private: |
| - base::WeakPtr<ImmersiveModeControllerAsh> controller_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(RevealedLockAsh); |
| -}; |
| +// Returns the bounds of the display nearest to |window| in screen coordinates. |
| +gfx::Rect GetDisplayBoundsInScreen(aura::Window* window) { |
| + return Shell::GetScreen()->GetDisplayNearestWindow(window).bounds(); |
| +} |
| } // namespace |
| @@ -141,14 +115,15 @@ class RevealedLockAsh : public ImmersiveRevealedLock { |
| // Class which keeps the top-of-window views revealed as long as one of the |
| // bubbles it is observing is visible. The logic to keep the top-of-window |
| // views revealed based on the visibility of bubbles anchored to |
| -// children of |ImmersiveModeController::top_container_| is separate from |
| -// the logic related to |ImmersiveModeControllerAsh::focus_revealed_lock_| |
| +// children of |ImmersiveFullscreenController::top_container_| is separate from |
| +// the logic related to |ImmersiveFullscreenController::focus_revealed_lock_| |
| // so that bubbles which are not activatable and bubbles which do not close |
| // upon deactivation also keep the top-of-window views revealed for the |
| // duration of their visibility. |
| -class ImmersiveModeControllerAsh::BubbleManager : public aura::WindowObserver { |
| +class ImmersiveFullscreenController::BubbleManager |
| + : public aura::WindowObserver { |
| public: |
| - explicit BubbleManager(ImmersiveModeControllerAsh* controller); |
| + explicit BubbleManager(ImmersiveFullscreenController* controller); |
| virtual ~BubbleManager(); |
| // Start / stop observing changes to |bubble|'s visibility. |
| @@ -164,7 +139,7 @@ class ImmersiveModeControllerAsh::BubbleManager : public aura::WindowObserver { |
| bool visible) OVERRIDE; |
| virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; |
| - ImmersiveModeControllerAsh* controller_; |
| + ImmersiveFullscreenController* controller_; |
| std::set<aura::Window*> bubbles_; |
| @@ -175,19 +150,19 @@ class ImmersiveModeControllerAsh::BubbleManager : public aura::WindowObserver { |
| DISALLOW_COPY_AND_ASSIGN(BubbleManager); |
| }; |
| -ImmersiveModeControllerAsh::BubbleManager::BubbleManager( |
| - ImmersiveModeControllerAsh* controller) |
| +ImmersiveFullscreenController::BubbleManager::BubbleManager( |
| + ImmersiveFullscreenController* controller) |
| : controller_(controller) { |
| } |
| -ImmersiveModeControllerAsh::BubbleManager::~BubbleManager() { |
| +ImmersiveFullscreenController::BubbleManager::~BubbleManager() { |
| for (std::set<aura::Window*>::const_iterator it = bubbles_.begin(); |
| it != bubbles_.end(); ++it) { |
| (*it)->RemoveObserver(this); |
| } |
| } |
| -void ImmersiveModeControllerAsh::BubbleManager::StartObserving( |
| +void ImmersiveFullscreenController::BubbleManager::StartObserving( |
| aura::Window* bubble) { |
| if (bubbles_.insert(bubble).second) { |
| bubble->AddObserver(this); |
| @@ -195,7 +170,7 @@ void ImmersiveModeControllerAsh::BubbleManager::StartObserving( |
| } |
| } |
| -void ImmersiveModeControllerAsh::BubbleManager::StopObserving( |
| +void ImmersiveFullscreenController::BubbleManager::StopObserving( |
| aura::Window* bubble) { |
| if (bubbles_.erase(bubble)) { |
| bubble->RemoveObserver(this); |
| @@ -203,7 +178,7 @@ void ImmersiveModeControllerAsh::BubbleManager::StopObserving( |
| } |
| } |
| -void ImmersiveModeControllerAsh::BubbleManager::UpdateRevealedLock() { |
| +void ImmersiveFullscreenController::BubbleManager::UpdateRevealedLock() { |
| bool has_visible_bubble = false; |
| for (std::set<aura::Window*>::const_iterator it = bubbles_.begin(); |
| it != bubbles_.end(); ++it) { |
| @@ -220,7 +195,7 @@ void ImmersiveModeControllerAsh::BubbleManager::UpdateRevealedLock() { |
| // weird for the top-of-window views to animate and the bubble not to |
| // animate along with the top-of-window views. |
| revealed_lock_.reset(controller_->GetRevealedLock( |
| - ImmersiveModeController::ANIMATE_REVEAL_NO)); |
| + ImmersiveFullscreenController::ANIMATE_REVEAL_NO)); |
| } |
| } else { |
| revealed_lock_.reset(); |
| @@ -239,81 +214,58 @@ void ImmersiveModeControllerAsh::BubbleManager::UpdateRevealedLock() { |
| } |
| } |
| -void ImmersiveModeControllerAsh::BubbleManager::OnWindowVisibilityChanged( |
| +void ImmersiveFullscreenController::BubbleManager::OnWindowVisibilityChanged( |
| aura::Window*, |
| bool visible) { |
| UpdateRevealedLock(); |
| } |
| -void ImmersiveModeControllerAsh::BubbleManager::OnWindowDestroying( |
| +void ImmersiveFullscreenController::BubbleManager::OnWindowDestroying( |
| aura::Window* window) { |
| StopObserving(window); |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| -ImmersiveModeControllerAsh::ImmersiveModeControllerAsh() |
| +ImmersiveFullscreenController::ImmersiveFullscreenController() |
| : delegate_(NULL), |
| - widget_(NULL), |
| top_container_(NULL), |
| + widget_(NULL), |
| + native_window_(NULL), |
| observers_enabled_(false), |
| enabled_(false), |
| reveal_state_(CLOSED), |
| revealed_lock_count_(0), |
| - tab_indicator_visibility_(TAB_INDICATORS_HIDE), |
| mouse_x_when_hit_top_in_screen_(-1), |
| gesture_begun_(false), |
| - native_window_(NULL), |
| animation_(new gfx::SlideAnimation(this)), |
| animations_disabled_for_test_(false), |
| weak_ptr_factory_(this) { |
| } |
| -ImmersiveModeControllerAsh::~ImmersiveModeControllerAsh() { |
| - // The browser view is being destroyed so there's no need to update its |
| - // layout or layers, even if the top views are revealed. But the window |
| - // observers still need to be removed. |
| +ImmersiveFullscreenController::~ImmersiveFullscreenController() { |
| EnableWindowObservers(false); |
| } |
| -void ImmersiveModeControllerAsh::LockRevealedState( |
| - AnimateReveal animate_reveal) { |
| - ++revealed_lock_count_; |
| - Animate animate = (animate_reveal == ANIMATE_REVEAL_YES) ? |
| - ANIMATE_FAST : ANIMATE_NO; |
| - MaybeStartReveal(animate); |
| -} |
| - |
| -void ImmersiveModeControllerAsh::UnlockRevealedState() { |
| - --revealed_lock_count_; |
| - DCHECK_GE(revealed_lock_count_, 0); |
| - if (revealed_lock_count_ == 0) { |
| - // Always animate ending the reveal fast. |
| - MaybeEndReveal(ANIMATE_FAST); |
| - } |
| -} |
| - |
| -void ImmersiveModeControllerAsh::Init( |
| - Delegate* delegate, |
| - views::Widget* widget, |
| - views::View* top_container) { |
| +void ImmersiveFullscreenController::Init(Delegate* delegate, |
| + views::Widget* widget, |
| + views::View* top_container) { |
| delegate_ = delegate; |
| + top_container_ = top_container; |
| widget_ = widget; |
| - // Browser view is detached from its widget during destruction. Cache the |
| - // window pointer so |this| can stop observing during destruction. |
| native_window_ = widget_->GetNativeWindow(); |
| - top_container_ = top_container; |
| } |
| -void ImmersiveModeControllerAsh::SetEnabled(bool enabled) { |
| - DCHECK(native_window_) << "Must initialize before enabling"; |
| +void ImmersiveFullscreenController::SetEnabled(bool enabled) { |
| if (enabled_ == enabled) |
| return; |
| enabled_ = enabled; |
| EnableWindowObservers(enabled_); |
| - UpdateUseMinimalChrome(LAYOUT_NO); |
| + // Auto hide the shelf in immersive fullscreen instead of hiding it. |
| + wm::GetWindowState(native_window_)->set_hide_shelf_when_fullscreen(!enabled); |
| + ash::Shell::GetInstance()->UpdateShelfVisibility(); |
| if (enabled_) { |
| // Animate enabling immersive mode by sliding out the top-of-window views. |
| @@ -321,8 +273,8 @@ void ImmersiveModeControllerAsh::SetEnabled(bool enabled) { |
| // Do a reveal to set the initial state for the animation. (And any |
| // required state in case the animation cannot run because of a lock holding |
| - // the top-of-window views open.) This call has the side effect of relaying |
| - // out |browser_view_|'s root view. |
| + // the top-of-window views open.) |
| + reveal_state_ = CLOSED; |
| MaybeStartReveal(ANIMATE_NO); |
| // Reset the located event and the focus revealed locks so that they do not |
| @@ -341,78 +293,51 @@ void ImmersiveModeControllerAsh::SetEnabled(bool enabled) { |
| } else { |
| // Stop cursor-at-top tracking. |
| top_edge_hover_timer_.Stop(); |
| - // Snap immediately to the closed state. |
| - reveal_state_ = CLOSED; |
|
James Cook
2013/10/28 18:32:51
You no longer want to snap to the closed state on
pkotwicz
2013/10/29 04:32:45
The change I was making was moving setting |reveal
|
| - top_container_->SetPaintToLayer(false); |
| - delegate_->SetImmersiveStyle(false); |
| - SetRenderWindowTopInsetsForTouch(0); |
| - // Layout the root view so that incognito avatar icon, if any, gets laid |
| - // out. |
| - LayoutBrowserRootView(); |
| + delegate_->OnImmersiveFullscreenExited(); |
| } |
| } |
| -bool ImmersiveModeControllerAsh::IsEnabled() const { |
| +bool ImmersiveFullscreenController::IsEnabled() const { |
| return enabled_; |
| } |
| -bool ImmersiveModeControllerAsh::ShouldHideTabIndicators() const { |
| - return tab_indicator_visibility_ != TAB_INDICATORS_SHOW; |
| -} |
| - |
| -bool ImmersiveModeControllerAsh::ShouldHideTopViews() const { |
| - return enabled_ && reveal_state_ == CLOSED; |
| -} |
| - |
| -bool ImmersiveModeControllerAsh::IsRevealed() const { |
| +bool ImmersiveFullscreenController::IsRevealed() const { |
| return enabled_ && reveal_state_ != CLOSED; |
| } |
| -int ImmersiveModeControllerAsh::GetTopContainerVerticalOffset( |
| - const gfx::Size& top_container_size) const { |
| - if (!enabled_ || reveal_state_ == REVEALED || reveal_state_ == CLOSED) |
| - return 0; |
| - |
| - return animation_->CurrentValueBetween( |
| - -top_container_size.height() + kAnimationOffsetY, 0); |
| -} |
| - |
| -ImmersiveRevealedLock* ImmersiveModeControllerAsh::GetRevealedLock( |
| +ImmersiveRevealedLock* ImmersiveFullscreenController::GetRevealedLock( |
| AnimateReveal animate_reveal) { |
| - return new RevealedLockAsh(weak_ptr_factory_.GetWeakPtr(), animate_reveal); |
| + return new ImmersiveRevealedLock(weak_ptr_factory_.GetWeakPtr(), |
| + animate_reveal); |
| } |
| -void ImmersiveModeControllerAsh::OnFindBarVisibleBoundsChanged( |
| - const gfx::Rect& new_visible_bounds_in_screen) { |
| - find_bar_visible_bounds_in_screen_ = new_visible_bounds_in_screen; |
| -} |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// Testing interface: |
| -void ImmersiveModeControllerAsh::SetupForTest() { |
| +void ImmersiveFullscreenController::SetupForTest() { |
| DCHECK(!enabled_); |
| animations_disabled_for_test_ = true; |
| - // Move the mouse off of the top-of-window views so that it does not keep |
| - // the top-of-window views revealed. |
| - gfx::Point cursor_pos(0, top_container_->bounds().bottom() + 100); |
| - views::View::ConvertPointToScreen(top_container_, &cursor_pos); |
| + // Move the mouse out of the way so that it does not keep the top-of-window |
| + // views revealed. |
| + std::vector<gfx::Rect> bounds_in_screen( |
| + delegate_->GetVisibleBoundsInScreen()); |
| + DCHECK(!bounds_in_screen.empty()); |
| + int bottommost_in_screen = bounds_in_screen[0].bottom(); |
| + for (size_t i = 1; i < bounds_in_screen.size(); ++i) { |
| + if (bounds_in_screen[i].bottom() > bottommost_in_screen) |
| + bottommost_in_screen = bounds_in_screen[i].bottom(); |
| + } |
| + gfx::Point cursor_pos(0, bottommost_in_screen + 100); |
| aura::Env::GetInstance()->set_last_mouse_location(cursor_pos); |
| UpdateLocatedEventRevealedLock(NULL, ALLOW_REVEAL_WHILE_CLOSING_NO); |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| -// Observers: |
| - |
| -void ImmersiveModeControllerAsh::Observe( |
| - int type, |
| - const content::NotificationSource& source, |
| - const content::NotificationDetails& details) { |
| - DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); |
| - if (enabled_) |
| - UpdateUseMinimalChrome(LAYOUT_YES); |
| -} |
| +// ui::EventHandler overrides: |
| -void ImmersiveModeControllerAsh::OnMouseEvent(ui::MouseEvent* event) { |
| +void ImmersiveFullscreenController::OnMouseEvent(ui::MouseEvent* event) { |
| if (!enabled_) |
| return; |
| @@ -442,14 +367,14 @@ void ImmersiveModeControllerAsh::OnMouseEvent(ui::MouseEvent* event) { |
| UpdateTopEdgeHoverTimer(event); |
| } |
| -void ImmersiveModeControllerAsh::OnTouchEvent(ui::TouchEvent* event) { |
| +void ImmersiveFullscreenController::OnTouchEvent(ui::TouchEvent* event) { |
| if (!enabled_ || event->type() != ui::ET_TOUCH_PRESSED) |
| return; |
| UpdateLocatedEventRevealedLock(event, ALLOW_REVEAL_WHILE_CLOSING_NO); |
| } |
| -void ImmersiveModeControllerAsh::OnGestureEvent(ui::GestureEvent* event) { |
| +void ImmersiveFullscreenController::OnGestureEvent(ui::GestureEvent* event) { |
| if (!enabled_) |
| return; |
| @@ -481,16 +406,24 @@ void ImmersiveModeControllerAsh::OnGestureEvent(ui::GestureEvent* event) { |
| } |
| } |
| -void ImmersiveModeControllerAsh::OnWillChangeFocus(views::View* focused_before, |
| - views::View* focused_now) { |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// views::FocusChangeListener overrides: |
| + |
| +void ImmersiveFullscreenController::OnWillChangeFocus( |
| + views::View* focused_before, |
| + views::View* focused_now) { |
| } |
| -void ImmersiveModeControllerAsh::OnDidChangeFocus(views::View* focused_before, |
| - views::View* focused_now) { |
| +void ImmersiveFullscreenController::OnDidChangeFocus( |
| + views::View* focused_before, |
| + views::View* focused_now) { |
| UpdateFocusRevealedLock(); |
| } |
| -void ImmersiveModeControllerAsh::OnWidgetDestroying(views::Widget* widget) { |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// views::WidgetObserver overrides: |
| + |
| +void ImmersiveFullscreenController::OnWidgetDestroying(views::Widget* widget) { |
| EnableWindowObservers(false); |
| native_window_ = NULL; |
| @@ -499,7 +432,7 @@ void ImmersiveModeControllerAsh::OnWidgetDestroying(views::Widget* widget) { |
| enabled_ = false; |
| } |
| -void ImmersiveModeControllerAsh::OnWidgetActivationChanged( |
| +void ImmersiveFullscreenController::OnWidgetActivationChanged( |
| views::Widget* widget, |
| bool active) { |
| // Mouse hover should not initiate revealing the top-of-window views while |
| @@ -520,52 +453,26 @@ void ImmersiveModeControllerAsh::OnWidgetActivationChanged( |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| -// Animation delegate: |
| +// gfx::AnimationDelegate overrides: |
| -void ImmersiveModeControllerAsh::AnimationEnded( |
| +void ImmersiveFullscreenController::AnimationEnded( |
| const gfx::Animation* animation) { |
| if (reveal_state_ == SLIDING_OPEN) { |
| - // AnimationProgressed() is called immediately before AnimationEnded() |
| - // and does a layout. |
| - OnSlideOpenAnimationCompleted(LAYOUT_NO); |
| + OnSlideOpenAnimationCompleted(); |
| } else if (reveal_state_ == SLIDING_CLOSED) { |
| OnSlideClosedAnimationCompleted(); |
| } |
| } |
| -void ImmersiveModeControllerAsh::AnimationProgressed( |
| +void ImmersiveFullscreenController::AnimationProgressed( |
| const gfx::Animation* animation) { |
| - // Relayout. This will also move any views whose position depends on the |
| - // top container position such as the find bar. |
| - // We do not call LayoutBrowserRootView() here because we are not toggling |
| - // the tab strip's immersive style so relaying out the non client view is not |
| - // necessary. |
| - top_container_->parent()->Layout(); |
| + delegate_->SetVisibility(animation->GetCurrentValue()); |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| // aura::WindowObserver overrides: |
| -void ImmersiveModeControllerAsh::OnWindowPropertyChanged(aura::Window* window, |
| - const void* key, |
| - intptr_t old) { |
| - if (!enabled_) |
| - return; |
| - |
| - if (key == aura::client::kShowStateKey) { |
| - // Disable immersive mode when the user exits fullscreen without going |
| - // through FullscreenController::ToggleFullscreenMode(). This is the case |
| - // if the user exits fullscreen via the restore button. |
| - ui::WindowShowState show_state = static_cast<ui::WindowShowState>( |
| - native_window_->GetProperty(aura::client::kShowStateKey)); |
| - if (show_state != ui::SHOW_STATE_FULLSCREEN && |
| - show_state != ui::SHOW_STATE_MINIMIZED) { |
| - delegate_->FullscreenStateChanged(); |
| - } |
| - } |
| -} |
| - |
| -void ImmersiveModeControllerAsh::OnAddTransientChild(aura::Window* window, |
| +void ImmersiveFullscreenController::OnAddTransientChild(aura::Window* window, |
| aura::Window* transient) { |
| views::BubbleDelegateView* bubble_delegate = AsBubbleDelegate(transient); |
| if (bubble_delegate && |
| @@ -578,76 +485,68 @@ void ImmersiveModeControllerAsh::OnAddTransientChild(aura::Window* window, |
| } |
| } |
| -void ImmersiveModeControllerAsh::OnRemoveTransientChild( |
| +void ImmersiveFullscreenController::OnRemoveTransientChild( |
| aura::Window* window, |
| aura::Window* transient) { |
| bubble_manager_->StopObserving(transient); |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| +// ash::ImmersiveRevealedLock::Delegate overrides: |
| + |
| +void ImmersiveFullscreenController::LockRevealedState( |
| + AnimateReveal animate_reveal) { |
| + ++revealed_lock_count_; |
| + Animate animate = (animate_reveal == ANIMATE_REVEAL_YES) ? |
| + ANIMATE_FAST : ANIMATE_NO; |
| + MaybeStartReveal(animate); |
| +} |
| + |
| +void ImmersiveFullscreenController::UnlockRevealedState() { |
| + --revealed_lock_count_; |
| + DCHECK_GE(revealed_lock_count_, 0); |
| + if (revealed_lock_count_ == 0) { |
| + // Always animate ending the reveal fast. |
| + MaybeEndReveal(ANIMATE_FAST); |
| + } |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| // private: |
| -void ImmersiveModeControllerAsh::EnableWindowObservers(bool enable) { |
| +void ImmersiveFullscreenController::EnableWindowObservers(bool enable) { |
| if (observers_enabled_ == enable) |
| return; |
| observers_enabled_ = enable; |
| - if (!native_window_) { |
| - NOTREACHED() << "ImmersiveModeControllerAsh not initialized"; |
| - return; |
| - } |
| - |
| views::Widget* widget = |
| views::Widget::GetWidgetForNativeWindow(native_window_); |
| views::FocusManager* focus_manager = widget->GetFocusManager(); |
| + |
| if (enable) { |
| widget->AddObserver(this); |
| focus_manager->AddFocusChangeListener(this); |
| + ash::Shell::GetInstance()->AddPreTargetHandler(this); |
| + native_window_->AddObserver(this); |
| + |
| + RecreateBubbleManager(); |
| } else { |
| widget->RemoveObserver(this); |
| focus_manager->RemoveFocusChangeListener(this); |
| - } |
| - |
| - if (enable) |
| - ash::Shell::GetInstance()->AddPreTargetHandler(this); |
| - else |
| ash::Shell::GetInstance()->RemovePreTargetHandler(this); |
| - |
| - if (enable) { |
| - native_window_->AddObserver(this); |
| - } else { |
| native_window_->RemoveObserver(this); |
| - } |
| - if (enable) { |
| - RecreateBubbleManager(); |
| - } else { |
| // We have stopped observing whether transient children are added or removed |
| // to |native_window_|. The set of bubbles that BubbleManager is observing |
| // will become stale really quickly. Destroy BubbleManager and recreate it |
| // when we start observing |native_window_| again. |
| bubble_manager_.reset(); |
| - } |
| - |
| - if (enable) { |
| - registrar_.Add( |
| - this, |
| - chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
| - content::Source<FullscreenController>( |
| - delegate_->GetFullscreenController())); |
| - } else { |
| - registrar_.Remove( |
| - this, |
| - chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
| - content::Source<FullscreenController>( |
| - delegate_->GetFullscreenController())); |
| - } |
| - if (!enable) |
| animation_->Stop(); |
| + } |
| } |
| -void ImmersiveModeControllerAsh::UpdateTopEdgeHoverTimer( |
| +void ImmersiveFullscreenController::UpdateTopEdgeHoverTimer( |
| ui::MouseEvent* event) { |
| DCHECK(enabled_); |
| // Stop the timer if the top-of-window views are already revealed. |
| @@ -664,8 +563,7 @@ void ImmersiveModeControllerAsh::UpdateTopEdgeHoverTimer( |
| // display. The bounds of |top_container_|'s parent are used to infer the hit |
| // bounds because |top_container_| will be partially offscreen if it is |
| // animating closed. |
| - gfx::Rect hit_bounds_in_screen = |
| - top_container_->parent()->GetBoundsInScreen(); |
| + gfx::Rect hit_bounds_in_screen = GetDisplayBoundsInScreen(native_window_); |
| hit_bounds_in_screen.set_height(kMouseRevealBoundsHeight); |
| if (!hit_bounds_in_screen.Contains(location_in_screen)) { |
| top_edge_hover_timer_.Stop(); |
| @@ -688,11 +586,12 @@ void ImmersiveModeControllerAsh::UpdateTopEdgeHoverTimer( |
| top_edge_hover_timer_.Start( |
| FROM_HERE, |
| base::TimeDelta::FromMilliseconds(kMouseRevealDelayMs), |
| - base::Bind(&ImmersiveModeControllerAsh::AcquireLocatedEventRevealedLock, |
| - base::Unretained(this))); |
| + base::Bind( |
| + &ImmersiveFullscreenController::AcquireLocatedEventRevealedLock, |
| + base::Unretained(this))); |
| } |
| -void ImmersiveModeControllerAsh::UpdateLocatedEventRevealedLock( |
| +void ImmersiveFullscreenController::UpdateLocatedEventRevealedLock( |
| ui::LocatedEvent* event, |
| AllowRevealWhileClosing allow_reveal_while_closing) { |
| if (!enabled_) |
| @@ -741,42 +640,42 @@ void ImmersiveModeControllerAsh::UpdateLocatedEventRevealedLock( |
| return; |
| } |
| - gfx::Rect hit_bounds_in_top_container = top_container_->GetVisibleBounds(); |
| - // TODO(tdanderson): Implement View::ConvertRectToScreen(); |
| - gfx::Point hit_bounds_in_screen_origin = hit_bounds_in_top_container.origin(); |
| - views::View::ConvertPointToScreen(top_container_, |
| - &hit_bounds_in_screen_origin); |
| - gfx::Rect hit_bounds_in_screen(hit_bounds_in_screen_origin, |
| - hit_bounds_in_top_container.size()); |
| - |
| - gfx::Rect find_bar_hit_bounds_in_screen = find_bar_visible_bounds_in_screen_; |
| - |
| - // Allow the cursor to move slightly off the top-of-window views before |
| - // sliding closed. This helps when the user is attempting to click on the |
| - // bookmark bar and overshoots slightly. |
| - if (event && event->type() == ui::ET_MOUSE_MOVED) { |
| - const int kBoundsOffsetY = 8; |
| - hit_bounds_in_screen.Inset(0, 0, 0, -kBoundsOffsetY); |
| - find_bar_hit_bounds_in_screen.Inset(0, 0, 0, -kBoundsOffsetY); |
| + // The visible bounds of |top_container_| should be contained in |
| + // |hit_bounds_in_screen|. |
| + std::vector<gfx::Rect> hit_bounds_in_screen = |
| + delegate_->GetVisibleBoundsInScreen(); |
| + bool keep_revealed = false; |
| + for (size_t i = 0; i < hit_bounds_in_screen.size(); ++i) { |
| + // Allow the cursor to move slightly off the top-of-window views before |
| + // sliding closed. In the case of ImmersiveModeControllerAsh, this helps |
| + // when the user is attempting to click on the bookmark bar and overshoots |
| + // slightly. |
| + if (event && event->type() == ui::ET_MOUSE_MOVED) { |
| + const int kBoundsOffsetY = 8; |
| + hit_bounds_in_screen[i].Inset(0, 0, 0, -kBoundsOffsetY); |
| + } |
| + |
| + if (hit_bounds_in_screen[i].Contains(location_in_screen)) { |
| + keep_revealed = true; |
| + break; |
| + } |
| } |
| - if (hit_bounds_in_screen.Contains(location_in_screen) || |
| - find_bar_hit_bounds_in_screen.Contains(location_in_screen)) { |
| + if (keep_revealed) |
| AcquireLocatedEventRevealedLock(); |
| - } else { |
| + else |
| located_event_revealed_lock_.reset(); |
| - } |
| } |
| -void ImmersiveModeControllerAsh::AcquireLocatedEventRevealedLock() { |
| +void ImmersiveFullscreenController::AcquireLocatedEventRevealedLock() { |
| // CAUTION: Acquiring the lock results in a reentrant call to |
| // AcquireLocatedEventRevealedLock() when |
| - // |ImmersiveModeControllerAsh::animations_disabled_for_test_| is true. |
| + // |ImmersiveFullscreenController::animations_disabled_for_test_| is true. |
| if (!located_event_revealed_lock_.get()) |
| located_event_revealed_lock_.reset(GetRevealedLock(ANIMATE_REVEAL_YES)); |
| } |
| -void ImmersiveModeControllerAsh::UpdateFocusRevealedLock() { |
| +void ImmersiveFullscreenController::UpdateFocusRevealedLock() { |
| if (!enabled_) |
| return; |
| @@ -824,7 +723,7 @@ void ImmersiveModeControllerAsh::UpdateFocusRevealedLock() { |
| } |
| } |
| -bool ImmersiveModeControllerAsh::UpdateRevealedLocksForSwipe( |
| +bool ImmersiveFullscreenController::UpdateRevealedLocksForSwipe( |
| SwipeType swipe_type) { |
| if (!enabled_ || swipe_type == SWIPE_NONE) |
| return false; |
| @@ -856,38 +755,7 @@ bool ImmersiveModeControllerAsh::UpdateRevealedLocksForSwipe( |
| return false; |
| } |
| -void ImmersiveModeControllerAsh::UpdateUseMinimalChrome(Layout layout) { |
| - // May be NULL in tests. |
| - FullscreenController* fullscreen_controller = |
| - delegate_->GetFullscreenController(); |
| - bool in_tab_fullscreen = fullscreen_controller ? |
| - fullscreen_controller->IsFullscreenForTabOrPending() : false; |
| - bool use_minimal_chrome = !in_tab_fullscreen && enabled_; |
| - |
| - // When using minimal chrome, the shelf is auto-hidden. The auto-hidden shelf |
| - // displays a 3px 'light bar' when it is closed. Otherwise, the shelf is |
| - // hidden completely and cannot be revealed. |
| - ash::wm::GetWindowState(native_window_)->set_hide_shelf_when_fullscreen( |
| - !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; |
| - } |
| - |
| - 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 (layout == LAYOUT_YES && reveal_state_ == CLOSED) |
| - LayoutBrowserRootView(); |
| - } |
| -} |
| - |
| -int ImmersiveModeControllerAsh::GetAnimationDuration(Animate animate) const { |
| +int ImmersiveFullscreenController::GetAnimationDuration(Animate animate) const { |
| switch (animate) { |
| case ANIMATE_NO: |
| return 0; |
| @@ -900,7 +768,7 @@ int ImmersiveModeControllerAsh::GetAnimationDuration(Animate animate) const { |
| return 0; |
| } |
| -void ImmersiveModeControllerAsh::MaybeStartReveal(Animate animate) { |
| +void ImmersiveFullscreenController::MaybeStartReveal(Animate animate) { |
| if (!enabled_) |
| return; |
| @@ -915,60 +783,37 @@ void ImmersiveModeControllerAsh::MaybeStartReveal(Animate animate) { |
| } |
| RevealState previous_reveal_state = reveal_state_; |
| - reveal_state_ = SLIDING_OPEN; |
| + RevealState new_reveal_state = (animate == ANIMATE_NO) ? |
|
pkotwicz
2013/10/29 04:32:45
Removed this change because it does not need to be
|
| + REVEALED : SLIDING_OPEN; |
| + reveal_state_ = new_reveal_state; |
| if (previous_reveal_state == CLOSED) { |
| - // Turn on layer painting so that we can overlap the web contents. |
| - top_container_->SetPaintToLayer(true); |
| - |
| - // Ensure window caption buttons are updated and the view bounds are |
| - // computed at normal (non-immersive-style) size. The layout call moves the |
| - // top-of-window views to their initial offscreen position for the |
| - // animation. |
| - delegate_->SetImmersiveStyle(false); |
| - SetRenderWindowTopInsetsForTouch(0); |
| - LayoutBrowserRootView(); |
| - |
| - // Do not do any more processing if LayoutBrowserView() changed |
| + delegate_->OnImmersiveRevealStarted(); |
| + |
| + // Do not do any more processing if OnImmersiveRevealStarted() changed |
| // |reveal_state_|. |
| - if (reveal_state_ != SLIDING_OPEN) { |
| - if (reveal_state_ == REVEALED) |
| - FOR_EACH_OBSERVER(Observer, observers_, OnImmersiveRevealStarted()); |
| + if (reveal_state_ != new_reveal_state) |
| return; |
| - } |
| } |
| // Slide in the reveal view. |
| if (animate == ANIMATE_NO) { |
| animation_->Reset(1); |
| - OnSlideOpenAnimationCompleted(LAYOUT_YES); |
| + OnSlideOpenAnimationCompleted(); |
| } else { |
| animation_->SetSlideDuration(GetAnimationDuration(animate)); |
| animation_->Show(); |
| } |
| - |
| - if (previous_reveal_state == CLOSED) |
| - FOR_EACH_OBSERVER(Observer, observers_, OnImmersiveRevealStarted()); |
| -} |
| - |
| -void ImmersiveModeControllerAsh::LayoutBrowserRootView() { |
| - // Update the window caption buttons. |
| - widget_->non_client_view()->frame_view()->ResetWindowControls(); |
| - // Layout all views, including BrowserView. |
| - widget_->GetRootView()->Layout(); |
| } |
| -void ImmersiveModeControllerAsh::OnSlideOpenAnimationCompleted(Layout layout) { |
| - DCHECK_EQ(SLIDING_OPEN, reveal_state_); |
| +void ImmersiveFullscreenController::OnSlideOpenAnimationCompleted() { |
| reveal_state_ = REVEALED; |
| - |
| - if (layout == LAYOUT_YES) |
| - top_container_->parent()->Layout(); |
| + delegate_->SetVisibility(1); |
| // The user may not have moved the mouse since the reveal was initiated. |
| // Update the revealed lock to reflect the mouse's current state. |
| UpdateLocatedEventRevealedLock(NULL, ALLOW_REVEAL_WHILE_CLOSING_NO); |
| } |
| -void ImmersiveModeControllerAsh::MaybeEndReveal(Animate animate) { |
| +void ImmersiveFullscreenController::MaybeEndReveal(Animate animate) { |
| if (!enabled_ || revealed_lock_count_ != 0) |
| return; |
| @@ -993,19 +838,13 @@ void ImmersiveModeControllerAsh::MaybeEndReveal(Animate animate) { |
| } |
| } |
| -void ImmersiveModeControllerAsh::OnSlideClosedAnimationCompleted() { |
| - DCHECK_EQ(SLIDING_CLOSED, reveal_state_); |
| +void ImmersiveFullscreenController::OnSlideClosedAnimationCompleted() { |
| reveal_state_ = CLOSED; |
| - // Layers aren't needed after animation completes. |
| - top_container_->SetPaintToLayer(false); |
| - // Update tabstrip for closed state. |
| - delegate_->SetImmersiveStyle(true); |
| - SetRenderWindowTopInsetsForTouch(kNearTopContainerDistance); |
| - LayoutBrowserRootView(); |
| + delegate_->OnImmersiveRevealEnded(); |
| } |
| -ImmersiveModeControllerAsh::SwipeType ImmersiveModeControllerAsh::GetSwipeType( |
| - ui::GestureEvent* event) const { |
| +ImmersiveFullscreenController::SwipeType |
| +ImmersiveFullscreenController::GetSwipeType(ui::GestureEvent* event) const { |
| if (event->type() != ui::ET_GESTURE_SCROLL_UPDATE) |
| return SWIPE_NONE; |
| // Make sure that it is a clear vertical gesture. |
| @@ -1019,7 +858,7 @@ ImmersiveModeControllerAsh::SwipeType ImmersiveModeControllerAsh::GetSwipeType( |
| return SWIPE_NONE; |
| } |
| -bool ImmersiveModeControllerAsh::ShouldIgnoreMouseEventAtLocation( |
| +bool ImmersiveFullscreenController::ShouldIgnoreMouseEventAtLocation( |
| const gfx::Point& location) const { |
| // Ignore mouse events in the region immediately above the top edge of the |
| // display. This is to handle the case of a user with a vertical display |
| @@ -1034,57 +873,44 @@ bool ImmersiveModeControllerAsh::ShouldIgnoreMouseEventAtLocation( |
| // (Mouse events in this region cannot start or end a reveal). This allows a |
| // user to overshoot the top of the bottom display and still reveal the |
| // top-of-window views. |
| - gfx::Rect dead_region = top_container_->parent()->GetBoundsInScreen(); |
| + gfx::Rect dead_region = GetDisplayBoundsInScreen(native_window_); |
| dead_region.set_y(dead_region.y() - kHeightOfDeadRegionAboveTopContainer); |
| dead_region.set_height(kHeightOfDeadRegionAboveTopContainer); |
| return dead_region.Contains(location); |
| } |
| -bool ImmersiveModeControllerAsh::ShouldHandleGestureEvent( |
| +bool ImmersiveFullscreenController::ShouldHandleGestureEvent( |
| const gfx::Point& location) const { |
| - gfx::Rect top_container_bounds_in_screen = |
| - top_container_->GetBoundsInScreen(); |
| - |
| - // All of the gestures that are of interest start in a region with left & |
| - // right edges agreeing with |top_container_|. When CLOSED it is difficult to |
| - // hit the bounds due to small size of the tab strip, so the hit target needs |
| - // to be extended on the bottom, thus the inset call. |
| - gfx::Rect near_bounds = top_container_bounds_in_screen; |
| - if (reveal_state_ == CLOSED) |
| - near_bounds.Inset(gfx::Insets(0, 0, -kNearTopContainerDistance, 0)); |
| - if (near_bounds.Contains(location)) |
| + if (reveal_state_ == REVEALED) { |
| + std::vector<gfx::Rect> hit_bounds_in_screen( |
| + delegate_->GetVisibleBoundsInScreen()); |
| + for (size_t i = 0; i < hit_bounds_in_screen.size(); ++i) { |
| + if (hit_bounds_in_screen[i].Contains(location)) |
| + return true; |
| + } |
| + return false; |
| + } |
| + |
| + // When the top-of-window views are closed, handle gestures which start in the |
| + // top few pixels of the screen. |
| + gfx::Rect hit_bounds_in_screen(GetDisplayBoundsInScreen(native_window_)); |
| + hit_bounds_in_screen.set_height(kNearTopContainerDistance); |
| + if (hit_bounds_in_screen.Contains(location)) |
| return true; |
| - // There may be a bezel sensor off screen logically above |top_container_| |
| - // thus the test needs to include gestures starting above, but this needs to |
| - // be distinguished from events originating on another screen from |
| - // (potentially) an extended desktop. The check for the event not contained by |
| - // the closest screen ensures that the event is from a valid bezel and can be |
| - // interpreted as such. |
| + // There may be a bezel sensor off screen logically above |
| + // |hit_bounds_in_screen|. The check for the event not contained by the |
| + // closest screen ensures that the event is from a valid bezel (as opposed to |
| + // another screen in an extended desktop). |
| gfx::Rect screen_bounds = |
| ash::Shell::GetScreen()->GetDisplayNearestPoint(location).bounds(); |
| return (!screen_bounds.Contains(location) && |
| - location.y() < top_container_bounds_in_screen.y() && |
| - location.x() >= top_container_bounds_in_screen.x() && |
| - location.x() < top_container_bounds_in_screen.right()); |
| -} |
| - |
| -void ImmersiveModeControllerAsh::SetRenderWindowTopInsetsForTouch( |
| - int top_inset) { |
| - content::WebContents* contents = delegate_->GetWebContents(); |
| - if (contents) { |
| - aura::Window* window = contents->GetView()->GetContentNativeView(); |
| - // |window| is NULL if the renderer crashed. |
| - if (window) { |
| - gfx::Insets inset(top_inset, 0, 0, 0); |
| - window->SetHitTestBoundsOverrideOuter( |
| - window->hit_test_bounds_override_outer_mouse(), |
| - inset); |
| - } |
| - } |
| + location.y() < hit_bounds_in_screen.y() && |
| + location.x() >= hit_bounds_in_screen.x() && |
| + location.x() < hit_bounds_in_screen.right()); |
| } |
| -void ImmersiveModeControllerAsh::RecreateBubbleManager() { |
| +void ImmersiveFullscreenController::RecreateBubbleManager() { |
| bubble_manager_.reset(new BubbleManager(this)); |
| const std::vector<aura::Window*> transient_children = |
| native_window_->transient_children(); |
| @@ -1099,3 +925,5 @@ void ImmersiveModeControllerAsh::RecreateBubbleManager() { |
| } |
| } |
| } |
| + |
| +} // namespace ash |