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/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 Loading... |
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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 break; | 873 break; |
917 | 874 |
918 default: | 875 default: |
919 break; | 876 break; |
920 } | 877 } |
921 float scale = ui::GetDeviceScaleFactor(layer()); | 878 float scale = ui::GetDeviceScaleFactor(layer()); |
922 ui::Transform transform = layer()->transform(); | 879 ui::Transform transform = layer()->transform(); |
923 transform.ConcatScale(scale, scale); | 880 transform.ConcatScale(scale, scale); |
924 event->UpdateForRootTransform(transform); | 881 event->UpdateForRootTransform(transform); |
925 bool handled = false; | 882 bool handled = false; |
926 ui::TouchStatus status = ui::TOUCH_STATUS_UNKNOWN; | 883 ui::EventResult result = ui::ER_UNHANDLED; |
927 Window* target = client::GetCaptureWindow(this); | 884 Window* target = client::GetCaptureWindow(this); |
928 if (!target) { | 885 if (!target) { |
929 target = ConsumerToWindow( | 886 target = ConsumerToWindow( |
930 gesture_recognizer_->GetTouchLockedTarget(event)); | 887 gesture_recognizer_->GetTouchLockedTarget(event)); |
931 if (!target) { | 888 if (!target) { |
932 target = ConsumerToWindow( | 889 target = ConsumerToWindow( |
933 gesture_recognizer_->GetTargetForLocation(event->location())); | 890 gesture_recognizer_->GetTargetForLocation(event->location())); |
934 } | 891 } |
935 } | 892 } |
936 | 893 |
937 if (!target && !bounds().Contains(event->location())) { | 894 if (!target && !bounds().Contains(event->location())) { |
938 // If the initial touch is outside the root window, target the root. | 895 // If the initial touch is outside the root window, target the root. |
939 target = this; | 896 target = this; |
940 status = ProcessTouchEvent(target, event); | 897 result = ProcessTouchEvent(target, event); |
941 CHECK_EQ(ui::TOUCH_STATUS_UNKNOWN, status); | 898 CHECK_EQ(ui::ER_UNHANDLED, result); |
942 } else { | 899 } else { |
943 // We only come here when the first contact was within the root window. | 900 // We only come here when the first contact was within the root window. |
944 if (!target) { | 901 if (!target) { |
945 target = GetEventHandlerForPoint(event->location()); | 902 target = GetEventHandlerForPoint(event->location()); |
946 if (!target) | 903 if (!target) |
947 return false; | 904 return false; |
948 } | 905 } |
949 | 906 |
950 ui::TouchEvent translated_event( | 907 ui::TouchEvent translated_event( |
951 *event, static_cast<Window*>(this), target); | 908 *event, static_cast<Window*>(this), target); |
952 status = ProcessTouchEvent(target, &translated_event); | 909 result = ProcessTouchEvent(target, &translated_event); |
953 handled = status != ui::TOUCH_STATUS_UNKNOWN; | 910 handled = result != ui::ER_UNHANDLED; |
954 | 911 |
955 if (status == ui::TOUCH_STATUS_QUEUED || | 912 if (result & ui::ER_ASYNC) { |
956 status == ui::TOUCH_STATUS_QUEUED_END) { | |
957 gesture_recognizer_->QueueTouchEventForGesture(target, *event); | 913 gesture_recognizer_->QueueTouchEventForGesture(target, *event); |
958 return true; | 914 return true; |
959 } | 915 } |
960 } | 916 } |
961 | 917 |
962 // Get the list of GestureEvents from GestureRecognizer. | 918 // Get the list of GestureEvents from GestureRecognizer. |
963 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; | 919 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; |
964 gestures.reset(gesture_recognizer_->ProcessTouchEventForGesture( | 920 gestures.reset(gesture_recognizer_->ProcessTouchEventForGesture( |
965 *event, status, target)); | 921 *event, result, target)); |
966 | 922 |
967 return ProcessGestures(gestures.get()) ? true : handled; | 923 return ProcessGestures(gestures.get()) ? true : handled; |
968 } | 924 } |
969 | 925 |
970 void RootWindow::OnHostLostCapture() { | 926 void RootWindow::OnHostLostCapture() { |
971 Window* capture_window = client::GetCaptureWindow(this); | 927 Window* capture_window = client::GetCaptureWindow(this); |
972 if (capture_window && capture_window->GetRootWindow() == this) | 928 if (capture_window && capture_window->GetRootWindow() == this) |
973 capture_window->ReleaseCapture(); | 929 capture_window->ReleaseCapture(); |
974 } | 930 } |
975 | 931 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 void RootWindow::UnlockCompositor() { | 1064 void RootWindow::UnlockCompositor() { |
1109 DCHECK(compositor_lock_); | 1065 DCHECK(compositor_lock_); |
1110 compositor_lock_ = NULL; | 1066 compositor_lock_ = NULL; |
1111 if (draw_on_compositor_unlock_) { | 1067 if (draw_on_compositor_unlock_) { |
1112 draw_on_compositor_unlock_ = false; | 1068 draw_on_compositor_unlock_ = false; |
1113 ScheduleDraw(); | 1069 ScheduleDraw(); |
1114 } | 1070 } |
1115 } | 1071 } |
1116 | 1072 |
1117 } // namespace aura | 1073 } // namespace aura |
OLD | NEW |