Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: ui/aura/root_window.cc

Issue 10964051: events: Clean up dispatching code for touch-events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/aura/root_window.h ('k') | ui/aura/shared/compound_event_filter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/aura/root_window.h" 5 #include "ui/aura/root_window.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 654
655 bool RootWindow::ProcessKeyEvent(Window* target, ui::KeyEvent* event) { 655 bool RootWindow::ProcessKeyEvent(Window* target, ui::KeyEvent* event) {
656 if (!target) 656 if (!target)
657 target = this; 657 target = this;
658 AutoReset<Window*> reset(&event_dispatch_target_, target); 658 AutoReset<Window*> reset(&event_dispatch_target_, target);
659 if (ProcessEvent(target, event) != ui::ER_UNHANDLED) 659 if (ProcessEvent(target, event) != ui::ER_UNHANDLED)
660 return true; 660 return true;
661 return false; 661 return false;
662 } 662 }
663 663
664 ui::TouchStatus RootWindow::ProcessTouchEvent(Window* target, 664 ui::EventResult RootWindow::ProcessTouchEvent(Window* target,
665 ui::TouchEvent* event) { 665 ui::TouchEvent* event) {
666 if (ProcessEvent(NULL, event) != ui::ER_UNHANDLED) 666 if (!target)
667 return ui::TOUCH_STATUS_CONTINUE; 667 target = this;
668 668 AutoReset<Window*> reset(&event_dispatch_target_, target);
669 if (!target->IsVisible()) 669 return static_cast<ui::EventResult>(ProcessEvent(target, event));
670 return ui::TOUCH_STATUS_UNKNOWN;
671
672 ui::Event::DispatcherApi dispatch_helper(event);
673 dispatch_helper.set_target(target);
674
675 // It is necessary to dispatch the event to the event-handlers on env first.
676 // TODO(sad): Fix touch-event handling so it can use the same
677 // event-dispatching code used for other events.
678 ui::EventTarget::DispatcherApi dispatch_target_helper(Env::GetInstance());
679 const ui::EventHandlerList& pre_target =
680 dispatch_target_helper.pre_target_list();
681 for (ui::EventHandlerList::const_iterator iter = pre_target.begin();
682 iter != pre_target.end(); ++iter) {
683 ui::TouchStatus status = (*iter)->OnTouchEvent(event);
684 if (status != ui::TOUCH_STATUS_UNKNOWN)
685 return status;
686 }
687
688 EventFilters filters;
689 if (target == this)
690 GetEventFiltersToNotify(target, &filters);
691 else
692 GetEventFiltersToNotify(target->parent(), &filters);
693
694 // |target| can be deleted by any of the handlers below.
695 WindowTracker tracker;
696 tracker.Add(target);
697
698 for (EventFilters::const_reverse_iterator it = filters.rbegin(),
699 rend = filters.rend();
700 it != rend; ++it) {
701 ui::TouchStatus status = (*it)->PreHandleTouchEvent(target, event);
702 if (status != ui::TOUCH_STATUS_UNKNOWN)
703 return status;
704 }
705
706 if (tracker.Contains(target) && target->delegate()) {
707 ui::TouchStatus status = target->delegate()->OnTouchEvent(event);
708 if (status != ui::TOUCH_STATUS_UNKNOWN)
709 return status;
710 }
711
712 return ui::TOUCH_STATUS_UNKNOWN;
713 } 670 }
714 671
715 ui::EventResult RootWindow::ProcessGestureEvent(Window* target, 672 ui::EventResult RootWindow::ProcessGestureEvent(Window* target,
716 ui::GestureEvent* event) { 673 ui::GestureEvent* event) {
717 if (!target) 674 if (!target)
718 target = this; 675 target = this;
719 AutoReset<Window*> reset(&event_dispatch_target_, target); 676 AutoReset<Window*> reset(&event_dispatch_target_, target);
720 return static_cast<ui::EventResult>(ProcessEvent(target, event)); 677 return static_cast<ui::EventResult>(ProcessEvent(target, event));
721 } 678 }
722 679
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 break; 867 break;
911 868
912 default: 869 default:
913 break; 870 break;
914 } 871 }
915 float scale = ui::GetDeviceScaleFactor(layer()); 872 float scale = ui::GetDeviceScaleFactor(layer());
916 ui::Transform transform = layer()->transform(); 873 ui::Transform transform = layer()->transform();
917 transform.ConcatScale(scale, scale); 874 transform.ConcatScale(scale, scale);
918 event->UpdateForRootTransform(transform); 875 event->UpdateForRootTransform(transform);
919 bool handled = false; 876 bool handled = false;
920 ui::TouchStatus status = ui::TOUCH_STATUS_UNKNOWN; 877 ui::EventResult result = ui::ER_UNHANDLED;
921 Window* target = client::GetCaptureWindow(this); 878 Window* target = client::GetCaptureWindow(this);
922 if (!target) { 879 if (!target) {
923 target = ConsumerToWindow( 880 target = ConsumerToWindow(
924 gesture_recognizer_->GetTouchLockedTarget(event)); 881 gesture_recognizer_->GetTouchLockedTarget(event));
925 if (!target) { 882 if (!target) {
926 target = ConsumerToWindow( 883 target = ConsumerToWindow(
927 gesture_recognizer_->GetTargetForLocation(event->location())); 884 gesture_recognizer_->GetTargetForLocation(event->location()));
928 } 885 }
929 } 886 }
930 887
931 if (!target && !bounds().Contains(event->location())) { 888 if (!target && !bounds().Contains(event->location())) {
932 // If the initial touch is outside the root window, target the root. 889 // If the initial touch is outside the root window, target the root.
933 target = this; 890 target = this;
934 status = ProcessTouchEvent(target, event); 891 result = ProcessTouchEvent(target, event);
935 CHECK_EQ(ui::TOUCH_STATUS_UNKNOWN, status); 892 CHECK_EQ(ui::ER_UNHANDLED, result);
936 } else { 893 } else {
937 // We only come here when the first contact was within the root window. 894 // We only come here when the first contact was within the root window.
938 if (!target) { 895 if (!target) {
939 target = GetEventHandlerForPoint(event->location()); 896 target = GetEventHandlerForPoint(event->location());
940 if (!target) 897 if (!target)
941 return false; 898 return false;
942 } 899 }
943 900
944 ui::TouchEvent translated_event( 901 ui::TouchEvent translated_event(
945 *event, static_cast<Window*>(this), target); 902 *event, static_cast<Window*>(this), target);
946 status = ProcessTouchEvent(target, &translated_event); 903 result = ProcessTouchEvent(target, &translated_event);
947 handled = status != ui::TOUCH_STATUS_UNKNOWN; 904 handled = result != ui::ER_UNHANDLED;
948 905
949 if (status == ui::TOUCH_STATUS_QUEUED || 906 if (result & ui::ER_ASYNC) {
950 status == ui::TOUCH_STATUS_QUEUED_END) {
951 gesture_recognizer_->QueueTouchEventForGesture(target, *event); 907 gesture_recognizer_->QueueTouchEventForGesture(target, *event);
952 return true; 908 return true;
953 } 909 }
954 } 910 }
955 911
956 // Get the list of GestureEvents from GestureRecognizer. 912 // Get the list of GestureEvents from GestureRecognizer.
957 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; 913 scoped_ptr<ui::GestureRecognizer::Gestures> gestures;
958 gestures.reset(gesture_recognizer_->ProcessTouchEventForGesture( 914 gestures.reset(gesture_recognizer_->ProcessTouchEventForGesture(
959 *event, status, target)); 915 *event, result, target));
960 916
961 return ProcessGestures(gestures.get()) ? true : handled; 917 return ProcessGestures(gestures.get()) ? true : handled;
962 } 918 }
963 919
964 void RootWindow::OnHostLostCapture() { 920 void RootWindow::OnHostLostCapture() {
965 Window* capture_window = client::GetCaptureWindow(this); 921 Window* capture_window = client::GetCaptureWindow(this);
966 if (capture_window && capture_window->GetRootWindow() == this) 922 if (capture_window && capture_window->GetRootWindow() == this)
967 capture_window->ReleaseCapture(); 923 capture_window->ReleaseCapture();
968 } 924 }
969 925
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 void RootWindow::UnlockCompositor() { 1058 void RootWindow::UnlockCompositor() {
1103 DCHECK(compositor_lock_); 1059 DCHECK(compositor_lock_);
1104 compositor_lock_ = NULL; 1060 compositor_lock_ = NULL;
1105 if (draw_on_compositor_unlock_) { 1061 if (draw_on_compositor_unlock_) {
1106 draw_on_compositor_unlock_ = false; 1062 draw_on_compositor_unlock_ = false;
1107 ScheduleDraw(); 1063 ScheduleDraw();
1108 } 1064 }
1109 } 1065 }
1110 1066
1111 } // namespace aura 1067 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/root_window.h ('k') | ui/aura/shared/compound_event_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698