| 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_watcher.h" | 23 #include "ui/views/pointer_down_watcher.h" |
| 24 #include "ui/views/touch_event_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. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 if (init_params.type == Widget::InitParams::TYPE_CONTROL) | 74 if (init_params.type == Widget::InitParams::TYPE_CONTROL) |
| 75 return nullptr; | 75 return nullptr; |
| 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::AddPointerDownWatcher( |
| 85 PointerDownWatcher* watcher) { |
| 85 // TODO(riajiang): Support multiple event matchers (crbug.com/627146). | 86 // TODO(riajiang): Support multiple event matchers (crbug.com/627146). |
| 86 DCHECK(!HasTouchEventWatcher()); | 87 DCHECK(!HasTouchEventWatcher()); |
| 87 bool had_watcher = HasPointerWatcher(); | 88 bool had_watcher = HasPointerDownWatcher(); |
| 88 pointer_watchers_.AddObserver(watcher); | 89 pointer_down_watchers_.AddObserver(watcher); |
| 89 if (!had_watcher) { | 90 if (!had_watcher) { |
| 90 // Start a watcher for pointer down. | 91 // Start a watcher for pointer down. |
| 91 // TODO(jamescook): Extend event observers to handle multiple event types. | 92 // TODO(jamescook): Extend event observers to handle multiple event types. |
| 92 ui::mojom::EventMatcherPtr matcher = ui::mojom::EventMatcher::New(); | 93 ui::mojom::EventMatcherPtr matcher = ui::mojom::EventMatcher::New(); |
| 93 matcher->type_matcher = ui::mojom::EventTypeMatcher::New(); | 94 matcher->type_matcher = ui::mojom::EventTypeMatcher::New(); |
| 94 matcher->type_matcher->type = ui::mojom::EventType::POINTER_DOWN; | 95 matcher->type_matcher->type = ui::mojom::EventType::POINTER_DOWN; |
| 95 client_->SetEventObserver(std::move(matcher)); | 96 client_->SetEventObserver(std::move(matcher)); |
| 96 } | 97 } |
| 97 } | 98 } |
| 98 | 99 |
| 99 void WindowManagerConnection::RemovePointerWatcher(PointerWatcher* watcher) { | 100 void WindowManagerConnection::RemovePointerDownWatcher( |
| 100 pointer_watchers_.RemoveObserver(watcher); | 101 PointerDownWatcher* watcher) { |
| 101 if (!HasPointerWatcher()) { | 102 pointer_down_watchers_.RemoveObserver(watcher); |
| 102 // Last PointerWatcher removed, stop the event observer. | 103 if (!HasPointerDownWatcher()) { |
| 104 // Last PointerDownWatcher removed, stop the event observer. |
| 103 client_->SetEventObserver(nullptr); | 105 client_->SetEventObserver(nullptr); |
| 104 } | 106 } |
| 105 } | 107 } |
| 106 | 108 |
| 107 void WindowManagerConnection::AddTouchEventWatcher(TouchEventWatcher* watcher) { | 109 void WindowManagerConnection::AddTouchEventWatcher(TouchEventWatcher* watcher) { |
| 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(!HasPointerDownWatcher()); |
| 110 bool had_watcher = HasTouchEventWatcher(); | 112 bool had_watcher = HasTouchEventWatcher(); |
| 111 touch_event_watchers_.AddObserver(watcher); | 113 touch_event_watchers_.AddObserver(watcher); |
| 112 if (!had_watcher) { | 114 if (!had_watcher) { |
| 113 ui::mojom::EventMatcherPtr matcher = ui::mojom::EventMatcher::New(); | 115 ui::mojom::EventMatcherPtr matcher = ui::mojom::EventMatcher::New(); |
| 114 matcher->pointer_kind_matcher = ui::mojom::PointerKindMatcher::New(); | 116 matcher->pointer_kind_matcher = ui::mojom::PointerKindMatcher::New(); |
| 115 matcher->pointer_kind_matcher->pointer_kind = ui::mojom::PointerKind::TOUCH; | 117 matcher->pointer_kind_matcher->pointer_kind = ui::mojom::PointerKind::TOUCH; |
| 116 client_->SetEventObserver(std::move(matcher)); | 118 client_->SetEventObserver(std::move(matcher)); |
| 117 } | 119 } |
| 118 } | 120 } |
| 119 | 121 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 ui::Clipboard::DestroyClipboardForCurrentThread(); | 163 ui::Clipboard::DestroyClipboardForCurrentThread(); |
| 162 ui::GpuService::Terminate(); | 164 ui::GpuService::Terminate(); |
| 163 lazy_tls_ptr.Pointer()->Set(nullptr); | 165 lazy_tls_ptr.Pointer()->Set(nullptr); |
| 164 | 166 |
| 165 if (ViewsDelegate::GetInstance()) { | 167 if (ViewsDelegate::GetInstance()) { |
| 166 ViewsDelegate::GetInstance()->set_native_widget_factory( | 168 ViewsDelegate::GetInstance()->set_native_widget_factory( |
| 167 ViewsDelegate::NativeWidgetFactory()); | 169 ViewsDelegate::NativeWidgetFactory()); |
| 168 } | 170 } |
| 169 } | 171 } |
| 170 | 172 |
| 171 bool WindowManagerConnection::HasPointerWatcher() { | 173 bool WindowManagerConnection::HasPointerDownWatcher() { |
| 172 // Check to see if we really have any observers left. This doesn't use | 174 // Check to see if we really have any observers left. This doesn't use |
| 173 // base::ObserverList<>::might_have_observers() because that returns true | 175 // base::ObserverList<>::might_have_observers() because that returns true |
| 174 // during iteration over the list even when the last observer is removed. | 176 // during iteration over the list even when the last observer is removed. |
| 175 base::ObserverList<PointerWatcher>::Iterator iterator(&pointer_watchers_); | 177 base::ObserverList<PointerDownWatcher>::Iterator iterator( |
| 178 &pointer_down_watchers_); |
| 176 return !!iterator.GetNext(); | 179 return !!iterator.GetNext(); |
| 177 } | 180 } |
| 178 | 181 |
| 179 bool WindowManagerConnection::HasTouchEventWatcher() { | 182 bool WindowManagerConnection::HasTouchEventWatcher() { |
| 180 // Check to see if we really have any observers left. This doesn't use | 183 // Check to see if we really have any observers left. This doesn't use |
| 181 // base::ObserverList<>::might_have_observers() because that returns true | 184 // base::ObserverList<>::might_have_observers() because that returns true |
| 182 // during iteration over the list even when the last observer is removed. | 185 // during iteration over the list even when the last observer is removed. |
| 183 base::ObserverList<TouchEventWatcher>::Iterator iterator( | 186 base::ObserverList<TouchEventWatcher>::Iterator iterator( |
| 184 &touch_event_watchers_); | 187 &touch_event_watchers_); |
| 185 return !!iterator.GetNext(); | 188 return !!iterator.GetNext(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 202 Widget* target_widget = nullptr; | 205 Widget* target_widget = nullptr; |
| 203 if (target) { | 206 if (target) { |
| 204 ui::Window* root = target->GetRoot(); | 207 ui::Window* root = target->GetRoot(); |
| 205 target_widget = NativeWidgetMus::GetWidgetForWindow(root); | 208 target_widget = NativeWidgetMus::GetWidgetForWindow(root); |
| 206 } | 209 } |
| 207 | 210 |
| 208 // The mojo input events type converter uses the event root_location field | 211 // The mojo input events type converter uses the event root_location field |
| 209 // to store screen coordinates. Screen coordinates really should be returned | 212 // to store screen coordinates. Screen coordinates really should be returned |
| 210 // separately. See http://crbug.com/608547 | 213 // separately. See http://crbug.com/608547 |
| 211 gfx::Point location_in_screen = event.AsLocatedEvent()->root_location(); | 214 gfx::Point location_in_screen = event.AsLocatedEvent()->root_location(); |
| 212 if (HasPointerWatcher()) { | 215 if (HasPointerDownWatcher()) { |
| 213 if (event.type() == ui::ET_MOUSE_PRESSED) { | 216 if (event.type() == ui::ET_MOUSE_PRESSED) { |
| 214 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, | 217 FOR_EACH_OBSERVER(PointerDownWatcher, pointer_down_watchers_, |
| 215 OnMousePressed(*event.AsMouseEvent(), | 218 OnMousePressed(*event.AsMouseEvent(), |
| 216 location_in_screen, target_widget)); | 219 location_in_screen, target_widget)); |
| 217 } else if (event.type() == ui::ET_TOUCH_PRESSED) { | 220 } else if (event.type() == ui::ET_TOUCH_PRESSED) { |
| 218 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, | 221 FOR_EACH_OBSERVER(PointerDownWatcher, pointer_down_watchers_, |
| 219 OnTouchPressed(*event.AsTouchEvent(), | 222 OnTouchPressed(*event.AsTouchEvent(), |
| 220 location_in_screen, target_widget)); | 223 location_in_screen, target_widget)); |
| 221 } | 224 } |
| 222 } else if (HasTouchEventWatcher()) { | 225 } else if (HasTouchEventWatcher()) { |
| 223 if (event.IsTouchEvent() || event.IsTouchPointerEvent()) { | 226 if (event.IsTouchEvent() || event.IsTouchPointerEvent()) { |
| 224 FOR_EACH_OBSERVER( | 227 FOR_EACH_OBSERVER( |
| 225 TouchEventWatcher, touch_event_watchers_, | 228 TouchEventWatcher, touch_event_watchers_, |
| 226 OnTouchEventObserved(*event.AsLocatedEvent(), target_widget)); | 229 OnTouchEventObserved(*event.AsLocatedEvent(), target_widget)); |
| 227 } | 230 } |
| 228 } | 231 } |
| 229 } | 232 } |
| 230 | 233 |
| 231 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { | 234 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { |
| 232 if (client_) | 235 if (client_) |
| 233 NativeWidgetMus::NotifyFrameChanged(client_.get()); | 236 NativeWidgetMus::NotifyFrameChanged(client_.get()); |
| 234 } | 237 } |
| 235 | 238 |
| 236 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { | 239 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { |
| 237 return client_->GetCursorScreenPoint(); | 240 return client_->GetCursorScreenPoint(); |
| 238 } | 241 } |
| 239 | 242 |
| 240 } // namespace views | 243 } // namespace views |
| OLD | NEW |