Diff
Modified: branches/safari-610-branch/Source/WebCore/ChangeLog (266554 => 266555)
--- branches/safari-610-branch/Source/WebCore/ChangeLog 2020-09-03 21:31:15 UTC (rev 266554)
+++ branches/safari-610-branch/Source/WebCore/ChangeLog 2020-09-03 21:31:21 UTC (rev 266555)
@@ -1,5 +1,97 @@
2020-09-03 Alan Coon <alanc...@apple.com>
+ Cherry-pick r266265. rdar://problem/68168939
+
+ [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:
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266265 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2020-08-27 Devin Rousso <drou...@apple.com>
+
+ [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-09-03 Alan Coon <alanc...@apple.com>
+
Cherry-pick r266218. rdar://problem/68168930
REGRESSION: touchbar controls don't reflect video state in fullscreen
Modified: branches/safari-610-branch/Source/WebCore/editing/Editor.cpp (266554 => 266555)
--- branches/safari-610-branch/Source/WebCore/editing/Editor.cpp 2020-09-03 21:31:15 UTC (rev 266554)
+++ branches/safari-610-branch/Source/WebCore/editing/Editor.cpp 2020-09-03 21:31:21 UTC (rev 266555)
@@ -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: branches/safari-610-branch/Source/WebCore/editing/Editor.h (266554 => 266555)
--- branches/safari-610-branch/Source/WebCore/editing/Editor.h 2020-09-03 21:31:15 UTC (rev 266554)
+++ branches/safari-610-branch/Source/WebCore/editing/Editor.h 2020-09-03 21:31:21 UTC (rev 266555)
@@ -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: branches/safari-610-branch/Source/WebCore/editing/cocoa/AlternativeTextUIController.h (266554 => 266555)
--- branches/safari-610-branch/Source/WebCore/editing/cocoa/AlternativeTextUIController.h 2020-09-03 21:31:15 UTC (rev 266554)
+++ branches/safari-610-branch/Source/WebCore/editing/cocoa/AlternativeTextUIController.h 2020-09-03 21:31:21 UTC (rev 266555)
@@ -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: branches/safari-610-branch/Source/WebCore/editing/cocoa/AlternativeTextUIController.mm (266554 => 266555)
--- branches/safari-610-branch/Source/WebCore/editing/cocoa/AlternativeTextUIController.mm 2020-09-03 21:31:15 UTC (rev 266554)
+++ branches/safari-610-branch/Source/WebCore/editing/cocoa/AlternativeTextUIController.mm 2020-09-03 21:31:21 UTC (rev 266555)
@@ -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: branches/safari-610-branch/Source/WebCore/page/ContextMenuController.cpp (266554 => 266555)
--- branches/safari-610-branch/Source/WebCore/page/ContextMenuController.cpp 2020-09-03 21:31:15 UTC (rev 266554)
+++ branches/safari-610-branch/Source/WebCore/page/ContextMenuController.cpp 2020-09-03 21:31:21 UTC (rev 266555)
@@ -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: branches/safari-610-branch/Source/WebKit/ChangeLog (266554 => 266555)
--- branches/safari-610-branch/Source/WebKit/ChangeLog 2020-09-03 21:31:15 UTC (rev 266554)
+++ branches/safari-610-branch/Source/WebKit/ChangeLog 2020-09-03 21:31:21 UTC (rev 266555)
@@ -1,5 +1,108 @@
2020-09-03 Alan Coon <alanc...@apple.com>
+ Cherry-pick r266265. rdar://problem/68168939
+
+ [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:
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266265 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2020-08-27 Devin Rousso <drou...@apple.com>
+
+ [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-09-03 Alan Coon <alanc...@apple.com>
+
Cherry-pick r266158. rdar://problem/67812825
Web Share API Level 2 functions even when its experimental feature flag is disabled
Modified: branches/safari-610-branch/Source/WebKit/Platform/spi/ios/UIKitSPI.h (266554 => 266555)
--- branches/safari-610-branch/Source/WebKit/Platform/spi/ios/UIKitSPI.h 2020-09-03 21:31:15 UTC (rev 266554)
+++ branches/safari-610-branch/Source/WebKit/Platform/spi/ios/UIKitSPI.h 2020-09-03 21:31:21 UTC (rev 266555)
@@ -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: branches/safari-610-branch/Source/WebKit/Shared/EditorState.cpp (266554 => 266555)
--- branches/safari-610-branch/Source/WebKit/Shared/EditorState.cpp 2020-09-03 21:31:15 UTC (rev 266554)
+++ branches/safari-610-branch/Source/WebKit/Shared/EditorState.cpp 2020-09-03 21:31:21 UTC (rev 266555)
@@ -113,6 +113,9 @@
encoder << characterAfterSelection;
encoder << characterBeforeSelection;
encoder << twoCharacterBeforeSelection;
+#if USE(DICTATION_ALTERNATIVES)
+ encoder << dictationContextsForSelection;
+#endif
encoder << isReplaceAllowed;
encoder << hasContent;
encoder << isStableStateUpdate;
@@ -183,6 +186,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: branches/safari-610-branch/Source/WebKit/Shared/EditorState.h (266554 => 266555)
--- branches/safari-610-branch/Source/WebKit/Shared/EditorState.h 2020-09-03 21:31:15 UTC (rev 266554)
+++ branches/safari-610-branch/Source/WebKit/Shared/EditorState.h 2020-09-03 21:31:21 UTC (rev 266555)
@@ -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: branches/safari-610-branch/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h (266554 => 266555)
--- branches/safari-610-branch/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h 2020-09-03 21:31:15 UTC (rev 266554)
+++ branches/safari-610-branch/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h 2020-09-03 21:31:21 UTC (rev 266555)
@@ -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: branches/safari-610-branch/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm (266554 => 266555)
--- branches/safari-610-branch/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm 2020-09-03 21:31:15 UTC (rev 266554)
+++ branches/safari-610-branch/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm 2020-09-03 21:31:21 UTC (rev 266555)
@@ -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: branches/safari-610-branch/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm (266554 => 266555)
--- branches/safari-610-branch/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm 2020-09-03 21:31:15 UTC (rev 266554)
+++ branches/safari-610-branch/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm 2020-09-03 21:31:21 UTC (rev 266555)
@@ -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: branches/safari-610-branch/Source/WebKit/UIProcess/PageClient.h (266554 => 266555)
--- branches/safari-610-branch/Source/WebKit/UIProcess/PageClient.h 2020-09-03 21:31:15 UTC (rev 266554)
+++ branches/safari-610-branch/Source/WebKit/UIProcess/PageClient.h 2020-09-03 21:31:21 UTC (rev 266555)
@@ -369,6 +369,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: branches/safari-610-branch/Source/WebKit/UIProcess/WebPageProxy.h (266554 => 266555)
--- branches/safari-610-branch/Source/WebKit/UIProcess/WebPageProxy.h 2020-09-03 21:31:15 UTC (rev 266554)
+++ branches/safari-610-branch/Source/WebKit/UIProcess/WebPageProxy.h 2020-09-03 21:31:21 UTC (rev 266555)
@@ -129,6 +129,7 @@
#include "EndowmentStateTracker.h"
#endif
+OBJC_CLASS NSTextAlternatives;
OBJC_CLASS NSView;
OBJC_CLASS _WKRemoteObjectRegistry;
@@ -879,6 +880,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: branches/safari-610-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (266554 => 266555)
--- branches/safari-610-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2020-09-03 21:31:15 UTC (rev 266554)
+++ branches/safari-610-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2020-09-03 21:31:21 UTC (rev 266555)
@@ -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: branches/safari-610-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (266554 => 266555)
--- branches/safari-610-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2020-09-03 21:31:15 UTC (rev 266554)
+++ branches/safari-610-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2020-09-03 21:31:21 UTC (rev 266555)
@@ -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: branches/safari-610-branch/Source/WebKitLegacy/mac/ChangeLog (266554 => 266555)
--- branches/safari-610-branch/Source/WebKitLegacy/mac/ChangeLog 2020-09-03 21:31:15 UTC (rev 266554)
+++ branches/safari-610-branch/Source/WebKitLegacy/mac/ChangeLog 2020-09-03 21:31:21 UTC (rev 266555)
@@ -1,3 +1,86 @@
+2020-09-03 Alan Coon <alanc...@apple.com>
+
+ Cherry-pick r266265. rdar://problem/68168939
+
+ [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:
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266265 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2020-08-27 Devin Rousso <drou...@apple.com>
+
+ [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-09-01 Alan Coon <alanc...@apple.com>
Cherry-pick r266143. rdar://problem/68164547
Modified: branches/safari-610-branch/Source/WebKitLegacy/mac/WebView/WebView.mm (266554 => 266555)
--- branches/safari-610-branch/Source/WebKitLegacy/mac/WebView/WebView.mm 2020-09-03 21:31:15 UTC (rev 266554)
+++ branches/safari-610-branch/Source/WebKitLegacy/mac/WebView/WebView.mm 2020-09-03 21:31:21 UTC (rev 266555)
@@ -9595,7 +9595,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: branches/safari-610-branch/Tools/ChangeLog (266554 => 266555)
--- branches/safari-610-branch/Tools/ChangeLog 2020-09-03 21:31:15 UTC (rev 266554)
+++ branches/safari-610-branch/Tools/ChangeLog 2020-09-03 21:31:21 UTC (rev 266555)
@@ -1,3 +1,86 @@
+2020-09-03 Alan Coon <alanc...@apple.com>
+
+ Cherry-pick r266265. rdar://problem/68168939
+
+ [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:
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266265 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2020-08-27 Devin Rousso <drou...@apple.com>
+
+ [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-09-01 Alan Coon <alanc...@apple.com>
Cherry-pick r266134. rdar://problem/68164543
Modified: branches/safari-610-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/InsertTextAlternatives.mm (266554 => 266555)
--- branches/safari-610-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/InsertTextAlternatives.mm 2020-09-03 21:31:15 UTC (rev 266554)
+++ branches/safari-610-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/InsertTextAlternatives.mm 2020-09-03 21:31:21 UTC (rev 266555)
@@ -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: branches/safari-610-branch/Tools/TestWebKitAPI/ios/UIKitSPI.h (266554 => 266555)
--- branches/safari-610-branch/Tools/TestWebKitAPI/ios/UIKitSPI.h 2020-09-03 21:31:15 UTC (rev 266554)
+++ branches/safari-610-branch/Tools/TestWebKitAPI/ios/UIKitSPI.h 2020-09-03 21:31:21 UTC (rev 266555)
@@ -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