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 "components/mus/ws/event_dispatcher.h" | 5 #include "components/mus/ws/event_dispatcher.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/time/time.h" | |
9 #include "cc/surfaces/surface_hittest.h" | 10 #include "cc/surfaces/surface_hittest.h" |
10 #include "components/mus/surfaces/surfaces_state.h" | 11 #include "components/mus/surfaces/surfaces_state.h" |
11 #include "components/mus/ws/event_dispatcher_delegate.h" | 12 #include "components/mus/ws/event_dispatcher_delegate.h" |
12 #include "components/mus/ws/server_window.h" | 13 #include "components/mus/ws/server_window.h" |
13 #include "components/mus/ws/server_window_delegate.h" | 14 #include "components/mus/ws/server_window_delegate.h" |
14 #include "components/mus/ws/window_coordinate_conversions.h" | 15 #include "components/mus/ws/window_coordinate_conversions.h" |
15 #include "components/mus/ws/window_finder.h" | 16 #include "components/mus/ws/window_finder.h" |
16 #include "components/mus/ws/window_tree_host_impl.h" | 17 #include "components/mus/ws/window_tree_host_impl.h" |
17 #include "mojo/converters/geometry/geometry_type_converters.h" | 18 #include "mojo/converters/geometry/geometry_type_converters.h" |
18 #include "ui/gfx/geometry/point.h" | 19 #include "ui/gfx/geometry/point.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 mojom::KeyboardCode keyboard_code_; | 151 mojom::KeyboardCode keyboard_code_; |
151 mojom::PointerKind pointer_kind_; | 152 mojom::PointerKind pointer_kind_; |
152 gfx::RectF pointer_region_; | 153 gfx::RectF pointer_region_; |
153 }; | 154 }; |
154 | 155 |
155 //////////////////////////////////////////////////////////////////////////////// | 156 //////////////////////////////////////////////////////////////////////////////// |
156 | 157 |
157 EventDispatcher::EventDispatcher(EventDispatcherDelegate* delegate) | 158 EventDispatcher::EventDispatcher(EventDispatcherDelegate* delegate) |
158 : delegate_(delegate), | 159 : delegate_(delegate), |
159 root_(nullptr), | 160 root_(nullptr), |
161 capture_window_(nullptr), | |
162 capture_window_in_nonclient_area_(false), | |
160 mouse_button_down_(false), | 163 mouse_button_down_(false), |
161 mouse_cursor_source_window_(nullptr) {} | 164 mouse_cursor_source_window_(nullptr) {} |
162 | 165 |
163 EventDispatcher::~EventDispatcher() { | 166 EventDispatcher::~EventDispatcher() { |
164 std::set<ServerWindow*> pointer_targets; | 167 std::set<ServerWindow*> pointer_targets; |
168 if (capture_window_) { | |
169 pointer_targets.insert(capture_window_); | |
170 capture_window_->RemoveObserver(this); | |
171 capture_window_ = nullptr; | |
172 } | |
165 for (const auto& pair : pointer_targets_) { | 173 for (const auto& pair : pointer_targets_) { |
166 if (pair.second.window && | 174 if (pair.second.window && |
167 pointer_targets.insert(pair.second.window).second) { | 175 pointer_targets.insert(pair.second.window).second) { |
168 pair.second.window->RemoveObserver(this); | 176 pair.second.window->RemoveObserver(this); |
169 } | 177 } |
170 } | 178 } |
179 pointer_targets_.clear(); | |
180 } | |
181 | |
182 void EventDispatcher::SetCaptureWindow(ServerWindow* window, | |
183 bool in_nonclient_area) { | |
184 if (window == capture_window_) | |
185 return; | |
186 | |
187 // Cancel implicit capture to all other windows. | |
188 bool observing_window = false; | |
189 std::set<ServerWindow*> unobserved_windows; | |
190 if (capture_window_) { | |
191 delegate_->OnLostCapture(capture_window_); | |
192 unobserved_windows.insert(capture_window_); | |
193 capture_window_->RemoveObserver(this); | |
194 } | |
195 | |
196 for (const auto& pair : pointer_targets_) { | |
197 ServerWindow* target = pair.second.window; | |
198 if (!target) | |
199 continue; | |
200 if (target == window) { | |
201 observing_window = true; | |
202 } else if (unobserved_windows.insert(target).second) { | |
sky
2016/01/29 20:47:00
Why do you only send the cancel once per window? I
jonross
2016/02/01 18:52:22
Good catch, I've updated this to send once cancel
| |
203 target->RemoveObserver(this); | |
204 mojom::EventPtr cancel_event = mojom::Event::New(); | |
205 cancel_event->action = mojom::EventType::POINTER_CANCEL; | |
206 cancel_event->flags = mojom::kEventFlagNone; | |
207 cancel_event->time_stamp = base::TimeTicks::Now().ToInternalValue(); | |
208 cancel_event->pointer_data = mojom::PointerData::New(); | |
209 // TODO(jonross): Do we want to track previous location in PointerTarger | |
sky
2016/01/29 20:47:00
PointerTarger->PointerTarget
And to your TODO, I t
jonross
2016/02/01 18:52:22
Fixed the comment.
I agree with storing the last
| |
210 // for sending cancels? | |
211 cancel_event->pointer_data->location = mojom::LocationData::New(); | |
212 cancel_event->pointer_data->pointer_id = pair.first; | |
213 DispatchToPointerTarget(pair.second, std::move(cancel_event)); | |
214 } | |
215 } | |
216 pointer_targets_.clear(); | |
217 | |
218 capture_window_ = window; | |
219 capture_window_in_nonclient_area_ = in_nonclient_area; | |
220 // Begin tracking the capture window if it is not yet being observed. | |
221 if (window && !observing_window) | |
222 window->AddObserver(this); | |
171 } | 223 } |
172 | 224 |
173 void EventDispatcher::UpdateCursorProviderByLastKnownLocation() { | 225 void EventDispatcher::UpdateCursorProviderByLastKnownLocation() { |
174 if (!mouse_button_down_) { | 226 if (!mouse_button_down_) { |
175 gfx::Point location = mouse_pointer_last_location_; | 227 gfx::Point location = mouse_pointer_last_location_; |
176 mouse_cursor_source_window_ = | 228 mouse_cursor_source_window_ = |
177 FindDeepestVisibleWindowForEvents(root_, surface_id_, &location); | 229 FindDeepestVisibleWindowForEvents(root_, surface_id_, &location); |
178 } | 230 } |
179 } | 231 } |
180 | 232 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 | 276 |
225 void EventDispatcher::ProcessKeyEvent(mojom::EventPtr event) { | 277 void EventDispatcher::ProcessKeyEvent(mojom::EventPtr event) { |
226 ServerWindow* focused_window = | 278 ServerWindow* focused_window = |
227 delegate_->GetFocusedWindowForEventDispatcher(); | 279 delegate_->GetFocusedWindowForEventDispatcher(); |
228 if (focused_window) | 280 if (focused_window) |
229 delegate_->DispatchInputEventToWindow(focused_window, false, | 281 delegate_->DispatchInputEventToWindow(focused_window, false, |
230 std::move(event)); | 282 std::move(event)); |
231 } | 283 } |
232 | 284 |
233 void EventDispatcher::ProcessPointerEvent(mojom::EventPtr event) { | 285 void EventDispatcher::ProcessPointerEvent(mojom::EventPtr event) { |
286 if (capture_window_) { | |
287 PointerTarget pointer_target; | |
288 pointer_target.window = capture_window_; | |
289 pointer_target.in_nonclient_area = capture_window_in_nonclient_area_; | |
290 DispatchToPointerTarget(pointer_target, std::move(event)); | |
291 return; | |
sky
2016/01/29 20:47:00
The problem with an early return here is mouse_poi
jonross
2016/02/01 18:52:22
I've moved this, and added logic for updating mous
| |
292 } | |
293 | |
234 const bool is_mouse_event = event->pointer_data && | 294 const bool is_mouse_event = event->pointer_data && |
235 event->pointer_data->kind == mojom::PointerKind::MOUSE; | 295 event->pointer_data->kind == mojom::PointerKind::MOUSE; |
236 | 296 |
237 if (is_mouse_event) | 297 if (is_mouse_event) |
238 mouse_pointer_last_location_ = EventLocationToPoint(*event); | 298 mouse_pointer_last_location_ = EventLocationToPoint(*event); |
239 | 299 |
240 const int32_t pointer_id = event->pointer_data->pointer_id; | 300 const int32_t pointer_id = event->pointer_data->pointer_id; |
241 if (!IsTrackingPointer(pointer_id) || | 301 if (!IsTrackingPointer(pointer_id) || |
242 !pointer_targets_[pointer_id].is_pointer_down) { | 302 !pointer_targets_[pointer_id].is_pointer_down) { |
243 const bool any_pointers_down = AreAnyPointersDown(); | 303 const bool any_pointers_down = AreAnyPointersDown(); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
373 transform.TransformPoint(&location); | 433 transform.TransformPoint(&location); |
374 event->pointer_data->location->x = location.x(); | 434 event->pointer_data->location->x = location.x(); |
375 event->pointer_data->location->y = location.y(); | 435 event->pointer_data->location->y = location.y(); |
376 delegate_->DispatchInputEventToWindow(target.window, target.in_nonclient_area, | 436 delegate_->DispatchInputEventToWindow(target.window, target.in_nonclient_area, |
377 std::move(event)); | 437 std::move(event)); |
378 } | 438 } |
379 | 439 |
380 void EventDispatcher::CancelPointerEventsToTarget(ServerWindow* window) { | 440 void EventDispatcher::CancelPointerEventsToTarget(ServerWindow* window) { |
381 window->RemoveObserver(this); | 441 window->RemoveObserver(this); |
382 | 442 |
443 if (capture_window_ == window) { | |
sky
2016/01/29 20:47:00
When this happens you may need to update the curso
jonross
2016/02/01 18:52:22
Done.
| |
444 capture_window_ = nullptr; | |
445 // A window only cares to be informed that it lost capture if it explicitly | |
446 // requested capture. A window can lose capture if another window gains | |
447 // explicit capture. | |
448 delegate_->OnLostCapture(window); | |
449 return; | |
450 } | |
451 | |
383 for (auto& pair : pointer_targets_) { | 452 for (auto& pair : pointer_targets_) { |
384 if (pair.second.window == window) | 453 if (pair.second.window == window) |
385 pair.second.window = nullptr; | 454 pair.second.window = nullptr; |
386 } | 455 } |
387 } | 456 } |
388 | 457 |
389 bool EventDispatcher::IsObservingWindow(ServerWindow* window) { | 458 bool EventDispatcher::IsObservingWindow(ServerWindow* window) { |
390 for (const auto& pair : pointer_targets_) { | 459 for (const auto& pair : pointer_targets_) { |
391 if (pair.second.window == window) | 460 if (pair.second.window == window) |
392 return true; | 461 return true; |
(...skipping 25 matching lines...) Expand all Loading... | |
418 | 487 |
419 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { | 488 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { |
420 CancelPointerEventsToTarget(window); | 489 CancelPointerEventsToTarget(window); |
421 | 490 |
422 if (mouse_cursor_source_window_ == window) | 491 if (mouse_cursor_source_window_ == window) |
423 mouse_cursor_source_window_ = nullptr; | 492 mouse_cursor_source_window_ = nullptr; |
424 } | 493 } |
425 | 494 |
426 } // namespace ws | 495 } // namespace ws |
427 } // namespace mus | 496 } // namespace mus |
OLD | NEW |