| 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 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
| 6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
| 7 | 7 |
| 8 #include "content/browser/renderer_host/input/web_input_event_util.h" | 8 #include "content/browser/renderer_host/input/web_input_event_util.h" |
| 9 | 9 |
| 10 #include <cmath> | 10 #include <cmath> |
| 11 | 11 |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "content/common/input/web_touch_event_traits.h" | 13 #include "content/common/input/web_touch_event_traits.h" |
| 14 #include "ui/events/event_constants.h" | 14 #include "ui/events/event_constants.h" |
| 15 #include "ui/events/gesture_detection/gesture_event_data.h" | 15 #include "ui/events/gesture_detection/gesture_event_data.h" |
| 16 #include "ui/events/gesture_detection/motion_event.h" | 16 #include "ui/events/gesture_detection/motion_event.h" |
| 17 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 17 | 18 |
| 18 using blink::WebGestureEvent; | 19 using blink::WebGestureEvent; |
| 19 using blink::WebInputEvent; | 20 using blink::WebInputEvent; |
| 20 using blink::WebTouchEvent; | 21 using blink::WebTouchEvent; |
| 21 using blink::WebTouchPoint; | 22 using blink::WebTouchPoint; |
| 22 using ui::MotionEvent; | 23 using ui::MotionEvent; |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 const char* GetKeyIdentifier(ui::KeyboardCode key_code) { | 27 const char* GetKeyIdentifier(ui::KeyboardCode key_code) { |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 std::min(event.GetPointerCount(), | 273 std::min(event.GetPointerCount(), |
| 273 static_cast<size_t>(WebTouchEvent::touchesLengthCap)); | 274 static_cast<size_t>(WebTouchEvent::touchesLengthCap)); |
| 274 DCHECK_GT(result.touchesLength, 0U); | 275 DCHECK_GT(result.touchesLength, 0U); |
| 275 | 276 |
| 276 for (size_t i = 0; i < result.touchesLength; ++i) | 277 for (size_t i = 0; i < result.touchesLength; ++i) |
| 277 result.touches[i] = CreateWebTouchPoint(event, i); | 278 result.touches[i] = CreateWebTouchPoint(event, i); |
| 278 | 279 |
| 279 return result; | 280 return result; |
| 280 } | 281 } |
| 281 | 282 |
| 282 WebGestureEvent CreateWebGestureEventFromGestureEventData( | 283 WebGestureEvent CreateWebGestureEvent(const ui::GestureEventDetails& details, |
| 283 const ui::GestureEventData& data) { | 284 base::TimeDelta timestamp, |
| 285 const gfx::PointF& location, |
| 286 const gfx::PointF& raw_location, |
| 287 int flags) { |
| 284 WebGestureEvent gesture; | 288 WebGestureEvent gesture; |
| 285 gesture.modifiers = EventFlagsToWebEventModifiers(data.flags); | 289 gesture.timeStampSeconds = timestamp.InSecondsF(); |
| 286 gesture.x = data.x; | 290 gesture.x = gfx::ToFlooredInt(location.x()); |
| 287 gesture.y = data.y; | 291 gesture.y = gfx::ToFlooredInt(location.y()); |
| 288 gesture.globalX = data.raw_x; | 292 gesture.globalX = gfx::ToFlooredInt(raw_location.x()); |
| 289 gesture.globalY = data.raw_y; | 293 gesture.globalY = gfx::ToFlooredInt(raw_location.y()); |
| 290 gesture.timeStampSeconds = (data.time - base::TimeTicks()).InSecondsF(); | 294 gesture.modifiers = EventFlagsToWebEventModifiers(flags); |
| 291 gesture.sourceDevice = blink::WebGestureDeviceTouchscreen; | 295 gesture.sourceDevice = blink::WebGestureDeviceTouchscreen; |
| 292 | 296 |
| 293 switch (data.type()) { | 297 switch (details.type()) { |
| 294 case ui::ET_GESTURE_SHOW_PRESS: | 298 case ui::ET_GESTURE_SHOW_PRESS: |
| 295 gesture.type = WebInputEvent::GestureShowPress; | 299 gesture.type = WebInputEvent::GestureShowPress; |
| 296 gesture.data.showPress.width = data.details.bounding_box_f().width(); | 300 gesture.data.showPress.width = details.bounding_box_f().width(); |
| 297 gesture.data.showPress.height = data.details.bounding_box_f().height(); | 301 gesture.data.showPress.height = details.bounding_box_f().height(); |
| 298 break; | 302 break; |
| 299 case ui::ET_GESTURE_DOUBLE_TAP: | 303 case ui::ET_GESTURE_DOUBLE_TAP: |
| 300 gesture.type = WebInputEvent::GestureDoubleTap; | 304 gesture.type = WebInputEvent::GestureDoubleTap; |
| 301 DCHECK_EQ(1, data.details.tap_count()); | 305 DCHECK_EQ(1, details.tap_count()); |
| 302 gesture.data.tap.tapCount = data.details.tap_count(); | 306 gesture.data.tap.tapCount = details.tap_count(); |
| 303 gesture.data.tap.width = data.details.bounding_box_f().width(); | 307 gesture.data.tap.width = details.bounding_box_f().width(); |
| 304 gesture.data.tap.height = data.details.bounding_box_f().height(); | 308 gesture.data.tap.height = details.bounding_box_f().height(); |
| 305 break; | 309 break; |
| 306 case ui::ET_GESTURE_TAP: | 310 case ui::ET_GESTURE_TAP: |
| 307 gesture.type = WebInputEvent::GestureTap; | 311 gesture.type = WebInputEvent::GestureTap; |
| 308 DCHECK_EQ(1, data.details.tap_count()); | 312 DCHECK_EQ(1, details.tap_count()); |
| 309 gesture.data.tap.tapCount = data.details.tap_count(); | 313 gesture.data.tap.tapCount = details.tap_count(); |
| 310 gesture.data.tap.width = data.details.bounding_box_f().width(); | 314 gesture.data.tap.width = details.bounding_box_f().width(); |
| 311 gesture.data.tap.height = data.details.bounding_box_f().height(); | 315 gesture.data.tap.height = details.bounding_box_f().height(); |
| 312 break; | 316 break; |
| 313 case ui::ET_GESTURE_TAP_UNCONFIRMED: | 317 case ui::ET_GESTURE_TAP_UNCONFIRMED: |
| 314 gesture.type = WebInputEvent::GestureTapUnconfirmed; | 318 gesture.type = WebInputEvent::GestureTapUnconfirmed; |
| 315 DCHECK_EQ(1, data.details.tap_count()); | 319 DCHECK_EQ(1, details.tap_count()); |
| 316 gesture.data.tap.tapCount = data.details.tap_count(); | 320 gesture.data.tap.tapCount = details.tap_count(); |
| 317 gesture.data.tap.width = data.details.bounding_box_f().width(); | 321 gesture.data.tap.width = details.bounding_box_f().width(); |
| 318 gesture.data.tap.height = data.details.bounding_box_f().height(); | 322 gesture.data.tap.height = details.bounding_box_f().height(); |
| 319 break; | 323 break; |
| 320 case ui::ET_GESTURE_LONG_PRESS: | 324 case ui::ET_GESTURE_LONG_PRESS: |
| 321 gesture.type = WebInputEvent::GestureLongPress; | 325 gesture.type = WebInputEvent::GestureLongPress; |
| 322 gesture.data.longPress.width = data.details.bounding_box_f().width(); | 326 gesture.data.longPress.width = details.bounding_box_f().width(); |
| 323 gesture.data.longPress.height = data.details.bounding_box_f().height(); | 327 gesture.data.longPress.height = details.bounding_box_f().height(); |
| 324 break; | 328 break; |
| 325 case ui::ET_GESTURE_LONG_TAP: | 329 case ui::ET_GESTURE_LONG_TAP: |
| 326 gesture.type = WebInputEvent::GestureLongTap; | 330 gesture.type = WebInputEvent::GestureLongTap; |
| 327 gesture.data.longPress.width = data.details.bounding_box_f().width(); | 331 gesture.data.longPress.width = details.bounding_box_f().width(); |
| 328 gesture.data.longPress.height = data.details.bounding_box_f().height(); | 332 gesture.data.longPress.height = details.bounding_box_f().height(); |
| 333 break; |
| 334 case ui::ET_GESTURE_TWO_FINGER_TAP: |
| 335 gesture.type = blink::WebInputEvent::GestureTwoFingerTap; |
| 336 gesture.data.twoFingerTap.firstFingerWidth = details.first_finger_width(); |
| 337 gesture.data.twoFingerTap.firstFingerHeight = |
| 338 details.first_finger_height(); |
| 329 break; | 339 break; |
| 330 case ui::ET_GESTURE_SCROLL_BEGIN: | 340 case ui::ET_GESTURE_SCROLL_BEGIN: |
| 331 gesture.type = WebInputEvent::GestureScrollBegin; | 341 gesture.type = WebInputEvent::GestureScrollBegin; |
| 332 gesture.data.scrollBegin.deltaXHint = data.details.scroll_x_hint(); | 342 gesture.data.scrollBegin.deltaXHint = details.scroll_x_hint(); |
| 333 gesture.data.scrollBegin.deltaYHint = data.details.scroll_y_hint(); | 343 gesture.data.scrollBegin.deltaYHint = details.scroll_y_hint(); |
| 334 break; | 344 break; |
| 335 case ui::ET_GESTURE_SCROLL_UPDATE: | 345 case ui::ET_GESTURE_SCROLL_UPDATE: |
| 336 gesture.type = WebInputEvent::GestureScrollUpdate; | 346 gesture.type = WebInputEvent::GestureScrollUpdate; |
| 337 gesture.data.scrollUpdate.deltaX = data.details.scroll_x(); | 347 gesture.data.scrollUpdate.deltaX = details.scroll_x(); |
| 338 gesture.data.scrollUpdate.deltaY = data.details.scroll_y(); | 348 gesture.data.scrollUpdate.deltaY = details.scroll_y(); |
| 349 gesture.data.scrollUpdate.previousUpdateInSequencePrevented = |
| 350 details.previous_scroll_update_in_sequence_prevented(); |
| 339 break; | 351 break; |
| 340 case ui::ET_GESTURE_SCROLL_END: | 352 case ui::ET_GESTURE_SCROLL_END: |
| 341 gesture.type = WebInputEvent::GestureScrollEnd; | 353 gesture.type = WebInputEvent::GestureScrollEnd; |
| 342 break; | 354 break; |
| 343 case ui::ET_SCROLL_FLING_START: | 355 case ui::ET_SCROLL_FLING_START: |
| 344 gesture.type = WebInputEvent::GestureFlingStart; | 356 gesture.type = WebInputEvent::GestureFlingStart; |
| 345 gesture.data.flingStart.velocityX = data.details.velocity_x(); | 357 gesture.data.flingStart.velocityX = details.velocity_x(); |
| 346 gesture.data.flingStart.velocityY = data.details.velocity_y(); | 358 gesture.data.flingStart.velocityY = details.velocity_y(); |
| 347 break; | 359 break; |
| 348 case ui::ET_SCROLL_FLING_CANCEL: | 360 case ui::ET_SCROLL_FLING_CANCEL: |
| 349 gesture.type = WebInputEvent::GestureFlingCancel; | 361 gesture.type = WebInputEvent::GestureFlingCancel; |
| 350 break; | 362 break; |
| 351 case ui::ET_GESTURE_PINCH_BEGIN: | 363 case ui::ET_GESTURE_PINCH_BEGIN: |
| 352 gesture.type = WebInputEvent::GesturePinchBegin; | 364 gesture.type = WebInputEvent::GesturePinchBegin; |
| 353 break; | 365 break; |
| 354 case ui::ET_GESTURE_PINCH_UPDATE: | 366 case ui::ET_GESTURE_PINCH_UPDATE: |
| 355 gesture.type = WebInputEvent::GesturePinchUpdate; | 367 gesture.type = WebInputEvent::GesturePinchUpdate; |
| 356 gesture.data.pinchUpdate.scale = data.details.scale(); | 368 gesture.data.pinchUpdate.scale = details.scale(); |
| 357 break; | 369 break; |
| 358 case ui::ET_GESTURE_PINCH_END: | 370 case ui::ET_GESTURE_PINCH_END: |
| 359 gesture.type = WebInputEvent::GesturePinchEnd; | 371 gesture.type = WebInputEvent::GesturePinchEnd; |
| 360 break; | 372 break; |
| 361 case ui::ET_GESTURE_TAP_CANCEL: | 373 case ui::ET_GESTURE_TAP_CANCEL: |
| 362 gesture.type = WebInputEvent::GestureTapCancel; | 374 gesture.type = WebInputEvent::GestureTapCancel; |
| 363 break; | 375 break; |
| 364 case ui::ET_GESTURE_TAP_DOWN: | 376 case ui::ET_GESTURE_TAP_DOWN: |
| 365 gesture.type = WebInputEvent::GestureTapDown; | 377 gesture.type = WebInputEvent::GestureTapDown; |
| 366 gesture.data.tapDown.width = data.details.bounding_box_f().width(); | 378 gesture.data.tapDown.width = details.bounding_box_f().width(); |
| 367 gesture.data.tapDown.height = data.details.bounding_box_f().height(); | 379 gesture.data.tapDown.height = details.bounding_box_f().height(); |
| 368 break; | 380 break; |
| 369 case ui::ET_GESTURE_BEGIN: | 381 case ui::ET_GESTURE_BEGIN: |
| 370 case ui::ET_GESTURE_END: | 382 case ui::ET_GESTURE_END: |
| 371 NOTREACHED() << "ET_GESTURE_BEGIN and ET_GESTURE_END are only produced " | 383 NOTREACHED() << "ET_GESTURE_BEGIN and ET_GESTURE_END are only produced " |
| 372 << "in Aura, and should never end up here."; | 384 << "in Aura, and should never end up here."; |
| 373 break; | 385 break; |
| 386 case ui::ET_GESTURE_SWIPE: |
| 387 NOTREACHED() << "ET_GESTURE_SWIPE events are only produced in Aura, and " |
| 388 << "should never end up here."; |
| 389 break; |
| 374 default: | 390 default: |
| 375 NOTREACHED() << "ui::EventType provided wasn't a valid gesture event."; | 391 NOTREACHED() << "ui::EventType provided wasn't a valid gesture event."; |
| 376 break; | 392 break; |
| 377 } | 393 } |
| 378 | 394 |
| 379 return gesture; | 395 return gesture; |
| 380 } | 396 } |
| 381 | 397 |
| 398 WebGestureEvent CreateWebGestureEventFromGestureEventData( |
| 399 const ui::GestureEventData& data) { |
| 400 return CreateWebGestureEvent(data.details, |
| 401 data.time - base::TimeTicks(), |
| 402 gfx::PointF(data.x, data.y), |
| 403 gfx::PointF(data.raw_x, data.raw_y), |
| 404 data.flags); |
| 405 } |
| 406 |
| 382 int EventFlagsToWebEventModifiers(int flags) { | 407 int EventFlagsToWebEventModifiers(int flags) { |
| 383 int modifiers = 0; | 408 int modifiers = 0; |
| 384 | 409 |
| 385 if (flags & ui::EF_SHIFT_DOWN) | 410 if (flags & ui::EF_SHIFT_DOWN) |
| 386 modifiers |= blink::WebInputEvent::ShiftKey; | 411 modifiers |= blink::WebInputEvent::ShiftKey; |
| 387 if (flags & ui::EF_CONTROL_DOWN) | 412 if (flags & ui::EF_CONTROL_DOWN) |
| 388 modifiers |= blink::WebInputEvent::ControlKey; | 413 modifiers |= blink::WebInputEvent::ControlKey; |
| 389 if (flags & ui::EF_ALT_DOWN) | 414 if (flags & ui::EF_ALT_DOWN) |
| 390 modifiers |= blink::WebInputEvent::AltKey; | 415 modifiers |= blink::WebInputEvent::AltKey; |
| 391 if (flags & ui::EF_COMMAND_DOWN) | 416 if (flags & ui::EF_COMMAND_DOWN) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 flags |= ui::EF_CAPS_LOCK_DOWN; | 454 flags |= ui::EF_CAPS_LOCK_DOWN; |
| 430 if (modifiers & blink::WebInputEvent::IsAutoRepeat) | 455 if (modifiers & blink::WebInputEvent::IsAutoRepeat) |
| 431 flags |= ui::EF_IS_REPEAT; | 456 flags |= ui::EF_IS_REPEAT; |
| 432 if (modifiers & blink::WebInputEvent::IsKeyPad) | 457 if (modifiers & blink::WebInputEvent::IsKeyPad) |
| 433 flags |= ui::EF_NUMPAD_KEY; | 458 flags |= ui::EF_NUMPAD_KEY; |
| 434 | 459 |
| 435 return flags; | 460 return flags; |
| 436 } | 461 } |
| 437 | 462 |
| 438 } // namespace content | 463 } // namespace content |
| OLD | NEW |