immersive_mode_controller.h revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
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 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_UI_VIEWS_FRAME_IMMERSIVE_MODE_CONTROLLER_H_ 6#define CHROME_BROWSER_UI_VIEWS_FRAME_IMMERSIVE_MODE_CONTROLLER_H_ 7 8#include "base/compiler_specific.h" 9 10class BookmarkBarView; 11class FullscreenController; 12 13namespace gfx { 14class Rect; 15class Size; 16} 17 18namespace views { 19class View; 20class Widget; 21} 22 23// Base class for a lock which keeps the top-of-window views revealed for the 24// duration of its lifetime. See ImmersiveModeController::GetRevealedLock() for 25// more details. 26class ImmersiveRevealedLock { 27 public: 28 virtual ~ImmersiveRevealedLock() {} 29}; 30 31// Controller for an "immersive mode" similar to MacOS presentation mode where 32// the top-of-window views are hidden until the mouse hits the top of the 33// screen. The tab strip is optionally painted with miniature "tab indicator" 34// rectangles. 35// Currently, immersive mode is only available for Chrome OS. 36class ImmersiveModeController { 37 public: 38 enum AnimateReveal { 39 ANIMATE_REVEAL_YES, 40 ANIMATE_REVEAL_NO 41 }; 42 43 class Delegate { 44 public: 45 // Returns the bookmark bar, or NULL if the window does not support one. 46 virtual BookmarkBarView* GetBookmarkBar() = 0; 47 48 // Returns the browser's FullscreenController. 49 virtual FullscreenController* GetFullscreenController() = 0; 50 51 // Notifies the delegate that fullscreen has been entered or exited. 52 virtual void FullscreenStateChanged() = 0; 53 54 // Requests that the tab strip be painted in a short, "light bar" style. 55 virtual void SetImmersiveStyle(bool immersive) = 0; 56 57 protected: 58 virtual ~Delegate() {} 59 }; 60 61 virtual ~ImmersiveModeController() {} 62 63 // Must initialize after browser view has a Widget and native window. 64 virtual void Init(Delegate* delegate, 65 views::Widget* widget, 66 views::View* top_container) = 0; 67 68 // Enables or disables immersive mode. 69 virtual void SetEnabled(bool enabled) = 0; 70 virtual bool IsEnabled() const = 0; 71 72 // True if the miniature "tab indicators" should be hidden in the main browser 73 // view when immersive mode is enabled. 74 virtual bool ShouldHideTabIndicators() const = 0; 75 76 // True when the top views are hidden due to immersive mode. 77 virtual bool ShouldHideTopViews() const = 0; 78 79 // True when the top views are fully or partially visible. 80 virtual bool IsRevealed() const = 0; 81 82 // Returns the top container's vertical offset relative to its parent. When 83 // revealing or closing the top-of-window views, part of the top container is 84 // offscreen. 85 // This method takes in the top container's size because it is called as part 86 // of computing the new bounds for the top container in 87 // BrowserViewLayout::UpdateTopContainerBounds(). 88 virtual int GetTopContainerVerticalOffset( 89 const gfx::Size& top_container_size) const = 0; 90 91 // Returns a lock which will keep the top-of-window views revealed for its 92 // lifetime. Several locks can be obtained. When all of the locks are 93 // destroyed, if immersive mode is enabled and there is nothing else keeping 94 // the top-of-window views revealed, the top-of-window views will be closed. 95 // This method always returns a valid lock regardless of whether immersive 96 // mode is enabled. The lock's lifetime can span immersive mode being 97 // enabled / disabled. 98 // If acquiring the lock causes a reveal, the top-of-window views will animate 99 // according to |animate_reveal|. 100 // The caller takes ownership of the returned lock. 101 virtual ImmersiveRevealedLock* GetRevealedLock( 102 AnimateReveal animate_reveal) WARN_UNUSED_RESULT = 0; 103 104 // Anchor |widget| to the top-of-window views. This repositions |widget| such 105 // that it stays |y_offset| below the top-of-window views when the 106 // top-of-window views are animating (top-of-window views reveal / unreveal) 107 // or the top container's bounds change (eg the bookmark bar is shown). 108 // If the top-of-window views are revealed (or become revealed), |widget| 109 // will keep the top-of-window views revealed till either |widget| is hidden 110 // or UnanchorWidgetFromTopContainer() is called. 111 // It is legal for a widget to be anchored when immersive fullscreen is 112 // disabled, however it will have no effect till immersive fullscreen is 113 // enabled. 114 virtual void AnchorWidgetToTopContainer(views::Widget* widget, 115 int y_offset) = 0; 116 117 // Stops managing |widget|'s y position. 118 // Closes the top-of-window views if no locks or other anchored widgets are 119 // keeping the top-of-window views revealed. 120 virtual void UnanchorWidgetFromTopContainer(views::Widget* widget) = 0; 121 122 // Called by the TopContainerView to indicate that its bounds have changed. 123 virtual void OnTopContainerBoundsChanged() = 0; 124 125 // Called by the find bar to indicate that its visible bounds have changed. 126 // |new_visible_bounds_in_screen| should be empty if the find bar is not 127 // visible. 128 virtual void OnFindBarVisibleBoundsChanged( 129 const gfx::Rect& new_visible_bounds_in_screen) = 0; 130}; 131 132namespace chrome { 133 134// Implemented in immersive_mode_controller_factory.cc. 135ImmersiveModeController* CreateImmersiveModeController(); 136 137} // namespace chrome 138 139#endif // CHROME_BROWSER_UI_VIEWS_FRAME_IMMERSIVE_MODE_CONTROLLER_H_ 140