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