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/views/corewm/capture_controller.h" | 5 #include "ui/views/corewm/capture_controller.h" |
6 | 6 |
7 #include "ui/aura/root_window.h" | 7 #include "ui/aura/root_window.h" |
8 #include "ui/aura/window.h" | 8 #include "ui/aura/window.h" |
9 | 9 |
10 namespace views { | 10 namespace views { |
11 namespace corewm { | 11 namespace corewm { |
12 | 12 |
13 //////////////////////////////////////////////////////////////////////////////// | 13 //////////////////////////////////////////////////////////////////////////////// |
14 // CaptureController, public: | 14 // CaptureController, public: |
15 | 15 |
16 void CaptureController::Attach(aura::RootWindow* root) { | 16 void CaptureController::Attach(aura::Window* root) { |
17 DCHECK_EQ(0u, root_windows_.count(root)); | 17 DCHECK_EQ(0u, root_windows_.count(root)); |
18 root_windows_.insert(root); | 18 root_windows_.insert(root); |
19 aura::client::SetCaptureClient(root, this); | 19 aura::client::SetCaptureClient(root, this); |
20 } | 20 } |
21 | 21 |
22 void CaptureController::Detach(aura::RootWindow* root) { | 22 void CaptureController::Detach(aura::Window* root) { |
23 root_windows_.erase(root); | 23 root_windows_.erase(root); |
24 aura::client::SetCaptureClient(root, NULL); | 24 aura::client::SetCaptureClient(root, NULL); |
25 } | 25 } |
26 | 26 |
27 //////////////////////////////////////////////////////////////////////////////// | 27 //////////////////////////////////////////////////////////////////////////////// |
28 // CaptureController, aura::client::CaptureClient implementation: | 28 // CaptureController, aura::client::CaptureClient implementation: |
29 | 29 |
30 void CaptureController::SetCapture(aura::Window* new_capture_window) { | 30 void CaptureController::SetCapture(aura::Window* new_capture_window) { |
31 if (capture_window_ == new_capture_window) | 31 if (capture_window_ == new_capture_window) |
32 return; | 32 return; |
33 | 33 |
34 // Make sure window has a root window. | 34 // Make sure window has a root window. |
35 DCHECK(!new_capture_window || new_capture_window->GetRootWindow()); | 35 DCHECK(!new_capture_window || new_capture_window->GetRootWindow()); |
36 DCHECK(!capture_window_ || capture_window_->GetRootWindow()); | 36 DCHECK(!capture_window_ || capture_window_->GetRootWindow()); |
37 | 37 |
38 aura::Window* old_capture_window = capture_window_; | 38 aura::Window* old_capture_window = capture_window_; |
39 aura::RootWindow* old_capture_root = old_capture_window ? | 39 aura::Window* old_capture_root = old_capture_window ? |
40 old_capture_window->GetRootWindow() : NULL; | 40 old_capture_window->GetRootWindow() : NULL; |
41 | 41 |
42 // Copy the list in case it's modified out from under us. | 42 // Copy the list in case it's modified out from under us. |
43 RootWindows root_windows(root_windows_); | 43 RootWindows root_windows(root_windows_); |
44 | 44 |
45 // If we're actually starting capture, then cancel any touches/gestures | 45 // If we're actually starting capture, then cancel any touches/gestures |
46 // that aren't already locked to the new window, and transfer any on the | 46 // that aren't already locked to the new window, and transfer any on the |
47 // old capture window to the new one. When capture is released we have no | 47 // old capture window to the new one. When capture is released we have no |
48 // distinction between the touches/gestures that were in the window all | 48 // distinction between the touches/gestures that were in the window all |
49 // along (and so shouldn't be canceled) and those that got moved, so | 49 // along (and so shouldn't be canceled) and those that got moved, so |
50 // just leave them all where they are. | 50 // just leave them all where they are. |
51 if (new_capture_window) { | 51 if (new_capture_window) { |
52 ui::GestureRecognizer::Get()->TransferEventsTo(old_capture_window, | 52 ui::GestureRecognizer::Get()->TransferEventsTo(old_capture_window, |
53 new_capture_window); | 53 new_capture_window); |
54 } | 54 } |
55 | 55 |
56 capture_window_ = new_capture_window; | 56 capture_window_ = new_capture_window; |
57 | 57 |
58 for (RootWindows::const_iterator i = root_windows.begin(); | 58 for (RootWindows::const_iterator i = root_windows.begin(); |
59 i != root_windows.end(); ++i) { | 59 i != root_windows.end(); ++i) { |
60 aura::client::CaptureDelegate* delegate = *i; | 60 aura::client::CaptureDelegate* delegate = (*i)->GetDispatcher(); |
61 delegate->UpdateCapture(old_capture_window, new_capture_window); | 61 delegate->UpdateCapture(old_capture_window, new_capture_window); |
62 } | 62 } |
63 | 63 |
64 aura::RootWindow* capture_root = | 64 aura::Window* capture_root = |
65 capture_window_ ? capture_window_->GetRootWindow() : NULL; | 65 capture_window_ ? capture_window_->GetRootWindow() : NULL; |
66 if (capture_root != old_capture_root) { | 66 if (capture_root != old_capture_root) { |
67 if (old_capture_root) { | 67 if (old_capture_root) { |
68 aura::client::CaptureDelegate* delegate = old_capture_root; | 68 aura::client::CaptureDelegate* delegate = |
| 69 old_capture_root->GetDispatcher(); |
69 delegate->ReleaseNativeCapture(); | 70 delegate->ReleaseNativeCapture(); |
70 } | 71 } |
71 if (capture_root) { | 72 if (capture_root) { |
72 aura::client::CaptureDelegate* delegate = capture_root; | 73 aura::client::CaptureDelegate* delegate = capture_root->GetDispatcher(); |
73 delegate->SetNativeCapture(); | 74 delegate->SetNativeCapture(); |
74 } | 75 } |
75 } | 76 } |
76 } | 77 } |
77 | 78 |
78 void CaptureController::ReleaseCapture(aura::Window* window) { | 79 void CaptureController::ReleaseCapture(aura::Window* window) { |
79 if (capture_window_ != window) | 80 if (capture_window_ != window) |
80 return; | 81 return; |
81 SetCapture(NULL); | 82 SetCapture(NULL); |
82 } | 83 } |
(...skipping 11 matching lines...) Expand all Loading... |
94 | 95 |
95 CaptureController::~CaptureController() { | 96 CaptureController::~CaptureController() { |
96 } | 97 } |
97 | 98 |
98 //////////////////////////////////////////////////////////////////////////////// | 99 //////////////////////////////////////////////////////////////////////////////// |
99 // ScopedCaptureClient: | 100 // ScopedCaptureClient: |
100 | 101 |
101 // static | 102 // static |
102 CaptureController* ScopedCaptureClient::capture_controller_ = NULL; | 103 CaptureController* ScopedCaptureClient::capture_controller_ = NULL; |
103 | 104 |
104 ScopedCaptureClient::ScopedCaptureClient(aura::RootWindow* root) | 105 ScopedCaptureClient::ScopedCaptureClient(aura::Window* root) |
105 : root_window_(root) { | 106 : root_window_(root) { |
106 root->AddObserver(this); | 107 root->AddObserver(this); |
107 if (!capture_controller_) | 108 if (!capture_controller_) |
108 capture_controller_ = new CaptureController; | 109 capture_controller_ = new CaptureController; |
109 capture_controller_->Attach(root); | 110 capture_controller_->Attach(root); |
110 } | 111 } |
111 | 112 |
112 ScopedCaptureClient::~ScopedCaptureClient() { | 113 ScopedCaptureClient::~ScopedCaptureClient() { |
113 Shutdown(); | 114 Shutdown(); |
114 } | 115 } |
(...skipping 16 matching lines...) Expand all Loading... |
131 capture_controller_->Detach(root_window_); | 132 capture_controller_->Detach(root_window_); |
132 if (!capture_controller_->is_active()) { | 133 if (!capture_controller_->is_active()) { |
133 delete capture_controller_; | 134 delete capture_controller_; |
134 capture_controller_ = NULL; | 135 capture_controller_ = NULL; |
135 } | 136 } |
136 root_window_ = NULL; | 137 root_window_ = NULL; |
137 } | 138 } |
138 | 139 |
139 } // namespace corewm | 140 } // namespace corewm |
140 } // namespace views | 141 } // namespace views |
OLD | NEW |