| OLD | NEW |
| 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 Loading... |
| 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::AddPointerEventWatcher( |
| 108 PointerEventWatcher* watcher, |
| 109 ui::EventPointerType type) { |
| 108 // TODO(riajiang): Support multiple event matchers (crbug.com/627146). | 110 // TODO(riajiang): Support multiple event matchers (crbug.com/627146). |
| 109 DCHECK(!HasPointerWatcher()); | 111 DCHECK(!HasPointerWatcher()); |
| 110 bool had_watcher = HasTouchEventWatcher(); | 112 bool had_watcher = false; |
| 111 touch_event_watchers_.AddObserver(watcher); | 113 if (type == ui::EventPointerType::POINTER_TYPE_TOUCH) { |
| 114 DCHECK(!HasMouseEventWatcher()); |
| 115 had_watcher = HasTouchEventWatcher(); |
| 116 touch_event_watchers_.AddObserver(watcher); |
| 117 } else if (type == ui::EventPointerType::POINTER_TYPE_MOUSE) { |
| 118 DCHECK(!HasTouchEventWatcher()); |
| 119 had_watcher = HasMouseEventWatcher(); |
| 120 mouse_event_watchers_.AddObserver(watcher); |
| 121 } |
| 112 if (!had_watcher) { | 122 if (!had_watcher) { |
| 113 ui::mojom::EventMatcherPtr matcher = ui::mojom::EventMatcher::New(); | 123 ui::mojom::EventMatcherPtr matcher = ui::mojom::EventMatcher::New(); |
| 114 matcher->pointer_kind_matcher = ui::mojom::PointerKindMatcher::New(); | 124 matcher->pointer_kind_matcher = ui::mojom::PointerKindMatcher::New(); |
| 115 matcher->pointer_kind_matcher->pointer_kind = ui::mojom::PointerKind::TOUCH; | 125 matcher->pointer_kind_matcher->pointer_kind = |
| 126 type == ui::EventPointerType::POINTER_TYPE_TOUCH |
| 127 ? ui::mojom::PointerKind::TOUCH |
| 128 : ui::mojom::PointerKind::MOUSE; |
| 116 client_->SetEventObserver(std::move(matcher)); | 129 client_->SetEventObserver(std::move(matcher)); |
| 117 } | 130 } |
| 118 } | 131 } |
| 119 | 132 |
| 120 void WindowManagerConnection::RemoveTouchEventWatcher( | 133 void WindowManagerConnection::RemovePointerEventWatcher( |
| 121 TouchEventWatcher* watcher) { | 134 PointerEventWatcher* watcher, |
| 122 touch_event_watchers_.RemoveObserver(watcher); | 135 ui::EventPointerType type) { |
| 123 if (!HasTouchEventWatcher()) { | 136 bool has_watcher = false; |
| 124 // Last TouchEventWatcher removed, stop the event observer. | 137 if (type == ui::EventPointerType::POINTER_TYPE_TOUCH) { |
| 138 touch_event_watchers_.RemoveObserver(watcher); |
| 139 has_watcher = HasTouchEventWatcher(); |
| 140 } else if (type == ui::EventPointerType::POINTER_TYPE_MOUSE) { |
| 141 mouse_event_watchers_.RemoveObserver(watcher); |
| 142 has_watcher = HasMouseEventWatcher(); |
| 143 } |
| 144 if (!has_watcher) { |
| 145 // Last PointerEventWatcher removed, stop the event observer. |
| 125 client_->SetEventObserver(nullptr); | 146 client_->SetEventObserver(nullptr); |
| 126 } | 147 } |
| 127 } | 148 } |
| 128 | 149 |
| 129 const std::set<ui::Window*>& WindowManagerConnection::GetRoots() const { | 150 const std::set<ui::Window*>& WindowManagerConnection::GetRoots() const { |
| 130 return client_->GetRoots(); | 151 return client_->GetRoots(); |
| 131 } | 152 } |
| 132 | 153 |
| 133 WindowManagerConnection::WindowManagerConnection( | 154 WindowManagerConnection::WindowManagerConnection( |
| 134 shell::Connector* connector, | 155 shell::Connector* connector, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 // base::ObserverList<>::might_have_observers() because that returns true | 194 // base::ObserverList<>::might_have_observers() because that returns true |
| 174 // during iteration over the list even when the last observer is removed. | 195 // during iteration over the list even when the last observer is removed. |
| 175 base::ObserverList<PointerWatcher>::Iterator iterator(&pointer_watchers_); | 196 base::ObserverList<PointerWatcher>::Iterator iterator(&pointer_watchers_); |
| 176 return !!iterator.GetNext(); | 197 return !!iterator.GetNext(); |
| 177 } | 198 } |
| 178 | 199 |
| 179 bool WindowManagerConnection::HasTouchEventWatcher() { | 200 bool WindowManagerConnection::HasTouchEventWatcher() { |
| 180 // Check to see if we really have any observers left. This doesn't use | 201 // Check to see if we really have any observers left. This doesn't use |
| 181 // base::ObserverList<>::might_have_observers() because that returns true | 202 // base::ObserverList<>::might_have_observers() because that returns true |
| 182 // during iteration over the list even when the last observer is removed. | 203 // during iteration over the list even when the last observer is removed. |
| 183 base::ObserverList<TouchEventWatcher>::Iterator iterator( | 204 base::ObserverList<PointerEventWatcher>::Iterator iterator( |
| 184 &touch_event_watchers_); | 205 &touch_event_watchers_); |
| 185 return !!iterator.GetNext(); | 206 return !!iterator.GetNext(); |
| 186 } | 207 } |
| 187 | 208 |
| 209 bool WindowManagerConnection::HasMouseEventWatcher() { |
| 210 // Check to see if we really have any observers left. This doesn't use |
| 211 // base::ObserverList<>::might_have_observers() because that returns true |
| 212 // during iteration over the list even when the last observer is removed. |
| 213 base::ObserverList<PointerEventWatcher>::Iterator iterator( |
| 214 &mouse_event_watchers_); |
| 215 return !!iterator.GetNext(); |
| 216 } |
| 217 |
| 188 void WindowManagerConnection::OnEmbed(ui::Window* root) {} | 218 void WindowManagerConnection::OnEmbed(ui::Window* root) {} |
| 189 | 219 |
| 190 void WindowManagerConnection::OnDidDestroyClient(ui::WindowTreeClient* client) { | 220 void WindowManagerConnection::OnDidDestroyClient(ui::WindowTreeClient* client) { |
| 191 if (client_.get() == client) { | 221 if (client_.get() == client) { |
| 192 client_.release(); | 222 client_.release(); |
| 193 } else { | 223 } else { |
| 194 DCHECK(!client_); | 224 DCHECK(!client_); |
| 195 } | 225 } |
| 196 } | 226 } |
| 197 | 227 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 215 OnMousePressed(*event.AsMouseEvent(), | 245 OnMousePressed(*event.AsMouseEvent(), |
| 216 location_in_screen, target_widget)); | 246 location_in_screen, target_widget)); |
| 217 } else if (event.type() == ui::ET_TOUCH_PRESSED) { | 247 } else if (event.type() == ui::ET_TOUCH_PRESSED) { |
| 218 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, | 248 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, |
| 219 OnTouchPressed(*event.AsTouchEvent(), | 249 OnTouchPressed(*event.AsTouchEvent(), |
| 220 location_in_screen, target_widget)); | 250 location_in_screen, target_widget)); |
| 221 } | 251 } |
| 222 } else if (HasTouchEventWatcher()) { | 252 } else if (HasTouchEventWatcher()) { |
| 223 if (event.IsTouchEvent() || event.IsTouchPointerEvent()) { | 253 if (event.IsTouchEvent() || event.IsTouchPointerEvent()) { |
| 224 FOR_EACH_OBSERVER( | 254 FOR_EACH_OBSERVER( |
| 225 TouchEventWatcher, touch_event_watchers_, | 255 PointerEventWatcher, touch_event_watchers_, |
| 226 OnTouchEventObserved(*event.AsLocatedEvent(), target_widget)); | 256 OnPointerEventObserved(*event.AsLocatedEvent(), target_widget)); |
| 257 } |
| 258 } else if (HasMouseEventWatcher()) { |
| 259 if (event.IsMouseEvent() || event.IsMousePointerEvent()) { |
| 260 FOR_EACH_OBSERVER( |
| 261 PointerEventWatcher, mouse_event_watchers_, |
| 262 OnPointerEventObserved(*event.AsLocatedEvent(), target_widget)); |
| 227 } | 263 } |
| 228 } | 264 } |
| 229 } | 265 } |
| 230 | 266 |
| 231 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { | 267 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { |
| 232 if (client_) | 268 if (client_) |
| 233 NativeWidgetMus::NotifyFrameChanged(client_.get()); | 269 NativeWidgetMus::NotifyFrameChanged(client_.get()); |
| 234 } | 270 } |
| 235 | 271 |
| 236 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { | 272 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { |
| 237 return client_->GetCursorScreenPoint(); | 273 return client_->GetCursorScreenPoint(); |
| 238 } | 274 } |
| 239 | 275 |
| 240 } // namespace views | 276 } // namespace views |
| OLD | NEW |