Changeset 212149 in webkit


Ignore:
Timestamp:
Feb 10, 2017, 2:16:19 PM (9 years ago)
Author:
mitz@apple.com
Message:

[Cocoa] Add shouldChangeSelectedRange to WKWebProcessPlugInEditingDelegate
https://bugs.webkit.org/show_bug.cgi?id=168097

Reviewed by Tim Horton.

Source/WebCore:

Added a userTriggered argument to FrameSelection::setSelectedRange so that WebKit2 can
indicate that changes should be agreed to by the delegate.

  • editing/FrameSelection.cpp:

(WebCore::FrameSelection::setSelectedRange): If the change is user-triggered, check with

shouldChangeSelection.

  • editing/FrameSelection.h:

Source/WebKit2:

  • WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInEditingDelegate.h: Declared new delegate method.
  • WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:

(-[WKWebProcessPlugInBrowserContextController _setEditingDelegate:]): Dispatch new delegate

method.

  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::WebPage::selectWithGesture): Pass UserTriggered whan calling

WebCore::Frame::Selection::setSelectedRange, so that the delegate is consulted.

(WebKit::WebPage::changeBlockSelection): Ditto.
(WebKit::WebPage::updateSelectionWithTouches): Ditto.
(WebKit::WebPage::selectWithTwoTouches): Ditto.
(WebKit::WebPage::extendSelection): Ditto.
(WebKit::WebPage::selectWordBackward): Ditto,
(WebKit::WebPage::moveSelectionByOffset): Ditto.
(WebKit::WebPage::selectPositionAtPoint): Ditto.
(WebKit::WebPage::selectPositionAtBoundaryWithDirection): Ditto.
(WebKit::WebPage::moveSelectionAtBoundaryWithDirection): Ditto.
(WebKit::WebPage::selectTextWithGranularityAtPoint): Ditto.
(WebKit::WebPage::updateSelectionWithExtentPointAndBoundary): Ditto.
(WebKit::WebPage::updateSelectionWithExtentPoint): Ditto.

Location:
trunk/Source
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r212148 r212149  
     12017-02-10  Dan Bernstein  <mitz@apple.com>
     2
     3        [Cocoa] Add shouldChangeSelectedRange to WKWebProcessPlugInEditingDelegate
     4        https://bugs.webkit.org/show_bug.cgi?id=168097
     5
     6        Reviewed by Tim Horton.
     7
     8        Added a userTriggered argument to FrameSelection::setSelectedRange so that WebKit2 can
     9        indicate that changes should be agreed to by the delegate.
     10
     11        * editing/FrameSelection.cpp:
     12        (WebCore::FrameSelection::setSelectedRange): If the change is user-triggered, check with
     13          shouldChangeSelection.
     14        * editing/FrameSelection.h:
     15
    1162017-02-10  Jonathan Bedard  <jbedard@apple.com>
    217
  • trunk/Source/WebCore/editing/FrameSelection.cpp

    r211591 r212149  
    19441944}
    19451945
    1946 bool FrameSelection::setSelectedRange(Range* range, EAffinity affinity, bool closeTyping)
     1946bool FrameSelection::setSelectedRange(Range* range, EAffinity affinity, bool closeTyping, EUserTriggered userTriggered)
    19471947{
    19481948    if (!range)
     
    19571957        return false;
    19581958#endif
     1959
     1960    if (userTriggered == UserTriggered) {
     1961        FrameSelection trialFrameSelection;
     1962        trialFrameSelection.setSelection(newSelection, ClearTypingStyle | (closeTyping ? CloseTyping : 0));
     1963
     1964        if (!shouldChangeSelection(trialFrameSelection.selection()))
     1965            return false;
     1966    }
    19591967
    19601968    setSelection(newSelection, ClearTypingStyle | (closeTyping ? CloseTyping : 0));
  • trunk/Source/WebCore/editing/FrameSelection.h

    r209411 r212149  
    146146    const VisibleSelection& selection() const { return m_selection; }
    147147    WEBCORE_EXPORT void setSelection(const VisibleSelection&, SetSelectionOptions = defaultSetSelectionOptions(), AXTextStateChangeIntent = AXTextStateChangeIntent(), CursorAlignOnScroll = AlignCursorOnScrollIfNeeded, TextGranularity = CharacterGranularity);
    148     WEBCORE_EXPORT bool setSelectedRange(Range*, EAffinity, bool closeTyping);
     148    WEBCORE_EXPORT bool setSelectedRange(Range*, EAffinity, bool closeTyping, EUserTriggered = NotUserTriggered);
    149149    WEBCORE_EXPORT void selectAll();
    150150    WEBCORE_EXPORT void clear();
  • trunk/Source/WebKit2/ChangeLog

    r212134 r212149  
     12017-02-10  Dan Bernstein  <mitz@apple.com>
     2
     3        [Cocoa] Add shouldChangeSelectedRange to WKWebProcessPlugInEditingDelegate
     4        https://bugs.webkit.org/show_bug.cgi?id=168097
     5
     6        Reviewed by Tim Horton.
     7
     8        * WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInEditingDelegate.h:
     9          Declared new delegate method.
     10        * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
     11        (-[WKWebProcessPlugInBrowserContextController _setEditingDelegate:]): Dispatch new delegate
     12          method.
     13
     14        * WebProcess/WebPage/ios/WebPageIOS.mm:
     15        (WebKit::WebPage::selectWithGesture): Pass UserTriggered whan calling
     16          WebCore::Frame::Selection::setSelectedRange, so that the delegate is consulted.
     17        (WebKit::WebPage::changeBlockSelection): Ditto.
     18        (WebKit::WebPage::updateSelectionWithTouches): Ditto.
     19        (WebKit::WebPage::selectWithTwoTouches): Ditto.
     20        (WebKit::WebPage::extendSelection): Ditto.
     21        (WebKit::WebPage::selectWordBackward): Ditto,
     22        (WebKit::WebPage::moveSelectionByOffset): Ditto.
     23        (WebKit::WebPage::selectPositionAtPoint): Ditto.
     24        (WebKit::WebPage::selectPositionAtBoundaryWithDirection): Ditto.
     25        (WebKit::WebPage::moveSelectionAtBoundaryWithDirection): Ditto.
     26        (WebKit::WebPage::selectTextWithGranularityAtPoint): Ditto.
     27        (WebKit::WebPage::updateSelectionWithExtentPointAndBoundary): Ditto.
     28        (WebKit::WebPage::updateSelectionWithExtentPoint): Ditto.
     29
    1302017-02-10  Brady Eidson  <beidson@apple.com>
    231
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInEditingDelegate.h

    r209775 r212149  
    3131#import <WebKit/WKWebProcessPlugInRangeHandle.h>
    3232
     33#if TARGET_OS_IPHONE
     34#import <UIKit/UIKit.h>
     35#else
     36#import <AppKit/AppKit.h>
     37#endif
     38
    3339NS_ASSUME_NONNULL_BEGIN
    3440
     
    4551
    4652- (BOOL)_webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller shouldInsertText:(NSString *)text replacingRange:(WKWebProcessPlugInRangeHandle *)range givenAction:(WKEditorInsertAction)action;
     53#if TARGET_OS_IPHONE
     54- (BOOL)_webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller shouldChangeSelectedRange:(WKDOMRange *)currentRange toRange:(WKDOMRange *)proposedRange affinity:(UITextStorageDirection)selectionAffinity stillSelecting:(BOOL)stillSelecting;
     55#else
     56- (BOOL)_webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller shouldChangeSelectedRange:(WKDOMRange *)currentRange toRange:(WKDOMRange *)proposedRange affinity:(NSSelectionAffinity)selectionAffinity stillSelecting:(BOOL)stillSelecting;
     57#endif
    4758- (void)_webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller willWriteRangeToPasteboard:(WKWebProcessPlugInRangeHandle *)range;
    4859- (NSDictionary<NSString *, NSData *> *)_webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller pasteboardDataForRange:(WKWebProcessPlugInRangeHandle *)range;
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm

    r210109 r212149  
    607607        }
    608608
     609        bool shouldChangeSelectedRange(WebPage&, Range* fromRange, Range* toRange, EAffinity affinity, bool stillSelecting) final
     610        {
     611            if (!m_delegateMethods.shouldChangeSelectedRange)
     612                return true;
     613
     614            auto apiFromRange = fromRange ? adoptNS([[WKDOMRange alloc] _initWithImpl:fromRange]) : nil;
     615            auto apiToRange = toRange ? adoptNS([[WKDOMRange alloc] _initWithImpl:toRange]) : nil;
     616#if PLATFORM(IOS)
     617            UITextStorageDirection apiAffinity = affinity == UPSTREAM ? UITextStorageDirectionBackward : UITextStorageDirectionForward;
     618#else
     619            NSSelectionAffinity apiAffinity = affinity == UPSTREAM ? NSSelectionAffinityUpstream : NSSelectionAffinityDownstream;
     620#endif
     621
     622            return [m_controller->_editingDelegate.get() _webProcessPlugInBrowserContextController:m_controller shouldChangeSelectedRange:apiFromRange.get() toRange:apiToRange.get() affinity:apiAffinity stillSelecting:stillSelecting];
     623        }
     624
    609625        void willWriteToPasteboard(WebKit::WebPage&, WebCore::Range* range) final
    610626        {
     
    639655            DelegateMethods(RetainPtr<id <WKWebProcessPlugInEditingDelegate>> delegate)
    640656                : shouldInsertText([delegate respondsToSelector:@selector(_webProcessPlugInBrowserContextController:shouldInsertText:replacingRange:givenAction:)])
     657                , shouldChangeSelectedRange([delegate respondsToSelector:@selector(_webProcessPlugInBrowserContextController:shouldChangeSelectedRange:toRange:affinity:stillSelecting:)])
    641658                , willWriteToPasteboard([delegate respondsToSelector:@selector(_webProcessPlugInBrowserContextController:willWriteRangeToPasteboard:)])
    642659                , getPasteboardDataForRange([delegate respondsToSelector:@selector(_webProcessPlugInBrowserContextController:pasteboardDataForRange:)])
     
    646663
    647664            bool shouldInsertText;
     665            bool shouldChangeSelectedRange;
    648666            bool willWriteToPasteboard;
    649667            bool getPasteboardDataForRange;
  • trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

    r211679 r212149  
    11611161    }
    11621162    if (range)
    1163         frame.selection().setSelectedRange(range.get(), position.affinity(), true);
     1163        frame.selection().setSelectedRange(range.get(), position.affinity(), true, UserTriggered);
    11641164
    11651165    send(Messages::WebPageProxy::GestureCallback(point, gestureType, gestureState, static_cast<uint32_t>(flags), callbackID));
     
    16141614    if (newRange) {
    16151615        m_currentBlockSelection = newRange;
    1616         frame.selection().setSelectedRange(newRange.get(), VP_DEFAULT_AFFINITY, true);
     1616        frame.selection().setSelectedRange(newRange.get(), VP_DEFAULT_AFFINITY, true, UserTriggered);
    16171617    }
    16181618
     
    17381738    }
    17391739    if (range && flags != IsBlockSelection)
    1740         frame.selection().setSelectedRange(range.get(), position.affinity(), true);
     1740        frame.selection().setSelectedRange(range.get(), position.affinity(), true, UserTriggered);
    17411741
    17421742    send(Messages::WebPageProxy::TouchesCallback(point, touches, flags, callbackID));
     
    17441744        // We just switched to block selection therefore we need to compute the thresholds.
    17451745        m_currentBlockSelection = range;
    1746         frame.selection().setSelectedRange(range.get(), position.affinity(), true);
     1746        frame.selection().setSelectedRange(range.get(), position.affinity(), true, UserTriggered);
    17471747       
    17481748        float growThreshold = 0;
     
    17641764        else
    17651765            range = Range::create(*frame.document(), toPosition, fromPosition);
    1766         frame.selection().setSelectedRange(range.get(), fromPosition.affinity(), true);
     1766        frame.selection().setSelectedRange(range.get(), fromPosition.affinity(), true, UserTriggered);
    17671767    }
    17681768
     
    17791779
    17801780    VisiblePosition position = frame.selection().selection().start();
    1781     frame.selection().setSelectedRange(wordRangeFromPosition(position).get(), position.affinity(), true);
     1781    frame.selection().setSelectedRange(wordRangeFromPosition(position).get(), position.affinity(), true, UserTriggered);
    17821782}
    17831783
     
    17911791    VisiblePosition startPosition = positionOfNextBoundaryOfGranularity(position, WordGranularity, DirectionBackward);
    17921792    if (startPosition.isNotNull() && startPosition != position)
    1793         frame.selection().setSelectedRange(Range::create(*frame.document(), startPosition, position).ptr(), position.affinity(), true);
     1793        frame.selection().setSelectedRange(Range::create(*frame.document(), startPosition, position).ptr(), position.affinity(), true, UserTriggered);
    17941794}
    17951795
     
    18091809    }
    18101810    if (position.isNotNull() && startPosition != position)
    1811         frame.selection().setSelectedRange(Range::create(*frame.document(), position, position).ptr(), position.affinity(), true);
     1811        frame.selection().setSelectedRange(Range::create(*frame.document(), position, position).ptr(), position.affinity(), true, UserTriggered);
    18121812    send(Messages::WebPageProxy::VoidCallback(callbackID));
    18131813}
     
    19041904   
    19051905    if (position.isNotNull())
    1906         frame.selection().setSelectedRange(Range::create(*frame.document(), position, position).ptr(), position.affinity(), true);
     1906        frame.selection().setSelectedRange(Range::create(*frame.document(), position, position).ptr(), position.affinity(), true, UserTriggered);
    19071907    send(Messages::WebPageProxy::VoidCallback(callbackID));
    19081908}
     
    19161916        position = positionOfNextBoundaryOfGranularity(position, static_cast<WebCore::TextGranularity>(granularity), static_cast<SelectionDirection>(direction));
    19171917        if (position.isNotNull())
    1918             frame.selection().setSelectedRange(Range::create(*frame.document(), position, position).ptr(), UPSTREAM, true);
     1918            frame.selection().setSelectedRange(Range::create(*frame.document(), position, position).ptr(), UPSTREAM, true, UserTriggered);
    19191919    }
    19201920    send(Messages::WebPageProxy::VoidCallback(callbackID));
     
    19301930        position = positionOfNextBoundaryOfGranularity(position, static_cast<WebCore::TextGranularity>(granularity), static_cast<SelectionDirection>(direction));
    19311931        if (position.isNotNull())
    1932             frame.selection().setSelectedRange(Range::create(*frame.document(), position, position).ptr(), isForward? UPSTREAM : DOWNSTREAM, true);
     1932            frame.selection().setSelectedRange(Range::create(*frame.document(), position, position).ptr(), isForward? UPSTREAM : DOWNSTREAM, true, UserTriggered);
    19331933    }
    19341934    send(Messages::WebPageProxy::VoidCallback(callbackID));
     
    19871987
    19881988    if (range)
    1989         frame.selection().setSelectedRange(range.get(), UPSTREAM, true);
     1989        frame.selection().setSelectedRange(range.get(), UPSTREAM, true, UserTriggered);
    19901990    m_initialSelection = range;
    19911991    send(Messages::WebPageProxy::VoidCallback(callbackID));
     
    20222022   
    20232023    if (range)
    2024         frame.selection().setSelectedRange(range.get(), UPSTREAM, true);
     2024        frame.selection().setSelectedRange(range.get(), UPSTREAM, true, UserTriggered);
    20252025   
    20262026    send(Messages::WebPageProxy::UnsignedCallback(selectionStart == m_initialSelection->startPosition(), callbackID));
     
    20652065
    20662066    if (range)
    2067         frame.selection().setSelectedRange(range.get(), UPSTREAM, true);
     2067        frame.selection().setSelectedRange(range.get(), UPSTREAM, true, UserTriggered);
    20682068
    20692069    send(Messages::WebPageProxy::UnsignedCallback(m_selectionAnchor == Start, callbackID));
Note: See TracChangeset for help on using the changeset viewer.