chromium/third_party/blink/renderer/core/input/event_handler.cc

/*
 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights
 * reserved.
 * Copyright (C) 2006 Alexey Proskuryakov ([email protected])
 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies)
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#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 {

// Refetch the event target node if it is removed or currently is the shadow
// node inside an <input> element.  If a mouse event handler changes the input
// element type to one that has a EmbeddedContentView associated, we'd like to
// EventHandler::handleMousePressEvent to pass the event to the
// EmbeddedContentView and thus the event target node can't still be the shadow
// node.
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) {}

// Returns whether the hit element contains a title and isn't a SVGUseElement or
// part of an SVGUseElement.
bool HasTitleAndNotSVGUseElement(const HitTestResult& hovered_node_result) {}

// Get the entire style of scrollbar to get the cursor style of scrollbar
const ComputedStyle* GetComputedStyleFromScrollbar(
    const LayoutObject& layout_object,
    const HitTestResult& result) {}

}  // namespace

// The amount of time to wait for a cursor update on style and layout changes
// Set to 50Hz, no need to be faster than common screen refresh rate
static constexpr base::TimeDelta kCursorUpdateInterval =;

// The maximum size a cursor can be without falling back to the default cursor
// when intersecting browser native UI.
// https://developer.mozilla.org/en-US/docs/Web/CSS/cursor#icon_size_limits.
static const int kMaximumCursorSizeWithoutFallback =;

// The minimum amount of time an element stays active after a ShowPress
// This is roughly 9 frames, which should be long enough to be noticeable.
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() {}

// TODO(bokan): This should be merged with logicalScroll assuming
// defaultSpaceEventHandler's chaining scroll can be done crossing frames.
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) {}

// TODO(crbug.com/665924): This function bypasses all Handle*Event path.
// It should be using that flow instead of creating/sending events directly.
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) {}

// Update the hover and active state across all frames.  This logic is
// different than the mouse case because mice send MouseLeave events to frames
// as they're exited.  With gestures or manual applications, a single event
// conceptually both 'leaves' whatever frame currently had hover and enters a
// new frame so we need to update state in the old frame chain as well.
void EventHandler::UpdateCrossFrameHoverActiveState(bool is_active,
                                                    Element* inner_element) {}

// Update the mouseover/mouseenter/mouseout/mouseleave events across all frames
// for this gesture, before passing the targeted gesture event directly to a hit
// frame.
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) {}

// If scrollbar (under mouse) is different from last, send a mouse exited. Set
// last to scrollbar if setLast is true; else set last to 0.
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() {}

}  // namespace blink