• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 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 UI_WM_CORE_CAPTURE_CONTROLLER_H_
6 #define UI_WM_CORE_CAPTURE_CONTROLLER_H_
7 
8 #include <set>
9 
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "ui/aura/client/capture_client.h"
13 #include "ui/aura/window_observer.h"
14 #include "ui/wm/wm_export.h"
15 
16 namespace wm {
17 
18 // Internal CaptureClient implementation. See ScopedCaptureClient for details.
19 class WM_EXPORT CaptureController : public aura::client::CaptureClient {
20  public:
21   // Adds |root| to the list of RootWindows notified when capture changes.
22   void Attach(aura::Window* root);
23 
24   // Removes |root| from the list of RootWindows notified when capture changes.
25   void Detach(aura::Window* root);
26 
27   // Returns true if this CaptureController is installed on at least one
28   // RootWindow.
is_active()29   bool is_active() const { return !root_windows_.empty(); }
30 
31   // Overridden from aura::client::CaptureClient:
32   virtual void SetCapture(aura::Window* window) OVERRIDE;
33   virtual void ReleaseCapture(aura::Window* window) OVERRIDE;
34   virtual aura::Window* GetCaptureWindow() OVERRIDE;
35   virtual aura::Window* GetGlobalCaptureWindow() OVERRIDE;
36 
37  private:
38   friend class ScopedCaptureClient;
39   typedef std::set<aura::Window*> RootWindows;
40 
41   CaptureController();
42   virtual ~CaptureController();
43 
44   // The current capture window. NULL if there is no capture window.
45   aura::Window* capture_window_;
46 
47   // Set of RootWindows notified when capture changes.
48   RootWindows root_windows_;
49 
50   DISALLOW_COPY_AND_ASSIGN(CaptureController);
51 };
52 
53 // ScopedCaptureClient is responsible for creating a CaptureClient for a
54 // RootWindow. Specifically it creates a single CaptureController that is shared
55 // among all ScopedCaptureClients and adds the RootWindow to it.
56 class WM_EXPORT ScopedCaptureClient : public aura::WindowObserver {
57  public:
58   explicit ScopedCaptureClient(aura::Window* root);
59   virtual ~ScopedCaptureClient();
60 
61   // Returns true if there is a CaptureController with at least one RootWindow.
62   static bool IsActive();
63 
capture_client()64   aura::client::CaptureClient* capture_client() {
65     return capture_controller_;
66   }
67 
68   // Overridden from aura::WindowObserver:
69   virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE;
70 
71  private:
72   // Invoked from destructor and OnWindowDestroyed() to cleanup.
73   void Shutdown();
74 
75   // The single CaptureController instance.
76   static CaptureController* capture_controller_;
77 
78   // RootWindow this ScopedCaptureClient was create for.
79   aura::Window* root_window_;
80 
81   DISALLOW_COPY_AND_ASSIGN(ScopedCaptureClient);
82 };
83 
84 }  // namespace wm
85 
86 #endif  // UI_WM_CORE_CAPTURE_CONTROLLER_H_
87