| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/common/input/synthetic_web_input_event_builders.h" | 5 #include "content/common/input/synthetic_web_input_event_builders.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/common/input/web_touch_event_traits.h" | 8 #include "content/common/input/web_touch_event_traits.h" |
| 9 #include "ui/events/base_event_utils.h" | 9 #include "ui/events/base_event_utils.h" |
| 10 #include "ui/events/keycodes/keyboard_codes.h" | 10 #include "ui/events/keycodes/keyboard_codes.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 | 13 |
| 14 using blink::WebInputEvent; | 14 using blink::WebInputEvent; |
| 15 using blink::WebKeyboardEvent; | 15 using blink::WebKeyboardEvent; |
| 16 using blink::WebGestureEvent; | 16 using blink::WebGestureEvent; |
| 17 using blink::WebMouseEvent; | 17 using blink::WebMouseEvent; |
| 18 using blink::WebMouseWheelEvent; | 18 using blink::WebMouseWheelEvent; |
| 19 using blink::WebTouchEvent; | 19 using blink::WebTouchEvent; |
| 20 using blink::WebTouchPoint; | 20 using blink::WebTouchPoint; |
| 21 | 21 |
| 22 WebMouseEvent SyntheticWebMouseEventBuilder::Build( | 22 WebMouseEvent SyntheticWebMouseEventBuilder::Build( |
| 23 blink::WebInputEvent::Type type) { | 23 blink::WebInputEvent::Type type) { |
| 24 WebMouseEvent result; | 24 return WebMouseEvent(type, WebInputEvent::NoModifiers, |
| 25 result.type = type; | 25 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); |
| 26 return result; | |
| 27 } | 26 } |
| 28 | 27 |
| 29 WebMouseEvent SyntheticWebMouseEventBuilder::Build( | 28 WebMouseEvent SyntheticWebMouseEventBuilder::Build( |
| 30 blink::WebInputEvent::Type type, | 29 blink::WebInputEvent::Type type, |
| 31 int window_x, | 30 int window_x, |
| 32 int window_y, | 31 int window_y, |
| 33 int modifiers) { | 32 int modifiers) { |
| 34 DCHECK(WebInputEvent::isMouseEventType(type)); | 33 DCHECK(WebInputEvent::isMouseEventType(type)); |
| 35 WebMouseEvent result = Build(type); | 34 WebMouseEvent result(type, modifiers, |
| 35 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); |
| 36 result.x = window_x; | 36 result.x = window_x; |
| 37 result.y = window_y; | 37 result.y = window_y; |
| 38 result.windowX = window_x; | 38 result.windowX = window_x; |
| 39 result.windowY = window_y; | 39 result.windowY = window_y; |
| 40 result.modifiers = modifiers; | |
| 41 | 40 |
| 42 if (type == WebInputEvent::MouseDown || type == WebInputEvent::MouseUp) | 41 if (type == WebInputEvent::MouseDown || type == WebInputEvent::MouseUp) |
| 43 result.button = WebMouseEvent::Button::Left; | 42 result.button = WebMouseEvent::Button::Left; |
| 44 else | 43 else |
| 45 result.button = WebMouseEvent::Button::NoButton; | 44 result.button = WebMouseEvent::Button::NoButton; |
| 46 | 45 |
| 47 return result; | 46 return result; |
| 48 } | 47 } |
| 49 | 48 |
| 50 WebMouseWheelEvent SyntheticWebMouseWheelEventBuilder::Build( | 49 WebMouseWheelEvent SyntheticWebMouseWheelEventBuilder::Build( |
| 51 WebMouseWheelEvent::Phase phase) { | 50 WebMouseWheelEvent::Phase phase) { |
| 52 WebMouseWheelEvent result; | 51 WebMouseWheelEvent result(WebInputEvent::MouseWheel, |
| 53 result.type = WebInputEvent::MouseWheel; | 52 WebInputEvent::NoModifiers, |
| 53 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); |
| 54 result.phase = phase; | 54 result.phase = phase; |
| 55 return result; | 55 return result; |
| 56 } | 56 } |
| 57 | 57 |
| 58 WebMouseWheelEvent SyntheticWebMouseWheelEventBuilder::Build(float x, | 58 WebMouseWheelEvent SyntheticWebMouseWheelEventBuilder::Build(float x, |
| 59 float y, | 59 float y, |
| 60 float dx, | 60 float dx, |
| 61 float dy, | 61 float dy, |
| 62 int modifiers, | 62 int modifiers, |
| 63 bool precise) { | 63 bool precise) { |
| 64 return Build(x, y, 0, 0, dx, dy, modifiers, precise); | 64 return Build(x, y, 0, 0, dx, dy, modifiers, precise); |
| 65 } | 65 } |
| 66 | 66 |
| 67 WebMouseWheelEvent SyntheticWebMouseWheelEventBuilder::Build(float x, | 67 WebMouseWheelEvent SyntheticWebMouseWheelEventBuilder::Build(float x, |
| 68 float y, | 68 float y, |
| 69 float global_x, | 69 float global_x, |
| 70 float global_y, | 70 float global_y, |
| 71 float dx, | 71 float dx, |
| 72 float dy, | 72 float dy, |
| 73 int modifiers, | 73 int modifiers, |
| 74 bool precise) { | 74 bool precise) { |
| 75 WebMouseWheelEvent result; | 75 WebMouseWheelEvent result(WebInputEvent::MouseWheel, modifiers, |
| 76 result.type = WebInputEvent::MouseWheel; | 76 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); |
| 77 result.globalX = global_x; | 77 result.globalX = global_x; |
| 78 result.globalY = global_y; | 78 result.globalY = global_y; |
| 79 result.x = x; | 79 result.x = x; |
| 80 result.y = y; | 80 result.y = y; |
| 81 result.deltaX = dx; | 81 result.deltaX = dx; |
| 82 result.deltaY = dy; | 82 result.deltaY = dy; |
| 83 if (dx) | 83 if (dx) |
| 84 result.wheelTicksX = dx > 0.0f ? 1.0f : -1.0f; | 84 result.wheelTicksX = dx > 0.0f ? 1.0f : -1.0f; |
| 85 if (dy) | 85 if (dy) |
| 86 result.wheelTicksY = dy > 0.0f ? 1.0f : -1.0f; | 86 result.wheelTicksY = dy > 0.0f ? 1.0f : -1.0f; |
| 87 result.modifiers = modifiers; | |
| 88 result.hasPreciseScrollingDeltas = precise; | 87 result.hasPreciseScrollingDeltas = precise; |
| 89 return result; | 88 return result; |
| 90 } | 89 } |
| 91 | 90 |
| 92 WebKeyboardEvent SyntheticWebKeyboardEventBuilder::Build( | 91 WebKeyboardEvent SyntheticWebKeyboardEventBuilder::Build( |
| 93 WebInputEvent::Type type) { | 92 WebInputEvent::Type type) { |
| 94 DCHECK(WebInputEvent::isKeyboardEventType(type)); | 93 DCHECK(WebInputEvent::isKeyboardEventType(type)); |
| 95 WebKeyboardEvent result; | 94 WebKeyboardEvent result(type, WebInputEvent::NoModifiers, |
| 96 result.type = type; | 95 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); |
| 97 result.windowsKeyCode = ui::VKEY_L; // non-null made up value. | 96 result.windowsKeyCode = ui::VKEY_L; // non-null made up value. |
| 98 return result; | 97 return result; |
| 99 } | 98 } |
| 100 | 99 |
| 101 WebGestureEvent SyntheticWebGestureEventBuilder::Build( | 100 WebGestureEvent SyntheticWebGestureEventBuilder::Build( |
| 102 WebInputEvent::Type type, | 101 WebInputEvent::Type type, |
| 103 blink::WebGestureDevice source_device) { | 102 blink::WebGestureDevice source_device, |
| 103 int modifiers) { |
| 104 DCHECK(WebInputEvent::isGestureEventType(type)); | 104 DCHECK(WebInputEvent::isGestureEventType(type)); |
| 105 WebGestureEvent result; | 105 WebGestureEvent result(type, modifiers, |
| 106 result.type = type; | 106 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); |
| 107 result.sourceDevice = source_device; | 107 result.sourceDevice = source_device; |
| 108 if (type == WebInputEvent::GestureTap || | 108 if (type == WebInputEvent::GestureTap || |
| 109 type == WebInputEvent::GestureTapUnconfirmed || | 109 type == WebInputEvent::GestureTapUnconfirmed || |
| 110 type == WebInputEvent::GestureDoubleTap) { | 110 type == WebInputEvent::GestureDoubleTap) { |
| 111 result.data.tap.tapCount = 1; | 111 result.data.tap.tapCount = 1; |
| 112 result.data.tap.width = 10; | 112 result.data.tap.width = 10; |
| 113 result.data.tap.height = 10; | 113 result.data.tap.height = 10; |
| 114 } | 114 } |
| 115 return result; | 115 return result; |
| 116 } | 116 } |
| 117 | 117 |
| 118 WebGestureEvent SyntheticWebGestureEventBuilder::BuildScrollBegin( | 118 WebGestureEvent SyntheticWebGestureEventBuilder::BuildScrollBegin( |
| 119 float dx_hint, | 119 float dx_hint, |
| 120 float dy_hint, | 120 float dy_hint, |
| 121 blink::WebGestureDevice source_device) { | 121 blink::WebGestureDevice source_device) { |
| 122 WebGestureEvent result = | 122 WebGestureEvent result = |
| 123 Build(WebInputEvent::GestureScrollBegin, source_device); | 123 Build(WebInputEvent::GestureScrollBegin, source_device); |
| 124 result.data.scrollBegin.deltaXHint = dx_hint; | 124 result.data.scrollBegin.deltaXHint = dx_hint; |
| 125 result.data.scrollBegin.deltaYHint = dy_hint; | 125 result.data.scrollBegin.deltaYHint = dy_hint; |
| 126 return result; | 126 return result; |
| 127 } | 127 } |
| 128 | 128 |
| 129 WebGestureEvent SyntheticWebGestureEventBuilder::BuildScrollUpdate( | 129 WebGestureEvent SyntheticWebGestureEventBuilder::BuildScrollUpdate( |
| 130 float dx, | 130 float dx, |
| 131 float dy, | 131 float dy, |
| 132 int modifiers, | 132 int modifiers, |
| 133 blink::WebGestureDevice source_device) { | 133 blink::WebGestureDevice source_device) { |
| 134 WebGestureEvent result = | 134 WebGestureEvent result = |
| 135 Build(WebInputEvent::GestureScrollUpdate, source_device); | 135 Build(WebInputEvent::GestureScrollUpdate, source_device, modifiers); |
| 136 result.data.scrollUpdate.deltaX = dx; | 136 result.data.scrollUpdate.deltaX = dx; |
| 137 result.data.scrollUpdate.deltaY = dy; | 137 result.data.scrollUpdate.deltaY = dy; |
| 138 result.modifiers = modifiers; | |
| 139 return result; | 138 return result; |
| 140 } | 139 } |
| 141 | 140 |
| 142 WebGestureEvent SyntheticWebGestureEventBuilder::BuildPinchUpdate( | 141 WebGestureEvent SyntheticWebGestureEventBuilder::BuildPinchUpdate( |
| 143 float scale, | 142 float scale, |
| 144 float anchor_x, | 143 float anchor_x, |
| 145 float anchor_y, | 144 float anchor_y, |
| 146 int modifiers, | 145 int modifiers, |
| 147 blink::WebGestureDevice source_device) { | 146 blink::WebGestureDevice source_device) { |
| 148 WebGestureEvent result = | 147 WebGestureEvent result = |
| 149 Build(WebInputEvent::GesturePinchUpdate, source_device); | 148 Build(WebInputEvent::GesturePinchUpdate, source_device, modifiers); |
| 150 result.data.pinchUpdate.scale = scale; | 149 result.data.pinchUpdate.scale = scale; |
| 151 result.x = anchor_x; | 150 result.x = anchor_x; |
| 152 result.y = anchor_y; | 151 result.y = anchor_y; |
| 153 result.globalX = anchor_x; | 152 result.globalX = anchor_x; |
| 154 result.globalY = anchor_y; | 153 result.globalY = anchor_y; |
| 155 result.modifiers = modifiers; | |
| 156 return result; | 154 return result; |
| 157 } | 155 } |
| 158 | 156 |
| 159 WebGestureEvent SyntheticWebGestureEventBuilder::BuildFling( | 157 WebGestureEvent SyntheticWebGestureEventBuilder::BuildFling( |
| 160 float velocity_x, | 158 float velocity_x, |
| 161 float velocity_y, | 159 float velocity_y, |
| 162 blink::WebGestureDevice source_device) { | 160 blink::WebGestureDevice source_device) { |
| 163 WebGestureEvent result = Build(WebInputEvent::GestureFlingStart, | 161 WebGestureEvent result = Build(WebInputEvent::GestureFlingStart, |
| 164 source_device); | 162 source_device); |
| 165 result.data.flingStart.velocityX = velocity_x; | 163 result.data.flingStart.velocityX = velocity_x; |
| 166 result.data.flingStart.velocityY = velocity_y; | 164 result.data.flingStart.velocityY = velocity_y; |
| 167 return result; | 165 return result; |
| 168 } | 166 } |
| 169 | 167 |
| 170 SyntheticWebTouchEvent::SyntheticWebTouchEvent() : WebTouchEvent() { | 168 SyntheticWebTouchEvent::SyntheticWebTouchEvent() : WebTouchEvent() { |
| 171 uniqueTouchEventId = ui::GetNextTouchEventId(); | 169 uniqueTouchEventId = ui::GetNextTouchEventId(); |
| 172 SetTimestamp(base::TimeTicks::Now()); | 170 SetTimestamp(ui::EventTimeForNow()); |
| 173 } | 171 } |
| 174 | 172 |
| 175 void SyntheticWebTouchEvent::ResetPoints() { | 173 void SyntheticWebTouchEvent::ResetPoints() { |
| 176 int point = 0; | 174 int point = 0; |
| 177 for (unsigned int i = 0; i < touchesLength; ++i) { | 175 for (unsigned int i = 0; i < touchesLength; ++i) { |
| 178 if (touches[i].state == WebTouchPoint::StateReleased) | 176 if (touches[i].state == WebTouchPoint::StateReleased) |
| 179 continue; | 177 continue; |
| 180 | 178 |
| 181 touches[point] = touches[i]; | 179 touches[point] = touches[i]; |
| 182 touches[point].state = WebTouchPoint::StateStationary; | 180 touches[point].state = WebTouchPoint::StateStationary; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 194 WebTouchPoint& point = touches[touchesLength]; | 192 WebTouchPoint& point = touches[touchesLength]; |
| 195 point.id = touchesLength; | 193 point.id = touchesLength; |
| 196 point.position.x = point.screenPosition.x = x; | 194 point.position.x = point.screenPosition.x = x; |
| 197 point.position.y = point.screenPosition.y = y; | 195 point.position.y = point.screenPosition.y = y; |
| 198 point.state = WebTouchPoint::StatePressed; | 196 point.state = WebTouchPoint::StatePressed; |
| 199 point.radiusX = point.radiusY = 1.f; | 197 point.radiusX = point.radiusY = 1.f; |
| 200 point.rotationAngle = 1.f; | 198 point.rotationAngle = 1.f; |
| 201 point.force = 1.f; | 199 point.force = 1.f; |
| 202 point.tiltX = point.tiltY = 0; | 200 point.tiltX = point.tiltY = 0; |
| 203 ++touchesLength; | 201 ++touchesLength; |
| 204 WebTouchEventTraits::ResetType( | 202 WebTouchEventTraits::ResetType(WebInputEvent::TouchStart, timeStampSeconds, |
| 205 WebInputEvent::TouchStart, timeStampSeconds, this); | 203 this); |
| 206 return point.id; | 204 return point.id; |
| 207 } | 205 } |
| 208 | 206 |
| 209 void SyntheticWebTouchEvent::MovePoint(int index, float x, float y) { | 207 void SyntheticWebTouchEvent::MovePoint(int index, float x, float y) { |
| 210 CHECK_GE(index, 0); | 208 CHECK_GE(index, 0); |
| 211 CHECK_LT(index, kTouchesLengthCap); | 209 CHECK_LT(index, kTouchesLengthCap); |
| 212 // Always set this bit to avoid otherwise unexpected touchmove suppression. | 210 // Always set this bit to avoid otherwise unexpected touchmove suppression. |
| 213 // The caller can opt-out explicitly, if necessary. | 211 // The caller can opt-out explicitly, if necessary. |
| 214 movedBeyondSlopRegion = true; | 212 movedBeyondSlopRegion = true; |
| 215 WebTouchPoint& point = touches[index]; | 213 WebTouchPoint& point = touches[index]; |
| 216 point.position.x = point.screenPosition.x = x; | 214 point.position.x = point.screenPosition.x = x; |
| 217 point.position.y = point.screenPosition.y = y; | 215 point.position.y = point.screenPosition.y = y; |
| 218 touches[index].state = WebTouchPoint::StateMoved; | 216 touches[index].state = WebTouchPoint::StateMoved; |
| 219 WebTouchEventTraits::ResetType( | 217 WebTouchEventTraits::ResetType(WebInputEvent::TouchMove, timeStampSeconds, |
| 220 WebInputEvent::TouchMove, timeStampSeconds, this); | 218 this); |
| 221 } | 219 } |
| 222 | 220 |
| 223 void SyntheticWebTouchEvent::ReleasePoint(int index) { | 221 void SyntheticWebTouchEvent::ReleasePoint(int index) { |
| 224 CHECK_GE(index, 0); | 222 CHECK_GE(index, 0); |
| 225 CHECK_LT(index, kTouchesLengthCap); | 223 CHECK_LT(index, kTouchesLengthCap); |
| 226 touches[index].state = WebTouchPoint::StateReleased; | 224 touches[index].state = WebTouchPoint::StateReleased; |
| 227 WebTouchEventTraits::ResetType( | 225 WebTouchEventTraits::ResetType(WebInputEvent::TouchEnd, timeStampSeconds, |
| 228 WebInputEvent::TouchEnd, timeStampSeconds, this); | 226 this); |
| 229 } | 227 } |
| 230 | 228 |
| 231 void SyntheticWebTouchEvent::CancelPoint(int index) { | 229 void SyntheticWebTouchEvent::CancelPoint(int index) { |
| 232 CHECK_GE(index, 0); | 230 CHECK_GE(index, 0); |
| 233 CHECK_LT(index, kTouchesLengthCap); | 231 CHECK_LT(index, kTouchesLengthCap); |
| 234 touches[index].state = WebTouchPoint::StateCancelled; | 232 touches[index].state = WebTouchPoint::StateCancelled; |
| 235 WebTouchEventTraits::ResetType( | 233 WebTouchEventTraits::ResetType(WebInputEvent::TouchCancel, timeStampSeconds, |
| 236 WebInputEvent::TouchCancel, timeStampSeconds, this); | 234 this); |
| 237 } | 235 } |
| 238 | 236 |
| 239 void SyntheticWebTouchEvent::SetTimestamp(base::TimeTicks timestamp) { | 237 void SyntheticWebTouchEvent::SetTimestamp(base::TimeTicks timestamp) { |
| 240 timeStampSeconds = ui::EventTimeStampToSeconds(timestamp); | 238 setTimeStampSeconds(ui::EventTimeStampToSeconds(timestamp)); |
| 241 } | 239 } |
| 242 | 240 |
| 243 } // namespace content | 241 } // namespace content |
| OLD | NEW |