1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_FRAME_IMMERSIVE_MODE_CONTROLLER_H_
#define CHROME_BROWSER_UI_VIEWS_FRAME_IMMERSIVE_MODE_CONTROLLER_H_
#include <memory>
#include "base/observer_list.h"
class BrowserView;
namespace gfx {
class Rect;
class Size;
} // namespace gfx
namespace views {
class Widget;
}
// A lock which will keep the top-of-window views revealed for its
// lifetime.
// See ImmersiveModeController::GetRevealedLock for details.
class ImmersiveRevealedLock {
public:
virtual ~ImmersiveRevealedLock() = default;
protected:
ImmersiveRevealedLock() = default;
};
// Controller for an "immersive mode" similar to MacOS presentation mode where
// the top-of-window views are hidden until the mouse hits the top of the
// screen. The tab strip is optionally painted with miniature "tab indicator"
// rectangles.
// Currently, immersive mode is only available for Chrome OS and macOS.
class ImmersiveModeController {
public:
enum AnimateReveal { ANIMATE_REVEAL_YES, ANIMATE_REVEAL_NO };
class Observer {
public:
// Called when a reveal of the top-of-window views has been initiated.
virtual void OnImmersiveRevealStarted() {}
// Called when a reveal of the top-of-window views has finished.
virtual void OnImmersiveRevealEnded() {}
// Called when the immersive mode controller has been destroyed.
virtual void OnImmersiveModeControllerDestroyed() {}
// Called when immersive mode is entered.
virtual void OnImmersiveFullscreenEntered() {}
// Called when immersive mode is exited.
virtual void OnImmersiveFullscreenExited() {}
protected:
virtual ~Observer() = default;
};
ImmersiveModeController();
ImmersiveModeController(const ImmersiveModeController&) = delete;
ImmersiveModeController& operator=(const ImmersiveModeController&) = delete;
virtual ~ImmersiveModeController();
// Must initialize after browser view has a Widget and native window.
virtual void Init(BrowserView* browser_view) = 0;
// Enables or disables immersive mode.
virtual void SetEnabled(bool enabled) = 0;
virtual bool IsEnabled() const = 0;
// True when the top views are hidden due to immersive mode.
virtual bool ShouldHideTopViews() const = 0;
// True when the top views are fully or partially visible.
virtual bool IsRevealed() const = 0;
// Returns the top container's vertical offset relative to its parent. When
// revealing or closing the top-of-window views, part of the top container is
// offscreen.
// This method takes in the top container's size because it is called as part
// of computing the new bounds for the top container in
// BrowserViewLayout::UpdateTopContainerBounds().
virtual int GetTopContainerVerticalOffset(
const gfx::Size& top_container_size) const = 0;
// Returns a lock which will keep the top-of-window views revealed for its
// lifetime. Several locks can be obtained. When all of the locks are
// destroyed, if immersive mode is enabled and there is nothing else keeping
// the top-of-window views revealed, the top-of-window views will be closed.
// This method always returns a valid lock regardless of whether immersive
// mode is enabled. The lock's lifetime can span immersive mode being
// enabled / disabled.
// If acquiring the lock causes a reveal, the top-of-window views will animate
// according to `animate_reveal`.
// This is currently only supported on Ash.
virtual std::unique_ptr<ImmersiveRevealedLock> GetRevealedLock(
AnimateReveal animate_reveal) = 0;
// Called by the find bar to indicate that its visible bounds have changed.
// `new_visible_bounds_in_screen` should be empty if the find bar is not
// visible.
virtual void OnFindBarVisibleBoundsChanged(
const gfx::Rect& new_visible_bounds_in_screen) = 0;
// Returns true if we should stay in immersive mode after exiting fullscreen.
// This should be true unless we are leaving fullscreen while in tablet mode,
// in which case we should stay in immersive mode.
virtual bool ShouldStayImmersiveAfterExitingFullscreen() = 0;
// Called by browser view to indicate the widget activation has changed.
// Immersive mode should be enabled/disabled if the widget is
// active/nonactive when the auto hide title bars in tablet mode feature is
// on.
virtual void OnWidgetActivationChanged(views::Widget* widget,
bool active) = 0;
// Returns the minimum y-offset for the web contents. Used on Mac to prevent
// find results from hiding under the top chrome when the find bar is in use.
virtual int GetMinimumContentOffset() const = 0;
// Returns an offset to add to the vertical origin of the infobar while
// laying out the browser view. Used on Mac to ensure the infobar stays
// visible when revealing topchrome.
virtual int GetExtraInfobarOffset() const = 0;
// Called when entering or exiting content fullscreen.
// Content fullscreen is distinct from browser fullscreen. Content fullscreen
// is when a single tab enters fullscreen, where browser fullscreen is when
// the entire browser window, including toolbar, is fullscreen.
// This is currently only used on macOS.
virtual void OnContentFullscreenChanged(bool is_content_fullscreen) = 0;
virtual void AddObserver(Observer* observer);
virtual void RemoveObserver(Observer* observer);
protected:
base::ObserverList<Observer>::Unchecked observers_;
};
class BrowserView;
namespace chrome {
// Implemented in immersive_mode_controller_factory.cc.
std::unique_ptr<ImmersiveModeController> CreateImmersiveModeController(
const BrowserView* browser_view);
} // namespace chrome
#endif // CHROME_BROWSER_UI_VIEWS_FRAME_IMMERSIVE_MODE_CONTROLLER_H_
|