Home | History | Annotate | Download | only in win
      1 // Copyright 2013 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 UI_VIEWS_WIN_APPBAR_H_
      6 #define UI_VIEWS_WIN_APPBAR_H_
      7 
      8 #include <map>
      9 
     10 #include <windows.h>
     11 
     12 #include "base/basictypes.h"
     13 #include "base/callback_forward.h"
     14 #include "base/memory/weak_ptr.h"
     15 
     16 namespace views {
     17 
     18 // Appbar provides an API to query for the edges of the monitor that have an
     19 // autohide bar.
     20 // NOTE: querying is done on a separate thread as it spawns a nested message
     21 // loop. The nested message loop is particularly problematic here as it's
     22 // possible for the nested message loop to run during window creation and
     23 // startup time (WM_NCCALCSIZE is called at creation time).
     24 class Appbar {
     25  public:
     26   enum Edge {
     27     EDGE_TOP    = 1 << 0,
     28     EDGE_LEFT   = 1 << 1,
     29     EDGE_BOTTOM = 1 << 2,
     30     EDGE_RIGHT  = 1 << 3,
     31   };
     32 
     33   // Returns the singleton instance.
     34   static Appbar* instance();
     35 
     36   // Starts a query for the autohide edges of the specified monitor and returns
     37   // the current value. If the edges have changed |callback| is subsequently
     38   // invoked. If the edges have not changed |callback| is never run.
     39   //
     40   // Return value is a bitmask of Edges.
     41   int GetAutohideEdges(HMONITOR monitor, const base::Closure& callback);
     42 
     43  private:
     44   typedef std::map<HMONITOR, int> EdgeMap;
     45 
     46   Appbar();
     47   ~Appbar();
     48 
     49   // Callback on main thread with the edges. |returned_edges| is the value that
     50   // was returned from the call to GetAutohideEdges() that initiated the lookup.
     51   void OnGotEdges(const base::Closure& callback,
     52                   HMONITOR monitor,
     53                   int returned_edges,
     54                   int* edges);
     55 
     56   EdgeMap edge_map_;
     57 
     58   base::WeakPtrFactory<Appbar> weak_factory_;
     59 
     60   // If true we're in the process of notifying a callback. When true we do not
     61   // start a new query.
     62   bool in_callback_;
     63 
     64   DISALLOW_COPY_AND_ASSIGN(Appbar);
     65 };
     66 
     67 }  // namespace views
     68 
     69 #endif  // UI_VIEWS_WIN_APPBAR_H_
     70 
     71