#include "third_party/blink/renderer/core/input/event_handler.h"
#include <memory>
#include <utility>
#include "base/check.h"
#include "build/build_config.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 "third_party/blink/public/mojom/frame/user_activation_notification_type.mojom-blink.h"
#include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom-blink.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/public/web/web_link_preview_triggerer.h"
#include "third_party/blink/renderer/core/clipboard/data_transfer.h"
#include "third_party/blink/renderer/core/css/style_engine.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/flat_tree_traversal.h"
#include "third_party/blink/renderer/core/dom/shadow_root.h"
#include "third_party/blink/renderer/core/editing/editing_utilities.h"
#include "third_party/blink/renderer/core/editing/editor.h"
#include "third_party/blink/renderer/core/editing/frame_selection.h"
#include "third_party/blink/renderer/core/editing/local_caret_rect.h"
#include "third_party/blink/renderer/core/editing/selection_controller.h"
#include "third_party/blink/renderer/core/editing/selection_template.h"
#include "third_party/blink/renderer/core/editing/text_affinity.h"
#include "third_party/blink/renderer/core/editing/visible_selection.h"
#include "third_party/blink/renderer/core/events/keyboard_event.h"
#include "third_party/blink/renderer/core/events/mouse_event.h"
#include "third_party/blink/renderer/core/events/pointer_event.h"
#include "third_party/blink/renderer/core/events/pointer_event_factory.h"
#include "third_party/blink/renderer/core/events/text_event.h"
#include "third_party/blink/renderer/core/events/touch_event.h"
#include "third_party/blink/renderer/core/frame/event_handler_registry.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/frame/visual_viewport.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html/html_dialog_element.h"
#include "third_party/blink/renderer/core/html/html_frame_element_base.h"
#include "third_party/blink/renderer/core/html/html_frame_set_element.h"
#include "third_party/blink/renderer/core/input/event_handling_util.h"
#include "third_party/blink/renderer/core/input/input_device_capabilities.h"
#include "third_party/blink/renderer/core/input_type_names.h"
#include "third_party/blink/renderer/core/layout/custom_scrollbar.h"
#include "third_party/blink/renderer/core/layout/geometry/physical_offset.h"
#include "third_party/blink/renderer/core/layout/hit_test_request.h"
#include "third_party/blink/renderer/core/layout/hit_test_result.h"
#include "third_party/blink/renderer/core/layout/layout_box.h"
#include "third_party/blink/renderer/core/layout/layout_custom_scrollbar_part.h"
#include "third_party/blink/renderer/core/layout/layout_embedded_content.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/loader/anchor_element_interaction_tracker.h"
#include "third_party/blink/renderer/core/loader/resource/image_resource_content.h"
#include "third_party/blink/renderer/core/page/autoscroll_controller.h"
#include "third_party/blink/renderer/core/page/chrome_client.h"
#include "third_party/blink/renderer/core/page/drag_state.h"
#include "third_party/blink/renderer/core/page/frame_tree.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/page/touch_adjustment.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/core/paint/paint_layer_scrollable_area.h"
#include "third_party/blink/renderer/core/scroll/scroll_types.h"
#include "third_party/blink/renderer/core/scroll/scrollbar.h"
#include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/core/style/computed_style_base_constants.h"
#include "third_party/blink/renderer/core/style/cursor_data.h"
#include "third_party/blink/renderer/core/svg/graphics/svg_image_for_container.h"
#include "third_party/blink/renderer/core/svg/svg_use_element.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/cursors.h"
#include "third_party/blink/renderer/platform/geometry/layout_unit.h"
#include "third_party/blink/renderer/platform/graphics/image_orientation.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cancellable_task.h"
#include "third_party/blink/renderer/platform/windows_keyboard_codes.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/cursor/mojom/cursor_type.mojom-blink.h"
#include "ui/base/dragdrop/mojom/drag_drop_types.mojom-blink.h"
#include "ui/display/screen_info.h"
#include "ui/display/screen_infos.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/geometry/size_f.h"
namespace blink {
FormControlType;
namespace {
bool ShouldRefetchEventTarget(const MouseEventWithHitTestResults& mev) { … }
gfx::Point GetMiddleSelectionCaretOfPosition(
const PositionWithAffinity& position) { … }
bool ContainsEvenAtEdge(const gfx::Rect& rect, const gfx::Point& point) { … }
gfx::Point DetermineHotSpot(const Image& image,
bool hot_spot_specified,
const gfx::Point& specified_hot_spot) { … }
bool HasTitleAndNotSVGUseElement(const HitTestResult& hovered_node_result) { … }
const ComputedStyle* GetComputedStyleFromScrollbar(
const LayoutObject& layout_object,
const HitTestResult& result) { … }
}
static constexpr base::TimeDelta kCursorUpdateInterval = …;
static const int kMaximumCursorSizeWithoutFallback = …;
constexpr base::TimeDelta kMinimumActiveInterval = …;
EventHandler::EventHandler(LocalFrame& frame)
: … { … }
void EventHandler::Trace(Visitor* visitor) const { … }
void EventHandler::Clear() { … }
void EventHandler::UpdateSelectionForMouseDrag() { … }
void EventHandler::StartMiddleClickAutoscroll(LayoutObject* layout_object) { … }
void EventHandler::PerformHitTest(const HitTestLocation& location,
HitTestResult& result,
bool no_lifecycle_update) const { … }
HitTestResult EventHandler::HitTestResultAtLocation(
const HitTestLocation& location,
HitTestRequest::HitTestRequestType hit_type,
const LayoutObject* stop_node,
bool no_lifecycle_update,
std::optional<HitTestRequest::HitNodeCb> hit_node_cb) { … }
void EventHandler::StopAutoscroll() { … }
bool EventHandler::BubblingScroll(mojom::blink::ScrollDirection direction,
ui::ScrollGranularity granularity,
Node* starting_node) { … }
gfx::PointF EventHandler::LastKnownMousePositionInRootFrame() const { … }
gfx::PointF EventHandler::LastKnownMouseScreenPosition() const { … }
gfx::Point EventHandler::DragDataTransferLocationForTesting() { … }
static bool IsSubmitImage(const Node* node) { … }
bool EventHandler::UsesHandCursor(const Node* node) { … }
void EventHandler::CursorUpdateTimerFired(TimerBase*) { … }
void EventHandler::UpdateCursor() { … }
bool EventHandler::ShouldShowResizeForNode(const LayoutObject& layout_object,
const HitTestLocation& location) { … }
bool EventHandler::IsSelectingLink(const HitTestResult& result) { … }
bool EventHandler::ShouldShowIBeamForNode(const Node* node,
const HitTestResult& result) { … }
std::optional<ui::Cursor> EventHandler::SelectCursor(
const HitTestLocation& location,
const HitTestResult& result) { … }
std::optional<ui::Cursor> EventHandler::SelectAutoCursor(
const HitTestResult& result,
Node* node,
const ui::Cursor& i_beam) { … }
WebInputEventResult EventHandler::DispatchBufferedTouchEvents() { … }
WebInputEventResult EventHandler::HandlePointerEvent(
const WebPointerEvent& web_pointer_event,
const Vector<WebPointerEvent>& coalesced_events,
const Vector<WebPointerEvent>& predicted_events) { … }
WebInputEventResult EventHandler::HandleMousePressEvent(
const WebMouseEvent& mouse_event) { … }
WebInputEventResult EventHandler::HandleMouseMoveEvent(
const WebMouseEvent& event,
const Vector<WebMouseEvent>& coalesced_events,
const Vector<WebMouseEvent>& predicted_events) { … }
void EventHandler::HandleMouseLeaveEvent(const WebMouseEvent& event) { … }
WebInputEventResult EventHandler::HandleMouseMoveOrLeaveEvent(
const WebMouseEvent& mouse_event,
const Vector<WebMouseEvent>& coalesced_events,
const Vector<WebMouseEvent>& predicted_events,
HitTestResult* hovered_node_result,
HitTestLocation* hit_test_location) { … }
WebInputEventResult EventHandler::HandleMouseReleaseEvent(
const WebMouseEvent& mouse_event) { … }
static LocalFrame* LocalFrameFromTargetNode(Node* target) { … }
WebInputEventResult EventHandler::UpdateDragAndDrop(
const WebMouseEvent& event,
DataTransfer* data_transfer) { … }
void EventHandler::CancelDragAndDrop(const WebMouseEvent& event,
DataTransfer* data_transfer) { … }
WebInputEventResult EventHandler::PerformDragAndDrop(
const WebMouseEvent& event,
DataTransfer* data_transfer) { … }
void EventHandler::ClearDragState() { … }
void EventHandler::RecomputeMouseHoverStateIfNeeded() { … }
void EventHandler::MarkHoverStateDirty() { … }
Element* EventHandler::EffectiveMouseEventTargetElement(
Element* target_element) { … }
void EventHandler::OnScrollbarDestroyed(const Scrollbar& scrollbar) { … }
Element* EventHandler::GetElementUnderMouse() { … }
Element* EventHandler::CurrentTouchDownElement() { … }
void EventHandler::SetDelayedNavigationTaskHandle(TaskHandle task_handle) { … }
TaskHandle& EventHandler::GetDelayedNavigationTaskHandle() { … }
bool EventHandler::IsPointerIdActiveOnFrame(PointerId pointer_id,
LocalFrame* frame) const { … }
bool EventHandler::RootFrameTrackedActivePointerInCurrentFrame(
PointerId pointer_id) const { … }
bool EventHandler::IsPointerEventActive(PointerId pointer_id) { … }
LocalFrame* EventHandler::DetermineActivePointerTrackerFrame(
PointerId pointer_id) const { … }
void EventHandler::SetPointerCapture(PointerId pointer_id,
Element* target,
bool explicit_capture) { … }
void EventHandler::ReleasePointerCapture(PointerId pointer_id,
Element* target) { … }
void EventHandler::ReleaseMousePointerCapture() { … }
bool EventHandler::HasPointerCapture(PointerId pointer_id,
const Element* target) const { … }
void EventHandler::ElementRemoved(Element* target) { … }
void EventHandler::ResetMousePositionForPointerUnlock() { … }
bool EventHandler::LongTapShouldInvokeContextMenu() { … }
WebInputEventResult EventHandler::DispatchMousePointerEvent(
const WebInputEvent::Type event_type,
Element* target_element,
const WebMouseEvent& mouse_event,
const Vector<WebMouseEvent>& coalesced_events,
const Vector<WebMouseEvent>& predicted_events,
bool skip_click_dispatch) { … }
WebInputEventResult EventHandler::HandleWheelEvent(
const WebMouseWheelEvent& event) { … }
WebInputEventResult EventHandler::HandleTargetedMouseEvent(
Element* target,
const WebMouseEvent& event,
const AtomicString& mouse_event_type,
const Vector<WebMouseEvent>& coalesced_events,
const Vector<WebMouseEvent>& predicted_events) { … }
WebInputEventResult EventHandler::HandleGestureEvent(
const WebGestureEvent& gesture_event) { … }
WebInputEventResult EventHandler::HandleGestureEvent(
const GestureEventWithHitTestResults& targeted_event) { … }
WebInputEventResult EventHandler::HandleGestureEventInFrame(
const GestureEventWithHitTestResults& targeted_event) { … }
void EventHandler::SetMouseDownMayStartAutoscroll() { … }
bool EventHandler::ShouldApplyTouchAdjustment(
const WebGestureEvent& event) const { … }
void EventHandler::CacheTouchAdjustmentResult(uint32_t id,
gfx::PointF adjusted_point) { … }
bool EventHandler::GestureCorrespondsToAdjustedTouch(
const WebGestureEvent& event) { … }
bool EventHandler::BestNodeForHitTestResult(
TouchAdjustmentCandidateType candidate_type,
const HitTestLocation& location,
const HitTestResult& result,
gfx::Point& adjusted_point,
Node*& adjusted_node) { … }
void EventHandler::UpdateCrossFrameHoverActiveState(bool is_active,
Element* inner_element) { … }
void EventHandler::UpdateGestureTargetNodeForMouseEvent(
const GestureEventWithHitTestResults& targeted_event) { … }
GestureEventWithHitTestResults EventHandler::TargetGestureEvent(
const WebGestureEvent& gesture_event,
bool read_only) { … }
GestureEventWithHitTestResults EventHandler::HitTestResultForGestureEvent(
const WebGestureEvent& gesture_event,
HitTestRequest::HitTestRequestType hit_type) { … }
void EventHandler::ApplyTouchAdjustment(WebGestureEvent* gesture_event,
HitTestLocation& location,
HitTestResult& hit_test_result) { … }
WebInputEventResult EventHandler::SendContextMenuEvent(
const WebMouseEvent& event,
Element* override_target_element) { … }
static bool ShouldShowContextMenuAtSelection(const FrameSelection& selection) { … }
WebInputEventResult EventHandler::ShowNonLocatedContextMenu(
Element* override_target_element,
WebMenuSourceType source_type) { … }
gfx::Rect EventHandler::GetFocusedElementRectForNonLocatedContextMenu(
Element* focused_element) { … }
void EventHandler::ScheduleHoverStateUpdate() { … }
void EventHandler::ScheduleCursorUpdate() { … }
bool EventHandler::CursorUpdatePending() { … }
bool EventHandler::IsHandlingKeyEvent() const { … }
void EventHandler::SetResizingFrameSet(HTMLFrameSetElement* frame_set) { … }
void EventHandler::ResizeScrollableAreaDestroyed() { … }
void EventHandler::HoverTimerFired(TimerBase*) { … }
void EventHandler::ActiveIntervalTimerFired(TimerBase*) { … }
void EventHandler::NotifyElementActivated() { … }
bool EventHandler::HandleAccessKey(const WebKeyboardEvent& evt) { … }
WebInputEventResult EventHandler::KeyEvent(
const WebKeyboardEvent& initial_key_event) { … }
void EventHandler::DefaultKeyboardEventHandler(KeyboardEvent* event) { … }
void EventHandler::DragSourceEndedAt(
const WebMouseEvent& event,
ui::mojom::blink::DragOperation operation) { … }
void EventHandler::UpdateDragStateAfterEditDragIfNeeded(
Element* root_editable_element) { … }
bool EventHandler::HandleTextInputEvent(const String& text,
Event* underlying_event,
TextEventInputType input_type) { … }
void EventHandler::DefaultTextInputEventHandler(TextEvent* event) { … }
void EventHandler::CapsLockStateMayHaveChanged() { … }
bool EventHandler::PassMousePressEventToScrollbar(
MouseEventWithHitTestResults& mev) { … }
void EventHandler::UpdateLastScrollbarUnderMouse(Scrollbar* scrollbar,
bool set_last) { … }
WebInputEventResult EventHandler::PassMousePressEventToSubframe(
MouseEventWithHitTestResults& mev,
LocalFrame* subframe) { … }
WebInputEventResult EventHandler::PassMouseMoveEventToSubframe(
MouseEventWithHitTestResults& mev,
const Vector<WebMouseEvent>& coalesced_events,
const Vector<WebMouseEvent>& predicted_events,
LocalFrame* subframe,
HitTestResult* hovered_node,
HitTestLocation* hit_test_location) { … }
WebInputEventResult EventHandler::PassMouseReleaseEventToSubframe(
MouseEventWithHitTestResults& mev,
LocalFrame* subframe) { … }
void EventHandler::CaptureMouseEventsToWidget(bool capture) { … }
MouseEventWithHitTestResults EventHandler::GetMouseEventTarget(
const HitTestRequest& request,
const WebMouseEvent& event) { … }
void EventHandler::ReleaseMouseCaptureFromLocalRoot() { … }
void EventHandler::ReleaseMouseCaptureFromCurrentFrame() { … }
base::debug::CrashKeyString* EventHandler::CrashKeyForBug1519197() const { … }
void EventHandler::ResetLastMousePositionForWebTest() { … }
}