Skip to content

Commit

Permalink
Support Coalesced Touch in ppapi
Browse files Browse the repository at this point in the history
This patch route coalesced events through webplugin interface. The
coalesced touch events will be dispatched to nacl when client request
PP_INPUTEVENT_CLASS_COALESCED_TOUCH.

BUG=720529

Review-Url: https://codereview.chromium.org/2844823002
Cr-Commit-Position: refs/heads/master@{#471909}
  • Loading branch information
Catramen authored and Commit bot committed May 15, 2017
1 parent 9a68250 commit 8e72a1b
Show file tree
Hide file tree
Showing 25 changed files with 230 additions and 62 deletions.
10 changes: 5 additions & 5 deletions components/plugins/renderer/webview_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<const WebMouseEvent&>(event);
Expand Down
2 changes: 1 addition & 1 deletion components/plugins/renderer/webview_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion content/renderer/browser_plugin/browser_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion content/renderer/browser_plugin/browser_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions content/renderer/pepper/pepper_plugin_instance_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions content/renderer/pepper/pepper_plugin_instance_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct PP_Point;
class SkBitmap;

namespace blink {
class WebCoalescedInputEvent;
class WebInputEvent;
class WebLayer;
class WebMouseEvent;
Expand Down Expand Up @@ -226,6 +227,8 @@ class CONTENT_EXPORT PepperPluginInstanceImpl
bool full_frame,
std::unique_ptr<PluginInstanceThrottlerImpl> 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);
Expand Down
5 changes: 3 additions & 2 deletions content/renderer/pepper/pepper_webplugin_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion content/renderer/pepper/pepper_webplugin_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion content/shell/test_runner/test_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion content/shell/test_runner/test_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 10 additions & 1 deletion ppapi/api/ppb_input_event.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

/**
Expand Down
12 changes: 10 additions & 2 deletions ppapi/c/ppb_input_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down Expand Up @@ -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);
/**
Expand Down
20 changes: 13 additions & 7 deletions third_party/WebKit/Source/core/events/TouchEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -196,13 +197,17 @@ void LogTouchTargetHistogram(EventTarget* event_target,
static_cast<TouchTargetAndDispatchResultType>(result));
}

// Helper function to get WebTouchEvent from WebCoalescedInputEvent.
const WebTouchEvent* GetWebTouchEvent(const WebCoalescedInputEvent& event) {
return static_cast<const WebTouchEvent*>(&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,
Expand All @@ -215,19 +220,20 @@ TouchEvent::TouchEvent(const WebTouchEvent& event,
: UIEventWithKeyState(
type,
true,
event.IsCancelable(),
GetWebTouchEvent(event)->IsCancelable(),
view,
0,
static_cast<WebInputEvent::Modifiers>(event.GetModifiers()),
TimeTicks::FromSeconds(event.TimeStampSeconds()),
static_cast<WebInputEvent::Modifiers>(event.Event().GetModifiers()),
TimeTicks::FromSeconds(event.Event().TimeStampSeconds()),
view ? view->GetInputDeviceCapabilities()->FiresTouchEvents(true)
: nullptr),
touches_(touches),
target_touches_(target_touches),
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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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() {
Expand Down
11 changes: 7 additions & 4 deletions third_party/WebKit/Source/core/events/TouchEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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<WebTouchEvent> native_event_;
std::unique_ptr<WebCoalescedInputEvent> native_event_;
};

class TouchEventDispatchMediator final : public EventDispatchMediator {
Expand Down
4 changes: 2 additions & 2 deletions third_party/WebKit/Source/core/events/TouchEventTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion third_party/WebKit/Source/core/input/PointerEventManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading

0 comments on commit 8e72a1b

Please sign in to comment.