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/root_window.h"
8 #include "ui/aura/window.h"
13 DesktopCaptureClient::CaptureClients*
14 DesktopCaptureClient::capture_clients_ = NULL;
16 DesktopCaptureClient::DesktopCaptureClient(aura::RootWindow* root)
18 capture_window_(NULL) {
19 if (!capture_clients_)
20 capture_clients_ = new CaptureClients;
21 capture_clients_->insert(this);
22 aura::client::SetCaptureClient(root, this);
25 DesktopCaptureClient::~DesktopCaptureClient() {
26 aura::client::SetCaptureClient(root_, NULL);
27 capture_clients_->erase(this);
30 void DesktopCaptureClient::SetCapture(aura::Window* new_capture_window) {
31 if (capture_window_ == new_capture_window)
34 // We should only ever be told to capture a child of |root_|. Otherwise
35 // things are going to be really confused.
36 DCHECK(!new_capture_window ||
37 (new_capture_window->GetRootWindow() == root_));
38 DCHECK(!capture_window_ || capture_window_->GetRootWindow());
40 aura::Window* old_capture_window = capture_window_;
42 // If we're actually starting capture, then cancel any touches/gestures
43 // that aren't already locked to the new window, and transfer any on the
44 // old capture window to the new one. When capture is released we have no
45 // distinction between the touches/gestures that were in the window all
46 // along (and so shouldn't be canceled) and those that got moved, so
47 // just leave them all where they are.
48 if (new_capture_window) {
49 ui::GestureRecognizer::Get()->TransferEventsTo(old_capture_window,
53 capture_window_ = new_capture_window;
55 aura::client::CaptureDelegate* delegate = root_;
56 delegate->UpdateCapture(old_capture_window, new_capture_window);
58 // Initiate native capture updating.
59 if (!capture_window_) {
60 delegate->ReleaseNativeCapture();
61 } else if (!old_capture_window) {
62 delegate->SetNativeCapture();
64 // Notify the other roots that we got capture. This is important so that
66 CaptureClients capture_clients(*capture_clients_);
67 for (CaptureClients::iterator i = capture_clients.begin();
68 i != capture_clients.end(); ++i) {
70 aura::client::CaptureDelegate* delegate = (*i)->root_;
71 delegate->OnOtherRootGotCapture();
74 } // else case is capture is remaining in our root, nothing to do.
77 void DesktopCaptureClient::ReleaseCapture(aura::Window* window) {
78 if (capture_window_ != window)
83 aura::Window* DesktopCaptureClient::GetCaptureWindow() {
84 return capture_window_;