Skip to content

Commit

Permalink
Keep track of coalesced events in main thread event queue
Browse files Browse the repository at this point in the history
This CL keeps track of the coaleced events in the
main thread event queue and passes them to Blink. So
that Blink later exposes them to the js through
PointerEvent.getCoalescedEvents API.

BUG=680678

Review-Url: https://codereview.chromium.org/2621303004
Cr-Commit-Position: refs/heads/master@{#445528}
  • Loading branch information
NavidZ authored and Commit bot committed Jan 23, 2017
1 parent 22632c5 commit 5d85965
Show file tree
Hide file tree
Showing 51 changed files with 371 additions and 239 deletions.
5 changes: 3 additions & 2 deletions components/plugins/renderer/webview_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "content/public/renderer/render_view.h"
#include "gin/converter.h"
#include "skia/ext/platform_canvas.h"
#include "third_party/WebKit/public/platform/WebInputEvent.h"
#include "third_party/WebKit/public/platform/WebCoalescedInputEvent.h"
#include "third_party/WebKit/public/platform/WebURL.h"
#include "third_party/WebKit/public/platform/WebURLResponse.h"
#include "third_party/WebKit/public/web/WebDocument.h"
Expand Down Expand Up @@ -219,7 +219,8 @@ blink::WebInputEventResult WebViewPlugin::handleInputEvent(
return blink::WebInputEventResult::HandledSuppressed;
}
current_cursor_ = cursor;
blink::WebInputEventResult handled = web_view()->handleInputEvent(event);
blink::WebInputEventResult handled =
web_view()->handleInputEvent(blink::WebCoalescedInputEvent(event));
cursor = current_cursor_;

return handled;
Expand Down
7 changes: 4 additions & 3 deletions components/test_runner/event_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
#include "gin/handle.h"
#include "gin/object_template_builder.h"
#include "gin/wrappable.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/WebKeyboardEvent.h"
#include "third_party/WebKit/public/platform/WebPointerProperties.h"
#include "third_party/WebKit/public/platform/WebString.h"
Expand Down Expand Up @@ -2808,15 +2808,16 @@ WebInputEventResult EventSender::HandleInputEventOnViewOrPopup(
raw_event, delegate()->GetWindowToViewportScale());
const WebInputEvent* popup_friendly_event =
scaled_event.get() ? scaled_event.get() : &raw_event;
return popup->handleInputEvent(*popup_friendly_event);
return popup->handleInputEvent(
blink::WebCoalescedInputEvent(*popup_friendly_event));
}

std::unique_ptr<WebInputEvent> widget_event =
TransformScreenToWidgetCoordinates(raw_event);
const WebInputEvent* event =
widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get())
: &raw_event;
return widget()->handleInputEvent(*event);
return widget()->handleInputEvent(blink::WebCoalescedInputEvent(*event));
}

void EventSender::SendGesturesForMouseWheelEvent(
Expand Down
4 changes: 2 additions & 2 deletions components/test_runner/text_input_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "gin/handle.h"
#include "gin/object_template_builder.h"
#include "gin/wrappable.h"
#include "third_party/WebKit/public/platform/WebInputEvent.h"
#include "third_party/WebKit/public/platform/WebCoalescedInputEvent.h"
#include "third_party/WebKit/public/platform/WebInputEventResult.h"
#include "third_party/WebKit/public/platform/WebKeyboardEvent.h"
#include "third_party/WebKit/public/web/WebCompositionUnderline.h"
Expand Down Expand Up @@ -301,7 +301,7 @@ void TextInputController::SetComposition(const std::string& text) {
ui::EventTimeStampToSeconds(ui::EventTimeForNow()));

key_down.windowsKeyCode = 0xE5; // VKEY_PROCESSKEY
view()->handleInputEvent(key_down);
view()->handleInputEvent(blink::WebCoalescedInputEvent(key_down));

// The value returned by std::string::length() may not correspond to the
// actual number of encoded characters in sequences of multi-byte or
Expand Down
5 changes: 3 additions & 2 deletions content/browser/renderer_host/input/input_router_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,9 @@ bool InputRouterImpl::OfferToRenderer(const WebInputEvent& input_event,
const WebInputEvent* event_to_send =
event_in_viewport ? event_in_viewport.get() : &input_event;

if (Send(new InputMsg_HandleInputEvent(routing_id(), event_to_send,
latency_info, dispatch_type))) {
if (Send(new InputMsg_HandleInputEvent(
routing_id(), event_to_send, std::vector<IPC::WebInputEventPointer>(),
latency_info, dispatch_type))) {
// Ack messages for ignored ack event types should never be sent by the
// renderer. Consequently, such event types should not affect event time
// or in-flight event count metrics.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,7 @@ void CheckLatencyInfoComponentInMessage(RenderWidgetHostProcess* process,
EXPECT_TRUE(InputMsg_HandleInputEvent::Read(message, &params));

const WebInputEvent* event = std::get<0>(params);
ui::LatencyInfo latency_info = std::get<1>(params);
ui::LatencyInfo latency_info = std::get<2>(params);

EXPECT_TRUE(event->type() == expected_type);
EXPECT_TRUE(latency_info.FindLatency(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ class RenderWidgetHostViewAuraTest : public testing::Test {
return;
}

InputEventDispatchType dispatch_type = std::get<2>(params);
InputEventDispatchType dispatch_type = std::get<3>(params);
if (dispatch_type == InputEventDispatchType::DISPATCH_TYPE_NON_BLOCKING)
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,8 @@ bool ZoomDisabledForPinchUpdateMessage() {
break;
}
DCHECK(message);
std::tuple<IPC::WebInputEventPointer, ui::LatencyInfo,
std::tuple<IPC::WebInputEventPointer,
std::vector<IPC::WebInputEventPointer>, ui::LatencyInfo,
InputEventDispatchType>
data;
InputMsg_HandleInputEvent::Read(message, &data);
Expand Down
15 changes: 11 additions & 4 deletions content/common/input/event_with_latency_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace content {
ScopedWebInputEventWithLatencyInfo::ScopedWebInputEventWithLatencyInfo(
blink::WebScopedInputEvent event,
const ui::LatencyInfo& latency_info)
: event_(std::move(event)), latency_(latency_info) {}
: event_(new blink::WebCoalescedInputEvent(std::move(event))),
latency_(latency_info) {}

ScopedWebInputEventWithLatencyInfo::~ScopedWebInputEventWithLatencyInfo() {}

Expand All @@ -29,8 +30,9 @@ void ScopedWebInputEventWithLatencyInfo::CoalesceWith(
// New events get coalesced into older events, and the newer timestamp
// should always be preserved.
const double time_stamp_seconds = other.event().timeStampSeconds();
ui::Coalesce(other.event(), event_.get());
event_->setTimeStampSeconds(time_stamp_seconds);
ui::Coalesce(other.event(), event_->eventPointer());
event_->eventPointer()->setTimeStampSeconds(time_stamp_seconds);
event_->addCoalescedEvent(other.event());

// When coalescing two input events, we keep the oldest LatencyInfo
// since it will represent the longest latency.
Expand All @@ -39,10 +41,15 @@ void ScopedWebInputEventWithLatencyInfo::CoalesceWith(
}

const blink::WebInputEvent& ScopedWebInputEventWithLatencyInfo::event() const {
return *event_;
return event_->event();
}

blink::WebInputEvent& ScopedWebInputEventWithLatencyInfo::event() {
return *event_->eventPointer();
}

const blink::WebCoalescedInputEvent&
ScopedWebInputEventWithLatencyInfo::coalesced_event() const {
return *event_;
}

Expand Down
3 changes: 2 additions & 1 deletion content/common/input/event_with_latency_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ class ScopedWebInputEventWithLatencyInfo {
WARN_UNUSED_RESULT;

const blink::WebInputEvent& event() const;
const blink::WebCoalescedInputEvent& coalesced_event() const;
blink::WebInputEvent& event();
const ui::LatencyInfo latencyInfo() const { return latency_; }

void CoalesceWith(const ScopedWebInputEventWithLatencyInfo& other);

private:
blink::WebScopedInputEvent event_;
blink::WebScopedCoalescedInputEvent event_;
mutable ui::LatencyInfo latency_;
};

Expand Down
14 changes: 9 additions & 5 deletions content/common/input_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,15 @@ IPC_STRUCT_TRAITS_BEGIN(content::InputEventAck)
IPC_STRUCT_TRAITS_MEMBER(unique_touch_event_id)
IPC_STRUCT_TRAITS_END()

// Sends an input event to the render widget.
IPC_MESSAGE_ROUTED3(InputMsg_HandleInputEvent,
IPC::WebInputEventPointer /* event */,
ui::LatencyInfo /* latency_info */,
content::InputEventDispatchType)
// Sends an input event to the render widget. The input event in general
// contains a list of coalesced events and one event that is representative of
// all those events (https://w3c.github.io/pointerevents/extension.html).
IPC_MESSAGE_ROUTED4(
InputMsg_HandleInputEvent,
IPC::WebInputEventPointer /* event */,
std::vector<IPC::WebInputEventPointer> /* coalesced events */,
ui::LatencyInfo /* latency_info */,
content::InputEventDispatchType)

// Sends the cursor visibility state to the render widget.
IPC_MESSAGE_ROUTED1(InputMsg_CursorVisibilityChange,
Expand Down
14 changes: 7 additions & 7 deletions content/public/test/render_view_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,15 @@ void RenderViewTest::SendWebKeyboardEvent(
const blink::WebKeyboardEvent& key_event) {
RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_);
impl->OnMessageReceived(InputMsg_HandleInputEvent(
0, &key_event, ui::LatencyInfo(),
0, &key_event, std::vector<const WebInputEvent*>(), ui::LatencyInfo(),
InputEventDispatchType::DISPATCH_TYPE_BLOCKING));
}

void RenderViewTest::SendWebMouseEvent(
const blink::WebMouseEvent& mouse_event) {
RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_);
impl->OnMessageReceived(InputMsg_HandleInputEvent(
0, &mouse_event, ui::LatencyInfo(),
0, &mouse_event, std::vector<const WebInputEvent*>(), ui::LatencyInfo(),
InputEventDispatchType::DISPATCH_TYPE_BLOCKING));
}

Expand Down Expand Up @@ -462,11 +462,11 @@ void RenderViewTest::SimulatePointClick(const gfx::Point& point) {
mouse_event.clickCount = 1;
RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_);
impl->OnMessageReceived(InputMsg_HandleInputEvent(
0, &mouse_event, ui::LatencyInfo(),
0, &mouse_event, std::vector<const WebInputEvent*>(), ui::LatencyInfo(),
InputEventDispatchType::DISPATCH_TYPE_BLOCKING));
mouse_event.setType(WebInputEvent::MouseUp);
impl->OnMessageReceived(InputMsg_HandleInputEvent(
0, &mouse_event, ui::LatencyInfo(),
0, &mouse_event, std::vector<const WebInputEvent*>(), ui::LatencyInfo(),
InputEventDispatchType::DISPATCH_TYPE_BLOCKING));
}

Expand All @@ -489,11 +489,11 @@ void RenderViewTest::SimulatePointRightClick(const gfx::Point& point) {
mouse_event.clickCount = 1;
RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_);
impl->OnMessageReceived(InputMsg_HandleInputEvent(
0, &mouse_event, ui::LatencyInfo(),
0, &mouse_event, std::vector<const WebInputEvent*>(), ui::LatencyInfo(),
InputEventDispatchType::DISPATCH_TYPE_BLOCKING));
mouse_event.setType(WebInputEvent::MouseUp);
impl->OnMessageReceived(InputMsg_HandleInputEvent(
0, &mouse_event, ui::LatencyInfo(),
0, &mouse_event, std::vector<const WebInputEvent*>(), ui::LatencyInfo(),
InputEventDispatchType::DISPATCH_TYPE_BLOCKING));
}

Expand All @@ -509,7 +509,7 @@ void RenderViewTest::SimulateRectTap(const gfx::Rect& rect) {
gesture_event.sourceDevice = blink::WebGestureDeviceTouchpad;
RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_);
impl->OnMessageReceived(InputMsg_HandleInputEvent(
0, &gesture_event, ui::LatencyInfo(),
0, &gesture_event, std::vector<const WebInputEvent*>(), ui::LatencyInfo(),
InputEventDispatchType::DISPATCH_TYPE_BLOCKING));
impl->FocusChangeComplete();
}
Expand Down
3 changes: 2 additions & 1 deletion content/renderer/gpu/gpu_benchmarking_extension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ bool BeginSmoothScroll(v8::Isolate* isolate,
ui::EventTimeStampToSeconds(ui::EventTimeForNow()));
mouseMove.x = (contentRect.x + contentRect.width / 2) * page_scale_factor;
mouseMove.y = (contentRect.y + contentRect.height / 2) * page_scale_factor;
context.web_view()->handleInputEvent(mouseMove);
context.web_view()->handleInputEvent(
blink::WebCoalescedInputEvent(mouseMove));
context.web_view()->setCursorVisibilityState(true);
}

Expand Down
1 change: 1 addition & 0 deletions content/renderer/idle_user_detector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ bool IdleUserDetector::OnMessageReceived(const IPC::Message& message) {

void IdleUserDetector::OnHandleInputEvent(
const blink::WebInputEvent* event,
const std::vector<const blink::WebInputEvent*>& coalesced_events,
const ui::LatencyInfo& latency_info,
InputEventDispatchType dispatch_type) {
if (GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) {
Expand Down
10 changes: 7 additions & 3 deletions content/renderer/idle_user_detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "content/common/input/input_event_dispatch_type.h"
#include "content/public/renderer/render_view_observer.h"

#include <vector>

namespace blink {
class WebInputEvent;
}
Expand All @@ -31,9 +33,11 @@ class IdleUserDetector : public RenderViewObserver {
bool OnMessageReceived(const IPC::Message& message) override;
void OnDestruct() override;

void OnHandleInputEvent(const blink::WebInputEvent* event,
const ui::LatencyInfo& latency_info,
InputEventDispatchType dispatch_type);
void OnHandleInputEvent(
const blink::WebInputEvent* event,
const std::vector<const blink::WebInputEvent*>& coalesced_events,
const ui::LatencyInfo& latency_info,
InputEventDispatchType dispatch_type);

DISALLOW_COPY_AND_ASSIGN(IdleUserDetector);
};
Expand Down
11 changes: 6 additions & 5 deletions content/renderer/input/input_event_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ void InputEventFilter::ForwardToHandler(const IPC::Message& message,
return;
blink::WebScopedInputEvent event =
ui::WebInputEventTraits::Clone(*std::get<0>(params));
ui::LatencyInfo latency_info = std::get<1>(params);
InputEventDispatchType dispatch_type = std::get<2>(params);
ui::LatencyInfo latency_info = std::get<2>(params);
InputEventDispatchType dispatch_type = std::get<3>(params);

DCHECK(event);
DCHECK(dispatch_type == DISPATCH_TYPE_BLOCKING ||
Expand Down Expand Up @@ -287,13 +287,14 @@ void InputEventFilter::SendMessageOnIOThread(

void InputEventFilter::HandleEventOnMainThread(
int routing_id,
const blink::WebInputEvent* event,
const blink::WebCoalescedInputEvent* event,
const ui::LatencyInfo& latency_info,
InputEventDispatchType dispatch_type) {
TRACE_EVENT_INSTANT0("input", "InputEventFilter::HandlEventOnMainThread",
TRACE_EVENT_SCOPE_THREAD);
IPC::Message new_msg =
InputMsg_HandleInputEvent(routing_id, event, latency_info, dispatch_type);
IPC::Message new_msg = InputMsg_HandleInputEvent(
routing_id, &event->event(), event->getCoalescedEventsPointers(),
latency_info, dispatch_type);
main_listener_.Run(new_msg);
}

Expand Down
2 changes: 1 addition & 1 deletion content/renderer/input/input_event_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class CONTENT_EXPORT InputEventFilter : public InputHandlerManagerClient,

// MainThreadEventQueueClient methods:
void HandleEventOnMainThread(int routing_id,
const blink::WebInputEvent* event,
const blink::WebCoalescedInputEvent* event,
const ui::LatencyInfo& latency,
InputEventDispatchType dispatch_type) override;
// Send an InputEventAck IPC message. |touch_event_id| represents
Expand Down
Loading

0 comments on commit 5d85965

Please sign in to comment.