#include "components/input/input_router_impl.h"
#include <math.h>
#include <utility>
#include "base/auto_reset.h"
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "components/input/gesture_event_queue.h"
#include "components/input/web_touch_event_traits.h"
#include "components/input/input_disposition_handler.h"
#include "components/input/input_router_client.h"
#include "components/input/input_event_ack_state.h"
#include "services/tracing/public/cpp/perfetto/flow_event_utils.h"
#include "third_party/blink/public/common/input/web_coalesced_input_event.h"
#include "third_party/blink/public/mojom/input/input_event_result.mojom-shared.h"
#include "third_party/blink/public/mojom/input/input_handler.mojom-shared.h"
#include "third_party/blink/public/mojom/input/touch_event.mojom.h"
#include "ui/events/blink/blink_event_util.h"
#include "ui/events/blink/blink_features.h"
#include "ui/events/blink/did_overscroll_params.h"
#include "ui/events/blink/web_input_event_traits.h"
#include "ui/events/event.h"
#include "ui/events/keycodes/keyboard_codes.h"
namespace input {
WebGestureEvent;
WebInputEvent;
WebKeyboardEvent;
WebMouseEvent;
WebMouseWheelEvent;
WebTouchEvent;
ChromeLatencyInfo;
TrackEvent;
WebInputEventTraits;
namespace {
bool WasHandled(blink::mojom::InputEventResultState state) { … }
std::unique_ptr<blink::WebCoalescedInputEvent> ScaleEvent(
const WebInputEvent& event,
double scale,
const ui::LatencyInfo& latency_info) { … }
ChromeLatencyInfo::InputType GetInputTypeForLatencyInfo(
const WebInputEvent& input_event) { … }
}
InputRouterImpl::InputRouterImpl(
InputRouterClient* client,
InputDispositionHandler* disposition_handler,
FlingControllerSchedulerClient* fling_scheduler_client,
const Config& config)
: … { … }
InputRouterImpl::~InputRouterImpl() { … }
void InputRouterImpl::SendMouseEvent(
const MouseEventWithLatencyInfo& mouse_event,
MouseEventCallback event_result_callback) { … }
void InputRouterImpl::SendWheelEvent(
const MouseWheelEventWithLatencyInfo& wheel_event) { … }
void InputRouterImpl::SendKeyboardEvent(
const NativeWebKeyboardEventWithLatencyInfo& key_event,
KeyboardEventCallback event_result_callback) { … }
void InputRouterImpl::SendGestureEvent(
const GestureEventWithLatencyInfo& original_gesture_event) { … }
void InputRouterImpl::SendGestureEventWithoutQueueing(
GestureEventWithLatencyInfo& gesture_event,
const FilterGestureEventResult& existing_result) { … }
bool InputRouterImpl::HandleGestureScrollForStylusWriting(
const blink::WebGestureEvent& event) { … }
void InputRouterImpl::SendTouchEvent(
const TouchEventWithLatencyInfo& touch_event) { … }
void InputRouterImpl::NotifySiteIsMobileOptimized(bool is_mobile_optimized) { … }
bool InputRouterImpl::HasPendingEvents() const { … }
void InputRouterImpl::SetDeviceScaleFactor(float device_scale_factor) { … }
void InputRouterImpl::SetForceEnableZoom(bool enabled) { … }
std::optional<cc::TouchAction> InputRouterImpl::AllowedTouchAction() { … }
std::optional<cc::TouchAction> InputRouterImpl::ActiveTouchAction() { … }
mojo::PendingRemote<blink::mojom::WidgetInputHandlerHost>
InputRouterImpl::BindNewHost(
scoped_refptr<base::SequencedTaskRunner> task_runner) { … }
void InputRouterImpl::StopFling() { … }
void InputRouterImpl::ProcessDeferredGestureEventQueue() { … }
void InputRouterImpl::SetTouchActionFromMain(cc::TouchAction touch_action) { … }
void InputRouterImpl::SetPanAction(blink::mojom::PanAction pan_action) { … }
void InputRouterImpl::OnSetCompositorAllowedTouchAction(
cc::TouchAction touch_action) { … }
void InputRouterImpl::DidOverscroll(
blink::mojom::DidOverscrollParamsPtr params) { … }
void InputRouterImpl::DidStartScrollingViewport() { … }
void InputRouterImpl::ImeCancelComposition() { … }
void InputRouterImpl::ImeCompositionRangeChanged(
const gfx::Range& range,
const std::optional<std::vector<gfx::Rect>>& character_bounds,
const std::optional<std::vector<gfx::Rect>>& line_bounds) { … }
void InputRouterImpl::SetMouseCapture(bool capture) { … }
void InputRouterImpl::SetAutoscrollSelectionActiveInMainFrame(
bool autoscroll_selection) { … }
void InputRouterImpl::RequestMouseLock(bool from_user_gesture,
bool unadjusted_movement,
RequestMouseLockCallback response) { … }
void InputRouterImpl::SetMovementXYForTouchPoints(blink::WebTouchEvent* event) { … }
void InputRouterImpl::SendMouseEventImmediately(
const MouseEventWithLatencyInfo& mouse_event,
MouseEventCallback event_result_callback) { … }
void InputRouterImpl::SendTouchEventImmediately(
const TouchEventWithLatencyInfo& touch_event) { … }
void InputRouterImpl::FlushDeferredGestureQueue() { … }
void InputRouterImpl::OnTouchEventAck(
const TouchEventWithLatencyInfo& event,
blink::mojom::InputEventResultSource ack_source,
blink::mojom::InputEventResultState ack_result) { … }
void InputRouterImpl::OnFilteringTouchEvent(const WebTouchEvent& touch_event) { … }
void InputRouterImpl::SendGestureEventImmediately(
const GestureEventWithLatencyInfo& gesture_event) { … }
void InputRouterImpl::OnGestureEventAck(
const GestureEventWithLatencyInfo& event,
blink::mojom::InputEventResultSource ack_source,
blink::mojom::InputEventResultState ack_result) { … }
void InputRouterImpl::SendGeneratedWheelEvent(
const MouseWheelEventWithLatencyInfo& wheel_event) { … }
void InputRouterImpl::SendGeneratedGestureScrollEvents(
const GestureEventWithLatencyInfo& gesture_event) { … }
gfx::Size InputRouterImpl::GetRootWidgetViewportSize() { … }
void InputRouterImpl::SendMouseWheelEventImmediately(
const MouseWheelEventWithLatencyInfo& wheel_event,
MouseWheelEventQueueClient::MouseWheelEventHandledCallback
callee_callback) { … }
void InputRouterImpl::OnMouseWheelEventAck(
const MouseWheelEventWithLatencyInfo& event,
blink::mojom::InputEventResultSource ack_source,
blink::mojom::InputEventResultState ack_result) { … }
void InputRouterImpl::ForwardGestureEventWithLatencyInfo(
const blink::WebGestureEvent& event,
const ui::LatencyInfo& latency_info) { … }
void InputRouterImpl::SendMouseWheelEventForPinchImmediately(
const MouseWheelEventWithLatencyInfo& event,
TouchpadPinchEventQueueClient::MouseWheelEventHandledCallback callback) { … }
void InputRouterImpl::OnGestureEventForPinchAck(
const GestureEventWithLatencyInfo& event,
blink::mojom::InputEventResultSource ack_source,
blink::mojom::InputEventResultState ack_result) { … }
bool InputRouterImpl::IsWheelScrollInProgress() { … }
bool InputRouterImpl::IsAutoscrollInProgress() { … }
void InputRouterImpl::FilterAndSendWebInputEvent(
const WebInputEvent& input_event,
const ui::LatencyInfo& latency_info,
blink::mojom::WidgetInputHandler::DispatchEventCallback callback) { … }
void InputRouterImpl::KeyboardEventHandled(
const NativeWebKeyboardEventWithLatencyInfo& event,
KeyboardEventCallback event_result_callback,
blink::mojom::InputEventResultSource source,
const ui::LatencyInfo& latency,
blink::mojom::InputEventResultState state,
blink::mojom::DidOverscrollParamsPtr overscroll,
blink::mojom::TouchActionOptionalPtr touch_action) { … }
void InputRouterImpl::MouseEventHandled(
const MouseEventWithLatencyInfo& event,
MouseEventCallback event_result_callback,
blink::mojom::InputEventResultSource source,
const ui::LatencyInfo& latency,
blink::mojom::InputEventResultState state,
blink::mojom::DidOverscrollParamsPtr overscroll,
blink::mojom::TouchActionOptionalPtr touch_action) { … }
void InputRouterImpl::TouchEventHandled(
const TouchEventWithLatencyInfo& touch_event,
blink::mojom::InputEventResultSource source,
const ui::LatencyInfo& latency,
blink::mojom::InputEventResultState state,
blink::mojom::DidOverscrollParamsPtr overscroll,
blink::mojom::TouchActionOptionalPtr touch_action) { … }
void InputRouterImpl::GestureEventHandled(
const GestureEventWithLatencyInfo& gesture_event,
blink::mojom::InputEventResultSource source,
const ui::LatencyInfo& latency,
blink::mojom::InputEventResultState state,
blink::mojom::DidOverscrollParamsPtr overscroll,
blink::mojom::TouchActionOptionalPtr touch_action) { … }
void InputRouterImpl::MouseWheelEventHandled(
const MouseWheelEventWithLatencyInfo& event,
MouseWheelEventQueueClient::MouseWheelEventHandledCallback callback,
blink::mojom::InputEventResultSource source,
const ui::LatencyInfo& latency,
blink::mojom::InputEventResultState state,
blink::mojom::DidOverscrollParamsPtr overscroll,
blink::mojom::TouchActionOptionalPtr touch_action) { … }
void InputRouterImpl::OnHasTouchEventConsumers(
blink::mojom::TouchEventConsumersPtr consumers) { … }
void InputRouterImpl::WaitForInputProcessed(base::OnceClosure callback) { … }
void InputRouterImpl::ForceSetTouchActionAuto() { … }
void InputRouterImpl::ForceResetTouchActionForTest() { … }
bool InputRouterImpl::IsFlingActiveForTest() { … }
void InputRouterImpl::UpdateTouchAckTimeoutEnabled() { … }
}