Title: [266265] trunk
Revision
266265
Author
[email protected]
Date
2020-08-27 18:18:07 -0700 (Thu, 27 Aug 2020)

Log Message

[iOS] provide a way to get previously inserted alternatives for the selected text
https://bugs.webkit.org/show_bug.cgi?id=215816
<rdar://problem/66646042>

Reviewed by Darin Adler.

Source/WebCore:

* editing/cocoa/AlternativeTextUIController.h:
* editing/cocoa/AlternativeTextUIController.mm:
(WebCore::AlternativeTextUIController::alternativesForContext):
Return the raw `NSTextAlternatives *` and let the caller create the `Vector<String>` if they
need to so that callers that don't can use the actual `NSTextAlternatives *`.

* editing/Editor.h:
* editing/Editor.cpp:
(WebCore::Editor::applyDictationAlternative): Added.
(WebCore::Editor::applyDictationAlternativelternative): Deleted.
* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::contextMenuItemSelected):
Drive-by: fix typo.

Source/WebKit:

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView alternativesForSelectedText]):

* UIProcess/WebPageProxy.h:
* UIProcess/Cocoa/WebPageProxyCocoa.mm:
(WebKit::WebPageProxy::platformDictationAlternatives): Added.
* UIProcess/PageClient.h:
* UIProcess/Cocoa/PageClientImplCocoa.h:
* UIProcess/Cocoa/PageClientImplCocoa.mm:
(WebKit::PageClientImplCocoa::dictationAlternatives):
(WebKit::PageClientImplCocoa::platformDictationAlternatives): Added.
Provide a way to get the raw `NSTextAlternatives *` for a given `WebCore::DictationContext`.

* Shared/EditorState.h:
* Shared/EditorState.cpp:
(WebKit::EditorState::PostLayoutData::encode const):
(WebKit::EditorState::PostLayoutData::decode):
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::getPlatformEditorState const):
Include a `Vector<WebCore::DictationContext>` as part of the `EditorState` that contains all
of the `WebCore::DictationContext` that exist in the currently selected range (or the range
of the word containing the cursor if nothing is selected).

* Platform/spi/ios/UIKitSPI.h:

Source/WebKitLegacy/mac:

* WebView/WebView.mm:
(-[WebView _dictationAlternatives:]):
Create a `Vector<String>` from the returned `NSTextAlternatives *` now that the member
`WebCore::AlternativeTextUIController::alternativesForContext` returns it.

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/InsertTextAlternatives.mm:
(InsertTextAlternatives.Simple):

* TestWebKitAPI/ios/UIKitSPI.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (266264 => 266265)


--- trunk/Source/WebCore/ChangeLog	2020-08-28 00:27:19 UTC (rev 266264)
+++ trunk/Source/WebCore/ChangeLog	2020-08-28 01:18:07 UTC (rev 266265)
@@ -1,3 +1,25 @@
+2020-08-27  Devin Rousso  <[email protected]>
+
+        [iOS] provide a way to get previously inserted alternatives for the selected text
+        https://bugs.webkit.org/show_bug.cgi?id=215816
+        <rdar://problem/66646042>
+
+        Reviewed by Darin Adler.
+
+        * editing/cocoa/AlternativeTextUIController.h:
+        * editing/cocoa/AlternativeTextUIController.mm:
+        (WebCore::AlternativeTextUIController::alternativesForContext):
+        Return the raw `NSTextAlternatives *` and let the caller create the `Vector<String>` if they
+        need to so that callers that don't can use the actual `NSTextAlternatives *`.
+
+        * editing/Editor.h:
+        * editing/Editor.cpp:
+        (WebCore::Editor::applyDictationAlternative): Added.
+        (WebCore::Editor::applyDictationAlternativelternative): Deleted.
+        * page/ContextMenuController.cpp:
+        (WebCore::ContextMenuController::contextMenuItemSelected):
+        Drive-by: fix typo.
+
 2020-08-27  Chris Dumez  <[email protected]>
 
         AudioParam does not need to store its values as double

Modified: trunk/Source/WebCore/editing/Editor.cpp (266264 => 266265)


--- trunk/Source/WebCore/editing/Editor.cpp	2020-08-28 00:27:19 UTC (rev 266264)
+++ trunk/Source/WebCore/editing/Editor.cpp	2020-08-28 01:18:07 UTC (rev 266265)
@@ -4221,7 +4221,7 @@
     return m_alternativeTextController->dictationAlternativesForMarker(marker);
 }
 
-void Editor::applyDictationAlternativelternative(const String& alternativeString)
+void Editor::applyDictationAlternative(const String& alternativeString)
 {
     m_alternativeTextController->applyDictationAlternative(alternativeString);
 }

Modified: trunk/Source/WebCore/editing/Editor.h (266264 => 266265)


--- trunk/Source/WebCore/editing/Editor.h	2020-08-28 00:27:19 UTC (rev 266264)
+++ trunk/Source/WebCore/editing/Editor.h	2020-08-28 01:18:07 UTC (rev 266265)
@@ -489,7 +489,7 @@
     EditorParagraphSeparator defaultParagraphSeparator() const { return m_defaultParagraphSeparator; }
     void setDefaultParagraphSeparator(EditorParagraphSeparator separator) { m_defaultParagraphSeparator = separator; }
     Vector<String> dictationAlternativesForMarker(const DocumentMarker&);
-    void applyDictationAlternativelternative(const String& alternativeString);
+    void applyDictationAlternative(const String& alternativeString);
 
 #if USE(APPKIT)
     WEBCORE_EXPORT void uppercaseWord();

Modified: trunk/Source/WebCore/editing/cocoa/AlternativeTextUIController.h (266264 => 266265)


--- trunk/Source/WebCore/editing/cocoa/AlternativeTextUIController.h	2020-08-28 00:27:19 UTC (rev 266264)
+++ trunk/Source/WebCore/editing/cocoa/AlternativeTextUIController.h	2020-08-28 01:18:07 UTC (rev 266265)
@@ -38,7 +38,7 @@
     WEBCORE_EXPORT void removeAlternatives(DictationContext);
     WEBCORE_EXPORT void clear();
 
-    WEBCORE_EXPORT Vector<String> alternativesForContext(DictationContext);
+    WEBCORE_EXPORT NSTextAlternatives *alternativesForContext(DictationContext);
 
 #if USE(APPKIT)
     using AcceptanceHandler = void (^)(NSString *);

Modified: trunk/Source/WebCore/editing/cocoa/AlternativeTextUIController.mm (266264 => 266265)


--- trunk/Source/WebCore/editing/cocoa/AlternativeTextUIController.mm	2020-08-28 00:27:19 UTC (rev 266264)
+++ trunk/Source/WebCore/editing/cocoa/AlternativeTextUIController.mm	2020-08-28 01:18:07 UTC (rev 266265)
@@ -27,7 +27,6 @@
 #import "AlternativeTextUIController.h"
 
 #import "FloatRect.h"
-#import <wtf/cocoa/VectorCocoa.h>
 
 #if USE(APPKIT)
 #import <AppKit/NSSpellChecker.h>
@@ -46,9 +45,9 @@
     return m_contextController.addAlternatives(alternatives);
 }
 
-Vector<String> AlternativeTextUIController::alternativesForContext(DictationContext context)
+NSTextAlternatives *AlternativeTextUIController::alternativesForContext(DictationContext context)
 {
-    return makeVector<String>(m_contextController.alternativesForContext(context).alternativeStrings);
+    return m_contextController.alternativesForContext(context);
 }
 
 void AlternativeTextUIController::clear()

Modified: trunk/Source/WebCore/page/ContextMenuController.cpp (266264 => 266265)


--- trunk/Source/WebCore/page/ContextMenuController.cpp	2020-08-28 00:27:19 UTC (rev 266264)
+++ trunk/Source/WebCore/page/ContextMenuController.cpp	2020-08-28 01:18:07 UTC (rev 266265)
@@ -532,7 +532,7 @@
             page->inspectorController().inspect(m_context.hitTestResult().innerNonSharedNode());
         break;
     case ContextMenuItemTagDictationAlternative:
-        frame->editor().applyDictationAlternativelternative(title);
+        frame->editor().applyDictationAlternative(title);
         break;
     default:
         break;

Modified: trunk/Source/WebKit/ChangeLog (266264 => 266265)


--- trunk/Source/WebKit/ChangeLog	2020-08-28 00:27:19 UTC (rev 266264)
+++ trunk/Source/WebKit/ChangeLog	2020-08-28 01:18:07 UTC (rev 266265)
@@ -1,3 +1,36 @@
+2020-08-27  Devin Rousso  <[email protected]>
+
+        [iOS] provide a way to get previously inserted alternatives for the selected text
+        https://bugs.webkit.org/show_bug.cgi?id=215816
+        <rdar://problem/66646042>
+
+        Reviewed by Darin Adler.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView alternativesForSelectedText]):
+
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
+        (WebKit::WebPageProxy::platformDictationAlternatives): Added.
+        * UIProcess/PageClient.h:
+        * UIProcess/Cocoa/PageClientImplCocoa.h:
+        * UIProcess/Cocoa/PageClientImplCocoa.mm:
+        (WebKit::PageClientImplCocoa::dictationAlternatives):
+        (WebKit::PageClientImplCocoa::platformDictationAlternatives): Added.
+        Provide a way to get the raw `NSTextAlternatives *` for a given `WebCore::DictationContext`.
+
+        * Shared/EditorState.h:
+        * Shared/EditorState.cpp:
+        (WebKit::EditorState::PostLayoutData::encode const):
+        (WebKit::EditorState::PostLayoutData::decode):
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::getPlatformEditorState const):
+        Include a `Vector<WebCore::DictationContext>` as part of the `EditorState` that contains all
+        of the `WebCore::DictationContext` that exist in the currently selected range (or the range
+        of the word containing the cursor if nothing is selected).
+
+        * Platform/spi/ios/UIKitSPI.h:
+
 2020-08-27  Jer Noble  <[email protected]>
 
         REGRESSION(r264710): Initializing the AVPlayer Obj-C class at process start up causes a regression in power-use tests

Modified: trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h (266264 => 266265)


--- trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2020-08-28 00:27:19 UTC (rev 266264)
+++ trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2020-08-28 01:18:07 UTC (rev 266265)
@@ -733,6 +733,7 @@
 - (void)requestDictationContext:(void (^)(NSString *selectedText, NSString *prefixText, NSString *postfixText))completionHandler;
 - (BOOL)pointIsNearMarkedText:(CGPoint)point;
 - (NSString *)selectedText;
+- (NSArray<NSTextAlternatives *> *)alternativesForSelectedText;
 - (void)replaceText:(NSString *)text withText:(NSString *)word;
 - (void)selectWordForReplacement;
 - (BOOL)isReplaceAllowed;

Modified: trunk/Source/WebKit/Shared/EditorState.cpp (266264 => 266265)


--- trunk/Source/WebKit/Shared/EditorState.cpp	2020-08-28 00:27:19 UTC (rev 266264)
+++ trunk/Source/WebKit/Shared/EditorState.cpp	2020-08-28 01:18:07 UTC (rev 266265)
@@ -113,6 +113,9 @@
     encoder << characterAfterSelection;
     encoder << characterBeforeSelection;
     encoder << twoCharacterBeforeSelection;
+#if USE(DICTATION_ALTERNATIVES)
+    encoder << dictationContextsForSelection;
+#endif
     encoder << isReplaceAllowed;
     encoder << hasContent;
     encoder << isStableStateUpdate;
@@ -184,6 +187,10 @@
         return false;
     if (!decoder.decode(result.twoCharacterBeforeSelection))
         return false;
+#if USE(DICTATION_ALTERNATIVES)
+    if (!decoder.decode(result.dictationContextsForSelection))
+        return false;
+#endif
     if (!decoder.decode(result.isReplaceAllowed))
         return false;
     if (!decoder.decode(result.hasContent))

Modified: trunk/Source/WebKit/Shared/EditorState.h (266264 => 266265)


--- trunk/Source/WebKit/Shared/EditorState.h	2020-08-28 00:27:19 UTC (rev 266264)
+++ trunk/Source/WebKit/Shared/EditorState.h	2020-08-28 01:18:07 UTC (rev 266265)
@@ -36,6 +36,10 @@
 #include <WebCore/SelectionRect.h>
 #endif
 
+#if USE(DICTATION_ALTERNATIVES)
+#include <WebCore/DictationContext.h>
+#endif
+
 namespace WTF {
 class TextStream;
 };
@@ -100,6 +104,9 @@
         UChar32 characterAfterSelection { 0 };
         UChar32 characterBeforeSelection { 0 };
         UChar32 twoCharacterBeforeSelection { 0 };
+#if USE(DICTATION_ALTERNATIVES)
+        Vector<WebCore::DictationContext> dictationContextsForSelection;
+#endif
         bool isReplaceAllowed { false };
         bool hasContent { false };
         bool isStableStateUpdate { false };

Modified: trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h (266264 => 266265)


--- trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h	2020-08-28 00:27:19 UTC (rev 266264)
+++ trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h	2020-08-28 01:18:07 UTC (rev 266265)
@@ -65,6 +65,7 @@
     WebCore::DictationContext addDictationAlternatives(NSTextAlternatives *) final;
     void removeDictationAlternatives(WebCore::DictationContext) final;
     Vector<String> dictationAlternatives(WebCore::DictationContext) final;
+    NSTextAlternatives *platformDictationAlternatives(WebCore::DictationContext) final;
 
 protected:
     WeakObjCPtr<WKWebView> m_webView;

Modified: trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm (266264 => 266265)


--- trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm	2020-08-28 00:27:19 UTC (rev 266264)
+++ trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm	2020-08-28 01:18:07 UTC (rev 266265)
@@ -31,6 +31,8 @@
 #import "WKWebViewPrivateForTesting.h"
 #import <WebCore/AlternativeTextUIController.h>
 #import <wtf/Vector.h>
+#import <wtf/cocoa/VectorCocoa.h>
+#import <wtf/text/WTFString.h>
 
 namespace WebKit {
 
@@ -108,6 +110,11 @@
 
 Vector<String> PageClientImplCocoa::dictationAlternatives(WebCore::DictationContext dictationContext)
 {
+    return makeVector<String>(platformDictationAlternatives(dictationContext).alternativeStrings);
+}
+
+NSTextAlternatives *PageClientImplCocoa::platformDictationAlternatives(WebCore::DictationContext dictationContext)
+{
     return m_alternativeTextUIController->alternativesForContext(dictationContext);
 }
     

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm (266264 => 266265)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2020-08-28 00:27:19 UTC (rev 266264)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2020-08-28 01:18:07 UTC (rev 266265)
@@ -299,6 +299,15 @@
     send(Messages::WebPage::InsertDictatedTextAsync { text, replacementRange, dictationAlternatives, WTFMove(options) });
 }
 
+#if USE(DICTATION_ALTERNATIVES)
+
+NSTextAlternatives *WebPageProxy::platformDictationAlternatives(WebCore::DictationContext dictationContext)
+{
+    return pageClient().platformDictationAlternatives(dictationContext);
+}
+
+#endif
+
 ResourceError WebPageProxy::errorForUnpermittedAppBoundDomainNavigation(const URL& url)
 {
     return { WKErrorDomain, WKErrorNavigationAppBoundDomain, url, localizedDescriptionForErrorCode(WKErrorNavigationAppBoundDomain) };

Modified: trunk/Source/WebKit/UIProcess/PageClient.h (266264 => 266265)


--- trunk/Source/WebKit/UIProcess/PageClient.h	2020-08-28 00:27:19 UTC (rev 266264)
+++ trunk/Source/WebKit/UIProcess/PageClient.h	2020-08-28 01:18:07 UTC (rev 266265)
@@ -378,6 +378,7 @@
     virtual void removeDictationAlternatives(WebCore::DictationContext) = 0;
     virtual void showDictationAlternativeUI(const WebCore::FloatRect& boundingBoxOfDictatedText, WebCore::DictationContext) = 0;
     virtual Vector<String> dictationAlternatives(WebCore::DictationContext) = 0;
+    virtual NSTextAlternatives *platformDictationAlternatives(WebCore::DictationContext) = 0;
 #endif
 
 #if PLATFORM(MAC)

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (266264 => 266265)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2020-08-28 00:27:19 UTC (rev 266264)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2020-08-28 01:18:07 UTC (rev 266265)
@@ -129,6 +129,7 @@
 #include "EndowmentStateTracker.h"
 #endif
 
+OBJC_CLASS NSTextAlternatives;
 OBJC_CLASS NSView;
 OBJC_CLASS _WKRemoteObjectRegistry;
 
@@ -884,6 +885,10 @@
     void insertTextAsync(const String&, const EditingRange& replacementRange, InsertTextOptions&&);
     void insertDictatedTextAsync(const String&, const EditingRange& replacementRange, const Vector<WebCore::TextAlternativeWithRange>&, InsertTextOptions&&);
 
+#if USE(DICTATION_ALTERNATIVES)
+    NSTextAlternatives *platformDictationAlternatives(WebCore::DictationContext);
+#endif
+
     void hasMarkedText(CompletionHandler<void(bool)>&&);
     void getMarkedRangeAsync(CompletionHandler<void(const EditingRange&)>&&);
     void getSelectedRangeAsync(CompletionHandler<void(const EditingRange&)>&&);

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (266264 => 266265)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2020-08-28 00:27:19 UTC (rev 266264)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2020-08-28 01:18:07 UTC (rev 266265)
@@ -3118,6 +3118,14 @@
     return (NSString *)_page->editorState().postLayoutData().wordAtSelection;
 }
 
+- (NSArray<NSTextAlternatives *> *)alternativesForSelectedText
+{
+    auto& dictationContextsForSelection = _page->editorState().postLayoutData().dictationContextsForSelection;
+    return createNSArray(dictationContextsForSelection, [&] (auto& dictationContext) {
+        return _page->platformDictationAlternatives(dictationContext);
+    }).autorelease();
+}
+
 - (void)makeTextWritingDirectionNaturalForWebView:(id)sender
 {
     // Match platform behavior on iOS as well as legacy WebKit behavior by modifying the

Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (266264 => 266265)


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2020-08-28 00:27:19 UTC (rev 266264)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2020-08-28 01:18:07 UTC (rev 266265)
@@ -69,6 +69,7 @@
 #import <WebCore/DiagnosticLoggingClient.h>
 #import <WebCore/DiagnosticLoggingKeys.h>
 #import <WebCore/DocumentLoader.h>
+#import <WebCore/DocumentMarkerController.h>
 #import <WebCore/DragController.h>
 #import <WebCore/Editing.h>
 #import <WebCore/Editor.h>
@@ -121,6 +122,7 @@
 #import <WebCore/RenderLayer.h>
 #import <WebCore/RenderThemeIOS.h>
 #import <WebCore/RenderView.h>
+#import <WebCore/RenderedDocumentMarker.h>
 #import <WebCore/RuntimeApplicationChecks.h>
 #import <WebCore/Settings.h>
 #import <WebCore/ShadowRoot.h>
@@ -280,6 +282,7 @@
     }
 
     const auto& selection = frame.selection().selection();
+    Optional<SimpleRange> selectedRange;
     postLayoutData.isStableStateUpdate = m_isInStableState;
     bool startNodeIsInsideFixedPosition = false;
     bool endNodeIsInsideFixedPosition = false;
@@ -289,13 +292,16 @@
         postLayoutData.caretRectAtEnd = postLayoutData.caretRectAtStart;
         // FIXME: The following check should take into account writing direction.
         postLayoutData.isReplaceAllowed = result.isContentEditable && atBoundaryOfGranularity(selection.start(), TextGranularity::WordGranularity, SelectionDirection::Forward);
-        postLayoutData.wordAtSelection = plainTextForContext(wordRangeFromPosition(selection.start()));
+
+        selectedRange = wordRangeFromPosition(selection.start());
+        postLayoutData.wordAtSelection = plainTextForContext(selectedRange);
+
         if (selection.isContentEditable())
             charactersAroundPosition(selection.start(), postLayoutData.characterAfterSelection, postLayoutData.characterBeforeSelection, postLayoutData.twoCharacterBeforeSelection);
     } else if (selection.isRange()) {
         postLayoutData.caretRectAtStart = view->contentsToRootView(VisiblePosition(selection.start()).absoluteCaretBounds(&startNodeIsInsideFixedPosition));
         postLayoutData.caretRectAtEnd = view->contentsToRootView(VisiblePosition(selection.end()).absoluteCaretBounds(&endNodeIsInsideFixedPosition));
-        auto selectedRange = selection.toNormalizedRange();
+        selectedRange = selection.toNormalizedRange();
         String selectedText;
         if (selectedRange) {
             postLayoutData.selectionRects = RenderObject::collectSelectionRects(*selectedRange);
@@ -308,6 +314,16 @@
         // FIXME: We should disallow replace when the string contains only CJ characters.
         postLayoutData.isReplaceAllowed = result.isContentEditable && !result.isInPasswordField && !selectedText.isAllSpecialCharacters<isHTMLSpace>();
     }
+
+#if USE(DICTATION_ALTERNATIVES)
+    if (selectedRange) {
+        auto markers = frame.document()->markers().markersInRange(*selectedRange, DocumentMarker::MarkerType::DictationAlternatives);
+        postLayoutData.dictationContextsForSelection = WTF::map(markers, [] (auto* marker) {
+            return WTF::get<DocumentMarker::DictationData>(marker->data()).context;
+        });
+    }
+#endif
+
     postLayoutData.atStartOfSentence = frame.selection().selectionAtSentenceStart();
     postLayoutData.insideFixedPosition = startNodeIsInsideFixedPosition || endNodeIsInsideFixedPosition;
     if (!selection.isNone()) {

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (266264 => 266265)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2020-08-28 00:27:19 UTC (rev 266264)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2020-08-28 01:18:07 UTC (rev 266265)
@@ -1,3 +1,16 @@
+2020-08-27  Devin Rousso  <[email protected]>
+
+        [iOS] provide a way to get previously inserted alternatives for the selected text
+        https://bugs.webkit.org/show_bug.cgi?id=215816
+        <rdar://problem/66646042>
+
+        Reviewed by Darin Adler.
+
+        * WebView/WebView.mm:
+        (-[WebView _dictationAlternatives:]):
+        Create a `Vector<String>` from the returned `NSTextAlternatives *` now that the member
+        `WebCore::AlternativeTextUIController::alternativesForContext` returns it.
+
 2020-08-27  Youenn Fablet  <[email protected]>
 
         Add support for TransformStream

Modified: trunk/Source/WebKitLegacy/mac/WebView/WebView.mm (266264 => 266265)


--- trunk/Source/WebKitLegacy/mac/WebView/WebView.mm	2020-08-28 00:27:19 UTC (rev 266264)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebView.mm	2020-08-28 01:18:07 UTC (rev 266265)
@@ -9596,7 +9596,7 @@
 
 - (Vector<String>)_dictationAlternatives:(WebCore::DictationContext)dictationContext
 {
-    return _private->m_alternativeTextUIController->alternativesForContext(dictationContext);
+    return makeVector<String>(_private->m_alternativeTextUIController->alternativesForContext(dictationContext).alternativeStrings);
 }
 
 #if ENABLE(SERVICE_CONTROLS)

Modified: trunk/Tools/ChangeLog (266264 => 266265)


--- trunk/Tools/ChangeLog	2020-08-28 00:27:19 UTC (rev 266264)
+++ trunk/Tools/ChangeLog	2020-08-28 01:18:07 UTC (rev 266265)
@@ -1,3 +1,16 @@
+2020-08-27  Devin Rousso  <[email protected]>
+
+        [iOS] provide a way to get previously inserted alternatives for the selected text
+        https://bugs.webkit.org/show_bug.cgi?id=215816
+        <rdar://problem/66646042>
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/InsertTextAlternatives.mm:
+        (InsertTextAlternatives.Simple):
+
+        * TestWebKitAPI/ios/UIKitSPI.h:
+
 2020-08-27  Aakash Jain  <[email protected]>
 
         Ensure that email notifications are not sent for obsolete and r- patches

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/InsertTextAlternatives.mm (266264 => 266265)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/InsertTextAlternatives.mm	2020-08-28 00:27:19 UTC (rev 266264)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/InsertTextAlternatives.mm	2020-08-28 01:18:07 UTC (rev 266265)
@@ -56,6 +56,18 @@
     EXPECT_FALSE([[webView objectByEvaluatingJavaScript:@"internals.hasDictationAlternativesMarker(2, 3)"] boolValue]); // big
     EXPECT_FALSE([[webView objectByEvaluatingJavaScript:@"internals.hasDictationAlternativesMarker(0, 6)"] boolValue]); // "A big "
     EXPECT_TRUE([[webView objectByEvaluatingJavaScript:@"internals.hasDictationAlternativesMarker(6, 5)"] boolValue]); // hello
+
+    [webView objectByEvaluatingJavaScript:@"getSelection().setPosition(document.body.firstChild, 8)"]; // in the middle of "hello"
+    [webView waitForNextPresentationUpdate];
+
+    EXPECT_WK_STREQ("hello", [[webView textInputContentView] selectedText]);
+
+    auto *alternatives = [(id<UIWKInteractionViewProtocol_Staging66646042>)[webView textInputContentView] alternativesForSelectedText];
+    EXPECT_EQ(1ul, alternatives.count);
+    EXPECT_WK_STREQ("hello", alternatives[0].primaryString);
+    EXPECT_EQ(1ul, alternatives[0].alternativeStrings.count);
+    EXPECT_WK_STREQ("yellow", alternatives[0].alternativeStrings[0]);
+    EXPECT_FALSE(alternatives[0].isLowConfidence);
 }
 
 TEST(InsertTextAlternatives, InsertLeadingSpace)

Modified: trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h (266264 => 266265)


--- trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h	2020-08-28 00:27:19 UTC (rev 266264)
+++ trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h	2020-08-28 01:18:07 UTC (rev 266265)
@@ -29,6 +29,7 @@
 
 #if USE(APPLE_INTERNAL_SDK)
 
+#import <UIKit/NSTextAlternatives.h>
 #import <UIKit/UIApplication_Private.h>
 #import <UIKit/UIBarButtonItemGroup_Private.h>
 #import <UIKit/UICalloutBar.h>
@@ -61,6 +62,12 @@
 
 #else // USE(APPLE_INTERNAL_SDK)
 
+@interface NSTextAlternatives : NSObject
+@property (readonly) NSString *primaryString;
+@property (readonly) NSArray<NSString *> *alternativeStrings;
+@property (readonly) BOOL isLowConfidence;
+@end
+
 WTF_EXTERN_C_BEGIN
 
 void UIApplicationInitialize(void);
@@ -238,6 +245,11 @@
 #define UIWKDocumentRequestMarkedTextRects (1 << 5)
 #define UIWKDocumentRequestSpatialAndCurrentSelection (1 << 6)
 
+@protocol UIWKInteractionViewProtocol_Staging66646042 <UIWKInteractionViewProtocol>
+@optional
+- (NSArray<NSTextAlternatives *> *)alternativesForSelectedText;
+@end
+
 @interface UITextAutofillSuggestion ()
 + (instancetype)autofillSuggestionWithUsername:(NSString *)username password:(NSString *)password;
 @end
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to