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

Side by Side Diff: ui/views/mus/window_manager_connection.cc

Issue 2163453002: mus: Change PointerWatcher to watch for all events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a comment. Created 4 years, 5 months 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/mus/window_manager_connection.h" 5 #include "ui/views/mus/window_manager_connection.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/threading/thread_local.h" 10 #include "base/threading/thread_local.h"
11 #include "services/shell/public/cpp/connection.h" 11 #include "services/shell/public/cpp/connection.h"
12 #include "services/shell/public/cpp/connector.h" 12 #include "services/shell/public/cpp/connector.h"
13 #include "services/ui/common/gpu_service.h" 13 #include "services/ui/common/gpu_service.h"
14 #include "services/ui/public/cpp/property_type_converters.h" 14 #include "services/ui/public/cpp/property_type_converters.h"
15 #include "services/ui/public/cpp/window.h" 15 #include "services/ui/public/cpp/window.h"
16 #include "services/ui/public/cpp/window_property.h" 16 #include "services/ui/public/cpp/window_property.h"
17 #include "services/ui/public/cpp/window_tree_client.h" 17 #include "services/ui/public/cpp/window_tree_client.h"
18 #include "services/ui/public/interfaces/event_matcher.mojom.h" 18 #include "services/ui/public/interfaces/event_matcher.mojom.h"
19 #include "services/ui/public/interfaces/window_tree.mojom.h" 19 #include "services/ui/public/interfaces/window_tree.mojom.h"
20 #include "ui/views/mus/clipboard_mus.h" 20 #include "ui/views/mus/clipboard_mus.h"
21 #include "ui/views/mus/native_widget_mus.h" 21 #include "ui/views/mus/native_widget_mus.h"
22 #include "ui/views/mus/screen_mus.h" 22 #include "ui/views/mus/screen_mus.h"
23 #include "ui/views/pointer_event_watcher.h"
23 #include "ui/views/pointer_watcher.h" 24 #include "ui/views/pointer_watcher.h"
24 #include "ui/views/touch_event_watcher.h"
25 #include "ui/views/views_delegate.h" 25 #include "ui/views/views_delegate.h"
26 26
27 namespace views { 27 namespace views {
28 namespace { 28 namespace {
29 29
30 using WindowManagerConnectionPtr = 30 using WindowManagerConnectionPtr =
31 base::ThreadLocalPointer<views::WindowManagerConnection>; 31 base::ThreadLocalPointer<views::WindowManagerConnection>;
32 32
33 // Env is thread local so that aura may be used on multiple threads. 33 // Env is thread local so that aura may be used on multiple threads.
34 base::LazyInstance<WindowManagerConnectionPtr>::Leaky lazy_tls_ptr = 34 base::LazyInstance<WindowManagerConnectionPtr>::Leaky lazy_tls_ptr =
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 std::map<std::string, std::vector<uint8_t>> properties = props; 76 std::map<std::string, std::vector<uint8_t>> properties = props;
77 NativeWidgetMus::ConfigurePropertiesForNewWindow(init_params, &properties); 77 NativeWidgetMus::ConfigurePropertiesForNewWindow(init_params, &properties);
78 properties[ui::mojom::WindowManager::kAppID_Property] = 78 properties[ui::mojom::WindowManager::kAppID_Property] =
79 mojo::ConvertTo<std::vector<uint8_t>>(identity_.name()); 79 mojo::ConvertTo<std::vector<uint8_t>>(identity_.name());
80 return new NativeWidgetMus(delegate, connector_, NewWindow(properties), 80 return new NativeWidgetMus(delegate, connector_, NewWindow(properties),
81 ui::mojom::SurfaceType::DEFAULT); 81 ui::mojom::SurfaceType::DEFAULT);
82 } 82 }
83 83
84 void WindowManagerConnection::AddPointerWatcher(PointerWatcher* watcher) { 84 void WindowManagerConnection::AddPointerWatcher(PointerWatcher* watcher) {
85 // TODO(riajiang): Support multiple event matchers (crbug.com/627146). 85 // TODO(riajiang): Support multiple event matchers (crbug.com/627146).
86 DCHECK(!HasTouchEventWatcher()); 86 DCHECK(!HasTouchEventWatcher() && !HasMouseEventWatcher());
87 bool had_watcher = HasPointerWatcher(); 87 bool had_watcher = HasPointerWatcher();
88 pointer_watchers_.AddObserver(watcher); 88 pointer_watchers_.AddObserver(watcher);
89 if (!had_watcher) { 89 if (!had_watcher) {
90 // Start a watcher for pointer down. 90 // Start a watcher for pointer down.
91 // TODO(jamescook): Extend event observers to handle multiple event types. 91 // TODO(jamescook): Extend event observers to handle multiple event types.
92 ui::mojom::EventMatcherPtr matcher = ui::mojom::EventMatcher::New(); 92 ui::mojom::EventMatcherPtr matcher = ui::mojom::EventMatcher::New();
93 matcher->type_matcher = ui::mojom::EventTypeMatcher::New(); 93 matcher->type_matcher = ui::mojom::EventTypeMatcher::New();
94 matcher->type_matcher->type = ui::mojom::EventType::POINTER_DOWN; 94 matcher->type_matcher->type = ui::mojom::EventType::POINTER_DOWN;
95 client_->SetEventObserver(std::move(matcher)); 95 client_->SetEventObserver(std::move(matcher));
96 } 96 }
97 } 97 }
98 98
99 void WindowManagerConnection::RemovePointerWatcher(PointerWatcher* watcher) { 99 void WindowManagerConnection::RemovePointerWatcher(PointerWatcher* watcher) {
100 pointer_watchers_.RemoveObserver(watcher); 100 pointer_watchers_.RemoveObserver(watcher);
101 if (!HasPointerWatcher()) { 101 if (!HasPointerWatcher()) {
102 // Last PointerWatcher removed, stop the event observer. 102 // Last PointerWatcher removed, stop the event observer.
103 client_->SetEventObserver(nullptr); 103 client_->SetEventObserver(nullptr);
104 } 104 }
105 } 105 }
106 106
107 void WindowManagerConnection::AddTouchEventWatcher(TouchEventWatcher* watcher) { 107 void WindowManagerConnection::AddTouchEventWatcher(
108 PointerEventWatcher* watcher) {
108 // TODO(riajiang): Support multiple event matchers (crbug.com/627146). 109 // TODO(riajiang): Support multiple event matchers (crbug.com/627146).
109 DCHECK(!HasPointerWatcher()); 110 DCHECK(!HasPointerWatcher() && !HasMouseEventWatcher());
110 bool had_watcher = HasTouchEventWatcher(); 111 bool had_watcher = HasTouchEventWatcher();
111 touch_event_watchers_.AddObserver(watcher); 112 touch_event_watchers_.AddObserver(watcher);
112 if (!had_watcher) { 113 if (!had_watcher) {
113 ui::mojom::EventMatcherPtr matcher = ui::mojom::EventMatcher::New(); 114 ui::mojom::EventMatcherPtr matcher = ui::mojom::EventMatcher::New();
114 matcher->pointer_kind_matcher = ui::mojom::PointerKindMatcher::New(); 115 matcher->pointer_kind_matcher = ui::mojom::PointerKindMatcher::New();
115 matcher->pointer_kind_matcher->pointer_kind = ui::mojom::PointerKind::TOUCH; 116 matcher->pointer_kind_matcher->pointer_kind = ui::mojom::PointerKind::TOUCH;
116 client_->SetEventObserver(std::move(matcher)); 117 client_->SetEventObserver(std::move(matcher));
117 } 118 }
118 } 119 }
119 120
120 void WindowManagerConnection::RemoveTouchEventWatcher( 121 void WindowManagerConnection::RemoveTouchEventWatcher(
121 TouchEventWatcher* watcher) { 122 PointerEventWatcher* watcher) {
122 touch_event_watchers_.RemoveObserver(watcher); 123 touch_event_watchers_.RemoveObserver(watcher);
123 if (!HasTouchEventWatcher()) { 124 if (!HasTouchEventWatcher()) {
124 // Last TouchEventWatcher removed, stop the event observer. 125 // Last TouchEventWatcher removed, stop the event observer.
125 client_->SetEventObserver(nullptr); 126 client_->SetEventObserver(nullptr);
126 } 127 }
127 } 128 }
128 129
130 void WindowManagerConnection::AddMouseEventWatcher(
131 PointerEventWatcher* watcher) {
132 // TODO(riajiang): Support multiple event matchers (crbug.com/627146).
133 DCHECK(!HasPointerWatcher() && !HasTouchEventWatcher());
134 bool had_watcher = HasMouseEventWatcher();
135 mouse_event_watchers_.AddObserver(watcher);
136 if (!had_watcher) {
137 ui::mojom::EventMatcherPtr matcher = ui::mojom::EventMatcher::New();
138 matcher->pointer_kind_matcher = ui::mojom::PointerKindMatcher::New();
139 matcher->pointer_kind_matcher->pointer_kind = ui::mojom::PointerKind::MOUSE;
140 client_->SetEventObserver(std::move(matcher));
141 }
142 }
143
144 void WindowManagerConnection::RemoveMouseEventWatcher(
145 PointerEventWatcher* watcher) {
146 mouse_event_watchers_.RemoveObserver(watcher);
147 if (!HasMouseEventWatcher()) {
148 // Last MouseEventWatcher removed, stop the event observer.
149 client_->SetEventObserver(nullptr);
150 }
151 }
152
129 const std::set<ui::Window*>& WindowManagerConnection::GetRoots() const { 153 const std::set<ui::Window*>& WindowManagerConnection::GetRoots() const {
130 return client_->GetRoots(); 154 return client_->GetRoots();
131 } 155 }
132 156
133 WindowManagerConnection::WindowManagerConnection( 157 WindowManagerConnection::WindowManagerConnection(
134 shell::Connector* connector, 158 shell::Connector* connector,
135 const shell::Identity& identity) 159 const shell::Identity& identity)
136 : connector_(connector), identity_(identity) { 160 : connector_(connector), identity_(identity) {
137 lazy_tls_ptr.Pointer()->Set(this); 161 lazy_tls_ptr.Pointer()->Set(this);
138 162
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // base::ObserverList<>::might_have_observers() because that returns true 197 // base::ObserverList<>::might_have_observers() because that returns true
174 // during iteration over the list even when the last observer is removed. 198 // during iteration over the list even when the last observer is removed.
175 base::ObserverList<PointerWatcher>::Iterator iterator(&pointer_watchers_); 199 base::ObserverList<PointerWatcher>::Iterator iterator(&pointer_watchers_);
176 return !!iterator.GetNext(); 200 return !!iterator.GetNext();
177 } 201 }
178 202
179 bool WindowManagerConnection::HasTouchEventWatcher() { 203 bool WindowManagerConnection::HasTouchEventWatcher() {
180 // Check to see if we really have any observers left. This doesn't use 204 // Check to see if we really have any observers left. This doesn't use
181 // base::ObserverList<>::might_have_observers() because that returns true 205 // base::ObserverList<>::might_have_observers() because that returns true
182 // during iteration over the list even when the last observer is removed. 206 // during iteration over the list even when the last observer is removed.
183 base::ObserverList<TouchEventWatcher>::Iterator iterator( 207 base::ObserverList<PointerEventWatcher>::Iterator iterator(
184 &touch_event_watchers_); 208 &touch_event_watchers_);
185 return !!iterator.GetNext(); 209 return !!iterator.GetNext();
186 } 210 }
187 211
212 bool WindowManagerConnection::HasMouseEventWatcher() {
213 // Check to see if we really have any observers left. This doesn't use
214 // base::ObserverList<>::might_have_observers() because that returns true
215 // during iteration over the list even when the last observer is removed.
216 base::ObserverList<PointerEventWatcher>::Iterator iterator(
217 &mouse_event_watchers_);
218 return !!iterator.GetNext();
219 }
220
188 void WindowManagerConnection::OnEmbed(ui::Window* root) {} 221 void WindowManagerConnection::OnEmbed(ui::Window* root) {}
189 222
190 void WindowManagerConnection::OnDidDestroyClient(ui::WindowTreeClient* client) { 223 void WindowManagerConnection::OnDidDestroyClient(ui::WindowTreeClient* client) {
191 if (client_.get() == client) { 224 if (client_.get() == client) {
192 client_.release(); 225 client_.release();
193 } else { 226 } else {
194 DCHECK(!client_); 227 DCHECK(!client_);
195 } 228 }
196 } 229 }
197 230
(...skipping 17 matching lines...) Expand all
215 OnMousePressed(*event.AsMouseEvent(), 248 OnMousePressed(*event.AsMouseEvent(),
216 location_in_screen, target_widget)); 249 location_in_screen, target_widget));
217 } else if (event.type() == ui::ET_TOUCH_PRESSED) { 250 } else if (event.type() == ui::ET_TOUCH_PRESSED) {
218 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, 251 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_,
219 OnTouchPressed(*event.AsTouchEvent(), 252 OnTouchPressed(*event.AsTouchEvent(),
220 location_in_screen, target_widget)); 253 location_in_screen, target_widget));
221 } 254 }
222 } else if (HasTouchEventWatcher()) { 255 } else if (HasTouchEventWatcher()) {
223 if (event.IsTouchEvent() || event.IsTouchPointerEvent()) { 256 if (event.IsTouchEvent() || event.IsTouchPointerEvent()) {
224 FOR_EACH_OBSERVER( 257 FOR_EACH_OBSERVER(
225 TouchEventWatcher, touch_event_watchers_, 258 PointerEventWatcher, touch_event_watchers_,
226 OnTouchEventObserved(*event.AsLocatedEvent(), target_widget)); 259 OnTouchEventObserved(*event.AsLocatedEvent(), target_widget));
227 } 260 }
261 } else if (HasMouseEventWatcher()) {
262 if (event.IsMouseEvent() || event.IsMousePointerEvent()) {
263 FOR_EACH_OBSERVER(
264 PointerEventWatcher, mouse_event_watchers_,
265 OnMouseEventObserved(*event.AsLocatedEvent(), target_widget));
266 }
228 } 267 }
229 } 268 }
230 269
231 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { 270 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() {
232 if (client_) 271 if (client_)
233 NativeWidgetMus::NotifyFrameChanged(client_.get()); 272 NativeWidgetMus::NotifyFrameChanged(client_.get());
234 } 273 }
235 274
236 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { 275 gfx::Point WindowManagerConnection::GetCursorScreenPoint() {
237 return client_->GetCursorScreenPoint(); 276 return client_->GetCursorScreenPoint();
238 } 277 }
239 278
240 } // namespace views 279 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698