From ba38c72a21a6ebde6abf8f19c00c5c4423534106 Mon Sep 17 00:00:00 2001 From: Dave Tapuska Date: Mon, 6 Jan 2020 23:48:47 +0000 Subject: [PATCH] Modernize WebInputEvent Reland 547be4072d5ef59ba1eea93aa0ac6a294f1660d7. It was previously reverted because CFI bot started to fail. That was fixed here: crrev.com/2708646cd1a812a84200a1db6208732fe20d49b8 Since the class is no longer memcopied between processes we can use virtuals. - Add virtual destructor - Add pure virtual cloning - Remove memset - Remove size attribute BUG=836826 TBR=nasko@chromium.org,bokan@chromium.org,jbroman@chromium.org Change-Id: I091683184ada8d693c11f8cb7aff9dae3eaf93e4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1988849 Reviewed-by: Dave Tapuska Commit-Queue: Dave Tapuska Cr-Commit-Position: refs/heads/master@{#728694} --- .../devtools/protocol/input_handler.cc | 2 +- .../renderer_host/input/input_router_impl.cc | 3 +- .../renderer_host/render_widget_targeter.cc | 2 +- .../site_per_process_hit_test_browsertest.cc | 2 +- .../common/input/event_with_latency_info.h | 3 - content/common/input/input_event.cc | 3 +- .../browser/native_web_keyboard_event.h | 2 +- .../renderer/input/input_event_prediction.cc | 3 +- .../input/main_thread_event_queue_unittest.cc | 33 +--------- .../input/widget_input_handler_manager.cc | 3 +- third_party/blink/common/BUILD.gn | 1 + .../blink/common/input/web_gesture_event.cc | 4 ++ .../blink/common/input/web_keyboard_event.cc | 13 ++++ .../blink/common/input/web_mouse_event.cc | 6 +- .../common/input/web_mouse_wheel_event.cc | 4 ++ .../blink/common/input/web_pointer_event.cc | 12 ++-- .../blink/common/input/web_touch_event.cc | 4 ++ .../public/common/input/web_gesture_event.h | 17 +++--- .../public/common/input/web_input_event.h | 53 ++++------------ .../public/common/input/web_keyboard_event.h | 24 ++++---- .../public/common/input/web_mouse_event.h | 31 +++------- .../common/input/web_mouse_wheel_event.h | 60 ++++++------------- .../public/common/input/web_pointer_event.h | 24 ++++---- .../common/input/web_pointer_properties.h | 18 ++---- .../public/common/input/web_touch_event.h | 22 +++---- .../public/common/input/web_touch_point.h | 16 ++--- .../platform/web_coalesced_input_event.h | 7 +-- .../core/events/web_input_event_conversion.cc | 4 +- .../exported/web_coalesced_input_event.cc | 40 ------------- .../main_thread_scheduler_impl_unittest.cc | 7 ++- .../blink/compositor_thread_event_queue.cc | 4 +- ui/events/blink/event_with_callback.cc | 2 +- .../blink/input_handler_proxy_unittest.cc | 8 +-- ui/events/blink/scroll_predictor_unittest.cc | 10 ++-- ui/events/blink/web_input_event_traits.cc | 35 ----------- ui/events/blink/web_input_event_traits.h | 8 +-- 36 files changed, 164 insertions(+), 326 deletions(-) create mode 100644 third_party/blink/common/input/web_keyboard_event.cc diff --git a/content/browser/devtools/protocol/input_handler.cc b/content/browser/devtools/protocol/input_handler.cc index 3d20f3d4d410..c7a95973d938 100644 --- a/content/browser/devtools/protocol/input_handler.cc +++ b/content/browser/devtools/protocol/input_handler.cc @@ -672,7 +672,7 @@ void InputHandler::DispatchMouseEvent( modifiers |= button_modifiers; base::TimeTicks timestamp = GetEventTimeTicks(maybe_timestamp); - std::unique_ptr mouse_event; + std::unique_ptr mouse_event; blink::WebMouseWheelEvent* wheel_event = nullptr; if (type == blink::WebInputEvent::kMouseWheel) { diff --git a/content/browser/renderer_host/input/input_router_impl.cc b/content/browser/renderer_host/input/input_router_impl.cc index 44c32d2368ee..4b3e15112bdb 100644 --- a/content/browser/renderer_host/input/input_router_impl.cc +++ b/content/browser/renderer_host/input/input_router_impl.cc @@ -66,8 +66,7 @@ std::unique_ptr ScaleEvent(const WebInputEvent& event, latency_info.ScaledBy(scale)); } - return std::make_unique(ui::WebInputEventTraits::Clone(event), - latency_info); + return std::make_unique(event.Clone(), latency_info); } } // namespace diff --git a/content/browser/renderer_host/render_widget_targeter.cc b/content/browser/renderer_host/render_widget_targeter.cc index 5171535dbe68..dd2876a5233c 100644 --- a/content/browser/renderer_host/render_widget_targeter.cc +++ b/content/browser/renderer_host/render_widget_targeter.cc @@ -106,7 +106,7 @@ RenderWidgetTargeter::TargetingRequest::TargetingRequest( const ui::LatencyInfo& latency) { this->root_view = std::move(root_view); this->location = ComputeEventLocation(event); - this->event = ui::WebInputEventTraits::Clone(event); + this->event = event.Clone(); this->latency = latency; } diff --git a/content/browser/site_per_process_hit_test_browsertest.cc b/content/browser/site_per_process_hit_test_browsertest.cc index 228c8cbc9f3e..48cb1ebc744c 100644 --- a/content/browser/site_per_process_hit_test_browsertest.cc +++ b/content/browser/site_per_process_hit_test_browsertest.cc @@ -95,7 +95,7 @@ class TestInputEventObserver : public RenderWidgetHost::InputEventObserver { void OnInputEvent(const blink::WebInputEvent& event) override { events_received_.push_back(event.GetType()); - event_ = ui::WebInputEventTraits::Clone(event); + event_ = event.Clone(); } const std::vector& events_acked() { diff --git a/content/common/input/event_with_latency_info.h b/content/common/input/event_with_latency_info.h index e61aa653725e..58e8b8ca2de6 100644 --- a/content/common/input/event_with_latency_info.h +++ b/content/common/input/event_with_latency_info.h @@ -41,9 +41,6 @@ class EventWithLatencyInfo { if (other.event.GetType() != event.GetType()) return false; - DCHECK_EQ(sizeof(T), event.size()); - DCHECK_EQ(sizeof(T), other.event.size()); - return ui::CanCoalesce(other.event, event); } diff --git a/content/common/input/input_event.cc b/content/common/input/input_event.cc index 5204dde65a54..4e11e69a36a1 100644 --- a/content/common/input/input_event.cc +++ b/content/common/input/input_event.cc @@ -16,8 +16,7 @@ InputEvent::InputEvent(ui::WebScopedInputEvent event, InputEvent::InputEvent(const blink::WebInputEvent& web_event, const ui::LatencyInfo& latency_info) - : web_event(ui::WebInputEventTraits::Clone(web_event)), - latency_info(latency_info) {} + : web_event(web_event.Clone()), latency_info(latency_info) {} InputEvent::~InputEvent() {} diff --git a/content/public/browser/native_web_keyboard_event.h b/content/public/browser/native_web_keyboard_event.h index 7b10a7402d59..8498d45e54b7 100644 --- a/content/public/browser/native_web_keyboard_event.h +++ b/content/public/browser/native_web_keyboard_event.h @@ -57,7 +57,7 @@ struct CONTENT_EXPORT NativeWebKeyboardEvent : public blink::WebKeyboardEvent { #endif NativeWebKeyboardEvent(const NativeWebKeyboardEvent& event); - ~NativeWebKeyboardEvent(); + ~NativeWebKeyboardEvent() override; NativeWebKeyboardEvent& operator=(const NativeWebKeyboardEvent& event); diff --git a/content/renderer/input/input_event_prediction.cc b/content/renderer/input/input_event_prediction.cc index bd43bcb389e3..b8a79476e80c 100644 --- a/content/renderer/input/input_event_prediction.cc +++ b/content/renderer/input/input_event_prediction.cc @@ -168,8 +168,7 @@ void InputEventPrediction::AddPredictedEvents( last_event_timestamp_ + mouse_predictor_->MaxPredictionTime(); bool success = true; while (success) { - ui::WebScopedInputEvent predicted_event = - ui::WebInputEventTraits::Clone(coalesced_event.Event()); + ui::WebScopedInputEvent predicted_event = coalesced_event.Event().Clone(); success = false; if (predicted_event->GetType() == WebInputEvent::kTouchMove) { WebTouchEvent& touch_event = diff --git a/content/renderer/input/main_thread_event_queue_unittest.cc b/content/renderer/input/main_thread_event_queue_unittest.cc index 35a467cf9af2..299833e08d7d 100644 --- a/content/renderer/input/main_thread_event_queue_unittest.cc +++ b/content/renderer/input/main_thread_event_queue_unittest.cc @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -197,8 +198,8 @@ class MainThreadEventQueueTest : public testing::Test, void HandleEvent(WebInputEvent& event, InputEventAckState ack_result) { base::AutoReset in_handle_event(&handler_callback_->handling_event_, true); - queue_->HandleEvent(ui::WebInputEventTraits::Clone(event), - ui::LatencyInfo(), DISPATCH_TYPE_BLOCKING, ack_result, + queue_->HandleEvent(event.Clone(), ui::LatencyInfo(), + DISPATCH_TYPE_BLOCKING, ack_result, handler_callback_->GetCallback()); } @@ -354,8 +355,6 @@ TEST_F(MainThreadEventQueueTest, NonBlockingWheel) { } { - EXPECT_EQ(kEvents[0].size(), - handled_tasks_.at(0)->taskAsEvent()->Event().size()); EXPECT_EQ(kEvents[0].GetType(), handled_tasks_.at(0)->taskAsEvent()->Event().GetType()); const WebMouseWheelEvent* last_wheel_event = @@ -446,8 +445,6 @@ TEST_F(MainThreadEventQueueTest, NonBlockingTouch) { EXPECT_EQ(0u, event_queue().size()); EXPECT_EQ(3u, handled_tasks_.size()); - EXPECT_EQ(kEvents[0].size(), - handled_tasks_.at(0)->taskAsEvent()->Event().size()); EXPECT_EQ(kEvents[0].GetType(), handled_tasks_.at(0)->taskAsEvent()->Event().GetType()); const WebTouchEvent* last_touch_event = static_cast( @@ -464,8 +461,6 @@ TEST_F(MainThreadEventQueueTest, NonBlockingTouch) { EXPECT_TRUE(Equal(kEvents[0], *coalesced_touch_event)); } - EXPECT_EQ(kEvents[1].size(), - handled_tasks_.at(1)->taskAsEvent()->Event().size()); EXPECT_EQ(kEvents[1].GetType(), handled_tasks_.at(1)->taskAsEvent()->Event().GetType()); last_touch_event = static_cast( @@ -482,8 +477,6 @@ TEST_F(MainThreadEventQueueTest, NonBlockingTouch) { EXPECT_TRUE(Equal(kEvents[1], *coalesced_touch_event)); } - EXPECT_EQ(kEvents[2].size(), - handled_tasks_.at(1)->taskAsEvent()->Event().size()); EXPECT_EQ(kEvents[2].GetType(), handled_tasks_.at(2)->taskAsEvent()->Event().GetType()); last_touch_event = static_cast( @@ -602,8 +595,6 @@ TEST_F(MainThreadEventQueueTest, InterleavedEvents) { EXPECT_EQ(0u, event_queue().size()); EXPECT_EQ(2u, handled_tasks_.size()); { - EXPECT_EQ(kWheelEvents[0].size(), - handled_tasks_.at(0)->taskAsEvent()->Event().size()); EXPECT_EQ(kWheelEvents[0].GetType(), handled_tasks_.at(0)->taskAsEvent()->Event().GetType()); const WebMouseWheelEvent* last_wheel_event = @@ -618,8 +609,6 @@ TEST_F(MainThreadEventQueueTest, InterleavedEvents) { EXPECT_TRUE(Equal(coalesced_event, *last_wheel_event)); } { - EXPECT_EQ(kTouchEvents[0].size(), - handled_tasks_.at(1)->taskAsEvent()->Event().size()); EXPECT_EQ(kTouchEvents[0].GetType(), handled_tasks_.at(1)->taskAsEvent()->Event().GetType()); const WebTouchEvent* last_touch_event = static_cast( @@ -999,8 +988,6 @@ TEST_F(MainThreadEventQueueTest, BlockingTouchesDuringFling) { EXPECT_FALSE(main_task_runner_->HasPendingTask()); EXPECT_EQ(0u, event_queue().size()); EXPECT_EQ(1u, handled_tasks_.size()); - EXPECT_EQ(kEvents.size(), - handled_tasks_.at(0)->taskAsEvent()->Event().size()); EXPECT_EQ(kEvents.GetType(), handled_tasks_.at(0)->taskAsEvent()->Event().GetType()); EXPECT_TRUE(last_touch_start_forced_nonblocking_due_to_fling()); @@ -1020,8 +1007,6 @@ TEST_F(MainThreadEventQueueTest, BlockingTouchesDuringFling) { EXPECT_FALSE(main_task_runner_->HasPendingTask()); EXPECT_EQ(0u, event_queue().size()); EXPECT_EQ(2u, handled_tasks_.size()); - EXPECT_EQ(kEvents.size(), - handled_tasks_.at(1)->taskAsEvent()->Event().size()); EXPECT_EQ(kEvents.GetType(), handled_tasks_.at(1)->taskAsEvent()->Event().GetType()); EXPECT_TRUE(last_touch_start_forced_nonblocking_due_to_fling()); @@ -1040,8 +1025,6 @@ TEST_F(MainThreadEventQueueTest, BlockingTouchesDuringFling) { EXPECT_FALSE(main_task_runner_->HasPendingTask()); EXPECT_EQ(0u, event_queue().size()); EXPECT_EQ(3u, handled_tasks_.size()); - EXPECT_EQ(kEvents.size(), - handled_tasks_.at(2)->taskAsEvent()->Event().size()); EXPECT_EQ(kEvents.GetType(), handled_tasks_.at(2)->taskAsEvent()->Event().GetType()); EXPECT_EQ(kEvents.dispatch_type, WebInputEvent::kBlocking); @@ -1058,8 +1041,6 @@ TEST_F(MainThreadEventQueueTest, BlockingTouchesDuringFling) { EXPECT_FALSE(main_task_runner_->HasPendingTask()); EXPECT_EQ(0u, event_queue().size()); EXPECT_EQ(4u, handled_tasks_.size()); - EXPECT_EQ(kEvents.size(), - handled_tasks_.at(3)->taskAsEvent()->Event().size()); EXPECT_EQ(kEvents.GetType(), handled_tasks_.at(3)->taskAsEvent()->Event().GetType()); EXPECT_EQ(kEvents.dispatch_type, WebInputEvent::kBlocking); @@ -1086,8 +1067,6 @@ TEST_F(MainThreadEventQueueTest, BlockingTouchesOutsideFling) { EXPECT_FALSE(main_task_runner_->HasPendingTask()); EXPECT_EQ(0u, event_queue().size()); EXPECT_EQ(1u, handled_tasks_.size()); - EXPECT_EQ(kEvents.size(), - handled_tasks_.at(0)->taskAsEvent()->Event().size()); EXPECT_EQ(kEvents.GetType(), handled_tasks_.at(0)->taskAsEvent()->Event().GetType()); EXPECT_EQ(kEvents.dispatch_type, WebInputEvent::kBlocking); @@ -1105,8 +1084,6 @@ TEST_F(MainThreadEventQueueTest, BlockingTouchesOutsideFling) { EXPECT_FALSE(main_task_runner_->HasPendingTask()); EXPECT_EQ(0u, event_queue().size()); EXPECT_EQ(2u, handled_tasks_.size()); - EXPECT_EQ(kEvents.size(), - handled_tasks_.at(1)->taskAsEvent()->Event().size()); EXPECT_EQ(kEvents.GetType(), handled_tasks_.at(1)->taskAsEvent()->Event().GetType()); EXPECT_EQ(kEvents.dispatch_type, WebInputEvent::kBlocking); @@ -1124,8 +1101,6 @@ TEST_F(MainThreadEventQueueTest, BlockingTouchesOutsideFling) { EXPECT_FALSE(main_task_runner_->HasPendingTask()); EXPECT_EQ(0u, event_queue().size()); EXPECT_EQ(3u, handled_tasks_.size()); - EXPECT_EQ(kEvents.size(), - handled_tasks_.at(2)->taskAsEvent()->Event().size()); EXPECT_EQ(kEvents.GetType(), handled_tasks_.at(2)->taskAsEvent()->Event().GetType()); EXPECT_EQ(kEvents.dispatch_type, WebInputEvent::kBlocking); @@ -1143,8 +1118,6 @@ TEST_F(MainThreadEventQueueTest, BlockingTouchesOutsideFling) { EXPECT_FALSE(main_task_runner_->HasPendingTask()); EXPECT_EQ(0u, event_queue().size()); EXPECT_EQ(4u, handled_tasks_.size()); - EXPECT_EQ(kEvents.size(), - handled_tasks_.at(3)->taskAsEvent()->Event().size()); EXPECT_EQ(kEvents.GetType(), handled_tasks_.at(3)->taskAsEvent()->Event().GetType()); EXPECT_EQ(kEvents.dispatch_type, WebInputEvent::kBlocking); diff --git a/content/renderer/input/widget_input_handler_manager.cc b/content/renderer/input/widget_input_handler_manager.cc index 21a11e35ece0..eafde289309f 100644 --- a/content/renderer/input/widget_input_handler_manager.cc +++ b/content/renderer/input/widget_input_handler_manager.cc @@ -258,8 +258,7 @@ void WidgetInputHandlerManager::GenerateScrollBeginAndSendToMainThread( blink::WebGestureEvent scroll_begin = ui::ScrollBeginFromScrollUpdate(update_event); - DispatchNonBlockingEventToMainThread( - ui::WebInputEventTraits::Clone(scroll_begin), ui::LatencyInfo()); + DispatchNonBlockingEventToMainThread(scroll_begin.Clone(), ui::LatencyInfo()); } void WidgetInputHandlerManager::SetWhiteListedTouchAction( diff --git a/third_party/blink/common/BUILD.gn b/third_party/blink/common/BUILD.gn index 2461000838d2..b003d6e6db93 100644 --- a/third_party/blink/common/BUILD.gn +++ b/third_party/blink/common/BUILD.gn @@ -48,6 +48,7 @@ jumbo_source_set("common") { "indexeddb/indexeddb_key_range.cc", "indexeddb/indexeddb_metadata.cc", "input/web_gesture_event.cc", + "input/web_keyboard_event.cc", "input/web_mouse_event.cc", "input/web_mouse_wheel_event.cc", "input/web_pointer_event.cc", diff --git a/third_party/blink/common/input/web_gesture_event.cc b/third_party/blink/common/input/web_gesture_event.cc index 512cd96b073d..85a0dc6acb0f 100644 --- a/third_party/blink/common/input/web_gesture_event.cc +++ b/third_party/blink/common/input/web_gesture_event.cc @@ -6,6 +6,10 @@ namespace blink { +std::unique_ptr WebGestureEvent::Clone() const { + return std::make_unique(*this); +} + float WebGestureEvent::DeltaXInRootFrame() const { if (type_ == WebInputEvent::kGestureScrollBegin) return data.scroll_begin.delta_x_hint / frame_scale_; diff --git a/third_party/blink/common/input/web_keyboard_event.cc b/third_party/blink/common/input/web_keyboard_event.cc new file mode 100644 index 000000000000..a75be6d05e3b --- /dev/null +++ b/third_party/blink/common/input/web_keyboard_event.cc @@ -0,0 +1,13 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "third_party/blink/public/common/input/web_keyboard_event.h" + +namespace blink { + +std::unique_ptr WebKeyboardEvent::Clone() const { + return std::make_unique(*this); +} + +} // namespace blink diff --git a/third_party/blink/common/input/web_mouse_event.cc b/third_party/blink/common/input/web_mouse_event.cc index 1942ad589062..5057d07b0afc 100644 --- a/third_party/blink/common/input/web_mouse_event.cc +++ b/third_party/blink/common/input/web_mouse_event.cc @@ -15,7 +15,7 @@ WebMouseEvent::WebMouseEvent(WebInputEvent::Type type, int modifiers, base::TimeTicks time_stamp, PointerId id_param) - : WebInputEvent(sizeof(WebMouseEvent), type, modifiers, time_stamp), + : WebInputEvent(type, modifiers, time_stamp), WebPointerProperties(id_param, WebPointerProperties::PointerType::kMouse, button_param), @@ -34,6 +34,10 @@ gfx::PointF WebMouseEvent::PositionInRootFrame() const { frame_translate_; } +std::unique_ptr WebMouseEvent::Clone() const { + return std::make_unique(*this); +} + WebMouseEvent WebMouseEvent::FlattenTransform() const { WebMouseEvent result = *this; result.FlattenTransformSelf(); diff --git a/third_party/blink/common/input/web_mouse_wheel_event.cc b/third_party/blink/common/input/web_mouse_wheel_event.cc index 7de30cb50a63..eea98f9a5387 100644 --- a/third_party/blink/common/input/web_mouse_wheel_event.cc +++ b/third_party/blink/common/input/web_mouse_wheel_event.cc @@ -6,6 +6,10 @@ namespace blink { +std::unique_ptr WebMouseWheelEvent::Clone() const { + return std::make_unique(*this); +} + float WebMouseWheelEvent::DeltaXInRootFrame() const { return delta_x / frame_scale_; } diff --git a/third_party/blink/common/input/web_pointer_event.cc b/third_party/blink/common/input/web_pointer_event.cc index 3cc2213dcb27..aa09d605a7d0 100644 --- a/third_party/blink/common/input/web_pointer_event.cc +++ b/third_party/blink/common/input/web_pointer_event.cc @@ -30,8 +30,7 @@ WebInputEvent::Type PointerEventTypeForTouchPointState( WebPointerEvent::WebPointerEvent(const WebTouchEvent& touch_event, const WebTouchPoint& touch_point) - : WebInputEvent(sizeof(WebPointerEvent), - PointerEventTypeForTouchPointState(touch_point.state), + : WebInputEvent(PointerEventTypeForTouchPointState(touch_point.state), touch_event.GetModifiers(), touch_event.TimeStamp()), @@ -58,10 +57,7 @@ WebPointerEvent::WebPointerEvent(const WebTouchEvent& touch_event, WebPointerEvent::WebPointerEvent(WebInputEvent::Type type, const WebMouseEvent& mouse_event) - : WebInputEvent(sizeof(WebPointerEvent), - type, - mouse_event.GetModifiers(), - mouse_event.TimeStamp()), + : WebInputEvent(type, mouse_event.GetModifiers(), mouse_event.TimeStamp()), WebPointerProperties(mouse_event), hovering(true), width(std::numeric_limits::quiet_NaN()), @@ -72,6 +68,10 @@ WebPointerEvent::WebPointerEvent(WebInputEvent::Type type, SetFrameTranslate(mouse_event.FrameTranslate()); } +std::unique_ptr WebPointerEvent::Clone() const { + return std::make_unique(*this); +} + WebPointerEvent WebPointerEvent::CreatePointerCausesUaActionEvent( WebPointerProperties::PointerType type, base::TimeTicks time_stamp) { diff --git a/third_party/blink/common/input/web_touch_event.cc b/third_party/blink/common/input/web_touch_event.cc index ed4904625db1..20a55c26329a 100644 --- a/third_party/blink/common/input/web_touch_event.cc +++ b/third_party/blink/common/input/web_touch_event.cc @@ -6,6 +6,10 @@ namespace blink { +std::unique_ptr WebTouchEvent::Clone() const { + return std::make_unique(*this); +} + WebTouchEvent WebTouchEvent::FlattenTransform() const { WebTouchEvent transformed_event = *this; for (unsigned i = 0; i < touches_length; ++i) { diff --git a/third_party/blink/public/common/input/web_gesture_event.h b/third_party/blink/public/common/input/web_gesture_event.h index 581955550705..947c1b601916 100644 --- a/third_party/blink/public/common/input/web_gesture_event.h +++ b/third_party/blink/public/common/input/web_gesture_event.h @@ -26,7 +26,7 @@ class BLINK_COMMON_EXPORT WebGestureEvent : public WebInputEvent { kMaxValue = kMomentum, }; - bool is_source_touch_event_set_non_blocking; + bool is_source_touch_event_set_non_blocking = false; // The pointer type for the first touch point in the gesture. WebPointerProperties::PointerType primary_pointer_type = @@ -38,7 +38,7 @@ class BLINK_COMMON_EXPORT WebGestureEvent : public WebInputEvent { // not released through a touch event (e.g. timer-released gesture events or // gesture events with source_device != WebGestureDevice::kTouchscreen), the // field contains 0. See crbug.com/618738. - uint32_t unique_touch_event_id; + uint32_t unique_touch_event_id = 0; union { // Tap information must be set for GestureTap, GestureTapUnconfirmed, @@ -180,23 +180,24 @@ class BLINK_COMMON_EXPORT WebGestureEvent : public WebInputEvent { // Screen coordinate gfx::PointF position_in_screen_; - WebGestureDevice source_device_; + WebGestureDevice source_device_ = WebGestureDevice::kUninitialized; public: WebGestureEvent(Type type, int modifiers, base::TimeTicks time_stamp, WebGestureDevice device = WebGestureDevice::kUninitialized) - : WebInputEvent(sizeof(WebGestureEvent), type, modifiers, time_stamp), - source_device_(device) {} + : WebInputEvent(type, modifiers, time_stamp), source_device_(device) { + memset(&data, 0, sizeof(data)); + } - WebGestureEvent() - : WebInputEvent(sizeof(WebGestureEvent)), - source_device_(WebGestureDevice::kUninitialized) {} + WebGestureEvent() { memset(&data, 0, sizeof(data)); } const gfx::PointF& PositionInWidget() const { return position_in_widget_; } const gfx::PointF& PositionInScreen() const { return position_in_screen_; } + std::unique_ptr Clone() const override; + void SetPositionInWidget(const gfx::PointF& point) { position_in_widget_ = point; } diff --git a/third_party/blink/public/common/input/web_input_event.h b/third_party/blink/public/common/input/web_input_event.h index c137231c75f1..5d30b5eaab6a 100644 --- a/third_party/blink/public/common/input/web_input_event.h +++ b/third_party/blink/public/common/input/web_input_event.h @@ -42,7 +42,7 @@ namespace blink { // WebInputEvent -------------------------------------------------------------- -class WebInputEvent { +class BLINK_COMMON_EXPORT WebInputEvent { public: // When we use an input method (or an input method editor), we receive // two events for a keypress. The former event is a keydown, which @@ -426,61 +426,30 @@ class WebInputEvent { base::TimeTicks TimeStamp() const { return time_stamp_; } void SetTimeStamp(base::TimeTicks time_stamp) { time_stamp_ = time_stamp; } - unsigned size() const { return size_; } - void SetTargetFrameMovedRecently() { modifiers_ |= kTargetFrameMovedRecently; } + virtual ~WebInputEvent() = default; + + virtual std::unique_ptr Clone() const = 0; + protected: // The root frame scale. - float frame_scale_; + float frame_scale_ = 1; // The root frame translation (applied post scale). gfx::Vector2dF frame_translate_; - WebInputEvent(unsigned size, - Type type, - int modifiers, - base::TimeTicks time_stamp) { - // TODO(dtapuska): Remove this memset when we remove the chrome IPC of this - // struct. - memset(this, 0, size); - time_stamp_ = time_stamp; - size_ = size; - type_ = type; - modifiers_ = modifiers; -#if DCHECK_IS_ON() - // If dcheck is on force failures if frame scale is not initialized - // correctly by causing DIV0. - frame_scale_ = 0; -#else - frame_scale_ = 1; -#endif - } + WebInputEvent(Type type, int modifiers, base::TimeTicks time_stamp) + : time_stamp_(time_stamp), type_(type), modifiers_(modifiers) {} - explicit WebInputEvent(unsigned size_param) { - // TODO(dtapuska): Remove this memset when we remove the chrome IPC of this - // struct. - memset(this, 0, size_param); - time_stamp_ = base::TimeTicks(); - size_ = size_param; - type_ = kUndefined; -#if DCHECK_IS_ON() - // If dcheck is on force failures if frame scale is not initialized - // correctly by causing DIV0. - frame_scale_ = 0; -#else - frame_scale_ = 1; -#endif - } + WebInputEvent() { time_stamp_ = base::TimeTicks(); } // Event time since platform start with microsecond resolution. base::TimeTicks time_stamp_; - // The size of this structure, for serialization. - unsigned size_; - Type type_; - int modifiers_; + Type type_ = kUndefined; + int modifiers_ = kNoModifiers; }; } // namespace blink diff --git a/third_party/blink/public/common/input/web_keyboard_event.h b/third_party/blink/public/common/input/web_keyboard_event.h index 18cfb20dbe32..5f38e9ec8fa0 100644 --- a/third_party/blink/public/common/input/web_keyboard_event.h +++ b/third_party/blink/public/common/input/web_keyboard_event.h @@ -12,7 +12,7 @@ namespace blink { // WebKeyboardEvent ----------------------------------------------------------- -class WebKeyboardEvent : public WebInputEvent { +class BLINK_COMMON_EXPORT WebKeyboardEvent : public WebInputEvent { public: // Caps on string lengths so we can make them static arrays and keep // them PODs. @@ -26,32 +26,32 @@ class WebKeyboardEvent : public WebInputEvent { // what is returned by the Windows API. For example, it should // store VK_SHIFT instead of VK_RSHIFT. The location information // should be stored in |modifiers|. - int windows_key_code; + int windows_key_code = 0; // The actual key code genenerated by the platform. The DOM spec runs // on Windows-equivalent codes (thus |windows_key_code| above) but it // doesn't hurt to have this one around. - int native_key_code; + int native_key_code = 0; // The DOM code enum of the key pressed as passed by the embedder. DOM code // enums are defined in ui/events/keycodes/dom/keycode_converter_data.inc. - int dom_code; + int dom_code = 0; // The DOM key enum of the key pressed as passed by the embedder. DOM // key enums are defined in ui/events/keycodes/dom/dom_key_data.inc. - int dom_key; + int dom_key = 0; // This identifies whether this event was tagged by the system as being a // "system key" event (see // https://docs.microsoft.com/en-us/windows/desktop/inputdev/wm-syskeydown for // details). Other platforms don't have this concept, but it's just // easier to leave it always false than ifdef. - bool is_system_key; + bool is_system_key = false; // Whether the event forms part of a browser-handled keyboard shortcut. // This can be used to conditionally suppress Char events after a // shortcut-triggering RawKeyDown goes unhandled. - bool is_browser_shortcut; + bool is_browser_shortcut = false; // |text| is the text generated by this keystroke. |unmodified_text| is // |text|, but unmodified by an concurrently-held modifiers (except @@ -59,13 +59,15 @@ class WebKeyboardEvent : public WebInputEvent { // Windows guarantee one character per event. The Mac does not, but in // reality that's all it ever gives. We're generous, and cap it a bit // longer. - base::char16 text[kTextLengthCap]; - base::char16 unmodified_text[kTextLengthCap]; + base::char16 text[kTextLengthCap] = {}; + base::char16 unmodified_text[kTextLengthCap] = {}; WebKeyboardEvent(Type type, int modifiers, base::TimeTicks time_stamp) - : WebInputEvent(sizeof(WebKeyboardEvent), type, modifiers, time_stamp) {} + : WebInputEvent(type, modifiers, time_stamp) {} - WebKeyboardEvent() : WebInputEvent(sizeof(WebKeyboardEvent)) {} + WebKeyboardEvent() = default; + + std::unique_ptr Clone() const override; // Please refer to bug http://b/issue?id=961192, which talks about Webkit // keyboard event handling changes. It also mentions the list of keys diff --git a/third_party/blink/public/common/input/web_mouse_event.h b/third_party/blink/public/common/input/web_mouse_event.h index 25da4f16f58a..957e83c238b9 100644 --- a/third_party/blink/public/common/input/web_mouse_event.h +++ b/third_party/blink/public/common/input/web_mouse_event.h @@ -20,10 +20,10 @@ class BLINK_COMMON_EXPORT WebMouseEvent : public WebInputEvent, public: static constexpr PointerId kMousePointerId = std::numeric_limits::max(); - int click_count; + int click_count = {}; // Only used for contextmenu events. - WebMenuSourceType menu_source_type; + WebMenuSourceType menu_source_type = kMenuSourceNone; WebMouseEvent(Type type_param, gfx::PointF position, @@ -34,10 +34,7 @@ class BLINK_COMMON_EXPORT WebMouseEvent : public WebInputEvent, base::TimeTicks time_stamp_param, WebMenuSourceType menu_source_type_param = kMenuSourceNone, PointerId id_param = kMousePointerId) - : WebInputEvent(sizeof(WebMouseEvent), - type_param, - modifiers_param, - time_stamp_param), + : WebInputEvent(type_param, modifiers_param, time_stamp_param), WebPointerProperties(id_param, PointerType::kMouse, button_param, @@ -53,13 +50,10 @@ class BLINK_COMMON_EXPORT WebMouseEvent : public WebInputEvent, int modifiers_param, base::TimeTicks time_stamp_param, PointerId id_param = kMousePointerId) - : WebMouseEvent(sizeof(WebMouseEvent), - type_param, - modifiers_param, - time_stamp_param, - id_param) {} + : WebInputEvent(type_param, modifiers_param, time_stamp_param), + WebPointerProperties(id_param) {} - WebMouseEvent() : WebMouseEvent(sizeof(WebMouseEvent), kMousePointerId) {} + WebMouseEvent() : WebMouseEvent(kMousePointerId) {} bool FromTouch() const { return (GetModifiers() & kIsCompatibilityEventForTouch) != 0; @@ -73,6 +67,8 @@ class BLINK_COMMON_EXPORT WebMouseEvent : public WebInputEvent, base::TimeTicks time_stamp_param, PointerId id_param = kMousePointerId); + std::unique_ptr Clone() const override; + gfx::PointF PositionInRootFrame() const; // Sets any scaled values to be their computed values and sets |frame_scale_| @@ -80,16 +76,7 @@ class BLINK_COMMON_EXPORT WebMouseEvent : public WebInputEvent, WebMouseEvent FlattenTransform() const; protected: - WebMouseEvent(unsigned size_param, PointerId id_param) - : WebInputEvent(size_param), WebPointerProperties(id_param) {} - - WebMouseEvent(unsigned size_param, - Type type, - int modifiers, - base::TimeTicks time_stamp, - PointerId id_param) - : WebInputEvent(size_param, type, modifiers, time_stamp), - WebPointerProperties(id_param) {} + WebMouseEvent(PointerId id_param) : WebPointerProperties(id_param) {} void FlattenTransformSelf(); diff --git a/third_party/blink/public/common/input/web_mouse_wheel_event.h b/third_party/blink/public/common/input/web_mouse_wheel_event.h index 605740b8c01d..79697fe69e08 100644 --- a/third_party/blink/public/common/input/web_mouse_wheel_event.h +++ b/third_party/blink/public/common/input/web_mouse_wheel_event.h @@ -52,25 +52,25 @@ class BLINK_COMMON_EXPORT WebMouseWheelEvent : public WebMouseEvent { kScrollVertical }; - float delta_x; - float delta_y; - float wheel_ticks_x; - float wheel_ticks_y; + float delta_x = 0.0f; + float delta_y = 0.0f; + float wheel_ticks_x = 0.0f; + float wheel_ticks_y = 0.0f; - float acceleration_ratio_x; - float acceleration_ratio_y; + float acceleration_ratio_x = 1.0f; + float acceleration_ratio_y = 1.0f; - Phase phase; - Phase momentum_phase; + Phase phase = kPhaseNone; + Phase momentum_phase = kPhaseNone; - RailsMode rails_mode; + RailsMode rails_mode = kRailsModeFree; // Whether the event is blocking, non-blocking, all event // listeners were passive or was forced to be non-blocking. - DispatchType dispatch_type; + DispatchType dispatch_type = kBlocking; // The expected result of this wheel event (if not canceled). - EventAction event_action; + EventAction event_action = EventAction::kPageZoom; // True when phase information is added in mouse_wheel_phase_handler based // on its timer. @@ -80,39 +80,13 @@ class BLINK_COMMON_EXPORT WebMouseWheelEvent : public WebMouseEvent { // kScrollByPrecisePixel, kScrollByPixel, and kScrollByPage, as they are // the only values expected after converting an OS event to a // WebMouseWheelEvent. - ui::input_types::ScrollGranularity delta_units; + ui::input_types::ScrollGranularity delta_units = + ui::input_types::ScrollGranularity::kScrollByPixel; WebMouseWheelEvent(Type type, int modifiers, base::TimeTicks time_stamp) - : WebMouseEvent(sizeof(WebMouseWheelEvent), - type, - modifiers, - time_stamp, - kMousePointerId), - delta_x(0.0f), - delta_y(0.0f), - wheel_ticks_x(0.0f), - wheel_ticks_y(0.0f), - acceleration_ratio_x(1.0f), - acceleration_ratio_y(1.0f), - phase(kPhaseNone), - momentum_phase(kPhaseNone), - rails_mode(kRailsModeFree), - dispatch_type(kBlocking), - delta_units(ui::input_types::ScrollGranularity::kScrollByPixel) {} - - WebMouseWheelEvent() - : WebMouseEvent(sizeof(WebMouseWheelEvent), kMousePointerId), - delta_x(0.0f), - delta_y(0.0f), - wheel_ticks_x(0.0f), - wheel_ticks_y(0.0f), - acceleration_ratio_x(1.0f), - acceleration_ratio_y(1.0f), - phase(kPhaseNone), - momentum_phase(kPhaseNone), - rails_mode(kRailsModeFree), - dispatch_type(kBlocking), - delta_units(ui::input_types::ScrollGranularity::kScrollByPixel) {} + : WebMouseEvent(type, modifiers, time_stamp, kMousePointerId) {} + + WebMouseWheelEvent() : WebMouseEvent(kMousePointerId) {} float DeltaXInRootFrame() const; float DeltaYInRootFrame() const; @@ -122,6 +96,8 @@ class BLINK_COMMON_EXPORT WebMouseWheelEvent : public WebMouseEvent { WebMouseWheelEvent FlattenTransform() const; bool IsCancelable() const { return dispatch_type == kBlocking; } + + std::unique_ptr Clone() const override; }; } // namespace blink diff --git a/third_party/blink/public/common/input/web_pointer_event.h b/third_party/blink/public/common/input/web_pointer_event.h index cdf6b9984dcb..efb5847eb8ec 100644 --- a/third_party/blink/public/common/input/web_pointer_event.h +++ b/third_party/blink/public/common/input/web_pointer_event.h @@ -21,14 +21,12 @@ namespace blink { class BLINK_COMMON_EXPORT WebPointerEvent : public WebInputEvent, public WebPointerProperties { public: - WebPointerEvent() - : WebInputEvent(sizeof(WebPointerEvent)), WebPointerProperties(0) {} + WebPointerEvent() : WebPointerProperties(0) {} WebPointerEvent(WebInputEvent::Type type_param, WebPointerProperties web_pointer_properties_param, float width_param, float height_param) - : WebInputEvent(sizeof(WebPointerEvent)), - WebPointerProperties(web_pointer_properties_param), + : WebPointerProperties(web_pointer_properties_param), width(width_param), height(height_param) { SetType(type_param); @@ -36,44 +34,46 @@ class BLINK_COMMON_EXPORT WebPointerEvent : public WebInputEvent, WebPointerEvent(const WebTouchEvent&, const WebTouchPoint&); WebPointerEvent(WebInputEvent::Type, const WebMouseEvent&); + std::unique_ptr Clone() const override; + static WebPointerEvent CreatePointerCausesUaActionEvent( WebPointerProperties::PointerType, base::TimeTicks time_stamp); // ------------ Touch Point Specific ------------ - float rotation_angle; + float rotation_angle = 0.0f; // ------------ Touch Event Specific ------------ // A unique identifier for the touch event. Valid ids start at one and // increase monotonically. Zero means an unknown id. - uint32_t unique_touch_event_id; + uint32_t unique_touch_event_id = 0; // Whether the event is blocking, non-blocking, all event // listeners were passive or was forced to be non-blocking. - DispatchType dispatch_type; + DispatchType dispatch_type = kBlocking; // For a single touch, this is true after the touch-point has moved beyond // the platform slop region. For a multitouch, this is true after any // touch-point has moved (by whatever amount). - bool moved_beyond_slop_region; + bool moved_beyond_slop_region = false; // Whether this touch event is a touchstart or a first touchmove event per // scroll. - bool touch_start_or_first_touch_move; + bool touch_start_or_first_touch_move = false; // ------------ Common fields across pointer types ------------ // True if this pointer was hovering and false otherwise. False value entails // the event was processed as part of gesture detection and it may cause // scrolling. - bool hovering; + bool hovering = false; // TODO(crbug.com/736014): We need a clarified definition of the scale and // the coordinate space on these attributes. - float width; - float height; + float width = 0.0f; + float height = 0.0f; bool IsCancelable() const { return dispatch_type == kBlocking; } bool HasWidth() const { return !std::isnan(width); } diff --git a/third_party/blink/public/common/input/web_pointer_properties.h b/third_party/blink/public/common/input/web_pointer_properties.h index d122090fde30..c642fab9da4c 100644 --- a/third_party/blink/public/common/input/web_pointer_properties.h +++ b/third_party/blink/public/common/input/web_pointer_properties.h @@ -60,16 +60,10 @@ class WebPointerProperties { int movement_x = 0, int movement_y = 0) : id(id_param), - force(std::numeric_limits::quiet_NaN()), - tilt_x(0), - tilt_y(0), - tangential_pressure(0.0f), - twist(0), button(button_param), pointer_type(pointer_type_param), movement_x(movement_x), movement_y(movement_y), - is_raw_movement_event(false), position_in_widget_(position_in_widget), position_in_screen_(position_in_screen) {} @@ -96,23 +90,23 @@ class WebPointerProperties { // The valid range is [0,1], with NaN meaning pressure is not supported by // the input device. - float force; + float force = std::numeric_limits::quiet_NaN(); // Tilt of a pen stylus from surface normal as plane angles in degrees, // Values lie in [-90,90]. A positive tiltX is to the right and a positive // tiltY is towards the user. - int tilt_x; - int tilt_y; + int tilt_x = 0; + int tilt_y = 0; // The normalized tangential pressure (or barrel pressure), typically set by // an additional control of the stylus, which has a range of [-1,1], where 0 // is the neutral position of the control. Always 0 if the device does not // support it. - float tangential_pressure; + float tangential_pressure = 0.0f; // The clockwise rotation of a pen stylus around its own major axis, in // degrees in the range [0,359]. Always 0 if the device does not support it. - int twist; + int twist = 0; // - For pointerup/down events, the button of pointing device that triggered // the event. @@ -128,7 +122,7 @@ class WebPointerProperties { // True if this event has raw movement value from OS. // TODO(crbug.com/982379): Figure out how to avoid using this boolean. - bool is_raw_movement_event; + bool is_raw_movement_event = false; protected: // Widget coordinate, which is relative to the bound of current RenderWidget diff --git a/third_party/blink/public/common/input/web_touch_event.h b/third_party/blink/public/common/input/web_touch_event.h index 795976c6a8f8..9a59b3f63120 100644 --- a/third_party/blink/public/common/input/web_touch_event.h +++ b/third_party/blink/public/common/input/web_touch_event.h @@ -19,37 +19,37 @@ class BLINK_COMMON_EXPORT WebTouchEvent : public WebInputEvent { // Ash/Aura. enum { kTouchesLengthCap = 16 }; - unsigned touches_length; + unsigned touches_length = 0; // List of all touches, regardless of state. - WebTouchPoint touches[kTouchesLengthCap]; + WebTouchPoint touches[kTouchesLengthCap] = {}; // Whether the event is blocking, non-blocking, all event // listeners were passive or was forced to be non-blocking. - DispatchType dispatch_type; + DispatchType dispatch_type = kBlocking; // For a single touch, this is true after the touch-point has moved beyond // the platform slop region. For a multitouch, this is true after any // touch-point has moved (by whatever amount). - bool moved_beyond_slop_region; + bool moved_beyond_slop_region = false; // True for events from devices like some pens that support hovering // over digitizer and the events are sent while the device was hovering. - bool hovering; + bool hovering = false; // Whether this touch event is a touchstart or a first touchmove event per // scroll. - bool touch_start_or_first_touch_move; + bool touch_start_or_first_touch_move = false; // A unique identifier for the touch event. Valid ids start at one and // increase monotonically. Zero means an unknown id. - uint32_t unique_touch_event_id; + uint32_t unique_touch_event_id = 0; - WebTouchEvent() - : WebInputEvent(sizeof(WebTouchEvent)), dispatch_type(kBlocking) {} + WebTouchEvent() = default; WebTouchEvent(Type type, int modifiers, base::TimeTicks time_stamp) - : WebInputEvent(sizeof(WebTouchEvent), type, modifiers, time_stamp), - dispatch_type(kBlocking) {} + : WebInputEvent(type, modifiers, time_stamp) {} + + std::unique_ptr Clone() const override; // Sets any scaled values to be their computed values and sets |frame_scale_| // back to 1 and |frame_translate_| X and Y coordinates back to 0. diff --git a/third_party/blink/public/common/input/web_touch_point.h b/third_party/blink/public/common/input/web_touch_point.h index de8971f66487..939142edb2bc 100644 --- a/third_party/blink/public/common/input/web_touch_point.h +++ b/third_party/blink/public/common/input/web_touch_point.h @@ -38,16 +38,12 @@ namespace blink { // TODO(mustaq): Unify WebTouchPoint & WebMouseEvent into WebPointerEvent. // crbug.com/508283 -class WebTouchPoint : public WebPointerProperties { +class BLINK_COMMON_EXPORT WebTouchPoint : public WebPointerProperties { public: WebTouchPoint() : WebTouchPoint(WebPointerProperties(0)) {} WebTouchPoint(WebPointerProperties web_pointer_properties) - : WebPointerProperties(web_pointer_properties), - state(kStateUndefined), - radius_x(0), - radius_y(0), - rotation_angle(0) {} + : WebPointerProperties(web_pointer_properties) {} enum State { kStateUndefined, @@ -59,11 +55,11 @@ class WebTouchPoint : public WebPointerProperties { kStateMax = kStateCancelled }; - State state; + State state = kStateUndefined; - float radius_x; - float radius_y; - float rotation_angle; + float radius_x = 0.0f; + float radius_y = 0.0f; + float rotation_angle = 0.0f; }; } // namespace blink diff --git a/third_party/blink/public/platform/web_coalesced_input_event.h b/third_party/blink/public/platform/web_coalesced_input_event.h index bcf0359482c7..3095d0bb524d 100644 --- a/third_party/blink/public/platform/web_coalesced_input_event.h +++ b/third_party/blink/public/platform/web_coalesced_input_event.h @@ -42,12 +42,7 @@ class BLINK_PLATFORM_EXPORT WebCoalescedInputEvent { WebVector GetPredictedEventsPointers() const; private: - struct BLINK_PLATFORM_EXPORT WebInputEventDeleter { - void operator()(blink::WebInputEvent*) const; - }; - - using WebScopedInputEvent = - std::unique_ptr; + using WebScopedInputEvent = std::unique_ptr; WebScopedInputEvent MakeWebScopedInputEvent(const blink::WebInputEvent&); diff --git a/third_party/blink/renderer/core/events/web_input_event_conversion.cc b/third_party/blink/renderer/core/events/web_input_event_conversion.cc index 716617985147..fcf3fc6b4aff 100644 --- a/third_party/blink/renderer/core/events/web_input_event_conversion.cc +++ b/third_party/blink/renderer/core/events/web_input_event_conversion.cc @@ -120,8 +120,8 @@ unsigned ToWebInputEventModifierFrom(WebMouseEvent::Button button) { WebPointerEvent TransformWebPointerEvent(float frame_scale, gfx::Vector2dF frame_translate, const WebPointerEvent& event) { - // frameScale is default initialized in debug builds to be 0. - DCHECK_EQ(0, event.FrameScale()); + // frameScale is default initialized to 1. + DCHECK_EQ(1, event.FrameScale()); DCHECK_EQ(0, event.FrameTranslate().x()); DCHECK_EQ(0, event.FrameTranslate().y()); WebPointerEvent result = event; diff --git a/third_party/blink/renderer/platform/exported/web_coalesced_input_event.cc b/third_party/blink/renderer/platform/exported/web_coalesced_input_event.cc index ac42cd792eb1..21edc5fe3070 100644 --- a/third_party/blink/renderer/platform/exported/web_coalesced_input_event.cc +++ b/third_party/blink/renderer/platform/exported/web_coalesced_input_event.cc @@ -12,46 +12,6 @@ namespace blink { -namespace { - -struct WebInputEventDelete { - template - bool Execute(WebInputEvent* event) const { - if (!event) - return false; - DCHECK_EQ(sizeof(EventType), event->size()); - delete static_cast(event); - return true; - } -}; - -template -bool Apply(Operator op, WebInputEvent::Type type, const ArgIn& arg_in) { - if (WebInputEvent::IsMouseEventType(type)) - return op.template Execute(arg_in); - if (type == WebInputEvent::kMouseWheel) - return op.template Execute(arg_in); - if (WebInputEvent::IsKeyboardEventType(type)) - return op.template Execute(arg_in); - if (WebInputEvent::IsTouchEventType(type)) - return op.template Execute(arg_in); - if (WebInputEvent::IsGestureEventType(type)) - return op.template Execute(arg_in); - if (WebInputEvent::IsPointerEventType(type)) - return op.template Execute(arg_in); - - NOTREACHED() << "Unknown webkit event type " << type; - return false; -} -} - -void WebCoalescedInputEvent::WebInputEventDeleter::operator()( - WebInputEvent* event) const { - if (!event) - return; - Apply(WebInputEventDelete(), event->GetType(), event); -} - WebInputEvent* WebCoalescedInputEvent::EventPointer() { return event_.get(); } diff --git a/third_party/blink/renderer/platform/scheduler/main_thread/main_thread_scheduler_impl_unittest.cc b/third_party/blink/renderer/platform/scheduler/main_thread/main_thread_scheduler_impl_unittest.cc index 63d7ca8fb6e6..c44eecf2c2bd 100644 --- a/third_party/blink/renderer/platform/scheduler/main_thread/main_thread_scheduler_impl_unittest.cc +++ b/third_party/blink/renderer/platform/scheduler/main_thread/main_thread_scheduler_impl_unittest.cc @@ -58,10 +58,13 @@ class FakeInputEvent : public blink::WebInputEvent { public: explicit FakeInputEvent(blink::WebInputEvent::Type event_type, int modifiers = WebInputEvent::kNoModifiers) - : WebInputEvent(sizeof(FakeInputEvent), - event_type, + : WebInputEvent(event_type, modifiers, WebInputEvent::GetStaticTimeStampForTests()) {} + + std::unique_ptr Clone() const override { + return std::make_unique(*this); + } }; class FakeTouchEvent : public blink::WebTouchEvent { diff --git a/ui/events/blink/compositor_thread_event_queue.cc b/ui/events/blink/compositor_thread_event_queue.cc index f9c2b4609121..8d4e06475878 100644 --- a/ui/events/blink/compositor_thread_event_queue.cc +++ b/ui/events/blink/compositor_thread_event_queue.cc @@ -76,12 +76,12 @@ void CompositorThreadEventQueue::Queue( std::unique_ptr scroll_event = std::make_unique( - WebInputEventTraits::Clone(coalesced_events.first), oldest_latency, + coalesced_events.first.Clone(), oldest_latency, oldest_creation_timestamp, timestamp_now, nullptr); std::unique_ptr pinch_event = std::make_unique( - WebInputEventTraits::Clone(coalesced_events.second), oldest_latency, + coalesced_events.second.Clone(), oldest_latency, oldest_creation_timestamp, timestamp_now, std::move(combined_original_events)); diff --git a/ui/events/blink/event_with_callback.cc b/ui/events/blink/event_with_callback.cc index cbed00131204..c3c685dbae2c 100644 --- a/ui/events/blink/event_with_callback.cc +++ b/ui/events/blink/event_with_callback.cc @@ -19,7 +19,7 @@ EventWithCallback::EventWithCallback( const LatencyInfo& latency, base::TimeTicks timestamp_now, InputHandlerProxy::EventDispositionCallback callback) - : event_(WebInputEventTraits::Clone(*event)), + : event_(event->Clone()), latency_(latency), creation_timestamp_(timestamp_now), last_coalesced_timestamp_(timestamp_now) { diff --git a/ui/events/blink/input_handler_proxy_unittest.cc b/ui/events/blink/input_handler_proxy_unittest.cc index cf89aaa43cf7..9b2b867f2944 100644 --- a/ui/events/blink/input_handler_proxy_unittest.cc +++ b/ui/events/blink/input_handler_proxy_unittest.cc @@ -94,7 +94,7 @@ WebScopedInputEvent CreateGestureScrollPinch(WebInputEvent::Type type, gesture.data.pinch_update.scale = delta_y_or_scale; gesture.SetPositionInWidget(gfx::PointF(x, y)); } - return WebInputEventTraits::Clone(gesture); + return gesture.Clone(); } class MockInputHandler : public cc::InputHandler { @@ -2640,14 +2640,14 @@ class InputHandlerProxyMomentumScrollJankTest : public testing::Test { WebGestureEvent gesture(WebInputEvent::kGestureScrollBegin, WebInputEvent::kNoModifiers, tick_clock_.NowTicks(), blink::WebGestureDevice::kTouchscreen); - HandleGesture(WebInputEventTraits::Clone(gesture)); + HandleGesture(gesture.Clone()); } void HandleScrollEnd() { WebGestureEvent gesture(WebInputEvent::kGestureScrollEnd, WebInputEvent::kNoModifiers, tick_clock_.NowTicks(), blink::WebGestureDevice::kTouchscreen); - HandleGesture(WebInputEventTraits::Clone(gesture)); + HandleGesture(gesture.Clone()); } void HandleScrollUpdate(bool is_momentum) { @@ -2659,7 +2659,7 @@ class InputHandlerProxyMomentumScrollJankTest : public testing::Test { gesture.data.scroll_update.inertial_phase = blink::WebGestureEvent::InertialPhaseState::kMomentum; } - HandleGesture(WebInputEventTraits::Clone(gesture)); + HandleGesture(gesture.Clone()); } void AdvanceClock(uint32_t milliseconds) { diff --git a/ui/events/blink/scroll_predictor_unittest.cc b/ui/events/blink/scroll_predictor_unittest.cc index cbf1b8830690..e8409d23eb4a 100644 --- a/ui/events/blink/scroll_predictor_unittest.cc +++ b/ui/events/blink/scroll_predictor_unittest.cc @@ -58,10 +58,10 @@ class ScrollPredictorTest : public testing::Test { gesture.data.scroll_update.delta_y = delta_y; gesture.data.scroll_update.inertial_phase = phase; - original_events_.emplace_back(WebInputEventTraits::Clone(gesture), - LatencyInfo(), base::NullCallback()); + original_events_.emplace_back(gesture.Clone(), LatencyInfo(), + base::NullCallback()); - return WebInputEventTraits::Clone(gesture); + return gesture.Clone(); } void CoalesceWith(const WebScopedInputEvent& new_event, @@ -90,7 +90,7 @@ class ScrollPredictorTest : public testing::Test { WebInputEvent::GetStaticTimeStampForTests() + base::TimeDelta::FromMillisecondsD(time_delta_in_milliseconds)); - event = WebInputEventTraits::Clone(event_with_callback->event()); + event = event_with_callback->event().Clone(); } std::unique_ptr PredictionAvailable( @@ -203,7 +203,7 @@ TEST_F(ScrollPredictorTest, ScrollResamplingStates) { WebInputEvent::kNoModifiers, WebInputEvent::GetStaticTimeStampForTests(), blink::WebGestureDevice::kTouchscreen); - WebScopedInputEvent event = WebInputEventTraits::Clone(gesture_end); + WebScopedInputEvent event = gesture_end.Clone(); HandleResampleScrollEvents(event); EXPECT_FALSE(GetResamplingState()); } diff --git a/ui/events/blink/web_input_event_traits.cc b/ui/events/blink/web_input_event_traits.cc index 9734e1d0cd9d..19bd615be35b 100644 --- a/ui/events/blink/web_input_event_traits.cc +++ b/ui/events/blink/web_input_event_traits.cc @@ -105,17 +105,6 @@ void ApppendEventDetails(const WebPointerEvent& event, std::string* result) { event.rotation_angle, event.tilt_x, event.tilt_y); } -struct WebInputEventDelete { - template - bool Execute(WebInputEvent* event, void*) const { - if (!event) - return false; - DCHECK_EQ(sizeof(EventType), event->size()); - delete static_cast(event); - return true; - } -}; - struct WebInputEventToString { template bool Execute(const WebInputEvent& event, std::string* result) const { @@ -129,17 +118,6 @@ struct WebInputEventToString { } }; -struct WebInputEventClone { - template - bool Execute(const WebInputEvent& event, - WebScopedInputEvent* scoped_event) const { - DCHECK_EQ(sizeof(EventType), event.size()); - *scoped_event = WebScopedInputEvent( - new EventType(static_cast(event))); - return true; - } -}; - template bool Apply(Operator op, WebInputEvent::Type type, @@ -164,25 +142,12 @@ bool Apply(Operator op, } // namespace -void WebInputEventDeleter::operator()(WebInputEvent* event) const { - if (!event) - return; - void* temp = nullptr; - Apply(WebInputEventDelete(), event->GetType(), event, temp); -} - std::string WebInputEventTraits::ToString(const WebInputEvent& event) { std::string result; Apply(WebInputEventToString(), event.GetType(), event, &result); return result; } -WebScopedInputEvent WebInputEventTraits::Clone(const WebInputEvent& event) { - WebScopedInputEvent scoped_event; - Apply(WebInputEventClone(), event.GetType(), event, &scoped_event); - return scoped_event; -} - bool WebInputEventTraits::ShouldBlockEventStream(const WebInputEvent& event) { switch (event.GetType()) { case WebInputEvent::kContextMenu: diff --git a/ui/events/blink/web_input_event_traits.h b/ui/events/blink/web_input_event_traits.h index 19f9db8bd44c..10f60ba4eb0b 100644 --- a/ui/events/blink/web_input_event_traits.h +++ b/ui/events/blink/web_input_event_traits.h @@ -14,18 +14,12 @@ class WebGestureEvent; namespace ui { -struct WebInputEventDeleter { - void operator()(blink::WebInputEvent*) const; -}; - -using WebScopedInputEvent = - std::unique_ptr; +using WebScopedInputEvent = std::unique_ptr; // Utility class for performing operations on and with WebInputEvents. class WebInputEventTraits { public: static std::string ToString(const blink::WebInputEvent& event); - static WebScopedInputEvent Clone(const blink::WebInputEvent& event); static bool ShouldBlockEventStream(const blink::WebInputEvent& event); // Return uniqueTouchEventId for WebTouchEvent, otherwise return 0. -- 2.24.1