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

Side by Side Diff: content/browser/renderer_host/render_widget_host_impl.cc

Issue 569653002: Add input coordinate information to InputLatency (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use uint32 instead of size_t to unbreak IPC. Created 6 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
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 "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
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::InputCoordinate logical_coordinate(mouse_event.x,
861 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_coordinate, 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::InputCoordinate logical_coordinate(wheel_event.x,
893 CreateRWHLatencyInfoIfNotExist(&ui_latency, wheel_event.type); 895 wheel_event.y);
896
897 ui::LatencyInfo latency_info = CreateRWHLatencyInfoIfNotExist(
898 &ui_latency, wheel_event.type, &logical_coordinate, 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::InputCoordinate logical_coordinate(gesture_event.x,
922 CreateRWHLatencyInfoIfNotExist(&ui_latency, gesture_event.type); 927 gesture_event.y);
928
929 ui::LatencyInfo latency_info = CreateRWHLatencyInfoIfNotExist(
930 &ui_latency, gesture_event.type, &logical_coordinate, 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
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::InputCoordinate
963 logical_coordinates[ui::LatencyInfo::kMaxInputCoordinates];
964 size_t logical_coordinates_size =
965 std::min(arraysize(logical_coordinates),
966 static_cast<size_t>(touch_event.touchesLength));
967 for (size_t i = 0; i < logical_coordinates_size; i++) {
968 logical_coordinates[i] = ui::LatencyInfo::InputCoordinate(
969 touch_event.touches[i].position.x, touch_event.touches[i].position.y);
970 }
971
972 ui::LatencyInfo latency_info = CreateRWHLatencyInfoIfNotExist(
973 NULL, touch_event.type, logical_coordinates, logical_coordinates_size);
955 TouchEventWithLatencyInfo touch_with_latency(touch_event, latency_info); 974 TouchEventWithLatencyInfo touch_with_latency(touch_event, latency_info);
956 input_router_->SendTouchEvent(touch_with_latency); 975 input_router_->SendTouchEvent(touch_with_latency);
957 } 976 }
958 977
959 void RenderWidgetHostImpl::ForwardTouchEventWithLatencyInfo( 978 void RenderWidgetHostImpl::ForwardTouchEventWithLatencyInfo(
960 const blink::WebTouchEvent& touch_event, 979 const blink::WebTouchEvent& touch_event,
961 const ui::LatencyInfo& ui_latency) { 980 const ui::LatencyInfo& ui_latency) {
962 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardTouchEvent"); 981 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardTouchEvent");
963 982
964 // Always forward TouchEvents for touch stream consistency. They will be 983 // Always forward TouchEvents for touch stream consistency. They will be
965 // ignored if appropriate in FilterInputEvent(). 984 // ignored if appropriate in FilterInputEvent().
966 985
986 ui::LatencyInfo::InputCoordinate
987 logical_coordinates[ui::LatencyInfo::kMaxInputCoordinates];
988 size_t logical_coordinates_size =
989 std::min(arraysize(logical_coordinates),
990 static_cast<size_t>(touch_event.touchesLength));
991 for (size_t i = 0; i < logical_coordinates_size; i++) {
992 logical_coordinates[i] = ui::LatencyInfo::InputCoordinate(
993 touch_event.touches[i].position.x, touch_event.touches[i].position.y);
994 }
995
967 ui::LatencyInfo latency_info = 996 ui::LatencyInfo latency_info =
968 CreateRWHLatencyInfoIfNotExist(&ui_latency, touch_event.type); 997 CreateRWHLatencyInfoIfNotExist(&ui_latency,
998 touch_event.type,
999 logical_coordinates,
1000 logical_coordinates_size);
969 TouchEventWithLatencyInfo touch_with_latency(touch_event, latency_info); 1001 TouchEventWithLatencyInfo touch_with_latency(touch_event, latency_info);
970 1002
971 if (touch_emulator_ && 1003 if (touch_emulator_ &&
972 touch_emulator_->HandleTouchEvent(touch_with_latency.event)) { 1004 touch_emulator_->HandleTouchEvent(touch_with_latency.event)) {
973 if (view_) { 1005 if (view_) {
974 view_->ProcessAckedTouchEvent( 1006 view_->ProcessAckedTouchEvent(
975 touch_with_latency, INPUT_EVENT_ACK_STATE_CONSUMED); 1007 touch_with_latency, INPUT_EVENT_ACK_STATE_CONSUMED);
976 } 1008 }
977 return; 1009 return;
978 } 1010 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 1071
1040 if (key_event.type == WebKeyboardEvent::RawKeyDown) 1072 if (key_event.type == WebKeyboardEvent::RawKeyDown)
1041 suppress_next_char_events_ = false; 1073 suppress_next_char_events_ = false;
1042 } 1074 }
1043 1075
1044 if (touch_emulator_ && touch_emulator_->HandleKeyboardEvent(key_event)) 1076 if (touch_emulator_ && touch_emulator_->HandleKeyboardEvent(key_event))
1045 return; 1077 return;
1046 1078
1047 input_router_->SendKeyboardEvent( 1079 input_router_->SendKeyboardEvent(
1048 key_event, 1080 key_event,
1049 CreateRWHLatencyInfoIfNotExist(NULL, key_event.type), 1081 CreateRWHLatencyInfoIfNotExist(NULL, key_event.type, NULL, 0),
1050 is_shortcut); 1082 is_shortcut);
1051 } 1083 }
1052 1084
1053 void RenderWidgetHostImpl::QueueSyntheticGesture( 1085 void RenderWidgetHostImpl::QueueSyntheticGesture(
1054 scoped_ptr<SyntheticGesture> synthetic_gesture, 1086 scoped_ptr<SyntheticGesture> synthetic_gesture,
1055 const base::Callback<void(SyntheticGesture::Result)>& on_complete) { 1087 const base::Callback<void(SyntheticGesture::Result)>& on_complete) {
1056 if (!synthetic_gesture_controller_ && view_) { 1088 if (!synthetic_gesture_controller_ && view_) {
1057 synthetic_gesture_controller_.reset( 1089 synthetic_gesture_controller_.reset(
1058 new SyntheticGestureController( 1090 new SyntheticGestureController(
1059 view_->CreateSyntheticGestureTarget().Pass())); 1091 view_->CreateSyntheticGestureTarget().Pass()));
(...skipping 22 matching lines...) Expand all
1082 int64 RenderWidgetHostImpl::GetLatencyComponentId() { 1114 int64 RenderWidgetHostImpl::GetLatencyComponentId() {
1083 return GetRoutingID() | (static_cast<int64>(GetProcess()->GetID()) << 32); 1115 return GetRoutingID() | (static_cast<int64>(GetProcess()->GetID()) << 32);
1084 } 1116 }
1085 1117
1086 // static 1118 // static
1087 void RenderWidgetHostImpl::DisableResizeAckCheckForTesting() { 1119 void RenderWidgetHostImpl::DisableResizeAckCheckForTesting() {
1088 g_check_for_pending_resize_ack = false; 1120 g_check_for_pending_resize_ack = false;
1089 } 1121 }
1090 1122
1091 ui::LatencyInfo RenderWidgetHostImpl::CreateRWHLatencyInfoIfNotExist( 1123 ui::LatencyInfo RenderWidgetHostImpl::CreateRWHLatencyInfoIfNotExist(
1092 const ui::LatencyInfo* original, WebInputEvent::Type type) { 1124 const ui::LatencyInfo* original,
1125 WebInputEvent::Type type,
1126 const ui::LatencyInfo::InputCoordinate* logical_coordinates,
1127 size_t logical_coordinates_size) {
1093 ui::LatencyInfo info; 1128 ui::LatencyInfo info;
1094 if (original) 1129 if (original)
1095 info = *original; 1130 info = *original;
1096 // In Aura, gesture event will already carry its original touch event's 1131 // In Aura, gesture event will already carry its original touch event's
1097 // INPUT_EVENT_LATENCY_RWH_COMPONENT. 1132 // INPUT_EVENT_LATENCY_RWH_COMPONENT.
1098 if (!info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1133 if (!info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
1099 GetLatencyComponentId(), 1134 GetLatencyComponentId(),
1100 NULL)) { 1135 NULL)) {
1101 info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1136 info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
1102 GetLatencyComponentId(), 1137 GetLatencyComponentId(),
1103 ++last_input_number_); 1138 ++last_input_number_);
1104 info.TraceEventType(WebInputEventTraits::GetName(type)); 1139 info.TraceEventType(WebInputEventTraits::GetName(type));
1140
1141 // Convert logical coordinates to physical coordinates, based on the
1142 // device scale factor.
1143 float device_scale_factor =
1144 screen_info_ ? screen_info_->deviceScaleFactor : 1;
1145 DCHECK(logical_coordinates_size <= ui::LatencyInfo::kMaxInputCoordinates);
1146 info.input_coordinates_size = logical_coordinates_size;
1147 for (size_t i = 0; i < info.input_coordinates_size; i++) {
1148 info.input_coordinates[i].x =
1149 logical_coordinates[i].x * device_scale_factor;
1150 info.input_coordinates[i].y =
1151 logical_coordinates[i].y * device_scale_factor;
1152 }
1105 } 1153 }
1154
1106 return info; 1155 return info;
1107 } 1156 }
1108 1157
1109 1158
1110 void RenderWidgetHostImpl::AddKeyPressEventCallback( 1159 void RenderWidgetHostImpl::AddKeyPressEventCallback(
1111 const KeyPressEventCallback& callback) { 1160 const KeyPressEventCallback& callback) {
1112 key_press_event_callbacks_.push_back(callback); 1161 key_press_event_callbacks_.push_back(callback);
1113 } 1162 }
1114 1163
1115 void RenderWidgetHostImpl::RemoveKeyPressEventCallback( 1164 void RenderWidgetHostImpl::RemoveKeyPressEventCallback(
(...skipping 1206 matching lines...) Expand 10 before | Expand all | Expand 10 after
2322 } 2371 }
2323 #endif 2372 #endif
2324 2373
2325 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() { 2374 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() {
2326 if (view_) 2375 if (view_)
2327 return view_->PreferredReadbackFormat(); 2376 return view_->PreferredReadbackFormat();
2328 return kN32_SkColorType; 2377 return kN32_SkColorType;
2329 } 2378 }
2330 2379
2331 } // namespace content 2380 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.h ('k') | content/browser/renderer_host/render_widget_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698