Roll src/third_party/skia d32087a:1052f51
[chromium-blink-merge.git] / ui / wm / core / capture_controller.h
blobcc32ae77b21b3a53ce185b1d2d980b0ba82beb31
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_
8 #include <map>
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"
16 namespace aura {
17 namespace client {
18 class CaptureDelegate;
22 namespace wm {
24 // Internal CaptureClient implementation. See ScopedCaptureClient for details.
25 class WM_EXPORT CaptureController : public aura::client::CaptureClient {
26 public:
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
34 // root window.
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;
43 private:
44 friend class ScopedCaptureClient;
46 CaptureController();
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
55 // capture.
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 {
68 public:
69 class WM_EXPORT TestApi {
70 public:
71 explicit TestApi(ScopedCaptureClient* client) : client_(client) {}
72 ~TestApi() {}
74 // Sets the delegate.
75 void SetDelegate(aura::client::CaptureDelegate* delegate);
77 private:
78 // Not owned.
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;
97 private:
98 // Invoked from destructor and OnWindowDestroyed() to cleanup.
99 void Shutdown();
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);
110 } // namespace wm
112 #endif // UI_WM_CORE_CAPTURE_CONTROLLER_H_