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.
5 #ifndef UI_WM_CORE_CAPTURE_CONTROLLER_H_
6 #define UI_WM_CORE_CAPTURE_CONTROLLER_H_
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"
18 class CaptureDelegate
;
24 // Internal CaptureClient implementation. See ScopedCaptureClient for details.
25 class WM_EXPORT CaptureController
: public aura::client::CaptureClient
{
27 // Adds |root| to the list of root windows notified when capture changes.
28 void Attach(aura::Window
* root
);
30 // Removes |root| from the list of root windows notified when capture changes.
31 void Detach(aura::Window
* root
);
33 // Returns true if this CaptureController is installed on at least one
35 bool is_active() const { return !delegates_
.empty(); }
37 // Overridden from aura::client::CaptureClient:
38 void SetCapture(aura::Window
* window
) override
;
39 void ReleaseCapture(aura::Window
* window
) override
;
40 aura::Window
* GetCaptureWindow() override
;
41 aura::Window
* GetGlobalCaptureWindow() override
;
44 friend class ScopedCaptureClient
;
47 ~CaptureController() override
;
49 // The current capture window. NULL if there is no capture window.
50 aura::Window
* capture_window_
;
52 // The capture delegate for the root window with native capture. The root
53 // window with native capture may not contain |capture_window_|. This occurs
54 // if |capture_window_| is reparented to a different root window while it has
56 aura::client::CaptureDelegate
* capture_delegate_
;
58 // The delegates notified when capture changes.
59 std::map
<aura::Window
*, aura::client::CaptureDelegate
*> delegates_
;
61 DISALLOW_COPY_AND_ASSIGN(CaptureController
);
64 // ScopedCaptureClient is responsible for creating a CaptureClient for a
65 // RootWindow. Specifically it creates a single CaptureController that is shared
66 // among all ScopedCaptureClients and adds the RootWindow to it.
67 class WM_EXPORT ScopedCaptureClient
: public aura::WindowObserver
{
69 class WM_EXPORT TestApi
{
71 explicit TestApi(ScopedCaptureClient
* client
) : client_(client
) {}
75 void SetDelegate(aura::client::CaptureDelegate
* delegate
);
79 ScopedCaptureClient
* client_
;
81 DISALLOW_COPY_AND_ASSIGN(TestApi
);
84 explicit ScopedCaptureClient(aura::Window
* root
);
85 ~ScopedCaptureClient() override
;
87 // Returns true if there is a CaptureController with at least one RootWindow.
88 static bool IsActive();
90 aura::client::CaptureClient
* capture_client() {
91 return capture_controller_
;
94 // Overridden from aura::WindowObserver:
95 void OnWindowDestroyed(aura::Window
* window
) override
;
98 // Invoked from destructor and OnWindowDestroyed() to cleanup.
101 // The single CaptureController instance.
102 static CaptureController
* capture_controller_
;
104 // RootWindow this ScopedCaptureClient was create for.
105 aura::Window
* root_window_
;
107 DISALLOW_COPY_AND_ASSIGN(ScopedCaptureClient
);
112 #endif // UI_WM_CORE_CAPTURE_CONTROLLER_H_