immersive_mode_controller.h revision a02191e04bc25c4935f804f2c080ae28663d096d
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#include "base/observer_list.h" 10#include "chrome/browser/ui/host_desktop.h" 11 12#if defined(USE_ASH) 13#include "ash/wm/immersive_revealed_lock.h" 14#endif 15 16class BrowserView; 17 18namespace gfx { 19class Rect; 20class Size; 21} 22 23#if defined(USE_ASH) 24typedef ash::ImmersiveRevealedLock ImmersiveRevealedLock; 25#else 26// Do nothing version of ash::ImmersiveRevealedLock. 27class ImmersiveRevealedLock { 28 public: 29 ImmersiveRevealedLock() {} 30 ~ImmersiveRevealedLock() {} 31}; 32#endif 33 34// Controller for an "immersive mode" similar to MacOS presentation mode where 35// the top-of-window views are hidden until the mouse hits the top of the 36// screen. The tab strip is optionally painted with miniature "tab indicator" 37// rectangles. 38// Currently, immersive mode is only available for Chrome OS. 39class ImmersiveModeController { 40 public: 41 enum AnimateReveal { 42 ANIMATE_REVEAL_YES, 43 ANIMATE_REVEAL_NO 44 }; 45 46 class Observer { 47 public: 48 // Called when a reveal of the top-of-window views has been initiated. 49 virtual void OnImmersiveRevealStarted() {} 50 51 // Called when the immersive mode controller has been destroyed. 52 virtual void OnImmersiveModeControllerDestroyed() {} 53 54 protected: 55 virtual ~Observer() {} 56 }; 57 58 ImmersiveModeController(); 59 virtual ~ImmersiveModeController(); 60 61 // Must initialize after browser view has a Widget and native window. 62 virtual void Init(BrowserView* browser_view) = 0; 63 64 // Enables or disables immersive mode. 65 virtual void SetEnabled(bool enabled) = 0; 66 virtual bool IsEnabled() const = 0; 67 68 // True if the miniature "tab indicators" should be hidden in the main browser 69 // view when immersive mode is enabled. 70 virtual bool ShouldHideTabIndicators() const = 0; 71 72 // True when the top views are hidden due to immersive mode. 73 virtual bool ShouldHideTopViews() const = 0; 74 75 // True when the top views are fully or partially visible. 76 virtual bool IsRevealed() const = 0; 77 78 // Returns the top container's vertical offset relative to its parent. When 79 // revealing or closing the top-of-window views, part of the top container is 80 // offscreen. 81 // This method takes in the top container's size because it is called as part 82 // of computing the new bounds for the top container in 83 // BrowserViewLayout::UpdateTopContainerBounds(). 84 virtual int GetTopContainerVerticalOffset( 85 const gfx::Size& top_container_size) const = 0; 86 87 // Returns a lock which will keep the top-of-window views revealed for its 88 // lifetime. Several locks can be obtained. When all of the locks are 89 // destroyed, if immersive mode is enabled and there is nothing else keeping 90 // the top-of-window views revealed, the top-of-window views will be closed. 91 // This method always returns a valid lock regardless of whether immersive 92 // mode is enabled. The lock's lifetime can span immersive mode being 93 // enabled / disabled. 94 // If acquiring the lock causes a reveal, the top-of-window views will animate 95 // according to |animate_reveal|. 96 // The caller takes ownership of the returned lock. 97 virtual ImmersiveRevealedLock* GetRevealedLock( 98 AnimateReveal animate_reveal) WARN_UNUSED_RESULT = 0; 99 100 // Called by the find bar to indicate that its visible bounds have changed. 101 // |new_visible_bounds_in_screen| should be empty if the find bar is not 102 // visible. 103 virtual void OnFindBarVisibleBoundsChanged( 104 const gfx::Rect& new_visible_bounds_in_screen) = 0; 105 106 // Disables animations and moves the mouse so that it is not over the 107 // top-of-window views for the sake of testing. Must be called before 108 // enabling immersive fullscreen. 109 virtual void SetupForTest() = 0; 110 111 virtual void AddObserver(Observer* observer); 112 virtual void RemoveObserver(Observer* observer); 113 114 protected: 115 ObserverList<Observer> observers_; 116 117 private: 118 DISALLOW_COPY_AND_ASSIGN(ImmersiveModeController); 119}; 120 121namespace chrome { 122 123// Implemented in immersive_mode_controller_factory.cc. 124ImmersiveModeController* CreateImmersiveModeController( 125 chrome::HostDesktopType host_desktop_type); 126 127} // namespace chrome 128 129#endif // CHROME_BROWSER_UI_VIEWS_FRAME_IMMERSIVE_MODE_CONTROLLER_H_ 130