| 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/browser/renderer_host/input/web_input_event_util.h" | 5 #include "content/browser/renderer_host/input/web_input_event_util.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "ui/events/gesture_detection/gesture_event_data.h" | 8 #include "ui/events/gesture_detection/gesture_event_data.h" |
| 9 #include "ui/events/gesture_detection/motion_event.h" | 9 #include "ui/events/gesture_detection/motion_event.h" |
| 10 | 10 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 return "PrintScreen"; | 105 return "PrintScreen"; |
| 106 case ui::VKEY_RIGHT: | 106 case ui::VKEY_RIGHT: |
| 107 return "Right"; | 107 return "Right"; |
| 108 case ui::VKEY_SCROLL: | 108 case ui::VKEY_SCROLL: |
| 109 return "Scroll"; | 109 return "Scroll"; |
| 110 case ui::VKEY_SELECT: | 110 case ui::VKEY_SELECT: |
| 111 return "Select"; | 111 return "Select"; |
| 112 case ui::VKEY_UP: | 112 case ui::VKEY_UP: |
| 113 return "Up"; | 113 return "Up"; |
| 114 case ui::VKEY_DELETE: | 114 case ui::VKEY_DELETE: |
| 115 return "U+007F"; // Standard says that DEL becomes U+007F. | 115 return "U+007F"; // Standard says that DEL becomes U+007F. |
| 116 case ui::VKEY_MEDIA_NEXT_TRACK: | 116 case ui::VKEY_MEDIA_NEXT_TRACK: |
| 117 return "MediaNextTrack"; | 117 return "MediaNextTrack"; |
| 118 case ui::VKEY_MEDIA_PREV_TRACK: | 118 case ui::VKEY_MEDIA_PREV_TRACK: |
| 119 return "MediaPreviousTrack"; | 119 return "MediaPreviousTrack"; |
| 120 case ui::VKEY_MEDIA_STOP: | 120 case ui::VKEY_MEDIA_STOP: |
| 121 return "MediaStop"; | 121 return "MediaStop"; |
| 122 case ui::VKEY_MEDIA_PLAY_PAUSE: | 122 case ui::VKEY_MEDIA_PLAY_PAUSE: |
| 123 return "MediaPlayPause"; | 123 return "MediaPlayPause"; |
| 124 case ui::VKEY_VOLUME_MUTE: | 124 case ui::VKEY_VOLUME_MUTE: |
| 125 return "VolumeMute"; | 125 return "VolumeMute"; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 : WebTouchPoint::StateStationary; | 170 : WebTouchPoint::StateStationary; |
| 171 case MotionEvent::ACTION_POINTER_UP: | 171 case MotionEvent::ACTION_POINTER_UP: |
| 172 return is_action_pointer ? WebTouchPoint::StateReleased | 172 return is_action_pointer ? WebTouchPoint::StateReleased |
| 173 : WebTouchPoint::StateStationary; | 173 : WebTouchPoint::StateStationary; |
| 174 } | 174 } |
| 175 NOTREACHED() << "Invalid MotionEvent::Action."; | 175 NOTREACHED() << "Invalid MotionEvent::Action."; |
| 176 return WebTouchPoint::StateUndefined; | 176 return WebTouchPoint::StateUndefined; |
| 177 } | 177 } |
| 178 | 178 |
| 179 WebTouchPoint CreateWebTouchPoint(const MotionEvent& event, | 179 WebTouchPoint CreateWebTouchPoint(const MotionEvent& event, |
| 180 size_t pointer_index, | 180 size_t pointer_index) { |
| 181 float scale) { | |
| 182 WebTouchPoint touch; | 181 WebTouchPoint touch; |
| 183 touch.id = event.GetPointerId(pointer_index); | 182 touch.id = event.GetPointerId(pointer_index); |
| 184 touch.state = ToWebTouchPointState( | 183 touch.state = ToWebTouchPointState( |
| 185 event.GetAction(), | 184 event.GetAction(), |
| 186 static_cast<int>(pointer_index) == event.GetActionIndex()); | 185 static_cast<int>(pointer_index) == event.GetActionIndex()); |
| 187 touch.position.x = event.GetX(pointer_index) * scale; | 186 touch.position.x = event.GetX(pointer_index); |
| 188 touch.position.y = event.GetY(pointer_index) * scale; | 187 touch.position.y = event.GetY(pointer_index); |
| 189 // TODO(joth): Raw event co-ordinates. | 188 // TODO(joth): Raw event co-ordinates. |
| 190 touch.screenPosition = touch.position; | 189 touch.screenPosition = touch.position; |
| 191 touch.radiusX = touch.radiusY = | 190 touch.radiusX = touch.radiusY = event.GetTouchMajor(pointer_index) * 0.5f; |
| 192 event.GetTouchMajor(pointer_index) * 0.5f * scale; | |
| 193 touch.force = event.GetPressure(pointer_index); | 191 touch.force = event.GetPressure(pointer_index); |
| 194 | 192 |
| 195 return touch; | 193 return touch; |
| 196 } | 194 } |
| 197 | 195 |
| 198 } // namespace | 196 } // namespace |
| 199 | 197 |
| 200 namespace content { | 198 namespace content { |
| 201 | 199 |
| 202 void UpdateWindowsKeyCodeAndKeyIdentifier(blink::WebKeyboardEvent* event, | 200 void UpdateWindowsKeyCodeAndKeyIdentifier(blink::WebKeyboardEvent* event, |
| 203 ui::KeyboardCode windows_key_code) { | 201 ui::KeyboardCode windows_key_code) { |
| 204 event->windowsKeyCode = windows_key_code; | 202 event->windowsKeyCode = windows_key_code; |
| 205 | 203 |
| 206 const char* id = GetKeyIdentifier(windows_key_code); | 204 const char* id = GetKeyIdentifier(windows_key_code); |
| 207 if (id) { | 205 if (id) { |
| 208 base::strlcpy(event->keyIdentifier, id, sizeof(event->keyIdentifier) - 1); | 206 base::strlcpy(event->keyIdentifier, id, sizeof(event->keyIdentifier) - 1); |
| 209 } else { | 207 } else { |
| 210 base::snprintf(event->keyIdentifier, sizeof(event->keyIdentifier), "U+%04X", | 208 base::snprintf(event->keyIdentifier, |
| 209 sizeof(event->keyIdentifier), |
| 210 "U+%04X", |
| 211 base::ToUpperASCII(static_cast<int>(windows_key_code))); | 211 base::ToUpperASCII(static_cast<int>(windows_key_code))); |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 | 214 |
| 215 blink::WebTouchEvent CreateWebTouchEventFromMotionEvent( | 215 blink::WebTouchEvent CreateWebTouchEventFromMotionEvent( |
| 216 const ui::MotionEvent& event, | 216 const ui::MotionEvent& event) { |
| 217 float scale) { | |
| 218 blink::WebTouchEvent result; | 217 blink::WebTouchEvent result; |
| 219 | 218 |
| 220 result.type = ToWebInputEventType(event.GetAction()); | 219 result.type = ToWebInputEventType(event.GetAction()); |
| 221 DCHECK(WebInputEvent::isTouchEventType(result.type)); | 220 DCHECK(WebInputEvent::isTouchEventType(result.type)); |
| 222 | 221 |
| 223 result.timeStampSeconds = | 222 result.timeStampSeconds = |
| 224 (event.GetEventTime() - base::TimeTicks()).InSecondsF(); | 223 (event.GetEventTime() - base::TimeTicks()).InSecondsF(); |
| 225 | 224 |
| 226 result.touchesLength = | 225 result.touchesLength = |
| 227 std::min(event.GetPointerCount(), | 226 std::min(event.GetPointerCount(), |
| 228 static_cast<size_t>(WebTouchEvent::touchesLengthCap)); | 227 static_cast<size_t>(WebTouchEvent::touchesLengthCap)); |
| 229 DCHECK_GT(result.touchesLength, 0U); | 228 DCHECK_GT(result.touchesLength, 0U); |
| 230 | 229 |
| 231 for (size_t i = 0; i < result.touchesLength; ++i) | 230 for (size_t i = 0; i < result.touchesLength; ++i) |
| 232 result.touches[i] = CreateWebTouchPoint(event, i, scale); | 231 result.touches[i] = CreateWebTouchPoint(event, i); |
| 233 | 232 |
| 234 return result; | 233 return result; |
| 235 } | 234 } |
| 236 | 235 |
| 237 WebGestureEvent CreateWebGestureEventFromGestureEventData( | 236 WebGestureEvent CreateWebGestureEventFromGestureEventData( |
| 238 const ui::GestureEventData& data, | 237 const ui::GestureEventData& data) { |
| 239 float scale) { | |
| 240 WebGestureEvent gesture; | 238 WebGestureEvent gesture; |
| 241 gesture.x = data.x * scale; | 239 gesture.x = data.x; |
| 242 gesture.y = data.y * scale; | 240 gesture.y = data.y; |
| 243 gesture.timeStampSeconds = (data.time - base::TimeTicks()).InSecondsF(); | 241 gesture.timeStampSeconds = (data.time - base::TimeTicks()).InSecondsF(); |
| 244 gesture.sourceDevice = WebGestureEvent::Touchscreen; | 242 gesture.sourceDevice = WebGestureEvent::Touchscreen; |
| 245 | 243 |
| 246 switch (data.type) { | 244 switch (data.type) { |
| 247 case ui::ET_GESTURE_SHOW_PRESS: | 245 case ui::ET_GESTURE_SHOW_PRESS: |
| 248 gesture.type = WebInputEvent::GestureShowPress; | 246 gesture.type = WebInputEvent::GestureShowPress; |
| 249 gesture.data.showPress.width = | 247 gesture.data.showPress.width = data.details.bounding_box_f().width(); |
| 250 data.details.bounding_box_f().width() * scale; | 248 gesture.data.showPress.height = data.details.bounding_box_f().height(); |
| 251 gesture.data.showPress.height = | |
| 252 data.details.bounding_box_f().height() * scale; | |
| 253 break; | 249 break; |
| 254 case ui::ET_GESTURE_DOUBLE_TAP: | 250 case ui::ET_GESTURE_DOUBLE_TAP: |
| 255 gesture.type = WebInputEvent::GestureDoubleTap; | 251 gesture.type = WebInputEvent::GestureDoubleTap; |
| 256 DCHECK_EQ(1, data.details.tap_count()); | 252 DCHECK_EQ(1, data.details.tap_count()); |
| 257 gesture.data.tap.tapCount = data.details.tap_count(); | 253 gesture.data.tap.tapCount = data.details.tap_count(); |
| 258 gesture.data.tap.width = data.details.bounding_box_f().width() * scale; | 254 gesture.data.tap.width = data.details.bounding_box_f().width(); |
| 259 gesture.data.tap.height = data.details.bounding_box_f().height() * scale; | 255 gesture.data.tap.height = data.details.bounding_box_f().height(); |
| 260 break; | 256 break; |
| 261 case ui::ET_GESTURE_TAP: | 257 case ui::ET_GESTURE_TAP: |
| 262 gesture.type = WebInputEvent::GestureTap; | 258 gesture.type = WebInputEvent::GestureTap; |
| 263 DCHECK_EQ(1, data.details.tap_count()); | 259 DCHECK_EQ(1, data.details.tap_count()); |
| 264 gesture.data.tap.tapCount = data.details.tap_count(); | 260 gesture.data.tap.tapCount = data.details.tap_count(); |
| 265 gesture.data.tap.width = data.details.bounding_box_f().width() * scale; | 261 gesture.data.tap.width = data.details.bounding_box_f().width(); |
| 266 gesture.data.tap.height = data.details.bounding_box_f().height() * scale; | 262 gesture.data.tap.height = data.details.bounding_box_f().height(); |
| 267 break; | 263 break; |
| 268 case ui::ET_GESTURE_TAP_UNCONFIRMED: | 264 case ui::ET_GESTURE_TAP_UNCONFIRMED: |
| 269 gesture.type = WebInputEvent::GestureTapUnconfirmed; | 265 gesture.type = WebInputEvent::GestureTapUnconfirmed; |
| 270 DCHECK_EQ(1, data.details.tap_count()); | 266 DCHECK_EQ(1, data.details.tap_count()); |
| 271 gesture.data.tap.tapCount = data.details.tap_count(); | 267 gesture.data.tap.tapCount = data.details.tap_count(); |
| 272 gesture.data.tap.width = data.details.bounding_box_f().width() * scale; | 268 gesture.data.tap.width = data.details.bounding_box_f().width(); |
| 273 gesture.data.tap.height = data.details.bounding_box_f().height() * scale; | 269 gesture.data.tap.height = data.details.bounding_box_f().height(); |
| 274 break; | 270 break; |
| 275 case ui::ET_GESTURE_LONG_PRESS: | 271 case ui::ET_GESTURE_LONG_PRESS: |
| 276 gesture.type = WebInputEvent::GestureLongPress; | 272 gesture.type = WebInputEvent::GestureLongPress; |
| 277 gesture.data.longPress.width = | 273 gesture.data.longPress.width = data.details.bounding_box_f().width(); |
| 278 data.details.bounding_box_f().width() * scale; | 274 gesture.data.longPress.height = data.details.bounding_box_f().height(); |
| 279 gesture.data.longPress.height = | |
| 280 data.details.bounding_box_f().height() * scale; | |
| 281 break; | 275 break; |
| 282 case ui::ET_GESTURE_LONG_TAP: | 276 case ui::ET_GESTURE_LONG_TAP: |
| 283 gesture.type = WebInputEvent::GestureLongTap; | 277 gesture.type = WebInputEvent::GestureLongTap; |
| 284 gesture.data.longPress.width = | 278 gesture.data.longPress.width = data.details.bounding_box_f().width(); |
| 285 data.details.bounding_box_f().width() * scale; | 279 gesture.data.longPress.height = data.details.bounding_box_f().height(); |
| 286 gesture.data.longPress.height = | |
| 287 data.details.bounding_box_f().height() * scale; | |
| 288 break; | 280 break; |
| 289 case ui::ET_GESTURE_SCROLL_BEGIN: | 281 case ui::ET_GESTURE_SCROLL_BEGIN: |
| 290 gesture.type = WebInputEvent::GestureScrollBegin; | 282 gesture.type = WebInputEvent::GestureScrollBegin; |
| 291 gesture.data.scrollBegin.deltaXHint = | 283 gesture.data.scrollBegin.deltaXHint = data.details.scroll_x_hint(); |
| 292 data.details.scroll_x_hint() * scale; | 284 gesture.data.scrollBegin.deltaYHint = data.details.scroll_y_hint(); |
| 293 gesture.data.scrollBegin.deltaYHint = | |
| 294 data.details.scroll_y_hint() * scale; | |
| 295 break; | 285 break; |
| 296 case ui::ET_GESTURE_SCROLL_UPDATE: | 286 case ui::ET_GESTURE_SCROLL_UPDATE: |
| 297 gesture.type = WebInputEvent::GestureScrollUpdate; | 287 gesture.type = WebInputEvent::GestureScrollUpdate; |
| 298 gesture.data.scrollUpdate.deltaX = data.details.scroll_x() * scale; | 288 gesture.data.scrollUpdate.deltaX = data.details.scroll_x(); |
| 299 gesture.data.scrollUpdate.deltaY = data.details.scroll_y() * scale; | 289 gesture.data.scrollUpdate.deltaY = data.details.scroll_y(); |
| 300 gesture.data.scrollUpdate.velocityX = data.details.velocity_x() * scale; | 290 gesture.data.scrollUpdate.velocityX = data.details.velocity_x(); |
| 301 gesture.data.scrollUpdate.velocityY = data.details.velocity_y() * scale; | 291 gesture.data.scrollUpdate.velocityY = data.details.velocity_y(); |
| 302 break; | 292 break; |
| 303 case ui::ET_GESTURE_SCROLL_END: | 293 case ui::ET_GESTURE_SCROLL_END: |
| 304 gesture.type = WebInputEvent::GestureScrollEnd; | 294 gesture.type = WebInputEvent::GestureScrollEnd; |
| 305 break; | 295 break; |
| 306 case ui::ET_SCROLL_FLING_START: | 296 case ui::ET_SCROLL_FLING_START: |
| 307 gesture.type = WebInputEvent::GestureFlingStart; | 297 gesture.type = WebInputEvent::GestureFlingStart; |
| 308 gesture.data.flingStart.velocityX = data.details.velocity_x() * scale; | 298 gesture.data.flingStart.velocityX = data.details.velocity_x(); |
| 309 gesture.data.flingStart.velocityY = data.details.velocity_y() * scale; | 299 gesture.data.flingStart.velocityY = data.details.velocity_y(); |
| 310 break; | 300 break; |
| 311 case ui::ET_SCROLL_FLING_CANCEL: | 301 case ui::ET_SCROLL_FLING_CANCEL: |
| 312 gesture.type = WebInputEvent::GestureFlingCancel; | 302 gesture.type = WebInputEvent::GestureFlingCancel; |
| 313 break; | 303 break; |
| 314 case ui::ET_GESTURE_PINCH_BEGIN: | 304 case ui::ET_GESTURE_PINCH_BEGIN: |
| 315 gesture.type = WebInputEvent::GesturePinchBegin; | 305 gesture.type = WebInputEvent::GesturePinchBegin; |
| 316 break; | 306 break; |
| 317 case ui::ET_GESTURE_PINCH_UPDATE: | 307 case ui::ET_GESTURE_PINCH_UPDATE: |
| 318 gesture.type = WebInputEvent::GesturePinchUpdate; | 308 gesture.type = WebInputEvent::GesturePinchUpdate; |
| 319 gesture.data.pinchUpdate.scale = data.details.scale(); | 309 gesture.data.pinchUpdate.scale = data.details.scale(); |
| 320 break; | 310 break; |
| 321 case ui::ET_GESTURE_PINCH_END: | 311 case ui::ET_GESTURE_PINCH_END: |
| 322 gesture.type = WebInputEvent::GesturePinchEnd; | 312 gesture.type = WebInputEvent::GesturePinchEnd; |
| 323 break; | 313 break; |
| 324 case ui::ET_GESTURE_TAP_CANCEL: | 314 case ui::ET_GESTURE_TAP_CANCEL: |
| 325 gesture.type = WebInputEvent::GestureTapCancel; | 315 gesture.type = WebInputEvent::GestureTapCancel; |
| 326 break; | 316 break; |
| 327 case ui::ET_GESTURE_TAP_DOWN: | 317 case ui::ET_GESTURE_TAP_DOWN: |
| 328 gesture.type = WebInputEvent::GestureTapDown; | 318 gesture.type = WebInputEvent::GestureTapDown; |
| 329 gesture.data.tapDown.width = | 319 gesture.data.tapDown.width = data.details.bounding_box_f().width(); |
| 330 data.details.bounding_box_f().width() * scale; | 320 gesture.data.tapDown.height = data.details.bounding_box_f().height(); |
| 331 gesture.data.tapDown.height = | |
| 332 data.details.bounding_box_f().height() * scale; | |
| 333 break; | 321 break; |
| 334 case ui::ET_GESTURE_BEGIN: | 322 case ui::ET_GESTURE_BEGIN: |
| 335 case ui::ET_GESTURE_END: | 323 case ui::ET_GESTURE_END: |
| 336 NOTREACHED() << "ET_GESTURE_BEGIN and ET_GESTURE_END are only produced " | 324 NOTREACHED() << "ET_GESTURE_BEGIN and ET_GESTURE_END are only produced " |
| 337 << "in Aura, and should never end up here."; | 325 << "in Aura, and should never end up here."; |
| 338 break; | 326 break; |
| 339 default: | 327 default: |
| 340 NOTREACHED() << "ui::EventType provided wasn't a valid gesture event."; | 328 NOTREACHED() << "ui::EventType provided wasn't a valid gesture event."; |
| 341 break; | 329 break; |
| 342 } | 330 } |
| 343 | 331 |
| 344 return gesture; | 332 return gesture; |
| 345 } | 333 } |
| 346 | 334 |
| 347 } // namespace content | 335 } // namespace content |
| OLD | NEW |