1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/views/corewm/capture_controller.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
namespace views {
namespace corewm {
////////////////////////////////////////////////////////////////////////////////
// CaptureController, public:
void CaptureController::Attach(aura::Window* root) {
DCHECK_EQ(0u, root_windows_.count(root));
root_windows_.insert(root);
aura::client::SetCaptureClient(root, this);
}
void CaptureController::Detach(aura::Window* root) {
root_windows_.erase(root);
aura::client::SetCaptureClient(root, NULL);
}
////////////////////////////////////////////////////////////////////////////////
// CaptureController, aura::client::CaptureClient implementation:
void CaptureController::SetCapture(aura::Window* new_capture_window) {
if (capture_window_ == new_capture_window)
return;
// Make sure window has a root window.
DCHECK(!new_capture_window || new_capture_window->GetRootWindow());
DCHECK(!capture_window_ || capture_window_->GetRootWindow());
aura::Window* old_capture_window = capture_window_;
aura::Window* old_capture_root = old_capture_window ?
old_capture_window->GetRootWindow() : NULL;
// Copy the list in case it's modified out from under us.
RootWindows root_windows(root_windows_);
// If we're actually starting capture, then cancel any touches/gestures
// that aren't already locked to the new window, and transfer any on the
// old capture window to the new one. When capture is released we have no
// distinction between the touches/gestures that were in the window all
// along (and so shouldn't be canceled) and those that got moved, so
// just leave them all where they are.
if (new_capture_window) {
ui::GestureRecognizer::Get()->TransferEventsTo(old_capture_window,
new_capture_window);
}
capture_window_ = new_capture_window;
for (RootWindows::const_iterator i = root_windows.begin();
i != root_windows.end(); ++i) {
aura::client::CaptureDelegate* delegate = (*i)->GetDispatcher();
delegate->UpdateCapture(old_capture_window, new_capture_window);
}
aura::Window* capture_root =
capture_window_ ? capture_window_->GetRootWindow() : NULL;
if (capture_root != old_capture_root) {
if (old_capture_root) {
aura::client::CaptureDelegate* delegate =
old_capture_root->GetDispatcher();
delegate->ReleaseNativeCapture();
}
if (capture_root) {
aura::client::CaptureDelegate* delegate = capture_root->GetDispatcher();
delegate->SetNativeCapture();
}
}
}
void CaptureController::ReleaseCapture(aura::Window* window) {
if (capture_window_ != window)
return;
SetCapture(NULL);
}
aura::Window* CaptureController::GetCaptureWindow() {
return capture_window_;
}
aura::Window* CaptureController::GetGlobalCaptureWindow() {
return capture_window_;
}
////////////////////////////////////////////////////////////////////////////////
// CaptureController, private:
CaptureController::CaptureController()
: capture_window_(NULL) {
}
CaptureController::~CaptureController() {
}
////////////////////////////////////////////////////////////////////////////////
// ScopedCaptureClient:
// static
CaptureController* ScopedCaptureClient::capture_controller_ = NULL;
ScopedCaptureClient::ScopedCaptureClient(aura::Window* root)
: root_window_(root) {
root->AddObserver(this);
if (!capture_controller_)
capture_controller_ = new CaptureController;
capture_controller_->Attach(root);
}
ScopedCaptureClient::~ScopedCaptureClient() {
Shutdown();
}
// static
bool ScopedCaptureClient::IsActive() {
return capture_controller_ && capture_controller_->is_active();
}
void ScopedCaptureClient::OnWindowDestroyed(aura::Window* window) {
DCHECK_EQ(window, root_window_);
Shutdown();
}
void ScopedCaptureClient::Shutdown() {
if (!root_window_)
return;
root_window_->RemoveObserver(this);
capture_controller_->Detach(root_window_);
if (!capture_controller_->is_active()) {
delete capture_controller_;
capture_controller_ = NULL;
}
root_window_ = NULL;
}
} // namespace corewm
} // namespace views
|