OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/aura/client/default_capture_client.h" | 5 #include "ui/aura/client/default_capture_client.h" |
6 | 6 |
| 7 #include "ui/aura/client/capture_client_observer.h" |
7 #include "ui/aura/window.h" | 8 #include "ui/aura/window.h" |
8 #include "ui/aura/window_event_dispatcher.h" | 9 #include "ui/aura/window_event_dispatcher.h" |
9 #include "ui/aura/window_tree_host.h" | 10 #include "ui/aura/window_tree_host.h" |
10 | 11 |
11 namespace aura { | 12 namespace aura { |
12 namespace client { | 13 namespace client { |
| 14 namespace { |
13 | 15 |
14 // static | |
15 // Track the active capture window across root windows. | 16 // Track the active capture window across root windows. |
16 Window* global_capture_window_ = nullptr; | 17 Window* global_capture_window_ = nullptr; |
17 | 18 |
| 19 } // namespace |
| 20 |
18 DefaultCaptureClient::DefaultCaptureClient(Window* root_window) | 21 DefaultCaptureClient::DefaultCaptureClient(Window* root_window) |
19 : root_window_(root_window), | 22 : root_window_(root_window), capture_window_(nullptr) { |
20 capture_window_(NULL) { | |
21 SetCaptureClient(root_window_, this); | 23 SetCaptureClient(root_window_, this); |
22 } | 24 } |
23 | 25 |
24 DefaultCaptureClient::~DefaultCaptureClient() { | 26 DefaultCaptureClient::~DefaultCaptureClient() { |
25 if (global_capture_window_ == capture_window_) | 27 if (global_capture_window_ == capture_window_) |
26 global_capture_window_ = nullptr; | 28 global_capture_window_ = nullptr; |
27 SetCaptureClient(root_window_, NULL); | 29 SetCaptureClient(root_window_, nullptr); |
28 } | 30 } |
29 | 31 |
30 void DefaultCaptureClient::SetCapture(Window* window) { | 32 void DefaultCaptureClient::SetCapture(Window* window) { |
31 if (capture_window_ == window) | 33 if (capture_window_ == window) |
32 return; | 34 return; |
33 if (window) | 35 if (window) |
34 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(window); | 36 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(window); |
35 | 37 |
36 Window* old_capture_window = capture_window_; | 38 Window* old_capture_window = capture_window_; |
37 capture_window_ = window; | 39 capture_window_ = window; |
38 global_capture_window_ = window; | 40 global_capture_window_ = window; |
39 | 41 |
40 CaptureDelegate* capture_delegate = root_window_->GetHost()->dispatcher(); | 42 CaptureDelegate* capture_delegate = root_window_->GetHost()->dispatcher(); |
41 if (capture_window_) | 43 if (capture_window_) |
42 capture_delegate->SetNativeCapture(); | 44 capture_delegate->SetNativeCapture(); |
43 else | 45 else |
44 capture_delegate->ReleaseNativeCapture(); | 46 capture_delegate->ReleaseNativeCapture(); |
45 | 47 |
46 capture_delegate->UpdateCapture(old_capture_window, capture_window_); | 48 capture_delegate->UpdateCapture(old_capture_window, capture_window_); |
| 49 |
| 50 for (CaptureClientObserver& observer : observers_) |
| 51 observer.OnCaptureChanged(old_capture_window, capture_window_); |
47 } | 52 } |
48 | 53 |
49 void DefaultCaptureClient::ReleaseCapture(Window* window) { | 54 void DefaultCaptureClient::ReleaseCapture(Window* window) { |
50 if (capture_window_ != window) | 55 if (capture_window_ != window) |
51 return; | 56 return; |
52 SetCapture(NULL); | 57 SetCapture(NULL); |
53 } | 58 } |
54 | 59 |
55 Window* DefaultCaptureClient::GetCaptureWindow() { | 60 Window* DefaultCaptureClient::GetCaptureWindow() { |
56 return capture_window_; | 61 return capture_window_; |
57 } | 62 } |
58 | 63 |
59 Window* DefaultCaptureClient::GetGlobalCaptureWindow() { | 64 Window* DefaultCaptureClient::GetGlobalCaptureWindow() { |
60 return global_capture_window_; | 65 return global_capture_window_; |
61 } | 66 } |
62 | 67 |
| 68 void DefaultCaptureClient::AddObserver(CaptureClientObserver* observer) { |
| 69 observers_.AddObserver(observer); |
| 70 } |
| 71 |
| 72 void DefaultCaptureClient::RemoveObserver(CaptureClientObserver* observer) { |
| 73 observers_.RemoveObserver(observer); |
| 74 } |
| 75 |
63 } // namespace client | 76 } // namespace client |
64 } // namespace aura | 77 } // namespace aura |
OLD | NEW |