Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "core/inspector/InspectorInputAgent.h" | 31 #include "core/inspector/InspectorInputAgent.h" |
| 32 | 32 |
| 33 #include "core/frame/FrameView.h" | 33 #include "core/frame/FrameView.h" |
| 34 #include "core/input/EventHandler.h" | 34 #include "core/input/EventHandler.h" |
| 35 #include "core/inspector/InspectedFrames.h" | 35 #include "core/inspector/InspectedFrames.h" |
| 36 #include "core/page/ChromeClient.h" | 36 #include "core/page/ChromeClient.h" |
| 37 #include "core/page/Page.h" | 37 #include "core/page/Page.h" |
| 38 #include "platform/PlatformEvent.h" | 38 #include "platform/PlatformEvent.h" |
| 39 #include "platform/PlatformTouchEvent.h" | |
| 40 #include "platform/PlatformTouchPoint.h" | |
| 41 #include "platform/geometry/FloatSize.h" | 39 #include "platform/geometry/FloatSize.h" |
| 42 #include "platform/geometry/IntPoint.h" | 40 #include "platform/geometry/IntPoint.h" |
| 43 #include "platform/geometry/IntRect.h" | 41 #include "platform/geometry/IntRect.h" |
| 44 #include "platform/geometry/IntSize.h" | 42 #include "platform/geometry/IntSize.h" |
| 43 #include "public/platform/WebTouchEvent.h" | |
| 45 #include "wtf/CurrentTime.h" | 44 #include "wtf/CurrentTime.h" |
| 46 #include "wtf/Time.h" | 45 #include "wtf/Time.h" |
| 47 | 46 |
| 48 namespace { | 47 namespace { |
| 49 | 48 |
| 50 enum Modifiers { | 49 enum Modifiers { |
| 51 AltKey = 1 << 0, | 50 AltKey = 1 << 0, |
| 52 CtrlKey = 1 << 1, | 51 CtrlKey = 1 << 1, |
| 53 MetaKey = 1 << 2, | 52 MetaKey = 1 << 2, |
| 54 ShiftKey = 1 << 3 | 53 ShiftKey = 1 << 3 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 77 // for the duration of the application. | 76 // for the duration of the application. |
| 78 static double epochToMonotonicTimeDelta = | 77 static double epochToMonotonicTimeDelta = |
| 79 currentTime() - monotonicallyIncreasingTime(); | 78 currentTime() - monotonicallyIncreasingTime(); |
| 80 if (timestamp.isJust()) { | 79 if (timestamp.isJust()) { |
| 81 double ticksInSeconds = timestamp.fromJust() - epochToMonotonicTimeDelta; | 80 double ticksInSeconds = timestamp.fromJust() - epochToMonotonicTimeDelta; |
| 82 return TimeTicks::FromSeconds(ticksInSeconds); | 81 return TimeTicks::FromSeconds(ticksInSeconds); |
| 83 } | 82 } |
| 84 return TimeTicks::Now(); | 83 return TimeTicks::Now(); |
| 85 } | 84 } |
| 86 | 85 |
| 87 class SyntheticInspectorTouchPoint : public blink::PlatformTouchPoint { | 86 class SyntheticInspectorTouchPoint : public blink::WebTouchPoint { |
| 88 public: | 87 public: |
| 89 SyntheticInspectorTouchPoint(int id, | 88 SyntheticInspectorTouchPoint(int idParam, |
| 90 TouchState state, | 89 State stateParam, |
| 91 const blink::IntPoint& screenPos, | 90 const blink::IntPoint& screenPos, |
| 92 const blink::IntPoint& pos, | 91 const blink::IntPoint& pos, |
| 93 int radiusX, | 92 int radiusXParam, |
| 94 int radiusY, | 93 int radiusYParam, |
| 95 double rotationAngle, | 94 double rotationAngleParam, |
| 96 double force) { | 95 double forceParam) { |
| 97 m_pointerProperties.id = id; | 96 id = idParam; |
| 98 m_screenPos = screenPos; | 97 screenPosition = screenPos; |
| 99 m_pos = pos; | 98 position = pos; |
| 100 m_state = state; | 99 state = stateParam; |
| 101 m_radius = blink::FloatSize(radiusX, radiusY); | 100 radiusX = radiusXParam; |
| 102 m_rotationAngle = rotationAngle; | 101 radiusY = radiusYParam; |
| 103 m_pointerProperties.force = force; | 102 rotationAngle = rotationAngleParam; |
| 103 force = forceParam; | |
| 104 } | 104 } |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 class SyntheticInspectorTouchEvent : public blink::PlatformTouchEvent { | 107 class SyntheticInspectorTouchEvent : public blink::WebTouchEvent { |
| 108 public: | 108 public: |
| 109 SyntheticInspectorTouchEvent(const blink::PlatformEvent::EventType type, | 109 SyntheticInspectorTouchEvent(const blink::WebInputEvent::Type type, |
| 110 unsigned modifiers, | 110 unsigned modifiers, |
| 111 TimeTicks timestamp) { | 111 TimeTicks timestamp) { |
| 112 m_type = type; | 112 m_type = type; |
| 113 m_modifiers = modifiers; | 113 m_modifiers = modifiers; |
| 114 m_timestamp = timestamp; | 114 m_timeStampSeconds = timestamp.InSeconds(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void append(const blink::PlatformTouchPoint& point) { | 117 void append(const blink::WebTouchPoint& point) { |
| 118 m_touchPoints.push_back(point); | 118 if (touchesLength < kTouchesLengthCap) { |
| 119 touches[touchesLength] = point; | |
| 120 touchesLength++; | |
| 121 } | |
| 119 } | 122 } |
| 120 }; | 123 }; |
| 121 | 124 |
| 122 void ConvertInspectorPoint(blink::LocalFrame* frame, | 125 void ConvertInspectorPoint(blink::LocalFrame* frame, |
| 123 const blink::IntPoint& pointInFrame, | 126 const blink::IntPoint& pointInFrame, |
| 124 blink::IntPoint* convertedPoint, | 127 blink::IntPoint* convertedPoint, |
| 125 blink::IntPoint* globalPoint) { | 128 blink::IntPoint* globalPoint) { |
| 126 *convertedPoint = frame->view()->convertToRootFrame(pointInFrame); | 129 *convertedPoint = frame->view()->convertToRootFrame(pointInFrame); |
| 127 *globalPoint = | 130 *globalPoint = |
| 128 frame->page() | 131 frame->page() |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 139 InspectorInputAgent::InspectorInputAgent(InspectedFrames* inspectedFrames) | 142 InspectorInputAgent::InspectorInputAgent(InspectedFrames* inspectedFrames) |
| 140 : m_inspectedFrames(inspectedFrames) {} | 143 : m_inspectedFrames(inspectedFrames) {} |
| 141 | 144 |
| 142 InspectorInputAgent::~InspectorInputAgent() {} | 145 InspectorInputAgent::~InspectorInputAgent() {} |
| 143 | 146 |
| 144 Response InspectorInputAgent::dispatchTouchEvent( | 147 Response InspectorInputAgent::dispatchTouchEvent( |
| 145 const String& type, | 148 const String& type, |
| 146 std::unique_ptr<protocol::Array<protocol::Input::TouchPoint>> touchPoints, | 149 std::unique_ptr<protocol::Array<protocol::Input::TouchPoint>> touchPoints, |
| 147 protocol::Maybe<int> modifiers, | 150 protocol::Maybe<int> modifiers, |
| 148 protocol::Maybe<double> timestamp) { | 151 protocol::Maybe<double> timestamp) { |
| 149 PlatformEvent::EventType convertedType; | 152 WebInputEvent::Type convertedType; |
| 150 if (type == "touchStart") | 153 if (type == "touchStart") |
| 151 convertedType = PlatformEvent::TouchStart; | 154 convertedType = WebInputEvent::TouchStart; |
| 152 else if (type == "touchEnd") | 155 else if (type == "touchEnd") |
| 153 convertedType = PlatformEvent::TouchEnd; | 156 convertedType = WebInputEvent::TouchEnd; |
| 154 else if (type == "touchMove") | 157 else if (type == "touchMove") |
| 155 convertedType = PlatformEvent::TouchMove; | 158 convertedType = WebInputEvent::TouchMove; |
| 156 else | 159 else |
| 157 return Response::Error(String("Unrecognized type: " + type)); | 160 return Response::Error(String("Unrecognized type: " + type)); |
| 158 | 161 |
| 159 unsigned convertedModifiers = GetEventModifiers(modifiers.fromMaybe(0)); | 162 unsigned convertedModifiers = GetEventModifiers(modifiers.fromMaybe(0)); |
| 160 | 163 |
| 161 SyntheticInspectorTouchEvent event(convertedType, convertedModifiers, | 164 SyntheticInspectorTouchEvent event(convertedType, convertedModifiers, |
| 162 GetEventTimeStamp(timestamp)); | 165 GetEventTimeStamp(timestamp)); |
| 163 | 166 |
| 164 int autoId = 0; | 167 int autoId = 0; |
| 165 for (size_t i = 0; i < touchPoints->length(); ++i) { | 168 for (size_t i = 0; i < touchPoints->length(); ++i) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 177 autoId = -1; | 180 autoId = -1; |
| 178 } else { | 181 } else { |
| 179 id = autoId++; | 182 id = autoId++; |
| 180 } | 183 } |
| 181 if (id < 0) { | 184 if (id < 0) { |
| 182 return Response::Error( | 185 return Response::Error( |
| 183 "All or none of the provided TouchPoints must supply positive " | 186 "All or none of the provided TouchPoints must supply positive " |
| 184 "integer ids."); | 187 "integer ids."); |
| 185 } | 188 } |
| 186 | 189 |
| 187 PlatformTouchPoint::TouchState convertedState; | 190 WebTouchPoint::State convertedState; |
| 188 String state = point->getState(); | 191 String state = point->getState(); |
| 189 if (state == "touchPressed") | 192 if (state == "touchPressed") |
| 190 convertedState = PlatformTouchPoint::TouchPressed; | 193 convertedState = WebTouchPoint::StatePressed; |
| 191 else if (state == "touchReleased") | 194 else if (state == "touchReleased") |
| 192 convertedState = PlatformTouchPoint::TouchReleased; | 195 convertedState = WebTouchPoint::StateReleased; |
| 193 else if (state == "touchMoved") | 196 else if (state == "touchMoved") |
| 194 convertedState = PlatformTouchPoint::TouchMoved; | 197 convertedState = WebTouchPoint::StateMoved; |
| 195 else if (state == "touchStationary") | 198 else if (state == "touchStationary") |
| 196 convertedState = PlatformTouchPoint::TouchStationary; | 199 convertedState = WebTouchPoint::StateStationary; |
| 197 else if (state == "touchCancelled") | 200 else if (state == "touchCancelled") |
| 198 convertedState = PlatformTouchPoint::TouchCancelled; | 201 convertedState = WebTouchPoint::StateCancelled; |
| 199 else | 202 else |
| 200 return Response::Error(String("Unrecognized state: " + state)); | 203 return Response::Error(String("Unrecognized state: " + state)); |
| 201 | 204 |
| 202 // Some platforms may have flipped coordinate systems, but the given | 205 // Some platforms may have flipped coordinate systems, but the given |
| 203 // coordinates assume the origin is in the top-left of the window. Convert. | 206 // coordinates assume the origin is in the top-left of the window. Convert. |
| 204 IntPoint convertedPoint, globalPoint; | 207 IntPoint convertedPoint, globalPoint; |
| 205 ConvertInspectorPoint(m_inspectedFrames->root(), | 208 ConvertInspectorPoint(m_inspectedFrames->root(), |
| 206 IntPoint(point->getX(), point->getY()), | 209 IntPoint(point->getX(), point->getY()), |
| 207 &convertedPoint, &globalPoint); | 210 &convertedPoint, &globalPoint); |
| 208 | 211 |
| 209 SyntheticInspectorTouchPoint touchPoint(id++, convertedState, globalPoint, | 212 SyntheticInspectorTouchPoint touchPoint(id++, convertedState, globalPoint, |
| 210 convertedPoint, radiusX, radiusY, | 213 convertedPoint, radiusX, radiusY, |
| 211 rotationAngle, force); | 214 rotationAngle, force); |
| 212 event.append(touchPoint); | 215 event.append(touchPoint); |
| 213 } | 216 } |
| 214 | 217 |
| 218 event.setFrameScale( | |
| 219 m_inspectedFrames->root()->view()->inputEventsScaleFactor()); | |
| 220 | |
|
mustaq
2017/01/24 16:59:41
I guess we need to call event.setFrameTranslate()
dtapuska
2017/01/25 02:43:34
Done.
| |
| 215 // TODO: We need to add the support for generating coalesced events in | 221 // TODO: We need to add the support for generating coalesced events in |
| 216 // the devtools. | 222 // the devtools. |
| 217 Vector<PlatformTouchEvent> coalescedEvents; | 223 Vector<WebTouchEvent> coalescedEvents; |
| 218 | 224 |
| 219 m_inspectedFrames->root()->eventHandler().handleTouchEvent(event, | 225 m_inspectedFrames->root()->eventHandler().handleTouchEvent(event, |
| 220 coalescedEvents); | 226 coalescedEvents); |
| 221 return Response::OK(); | 227 return Response::OK(); |
| 222 } | 228 } |
| 223 | 229 |
| 224 DEFINE_TRACE(InspectorInputAgent) { | 230 DEFINE_TRACE(InspectorInputAgent) { |
| 225 visitor->trace(m_inspectedFrames); | 231 visitor->trace(m_inspectedFrames); |
| 226 InspectorBaseAgent::trace(visitor); | 232 InspectorBaseAgent::trace(visitor); |
| 227 } | 233 } |
| 228 | 234 |
| 229 } // namespace blink | 235 } // namespace blink |
| OLD | NEW |