#include "components/input/render_widget_host_input_event_router.h"
#include <algorithm>
#include <deque>
#include <memory>
#include <vector>
#include "base/debug/crash_logging.h"
#include "base/debug/dump_without_crashing.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/trace_event/trace_event.h"
#include "components/input/cursor_manager.h"
#include "components/input/touch_emulator.h"
#include "components/viz/common/features.h"
#include "components/viz/common/hit_test/hit_test_data_provider.h"
#include "components/viz/common/hit_test/hit_test_region_list.h"
#include "components/viz/common/quads/surface_draw_quad.h"
#include "third_party/blink/public/common/input/web_input_event.h"
#include "third_party/blink/public/common/input/web_mouse_wheel_event.h"
#include "ui/base/cursor/cursor.h"
#include "ui/gfx/geometry/dip_util.h"
namespace {
void TransformEventTouchPositions(blink::WebTouchEvent* event,
const gfx::Transform& transform) { … }
bool IsMouseButtonDown(const blink::WebMouseEvent& event) { … }
}
namespace input {
viz::HitTestQuery* GetHitTestQuery(viz::HitTestDataProvider* provider,
const viz::FrameSinkId& frame_sink_id) { … }
class TouchEventAckQueue { … };
void TouchEventAckQueue::Add(
const TouchEventWithLatencyInfo& touch_event,
RenderWidgetHostViewInput* target_view,
RenderWidgetHostViewInput* root_view,
TouchEventSource touch_event_source,
TouchEventAckStatus touch_event_ack_status,
blink::mojom::InputEventResultState ack_result) { … }
void TouchEventAckQueue::Add(
const TouchEventWithLatencyInfo& touch_event,
RenderWidgetHostViewInput* target_view,
RenderWidgetHostViewInput* root_view,
TouchEventSource touch_event_source) { … }
void TouchEventAckQueue::MarkAcked(
const TouchEventWithLatencyInfo& touch_event,
blink::mojom::InputEventResultState ack_result,
RenderWidgetHostViewInput* target_view) { … }
void TouchEventAckQueue::ProcessAckedTouchEvents() { … }
void TouchEventAckQueue::UpdateQueueAfterTargetDestroyed(
RenderWidgetHostViewInput* target_view) { … }
RenderWidgetHostInputEventRouter::TouchscreenPinchState::TouchscreenPinchState()
: … { … }
bool RenderWidgetHostInputEventRouter::TouchscreenPinchState::IsInPinch()
const { … }
bool RenderWidgetHostInputEventRouter::TouchscreenPinchState::
NeedsWrappingScrollSequence() const { … }
void RenderWidgetHostInputEventRouter::TouchscreenPinchState::
DidStartBubblingToRoot() { … }
void RenderWidgetHostInputEventRouter::TouchscreenPinchState::
DidStopBubblingToRoot() { … }
void RenderWidgetHostInputEventRouter::TouchscreenPinchState::
DidStartPinchInRoot() { … }
void RenderWidgetHostInputEventRouter::TouchscreenPinchState::
DidStartPinchInChild() { … }
void RenderWidgetHostInputEventRouter::TouchscreenPinchState::DidStopPinch() { … }
bool RenderWidgetHostInputEventRouter::HasEventsPendingDispatch() const { … }
size_t RenderWidgetHostInputEventRouter::TouchEventAckQueueLengthForTesting()
const { … }
size_t RenderWidgetHostInputEventRouter::RegisteredViewCountForTesting() const { … }
RenderWidgetHostViewInput*
RenderWidgetHostInputEventRouter::GetLastMouseMoveTargetForTest() { … }
RenderWidgetHostViewInput*
RenderWidgetHostInputEventRouter::GetLastMouseMoveRootViewForTest() { … }
void RenderWidgetHostInputEventRouter::OnRenderWidgetHostViewInputDestroyed(
RenderWidgetHostViewInput* view) { … }
void RenderWidgetHostInputEventRouter::ClearAllObserverRegistrations() { … }
RenderWidgetHostInputEventRouter::RenderWidgetHostInputEventRouter(
viz::HitTestDataProvider* provider,
Delegate* delegate)
: … { … }
RenderWidgetHostInputEventRouter::~RenderWidgetHostInputEventRouter() { … }
RenderWidgetTargetResult RenderWidgetHostInputEventRouter::FindMouseEventTarget(
RenderWidgetHostViewInput* root_view,
const blink::WebMouseEvent& event) const { … }
RenderWidgetTargetResult
RenderWidgetHostInputEventRouter::FindMouseWheelEventTarget(
RenderWidgetHostViewInput* root_view,
const blink::WebMouseWheelEvent& event) const { … }
RenderWidgetTargetResult RenderWidgetHostInputEventRouter::FindViewAtLocation(
RenderWidgetHostViewInput* root_view,
const gfx::PointF& point,
viz::EventSource source,
gfx::PointF* transformed_point) const { … }
void RenderWidgetHostInputEventRouter::RouteMouseEvent(
RenderWidgetHostViewInput* root_view,
const blink::WebMouseEvent* event,
const ui::LatencyInfo& latency) { … }
void RenderWidgetHostInputEventRouter::DispatchMouseEvent(
RenderWidgetHostViewInput* root_view,
RenderWidgetHostViewInput* target,
const blink::WebMouseEvent& mouse_event,
const ui::LatencyInfo& latency,
const std::optional<gfx::PointF>& target_location) { … }
void RenderWidgetHostInputEventRouter::RouteMouseWheelEvent(
RenderWidgetHostViewInput* root_view,
blink::WebMouseWheelEvent* event,
const ui::LatencyInfo& latency) { … }
static const char* PhaseToString(blink::WebMouseWheelEvent::Phase phase) { … }
void RenderWidgetHostInputEventRouter::DispatchMouseWheelEvent(
RenderWidgetHostViewInput* root_view,
RenderWidgetHostViewInput* target,
const blink::WebMouseWheelEvent& mouse_wheel_event,
const ui::LatencyInfo& latency,
const std::optional<gfx::PointF>& target_location) { … }
void RenderWidgetHostInputEventRouter::RouteGestureEvent(
RenderWidgetHostViewInput* root_view,
const blink::WebGestureEvent* event,
const ui::LatencyInfo& latency) { … }
namespace {
unsigned CountChangedTouchPoints(const blink::WebTouchEvent& event) { … }
}
void RenderWidgetHostInputEventRouter::OnHandledTouchStartOrFirstTouchMove(
uint32_t unique_touch_event_id) { … }
RenderWidgetTargetResult RenderWidgetHostInputEventRouter::FindTouchEventTarget(
RenderWidgetHostViewInput* root_view,
const blink::WebTouchEvent& event) { … }
void RenderWidgetHostInputEventRouter::DispatchTouchEvent(
RenderWidgetHostViewInput* root_view,
RenderWidgetHostViewInput* target,
const blink::WebTouchEvent& touch_event,
const ui::LatencyInfo& latency,
const std::optional<gfx::PointF>& target_location,
bool is_emulated_touchevent) { … }
void RenderWidgetHostInputEventRouter::ProcessAckedTouchEvent(
const TouchEventWithLatencyInfo& event,
blink::mojom::InputEventResultState ack_result,
RenderWidgetHostViewInput* view) { … }
void RenderWidgetHostInputEventRouter::RouteTouchEvent(
RenderWidgetHostViewInput* root_view,
blink::WebTouchEvent* event,
const ui::LatencyInfo& latency) { … }
void RenderWidgetHostInputEventRouter::SendMouseEnterOrLeaveEvents(
const blink::WebMouseEvent& event,
RenderWidgetHostViewInput* target,
RenderWidgetHostViewInput* root_view,
blink::WebInputEvent::Modifiers extra_modifiers,
bool include_target_view) { … }
void RenderWidgetHostInputEventRouter::ReportBubblingScrollToSameView(
const blink::WebGestureEvent& event,
const RenderWidgetHostViewInput* view) { … }
namespace {
bool IsAncestorView(RenderWidgetHostViewInput* starting_view,
const RenderWidgetHostViewInput* target_view,
const RenderWidgetHostViewInput* stay_within = nullptr) { … }
blink::WebGestureEvent GestureEventInTarget(
const blink::WebGestureEvent& event,
RenderWidgetHostViewInput* target_view) { … }
}
bool RenderWidgetHostInputEventRouter::BubbleScrollEvent(
RenderWidgetHostViewInput* target_view,
RenderWidgetHostViewInput* resending_view,
const blink::WebGestureEvent& event) { … }
void RenderWidgetHostInputEventRouter::SendGestureScrollBegin(
RenderWidgetHostViewInput* view,
const blink::WebGestureEvent& event) { … }
void RenderWidgetHostInputEventRouter::SendGestureScrollEnd(
RenderWidgetHostViewInput* view,
const blink::WebGestureEvent& event) { … }
void RenderWidgetHostInputEventRouter::SendGestureScrollEnd(
RenderWidgetHostViewInput* view,
blink::WebGestureDevice source_device) { … }
void RenderWidgetHostInputEventRouter::WillDetachChildView(
const RenderWidgetHostViewInput* detaching_view) { … }
void RenderWidgetHostInputEventRouter::CancelScrollBubbling() { … }
void RenderWidgetHostInputEventRouter::CancelScrollBubblingIfConflicting(
const RenderWidgetHostViewInput* target) { … }
void RenderWidgetHostInputEventRouter::StopFling() { … }
void RenderWidgetHostInputEventRouter::AddFrameSinkIdOwner(
const viz::FrameSinkId& id,
RenderWidgetHostViewInput* owner) { … }
void RenderWidgetHostInputEventRouter::RemoveFrameSinkIdOwner(
const viz::FrameSinkId& id) { … }
RenderWidgetHostViewInput*
RenderWidgetHostInputEventRouter::GetRenderWidgetHostViewInputAtPoint(
RenderWidgetHostViewInput* root_view,
const gfx::PointF& point,
gfx::PointF* transformed_point) { … }
void RenderWidgetHostInputEventRouter::GetRenderWidgetHostAtPointAsynchronously(
RenderWidgetHostViewInput* root_view,
const gfx::PointF& point,
RenderWidgetTargeter::RenderWidgetHostAtPointCallback callback) { … }
RenderWidgetTargetResult
RenderWidgetHostInputEventRouter::FindTouchscreenGestureEventTarget(
RenderWidgetHostViewInput* root_view,
const blink::WebGestureEvent& gesture_event) { … }
bool RenderWidgetHostInputEventRouter::IsViewInMap(
const RenderWidgetHostViewInput* view) const { … }
bool RenderWidgetHostInputEventRouter::ViewMapIsEmpty() const { … }
namespace {
bool IsPinchCurrentlyAllowedInTarget(RenderWidgetHostViewInput* target) { … }
}
void RenderWidgetHostInputEventRouter::DispatchTouchscreenGestureEvent(
RenderWidgetHostViewInput* root_view,
RenderWidgetHostViewInput* target,
const blink::WebGestureEvent& gesture_event,
const ui::LatencyInfo& latency,
const std::optional<gfx::PointF>& target_location) { … }
void RenderWidgetHostInputEventRouter::RouteTouchscreenGestureEvent(
RenderWidgetHostViewInput* root_view,
const blink::WebGestureEvent* event,
const ui::LatencyInfo& latency) { … }
RenderWidgetTargetResult
RenderWidgetHostInputEventRouter::FindTouchpadGestureEventTarget(
RenderWidgetHostViewInput* root_view,
const blink::WebGestureEvent& event) const { … }
void RenderWidgetHostInputEventRouter::RouteTouchpadGestureEvent(
RenderWidgetHostViewInput* root_view,
const blink::WebGestureEvent* event,
const ui::LatencyInfo& latency) { … }
void RenderWidgetHostInputEventRouter::DispatchTouchpadGestureEvent(
RenderWidgetHostViewInput* root_view,
RenderWidgetHostViewInput* target,
const blink::WebGestureEvent& touchpad_gesture_event,
const ui::LatencyInfo& latency,
const std::optional<gfx::PointF>& target_location) { … }
RenderWidgetHostViewInput*
RenderWidgetHostInputEventRouter::FindViewFromFrameSinkId(
const viz::FrameSinkId& frame_sink_id) const { … }
bool RenderWidgetHostInputEventRouter::ShouldContinueHitTesting(
RenderWidgetHostViewInput* target_view) const { … }
std::vector<RenderWidgetHostViewInput*>
RenderWidgetHostInputEventRouter::GetRenderWidgetHostViewInputsForTests()
const { … }
RenderWidgetTargeter*
RenderWidgetHostInputEventRouter::GetRenderWidgetTargeterForTests() { … }
RenderWidgetTargetResult
RenderWidgetHostInputEventRouter::FindTargetSynchronouslyAtPoint(
RenderWidgetHostViewInput* root_view,
const gfx::PointF& location) { … }
RenderWidgetTargetResult
RenderWidgetHostInputEventRouter::FindTargetSynchronously(
RenderWidgetHostViewInput* root_view,
const blink::WebInputEvent& event) { … }
void RenderWidgetHostInputEventRouter::SetEventsBeingFlushed(
bool events_being_flushed) { … }
void RenderWidgetHostInputEventRouter::SetTouchscreenGestureTarget(
RenderWidgetHostViewInput* target,
bool moved_recently,
bool moved_recently_for_iov2) { … }
void RenderWidgetHostInputEventRouter::ClearTouchscreenGestureTarget() { … }
void RenderWidgetHostInputEventRouter::DispatchEventToTarget(
RenderWidgetHostViewInput* root_view,
RenderWidgetHostViewInput* target,
blink::WebInputEvent* event,
const ui::LatencyInfo& latency,
const std::optional<gfx::PointF>& target_location) { … }
TouchEmulator* RenderWidgetHostInputEventRouter::GetTouchEmulator(
bool create_if_necessary) { … }
void RenderWidgetHostInputEventRouter::ForwardEmulatedGestureEvent(
const blink::WebGestureEvent& event) { … }
void RenderWidgetHostInputEventRouter::ForwardEmulatedTouchEvent(
const blink::WebTouchEvent& event,
RenderWidgetHostViewInput* target) { … }
void RenderWidgetHostInputEventRouter::SetCursor(const ui::Cursor& cursor) { … }
void RenderWidgetHostInputEventRouter::ShowContextMenuAtPoint(
const gfx::Point& point,
const ui::MenuSourceType source_type,
RenderWidgetHostViewInput* target) { … }
void RenderWidgetHostInputEventRouter::OnAggregatedHitTestRegionListUpdated(
const viz::FrameSinkId& frame_sink_id,
const std::vector<viz::AggregatedHitTestRegion>& hit_test_data) { … }
void RenderWidgetHostInputEventRouter::SetMouseCaptureTarget(
RenderWidgetHostViewInput* target,
bool capture) { … }
void RenderWidgetHostInputEventRouter::RootViewReceivesMouseUpIfNecessary(
bool root_view_receives_mouse_up) { … }
void RenderWidgetHostInputEventRouter::SetAutoScrollInProgress(
bool is_autoscroll_in_progress) { … }
bool IsMoveEvent(ui::EventType type) { … }
void RenderWidgetHostInputEventRouter::ForwardDelegatedInkPoint(
RenderWidgetHostViewInput* target_view,
RenderWidgetHostViewInput* root_view,
const blink::WebInputEvent& input_event,
const blink::WebPointerProperties& pointer_properties,
bool hovering) { … }
}