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 "services/ui/ws/event_dispatcher.h" | 5 #include "services/ui/ws/event_dispatcher.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | |
9 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/task_scheduler/post_task.h" | |
10 #include "base/time/time.h" | 12 #include "base/time/time.h" |
11 #include "services/ui/ws/accelerator.h" | 13 #include "services/ui/ws/accelerator.h" |
12 #include "services/ui/ws/drag_controller.h" | 14 #include "services/ui/ws/drag_controller.h" |
13 #include "services/ui/ws/drag_source.h" | 15 #include "services/ui/ws/drag_source.h" |
14 #include "services/ui/ws/event_dispatcher_delegate.h" | 16 #include "services/ui/ws/event_dispatcher_delegate.h" |
15 #include "services/ui/ws/server_window.h" | 17 #include "services/ui/ws/server_window.h" |
16 #include "services/ui/ws/server_window_delegate.h" | 18 #include "services/ui/ws/server_window_delegate.h" |
17 #include "services/ui/ws/window_coordinate_conversions.h" | 19 #include "services/ui/ws/window_coordinate_conversions.h" |
18 #include "services/ui/ws/window_finder.h" | 20 #include "services/ui/ws/window_finder.h" |
19 #include "ui/base/cursor/cursor.h" | 21 #include "ui/base/cursor/cursor.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
34 ui::EF_RIGHT_MOUSE_BUTTON); | 36 ui::EF_RIGHT_MOUSE_BUTTON); |
35 return button_only_flags == ui::EF_LEFT_MOUSE_BUTTON || | 37 return button_only_flags == ui::EF_LEFT_MOUSE_BUTTON || |
36 button_only_flags == ui::EF_MIDDLE_MOUSE_BUTTON || | 38 button_only_flags == ui::EF_MIDDLE_MOUSE_BUTTON || |
37 button_only_flags == ui::EF_RIGHT_MOUSE_BUTTON; | 39 button_only_flags == ui::EF_RIGHT_MOUSE_BUTTON; |
38 } | 40 } |
39 | 41 |
40 } // namespace | 42 } // namespace |
41 | 43 |
42 //////////////////////////////////////////////////////////////////////////////// | 44 //////////////////////////////////////////////////////////////////////////////// |
43 | 45 |
46 EventDispatcher::HitTestRequest::HitTestRequest(const gfx::Point& location, | |
47 HitTestCallback callback) | |
48 : hittest_location(location) { | |
49 hittest_callback = std::move(callback); | |
sky
2017/05/22 16:06:56
move to member initializer.
riajiang
2017/05/29 23:38:07
Done.
| |
50 } | |
51 | |
52 EventDispatcher::HitTestRequest::~HitTestRequest() {} | |
53 | |
44 EventDispatcher::EventDispatcher(EventDispatcherDelegate* delegate) | 54 EventDispatcher::EventDispatcher(EventDispatcherDelegate* delegate) |
45 : delegate_(delegate), | 55 : delegate_(delegate), |
46 capture_window_(nullptr), | 56 capture_window_(nullptr), |
47 capture_window_client_id_(kInvalidClientId), | 57 capture_window_client_id_(kInvalidClientId), |
48 modal_window_controller_(this), | 58 modal_window_controller_(this), |
49 mouse_button_down_(false), | 59 mouse_button_down_(false), |
50 mouse_cursor_source_window_(nullptr), | 60 mouse_cursor_source_window_(nullptr), |
51 mouse_cursor_in_non_client_area_(false) {} | 61 mouse_cursor_in_non_client_area_(false), |
62 hittest_in_flight_(false), | |
63 weak_ptr_factory_(this) {} | |
52 | 64 |
53 EventDispatcher::~EventDispatcher() { | 65 EventDispatcher::~EventDispatcher() { |
54 SetMouseCursorSourceWindow(nullptr); | 66 SetMouseCursorSourceWindow(nullptr); |
55 if (capture_window_) { | 67 if (capture_window_) { |
56 UnobserveWindow(capture_window_); | 68 UnobserveWindow(capture_window_); |
57 capture_window_ = nullptr; | 69 capture_window_ = nullptr; |
58 capture_window_client_id_ = kInvalidClientId; | 70 capture_window_client_id_ = kInvalidClientId; |
59 } | 71 } |
60 for (const auto& pair : pointer_targets_) { | 72 for (const auto& pair : pointer_targets_) { |
61 if (pair.second.window) | 73 if (pair.second.window) |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 const ClientSpecificId target_client_id = delegate_->GetEventTargetClientId( | 224 const ClientSpecificId target_client_id = delegate_->GetEventTargetClientId( |
213 mouse_cursor_source_window_, mouse_cursor_in_non_client_area_); | 225 mouse_cursor_source_window_, mouse_cursor_in_non_client_area_); |
214 const ServerWindow* window = mouse_cursor_source_window_; | 226 const ServerWindow* window = mouse_cursor_source_window_; |
215 while (window && window->id().client_id == target_client_id) | 227 while (window && window->id().client_id == target_client_id) |
216 window = window->parent(); | 228 window = window->parent(); |
217 return window; | 229 return window; |
218 } | 230 } |
219 | 231 |
220 void EventDispatcher::UpdateNonClientAreaForCurrentWindow() { | 232 void EventDispatcher::UpdateNonClientAreaForCurrentWindow() { |
221 if (mouse_cursor_source_window_) { | 233 if (mouse_cursor_source_window_) { |
222 DeepestWindow deepest_window = | 234 FindDeepestVisibleWindowForEvents( |
223 FindDeepestVisibleWindowForEvents(mouse_pointer_last_location_); | 235 mouse_pointer_last_location_, |
224 if (deepest_window.window == mouse_cursor_source_window_) { | 236 base::BindOnce( |
225 mouse_cursor_in_non_client_area_ = mouse_cursor_source_window_ | 237 &EventDispatcher::UpdateNonClientAreaForCurrentWindowOnFoundWindow, |
226 ? deepest_window.in_non_client_area | 238 weak_ptr_factory_.GetWeakPtr())); |
227 : false; | |
228 } | |
229 } | 239 } |
230 } | 240 } |
231 | 241 |
232 void EventDispatcher::UpdateCursorProviderByLastKnownLocation() { | 242 void EventDispatcher::UpdateCursorProviderByLastKnownLocation() { |
233 if (!mouse_button_down_) { | 243 if (!mouse_button_down_) { |
234 DeepestWindow deepest_window = | 244 FindDeepestVisibleWindowForEvents( |
235 FindDeepestVisibleWindowForEvents(mouse_pointer_last_location_); | 245 mouse_pointer_last_location_, |
236 SetMouseCursorSourceWindow(deepest_window.window); | 246 base::BindOnce(&EventDispatcher:: |
237 if (mouse_cursor_source_window_) { | 247 UpdateCursorProviderByLastKnownLocationOnFoundWindow, |
238 mouse_cursor_in_non_client_area_ = deepest_window.in_non_client_area; | 248 weak_ptr_factory_.GetWeakPtr())); |
239 } else { | |
240 gfx::Point location = mouse_pointer_last_location_; | |
241 SetMouseCursorSourceWindow(delegate_->GetRootWindowContaining(&location)); | |
242 mouse_cursor_in_non_client_area_ = true; | |
243 } | |
244 } | 249 } |
245 } | 250 } |
246 | 251 |
247 bool EventDispatcher::AddAccelerator(uint32_t id, | 252 bool EventDispatcher::AddAccelerator(uint32_t id, |
248 mojom::EventMatcherPtr event_matcher) { | 253 mojom::EventMatcherPtr event_matcher) { |
249 std::unique_ptr<Accelerator> accelerator(new Accelerator(id, *event_matcher)); | 254 std::unique_ptr<Accelerator> accelerator(new Accelerator(id, *event_matcher)); |
250 // If an accelerator with the same id or matcher already exists, then abort. | 255 // If an accelerator with the same id or matcher already exists, then abort. |
251 for (const auto& pair : accelerators_) { | 256 for (const auto& pair : accelerators_) { |
252 if (pair.first == id) { | 257 if (pair.first == id) { |
253 DVLOG(1) << "duplicate accelerator. Accelerator id=" << accelerator->id() | 258 DVLOG(1) << "duplicate accelerator. Accelerator id=" << accelerator->id() |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 } | 306 } |
302 ProcessKeyEvent(*key_event, match_phase); | 307 ProcessKeyEvent(*key_event, match_phase); |
303 return; | 308 return; |
304 } | 309 } |
305 | 310 |
306 DCHECK(event.IsPointerEvent()); | 311 DCHECK(event.IsPointerEvent()); |
307 ProcessPointerEvent(*event.AsPointerEvent()); | 312 ProcessPointerEvent(*event.AsPointerEvent()); |
308 return; | 313 return; |
309 } | 314 } |
310 | 315 |
316 bool EventDispatcher::IsHitTestInFlight() const { | |
317 if (hittest_in_flight_ || !hittest_request_queue_.empty()) | |
318 return true; | |
319 return false; | |
320 } | |
321 | |
311 void EventDispatcher::SetMouseCursorSourceWindow(ServerWindow* window) { | 322 void EventDispatcher::SetMouseCursorSourceWindow(ServerWindow* window) { |
312 if (mouse_cursor_source_window_ == window) | 323 if (mouse_cursor_source_window_ == window) |
313 return; | 324 return; |
314 | 325 |
315 if (mouse_cursor_source_window_) | 326 if (mouse_cursor_source_window_) |
316 UnobserveWindow(mouse_cursor_source_window_); | 327 UnobserveWindow(mouse_cursor_source_window_); |
317 mouse_cursor_source_window_ = window; | 328 mouse_cursor_source_window_ = window; |
318 if (mouse_cursor_source_window_) | 329 if (mouse_cursor_source_window_) |
319 ObserveWindow(mouse_cursor_source_window_); | 330 ObserveWindow(mouse_cursor_source_window_); |
320 } | 331 } |
(...skipping 19 matching lines...) Expand all Loading... | |
340 return; | 351 return; |
341 } | 352 } |
342 delegate_->OnEventTargetNotFound(event); | 353 delegate_->OnEventTargetNotFound(event); |
343 if (post_target) | 354 if (post_target) |
344 delegate_->OnAccelerator(post_target->id(), event, | 355 delegate_->OnAccelerator(post_target->id(), event, |
345 EventDispatcherDelegate::AcceleratorPhase::POST); | 356 EventDispatcherDelegate::AcceleratorPhase::POST); |
346 } | 357 } |
347 | 358 |
348 void EventDispatcher::ProcessPointerEvent(const ui::PointerEvent& event) { | 359 void EventDispatcher::ProcessPointerEvent(const ui::PointerEvent& event) { |
349 DCHECK(event.IsPointerEvent()); | 360 DCHECK(event.IsPointerEvent()); |
361 PointerTargetForEvent( | |
362 event, base::BindOnce(&EventDispatcher::ProcessPointerEventOnFoundTarget, | |
363 weak_ptr_factory_.GetWeakPtr(), event)); | |
364 } | |
365 | |
366 void EventDispatcher::ProcessPointerEventOnFoundTarget( | |
367 const ui::PointerEvent& event, | |
368 PointerTarget pointer_target_found) { | |
369 ProcessNextHittesetRequestFromQueue(); | |
370 | |
350 const bool is_mouse_event = event.IsMousePointerEvent(); | 371 const bool is_mouse_event = event.IsMousePointerEvent(); |
351 | 372 |
352 if (is_mouse_event) { | 373 if (is_mouse_event) { |
353 mouse_pointer_last_location_ = event.root_location(); | 374 mouse_pointer_last_location_ = event.root_location(); |
354 delegate_->OnMouseCursorLocationChanged(event.root_location()); | 375 delegate_->OnMouseCursorLocationChanged(event.root_location()); |
355 } | 376 } |
356 | 377 |
357 // Release capture on pointer up. For mouse we only release if there are | 378 // Release capture on pointer up. For mouse we only release if there are |
358 // no buttons down. | 379 // no buttons down. |
359 const bool is_pointer_going_up = | 380 const bool is_pointer_going_up = |
360 (event.type() == ui::ET_POINTER_UP || | 381 (event.type() == ui::ET_POINTER_UP || |
361 event.type() == ui::ET_POINTER_CANCELLED) && | 382 event.type() == ui::ET_POINTER_CANCELLED) && |
362 (!is_mouse_event || IsOnlyOneMouseButtonDown(event.flags())); | 383 (!is_mouse_event || IsOnlyOneMouseButtonDown(event.flags())); |
363 | 384 |
364 // Update mouse down state upon events which change it. | 385 // Update mouse down state upon events which change it. |
365 if (is_mouse_event) { | 386 if (is_mouse_event) { |
366 if (event.type() == ui::ET_POINTER_DOWN) | 387 if (event.type() == ui::ET_POINTER_DOWN) |
367 mouse_button_down_ = true; | 388 mouse_button_down_ = true; |
368 else if (is_pointer_going_up) | 389 else if (is_pointer_going_up) |
369 mouse_button_down_ = false; | 390 mouse_button_down_ = false; |
370 } | 391 } |
371 | 392 |
372 if (drag_controller_) { | 393 if (drag_controller_) { |
373 const PointerTarget target = PointerTargetForEvent(event); | 394 if (drag_controller_->DispatchPointerEvent(event, |
374 if (drag_controller_->DispatchPointerEvent(event, target.window)) | 395 pointer_target_found.window)) |
375 return; | 396 return; |
376 } | 397 } |
377 | 398 |
378 if (capture_window_) { | 399 if (capture_window_) { |
379 SetMouseCursorSourceWindow(capture_window_); | 400 SetMouseCursorSourceWindow(capture_window_); |
380 DispatchToClient(capture_window_, capture_window_client_id_, event); | 401 DispatchToClient(capture_window_, capture_window_client_id_, event); |
381 return; | 402 return; |
382 } | 403 } |
383 | 404 |
384 const int32_t pointer_id = event.pointer_details().id; | 405 const int32_t pointer_id = event.pointer_details().id; |
385 if (!IsTrackingPointer(pointer_id) || | 406 if (!IsTrackingPointer(pointer_id) || |
386 !pointer_targets_[pointer_id].is_pointer_down) { | 407 !pointer_targets_[pointer_id].is_pointer_down) { |
387 const bool any_pointers_down = AreAnyPointersDown(); | 408 const bool any_pointers_down = AreAnyPointersDown(); |
388 UpdateTargetForPointer(pointer_id, event); | 409 UpdateTargetForPointer(pointer_id, event, pointer_target_found); |
389 if (is_mouse_event) | 410 if (is_mouse_event) |
390 SetMouseCursorSourceWindow(pointer_targets_[pointer_id].window); | 411 SetMouseCursorSourceWindow(pointer_targets_[pointer_id].window); |
391 | 412 |
392 PointerTarget& pointer_target = pointer_targets_[pointer_id]; | 413 PointerTarget& pointer_target = pointer_targets_[pointer_id]; |
393 if (pointer_target.is_pointer_down) { | 414 if (pointer_target.is_pointer_down) { |
394 if (is_mouse_event) | 415 if (is_mouse_event) |
395 SetMouseCursorSourceWindow(pointer_target.window); | 416 SetMouseCursorSourceWindow(pointer_target.window); |
396 if (!any_pointers_down) { | 417 if (!any_pointers_down) { |
397 if (pointer_target.window) | 418 if (pointer_target.window) |
398 delegate_->SetFocusedWindowFromEventDispatcher(pointer_target.window); | 419 delegate_->SetFocusedWindowFromEventDispatcher(pointer_target.window); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
436 } | 457 } |
437 | 458 |
438 void EventDispatcher::StopTrackingPointer(int32_t pointer_id) { | 459 void EventDispatcher::StopTrackingPointer(int32_t pointer_id) { |
439 DCHECK(IsTrackingPointer(pointer_id)); | 460 DCHECK(IsTrackingPointer(pointer_id)); |
440 ServerWindow* window = pointer_targets_[pointer_id].window; | 461 ServerWindow* window = pointer_targets_[pointer_id].window; |
441 pointer_targets_.erase(pointer_id); | 462 pointer_targets_.erase(pointer_id); |
442 if (window) | 463 if (window) |
443 UnobserveWindow(window); | 464 UnobserveWindow(window); |
444 } | 465 } |
445 | 466 |
446 void EventDispatcher::UpdateTargetForPointer(int32_t pointer_id, | 467 void EventDispatcher::UpdateTargetForPointer( |
447 const ui::LocatedEvent& event) { | 468 int32_t pointer_id, |
469 const ui::PointerEvent& event, | |
470 const PointerTarget& pointer_target_found) { | |
448 if (!IsTrackingPointer(pointer_id)) { | 471 if (!IsTrackingPointer(pointer_id)) { |
449 StartTrackingPointer(pointer_id, PointerTargetForEvent(event)); | 472 StartTrackingPointer(pointer_id, pointer_target_found); |
450 return; | 473 return; |
451 } | 474 } |
452 | 475 |
453 const PointerTarget pointer_target = PointerTargetForEvent(event); | 476 if (pointer_target_found.window == pointer_targets_[pointer_id].window && |
454 if (pointer_target.window == pointer_targets_[pointer_id].window && | 477 pointer_target_found.in_nonclient_area == |
455 pointer_target.in_nonclient_area == | |
456 pointer_targets_[pointer_id].in_nonclient_area) { | 478 pointer_targets_[pointer_id].in_nonclient_area) { |
457 // The targets are the same, only set the down state to true if necessary. | 479 // The targets are the same, only set the down state to true if necessary. |
458 // Down going to up is handled by ProcessLocatedEvent(). | 480 // Down going to up is handled by ProcessLocatedEvent(). |
459 if (pointer_target.is_pointer_down) | 481 if (pointer_target_found.is_pointer_down) |
460 pointer_targets_[pointer_id].is_pointer_down = true; | 482 pointer_targets_[pointer_id].is_pointer_down = true; |
461 return; | 483 return; |
462 } | 484 } |
463 | 485 |
464 // The targets are changing. Send an exit if appropriate. | 486 // The targets are changing. Send an exit if appropriate. |
465 if (event.IsMousePointerEvent()) { | 487 if (event.IsMousePointerEvent()) { |
466 ui::PointerEvent exit_event( | 488 ui::PointerEvent exit_event( |
467 ui::ET_POINTER_EXITED, event.location(), event.root_location(), | 489 ui::ET_POINTER_EXITED, event.location(), event.root_location(), |
468 event.flags(), 0 /* changed_button_flags */, | 490 event.flags(), 0 /* changed_button_flags */, |
469 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE, | 491 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE, |
470 ui::MouseEvent::kMousePointerId), | 492 ui::MouseEvent::kMousePointerId), |
471 event.time_stamp()); | 493 event.time_stamp()); |
472 DispatchToPointerTarget(pointer_targets_[pointer_id], exit_event); | 494 DispatchToPointerTarget(pointer_targets_[pointer_id], exit_event); |
473 } | 495 } |
474 | 496 |
475 // Technically we're updating in place, but calling start then stop makes for | 497 // Technically we're updating in place, but calling start then stop makes for |
476 // simpler code. | 498 // simpler code. |
477 StopTrackingPointer(pointer_id); | 499 StopTrackingPointer(pointer_id); |
478 StartTrackingPointer(pointer_id, pointer_target); | 500 StartTrackingPointer(pointer_id, pointer_target_found); |
479 } | 501 } |
480 | 502 |
481 EventDispatcher::PointerTarget EventDispatcher::PointerTargetForEvent( | 503 void EventDispatcher::PointerTargetForEvent( |
482 const ui::LocatedEvent& event) { | 504 const ui::PointerEvent& event, |
505 PointerTargetForEventCallback callback) { | |
506 FindDeepestVisibleWindowForEvents( | |
507 event.root_location(), | |
508 base::BindOnce(&EventDispatcher::PointerTargetForEventOnFoundWindow, | |
509 weak_ptr_factory_.GetWeakPtr(), event, | |
510 std::move(callback))); | |
511 } | |
512 | |
513 void EventDispatcher::PointerTargetForEventOnFoundWindow( | |
514 const ui::PointerEvent& event, | |
515 PointerTargetForEventCallback callback, | |
516 DeepestWindow deepest_window) { | |
483 PointerTarget pointer_target; | 517 PointerTarget pointer_target; |
484 DeepestWindow deepest_window = | |
485 FindDeepestVisibleWindowForEvents(event.root_location()); | |
486 pointer_target.window = | 518 pointer_target.window = |
487 modal_window_controller_.GetTargetForWindow(deepest_window.window); | 519 modal_window_controller_.GetTargetForWindow(deepest_window.window); |
488 pointer_target.is_mouse_event = event.IsMousePointerEvent(); | 520 pointer_target.is_mouse_event = event.IsMousePointerEvent(); |
489 pointer_target.in_nonclient_area = | 521 pointer_target.in_nonclient_area = |
490 deepest_window.window != pointer_target.window || | 522 deepest_window.window != pointer_target.window || |
491 !pointer_target.window || deepest_window.in_non_client_area; | 523 !pointer_target.window || deepest_window.in_non_client_area; |
492 pointer_target.is_pointer_down = event.type() == ui::ET_POINTER_DOWN; | 524 pointer_target.is_pointer_down = event.type() == ui::ET_POINTER_DOWN; |
493 return pointer_target; | 525 std::move(callback).Run(pointer_target); |
494 } | 526 } |
495 | 527 |
496 bool EventDispatcher::AreAnyPointersDown() const { | 528 bool EventDispatcher::AreAnyPointersDown() const { |
497 for (const auto& pair : pointer_targets_) { | 529 for (const auto& pair : pointer_targets_) { |
498 if (pair.second.is_pointer_down) | 530 if (pair.second.is_pointer_down) |
499 return true; | 531 return true; |
500 } | 532 } |
501 return false; | 533 return false; |
502 } | 534 } |
503 | 535 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
573 Accelerator* EventDispatcher::FindAccelerator( | 605 Accelerator* EventDispatcher::FindAccelerator( |
574 const ui::KeyEvent& event, | 606 const ui::KeyEvent& event, |
575 const ui::mojom::AcceleratorPhase phase) { | 607 const ui::mojom::AcceleratorPhase phase) { |
576 for (const auto& pair : accelerators_) { | 608 for (const auto& pair : accelerators_) { |
577 if (pair.second->MatchesEvent(event, phase)) | 609 if (pair.second->MatchesEvent(event, phase)) |
578 return pair.second.get(); | 610 return pair.second.get(); |
579 } | 611 } |
580 return nullptr; | 612 return nullptr; |
581 } | 613 } |
582 | 614 |
583 DeepestWindow EventDispatcher::FindDeepestVisibleWindowForEvents( | 615 void EventDispatcher::FindDeepestVisibleWindowForEvents( |
584 const gfx::Point& location) { | 616 const gfx::Point& location, |
617 HitTestCallback callback) { | |
618 if (IsHitTestInFlight()) { | |
619 std::unique_ptr<HitTestRequest> hittest_request = | |
620 base::MakeUnique<HitTestRequest>(location, std::move(callback)); | |
621 hittest_request_queue_.push(std::move(hittest_request)); | |
622 return; | |
623 } | |
624 | |
625 FindDeepestVisibleWindowForEventsImpl(location, std::move(callback)); | |
626 } | |
627 | |
628 void EventDispatcher::FindDeepestVisibleWindowForEventsImpl( | |
629 const gfx::Point& location, | |
630 HitTestCallback callback) { | |
631 // TODO(riajiang): After HitTestComponent is implemented, do synchronous | |
632 // hit-test for most cases using shared memory and only ask Blink | |
633 // asynchronously for hard cases. For now, assume all synchronous hit-tests | |
634 // failed if the "enable-async-event-targeting" flag is turned on. | |
635 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
636 "enable-async-event-targeting")) { | |
637 DCHECK(!hittest_in_flight_); | |
638 hittest_in_flight_ = true; | |
639 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
640 FROM_HERE, | |
641 base::BindOnce(&EventDispatcher::FindDeepestVisibleWindowForEventsAsync, | |
642 weak_ptr_factory_.GetWeakPtr(), location, | |
643 std::move(callback))); | |
644 } else { | |
645 FindDeepestVisibleWindowForEventsAsync(location, std::move(callback)); | |
646 } | |
647 } | |
648 | |
649 void EventDispatcher::FindDeepestVisibleWindowForEventsAsync( | |
650 const gfx::Point& location, | |
651 HitTestCallback callback) { | |
585 gfx::Point relative_location(location); | 652 gfx::Point relative_location(location); |
586 // For the case of no root. | |
587 ServerWindow* root = delegate_->GetRootWindowContaining(&relative_location); | 653 ServerWindow* root = delegate_->GetRootWindowContaining(&relative_location); |
588 return root ? ui::ws::FindDeepestVisibleWindowForEvents(root, | 654 if (root) { |
589 relative_location) | 655 std::move(callback).Run( |
590 : DeepestWindow(); | 656 ui::ws::FindDeepestVisibleWindowForEvents(root, relative_location)); |
657 } else { | |
658 std::move(callback).Run(DeepestWindow()); | |
659 } | |
660 } | |
661 | |
662 void EventDispatcher::UpdateNonClientAreaForCurrentWindowOnFoundWindow( | |
663 DeepestWindow deepest_window) { | |
664 ProcessNextHittesetRequestFromQueue(); | |
665 | |
666 if (deepest_window.window == mouse_cursor_source_window_) { | |
667 mouse_cursor_in_non_client_area_ = | |
668 mouse_cursor_source_window_ ? deepest_window.in_non_client_area : false; | |
669 } | |
670 delegate_->UpdateNativeCursorFromDispatcher(); | |
671 } | |
672 | |
673 void EventDispatcher::UpdateCursorProviderByLastKnownLocationOnFoundWindow( | |
674 DeepestWindow deepest_window) { | |
675 ProcessNextHittesetRequestFromQueue(); | |
676 | |
677 SetMouseCursorSourceWindow(deepest_window.window); | |
678 if (mouse_cursor_source_window_) { | |
679 mouse_cursor_in_non_client_area_ = deepest_window.in_non_client_area; | |
680 } else { | |
681 gfx::Point location = mouse_pointer_last_location_; | |
682 SetMouseCursorSourceWindow(delegate_->GetRootWindowContaining(&location)); | |
683 mouse_cursor_in_non_client_area_ = true; | |
684 } | |
685 delegate_->UpdateNativeCursorFromDispatcher(); | |
686 } | |
687 | |
688 void EventDispatcher::ProcessNextHittesetRequestFromQueue() { | |
689 hittest_in_flight_ = false; | |
690 if (hittest_request_queue_.empty()) { | |
691 delegate_->ProcessNextEventFromQueue(); | |
692 return; | |
693 } | |
694 std::unique_ptr<HitTestRequest> hittest_request = | |
695 std::move(hittest_request_queue_.front()); | |
696 hittest_request_queue_.pop(); | |
697 FindDeepestVisibleWindowForEventsImpl( | |
698 hittest_request->hittest_location, | |
699 std::move(hittest_request->hittest_callback)); | |
591 } | 700 } |
592 | 701 |
593 void EventDispatcher::CancelImplicitCaptureExcept(ServerWindow* window, | 702 void EventDispatcher::CancelImplicitCaptureExcept(ServerWindow* window, |
594 ClientSpecificId client_id) { | 703 ClientSpecificId client_id) { |
595 for (const auto& pair : pointer_targets_) { | 704 for (const auto& pair : pointer_targets_) { |
596 ServerWindow* target = pair.second.window; | 705 ServerWindow* target = pair.second.window; |
597 if (!target) | 706 if (!target) |
598 continue; | 707 continue; |
599 UnobserveWindow(target); | 708 UnobserveWindow(target); |
600 if (target == window) | 709 if (target == window) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
653 if (mouse_cursor_source_window_ == window) | 762 if (mouse_cursor_source_window_ == window) |
654 SetMouseCursorSourceWindow(nullptr); | 763 SetMouseCursorSourceWindow(nullptr); |
655 } | 764 } |
656 | 765 |
657 void EventDispatcher::OnDragCursorUpdated() { | 766 void EventDispatcher::OnDragCursorUpdated() { |
658 delegate_->UpdateNativeCursorFromDispatcher(); | 767 delegate_->UpdateNativeCursorFromDispatcher(); |
659 } | 768 } |
660 | 769 |
661 } // namespace ws | 770 } // namespace ws |
662 } // namespace ui | 771 } // namespace ui |
OLD | NEW |