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 "components/mus/public/cpp/property_type_converters.h" | 11 #include "components/mus/public/cpp/property_type_converters.h" |
12 #include "components/mus/public/cpp/window.h" | 12 #include "components/mus/public/cpp/window.h" |
13 #include "components/mus/public/cpp/window_property.h" | 13 #include "components/mus/public/cpp/window_property.h" |
14 #include "components/mus/public/cpp/window_tree_client.h" | 14 #include "components/mus/public/cpp/window_tree_client.h" |
15 #include "components/mus/public/interfaces/event_matcher.mojom.h" | 15 #include "components/mus/public/interfaces/event_matcher.mojom.h" |
16 #include "components/mus/public/interfaces/window_tree.mojom.h" | 16 #include "components/mus/public/interfaces/window_tree.mojom.h" |
17 #include "mojo/common/common_type_converters.h" | |
17 #include "services/shell/public/cpp/connection.h" | 18 #include "services/shell/public/cpp/connection.h" |
18 #include "services/shell/public/cpp/connector.h" | 19 #include "services/shell/public/cpp/connector.h" |
19 #include "ui/views/mus/clipboard_mus.h" | 20 #include "ui/views/mus/clipboard_mus.h" |
20 #include "ui/views/mus/native_widget_mus.h" | 21 #include "ui/views/mus/native_widget_mus.h" |
21 #include "ui/views/mus/screen_mus.h" | 22 #include "ui/views/mus/screen_mus.h" |
22 #include "ui/views/pointer_watcher.h" | 23 #include "ui/views/pointer_watcher.h" |
23 #include "ui/views/views_delegate.h" | 24 #include "ui/views/views_delegate.h" |
24 | 25 |
25 namespace views { | 26 namespace views { |
26 namespace { | 27 namespace { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 mus::mojom::SurfaceType::DEFAULT); | 80 mus::mojom::SurfaceType::DEFAULT); |
80 } | 81 } |
81 | 82 |
82 void WindowManagerConnection::AddPointerWatcher(PointerWatcher* watcher) { | 83 void WindowManagerConnection::AddPointerWatcher(PointerWatcher* watcher) { |
83 bool had_watcher = HasPointerWatcher(); | 84 bool had_watcher = HasPointerWatcher(); |
84 pointer_watchers_.AddObserver(watcher); | 85 pointer_watchers_.AddObserver(watcher); |
85 if (!had_watcher) { | 86 if (!had_watcher) { |
86 // Start a watcher for pointer down. | 87 // Start a watcher for pointer down. |
87 // TODO(jamescook): Extend event observers to handle multiple event types. | 88 // TODO(jamescook): Extend event observers to handle multiple event types. |
88 mus::mojom::EventMatcherPtr matcher = mus::mojom::EventMatcher::New(); | 89 mus::mojom::EventMatcherPtr matcher = mus::mojom::EventMatcher::New(); |
89 matcher->type_matcher = mus::mojom::EventTypeMatcher::New(); | 90 matcher->types_matcher = mus::mojom::EventMultTypeMatcher::New(); |
90 matcher->type_matcher->type = ui::mojom::EventType::POINTER_DOWN; | 91 |
92 matcher->types_matcher->types = mojo::Array<ui::mojom::EventType>::New(4); | |
93 matcher->types_matcher->types.push_back(ui::mojom::EventType::POINTER_DOWN); | |
94 matcher->types_matcher->types.push_back(ui::mojom::EventType::POINTER_UP); | |
95 matcher->types_matcher->types.push_back(ui::mojom::EventType::POINTER_MOVE); | |
96 matcher->types_matcher->types.push_back( | |
97 ui::mojom::EventType::POINTER_CANCEL); | |
91 client_->SetEventObserver(std::move(matcher)); | 98 client_->SetEventObserver(std::move(matcher)); |
sadrul
2016/06/27 14:44:54
We currently have PointerWatcher instances that wa
riajiang
2016/06/28 21:52:51
Done.
| |
92 } | 99 } |
93 } | 100 } |
94 | 101 |
95 void WindowManagerConnection::RemovePointerWatcher(PointerWatcher* watcher) { | 102 void WindowManagerConnection::RemovePointerWatcher(PointerWatcher* watcher) { |
96 pointer_watchers_.RemoveObserver(watcher); | 103 pointer_watchers_.RemoveObserver(watcher); |
97 if (!HasPointerWatcher()) { | 104 if (!HasPointerWatcher()) { |
98 // Last PointerWatcher removed, stop the event observer. | 105 // Last PointerWatcher removed, stop the event observer. |
99 client_->SetEventObserver(nullptr); | 106 client_->SetEventObserver(nullptr); |
100 } | 107 } |
101 } | 108 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 mus::Window* root = target->GetRoot(); | 169 mus::Window* root = target->GetRoot(); |
163 target_widget = NativeWidgetMus::GetWidgetForWindow(root); | 170 target_widget = NativeWidgetMus::GetWidgetForWindow(root); |
164 } | 171 } |
165 | 172 |
166 // The mojo input events type converter uses the event root_location field | 173 // The mojo input events type converter uses the event root_location field |
167 // to store screen coordinates. Screen coordinates really should be returned | 174 // to store screen coordinates. Screen coordinates really should be returned |
168 // separately. See http://crbug.com/608547 | 175 // separately. See http://crbug.com/608547 |
169 gfx::Point location_in_screen = event.AsLocatedEvent()->root_location(); | 176 gfx::Point location_in_screen = event.AsLocatedEvent()->root_location(); |
170 if (event.type() == ui::ET_MOUSE_PRESSED) { | 177 if (event.type() == ui::ET_MOUSE_PRESSED) { |
171 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, | 178 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, |
172 OnMousePressed(*event.AsMouseEvent(), location_in_screen, | 179 OnMousePressObserved( |
173 target_widget)); | 180 *event.AsMouseEvent(), location_in_screen, |
181 target_widget)); | |
174 } else if (event.type() == ui::ET_TOUCH_PRESSED) { | 182 } else if (event.type() == ui::ET_TOUCH_PRESSED) { |
175 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, | 183 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, |
176 OnTouchPressed(*event.AsTouchEvent(), location_in_screen, | 184 OnTouchPressObserved( |
177 target_widget)); | 185 *event.AsTouchEvent(), location_in_screen, |
186 target_widget)); | |
187 } else if (event.type() == ui::ET_TOUCH_RELEASED) { | |
188 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, | |
189 OnTouchReleaseObserved( | |
190 *event.AsTouchEvent(), location_in_screen, | |
191 target_widget)); | |
192 } else if (event.type() == ui::ET_TOUCH_MOVED) { | |
193 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, | |
194 OnTouchMoveObserved( | |
195 *event.AsTouchEvent(), location_in_screen, | |
196 target_widget)); | |
197 } else if (event.type() == ui::ET_TOUCH_CANCELLED) { | |
198 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, | |
199 OnTouchCancellObserved( | |
200 *event.AsTouchEvent(), location_in_screen, | |
201 target_widget)); | |
178 } | 202 } |
179 } | 203 } |
180 | 204 |
181 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { | 205 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { |
182 if (client_) | 206 if (client_) |
183 NativeWidgetMus::NotifyFrameChanged(client_.get()); | 207 NativeWidgetMus::NotifyFrameChanged(client_.get()); |
184 } | 208 } |
185 | 209 |
186 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { | 210 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { |
187 return client_->GetCursorScreenPoint(); | 211 return client_->GetCursorScreenPoint(); |
188 } | 212 } |
189 | 213 |
190 } // namespace views | 214 } // namespace views |
OLD | NEW |