Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(524)

Side by Side Diff: ui/wm/core/capture_controller.cc

Issue 780273003: Fix releasing capture in Ozone (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/wm/core/capture_controller.h ('k') | ui/wm/core/capture_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/wm/core/capture_controller.h" 5 #include "ui/wm/core/capture_controller.h"
6 6
7 #include "ui/aura/window.h" 7 #include "ui/aura/window.h"
8 #include "ui/aura/window_event_dispatcher.h" 8 #include "ui/aura/window_event_dispatcher.h"
9 #include "ui/aura/window_tree_host.h" 9 #include "ui/aura/window_tree_host.h"
10 10
11 namespace wm { 11 namespace wm {
12 12
13 //////////////////////////////////////////////////////////////////////////////// 13 ////////////////////////////////////////////////////////////////////////////////
14 // CaptureController, public: 14 // CaptureController, public:
15 15
16 void CaptureController::Attach(aura::Window* root) { 16 void CaptureController::Attach(aura::Window* root) {
17 DCHECK_EQ(0u, root_windows_.count(root)); 17 DCHECK_EQ(0u, delegates_.count(root));
18 root_windows_.insert(root); 18 delegates_[root] = root->GetHost()->dispatcher();
19 aura::client::SetCaptureClient(root, this); 19 aura::client::SetCaptureClient(root, this);
20 } 20 }
21 21
22 void CaptureController::Detach(aura::Window* root) { 22 void CaptureController::Detach(aura::Window* root) {
23 root_windows_.erase(root); 23 delegates_.erase(root);
24 aura::client::SetCaptureClient(root, NULL); 24 aura::client::SetCaptureClient(root, nullptr);
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::Window* old_capture_root = old_capture_window ? 39 aura::client::CaptureDelegate* old_capture_delegate = capture_delegate_;
40 old_capture_window->GetRootWindow() : NULL;
41 40
42 // Copy the list in case it's modified out from under us. 41 // Copy the map in case it's modified out from under us.
43 RootWindows root_windows(root_windows_); 42 std::map<aura::Window*, aura::client::CaptureDelegate*> delegates =
43 delegates_;
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 aura::Window* capture_root_window =
58 capture_window_ ? capture_window_->GetRootWindow() : nullptr;
59 capture_delegate_ = delegates_.find(capture_root_window) == delegates_.end()
60 ? nullptr
61 : delegates_[capture_root_window];
57 62
58 for (RootWindows::const_iterator i = root_windows.begin(); 63 for (const auto& it : delegates)
59 i != root_windows.end(); ++i) { 64 it.second->UpdateCapture(old_capture_window, new_capture_window);
60 aura::client::CaptureDelegate* delegate = (*i)->GetHost()->dispatcher();
61 delegate->UpdateCapture(old_capture_window, new_capture_window);
62 }
63 65
64 aura::Window* capture_root = 66 if (capture_delegate_ != old_capture_delegate) {
65 capture_window_ ? capture_window_->GetRootWindow() : NULL; 67 if (old_capture_delegate)
66 if (capture_root != old_capture_root) { 68 old_capture_delegate->ReleaseNativeCapture();
67 if (old_capture_root) { 69 if (capture_delegate_)
68 aura::client::CaptureDelegate* delegate = 70 capture_delegate_->SetNativeCapture();
69 old_capture_root->GetHost()->dispatcher();
70 delegate->ReleaseNativeCapture();
71 }
72 if (capture_root) {
73 aura::client::CaptureDelegate* delegate =
74 capture_root->GetHost()->dispatcher();
75 delegate->SetNativeCapture();
76 }
77 } 71 }
78 } 72 }
79 73
80 void CaptureController::ReleaseCapture(aura::Window* window) { 74 void CaptureController::ReleaseCapture(aura::Window* window) {
81 if (capture_window_ != window) 75 if (capture_window_ != window)
82 return; 76 return;
83 SetCapture(NULL); 77 SetCapture(nullptr);
84 } 78 }
85 79
86 aura::Window* CaptureController::GetCaptureWindow() { 80 aura::Window* CaptureController::GetCaptureWindow() {
87 return capture_window_; 81 return capture_window_;
88 } 82 }
89 83
90 aura::Window* CaptureController::GetGlobalCaptureWindow() { 84 aura::Window* CaptureController::GetGlobalCaptureWindow() {
91 return capture_window_; 85 return capture_window_;
92 } 86 }
93 87
94 //////////////////////////////////////////////////////////////////////////////// 88 ////////////////////////////////////////////////////////////////////////////////
95 // CaptureController, private: 89 // CaptureController, private:
96 90
97 CaptureController::CaptureController() 91 CaptureController::CaptureController()
98 : capture_window_(NULL) { 92 : capture_window_(nullptr),
93 capture_delegate_(nullptr) {
99 } 94 }
100 95
101 CaptureController::~CaptureController() { 96 CaptureController::~CaptureController() {
102 } 97 }
103 98
104 //////////////////////////////////////////////////////////////////////////////// 99 ////////////////////////////////////////////////////////////////////////////////
105 // ScopedCaptureClient: 100 // ScopedCaptureClient:
106 101
107 // static 102 // static
108 CaptureController* ScopedCaptureClient::capture_controller_ = NULL; 103 CaptureController* ScopedCaptureClient::capture_controller_ = nullptr;
109 104
110 ScopedCaptureClient::ScopedCaptureClient(aura::Window* root) 105 ScopedCaptureClient::ScopedCaptureClient(aura::Window* root)
111 : root_window_(root) { 106 : root_window_(root) {
112 root->AddObserver(this); 107 root->AddObserver(this);
113 if (!capture_controller_) 108 if (!capture_controller_)
114 capture_controller_ = new CaptureController; 109 capture_controller_ = new CaptureController;
115 capture_controller_->Attach(root); 110 capture_controller_->Attach(root);
116 } 111 }
117 112
118 ScopedCaptureClient::~ScopedCaptureClient() { 113 ScopedCaptureClient::~ScopedCaptureClient() {
(...skipping 11 matching lines...) Expand all
130 } 125 }
131 126
132 void ScopedCaptureClient::Shutdown() { 127 void ScopedCaptureClient::Shutdown() {
133 if (!root_window_) 128 if (!root_window_)
134 return; 129 return;
135 130
136 root_window_->RemoveObserver(this); 131 root_window_->RemoveObserver(this);
137 capture_controller_->Detach(root_window_); 132 capture_controller_->Detach(root_window_);
138 if (!capture_controller_->is_active()) { 133 if (!capture_controller_->is_active()) {
139 delete capture_controller_; 134 delete capture_controller_;
140 capture_controller_ = NULL; 135 capture_controller_ = nullptr;
141 } 136 }
142 root_window_ = NULL; 137 root_window_ = nullptr;
138 }
139
140 ///////////////////////////////////////////////////////////////////////////////
141 // CaptureController::TestApi
142
143 void ScopedCaptureClient::TestApi::SetDelegate(
144 aura::client::CaptureDelegate* delegate) {
145 client_->capture_controller_->delegates_[client_->root_window_] = delegate;
143 } 146 }
144 147
145 } // namespace wm 148 } // namespace wm
OLDNEW
« no previous file with comments | « ui/wm/core/capture_controller.h ('k') | ui/wm/core/capture_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698