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

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

Issue 541033003: Added coordinates information to InputLatency (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses code style comments Created 6 years, 3 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 834 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 void RenderWidgetHostImpl::ForwardMouseEvent(const WebMouseEvent& mouse_event) { 845 void RenderWidgetHostImpl::ForwardMouseEvent(const WebMouseEvent& mouse_event) {
846 ForwardMouseEventWithLatencyInfo(mouse_event, ui::LatencyInfo()); 846 ForwardMouseEventWithLatencyInfo(mouse_event, ui::LatencyInfo());
847 } 847 }
848 848
849 void RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo( 849 void RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo(
850 const blink::WebMouseEvent& mouse_event, 850 const blink::WebMouseEvent& mouse_event,
851 const ui::LatencyInfo& ui_latency) { 851 const ui::LatencyInfo& ui_latency) {
852 TRACE_EVENT2("input", "RenderWidgetHostImpl::ForwardMouseEvent", 852 TRACE_EVENT2("input", "RenderWidgetHostImpl::ForwardMouseEvent",
853 "x", mouse_event.x, "y", mouse_event.y); 853 "x", mouse_event.x, "y", mouse_event.y);
854 854
855 ui::LatencyInfo::InputCoordinates logical_coordinates;
856 logical_coordinates.push_back(gfx::PointF(mouse_event.x, mouse_event.y));
857
855 ui::LatencyInfo latency_info = 858 ui::LatencyInfo latency_info =
856 CreateRWHLatencyInfoIfNotExist(&ui_latency, mouse_event.type); 859 CreateRWHLatencyInfoIfNotExist(&ui_latency, mouse_event.type,
860 logical_coordinates);
857 861
858 for (size_t i = 0; i < mouse_event_callbacks_.size(); ++i) { 862 for (size_t i = 0; i < mouse_event_callbacks_.size(); ++i) {
859 if (mouse_event_callbacks_[i].Run(mouse_event)) 863 if (mouse_event_callbacks_[i].Run(mouse_event))
860 return; 864 return;
861 } 865 }
862 866
863 if (IgnoreInputEvents()) 867 if (IgnoreInputEvents())
864 return; 868 return;
865 869
866 if (touch_emulator_ && touch_emulator_->HandleMouseEvent(mouse_event)) 870 if (touch_emulator_ && touch_emulator_->HandleMouseEvent(mouse_event))
867 return; 871 return;
868 872
869 input_router_->SendMouseEvent(MouseEventWithLatencyInfo(mouse_event, 873 input_router_->SendMouseEvent(MouseEventWithLatencyInfo(mouse_event,
870 latency_info)); 874 latency_info));
871 } 875 }
872 876
873 void RenderWidgetHostImpl::OnPointerEventActivate() { 877 void RenderWidgetHostImpl::OnPointerEventActivate() {
874 } 878 }
875 879
876 void RenderWidgetHostImpl::ForwardWheelEvent( 880 void RenderWidgetHostImpl::ForwardWheelEvent(
877 const WebMouseWheelEvent& wheel_event) { 881 const WebMouseWheelEvent& wheel_event) {
878 ForwardWheelEventWithLatencyInfo(wheel_event, ui::LatencyInfo()); 882 ForwardWheelEventWithLatencyInfo(wheel_event, ui::LatencyInfo());
879 } 883 }
880 884
881 void RenderWidgetHostImpl::ForwardWheelEventWithLatencyInfo( 885 void RenderWidgetHostImpl::ForwardWheelEventWithLatencyInfo(
882 const blink::WebMouseWheelEvent& wheel_event, 886 const blink::WebMouseWheelEvent& wheel_event,
883 const ui::LatencyInfo& ui_latency) { 887 const ui::LatencyInfo& ui_latency) {
884 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardWheelEvent"); 888 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardWheelEvent");
885 889
890 ui::LatencyInfo::InputCoordinates logical_coordinates;
891 logical_coordinates.push_back(gfx::PointF(wheel_event.x, wheel_event.y));
892
886 ui::LatencyInfo latency_info = 893 ui::LatencyInfo latency_info =
887 CreateRWHLatencyInfoIfNotExist(&ui_latency, wheel_event.type); 894 CreateRWHLatencyInfoIfNotExist(&ui_latency, wheel_event.type,
895 logical_coordinates);
888 896
889 if (IgnoreInputEvents()) 897 if (IgnoreInputEvents())
890 return; 898 return;
891 899
892 if (touch_emulator_ && touch_emulator_->HandleMouseWheelEvent(wheel_event)) 900 if (touch_emulator_ && touch_emulator_->HandleMouseWheelEvent(wheel_event))
893 return; 901 return;
894 902
895 input_router_->SendWheelEvent(MouseWheelEventWithLatencyInfo(wheel_event, 903 input_router_->SendWheelEvent(MouseWheelEventWithLatencyInfo(wheel_event,
896 latency_info)); 904 latency_info));
897 } 905 }
898 906
899 void RenderWidgetHostImpl::ForwardGestureEvent( 907 void RenderWidgetHostImpl::ForwardGestureEvent(
900 const blink::WebGestureEvent& gesture_event) { 908 const blink::WebGestureEvent& gesture_event) {
901 ForwardGestureEventWithLatencyInfo(gesture_event, ui::LatencyInfo()); 909 ForwardGestureEventWithLatencyInfo(gesture_event, ui::LatencyInfo());
902 } 910 }
903 911
904 void RenderWidgetHostImpl::ForwardGestureEventWithLatencyInfo( 912 void RenderWidgetHostImpl::ForwardGestureEventWithLatencyInfo(
905 const blink::WebGestureEvent& gesture_event, 913 const blink::WebGestureEvent& gesture_event,
906 const ui::LatencyInfo& ui_latency) { 914 const ui::LatencyInfo& ui_latency) {
907 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardGestureEvent"); 915 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardGestureEvent");
908 // Early out if necessary, prior to performing latency logic. 916 // Early out if necessary, prior to performing latency logic.
909 if (IgnoreInputEvents()) 917 if (IgnoreInputEvents())
910 return; 918 return;
911 919
912 if (delegate_->PreHandleGestureEvent(gesture_event)) 920 if (delegate_->PreHandleGestureEvent(gesture_event))
913 return; 921 return;
914 922
923 ui::LatencyInfo::InputCoordinates logical_coordinates;
924 logical_coordinates.push_back(gfx::PointF(gesture_event.x, gesture_event.y));
925
915 ui::LatencyInfo latency_info = 926 ui::LatencyInfo latency_info =
916 CreateRWHLatencyInfoIfNotExist(&ui_latency, gesture_event.type); 927 CreateRWHLatencyInfoIfNotExist(&ui_latency, gesture_event.type,
928 logical_coordinates);
917 929
918 if (gesture_event.type == blink::WebInputEvent::GestureScrollUpdate) { 930 if (gesture_event.type == blink::WebInputEvent::GestureScrollUpdate) {
919 latency_info.AddLatencyNumber( 931 latency_info.AddLatencyNumber(
920 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_RWH_COMPONENT, 932 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_RWH_COMPONENT,
921 GetLatencyComponentId(), 933 GetLatencyComponentId(),
922 ++last_input_number_); 934 ++last_input_number_);
923 935
924 // Make a copy of the INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT with a 936 // Make a copy of the INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT with a
925 // different name INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT. 937 // different name INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT.
926 // So we can track the latency specifically for scroll update events. 938 // So we can track the latency specifically for scroll update events.
(...skipping 10 matching lines...) Expand all
937 } 949 }
938 } 950 }
939 951
940 GestureEventWithLatencyInfo gesture_with_latency(gesture_event, latency_info); 952 GestureEventWithLatencyInfo gesture_with_latency(gesture_event, latency_info);
941 input_router_->SendGestureEvent(gesture_with_latency); 953 input_router_->SendGestureEvent(gesture_with_latency);
942 } 954 }
943 955
944 void RenderWidgetHostImpl::ForwardEmulatedTouchEvent( 956 void RenderWidgetHostImpl::ForwardEmulatedTouchEvent(
945 const blink::WebTouchEvent& touch_event) { 957 const blink::WebTouchEvent& touch_event) {
946 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardEmulatedTouchEvent"); 958 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardEmulatedTouchEvent");
959
960 ui::LatencyInfo::InputCoordinates logical_coordinates;
961 for (size_t i = 0; i < touch_event.touchesLength; i++) {
962 logical_coordinates.push_back(gfx::PointF(
963 touch_event.touches[i].position.x,
964 touch_event.touches[i].position.y));
965 }
966
947 ui::LatencyInfo latency_info = 967 ui::LatencyInfo latency_info =
948 CreateRWHLatencyInfoIfNotExist(NULL, touch_event.type); 968 CreateRWHLatencyInfoIfNotExist(NULL, touch_event.type,
969 logical_coordinates);
949 TouchEventWithLatencyInfo touch_with_latency(touch_event, latency_info); 970 TouchEventWithLatencyInfo touch_with_latency(touch_event, latency_info);
950 input_router_->SendTouchEvent(touch_with_latency); 971 input_router_->SendTouchEvent(touch_with_latency);
951 } 972 }
952 973
953 void RenderWidgetHostImpl::ForwardTouchEventWithLatencyInfo( 974 void RenderWidgetHostImpl::ForwardTouchEventWithLatencyInfo(
954 const blink::WebTouchEvent& touch_event, 975 const blink::WebTouchEvent& touch_event,
955 const ui::LatencyInfo& ui_latency) { 976 const ui::LatencyInfo& ui_latency) {
956 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardTouchEvent"); 977 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardTouchEvent");
957 978
958 // Always forward TouchEvents for touch stream consistency. They will be 979 // Always forward TouchEvents for touch stream consistency. They will be
959 // ignored if appropriate in FilterInputEvent(). 980 // ignored if appropriate in FilterInputEvent().
981 //
982 ui::LatencyInfo::InputCoordinates logical_coordinates;
983 for (size_t i = 0; i < touch_event.touchesLength; i++) {
984 logical_coordinates.push_back(gfx::PointF(
985 touch_event.touches[i].position.x,
986 touch_event.touches[i].position.y));
987 }
960 988
961 ui::LatencyInfo latency_info = 989 ui::LatencyInfo latency_info =
962 CreateRWHLatencyInfoIfNotExist(&ui_latency, touch_event.type); 990 CreateRWHLatencyInfoIfNotExist(&ui_latency, touch_event.type,
991 logical_coordinates);
963 TouchEventWithLatencyInfo touch_with_latency(touch_event, latency_info); 992 TouchEventWithLatencyInfo touch_with_latency(touch_event, latency_info);
964 993
965 if (touch_emulator_ && 994 if (touch_emulator_ &&
966 touch_emulator_->HandleTouchEvent(touch_with_latency.event)) { 995 touch_emulator_->HandleTouchEvent(touch_with_latency.event)) {
967 if (view_) { 996 if (view_) {
968 view_->ProcessAckedTouchEvent( 997 view_->ProcessAckedTouchEvent(
969 touch_with_latency, INPUT_EVENT_ACK_STATE_CONSUMED); 998 touch_with_latency, INPUT_EVENT_ACK_STATE_CONSUMED);
970 } 999 }
971 return; 1000 return;
972 } 1001 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 if (delegate_->PreHandleKeyboardEvent(key_event, &is_shortcut)) 1060 if (delegate_->PreHandleKeyboardEvent(key_event, &is_shortcut))
1032 return; 1061 return;
1033 1062
1034 if (key_event.type == WebKeyboardEvent::RawKeyDown) 1063 if (key_event.type == WebKeyboardEvent::RawKeyDown)
1035 suppress_next_char_events_ = false; 1064 suppress_next_char_events_ = false;
1036 } 1065 }
1037 1066
1038 if (touch_emulator_ && touch_emulator_->HandleKeyboardEvent(key_event)) 1067 if (touch_emulator_ && touch_emulator_->HandleKeyboardEvent(key_event))
1039 return; 1068 return;
1040 1069
1070 // Keyboard events have no coordinates attached.
1071 ui::LatencyInfo::InputCoordinates logical_coordinates;
1072
1041 input_router_->SendKeyboardEvent( 1073 input_router_->SendKeyboardEvent(
1042 key_event, 1074 key_event,
1043 CreateRWHLatencyInfoIfNotExist(NULL, key_event.type), 1075 CreateRWHLatencyInfoIfNotExist(NULL, key_event.type,
1076 logical_coordinates),
1044 is_shortcut); 1077 is_shortcut);
1045 } 1078 }
1046 1079
1047 void RenderWidgetHostImpl::QueueSyntheticGesture( 1080 void RenderWidgetHostImpl::QueueSyntheticGesture(
1048 scoped_ptr<SyntheticGesture> synthetic_gesture, 1081 scoped_ptr<SyntheticGesture> synthetic_gesture,
1049 const base::Callback<void(SyntheticGesture::Result)>& on_complete) { 1082 const base::Callback<void(SyntheticGesture::Result)>& on_complete) {
1050 if (!synthetic_gesture_controller_ && view_) { 1083 if (!synthetic_gesture_controller_ && view_) {
1051 synthetic_gesture_controller_.reset( 1084 synthetic_gesture_controller_.reset(
1052 new SyntheticGestureController( 1085 new SyntheticGestureController(
1053 view_->CreateSyntheticGestureTarget().Pass())); 1086 view_->CreateSyntheticGestureTarget().Pass()));
(...skipping 22 matching lines...) Expand all
1076 int64 RenderWidgetHostImpl::GetLatencyComponentId() { 1109 int64 RenderWidgetHostImpl::GetLatencyComponentId() {
1077 return GetRoutingID() | (static_cast<int64>(GetProcess()->GetID()) << 32); 1110 return GetRoutingID() | (static_cast<int64>(GetProcess()->GetID()) << 32);
1078 } 1111 }
1079 1112
1080 // static 1113 // static
1081 void RenderWidgetHostImpl::DisableResizeAckCheckForTesting() { 1114 void RenderWidgetHostImpl::DisableResizeAckCheckForTesting() {
1082 g_check_for_pending_resize_ack = false; 1115 g_check_for_pending_resize_ack = false;
1083 } 1116 }
1084 1117
1085 ui::LatencyInfo RenderWidgetHostImpl::CreateRWHLatencyInfoIfNotExist( 1118 ui::LatencyInfo RenderWidgetHostImpl::CreateRWHLatencyInfoIfNotExist(
1086 const ui::LatencyInfo* original, WebInputEvent::Type type) { 1119 const ui::LatencyInfo* original, WebInputEvent::Type type,
1120 const ui::LatencyInfo::InputCoordinates& logical_coordinates) {
1087 ui::LatencyInfo info; 1121 ui::LatencyInfo info;
1088 if (original) 1122 if (original)
1089 info = *original; 1123 info = *original;
1124
1090 // In Aura, gesture event will already carry its original touch event's 1125 // In Aura, gesture event will already carry its original touch event's
1091 // INPUT_EVENT_LATENCY_RWH_COMPONENT. 1126 // INPUT_EVENT_LATENCY_RWH_COMPONENT.
1092 if (!info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1127 if (!info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
1093 GetLatencyComponentId(), 1128 GetLatencyComponentId(),
1094 NULL)) { 1129 NULL)) {
1095 info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1130 info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
1096 GetLatencyComponentId(), 1131 GetLatencyComponentId(),
1097 ++last_input_number_); 1132 ++last_input_number_);
1098 info.TraceEventType(WebInputEventTraits::GetName(type)); 1133 info.TraceEventType(WebInputEventTraits::GetName(type));
1134
1135 // Convert logical coordinates to physical coordinates, based on the
1136 // device scale factor.
1137 info.coordinates = logical_coordinates;
1138 for (size_t i = 0; i < info.coordinates.size(); i++)
1139 info.coordinates[i].Scale(screen_info_->deviceScaleFactor);
1099 } 1140 }
1141
1100 return info; 1142 return info;
1101 } 1143 }
1102 1144
1103 1145
1104 void RenderWidgetHostImpl::AddKeyPressEventCallback( 1146 void RenderWidgetHostImpl::AddKeyPressEventCallback(
1105 const KeyPressEventCallback& callback) { 1147 const KeyPressEventCallback& callback) {
1106 key_press_event_callbacks_.push_back(callback); 1148 key_press_event_callbacks_.push_back(callback);
1107 } 1149 }
1108 1150
1109 void RenderWidgetHostImpl::RemoveKeyPressEventCallback( 1151 void RenderWidgetHostImpl::RemoveKeyPressEventCallback(
(...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after
2315 } 2357 }
2316 #endif 2358 #endif
2317 2359
2318 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() { 2360 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() {
2319 if (view_) 2361 if (view_)
2320 return view_->PreferredReadbackFormat(); 2362 return view_->PreferredReadbackFormat();
2321 return kN32_SkColorType; 2363 return kN32_SkColorType;
2322 } 2364 }
2323 2365
2324 } // namespace content 2366 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698