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 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 return &drag_info_; | 632 return &drag_info_; |
633 } | 633 } |
634 | 634 |
635 //////////////////////////////////////////////////////////////////////////////// | 635 //////////////////////////////////////////////////////////////////////////////// |
636 // RootView, private: | 636 // RootView, private: |
637 | 637 |
638 // Input ----------------------------------------------------------------------- | 638 // Input ----------------------------------------------------------------------- |
639 | 639 |
640 void RootView::DispatchGestureEvent(ui::GestureEvent* event) { | 640 void RootView::DispatchGestureEvent(ui::GestureEvent* event) { |
641 if (gesture_handler_) { | 641 if (gesture_handler_) { |
642 // |gesture_handler_| can be deleted during processing. In particular, it | 642 if (gesture_handler_->enabled()) { |
643 // will be set to NULL if the view is deleted or removed from the tree as | 643 // |gesture_handler_| can be deleted during processing. In particular, it |
644 // a result of an event dispatch. | 644 // will be set to NULL if the view is deleted or removed from the tree as |
645 ui::GestureEvent handler_event(*event, | 645 // a result of an event dispatch. |
646 static_cast<View*>(this), | 646 ui::GestureEvent handler_event(*event, |
647 gesture_handler_); | 647 static_cast<View*>(this), |
648 ui::EventDispatchDetails dispatch_details = | 648 gesture_handler_); |
649 DispatchEvent(gesture_handler_, &handler_event); | 649 ui::EventDispatchDetails dispatch_details = |
650 if (dispatch_details.dispatcher_destroyed) | 650 DispatchEvent(gesture_handler_, &handler_event); |
651 return; | 651 if (dispatch_details.dispatcher_destroyed) |
| 652 return; |
| 653 |
| 654 if (handler_event.stopped_propagation()) |
| 655 event->StopPropagation(); |
| 656 else if (handler_event.handled()) |
| 657 event->SetHandled(); |
| 658 } else { |
| 659 // Disabled views are permitted to be targets of gesture events, but |
| 660 // gesture events should never actually be dispatched to them. |
| 661 event->SetHandled(); |
| 662 } |
652 | 663 |
653 if (event->type() == ui::ET_GESTURE_END) { | 664 if (event->type() == ui::ET_GESTURE_END) { |
654 DCHECK_EQ(1, event->details().touch_points()); | 665 DCHECK_EQ(1, event->details().touch_points()); |
655 // In case a drag was in progress, reset all the handlers. Otherwise, just | 666 // In case a drag was in progress, reset all the handlers. Otherwise, just |
656 // reset the gesture handler. | 667 // reset the gesture handler. |
657 if (gesture_handler_ == mouse_pressed_handler_) | 668 if (gesture_handler_ == mouse_pressed_handler_) |
658 SetMouseHandler(NULL); | 669 SetMouseHandler(NULL); |
659 else | 670 else |
660 gesture_handler_ = NULL; | 671 gesture_handler_ = NULL; |
661 } | 672 } |
662 | 673 |
663 if (handler_event.stopped_propagation()) { | 674 if (event->handled()) |
664 event->StopPropagation(); | |
665 return; | 675 return; |
666 } else if (handler_event.handled()) { | |
667 event->SetHandled(); | |
668 return; | |
669 } | |
670 | 676 |
671 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) { | 677 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) { |
672 // Some view started processing gesture events, however it does not | 678 // Some view started processing gesture events, however it does not |
673 // process scroll-gesture events. In such case, we allow the event to | 679 // process scroll-gesture events. In such case, we allow the event to |
674 // bubble up. |gesture_handler_| is changed to its nearest ancestor | 680 // bubble up. |gesture_handler_| is changed to its nearest ancestor |
675 // that handles scroll-gesture events. | 681 // that handles scroll-gesture events. |
676 for (gesture_handler_ = gesture_handler_->parent(); | 682 for (gesture_handler_ = gesture_handler_->parent(); |
677 gesture_handler_ && gesture_handler_ != this; | 683 gesture_handler_ && gesture_handler_ != this; |
678 gesture_handler_ = gesture_handler_->parent()) { | 684 gesture_handler_ = gesture_handler_->parent()) { |
679 ui::GestureEvent gesture_event(*event, | 685 ui::GestureEvent gesture_event(*event, |
(...skipping 28 matching lines...) Expand all Loading... |
708 touch_rect.Offset(-touch_rect.width() / 2, -touch_rect.height() / 2); | 714 touch_rect.Offset(-touch_rect.width() / 2, -touch_rect.height() / 2); |
709 gesture_handler = GetEventHandlerForRect(touch_rect); | 715 gesture_handler = GetEventHandlerForRect(touch_rect); |
710 } else { | 716 } else { |
711 gesture_handler = GetEventHandlerForPoint(event->location()); | 717 gesture_handler = GetEventHandlerForPoint(event->location()); |
712 } | 718 } |
713 | 719 |
714 // Walk up the tree until we find a view that wants the gesture event. | 720 // Walk up the tree until we find a view that wants the gesture event. |
715 for (gesture_handler_ = gesture_handler; | 721 for (gesture_handler_ = gesture_handler; |
716 gesture_handler_ && (gesture_handler_ != this); | 722 gesture_handler_ && (gesture_handler_ != this); |
717 gesture_handler_ = gesture_handler_->parent()) { | 723 gesture_handler_ = gesture_handler_->parent()) { |
718 // Disabled views eat events but are treated as not handled. | 724 // Disabled views are permitted to be targets of gesture events, but |
719 if (!gesture_handler_->enabled()) | 725 // gesture events should never actually be dispatched to them. |
| 726 if (!gesture_handler_->enabled()) { |
| 727 event->SetHandled(); |
| 728 |
| 729 // Last ui::ET_GESTURE_END should not set the gesture_handler_. |
| 730 if (event->type() == ui::ET_GESTURE_END) { |
| 731 DCHECK_EQ(1, event->details().touch_points()); |
| 732 gesture_handler_ = NULL; |
| 733 } |
| 734 |
720 return; | 735 return; |
| 736 } |
721 | 737 |
722 // See if this view wants to handle the Gesture. | 738 // See if this view wants to handle the Gesture. |
723 ui::GestureEvent gesture_event(*event, | 739 ui::GestureEvent gesture_event(*event, |
724 static_cast<View*>(this), | 740 static_cast<View*>(this), |
725 gesture_handler_); | 741 gesture_handler_); |
726 ui::EventDispatchDetails dispatch_details = | 742 ui::EventDispatchDetails dispatch_details = |
727 DispatchEvent(gesture_handler_, &gesture_event); | 743 DispatchEvent(gesture_handler_, &gesture_event); |
728 if (dispatch_details.dispatcher_destroyed) | 744 if (dispatch_details.dispatcher_destroyed) |
729 return; | 745 return; |
730 | 746 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 | 827 |
812 #ifndef NDEBUG | 828 #ifndef NDEBUG |
813 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_)); | 829 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_)); |
814 #endif | 830 #endif |
815 | 831 |
816 return details; | 832 return details; |
817 } | 833 } |
818 | 834 |
819 } // namespace internal | 835 } // namespace internal |
820 } // namespace views | 836 } // namespace views |
OLD | NEW |