Changeset 245062 in webkit


Ignore:
Timestamp:
May 8, 2019 12:36:33 PM (5 years ago)
Author:
Wenson Hsieh
Message:

[iOS] Add a quirk to synthesize mouse events when modifying the selection
https://bugs.webkit.org/show_bug.cgi?id=197683
<rdar://problem/48003980>

Reviewed by Tim Horton.

Source/WebCore:

See WebKit ChangeLog for more details.

Test: editing/selection/ios/dispatch-mouse-events-when-modifying-selection-quirk.html

  • page/EventHandler.cpp:

(WebCore::EventHandler::handleMousePressEvent):
(WebCore::EventHandler::supportsSelectionUpdatesOnMouseDrag const):

Add some platform hooks to prevent mousemove events from updating the selection on iOS.

(WebCore::EventHandler::shouldAllowMouseDownToStartDrag const):

Add some platform hooks to prevent drag and drop from kicking in when sending synthetic mousemove events to the
page on iOS (drag and drop is instead triggered by EventHandler::tryToBeginDragAtPoint).

(WebCore::EventHandler::updateSelectionForMouseDrag):

  • page/EventHandler.h:
  • page/Quirks.cpp:

(WebCore::Quirks::shouldDispatchSyntheticMouseEventsWhenModifyingSelection const):

  • page/Quirks.h:

Add the new site-specific quirk.

  • page/Settings.yaml:
  • page/ios/EventHandlerIOS.mm:

(WebCore::EventHandler::tryToBeginDragAtPoint):
(WebCore::EventHandler::supportsSelectionUpdatesOnMouseDrag const):
(WebCore::EventHandler::shouldAllowMouseDownToStartDrag const):

  • testing/InternalSettings.cpp:

(WebCore::InternalSettings::Backup::Backup):
(WebCore::InternalSettings::Backup::restoreTo):
(WebCore::InternalSettings::setShouldDispatchSyntheticMouseEventsWhenModifyingSelection):

  • testing/InternalSettings.h:
  • testing/InternalSettings.idl:

Add an internal settings hook to opt into this quirk, for use in layout tests.

Source/WebKit:

Introduces support for dispatching synthetic mouse events when modifying the selection on some websites. See
below for more details.

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::selectAll):

  • UIProcess/WebPageProxy.h:

Instead of executing a "SelectAll" editing command using the generic WebPage::executeEditCommand method,
introduce a separate method for selectAll that executes the "SelectAll" edit command and then does some
platform-specific work. See platformDidSelectAll.

  • UIProcess/ios/WKContentViewInteraction.mm:

(-[WKContentView selectAllForWebView:]):

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::selectAll):
(WebKit::WebPage::shouldDispatchSyntheticMouseEventsWhenModifyingSelection const):

Add a helper method to determine whether the quirk should be enabled.

(WebKit::WebPage::platformDidSelectAll):

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/WebPage.messages.in:
  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::elementRectInRootViewCoordinates):

Move this function closer to the top of the file so that it can be used in
dispatchSyntheticMouseEventsForSelectionGesture.

(WebKit::WebPage::clearSelection):
(WebKit::WebPage::dispatchSyntheticMouseEventsForSelectionGesture):

Add a helper method to dispatch a synthetic mouse event for a given selection gesture type. Used in several
places in WebPageIOS to synthesize and dispatch mouse events during selection.

(WebKit::WebPage::updateSelectionWithTouches):

When changing the selection with selection handles, fake mousedown when the user first touches down on the
selection handle; mousemove as the user is moving the handle around; and finally, mouseup when the user lets go.

(WebKit::WebPage::extendSelection):
(WebKit::WebPage::platformDidSelectAll):

When tapping "Select All" and/or "Select" in the callout menu, fake a mousedown at the selection start, then a
mousemove at selection end, and finally, a mouseup at selection end.

(WebKit::WebPage::getFocusedElementInformation):

LayoutTests:

Adds a new layout test to enable the site-specific quirk and verify that mouse events are dispatched when
changing selection, both via the callout menu and by moving the selection grabber using gestures.

  • editing/selection/ios/dispatch-mouse-events-when-modifying-selection-quirk-expected.txt: Added.
  • editing/selection/ios/dispatch-mouse-events-when-modifying-selection-quirk.html: Added.
  • resources/ui-helper.js:

(window.UIHelper.waitForMenuToHide.return.new.Promise):
(window.UIHelper.waitForMenuToHide):

Introduce a new helper method to wait for the menu to hide (on iOS, this refers to the callout menu).

Location:
trunk
Files:
2 added
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r245059 r245062  
     12019-05-08  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [iOS] Add a quirk to synthesize mouse events when modifying the selection
     4        https://bugs.webkit.org/show_bug.cgi?id=197683
     5        <rdar://problem/48003980>
     6
     7        Reviewed by Tim Horton.
     8
     9        Adds a new layout test to enable the site-specific quirk and verify that mouse events are dispatched when
     10        changing selection, both via the callout menu and by moving the selection grabber using gestures.
     11
     12        * editing/selection/ios/dispatch-mouse-events-when-modifying-selection-quirk-expected.txt: Added.
     13        * editing/selection/ios/dispatch-mouse-events-when-modifying-selection-quirk.html: Added.
     14        * resources/ui-helper.js:
     15        (window.UIHelper.waitForMenuToHide.return.new.Promise):
     16        (window.UIHelper.waitForMenuToHide):
     17
     18        Introduce a new helper method to wait for the menu to hide (on iOS, this refers to the callout menu).
     19
    1202019-05-07  Ryan Haddad  <ryanhaddad@apple.com>
    221
  • trunk/LayoutTests/resources/ui-helper.js

    r244370 r245062  
    828828    }
    829829
     830    static waitForMenuToHide()
     831    {
     832        return new Promise(resolve => {
     833            testRunner.runUIScript(`
     834                (function() {
     835                    if (uiController.isShowingMenu)
     836                        uiController.didHideMenuCallback = () => uiController.uiScriptComplete();
     837                    else
     838                        uiController.uiScriptComplete();
     839                })()`, resolve);
     840        });
     841    }
     842
    830843    static isShowingMenu()
    831844    {
  • trunk/Source/WebCore/ChangeLog

    r245058 r245062  
     12019-05-08  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [iOS] Add a quirk to synthesize mouse events when modifying the selection
     4        https://bugs.webkit.org/show_bug.cgi?id=197683
     5        <rdar://problem/48003980>
     6
     7        Reviewed by Tim Horton.
     8
     9        See WebKit ChangeLog for more details.
     10
     11        Test: editing/selection/ios/dispatch-mouse-events-when-modifying-selection-quirk.html
     12
     13        * page/EventHandler.cpp:
     14        (WebCore::EventHandler::handleMousePressEvent):
     15        (WebCore::EventHandler::supportsSelectionUpdatesOnMouseDrag const):
     16
     17        Add some platform hooks to prevent mousemove events from updating the selection on iOS.
     18
     19        (WebCore::EventHandler::shouldAllowMouseDownToStartDrag const):
     20
     21        Add some platform hooks to prevent drag and drop from kicking in when sending synthetic mousemove events to the
     22        page on iOS (drag and drop is instead triggered by EventHandler::tryToBeginDragAtPoint).
     23
     24        (WebCore::EventHandler::updateSelectionForMouseDrag):
     25        * page/EventHandler.h:
     26        * page/Quirks.cpp:
     27        (WebCore::Quirks::shouldDispatchSyntheticMouseEventsWhenModifyingSelection const):
     28        * page/Quirks.h:
     29
     30        Add the new site-specific quirk.
     31
     32        * page/Settings.yaml:
     33        * page/ios/EventHandlerIOS.mm:
     34        (WebCore::EventHandler::tryToBeginDragAtPoint):
     35        (WebCore::EventHandler::supportsSelectionUpdatesOnMouseDrag const):
     36        (WebCore::EventHandler::shouldAllowMouseDownToStartDrag const):
     37        * testing/InternalSettings.cpp:
     38        (WebCore::InternalSettings::Backup::Backup):
     39        (WebCore::InternalSettings::Backup::restoreTo):
     40        (WebCore::InternalSettings::setShouldDispatchSyntheticMouseEventsWhenModifyingSelection):
     41        * testing/InternalSettings.h:
     42        * testing/InternalSettings.idl:
     43
     44        Add an internal settings hook to opt into this quirk, for use in layout tests.
     45
    1462019-05-08  Simon Fraser  <simon.fraser@apple.com>
    247
  • trunk/Source/WebCore/page/EventHandler.cpp

    r244440 r245062  
    777777    // Single mouse down on links or images can always trigger drag-n-drop.
    778778    bool isMouseDownOnLinkOrImage = event.isOverLink() || event.hitTestResult().image();
    779     m_mouseDownMayStartDrag = singleClick && (!event.event().shiftKey() || isMouseDownOnLinkOrImage);
     779    m_mouseDownMayStartDrag = singleClick && (!event.event().shiftKey() || isMouseDownOnLinkOrImage) && shouldAllowMouseDownToStartDrag();
    780780#endif
    781781
     
    848848
    849849#if ENABLE(DRAG_SUPPORT)
     850
     851#if !PLATFORM(IOS_FAMILY)
     852
     853bool EventHandler::supportsSelectionUpdatesOnMouseDrag() const
     854{
     855    return true;
     856}
     857
     858bool EventHandler::shouldAllowMouseDownToStartDrag() const
     859{
     860    return true;
     861}
     862
     863#endif
     864
    850865bool EventHandler::handleMouseDraggedEvent(const MouseEventWithHitTestResults& event, CheckDragHysteresis checkDragHysteresis)
    851866{
     
    927942void EventHandler::updateSelectionForMouseDrag()
    928943{
     944    if (!supportsSelectionUpdatesOnMouseDrag())
     945        return;
     946
    929947    FrameView* view = m_frame.view();
    930948    if (!view)
     
    942960void EventHandler::updateSelectionForMouseDrag(const HitTestResult& hitTestResult)
    943961{
     962    if (!supportsSelectionUpdatesOnMouseDrag())
     963        return;
     964
    944965    if (!m_mouseDownMayStartSelect)
    945966        return;
  • trunk/Source/WebCore/page/EventHandler.h

    r243043 r245062  
    366366#if ENABLE(DRAG_SUPPORT)
    367367    bool handleMouseDraggedEvent(const MouseEventWithHitTestResults&, CheckDragHysteresis = ShouldCheckDragHysteresis);
     368    bool shouldAllowMouseDownToStartDrag() const;
    368369#endif
    369370
     
    458459#if ENABLE(DRAG_SUPPORT)
    459460    DragSourceAction updateDragSourceActionsAllowed() const;
     461    bool supportsSelectionUpdatesOnMouseDrag() const;
    460462#endif
    461463
     
    617619    bool m_isHandlingWheelEvent { false };
    618620
     621#if PLATFORM(IOS_FAMILY)
     622    bool m_shouldAllowMouseDownToStartDrag { false };
     623#endif
     624
    619625#if ENABLE(CURSOR_VISIBILITY)
    620626    Timer m_autoHideCursorTimer;
  • trunk/Source/WebCore/page/Quirks.cpp

    r245005 r245062  
    238238#endif
    239239
     240bool Quirks::shouldDispatchSyntheticMouseEventsWhenModifyingSelection() const
     241{
     242    if (m_document->settings().shouldDispatchSyntheticMouseEventsWhenModifyingSelection())
     243        return true;
     244
     245    if (!needsQuirks())
     246        return false;
     247
     248    auto host = m_document->topDocument().url().host();
     249    if (equalLettersIgnoringASCIICase(host, "medium.com") || host.endsWithIgnoringASCIICase(".medium.com"))
     250        return true;
     251
     252    if (equalLettersIgnoringASCIICase(host, "weebly.com") || host.endsWithIgnoringASCIICase(".weebly.com"))
     253        return true;
     254
     255    return false;
     256}
     257
    240258bool Quirks::shouldSuppressAutocorrectionAndAutocaptializationInHiddenEditableAreas() const
    241259{
  • trunk/Source/WebCore/page/Quirks.h

    r244944 r245062  
    5353    bool needsInputModeNoneImplicitly(const HTMLElement&) const;
    5454
     55    WEBCORE_EXPORT bool shouldDispatchSyntheticMouseEventsWhenModifyingSelection() const;
    5556    WEBCORE_EXPORT bool shouldSuppressAutocorrectionAndAutocaptializationInHiddenEditableAreas() const;
    5657    WEBCORE_EXPORT bool isTouchBarUpdateSupressedForHiddenContentEditable() const;
  • trunk/Source/WebCore/page/Settings.yaml

    r244869 r245062  
    835835  initial: false
    836836
     837shouldDispatchSyntheticMouseEventsWhenModifyingSelection:
     838  initial: false
     839
    837840# Deprecated
    838841
  • trunk/Source/WebCore/page/ios/EventHandlerIOS.mm

    r244588 r245062  
    672672        return false;
    673673
     674    SetForScope<bool> shouldAllowMouseDownToStartDrag { m_shouldAllowMouseDownToStartDrag, true };
     675
    674676    document->updateLayoutIgnorePendingStylesheets();
    675677
     
    700702}
    701703
    702 #endif
     704bool EventHandler::supportsSelectionUpdatesOnMouseDrag() const
     705{
     706    return false;
     707}
     708
     709bool EventHandler::shouldAllowMouseDownToStartDrag() const
     710{
     711    return m_shouldAllowMouseDownToStartDrag;
     712}
     713
     714#endif // ENABLE(DRAG_SUPPORT)
    703715
    704716}
  • trunk/Source/WebCore/testing/InternalSettings.cpp

    r244766 r245062  
    101101    , m_inputEventsEnabled(settings.inputEventsEnabled())
    102102    , m_incompleteImageBorderEnabled(settings.incompleteImageBorderEnabled())
     103    , m_shouldDispatchSyntheticMouseEventsWhenModifyingSelection(settings.shouldDispatchSyntheticMouseEventsWhenModifyingSelection())
    103104    , m_shouldDeactivateAudioSession(PlatformMediaSessionManager::shouldDeactivateAudioSession())
    104105    , m_userInterfaceDirectionPolicy(settings.userInterfaceDirectionPolicy())
     
    208209    settings.setFrameFlattening(m_frameFlattening);
    209210    settings.setIncompleteImageBorderEnabled(m_incompleteImageBorderEnabled);
     211    settings.setShouldDispatchSyntheticMouseEventsWhenModifyingSelection(m_shouldDispatchSyntheticMouseEventsWhenModifyingSelection);
    210212    PlatformMediaSessionManager::setShouldDeactivateAudioSession(m_shouldDeactivateAudioSession);
    211213
     
    927929}
    928930
     931ExceptionOr<void> InternalSettings::setShouldDispatchSyntheticMouseEventsWhenModifyingSelection(bool shouldDispatch)
     932{
     933    if (!m_page)
     934        return Exception { InvalidAccessError };
     935    settings().setShouldDispatchSyntheticMouseEventsWhenModifyingSelection(shouldDispatch);
     936    return { };
     937}
     938
    929939static InternalSettings::ForcedAccessibilityValue settingsToInternalSettingsValue(Settings::ForcedAccessibilityValue value)
    930940{
  • trunk/Source/WebCore/testing/InternalSettings.h

    r244766 r245062  
    104104    ExceptionOr<void> setCustomPasteboardDataEnabled(bool);
    105105    ExceptionOr<void> setIncompleteImageBorderEnabled(bool);
     106    ExceptionOr<void> setShouldDispatchSyntheticMouseEventsWhenModifyingSelection(bool);
    106107
    107108    using FrameFlatteningValue = FrameFlattening;
     
    199200        bool m_inputEventsEnabled;
    200201        bool m_incompleteImageBorderEnabled;
     202        bool m_shouldDispatchSyntheticMouseEventsWhenModifyingSelection;
    201203        bool m_shouldDeactivateAudioSession;
    202204        UserInterfaceDirectionPolicy m_userInterfaceDirectionPolicy;
  • trunk/Source/WebCore/testing/InternalSettings.idl

    r244682 r245062  
    8989    [MayThrowException] void setFrameFlattening(FrameFlatteningValue frameFlattening);
    9090    [MayThrowException] void setIncompleteImageBorderEnabled(boolean enabled);
     91    [MayThrowException] void setShouldDispatchSyntheticMouseEventsWhenModifyingSelection(boolean shouldDispatch);
    9192
    9293    // RuntimeEnabledFeatures.
  • trunk/Source/WebKit/ChangeLog

    r245055 r245062  
     12019-05-08  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [iOS] Add a quirk to synthesize mouse events when modifying the selection
     4        https://bugs.webkit.org/show_bug.cgi?id=197683
     5        <rdar://problem/48003980>
     6
     7        Reviewed by Tim Horton.
     8
     9        Introduces support for dispatching synthetic mouse events when modifying the selection on some websites. See
     10        below for more details.
     11
     12        * UIProcess/WebPageProxy.cpp:
     13        (WebKit::WebPageProxy::selectAll):
     14        * UIProcess/WebPageProxy.h:
     15
     16        Instead of executing a "SelectAll" editing command using the generic WebPage::executeEditCommand method,
     17        introduce a separate method for selectAll that executes the "SelectAll" edit command and then does some
     18        platform-specific work. See platformDidSelectAll.
     19
     20        * UIProcess/ios/WKContentViewInteraction.mm:
     21        (-[WKContentView selectAllForWebView:]):
     22        * WebProcess/WebPage/WebPage.cpp:
     23        (WebKit::WebPage::selectAll):
     24        (WebKit::WebPage::shouldDispatchSyntheticMouseEventsWhenModifyingSelection const):
     25
     26        Add a helper method to determine whether the quirk should be enabled.
     27
     28        (WebKit::WebPage::platformDidSelectAll):
     29        * WebProcess/WebPage/WebPage.h:
     30        * WebProcess/WebPage/WebPage.messages.in:
     31        * WebProcess/WebPage/ios/WebPageIOS.mm:
     32        (WebKit::elementRectInRootViewCoordinates):
     33
     34        Move this function closer to the top of the file so that it can be used in
     35        dispatchSyntheticMouseEventsForSelectionGesture.
     36
     37        (WebKit::WebPage::clearSelection):
     38        (WebKit::WebPage::dispatchSyntheticMouseEventsForSelectionGesture):
     39
     40        Add a helper method to dispatch a synthetic mouse event for a given selection gesture type. Used in several
     41        places in WebPageIOS to synthesize and dispatch mouse events during selection.
     42
     43        (WebKit::WebPage::updateSelectionWithTouches):
     44
     45        When changing the selection with selection handles, fake mousedown when the user first touches down on the
     46        selection handle; mousemove as the user is moving the handle around; and finally, mouseup when the user lets go.
     47
     48        (WebKit::WebPage::extendSelection):
     49        (WebKit::WebPage::platformDidSelectAll):
     50
     51        When tapping "Select All" and/or "Select" in the callout menu, fake a mousedown at the selection start, then a
     52        mousemove at selection end, and finally, a mouseup at selection end.
     53
     54        (WebKit::WebPage::getFocusedElementInformation):
     55
    1562019-05-08  Alexander Mikhaylenko  <exalm7659@gmail.com>
    257
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r244970 r245062  
    20152015}
    20162016
     2017void WebPageProxy::selectAll()
     2018{
     2019    if (!hasRunningProcess())
     2020        return;
     2021
     2022    m_process->send(Messages::WebPage::SelectAll(), m_pageID);
     2023}
     2024
    20172025void WebPageProxy::executeEditCommand(const String& commandName, const String& argument, WTF::Function<void(CallbackBase::Error)>&& callbackFunction)
    20182026{
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r244897 r245062  
    596596    void addMIMETypeWithCustomContentProvider(const String& mimeType);
    597597
     598    void selectAll();
    598599    void executeEditCommand(const String& commandName, const String& argument = String());
    599600    void validateCommand(const String& commandName, WTF::Function<void (const String&, bool, int32_t, CallbackBase::Error)>&&);
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r245022 r245062  
    30803080{
    30813081    [_textSelectionAssistant selectAll:sender];
    3082     _page->executeEditCommand("selectAll"_s);
     3082    _page->selectAll();
    30833083}
    30843084
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r245048 r245062  
    11021102}
    11031103
     1104void WebPage::selectAll()
     1105{
     1106    executeEditingCommand("SelectAll"_s, { });
     1107    platformDidSelectAll();
     1108}
     1109
     1110bool WebPage::shouldDispatchSyntheticMouseEventsWhenModifyingSelection() const
     1111{
     1112    auto* document = m_page->mainFrame().document();
     1113    return document && document->quirks().shouldDispatchSyntheticMouseEventsWhenModifyingSelection();
     1114}
     1115
     1116#if !PLATFORM(IOS_FAMILY)
     1117
     1118void WebPage::platformDidSelectAll()
     1119{
     1120}
     1121
     1122#endif // !PLATFORM(IOS_FAMILY)
     1123
    11041124void WebPage::updateEditorStateAfterLayoutIfEditabilityChanged()
    11051125{
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r245048 r245062  
    600600    void viewportPropertiesDidChange(const WebCore::ViewportArguments&);
    601601    void executeEditCommandWithCallback(const String&, const String& argument, CallbackID);
     602    void selectAll();
    602603
    603604    void textInputContextsInRect(WebCore::FloatRect, CompletionHandler<void(const Vector<WebKit::TextInputContext>&)>&&);
     
    12291230    WebCore::VisiblePosition visiblePositionInFocusedNodeForPoint(const WebCore::Frame&, const WebCore::IntPoint&, bool isInteractingWithFocusedElement);
    12301231    RefPtr<WebCore::Range> rangeForGranularityAtPoint(WebCore::Frame&, const WebCore::IntPoint&, uint32_t granularity, bool isInteractingWithFocusedElement);
     1232    void dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch, const WebCore::IntPoint&);
    12311233
    12321234    void sendPositionInformation(InteractionInformationAtPosition&&);
     
    14671469#endif
    14681470
     1471    bool shouldDispatchSyntheticMouseEventsWhenModifyingSelection() const;
     1472    void platformDidSelectAll();
     1473
    14691474#if ENABLE(CONTEXT_MENUS)
    14701475    void didSelectItemFromActiveContextMenu(const WebContextMenuItemData&);
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in

    r244897 r245062  
    203203    ForceRepaint(WebKit::CallbackID callbackID)
    204204
     205    SelectAll()
    205206    ScheduleFullEditorStateUpdate()
    206207
  • trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r244998 r245062  
    14801480}
    14811481
    1482 void WebPage::clearSelection(){
     1482static IntRect elementRectInRootViewCoordinates(const Element& element)
     1483{
     1484    auto* frame = element.document().frame();
     1485    if (!frame)
     1486        return { };
     1487
     1488    auto* view = frame->view();
     1489    if (!view)
     1490        return { };
     1491
     1492    auto* renderer = element.renderer();
     1493    if (!renderer)
     1494        return { };
     1495
     1496    return view->contentsToRootView(renderer->absoluteBoundingBoxRect());
     1497}
     1498
     1499void WebPage::clearSelection()
     1500{
    14831501    m_startingGestureRange = nullptr;
    14841502    m_currentBlockSelection = nullptr;
    14851503    m_page->focusController().focusedOrMainFrame().selection().clear();
     1504}
     1505
     1506void WebPage::dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch touch, const IntPoint& point)
     1507{
     1508    auto frame = makeRef(m_page->focusController().focusedOrMainFrame());
     1509    if (!frame->selection().selection().isContentEditable())
     1510        return;
     1511
     1512    IntRect focusedElementRect;
     1513    if (m_focusedElement)
     1514        focusedElementRect = elementRectInRootViewCoordinates(*m_focusedElement);
     1515
     1516    if (focusedElementRect.isEmpty())
     1517        return;
     1518
     1519    auto adjustedPoint = point.constrainedBetween(focusedElementRect.minXMinYCorner(), focusedElementRect.maxXMaxYCorner());
     1520    auto& eventHandler = m_page->mainFrame().eventHandler();
     1521    switch (touch) {
     1522    case SelectionTouch::Started:
     1523        eventHandler.handleMousePressEvent({ adjustedPoint, adjustedPoint, LeftButton, PlatformEvent::MousePressed, 1, false, false, false, false, WallTime::now(), WebCore::ForceAtClick, NoTap });
     1524        break;
     1525    case SelectionTouch::Moved:
     1526        eventHandler.dispatchSyntheticMouseMove({ adjustedPoint, adjustedPoint, LeftButton, PlatformEvent::MouseMoved, 0, false, false, false, false, WallTime::now(), WebCore::ForceAtClick, NoTap });
     1527        break;
     1528    case SelectionTouch::Ended:
     1529    case SelectionTouch::EndedMovingForward:
     1530    case SelectionTouch::EndedMovingBackward:
     1531    case SelectionTouch::EndedNotMoving:
     1532        eventHandler.handleMouseReleaseEvent({ adjustedPoint, adjustedPoint, LeftButton, PlatformEvent::MouseReleased, 1, false, false, false, false, WallTime::now(), WebCore::ForceAtClick, NoTap });
     1533        break;
     1534    }
    14861535}
    14871536
     
    15001549    SelectionFlags flags = None;
    15011550
    1502     switch (static_cast<SelectionTouch>(touches)) {
     1551    auto selectionTouch = static_cast<SelectionTouch>(touches);
     1552    if (shouldDispatchSyntheticMouseEventsWhenModifyingSelection())
     1553        dispatchSyntheticMouseEventsForSelectionGesture(selectionTouch, point);
     1554
     1555    switch (selectionTouch) {
    15031556    case SelectionTouch::Started:
    15041557    case SelectionTouch::EndedNotMoving:
     
    15581611
    15591612    VisiblePosition position = frame.selection().selection().start();
    1560     frame.selection().setSelectedRange(wordRangeFromPosition(position).get(), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     1613    auto wordRange = wordRangeFromPosition(position);
     1614    if (!wordRange)
     1615        return;
     1616
     1617    IntPoint endLocationForSyntheticMouseEvents;
     1618    bool shouldDispatchMouseEvents = shouldDispatchSyntheticMouseEventsWhenModifyingSelection();
     1619    if (shouldDispatchMouseEvents) {
     1620        auto startLocationForSyntheticMouseEvents = frame.view()->contentsToRootView(VisiblePosition(wordRange->startPosition()).absoluteCaretBounds()).center();
     1621        endLocationForSyntheticMouseEvents = frame.view()->contentsToRootView(VisiblePosition(wordRange->endPosition()).absoluteCaretBounds()).center();
     1622        dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch::Started, startLocationForSyntheticMouseEvents);
     1623        dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch::Moved, endLocationForSyntheticMouseEvents);
     1624    }
     1625
     1626    frame.selection().setSelectedRange(wordRange.get(), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
     1627
     1628    if (shouldDispatchMouseEvents)
     1629        dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch::Ended, endLocationForSyntheticMouseEvents);
     1630}
     1631
     1632void WebPage::platformDidSelectAll()
     1633{
     1634    if (!shouldDispatchSyntheticMouseEventsWhenModifyingSelection())
     1635        return;
     1636
     1637    auto frame = makeRef(m_page->focusController().focusedOrMainFrame());
     1638    auto startCaretRect = frame->view()->contentsToRootView(VisiblePosition(frame->selection().selection().start()).absoluteCaretBounds());
     1639    auto endCaretRect = frame->view()->contentsToRootView(VisiblePosition(frame->selection().selection().end()).absoluteCaretBounds());
     1640    dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch::Started, startCaretRect.center());
     1641    dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch::Moved, endCaretRect.center());
     1642    dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch::Ended, endCaretRect.center());
    15611643}
    15621644
     
    25852667}
    25862668
    2587 static IntRect elementRectInRootViewCoordinates(const Node& node, const Frame& frame)
    2588 {
    2589     auto* view = frame.view();
    2590     if (!view)
    2591         return { };
    2592 
    2593     auto* renderer = node.renderer();
    2594     if (!renderer)
    2595         return { };
    2596 
    2597     return view->contentsToRootView(renderer->absoluteBoundingBoxRect());
    2598 }
    2599 
    26002669void WebPage::getFocusedElementInformation(FocusedElementInformation& information)
    26012670{
     
    26052674
    26062675    if (auto* renderer = m_focusedElement->renderer()) {
    2607         auto& elementFrame = m_page->focusController().focusedOrMainFrame();
    2608         information.elementRect = elementRectInRootViewCoordinates(*m_focusedElement, elementFrame);
     2676        information.elementRect = elementRectInRootViewCoordinates(*m_focusedElement);
    26092677        information.nodeFontSize = renderer->style().fontDescription().computedSize();
    26102678
     
    26222690    information.allowsUserScalingIgnoringAlwaysScalable = m_viewportConfiguration.allowsUserScalingIgnoringAlwaysScalable();
    26232691    if (auto* nextElement = nextAssistableElement(m_focusedElement.get(), *m_page, true)) {
    2624         if (auto* frame = nextElement->document().frame())
    2625             information.nextNodeRect = elementRectInRootViewCoordinates(*nextElement, *frame);
     2692        information.nextNodeRect = elementRectInRootViewCoordinates(*nextElement);
    26262693        information.hasNextNode = true;
    26272694    }
    26282695    if (auto* previousElement = nextAssistableElement(m_focusedElement.get(), *m_page, false)) {
    2629         if (auto* frame = previousElement->document().frame())
    2630             information.previousNodeRect = elementRectInRootViewCoordinates(*previousElement, *frame);
     2696        information.previousNodeRect = elementRectInRootViewCoordinates(*previousElement);
    26312697        information.hasPreviousNode = true;
    26322698    }
Note: See TracChangeset for help on using the changeset viewer.