| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/shell/renderer/test_runner/event_sender.h" | 5 #include "content/shell/renderer/test_runner/event_sender.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 bool IsSystemKeyEvent(const WebKeyboardEvent& event) { | 340 bool IsSystemKeyEvent(const WebKeyboardEvent& event) { |
| 341 #if defined(OS_MACOSX) | 341 #if defined(OS_MACOSX) |
| 342 return event.modifiers & WebInputEvent::MetaKey && | 342 return event.modifiers & WebInputEvent::MetaKey && |
| 343 event.windowsKeyCode != ui::VKEY_B && | 343 event.windowsKeyCode != ui::VKEY_B && |
| 344 event.windowsKeyCode != ui::VKEY_I; | 344 event.windowsKeyCode != ui::VKEY_I; |
| 345 #else | 345 #else |
| 346 return !!(event.modifiers & WebInputEvent::AltKey); | 346 return !!(event.modifiers & WebInputEvent::AltKey); |
| 347 #endif | 347 #endif |
| 348 } | 348 } |
| 349 | 349 |
| 350 const char* kSourceDeviceStringTouchpad = "touchpad"; |
| 351 const char* kSourceDeviceStringTouchscreen = "touchscreen"; |
| 352 |
| 350 } // namespace | 353 } // namespace |
| 351 | 354 |
| 352 class EventSenderBindings : public gin::Wrappable<EventSenderBindings> { | 355 class EventSenderBindings : public gin::Wrappable<EventSenderBindings> { |
| 353 public: | 356 public: |
| 354 static gin::WrapperInfo kWrapperInfo; | 357 static gin::WrapperInfo kWrapperInfo; |
| 355 | 358 |
| 356 static void Install(base::WeakPtr<EventSender> sender, | 359 static void Install(base::WeakPtr<EventSender> sender, |
| 357 blink::WebFrame* frame); | 360 blink::WebFrame* frame); |
| 358 | 361 |
| 359 private: | 362 private: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 377 void SetPageScaleFactor(gin::Arguments* args); | 380 void SetPageScaleFactor(gin::Arguments* args); |
| 378 void SetPageScaleFactorLimits(gin::Arguments* args); | 381 void SetPageScaleFactorLimits(gin::Arguments* args); |
| 379 void ClearTouchPoints(); | 382 void ClearTouchPoints(); |
| 380 void ReleaseTouchPoint(unsigned index); | 383 void ReleaseTouchPoint(unsigned index); |
| 381 void UpdateTouchPoint(unsigned index, double x, double y); | 384 void UpdateTouchPoint(unsigned index, double x, double y); |
| 382 void CancelTouchPoint(unsigned index); | 385 void CancelTouchPoint(unsigned index); |
| 383 void SetTouchModifier(const std::string& key_name, bool set_mask); | 386 void SetTouchModifier(const std::string& key_name, bool set_mask); |
| 384 void SetTouchCancelable(bool cancelable); | 387 void SetTouchCancelable(bool cancelable); |
| 385 void DumpFilenameBeingDragged(); | 388 void DumpFilenameBeingDragged(); |
| 386 void GestureFlingCancel(); | 389 void GestureFlingCancel(); |
| 387 void GestureFlingStart(float x, float y, float velocity_x, float velocity_y); | 390 void GestureFlingStart(float x, |
| 391 float y, |
| 392 float velocity_x, |
| 393 float velocity_y, |
| 394 gin::Arguments* args); |
| 388 void GestureScrollFirstPoint(int x, int y); | 395 void GestureScrollFirstPoint(int x, int y); |
| 389 void TouchStart(); | 396 void TouchStart(); |
| 390 void TouchMove(); | 397 void TouchMove(); |
| 391 void TouchCancel(); | 398 void TouchCancel(); |
| 392 void TouchEnd(); | 399 void TouchEnd(); |
| 393 void LeapForward(int milliseconds); | 400 void LeapForward(int milliseconds); |
| 394 void BeginDragWithFiles(const std::vector<std::string>& files); | 401 void BeginDragWithFiles(const std::vector<std::string>& files); |
| 395 void AddTouchPoint(gin::Arguments* args); | 402 void AddTouchPoint(gin::Arguments* args); |
| 396 void MouseDragBegin(); | 403 void MouseDragBegin(); |
| 397 void MouseDragEnd(); | 404 void MouseDragEnd(); |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 } | 722 } |
| 716 | 723 |
| 717 void EventSenderBindings::GestureFlingCancel() { | 724 void EventSenderBindings::GestureFlingCancel() { |
| 718 if (sender_) | 725 if (sender_) |
| 719 sender_->GestureFlingCancel(); | 726 sender_->GestureFlingCancel(); |
| 720 } | 727 } |
| 721 | 728 |
| 722 void EventSenderBindings::GestureFlingStart(float x, | 729 void EventSenderBindings::GestureFlingStart(float x, |
| 723 float y, | 730 float y, |
| 724 float velocity_x, | 731 float velocity_x, |
| 725 float velocity_y) { | 732 float velocity_y, |
| 733 gin::Arguments* args) { |
| 726 if (sender_) | 734 if (sender_) |
| 727 sender_->GestureFlingStart(x, y, velocity_x, velocity_y); | 735 sender_->GestureFlingStart(x, y, velocity_x, velocity_y, args); |
| 728 } | 736 } |
| 729 | 737 |
| 730 void EventSenderBindings::GestureScrollFirstPoint(int x, int y) { | 738 void EventSenderBindings::GestureScrollFirstPoint(int x, int y) { |
| 731 if (sender_) | 739 if (sender_) |
| 732 sender_->GestureScrollFirstPoint(x, y); | 740 sender_->GestureScrollFirstPoint(x, y); |
| 733 } | 741 } |
| 734 | 742 |
| 735 void EventSenderBindings::TouchStart() { | 743 void EventSenderBindings::TouchStart() { |
| 736 if (sender_) | 744 if (sender_) |
| 737 sender_->TouchStart(); | 745 sender_->TouchStart(); |
| (...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1639 event.type = WebInputEvent::GestureFlingCancel; | 1647 event.type = WebInputEvent::GestureFlingCancel; |
| 1640 event.timeStampSeconds = GetCurrentEventTimeSec(); | 1648 event.timeStampSeconds = GetCurrentEventTimeSec(); |
| 1641 | 1649 |
| 1642 if (force_layout_on_events_) | 1650 if (force_layout_on_events_) |
| 1643 view_->layout(); | 1651 view_->layout(); |
| 1644 | 1652 |
| 1645 HandleInputEventOnViewOrPopup(event); | 1653 HandleInputEventOnViewOrPopup(event); |
| 1646 } | 1654 } |
| 1647 | 1655 |
| 1648 void EventSender::GestureFlingStart(float x, | 1656 void EventSender::GestureFlingStart(float x, |
| 1649 float y, | 1657 float y, |
| 1650 float velocity_x, | 1658 float velocity_x, |
| 1651 float velocity_y) { | 1659 float velocity_y, |
| 1660 gin::Arguments* args) { |
| 1652 WebGestureEvent event; | 1661 WebGestureEvent event; |
| 1653 event.type = WebInputEvent::GestureFlingStart; | 1662 event.type = WebInputEvent::GestureFlingStart; |
| 1654 | 1663 |
| 1664 // TODO(tdresser): Once we've migrated all calls to GestureFlingStart |
| 1665 // to pass the device string, throw an error if args is empty. See |
| 1666 // crbug.com/456136 for details. |
| 1667 std::string device_string = kSourceDeviceStringTouchpad; |
| 1668 if (!args->PeekNext().IsEmpty() && args->PeekNext()->IsString()) { |
| 1669 if (!args->GetNext(&device_string)) { |
| 1670 args->ThrowError(); |
| 1671 return; |
| 1672 } |
| 1673 } |
| 1674 |
| 1675 if (device_string == kSourceDeviceStringTouchpad) { |
| 1676 event.sourceDevice = blink::WebGestureDeviceTouchpad; |
| 1677 } else if (device_string == kSourceDeviceStringTouchscreen) { |
| 1678 event.sourceDevice = blink::WebGestureDeviceTouchscreen; |
| 1679 } else { |
| 1680 args->ThrowError(); |
| 1681 return; |
| 1682 } |
| 1683 |
| 1655 event.x = x; | 1684 event.x = x; |
| 1656 event.y = y; | 1685 event.y = y; |
| 1657 event.globalX = event.x; | 1686 event.globalX = event.x; |
| 1658 event.globalY = event.y; | 1687 event.globalY = event.y; |
| 1659 | 1688 |
| 1660 event.data.flingStart.velocityX = velocity_x; | 1689 event.data.flingStart.velocityX = velocity_x; |
| 1661 event.data.flingStart.velocityY = velocity_y; | 1690 event.data.flingStart.velocityY = velocity_y; |
| 1662 event.timeStampSeconds = GetCurrentEventTimeSec(); | 1691 event.timeStampSeconds = GetCurrentEventTimeSec(); |
| 1663 | 1692 |
| 1664 if (force_layout_on_events_) | 1693 if (force_layout_on_events_) |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2030 // If the first argument is a string, it is to specify the device, otherwise | 2059 // If the first argument is a string, it is to specify the device, otherwise |
| 2031 // the device is assumed to be a touchscreen (since most tests were written | 2060 // the device is assumed to be a touchscreen (since most tests were written |
| 2032 // assuming this). | 2061 // assuming this). |
| 2033 event.sourceDevice = blink::WebGestureDeviceTouchscreen; | 2062 event.sourceDevice = blink::WebGestureDeviceTouchscreen; |
| 2034 if (args->PeekNext()->IsString()) { | 2063 if (args->PeekNext()->IsString()) { |
| 2035 std::string device_string; | 2064 std::string device_string; |
| 2036 if (!args->GetNext(&device_string)) { | 2065 if (!args->GetNext(&device_string)) { |
| 2037 args->ThrowError(); | 2066 args->ThrowError(); |
| 2038 return; | 2067 return; |
| 2039 } | 2068 } |
| 2040 if (device_string == "touchpad") { | 2069 if (device_string == kSourceDeviceStringTouchpad) { |
| 2041 event.sourceDevice = blink::WebGestureDeviceTouchpad; | 2070 event.sourceDevice = blink::WebGestureDeviceTouchpad; |
| 2042 } else if (device_string == "touchscreen") { | 2071 } else if (device_string == kSourceDeviceStringTouchscreen) { |
| 2043 event.sourceDevice = blink::WebGestureDeviceTouchscreen; | 2072 event.sourceDevice = blink::WebGestureDeviceTouchscreen; |
| 2044 } else { | 2073 } else { |
| 2045 args->ThrowError(); | 2074 args->ThrowError(); |
| 2046 return; | 2075 return; |
| 2047 } | 2076 } |
| 2048 } | 2077 } |
| 2049 | 2078 |
| 2050 double x; | 2079 double x; |
| 2051 double y; | 2080 double y; |
| 2052 if (!args->GetNext(&x) || !args->GetNext(&y)) { | 2081 if (!args->GetNext(&x) || !args->GetNext(&y)) { |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2459 | 2488 |
| 2460 bool EventSender::HandleInputEventOnViewOrPopup(const WebInputEvent& event) { | 2489 bool EventSender::HandleInputEventOnViewOrPopup(const WebInputEvent& event) { |
| 2461 if (WebPagePopup* popup = view_->pagePopup()) { | 2490 if (WebPagePopup* popup = view_->pagePopup()) { |
| 2462 if (!WebInputEvent::isKeyboardEventType(event.type)) | 2491 if (!WebInputEvent::isKeyboardEventType(event.type)) |
| 2463 return popup->handleInputEvent(event); | 2492 return popup->handleInputEvent(event); |
| 2464 } | 2493 } |
| 2465 return view_->handleInputEvent(event); | 2494 return view_->handleInputEvent(event); |
| 2466 } | 2495 } |
| 2467 | 2496 |
| 2468 } // namespace content | 2497 } // namespace content |
| OLD | NEW |