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