Title: [186849] trunk/Source/WebKit2
Revision
186849
Author
[email protected]
Date
2015-07-15 10:52:11 -0700 (Wed, 15 Jul 2015)

Log Message

[iOS] Add support for updateSelectionWithExtentPoint:withBoundary.
https://bugs.webkit.org/show_bug.cgi?id=146951
rdar://problem/20864286

Reviewed by Tim Horton.

Add implementation for new method used by text selection
engine on iOS. The new function modifies the selection near the given point
and snaps it at the boundary of the specified granularity.

* UIProcess/WebPageProxy.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView updateSelectionWithExtentPoint:completionHandler:]):
(-[WKContentView updateSelectionWithExtentPoint:withBoundary:completionHandler:]):
(-[WKContentView _characterBeforeCaretSelection]):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::updateSelectionWithExtentPoint):
(WebKit::WebPageProxy::updateSelectionWithExtentPointAndBoundary):
(WebKit::WebPageProxy::requestDictationContext):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::rangeForGranularityAtPoint):
(WebKit::WebPage::selectTextWithGranularityAtPoint):
(WebKit::WebPage::updateSelectionWithExtentPointAndBoundary):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (186848 => 186849)


--- trunk/Source/WebKit2/ChangeLog	2015-07-15 17:42:06 UTC (rev 186848)
+++ trunk/Source/WebKit2/ChangeLog	2015-07-15 17:52:11 UTC (rev 186849)
@@ -1,3 +1,31 @@
+2015-07-14  Enrica Casucci  <[email protected]>
+
+        [iOS] Add support for updateSelectionWithExtentPoint:withBoundary.
+        https://bugs.webkit.org/show_bug.cgi?id=146951
+        rdar://problem/20864286
+
+        Reviewed by Tim Horton.
+
+        Add implementation for new method used by text selection
+        engine on iOS. The new function modifies the selection near the given point
+        and snaps it at the boundary of the specified granularity.
+
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView updateSelectionWithExtentPoint:completionHandler:]):
+        (-[WKContentView updateSelectionWithExtentPoint:withBoundary:completionHandler:]):
+        (-[WKContentView _characterBeforeCaretSelection]):
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::updateSelectionWithExtentPoint):
+        (WebKit::WebPageProxy::updateSelectionWithExtentPointAndBoundary):
+        (WebKit::WebPageProxy::requestDictationContext):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::rangeForGranularityAtPoint):
+        (WebKit::WebPage::selectTextWithGranularityAtPoint):
+        (WebKit::WebPage::updateSelectionWithExtentPointAndBoundary):
+
 2015-07-15  Michael Catanzaro  <[email protected]>
 
         [Linux] SeccompBrokerClient should cache arbitrary file descriptors

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (186848 => 186849)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2015-07-15 17:42:06 UTC (rev 186848)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2015-07-15 17:52:11 UTC (rev 186849)
@@ -488,6 +488,7 @@
     void moveSelectionAtBoundaryWithDirection(WebCore::TextGranularity, WebCore::SelectionDirection, std::function<void(CallbackBase::Error)>);
     void beginSelectionInDirection(WebCore::SelectionDirection, std::function<void (uint64_t, CallbackBase::Error)>);
     void updateSelectionWithExtentPoint(const WebCore::IntPoint, std::function<void (uint64_t, CallbackBase::Error)>);
+    void updateSelectionWithExtentPointAndBoundary(const WebCore::IntPoint, WebCore::TextGranularity, std::function<void(uint64_t, CallbackBase::Error)>);
     void requestAutocorrectionData(const String& textForAutocorrection, std::function<void (const Vector<WebCore::FloatRect>&, const String&, double, uint64_t, CallbackBase::Error)>);
     void applyAutocorrection(const String& correction, const String& originalText, std::function<void (const String&, CallbackBase::Error)>);
     bool applyAutocorrection(const String& correction, const String& originalText);

Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (186848 => 186849)


--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm	2015-07-15 17:42:06 UTC (rev 186848)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm	2015-07-15 17:52:11 UTC (rev 186849)
@@ -2043,6 +2043,16 @@
     });
 }
 
+- (void)updateSelectionWithExtentPoint:(CGPoint)point withBoundary:(UITextGranularity)granularity completionHandler:(void (^)(BOOL selectionEndIsMoving))completionHandler
+{
+    UIWKSelectionWithDirectionCompletionHandler selectionHandler = [completionHandler copy];
+    
+    _page->updateSelectionWithExtentPointAndBoundary(WebCore::IntPoint(point), toWKTextGranularity(granularity), [selectionHandler](bool endIsMoving, WebKit::CallbackBase::Error error) {
+        selectionHandler(endIsMoving);
+        [selectionHandler release];
+    });
+}
+
 - (UTF32Char)_characterBeforeCaretSelection
 {
     return _page->editorState().postLayoutData().characterBeforeSelection;

Modified: trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm (186848 => 186849)


--- trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm	2015-07-15 17:42:06 UTC (rev 186848)
+++ trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm	2015-07-15 17:52:11 UTC (rev 186849)
@@ -496,6 +496,18 @@
     
 }
 
+void WebPageProxy::updateSelectionWithExtentPointAndBoundary(const WebCore::IntPoint point, WebCore::TextGranularity granularity, std::function<void(uint64_t, CallbackBase::Error)> callbackFunction)
+{
+    if (!isValid()) {
+        callbackFunction(0, CallbackBase::Error::Unknown);
+        return;
+    }
+    
+    uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), m_process->throttler().backgroundActivityToken());
+    m_process->send(Messages::WebPage::UpdateSelectionWithExtentPointAndBoundary(point, granularity, callbackID), m_pageID);
+    
+}
+
 void WebPageProxy::requestDictationContext(std::function<void (const String&, const String&, const String&, CallbackBase::Error)> callbackFunction)
 {
     if (!isValid()) {

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (186848 => 186849)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2015-07-15 17:42:06 UTC (rev 186848)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2015-07-15 17:52:11 UTC (rev 186849)
@@ -509,6 +509,7 @@
     void selectPositionAtPoint(const WebCore::IntPoint&, uint64_t callbackID);
     void beginSelectionInDirection(uint32_t direction, uint64_t callbackID);
     void updateSelectionWithExtentPoint(const WebCore::IntPoint&, uint64_t callbackID);
+    void updateSelectionWithExtentPointAndBoundary(const WebCore::IntPoint&, uint32_t granularity, uint64_t callbackID);
 
     void elementDidFocus(WebCore::Node*);
     void elementDidBlur(WebCore::Node*);
@@ -929,6 +930,7 @@
     void sendTapHighlightForNodeIfNecessary(uint64_t requestID, WebCore::Node*);
     void resetTextAutosizingBeforeLayoutIfNeeded(const WebCore::FloatSize& oldSize, const WebCore::FloatSize& newSize);
     WebCore::VisiblePosition visiblePositionInFocusedNodeForPoint(const WebCore::Frame&, const WebCore::IntPoint&);
+    PassRefPtr<WebCore::Range> rangeForGranularityAtPoint(const WebCore::Frame&, const WebCore::IntPoint&, uint32_t granularity);
     void volatilityTimerFired();
 #endif
 #if !PLATFORM(COCOA)
@@ -1346,6 +1348,7 @@
     WebCore::FloatSize m_screenSize;
     WebCore::FloatSize m_availableScreenSize;
     RefPtr<WebCore::Range> m_currentBlockSelection;
+    RefPtr<WebCore::Range> m_initialSelection;
     WebCore::IntSize m_blockSelectionDesiredSize;
     WebCore::FloatSize m_maximumUnobscuredSize;
     int32_t m_deviceOrientation;

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (186848 => 186849)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2015-07-15 17:42:06 UTC (rev 186848)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2015-07-15 17:52:11 UTC (rev 186849)
@@ -70,6 +70,7 @@
     SelectPositionAtPoint(WebCore::IntPoint point, uint64_t callbackID)
     BeginSelectionInDirection(uint32_t direction, uint64_t callbackID)
     UpdateSelectionWithExtentPoint(WebCore::IntPoint point, uint64_t callbackID)
+    UpdateSelectionWithExtentPointAndBoundary(WebCore::IntPoint point, uint32_t granularity, uint64_t callbackID)
     RequestDictationContext(uint64_t callbackID)
     ReplaceDictatedText(String oldText, String newText)
     ReplaceSelectedText(String oldText, String newText)

Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (186848 => 186849)


--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2015-07-15 17:42:06 UTC (rev 186848)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2015-07-15 17:52:11 UTC (rev 186849)
@@ -1734,9 +1734,8 @@
     send(Messages::WebPageProxy::VoidCallback(callbackID));
 }
 
-void WebPage::selectTextWithGranularityAtPoint(const WebCore::IntPoint& point, uint32_t granularity, uint64_t callbackID)
+PassRefPtr<Range> WebPage::rangeForGranularityAtPoint(const Frame& frame, const WebCore::IntPoint& point, uint32_t granularity)
 {
-    const Frame& frame = m_page->focusController().focusedOrMainFrame();
     VisiblePosition position = visiblePositionInFocusedNodeForPoint(frame, point);
 
     RefPtr<Range> range;
@@ -1756,8 +1755,17 @@
     default:
         break;
     }
+    return range;
+}
+
+void WebPage::selectTextWithGranularityAtPoint(const WebCore::IntPoint& point, uint32_t granularity, uint64_t callbackID)
+{
+    const Frame& frame = m_page->focusController().focusedOrMainFrame();
+    RefPtr<Range> range = rangeForGranularityAtPoint(frame, point, granularity);
+
     if (range)
         frame.selection().setSelectedRange(range.get(), UPSTREAM, true);
+    m_initialSelection = range;
     send(Messages::WebPageProxy::VoidCallback(callbackID));
 }
 
@@ -1766,7 +1774,36 @@
     m_selectionAnchor = (static_cast<SelectionDirection>(direction) == DirectionLeft) ? Start : End;
     send(Messages::WebPageProxy::UnsignedCallback(m_selectionAnchor == Start, callbackID));
 }
+
+void WebPage::updateSelectionWithExtentPointAndBoundary(const WebCore::IntPoint& point, uint32_t granularity, uint64_t callbackID)
+{
+    const Frame& frame = m_page->focusController().focusedOrMainFrame();
+    VisiblePosition position = visiblePositionInFocusedNodeForPoint(frame, point);
+    RefPtr<Range> newRange = rangeForGranularityAtPoint(frame, point, granularity);
     
+    if (position.isNull() || !m_initialSelection || !newRange) {
+        send(Messages::WebPageProxy::UnsignedCallback(false, callbackID));
+        return;
+    }
+    
+    RefPtr<Range> range;
+    VisiblePosition selectionStart = m_initialSelection->startPosition();
+    VisiblePosition selectionEnd = m_initialSelection->endPosition();
+
+    if (position > m_initialSelection->endPosition())
+        selectionEnd = newRange->endPosition();
+    else if (position < m_initialSelection->startPosition())
+        selectionStart = newRange->startPosition();
+    
+    if (selectionStart.isNotNull() && selectionEnd.isNotNull())
+        range = Range::create(*frame.document(), selectionStart, selectionEnd);
+    
+    if (range)
+        frame.selection().setSelectedRange(range.get(), UPSTREAM, true);
+    
+    send(Messages::WebPageProxy::UnsignedCallback(selectionStart == m_initialSelection->startPosition(), callbackID));
+}
+
 void WebPage::updateSelectionWithExtentPoint(const WebCore::IntPoint& point, uint64_t callbackID)
 {
     const Frame& frame = m_page->focusController().focusedOrMainFrame();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to