diff --git a/components/plugins/renderer/webview_plugin.cc b/components/plugins/renderer/webview_plugin.cc index 3aecdaf89384eb..76d9c8dc66228d 100644 --- a/components/plugins/renderer/webview_plugin.cc +++ b/components/plugins/renderer/webview_plugin.cc @@ -33,7 +33,6 @@ using blink::WebDragData; using blink::WebDragOperationsMask; using blink::WebFrameWidget; using blink::WebImage; -using blink::WebInputEvent; using blink::WebLocalFrame; using blink::WebMouseEvent; using blink::WebPlugin; @@ -205,19 +204,20 @@ void WebViewPlugin::UpdateFocus(bool focused, blink::WebFocusType focus_type) { } blink::WebInputEventResult WebViewPlugin::HandleInputEvent( - const WebInputEvent& event, + const blink::WebCoalescedInputEvent& coalesced_event, WebCursorInfo& cursor) { + const blink::WebInputEvent& event = coalesced_event.Event(); // For tap events, don't handle them. They will be converted to // mouse events later and passed to here. - if (event.GetType() == WebInputEvent::kGestureTap) + if (event.GetType() == blink::WebInputEvent::kGestureTap) return blink::WebInputEventResult::kNotHandled; // For LongPress events we return false, since otherwise the context menu will // be suppressed. https://crbug.com/482842 - if (event.GetType() == WebInputEvent::kGestureLongPress) + if (event.GetType() == blink::WebInputEvent::kGestureLongPress) return blink::WebInputEventResult::kNotHandled; - if (event.GetType() == WebInputEvent::kContextMenu) { + if (event.GetType() == blink::WebInputEvent::kContextMenu) { if (delegate_) { const WebMouseEvent& mouse_event = reinterpret_cast(event); diff --git a/components/plugins/renderer/webview_plugin.h b/components/plugins/renderer/webview_plugin.h index 44da6dea263b87..252ae790183704 100644 --- a/components/plugins/renderer/webview_plugin.h +++ b/components/plugins/renderer/webview_plugin.h @@ -101,7 +101,7 @@ class WebViewPlugin : public blink::WebPlugin, void UpdateVisibility(bool) override {} blink::WebInputEventResult HandleInputEvent( - const blink::WebInputEvent& event, + const blink::WebCoalescedInputEvent& event, blink::WebCursorInfo& cursor_info) override; void DidReceiveResponse(const blink::WebURLResponse& response) override; diff --git a/content/renderer/browser_plugin/browser_plugin.cc b/content/renderer/browser_plugin/browser_plugin.cc index 8f14c29aa7071f..eca5cc9c1664d0 100644 --- a/content/renderer/browser_plugin/browser_plugin.cc +++ b/content/renderer/browser_plugin/browser_plugin.cc @@ -29,6 +29,7 @@ #include "content/renderer/drop_data_builder.h" #include "content/renderer/render_thread_impl.h" #include "content/renderer/sad_plugin.h" +#include "third_party/WebKit/public/platform/WebCoalescedInputEvent.h" #include "third_party/WebKit/public/platform/WebGestureEvent.h" #include "third_party/WebKit/public/platform/WebInputEvent.h" #include "third_party/WebKit/public/platform/WebMouseWheelEvent.h" @@ -440,8 +441,9 @@ void BrowserPlugin::UpdateVisibility(bool visible) { } blink::WebInputEventResult BrowserPlugin::HandleInputEvent( - const blink::WebInputEvent& event, + const blink::WebCoalescedInputEvent& coalesced_event, blink::WebCursorInfo& cursor_info) { + const blink::WebInputEvent& event = coalesced_event.Event(); if (guest_crashed_ || !attached()) return blink::WebInputEventResult::kNotHandled; diff --git a/content/renderer/browser_plugin/browser_plugin.h b/content/renderer/browser_plugin/browser_plugin.h index 69f39d90a3aafb..b222390206f992 100644 --- a/content/renderer/browser_plugin/browser_plugin.h +++ b/content/renderer/browser_plugin/browser_plugin.h @@ -95,7 +95,7 @@ class CONTENT_EXPORT BrowserPlugin : void UpdateFocus(bool focused, blink::WebFocusType focus_type) override; void UpdateVisibility(bool visible) override; blink::WebInputEventResult HandleInputEvent( - const blink::WebInputEvent& event, + const blink::WebCoalescedInputEvent& event, blink::WebCursorInfo& cursor_info) override; bool HandleDragStatusUpdate(blink::WebDragStatus drag_status, const blink::WebDragData& drag_data, diff --git a/content/renderer/pepper/pepper_plugin_instance_impl.cc b/content/renderer/pepper/pepper_plugin_instance_impl.cc index d2e21155e1e718..bddc0aa5007dde 100644 --- a/content/renderer/pepper/pepper_plugin_instance_impl.cc +++ b/content/renderer/pepper/pepper_plugin_instance_impl.cc @@ -97,6 +97,7 @@ #include "printing/features/features.h" #include "skia/ext/platform_canvas.h" #include "third_party/WebKit/public/platform/URLConversion.h" +#include "third_party/WebKit/public/platform/WebCoalescedInputEvent.h" #include "third_party/WebKit/public/platform/WebCursorInfo.h" #include "third_party/WebKit/public/platform/WebFloatRect.h" #include "third_party/WebKit/public/platform/WebInputEvent.h" @@ -1115,6 +1116,22 @@ gfx::Rect PepperPluginInstanceImpl::GetCaretBounds() const { return caret; } +bool PepperPluginInstanceImpl::HandleCoalescedInputEvent( + const blink::WebCoalescedInputEvent& event, + WebCursorInfo* cursor_info) { + if (blink::WebInputEvent::IsTouchEventType(event.Event().GetType()) && + ((filtered_input_event_mask_ & PP_INPUTEVENT_CLASS_COALESCED_TOUCH) || + (input_event_mask_ & PP_INPUTEVENT_CLASS_COALESCED_TOUCH))) { + bool result = false; + for (size_t i = 0; i < event.CoalescedEventSize(); ++i) { + result |= HandleInputEvent(event.CoalescedEvent(i), cursor_info); + } + return result; + } else { + return HandleInputEvent(event.Event(), cursor_info); + } +} + bool PepperPluginInstanceImpl::HandleInputEvent( const blink::WebInputEvent& event, WebCursorInfo* cursor_info) { diff --git a/content/renderer/pepper/pepper_plugin_instance_impl.h b/content/renderer/pepper/pepper_plugin_instance_impl.h index 232a06770b5a6d..6a2b67ab857cce 100644 --- a/content/renderer/pepper/pepper_plugin_instance_impl.h +++ b/content/renderer/pepper/pepper_plugin_instance_impl.h @@ -72,6 +72,7 @@ struct PP_Point; class SkBitmap; namespace blink { +class WebCoalescedInputEvent; class WebInputEvent; class WebLayer; class WebMouseEvent; @@ -226,6 +227,8 @@ class CONTENT_EXPORT PepperPluginInstanceImpl bool full_frame, std::unique_ptr throttler); bool HandleDocumentLoad(const blink::WebURLResponse& response); + bool HandleCoalescedInputEvent(const blink::WebCoalescedInputEvent& event, + blink::WebCursorInfo* cursor_info); bool HandleInputEvent(const blink::WebInputEvent& event, blink::WebCursorInfo* cursor_info); PP_Var GetInstanceObject(v8::Isolate* isolate); diff --git a/content/renderer/pepper/pepper_webplugin_impl.cc b/content/renderer/pepper/pepper_webplugin_impl.cc index a188bd4d00cda4..3ff63b0c6e1b11 100644 --- a/content/renderer/pepper/pepper_webplugin_impl.cc +++ b/content/renderer/pepper/pepper_webplugin_impl.cc @@ -21,6 +21,7 @@ #include "content/renderer/render_frame_impl.h" #include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/shared_impl/var_tracker.h" +#include "third_party/WebKit/public/platform/WebCoalescedInputEvent.h" #include "third_party/WebKit/public/platform/WebPoint.h" #include "third_party/WebKit/public/platform/WebRect.h" #include "third_party/WebKit/public/platform/WebSize.h" @@ -210,13 +211,13 @@ void PepperWebPluginImpl::UpdateFocus(bool focused, void PepperWebPluginImpl::UpdateVisibility(bool visible) {} blink::WebInputEventResult PepperWebPluginImpl::HandleInputEvent( - const blink::WebInputEvent& event, + const blink::WebCoalescedInputEvent& coalesced_event, blink::WebCursorInfo& cursor_info) { // Re-entrancy may cause JS to try to execute script on the plugin before it // is fully initialized. See: crbug.com/715747. if (!instance_ || instance_->FlashIsFullscreenOrPending()) return blink::WebInputEventResult::kNotHandled; - return instance_->HandleInputEvent(event, &cursor_info) + return instance_->HandleCoalescedInputEvent(coalesced_event, &cursor_info) ? blink::WebInputEventResult::kHandledApplication : blink::WebInputEventResult::kNotHandled; } diff --git a/content/renderer/pepper/pepper_webplugin_impl.h b/content/renderer/pepper/pepper_webplugin_impl.h index 8327246bba09d4..bab8a8d384668c 100644 --- a/content/renderer/pepper/pepper_webplugin_impl.h +++ b/content/renderer/pepper/pepper_webplugin_impl.h @@ -51,7 +51,7 @@ class PepperWebPluginImpl : public blink::WebPlugin { void UpdateFocus(bool focused, blink::WebFocusType focus_type) override; void UpdateVisibility(bool visible) override; blink::WebInputEventResult HandleInputEvent( - const blink::WebInputEvent& event, + const blink::WebCoalescedInputEvent& event, blink::WebCursorInfo& cursor_info) override; void DidReceiveResponse(const blink::WebURLResponse& response) override; void DidReceiveData(const char* data, int data_length) override; diff --git a/content/shell/test_runner/test_plugin.cc b/content/shell/test_runner/test_plugin.cc index 0780042993edc6..bb7bdde33e1126 100644 --- a/content/shell/test_runner/test_plugin.cc +++ b/content/shell/test_runner/test_plugin.cc @@ -20,6 +20,7 @@ #include "content/shell/test_runner/web_test_delegate.h" #include "gpu/command_buffer/client/gles2_interface.h" #include "third_party/WebKit/public/platform/Platform.h" +#include "third_party/WebKit/public/platform/WebCoalescedInputEvent.h" #include "third_party/WebKit/public/platform/WebCompositorSupport.h" #include "third_party/WebKit/public/platform/WebGestureEvent.h" #include "third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h" @@ -534,8 +535,9 @@ GLuint TestPlugin::LoadProgram(const std::string& vertex_source, } blink::WebInputEventResult TestPlugin::HandleInputEvent( - const blink::WebInputEvent& event, + const blink::WebCoalescedInputEvent& coalesced_event, blink::WebCursorInfo& info) { + const blink::WebInputEvent& event = coalesced_event.Event(); const char* event_name = blink::WebInputEvent::GetName(event.GetType()); if (!strcmp(event_name, "") || !strcmp(event_name, "Undefined")) event_name = "unknown"; diff --git a/content/shell/test_runner/test_plugin.h b/content/shell/test_runner/test_plugin.h index 09c127c9dae19a..8e663ac78effb8 100644 --- a/content/shell/test_runner/test_plugin.h +++ b/content/shell/test_runner/test_plugin.h @@ -76,7 +76,7 @@ class TestPlugin : public blink::WebPlugin, public cc::TextureLayerClient { void UpdateFocus(bool focus, blink::WebFocusType focus_type) override {} void UpdateVisibility(bool visibility) override {} blink::WebInputEventResult HandleInputEvent( - const blink::WebInputEvent& event, + const blink::WebCoalescedInputEvent& event, blink::WebCursorInfo& info) override; bool HandleDragStatusUpdate(blink::WebDragStatus drag_status, const blink::WebDragData& data, diff --git a/ppapi/api/ppb_input_event.idl b/ppapi/api/ppb_input_event.idl index b737a2e4832b7b..25d2afb4f1c208 100644 --- a/ppapi/api/ppb_input_event.idl +++ b/ppapi/api/ppb_input_event.idl @@ -281,7 +281,16 @@ enum PP_InputEvent_Class { * * Request this input event class if you allow on-the-spot IME input. */ - PP_INPUTEVENT_CLASS_IME = 1 << 4 + PP_INPUTEVENT_CLASS_IME = 1 << 4, + + /** + * Identifies coalesced touch input events. + * + * Touch events are coalesced for each frame. By default, the coalesced touch + * events will be dropped. Request this input event class if you intend to + * handle all the touch events. + */ + PP_INPUTEVENT_CLASS_COALESCED_TOUCH = 1 << 5 }; /** diff --git a/ppapi/c/ppb_input_event.h b/ppapi/c/ppb_input_event.h index bd2c775e53bf29..75e66e423b8eaa 100644 --- a/ppapi/c/ppb_input_event.h +++ b/ppapi/c/ppb_input_event.h @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -/* From ppb_input_event.idl modified Thu Sep 1 12:40:05 2016. */ +/* From ppb_input_event.idl modified Wed Apr 26 13:40:13 2017. */ #ifndef PPAPI_C_PPB_INPUT_EVENT_H_ #define PPAPI_C_PPB_INPUT_EVENT_H_ @@ -290,7 +290,15 @@ typedef enum { * * Request this input event class if you allow on-the-spot IME input. */ - PP_INPUTEVENT_CLASS_IME = 1 << 4 + PP_INPUTEVENT_CLASS_IME = 1 << 4, + /** + * Identifies coalesced touch input events. + * + * Touch events are coalesced for each frame. By default, the coalesced touch + * events will be dropped. Request this input event class if you intend to + * handle all the touch events. + */ + PP_INPUTEVENT_CLASS_COALESCED_TOUCH = 1 << 5 } PP_InputEvent_Class; PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_Class, 4); /** diff --git a/third_party/WebKit/Source/core/events/TouchEvent.cpp b/third_party/WebKit/Source/core/events/TouchEvent.cpp index 481207383cb7f4..643ecf8b493014 100644 --- a/third_party/WebKit/Source/core/events/TouchEvent.cpp +++ b/third_party/WebKit/Source/core/events/TouchEvent.cpp @@ -36,6 +36,7 @@ #include "platform/Histogram.h" #include "platform/bindings/DOMWrapperWorld.h" #include "platform/bindings/ScriptState.h" +#include "public/platform/WebCoalescedInputEvent.h" namespace blink { @@ -196,13 +197,17 @@ void LogTouchTargetHistogram(EventTarget* event_target, static_cast(result)); } +// Helper function to get WebTouchEvent from WebCoalescedInputEvent. +const WebTouchEvent* GetWebTouchEvent(const WebCoalescedInputEvent& event) { + return static_cast(&event.Event()); +} } // namespace TouchEvent::TouchEvent() : default_prevented_before_current_target_(false), current_touch_action_(TouchAction::kTouchActionAuto) {} -TouchEvent::TouchEvent(const WebTouchEvent& event, +TouchEvent::TouchEvent(const WebCoalescedInputEvent& event, TouchList* touches, TouchList* target_touches, TouchList* changed_touches, @@ -215,11 +220,11 @@ TouchEvent::TouchEvent(const WebTouchEvent& event, : UIEventWithKeyState( type, true, - event.IsCancelable(), + GetWebTouchEvent(event)->IsCancelable(), view, 0, - static_cast(event.GetModifiers()), - TimeTicks::FromSeconds(event.TimeStampSeconds()), + static_cast(event.Event().GetModifiers()), + TimeTicks::FromSeconds(event.Event().TimeStampSeconds()), view ? view->GetInputDeviceCapabilities()->FiresTouchEvents(true) : nullptr), touches_(touches), @@ -227,7 +232,8 @@ TouchEvent::TouchEvent(const WebTouchEvent& event, changed_touches_(changed_touches), default_prevented_before_current_target_(false), current_touch_action_(current_touch_action) { - native_event_.reset(new WebTouchEvent(event)); + DCHECK(WebInputEvent::IsTouchEventType(event.Event().GetType())); + native_event_.reset(new WebCoalescedInputEvent(event)); } TouchEvent::TouchEvent(const AtomicString& type, @@ -267,7 +273,7 @@ void TouchEvent::preventDefault() { } if (native_event_ && - native_event_->dispatch_type == + GetWebTouchEvent(*native_event_)->dispatch_type == WebInputEvent:: kListenersForcedNonBlockingDueToMainThreadResponsiveness) { // Non blocking due to main thread responsiveness. @@ -338,7 +344,7 @@ void TouchEvent::preventDefault() { bool TouchEvent::IsTouchStartOrFirstTouchMove() const { if (!native_event_) return false; - return native_event_->touch_start_or_first_touch_move; + return GetWebTouchEvent(*native_event_)->touch_start_or_first_touch_move; } void TouchEvent::DoneDispatchingEventAtCurrentTarget() { diff --git a/third_party/WebKit/Source/core/events/TouchEvent.h b/third_party/WebKit/Source/core/events/TouchEvent.h index ecdf706bf7156e..72f52ad855a235 100644 --- a/third_party/WebKit/Source/core/events/TouchEvent.h +++ b/third_party/WebKit/Source/core/events/TouchEvent.h @@ -33,6 +33,7 @@ #include "core/events/TouchEventInit.h" #include "core/events/UIEventWithKeyState.h" #include "platform/graphics/TouchAction.h" +#include "public/platform/WebCoalescedInputEvent.h" #include "public/platform/WebTouchEvent.h" namespace blink { @@ -46,7 +47,7 @@ class CORE_EXPORT TouchEvent final : public UIEventWithKeyState { // We only initialize sourceCapabilities when we create TouchEvent from // EventHandler, null if it is from JavaScript. static TouchEvent* Create() { return new TouchEvent; } - static TouchEvent* Create(const WebTouchEvent& event, + static TouchEvent* Create(const WebCoalescedInputEvent& event, TouchList* touches, TouchList* target_touches, TouchList* changed_touches, @@ -84,13 +85,15 @@ class CORE_EXPORT TouchEvent final : public UIEventWithKeyState { EventDispatchMediator* CreateMediator() override; - const WebTouchEvent* NativeEvent() const { return native_event_.get(); } + const WebCoalescedInputEvent* NativeEvent() const { + return native_event_.get(); + } DECLARE_VIRTUAL_TRACE(); private: TouchEvent(); - TouchEvent(const WebTouchEvent&, + TouchEvent(const WebCoalescedInputEvent&, TouchList* touches, TouchList* target_touches, TouchList* changed_touches, @@ -110,7 +113,7 @@ class CORE_EXPORT TouchEvent final : public UIEventWithKeyState { // touchstart event is generated. It is used for UMA histograms. TouchAction current_touch_action_; - std::unique_ptr native_event_; + std::unique_ptr native_event_; }; class TouchEventDispatchMediator final : public EventDispatchMediator { diff --git a/third_party/WebKit/Source/core/events/TouchEventTest.cpp b/third_party/WebKit/Source/core/events/TouchEventTest.cpp index 779ece0645e6fd..5b45014908122a 100644 --- a/third_party/WebKit/Source/core/events/TouchEventTest.cpp +++ b/third_party/WebKit/Source/core/events/TouchEventTest.cpp @@ -64,8 +64,8 @@ class TouchEventTest : public testing::Test { TouchEvent* EventWithDispatchType(WebInputEvent::DispatchType dispatch_type) { WebTouchEvent web_touch_event(WebInputEvent::kTouchStart, 0, 0); web_touch_event.dispatch_type = dispatch_type; - return TouchEvent::Create(web_touch_event, nullptr, nullptr, nullptr, - "touchstart", &Window(), + return TouchEvent::Create(WebCoalescedInputEvent(web_touch_event), nullptr, + nullptr, nullptr, "touchstart", &Window(), TouchAction::kTouchActionAuto); } diff --git a/third_party/WebKit/Source/core/input/PointerEventManager.cpp b/third_party/WebKit/Source/core/input/PointerEventManager.cpp index 3008398da7fec1..745d0afcbeb624 100644 --- a/third_party/WebKit/Source/core/input/PointerEventManager.cpp +++ b/third_party/WebKit/Source/core/input/PointerEventManager.cpp @@ -318,7 +318,8 @@ WebInputEventResult PointerEventManager::HandleTouchEvents( DispatchTouchPointerEvents(event, coalesced_events, touch_infos); - return touch_event_manager_->HandleTouchEvent(event, touch_infos); + return touch_event_manager_->HandleTouchEvent(event, coalesced_events, + touch_infos); } void PointerEventManager::ComputeTouchTargets( diff --git a/third_party/WebKit/Source/core/input/TouchEventManager.cpp b/third_party/WebKit/Source/core/input/TouchEventManager.cpp index 7505b622e24935..846196fed56bd2 100644 --- a/third_party/WebKit/Source/core/input/TouchEventManager.cpp +++ b/third_party/WebKit/Source/core/input/TouchEventManager.cpp @@ -19,6 +19,7 @@ #include "platform/Histogram.h" #include "platform/wtf/CurrentTime.h" #include "platform/wtf/PtrUtil.h" +#include "public/platform/WebCoalescedInputEvent.h" #include "public/platform/WebTouchEvent.h" namespace blink { @@ -118,6 +119,7 @@ DEFINE_TRACE(TouchEventManager) { WebInputEventResult TouchEventManager::DispatchTouchEvents( const WebTouchEvent& event, + const Vector& coalesced_events, const HeapVector& touch_infos, bool all_touches_released) { // Build up the lists to use for the |touches|, |targetTouches| and @@ -201,6 +203,13 @@ WebInputEventResult TouchEventManager::DispatchTouchEvents( } WebInputEventResult event_result = WebInputEventResult::kNotHandled; + // First we construct the webcoalescedinputevent contains all the coalesced + // touch event. + std::vector coalesced_touches; + for (size_t i = 0; i < coalesced_events.size(); ++i) { + coalesced_touches.push_back(&coalesced_events[i]); + } + WebCoalescedInputEvent coalesced_event(event, coalesced_touches); // Now iterate through the |changedTouches| list and |m_targets| within it, // sending TouchEvents to the targets as required. @@ -213,7 +222,7 @@ WebInputEventResult TouchEventManager::DispatchTouchEvents( for (const auto& event_target : changed_touches[state].targets_) { EventTarget* touch_event_target = event_target; TouchEvent* touch_event = TouchEvent::Create( - event, touches, touches_by_target.at(touch_event_target), + coalesced_event, touches, touches_by_target.at(touch_event_target), changed_touches[state].touches_.Get(), event_name, touch_event_target->ToNode()->GetDocument().domWindow(), current_touch_action_); @@ -505,6 +514,7 @@ bool TouchEventManager::ReHitTestTouchPointsIfNeeded( WebInputEventResult TouchEventManager::HandleTouchEvent( const WebTouchEvent& event, + const Vector& coalesced_events, HeapVector& touch_infos) { if (!ReHitTestTouchPointsIfNeeded(event, touch_infos)) return WebInputEventResult::kNotHandled; @@ -517,7 +527,8 @@ WebInputEventResult TouchEventManager::HandleTouchEvent( all_touches_released = false; } - return DispatchTouchEvents(event, touch_infos, all_touches_released); + return DispatchTouchEvents(event, coalesced_events, touch_infos, + all_touches_released); } bool TouchEventManager::IsAnyTouchActive() const { diff --git a/third_party/WebKit/Source/core/input/TouchEventManager.h b/third_party/WebKit/Source/core/input/TouchEventManager.h index dc8654bb30bc2f..9b3ab7c67c42b7 100644 --- a/third_party/WebKit/Source/core/input/TouchEventManager.h +++ b/third_party/WebKit/Source/core/input/TouchEventManager.h @@ -10,6 +10,7 @@ #include "platform/graphics/TouchAction.h" #include "platform/wtf/Allocator.h" #include "platform/wtf/HashMap.h" +#include "platform/wtf/Vector.h" #include "public/platform/WebInputEventResult.h" #include "public/platform/WebTouchPoint.h" @@ -57,6 +58,7 @@ class CORE_EXPORT TouchEventManager // cannot be const as this function might change some of the properties in // TouchInfo objects. WebInputEventResult HandleTouchEvent(const WebTouchEvent&, + const Vector&, HeapVector&); // Resets the internal state of this object. @@ -70,6 +72,7 @@ class CORE_EXPORT TouchEventManager void SetAllPropertiesOfTouchInfos(HeapVector&); WebInputEventResult DispatchTouchEvents(const WebTouchEvent&, + const Vector&, const HeapVector&, bool all_touches_released); diff --git a/third_party/WebKit/Source/platform/exported/WebCoalescedInputEvent.cpp b/third_party/WebKit/Source/platform/exported/WebCoalescedInputEvent.cpp index b765e8790956f6..541e69e266fe72 100644 --- a/third_party/WebKit/Source/platform/exported/WebCoalescedInputEvent.cpp +++ b/third_party/WebKit/Source/platform/exported/WebCoalescedInputEvent.cpp @@ -92,6 +92,11 @@ WebCoalescedInputEvent::WebCoalescedInputEvent( coalesced_events_.push_back(MakeWebScopedInputEvent(*coalesced_event)); } +WebCoalescedInputEvent::WebCoalescedInputEvent( + const WebCoalescedInputEvent& event) + : WebCoalescedInputEvent(event.Event(), + event.GetCoalescedEventsPointers()) {} + WebCoalescedInputEvent::WebScopedInputEvent WebCoalescedInputEvent::MakeWebScopedInputEvent( const blink::WebInputEvent& event) { diff --git a/third_party/WebKit/Source/web/WebPluginContainerImpl.cpp b/third_party/WebKit/Source/web/WebPluginContainerImpl.cpp index 95bd292421266e..8e948606686516 100644 --- a/third_party/WebKit/Source/web/WebPluginContainerImpl.cpp +++ b/third_party/WebKit/Source/web/WebPluginContainerImpl.cpp @@ -86,6 +86,7 @@ #include "platform/wtf/Assertions.h" #include "public/platform/Platform.h" #include "public/platform/WebClipboard.h" +#include "public/platform/WebCoalescedInputEvent.h" #include "public/platform/WebCompositorSupport.h" #include "public/platform/WebCursorInfo.h" #include "public/platform/WebDragData.h" @@ -720,9 +721,9 @@ void WebPluginContainerImpl::HandleMouseEvent(MouseEvent* event) { FocusPlugin(); WebCursorInfo cursor_info; - if (web_plugin_ && - web_plugin_->HandleInputEvent(transformed_event, cursor_info) != - WebInputEventResult::kNotHandled) + if (web_plugin_ && web_plugin_->HandleInputEvent( + WebCoalescedInputEvent(transformed_event), + cursor_info) != WebInputEventResult::kNotHandled) event->SetDefaultHandled(); // A windowless plugin can change the cursor in response to a mouse move @@ -781,7 +782,8 @@ void WebPluginContainerImpl::HandleWheelEvent(WheelEvent* event) { translated_event.SetPositionInWidget(local_point.X(), local_point.Y()); WebCursorInfo cursor_info; - if (web_plugin_->HandleInputEvent(translated_event, cursor_info) != + if (web_plugin_->HandleInputEvent(WebCoalescedInputEvent(translated_event), + cursor_info) != WebInputEventResult::kNotHandled) event->SetDefaultHandled(); } @@ -818,11 +820,47 @@ void WebPluginContainerImpl::HandleKeyboardEvent(KeyboardEvent* event) { web_frame->Client()->HandleCurrentKeyboardEvent(); WebCursorInfo cursor_info; - if (web_plugin_->HandleInputEvent(web_event, cursor_info) != + if (web_plugin_->HandleInputEvent(WebCoalescedInputEvent(web_event), + cursor_info) != WebInputEventResult::kNotHandled) event->SetDefaultHandled(); } +WebTouchEvent WebPluginContainerImpl::TransformTouchEvent( + const WebInputEvent& event) { + DCHECK(blink::WebInputEvent::IsTouchEventType(event.GetType())); + const WebTouchEvent* touch_event = static_cast(&event); + WebTouchEvent transformed_event = touch_event->FlattenTransform(); + + for (unsigned i = 0; i < transformed_event.touches_length; ++i) { + WebFloatPoint absolute_location = transformed_event.touches[i].position; + + // Translate the root frame position to content coordinates. + if (parent_) { + absolute_location = parent_->RootFrameToContents(absolute_location); + } + + IntPoint local_point = + RoundedIntPoint(element_->GetLayoutObject()->AbsoluteToLocal( + absolute_location, kUseTransforms)); + transformed_event.touches[i].position.x = local_point.X(); + transformed_event.touches[i].position.y = local_point.Y(); + } + return transformed_event; +} + +WebCoalescedInputEvent WebPluginContainerImpl::TransformCoalescedTouchEvent( + const WebCoalescedInputEvent& coalesced_event) { + WebCoalescedInputEvent transformed_event( + TransformTouchEvent(coalesced_event.Event()), + std::vector()); + for (size_t i = 0; i < coalesced_event.CoalescedEventSize(); ++i) { + transformed_event.AddCoalescedEvent( + TransformTouchEvent(coalesced_event.CoalescedEvent(i))); + } + return transformed_event; +} + void WebPluginContainerImpl::HandleTouchEvent(TouchEvent* event) { switch (touch_event_request_type_) { case kTouchEventRequestTypeNone: @@ -834,23 +872,8 @@ void WebPluginContainerImpl::HandleTouchEvent(TouchEvent* event) { if (event->type() == EventTypeNames::touchstart) FocusPlugin(); - WebTouchEvent transformed_event = - event->NativeEvent()->FlattenTransform(); - - for (unsigned i = 0; i < transformed_event.touches_length; ++i) { - WebFloatPoint absolute_location = transformed_event.touches[i].position; - - // Translate the root frame position to content coordinates. - if (parent_) { - absolute_location = parent_->RootFrameToContents(absolute_location); - } - - IntPoint local_point = - RoundedIntPoint(element_->GetLayoutObject()->AbsoluteToLocal( - absolute_location, kUseTransforms)); - transformed_event.touches[i].position.x = local_point.X(); - transformed_event.touches[i].position.y = local_point.Y(); - } + WebCoalescedInputEvent transformed_event = + TransformCoalescedTouchEvent(*event->NativeEvent()); WebCursorInfo cursor_info; if (web_plugin_->HandleInputEvent(transformed_event, cursor_info) != @@ -884,7 +907,8 @@ void WebPluginContainerImpl::HandleGestureEvent(GestureEvent* event) { translated_event.y = local_point.Y(); WebCursorInfo cursor_info; - if (web_plugin_->HandleInputEvent(translated_event, cursor_info) != + if (web_plugin_->HandleInputEvent(WebCoalescedInputEvent(translated_event), + cursor_info) != WebInputEventResult::kNotHandled) { event->SetDefaultHandled(); return; @@ -900,7 +924,8 @@ void WebPluginContainerImpl::SynthesizeMouseEventIfPossible(TouchEvent* event) { return; WebCursorInfo cursor_info; - if (web_plugin_->HandleInputEvent(web_event, cursor_info) != + if (web_plugin_->HandleInputEvent(WebCoalescedInputEvent(web_event), + cursor_info) != WebInputEventResult::kNotHandled) event->SetDefaultHandled(); } diff --git a/third_party/WebKit/Source/web/WebPluginContainerImpl.h b/third_party/WebKit/Source/web/WebPluginContainerImpl.h index 542402ba28c8f8..ef1ac551dfa4c4 100644 --- a/third_party/WebKit/Source/web/WebPluginContainerImpl.h +++ b/third_party/WebKit/Source/web/WebPluginContainerImpl.h @@ -39,6 +39,8 @@ #include "platform/wtf/PassRefPtr.h" #include "platform/wtf/Vector.h" #include "platform/wtf/text/WTFString.h" +#include "public/platform/WebCoalescedInputEvent.h" +#include "public/platform/WebTouchEvent.h" #include "public/web/WebPluginContainer.h" #include "web/WebExport.h" @@ -191,6 +193,10 @@ class WEB_EXPORT WebPluginContainerImpl final WebPluginContainerImpl(HTMLPlugInElement*, WebPlugin*); + WebTouchEvent TransformTouchEvent(const WebInputEvent&); + WebCoalescedInputEvent TransformCoalescedTouchEvent( + const WebCoalescedInputEvent&); + void HandleMouseEvent(MouseEvent*); void HandleDragEvent(MouseEvent*); void HandleWheelEvent(WheelEvent*); diff --git a/third_party/WebKit/Source/web/tests/FakeWebPlugin.h b/third_party/WebKit/Source/web/tests/FakeWebPlugin.h index f5ce0fad9334b5..1dcc257661667a 100644 --- a/third_party/WebKit/Source/web/tests/FakeWebPlugin.h +++ b/third_party/WebKit/Source/web/tests/FakeWebPlugin.h @@ -35,8 +35,8 @@ namespace blink { +class WebCoalescedInputEvent; class WebDragData; -class WebInputEvent; class WebPluginContainer; class WebURLResponse; struct WebPluginParams; @@ -57,7 +57,7 @@ class FakeWebPlugin : public WebPlugin { bool is_visible) override {} void UpdateFocus(bool, WebFocusType) override {} void UpdateVisibility(bool) override {} - WebInputEventResult HandleInputEvent(const WebInputEvent&, + WebInputEventResult HandleInputEvent(const WebCoalescedInputEvent&, WebCursorInfo&) override { return WebInputEventResult::kNotHandled; } diff --git a/third_party/WebKit/Source/web/tests/WebPluginContainerTest.cpp b/third_party/WebKit/Source/web/tests/WebPluginContainerTest.cpp index e96b94a3003c9d..ec344c4a0f5f1f 100644 --- a/third_party/WebKit/Source/web/tests/WebPluginContainerTest.cpp +++ b/third_party/WebKit/Source/web/tests/WebPluginContainerTest.cpp @@ -451,8 +451,11 @@ class EventTestPlugin : public FakeWebPlugin { explicit EventTestPlugin(const WebPluginParams& params) : FakeWebPlugin(params), last_event_type_(WebInputEvent::kUndefined) {} - WebInputEventResult HandleInputEvent(const WebInputEvent& event, - WebCursorInfo&) override { + WebInputEventResult HandleInputEvent( + const WebCoalescedInputEvent& coalesced_event, + WebCursorInfo&) override { + const WebInputEvent& event = coalesced_event.Event(); + coalesced_event_count_ = coalesced_event.CoalescedEventSize(); last_event_type_ = event.GetType(); if (WebInputEvent::IsMouseEventType(event.GetType()) || event.GetType() == WebInputEvent::kMouseWheel) { @@ -479,7 +482,10 @@ class EventTestPlugin : public FakeWebPlugin { void ClearLastEventType() { last_event_type_ = WebInputEvent::kUndefined; } + size_t GetCoalescedEventCount() { return coalesced_event_count_; } + private: + size_t coalesced_event_count_; WebInputEvent::Type last_event_type_; IntPoint last_event_location_; }; @@ -611,6 +617,64 @@ TEST_F(WebPluginContainerTest, TouchEventScrolled) { EXPECT_EQ(rect.height / 2, test_plugin->GetLastEventLocation().Y()); } +TEST_F(WebPluginContainerTest, TouchEventScrolledWithCoalescedTouches) { + RegisterMockedURL("plugin_scroll.html"); + CustomPluginWebFrameClient + plugin_web_frame_client; // Must outlive webViewHelper. + FrameTestHelpers::WebViewHelper web_view_helper; + WebView* web_view = web_view_helper.InitializeAndLoad( + base_url_ + "plugin_scroll.html", true, &plugin_web_frame_client); + DCHECK(web_view); + web_view->GetSettings()->SetPluginsEnabled(true); + web_view->Resize(WebSize(300, 300)); + web_view->UpdateAllLifecyclePhases(); + RunPendingTasks(); + web_view->SmoothScroll(0, 200, 0); + web_view->UpdateAllLifecyclePhases(); + RunPendingTasks(); + + WebElement plugin_container_one_element = + web_view->MainFrame()->GetDocument().GetElementById( + WebString::FromUTF8("scrolled-plugin")); + plugin_container_one_element.PluginContainer()->RequestTouchEventType( + WebPluginContainer::kTouchEventRequestTypeRaw); + WebPlugin* plugin = static_cast( + plugin_container_one_element.PluginContainer()) + ->Plugin(); + EventTestPlugin* test_plugin = static_cast(plugin); + + WebTouchEvent event(WebInputEvent::kTouchStart, WebInputEvent::kNoModifiers, + WebInputEvent::kTimeStampForTesting); + WebRect rect = plugin_container_one_element.BoundsInViewport(); + event.touches_length = 1; + event.touches[0].state = WebTouchPoint::kStatePressed; + event.touches[0].position = + WebFloatPoint(rect.x + rect.width / 2, rect.y + rect.height / 2); + + WebCoalescedInputEvent coalesced_event(event); + + WebTouchEvent c_event(WebInputEvent::kTouchMove, WebInputEvent::kNoModifiers, + WebInputEvent::kTimeStampForTesting); + c_event.touches_length = 1; + c_event.touches[0].state = WebTouchPoint::kStatePressed; + c_event.touches[0].position = + WebFloatPoint(rect.x + rect.width / 2 + 1, rect.y + rect.height / 2 + 1); + + coalesced_event.AddCoalescedEvent(c_event); + c_event.touches[0].position = + WebFloatPoint(rect.x + rect.width / 2 + 2, rect.y + rect.height / 2 + 2); + coalesced_event.AddCoalescedEvent(c_event); + + web_view->HandleInputEvent(coalesced_event); + RunPendingTasks(); + + EXPECT_EQ(static_cast(3), + test_plugin->GetCoalescedEventCount()); + EXPECT_EQ(WebInputEvent::kTouchStart, test_plugin->GetLastInputEventType()); + EXPECT_EQ(rect.width / 2, test_plugin->GetLastEventLocation().X()); + EXPECT_EQ(rect.height / 2, test_plugin->GetLastEventLocation().Y()); +} + TEST_F(WebPluginContainerTest, MouseWheelEventScrolled) { RegisterMockedURL("plugin_scroll.html"); CustomPluginWebFrameClient diff --git a/third_party/WebKit/public/platform/WebCoalescedInputEvent.h b/third_party/WebKit/public/platform/WebCoalescedInputEvent.h index 966e3788128cfe..ee7e7996550573 100644 --- a/third_party/WebKit/public/platform/WebCoalescedInputEvent.h +++ b/third_party/WebKit/public/platform/WebCoalescedInputEvent.h @@ -20,6 +20,8 @@ class BLINK_PLATFORM_EXPORT WebCoalescedInputEvent { explicit WebCoalescedInputEvent(const WebInputEvent&); WebCoalescedInputEvent(const WebInputEvent&, const std::vector&); + // Copy constructor to deep copy the event. + WebCoalescedInputEvent(const WebCoalescedInputEvent&); WebInputEvent* EventPointer(); void AddCoalescedEvent(const blink::WebInputEvent&); diff --git a/third_party/WebKit/public/web/WebPlugin.h b/third_party/WebKit/public/web/WebPlugin.h index dff5299781a614..c5cbb9189ab822 100644 --- a/third_party/WebKit/public/web/WebPlugin.h +++ b/third_party/WebKit/public/web/WebPlugin.h @@ -43,8 +43,8 @@ namespace blink { +class WebCoalescedInputEvent; class WebDragData; -class WebInputEvent; class WebPluginContainer; class WebURLResponse; struct WebCompositionUnderline; @@ -117,7 +117,7 @@ class WebPlugin { virtual void UpdateVisibility(bool) = 0; - virtual WebInputEventResult HandleInputEvent(const WebInputEvent&, + virtual WebInputEventResult HandleInputEvent(const WebCoalescedInputEvent&, WebCursorInfo&) = 0; virtual bool HandleDragStatusUpdate(WebDragStatus,