OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/widget/root_view.h" | 5 #include "ui/views/widget/root_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
486 if (mouse_move_handler_ != NULL && | 486 if (mouse_move_handler_ != NULL && |
487 (!mouse_move_handler_->notify_enter_exit_on_child() || | 487 (!mouse_move_handler_->notify_enter_exit_on_child() || |
488 !mouse_move_handler_->Contains(v))) { | 488 !mouse_move_handler_->Contains(v))) { |
489 MouseEnterExitEvent exit(event, ui::ET_MOUSE_EXITED); | 489 MouseEnterExitEvent exit(event, ui::ET_MOUSE_EXITED); |
490 exit.ConvertLocationToTarget(static_cast<View*>(this), | 490 exit.ConvertLocationToTarget(static_cast<View*>(this), |
491 mouse_move_handler_); | 491 mouse_move_handler_); |
492 ui::EventDispatchDetails dispatch_details = | 492 ui::EventDispatchDetails dispatch_details = |
493 DispatchEvent(mouse_move_handler_, &exit); | 493 DispatchEvent(mouse_move_handler_, &exit); |
494 if (dispatch_details.dispatcher_destroyed) | 494 if (dispatch_details.dispatcher_destroyed) |
495 return; | 495 return; |
496 NotifyEnterExitOfDescendant(event, ui::ET_MOUSE_EXITED, | 496 // The mouse_move_handler_ could get reset to NULL if we end up in a |
497 mouse_move_handler_, v); | 497 // nested DispatchEvent callstack. |
498 if (mouse_move_handler_) { | |
sadrul
2015/03/17 16:09:14
I think checking for !dispatch_details.target_dest
ananta
2015/03/18 01:11:06
Done.
| |
499 NotifyEnterExitOfDescendant(event, ui::ET_MOUSE_EXITED, | |
500 mouse_move_handler_, v); | |
501 } | |
498 } | 502 } |
499 View* old_handler = mouse_move_handler_; | 503 View* old_handler = mouse_move_handler_; |
500 mouse_move_handler_ = v; | 504 mouse_move_handler_ = v; |
501 if (!mouse_move_handler_->notify_enter_exit_on_child() || | 505 if (!mouse_move_handler_->notify_enter_exit_on_child() || |
502 !mouse_move_handler_->Contains(old_handler)) { | 506 !mouse_move_handler_->Contains(old_handler)) { |
503 MouseEnterExitEvent entered(event, ui::ET_MOUSE_ENTERED); | 507 MouseEnterExitEvent entered(event, ui::ET_MOUSE_ENTERED); |
504 entered.ConvertLocationToTarget(static_cast<View*>(this), | 508 entered.ConvertLocationToTarget(static_cast<View*>(this), |
505 mouse_move_handler_); | 509 mouse_move_handler_); |
506 ui::EventDispatchDetails dispatch_details = | 510 ui::EventDispatchDetails dispatch_details = |
507 DispatchEvent(mouse_move_handler_, &entered); | 511 DispatchEvent(mouse_move_handler_, &entered); |
508 if (dispatch_details.dispatcher_destroyed) | 512 if (dispatch_details.dispatcher_destroyed) |
509 return; | 513 return; |
510 NotifyEnterExitOfDescendant(event, ui::ET_MOUSE_ENTERED, | 514 // The mouse_move_handler_ could get reset to NULL if we end up in a |
511 mouse_move_handler_, old_handler); | 515 // nested DispatchEvent callstack. |
516 if (mouse_move_handler_) { | |
517 NotifyEnterExitOfDescendant(event, ui::ET_MOUSE_ENTERED, | |
518 mouse_move_handler_, old_handler); | |
519 } | |
512 } | 520 } |
513 } | 521 } |
514 ui::MouseEvent moved_event(event, static_cast<View*>(this), | 522 ui::MouseEvent moved_event(event, static_cast<View*>(this), |
515 mouse_move_handler_); | 523 mouse_move_handler_); |
516 mouse_move_handler_->OnMouseMoved(moved_event); | 524 mouse_move_handler_->OnMouseMoved(moved_event); |
517 // TODO(tdanderson): It may be possible to avoid setting the cursor twice | 525 // TODO(tdanderson): It may be possible to avoid setting the cursor twice |
518 // (once here and once from CompoundEventFilter) on a | 526 // (once here and once from CompoundEventFilter) on a |
519 // mousemove. See crbug.com/351469. | 527 // mousemove. See crbug.com/351469. |
520 if (!(moved_event.flags() & ui::EF_IS_NON_CLIENT)) | 528 if (!(moved_event.flags() & ui::EF_IS_NON_CLIENT)) |
521 widget_->SetCursor(mouse_move_handler_->GetCursor(moved_event)); | 529 widget_->SetCursor(mouse_move_handler_->GetCursor(moved_event)); |
522 } else if (mouse_move_handler_ != NULL) { | 530 } else if (mouse_move_handler_ != NULL) { |
523 MouseEnterExitEvent exited(event, ui::ET_MOUSE_EXITED); | 531 MouseEnterExitEvent exited(event, ui::ET_MOUSE_EXITED); |
524 ui::EventDispatchDetails dispatch_details = | 532 ui::EventDispatchDetails dispatch_details = |
525 DispatchEvent(mouse_move_handler_, &exited); | 533 DispatchEvent(mouse_move_handler_, &exited); |
526 if (dispatch_details.dispatcher_destroyed) | 534 if (dispatch_details.dispatcher_destroyed) |
527 return; | 535 return; |
528 NotifyEnterExitOfDescendant(event, ui::ET_MOUSE_EXITED, | 536 // The mouse_move_handler_ could get reset to NULL if we end up in a nested |
529 mouse_move_handler_, v); | 537 // DispatchEvent callstack. |
538 if (mouse_move_handler_) { | |
539 NotifyEnterExitOfDescendant(event, ui::ET_MOUSE_EXITED, | |
540 mouse_move_handler_, v); | |
541 } | |
530 // On Aura the non-client area extends slightly outside the root view for | 542 // On Aura the non-client area extends slightly outside the root view for |
531 // some windows. Let the non-client cursor handling code set the cursor | 543 // some windows. Let the non-client cursor handling code set the cursor |
532 // as we do above. | 544 // as we do above. |
533 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) | 545 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) |
534 widget_->SetCursor(gfx::kNullCursor); | 546 widget_->SetCursor(gfx::kNullCursor); |
535 mouse_move_handler_ = NULL; | 547 mouse_move_handler_ = NULL; |
536 } | 548 } |
537 } | 549 } |
538 | 550 |
539 void RootView::OnMouseExited(const ui::MouseEvent& event) { | 551 void RootView::OnMouseExited(const ui::MouseEvent& event) { |
540 if (mouse_move_handler_ != NULL) { | 552 if (mouse_move_handler_ != NULL) { |
541 MouseEnterExitEvent exited(event, ui::ET_MOUSE_EXITED); | 553 MouseEnterExitEvent exited(event, ui::ET_MOUSE_EXITED); |
542 ui::EventDispatchDetails dispatch_details = | 554 ui::EventDispatchDetails dispatch_details = |
543 DispatchEvent(mouse_move_handler_, &exited); | 555 DispatchEvent(mouse_move_handler_, &exited); |
544 if (dispatch_details.dispatcher_destroyed) | 556 if (dispatch_details.dispatcher_destroyed) |
545 return; | 557 return; |
546 NotifyEnterExitOfDescendant(event, ui::ET_MOUSE_EXITED, | 558 // The mouse_move_handler_ could get reset to NULL if we end up in a nested |
547 mouse_move_handler_, NULL); | 559 // DispatchEvent callstack. |
560 if (mouse_move_handler_) { | |
561 NotifyEnterExitOfDescendant(event, ui::ET_MOUSE_EXITED, | |
562 mouse_move_handler_, NULL); | |
563 } | |
548 mouse_move_handler_ = NULL; | 564 mouse_move_handler_ = NULL; |
549 } | 565 } |
550 } | 566 } |
551 | 567 |
552 bool RootView::OnMouseWheel(const ui::MouseWheelEvent& event) { | 568 bool RootView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
553 for (View* v = GetEventHandlerForPoint(event.location()); | 569 for (View* v = GetEventHandlerForPoint(event.location()); |
554 v && v != this && !event.handled(); v = v->parent()) { | 570 v && v != this && !event.handled(); v = v->parent()) { |
555 ui::EventDispatchDetails dispatch_details = | 571 ui::EventDispatchDetails dispatch_details = |
556 DispatchEvent(v, const_cast<ui::MouseWheelEvent*>(&event)); | 572 DispatchEvent(v, const_cast<ui::MouseWheelEvent*>(&event)); |
557 if (dispatch_details.dispatcher_destroyed || | 573 if (dispatch_details.dispatcher_destroyed || |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
650 void RootView::SetMouseLocationAndFlags(const ui::MouseEvent& event) { | 666 void RootView::SetMouseLocationAndFlags(const ui::MouseEvent& event) { |
651 last_mouse_event_flags_ = event.flags(); | 667 last_mouse_event_flags_ = event.flags(); |
652 last_mouse_event_x_ = event.x(); | 668 last_mouse_event_x_ = event.x(); |
653 last_mouse_event_y_ = event.y(); | 669 last_mouse_event_y_ = event.y(); |
654 } | 670 } |
655 | 671 |
656 void RootView::NotifyEnterExitOfDescendant(const ui::MouseEvent& event, | 672 void RootView::NotifyEnterExitOfDescendant(const ui::MouseEvent& event, |
657 ui::EventType type, | 673 ui::EventType type, |
658 View* view, | 674 View* view, |
659 View* sibling) { | 675 View* sibling) { |
676 CHECK(view); | |
660 for (View* p = view->parent(); p; p = p->parent()) { | 677 for (View* p = view->parent(); p; p = p->parent()) { |
661 if (!p->notify_enter_exit_on_child()) | 678 if (!p->notify_enter_exit_on_child()) |
662 continue; | 679 continue; |
663 if (sibling && p->Contains(sibling)) | 680 if (sibling && p->Contains(sibling)) |
664 break; | 681 break; |
665 // It is necessary to recreate the notify-event for each dispatch, since one | 682 // It is necessary to recreate the notify-event for each dispatch, since one |
666 // of the callbacks can mark the event as handled, and that would cause | 683 // of the callbacks can mark the event as handled, and that would cause |
667 // incorrect event dispatch. | 684 // incorrect event dispatch. |
668 MouseEnterExitEvent notify_event(event, type); | 685 MouseEnterExitEvent notify_event(event, type); |
669 ui::EventDispatchDetails dispatch_details = DispatchEvent(p, ¬ify_event); | 686 ui::EventDispatchDetails dispatch_details = DispatchEvent(p, ¬ify_event); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
725 | 742 |
726 #ifndef NDEBUG | 743 #ifndef NDEBUG |
727 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_)); | 744 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_)); |
728 #endif | 745 #endif |
729 | 746 |
730 return details; | 747 return details; |
731 } | 748 } |
732 | 749 |
733 } // namespace internal | 750 } // namespace internal |
734 } // namespace views | 751 } // namespace views |
OLD | NEW |