immersive_mode_controller.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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 BrowserView;
11
12namespace views {
13class Widget;
14}
15
16// Base class for a lock which keeps the top-of-window views revealed for the
17// duration of its lifetime. See ImmersiveModeController::GetRevealedLock() for
18// more details.
19class ImmersiveRevealedLock {
20 public:
21  virtual ~ImmersiveRevealedLock() {}
22};
23
24// Controller for an "immersive mode" similar to MacOS presentation mode where
25// the top-of-window views are hidden until the mouse hits the top of the
26// screen. The tab strip is optionally painted with miniature "tab indicator"
27// rectangles.
28// Currently, immersive mode is only available for Chrome OS.
29class ImmersiveModeController {
30 public:
31  enum AnimateReveal {
32    ANIMATE_REVEAL_YES,
33    ANIMATE_REVEAL_NO
34  };
35
36  virtual ~ImmersiveModeController() {}
37
38  // Must initialize after browser view has a Widget and native window.
39  virtual void Init(BrowserView* browser_view) = 0;
40
41  // Enables or disables immersive mode.
42  virtual void SetEnabled(bool enabled) = 0;
43  virtual bool IsEnabled() const = 0;
44
45  // True if the miniature "tab indicators" should be hidden in the main browser
46  // view when immersive mode is enabled.
47  virtual bool ShouldHideTabIndicators() const = 0;
48
49  // True when the top views are hidden due to immersive mode.
50  virtual bool ShouldHideTopViews() const = 0;
51
52  // True when the top views are fully or partially visible.
53  virtual bool IsRevealed() const = 0;
54
55  // If the controller is temporarily revealing the top views ensures that
56  // the reveal view's layer is on top and hence visible over web contents.
57  virtual void MaybeStackViewAtTop() = 0;
58
59  // Returns a lock which will keep the top-of-window views revealed for its
60  // lifetime. Several locks can be obtained. When all of the locks are
61  // destroyed, if immersive mode is enabled and there is nothing else keeping
62  // the top-of-window views revealed, the top-of-window views will be closed.
63  // This method always returns a valid lock regardless of whether immersive
64  // mode is enabled. The lock's lifetime can span immersive mode being
65  // enabled / disabled.
66  // If acquiring the lock causes a reveal, the top-of-window views will animate
67  // according to |animate_reveal|.
68  // The caller takes ownership of the returned lock.
69  virtual ImmersiveRevealedLock* GetRevealedLock(
70      AnimateReveal animate_reveal) WARN_UNUSED_RESULT = 0;
71
72  // Anchor |widget| to the top-of-window views. This repositions |widget| such
73  // that it stays |y_offset| below the top-of-window views when the
74  // top-of-window views are animating (top-of-window views reveal / unreveal)
75  // or the top container's bounds change (eg the bookmark bar is shown).
76  // If the top-of-window views are revealed (or become revealed), |widget|
77  // will keep the top-of-window views revealed till either |widget| is hidden
78  // or UnanchorWidgetFromTopContainer() is called.
79  // It is legal for a widget to be anchored when immersive fullscreen is
80  // disabled, however it will have no effect till immersive fullscreen is
81  // enabled.
82  virtual void AnchorWidgetToTopContainer(views::Widget* widget,
83                                          int y_offset) = 0;
84
85  // Stops managing |widget|'s y position.
86  // Closes the top-of-window views if no locks or other anchored widgets are
87  // keeping the top-of-window views revealed.
88  virtual void UnanchorWidgetFromTopContainer(views::Widget* widget) = 0;
89
90  // Called by the TopContainerView to indicate that its bounds have changed.
91  virtual void OnTopContainerBoundsChanged() = 0;
92};
93
94namespace chrome {
95
96// Returns true if immersive mode should be used for fullscreen based on
97// command line flags.
98// Implemented in immersive_mode_controller_factory.cc.
99bool UseImmersiveFullscreen();
100
101// Implemented in immersive_mode_controller_factory.cc.
102void EnableImmersiveFullscreenForTest();
103
104// Implemented in immersive_mode_controller_factory.cc.
105ImmersiveModeController* CreateImmersiveModeController();
106
107}  // namespace chrome
108
109#endif  // CHROME_BROWSER_UI_VIEWS_FRAME_IMMERSIVE_MODE_CONTROLLER_H_
110