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 // Disabled views are permitted to be targets of gesture events, but | |
643 // gesture events should never actually be dispatched to them. | |
644 if (!gesture_handler_->enabled()) { | |
645 event->SetHandled(); | |
sadrul
2014/08/15 18:58:52
the indent here seems off
tdanderson
2014/08/15 20:21:50
Done.
| |
646 | |
647 if (event->type() == ui::ET_GESTURE_END) { | |
648 DCHECK_EQ(1, event->details().touch_points()); | |
649 // In case a drag was in progress, reset all the handlers. Otherwise, | |
650 // just reset the gesture handler. | |
651 if (gesture_handler_ == mouse_pressed_handler_) | |
652 SetMouseHandler(NULL); | |
653 else | |
654 gesture_handler_ = NULL; | |
655 } | |
sadrul
2014/08/15 18:58:52
Can you combine this block with the code below in
tdanderson
2014/08/15 20:21:50
Done. (I didn't do this originally because the pla
| |
656 | |
657 return; | |
658 } | |
659 | |
642 // |gesture_handler_| can be deleted during processing. In particular, it | 660 // |gesture_handler_| can be deleted during processing. In particular, it |
643 // will be set to NULL if the view is deleted or removed from the tree as | 661 // will be set to NULL if the view is deleted or removed from the tree as |
644 // a result of an event dispatch. | 662 // a result of an event dispatch. |
645 ui::GestureEvent handler_event(*event, | 663 ui::GestureEvent handler_event(*event, |
646 static_cast<View*>(this), | 664 static_cast<View*>(this), |
647 gesture_handler_); | 665 gesture_handler_); |
648 ui::EventDispatchDetails dispatch_details = | 666 ui::EventDispatchDetails dispatch_details = |
649 DispatchEvent(gesture_handler_, &handler_event); | 667 DispatchEvent(gesture_handler_, &handler_event); |
650 if (dispatch_details.dispatcher_destroyed) | 668 if (dispatch_details.dispatcher_destroyed) |
651 return; | 669 return; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
708 touch_rect.Offset(-touch_rect.width() / 2, -touch_rect.height() / 2); | 726 touch_rect.Offset(-touch_rect.width() / 2, -touch_rect.height() / 2); |
709 gesture_handler = GetEventHandlerForRect(touch_rect); | 727 gesture_handler = GetEventHandlerForRect(touch_rect); |
710 } else { | 728 } else { |
711 gesture_handler = GetEventHandlerForPoint(event->location()); | 729 gesture_handler = GetEventHandlerForPoint(event->location()); |
712 } | 730 } |
713 | 731 |
714 // Walk up the tree until we find a view that wants the gesture event. | 732 // Walk up the tree until we find a view that wants the gesture event. |
715 for (gesture_handler_ = gesture_handler; | 733 for (gesture_handler_ = gesture_handler; |
716 gesture_handler_ && (gesture_handler_ != this); | 734 gesture_handler_ && (gesture_handler_ != this); |
717 gesture_handler_ = gesture_handler_->parent()) { | 735 gesture_handler_ = gesture_handler_->parent()) { |
718 // Disabled views eat events but are treated as not handled. | 736 // Disabled views are permitted to be targets of gesture events, but |
719 if (!gesture_handler_->enabled()) | 737 // gesture events should never actually be dispatched to them. |
738 if (!gesture_handler_->enabled()) { | |
739 event->SetHandled(); | |
740 | |
741 // Last ui::ET_GESTURE_END should not set the gesture_handler_. | |
742 if (event->type() == ui::ET_GESTURE_END) { | |
743 DCHECK_EQ(1, event->details().touch_points()); | |
744 gesture_handler_ = NULL; | |
745 } | |
746 | |
720 return; | 747 return; |
748 } | |
721 | 749 |
722 // See if this view wants to handle the Gesture. | 750 // See if this view wants to handle the Gesture. |
723 ui::GestureEvent gesture_event(*event, | 751 ui::GestureEvent gesture_event(*event, |
724 static_cast<View*>(this), | 752 static_cast<View*>(this), |
725 gesture_handler_); | 753 gesture_handler_); |
726 ui::EventDispatchDetails dispatch_details = | 754 ui::EventDispatchDetails dispatch_details = |
727 DispatchEvent(gesture_handler_, &gesture_event); | 755 DispatchEvent(gesture_handler_, &gesture_event); |
728 if (dispatch_details.dispatcher_destroyed) | 756 if (dispatch_details.dispatcher_destroyed) |
729 return; | 757 return; |
730 | 758 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
811 | 839 |
812 #ifndef NDEBUG | 840 #ifndef NDEBUG |
813 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_)); | 841 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_)); |
814 #endif | 842 #endif |
815 | 843 |
816 return details; | 844 return details; |
817 } | 845 } |
818 | 846 |
819 } // namespace internal | 847 } // namespace internal |
820 } // namespace views | 848 } // namespace views |
OLD | NEW |