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 "content/browser/renderer_host/render_widget_host_impl.h" | 5 #include "content/browser/renderer_host/render_widget_host_impl.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
850 | 850 |
851 void RenderWidgetHostImpl::ForwardMouseEvent(const WebMouseEvent& mouse_event) { | 851 void RenderWidgetHostImpl::ForwardMouseEvent(const WebMouseEvent& mouse_event) { |
852 ForwardMouseEventWithLatencyInfo(mouse_event, ui::LatencyInfo()); | 852 ForwardMouseEventWithLatencyInfo(mouse_event, ui::LatencyInfo()); |
853 } | 853 } |
854 | 854 |
855 void RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo( | 855 void RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo( |
856 const blink::WebMouseEvent& mouse_event, | 856 const blink::WebMouseEvent& mouse_event, |
857 const ui::LatencyInfo& ui_latency) { | 857 const ui::LatencyInfo& ui_latency) { |
858 TRACE_EVENT2("input", "RenderWidgetHostImpl::ForwardMouseEvent", | 858 TRACE_EVENT2("input", "RenderWidgetHostImpl::ForwardMouseEvent", |
859 "x", mouse_event.x, "y", mouse_event.y); | 859 "x", mouse_event.x, "y", mouse_event.y); |
| 860 ui::LatencyInfo::InputCoordinates logical_coordinates = { |
| 861 {mouse_event.x, mouse_event.y}}; |
860 | 862 |
861 ui::LatencyInfo latency_info = | 863 ui::LatencyInfo latency_info = CreateRWHLatencyInfoIfNotExist( |
862 CreateRWHLatencyInfoIfNotExist(&ui_latency, mouse_event.type); | 864 &ui_latency, mouse_event.type, logical_coordinates, 1); |
863 | 865 |
864 for (size_t i = 0; i < mouse_event_callbacks_.size(); ++i) { | 866 for (size_t i = 0; i < mouse_event_callbacks_.size(); ++i) { |
865 if (mouse_event_callbacks_[i].Run(mouse_event)) | 867 if (mouse_event_callbacks_[i].Run(mouse_event)) |
866 return; | 868 return; |
867 } | 869 } |
868 | 870 |
869 if (IgnoreInputEvents()) | 871 if (IgnoreInputEvents()) |
870 return; | 872 return; |
871 | 873 |
872 if (touch_emulator_ && touch_emulator_->HandleMouseEvent(mouse_event)) | 874 if (touch_emulator_ && touch_emulator_->HandleMouseEvent(mouse_event)) |
873 return; | 875 return; |
874 | 876 |
875 input_router_->SendMouseEvent(MouseEventWithLatencyInfo(mouse_event, | 877 input_router_->SendMouseEvent(MouseEventWithLatencyInfo(mouse_event, |
876 latency_info)); | 878 latency_info)); |
877 } | 879 } |
878 | 880 |
879 void RenderWidgetHostImpl::OnPointerEventActivate() { | 881 void RenderWidgetHostImpl::OnPointerEventActivate() { |
880 } | 882 } |
881 | 883 |
882 void RenderWidgetHostImpl::ForwardWheelEvent( | 884 void RenderWidgetHostImpl::ForwardWheelEvent( |
883 const WebMouseWheelEvent& wheel_event) { | 885 const WebMouseWheelEvent& wheel_event) { |
884 ForwardWheelEventWithLatencyInfo(wheel_event, ui::LatencyInfo()); | 886 ForwardWheelEventWithLatencyInfo(wheel_event, ui::LatencyInfo()); |
885 } | 887 } |
886 | 888 |
887 void RenderWidgetHostImpl::ForwardWheelEventWithLatencyInfo( | 889 void RenderWidgetHostImpl::ForwardWheelEventWithLatencyInfo( |
888 const blink::WebMouseWheelEvent& wheel_event, | 890 const blink::WebMouseWheelEvent& wheel_event, |
889 const ui::LatencyInfo& ui_latency) { | 891 const ui::LatencyInfo& ui_latency) { |
890 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardWheelEvent"); | 892 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardWheelEvent"); |
891 | 893 |
892 ui::LatencyInfo latency_info = | 894 ui::LatencyInfo::InputCoordinates logical_coordinates = { |
893 CreateRWHLatencyInfoIfNotExist(&ui_latency, wheel_event.type); | 895 {wheel_event.x, wheel_event.y}}; |
| 896 |
| 897 ui::LatencyInfo latency_info = CreateRWHLatencyInfoIfNotExist( |
| 898 &ui_latency, wheel_event.type, logical_coordinates, 1); |
894 | 899 |
895 if (IgnoreInputEvents()) | 900 if (IgnoreInputEvents()) |
896 return; | 901 return; |
897 | 902 |
898 if (touch_emulator_ && touch_emulator_->HandleMouseWheelEvent(wheel_event)) | 903 if (touch_emulator_ && touch_emulator_->HandleMouseWheelEvent(wheel_event)) |
899 return; | 904 return; |
900 | 905 |
901 input_router_->SendWheelEvent(MouseWheelEventWithLatencyInfo(wheel_event, | 906 input_router_->SendWheelEvent(MouseWheelEventWithLatencyInfo(wheel_event, |
902 latency_info)); | 907 latency_info)); |
903 } | 908 } |
904 | 909 |
905 void RenderWidgetHostImpl::ForwardGestureEvent( | 910 void RenderWidgetHostImpl::ForwardGestureEvent( |
906 const blink::WebGestureEvent& gesture_event) { | 911 const blink::WebGestureEvent& gesture_event) { |
907 ForwardGestureEventWithLatencyInfo(gesture_event, ui::LatencyInfo()); | 912 ForwardGestureEventWithLatencyInfo(gesture_event, ui::LatencyInfo()); |
908 } | 913 } |
909 | 914 |
910 void RenderWidgetHostImpl::ForwardGestureEventWithLatencyInfo( | 915 void RenderWidgetHostImpl::ForwardGestureEventWithLatencyInfo( |
911 const blink::WebGestureEvent& gesture_event, | 916 const blink::WebGestureEvent& gesture_event, |
912 const ui::LatencyInfo& ui_latency) { | 917 const ui::LatencyInfo& ui_latency) { |
913 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardGestureEvent"); | 918 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardGestureEvent"); |
914 // Early out if necessary, prior to performing latency logic. | 919 // Early out if necessary, prior to performing latency logic. |
915 if (IgnoreInputEvents()) | 920 if (IgnoreInputEvents()) |
916 return; | 921 return; |
917 | 922 |
918 if (delegate_->PreHandleGestureEvent(gesture_event)) | 923 if (delegate_->PreHandleGestureEvent(gesture_event)) |
919 return; | 924 return; |
920 | 925 |
921 ui::LatencyInfo latency_info = | 926 ui::LatencyInfo::InputCoordinates logical_coordinates = { |
922 CreateRWHLatencyInfoIfNotExist(&ui_latency, gesture_event.type); | 927 {gesture_event.x, gesture_event.y}}; |
| 928 |
| 929 ui::LatencyInfo latency_info = CreateRWHLatencyInfoIfNotExist( |
| 930 &ui_latency, gesture_event.type, logical_coordinates, 1); |
923 | 931 |
924 if (gesture_event.type == blink::WebInputEvent::GestureScrollUpdate) { | 932 if (gesture_event.type == blink::WebInputEvent::GestureScrollUpdate) { |
925 latency_info.AddLatencyNumber( | 933 latency_info.AddLatencyNumber( |
926 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_RWH_COMPONENT, | 934 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_RWH_COMPONENT, |
927 GetLatencyComponentId(), | 935 GetLatencyComponentId(), |
928 ++last_input_number_); | 936 ++last_input_number_); |
929 | 937 |
930 // Make a copy of the INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT with a | 938 // Make a copy of the INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT with a |
931 // different name INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT. | 939 // different name INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT. |
932 // So we can track the latency specifically for scroll update events. | 940 // So we can track the latency specifically for scroll update events. |
(...skipping 10 matching lines...) Expand all Loading... |
943 } | 951 } |
944 } | 952 } |
945 | 953 |
946 GestureEventWithLatencyInfo gesture_with_latency(gesture_event, latency_info); | 954 GestureEventWithLatencyInfo gesture_with_latency(gesture_event, latency_info); |
947 input_router_->SendGestureEvent(gesture_with_latency); | 955 input_router_->SendGestureEvent(gesture_with_latency); |
948 } | 956 } |
949 | 957 |
950 void RenderWidgetHostImpl::ForwardEmulatedTouchEvent( | 958 void RenderWidgetHostImpl::ForwardEmulatedTouchEvent( |
951 const blink::WebTouchEvent& touch_event) { | 959 const blink::WebTouchEvent& touch_event) { |
952 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardEmulatedTouchEvent"); | 960 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardEmulatedTouchEvent"); |
953 ui::LatencyInfo latency_info = | 961 |
954 CreateRWHLatencyInfoIfNotExist(NULL, touch_event.type); | 962 ui::LatencyInfo::InputCoordinates logical_coordinates; |
| 963 size_t logical_coordinates_size = |
| 964 std::min(static_cast<size_t>(ui::LatencyInfo::kMaxInputCoordinates), |
| 965 static_cast<size_t>(touch_event.touchesLength)); |
| 966 for (size_t i = 0; i < logical_coordinates_size; i++) { |
| 967 logical_coordinates[i][0] = touch_event.touches[i].position.x; |
| 968 logical_coordinates[i][1] = touch_event.touches[i].position.y; |
| 969 } |
| 970 |
| 971 ui::LatencyInfo latency_info = CreateRWHLatencyInfoIfNotExist( |
| 972 NULL, touch_event.type, logical_coordinates, logical_coordinates_size); |
955 TouchEventWithLatencyInfo touch_with_latency(touch_event, latency_info); | 973 TouchEventWithLatencyInfo touch_with_latency(touch_event, latency_info); |
956 input_router_->SendTouchEvent(touch_with_latency); | 974 input_router_->SendTouchEvent(touch_with_latency); |
957 } | 975 } |
958 | 976 |
959 void RenderWidgetHostImpl::ForwardTouchEventWithLatencyInfo( | 977 void RenderWidgetHostImpl::ForwardTouchEventWithLatencyInfo( |
960 const blink::WebTouchEvent& touch_event, | 978 const blink::WebTouchEvent& touch_event, |
961 const ui::LatencyInfo& ui_latency) { | 979 const ui::LatencyInfo& ui_latency) { |
962 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardTouchEvent"); | 980 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardTouchEvent"); |
963 | 981 |
964 // Always forward TouchEvents for touch stream consistency. They will be | 982 // Always forward TouchEvents for touch stream consistency. They will be |
965 // ignored if appropriate in FilterInputEvent(). | 983 // ignored if appropriate in FilterInputEvent(). |
966 | 984 |
| 985 ui::LatencyInfo::InputCoordinates logical_coordinates; |
| 986 size_t logical_coordinates_size = |
| 987 std::min(static_cast<size_t>(ui::LatencyInfo::kMaxInputCoordinates), |
| 988 static_cast<size_t>(touch_event.touchesLength)); |
| 989 for (size_t i = 0; i < logical_coordinates_size; i++) { |
| 990 logical_coordinates[i][0] = touch_event.touches[i].position.x; |
| 991 logical_coordinates[i][1] = touch_event.touches[i].position.y; |
| 992 } |
| 993 |
967 ui::LatencyInfo latency_info = | 994 ui::LatencyInfo latency_info = |
968 CreateRWHLatencyInfoIfNotExist(&ui_latency, touch_event.type); | 995 CreateRWHLatencyInfoIfNotExist(&ui_latency, |
| 996 touch_event.type, |
| 997 logical_coordinates, |
| 998 logical_coordinates_size); |
969 TouchEventWithLatencyInfo touch_with_latency(touch_event, latency_info); | 999 TouchEventWithLatencyInfo touch_with_latency(touch_event, latency_info); |
970 | 1000 |
971 if (touch_emulator_ && | 1001 if (touch_emulator_ && |
972 touch_emulator_->HandleTouchEvent(touch_with_latency.event)) { | 1002 touch_emulator_->HandleTouchEvent(touch_with_latency.event)) { |
973 if (view_) { | 1003 if (view_) { |
974 view_->ProcessAckedTouchEvent( | 1004 view_->ProcessAckedTouchEvent( |
975 touch_with_latency, INPUT_EVENT_ACK_STATE_CONSUMED); | 1005 touch_with_latency, INPUT_EVENT_ACK_STATE_CONSUMED); |
976 } | 1006 } |
977 return; | 1007 return; |
978 } | 1008 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 if (delegate_->PreHandleKeyboardEvent(key_event, &is_shortcut)) | 1067 if (delegate_->PreHandleKeyboardEvent(key_event, &is_shortcut)) |
1038 return; | 1068 return; |
1039 | 1069 |
1040 if (key_event.type == WebKeyboardEvent::RawKeyDown) | 1070 if (key_event.type == WebKeyboardEvent::RawKeyDown) |
1041 suppress_next_char_events_ = false; | 1071 suppress_next_char_events_ = false; |
1042 } | 1072 } |
1043 | 1073 |
1044 if (touch_emulator_ && touch_emulator_->HandleKeyboardEvent(key_event)) | 1074 if (touch_emulator_ && touch_emulator_->HandleKeyboardEvent(key_event)) |
1045 return; | 1075 return; |
1046 | 1076 |
| 1077 // Keyboard events have no coordinates attached. |
| 1078 ui::LatencyInfo::InputCoordinates logical_coordinates; |
| 1079 |
1047 input_router_->SendKeyboardEvent( | 1080 input_router_->SendKeyboardEvent( |
1048 key_event, | 1081 key_event, |
1049 CreateRWHLatencyInfoIfNotExist(NULL, key_event.type), | 1082 CreateRWHLatencyInfoIfNotExist( |
| 1083 NULL, key_event.type, logical_coordinates, 0), |
1050 is_shortcut); | 1084 is_shortcut); |
1051 } | 1085 } |
1052 | 1086 |
1053 void RenderWidgetHostImpl::QueueSyntheticGesture( | 1087 void RenderWidgetHostImpl::QueueSyntheticGesture( |
1054 scoped_ptr<SyntheticGesture> synthetic_gesture, | 1088 scoped_ptr<SyntheticGesture> synthetic_gesture, |
1055 const base::Callback<void(SyntheticGesture::Result)>& on_complete) { | 1089 const base::Callback<void(SyntheticGesture::Result)>& on_complete) { |
1056 if (!synthetic_gesture_controller_ && view_) { | 1090 if (!synthetic_gesture_controller_ && view_) { |
1057 synthetic_gesture_controller_.reset( | 1091 synthetic_gesture_controller_.reset( |
1058 new SyntheticGestureController( | 1092 new SyntheticGestureController( |
1059 view_->CreateSyntheticGestureTarget().Pass())); | 1093 view_->CreateSyntheticGestureTarget().Pass())); |
(...skipping 22 matching lines...) Expand all Loading... |
1082 int64 RenderWidgetHostImpl::GetLatencyComponentId() { | 1116 int64 RenderWidgetHostImpl::GetLatencyComponentId() { |
1083 return GetRoutingID() | (static_cast<int64>(GetProcess()->GetID()) << 32); | 1117 return GetRoutingID() | (static_cast<int64>(GetProcess()->GetID()) << 32); |
1084 } | 1118 } |
1085 | 1119 |
1086 // static | 1120 // static |
1087 void RenderWidgetHostImpl::DisableResizeAckCheckForTesting() { | 1121 void RenderWidgetHostImpl::DisableResizeAckCheckForTesting() { |
1088 g_check_for_pending_resize_ack = false; | 1122 g_check_for_pending_resize_ack = false; |
1089 } | 1123 } |
1090 | 1124 |
1091 ui::LatencyInfo RenderWidgetHostImpl::CreateRWHLatencyInfoIfNotExist( | 1125 ui::LatencyInfo RenderWidgetHostImpl::CreateRWHLatencyInfoIfNotExist( |
1092 const ui::LatencyInfo* original, WebInputEvent::Type type) { | 1126 const ui::LatencyInfo* original, |
| 1127 WebInputEvent::Type type, |
| 1128 const ui::LatencyInfo::InputCoordinates& logical_coordinates, |
| 1129 size_t logical_coordinates_size) { |
1093 ui::LatencyInfo info; | 1130 ui::LatencyInfo info; |
1094 if (original) | 1131 if (original) |
1095 info = *original; | 1132 info = *original; |
| 1133 |
1096 // In Aura, gesture event will already carry its original touch event's | 1134 // In Aura, gesture event will already carry its original touch event's |
1097 // INPUT_EVENT_LATENCY_RWH_COMPONENT. | 1135 // INPUT_EVENT_LATENCY_RWH_COMPONENT. |
1098 if (!info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, | 1136 if (!info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
1099 GetLatencyComponentId(), | 1137 GetLatencyComponentId(), |
1100 NULL)) { | 1138 NULL)) { |
1101 info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, | 1139 info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
1102 GetLatencyComponentId(), | 1140 GetLatencyComponentId(), |
1103 ++last_input_number_); | 1141 ++last_input_number_); |
1104 info.TraceEventType(WebInputEventTraits::GetName(type)); | 1142 info.TraceEventType(WebInputEventTraits::GetName(type)); |
| 1143 |
| 1144 // Convert logical coordinates to physical coordinates, based on the |
| 1145 // device scale factor. |
| 1146 float device_scale_factor = |
| 1147 screen_info_ ? screen_info_->deviceScaleFactor : 1; |
| 1148 DCHECK(logical_coordinates_size <= ui::LatencyInfo::kMaxInputCoordinates); |
| 1149 info.input_coordinates_size = logical_coordinates_size; |
| 1150 for (size_t i = 0; i < info.input_coordinates_size; i++) { |
| 1151 for (size_t j = 0; j < arraysize(logical_coordinates[i]); j++) { |
| 1152 info.input_coordinates[i][j] = |
| 1153 logical_coordinates[i][j] * device_scale_factor; |
| 1154 } |
| 1155 } |
1105 } | 1156 } |
| 1157 |
1106 return info; | 1158 return info; |
1107 } | 1159 } |
1108 | 1160 |
1109 | 1161 |
1110 void RenderWidgetHostImpl::AddKeyPressEventCallback( | 1162 void RenderWidgetHostImpl::AddKeyPressEventCallback( |
1111 const KeyPressEventCallback& callback) { | 1163 const KeyPressEventCallback& callback) { |
1112 key_press_event_callbacks_.push_back(callback); | 1164 key_press_event_callbacks_.push_back(callback); |
1113 } | 1165 } |
1114 | 1166 |
1115 void RenderWidgetHostImpl::RemoveKeyPressEventCallback( | 1167 void RenderWidgetHostImpl::RemoveKeyPressEventCallback( |
(...skipping 1206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2322 } | 2374 } |
2323 #endif | 2375 #endif |
2324 | 2376 |
2325 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() { | 2377 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() { |
2326 if (view_) | 2378 if (view_) |
2327 return view_->PreferredReadbackFormat(); | 2379 return view_->PreferredReadbackFormat(); |
2328 return kN32_SkColorType; | 2380 return kN32_SkColorType; |
2329 } | 2381 } |
2330 | 2382 |
2331 } // namespace content | 2383 } // namespace content |
OLD | NEW |