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.
5 #include "ui/views/widget/desktop_aura/desktop_capture_client.h"
7 #include "ui/aura/window.h"
8 #include "ui/aura/window_event_dispatcher.h"
9 #include "ui/aura/window_tree_host.h"
14 DesktopCaptureClient::CaptureClients
*
15 DesktopCaptureClient::capture_clients_
= NULL
;
17 DesktopCaptureClient::DesktopCaptureClient(aura::Window
* root
)
19 capture_window_(NULL
) {
20 if (!capture_clients_
)
21 capture_clients_
= new CaptureClients
;
22 capture_clients_
->insert(this);
23 aura::client::SetCaptureClient(root
, this);
26 DesktopCaptureClient::~DesktopCaptureClient() {
27 aura::client::SetCaptureClient(root_
, NULL
);
28 capture_clients_
->erase(this);
31 void DesktopCaptureClient::SetCapture(aura::Window
* new_capture_window
) {
32 if (capture_window_
== new_capture_window
)
35 // We should only ever be told to capture a child of |root_|. Otherwise
36 // things are going to be really confused.
37 DCHECK(!new_capture_window
||
38 (new_capture_window
->GetRootWindow() == root_
));
39 DCHECK(!capture_window_
|| capture_window_
->GetRootWindow());
41 aura::Window
* old_capture_window
= capture_window_
;
43 // If we're starting a new capture, cancel all touches that aren't
44 // targeted to the capturing window.
45 if (new_capture_window
)
46 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(new_capture_window
);
48 capture_window_
= new_capture_window
;
50 aura::client::CaptureDelegate
* delegate
= root_
->GetHost()->dispatcher();
51 delegate
->UpdateCapture(old_capture_window
, new_capture_window
);
53 // Initiate native capture updating.
54 if (!capture_window_
) {
55 delegate
->ReleaseNativeCapture();
56 } else if (!old_capture_window
) {
57 delegate
->SetNativeCapture();
59 // Notify the other roots that we got capture. This is important so that
61 CaptureClients
capture_clients(*capture_clients_
);
62 for (CaptureClients::iterator i
= capture_clients
.begin();
63 i
!= capture_clients
.end(); ++i
) {
65 aura::client::CaptureDelegate
* delegate
=
66 (*i
)->root_
->GetHost()->dispatcher();
67 delegate
->OnOtherRootGotCapture();
70 } // else case is capture is remaining in our root, nothing to do.
73 void DesktopCaptureClient::ReleaseCapture(aura::Window
* window
) {
74 if (capture_window_
!= window
)
79 aura::Window
* DesktopCaptureClient::GetCaptureWindow() {
80 return capture_window_
;
83 aura::Window
* DesktopCaptureClient::GetGlobalCaptureWindow() {
84 for (CaptureClients::iterator i
= capture_clients_
->begin();
85 i
!= capture_clients_
->end(); ++i
) {
86 if ((*i
)->capture_window_
)
87 return (*i
)->capture_window_
;