This source file includes following definitions.
- capture_window_
- SetCapture
- ReleaseCapture
- GetCaptureWindow
- GetGlobalCaptureWindow
#include "ui/views/widget/desktop_aura/desktop_capture_client.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_tree_host.h"
namespace views {
DesktopCaptureClient::CaptureClients*
DesktopCaptureClient::capture_clients_ = NULL;
DesktopCaptureClient::DesktopCaptureClient(aura::Window* root)
: root_(root),
capture_window_(NULL) {
if (!capture_clients_)
capture_clients_ = new CaptureClients;
capture_clients_->insert(this);
aura::client::SetCaptureClient(root, this);
}
DesktopCaptureClient::~DesktopCaptureClient() {
aura::client::SetCaptureClient(root_, NULL);
capture_clients_->erase(this);
}
void DesktopCaptureClient::SetCapture(aura::Window* new_capture_window) {
if (capture_window_ == new_capture_window)
return;
DCHECK(!new_capture_window ||
(new_capture_window->GetRootWindow() == root_));
DCHECK(!capture_window_ || capture_window_->GetRootWindow());
aura::Window* old_capture_window = capture_window_;
if (new_capture_window) {
ui::GestureRecognizer::Get()->TransferEventsTo(old_capture_window,
new_capture_window);
}
capture_window_ = new_capture_window;
aura::client::CaptureDelegate* delegate = root_->GetHost()->dispatcher();
delegate->UpdateCapture(old_capture_window, new_capture_window);
if (!capture_window_) {
delegate->ReleaseNativeCapture();
} else if (!old_capture_window) {
delegate->SetNativeCapture();
CaptureClients capture_clients(*capture_clients_);
for (CaptureClients::iterator i = capture_clients.begin();
i != capture_clients.end(); ++i) {
if (*i != this) {
aura::client::CaptureDelegate* delegate =
(*i)->root_->GetHost()->dispatcher();
delegate->OnOtherRootGotCapture();
}
}
}
}
void DesktopCaptureClient::ReleaseCapture(aura::Window* window) {
if (capture_window_ != window)
return;
SetCapture(NULL);
}
aura::Window* DesktopCaptureClient::GetCaptureWindow() {
return capture_window_;
}
aura::Window* DesktopCaptureClient::GetGlobalCaptureWindow() {
for (CaptureClients::iterator i = capture_clients_->begin();
i != capture_clients_->end(); ++i) {
if ((*i)->capture_window_)
return (*i)->capture_window_;
}
return NULL;
}
}