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