Title: [258088] trunk/Source/WebKit
- Revision
- 258088
- Author
- [email protected]
- Date
- 2020-03-07 16:33:56 -0800 (Sat, 07 Mar 2020)
Log Message
[iOS] Implement support for dictation alternatives
https://bugs.webkit.org/show_bug.cgi?id=208720
<rdar://problem/58540114>
Reviewed by Brady Eidson.
Part 4
This patch was originally written by Morgan Winer. I just simplified it a bit and fixed some
formatting issues to conform to the code style guidelines.
Note that I haven't enable USE_DICTATION_ALTERNATIVES on iOS. So, this code isn't being
compiled for iOS. I will do that in a subsequent change once after all the code is in place
to do so.
* Platform/spi/ios/UIKitSPI.h: Expose more SPI.
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView insertText:alternatives:style:]): Added.
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (258087 => 258088)
--- trunk/Source/WebKit/ChangeLog 2020-03-08 00:30:28 UTC (rev 258087)
+++ trunk/Source/WebKit/ChangeLog 2020-03-08 00:33:56 UTC (rev 258088)
@@ -4,6 +4,27 @@
https://bugs.webkit.org/show_bug.cgi?id=208720
<rdar://problem/58540114>
+ Reviewed by Brady Eidson.
+
+ Part 4
+
+ This patch was originally written by Morgan Winer. I just simplified it a bit and fixed some
+ formatting issues to conform to the code style guidelines.
+
+ Note that I haven't enable USE_DICTATION_ALTERNATIVES on iOS. So, this code isn't being
+ compiled for iOS. I will do that in a subsequent change once after all the code is in place
+ to do so.
+
+ * Platform/spi/ios/UIKitSPI.h: Expose more SPI.
+ * UIProcess/ios/WKContentViewInteraction.mm:
+ (-[WKContentView insertText:alternatives:style:]): Added.
+
+2020-03-07 Daniel Bates <[email protected]>
+
+ [iOS] Implement support for dictation alternatives
+ https://bugs.webkit.org/show_bug.cgi?id=208720
+ <rdar://problem/58540114>
+
Reviewed by Brent Fulgham.
Part 3
Modified: trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h (258087 => 258088)
--- trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h 2020-03-08 00:30:28 UTC (rev 258087)
+++ trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h 2020-03-08 00:33:56 UTC (rev 258088)
@@ -27,6 +27,7 @@
#if USE(APPLE_INTERNAL_SDK)
+#import <UIKit/NSTextAlternatives.h>
#import <UIKit/UIAlertController_Private.h>
#import <UIKit/UIApplication_Private.h>
#import <UIKit/UIBarButtonItem_Private.h>
@@ -1114,7 +1115,15 @@
@end
#endif // HAVE(LINK_PREVIEW) && USE(UICONTEXTMENU)
+@interface NSTextAlternatives : NSObject
+- (id)initWithPrimaryString:(NSString *)primaryString alternativeStrings:(NSArray<NSString *> *)alternativeStrings;
+- (id)initWithPrimaryString:(NSString *)primaryString alternativeStrings:(NSArray<NSString *> *)alternativeStrings isLowConfidence:(BOOL)lowConfidence;
+@property (readonly) NSString *primaryString;
+@property (readonly) NSArray<NSString *> *alternativeStrings;
+@property (readonly) BOOL isLowConfidence;
+@end
+
#endif // USE(APPLE_INTERNAL_SDK)
#define UIWKDocumentRequestMarkedTextRects (1 << 5)
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (258087 => 258088)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2020-03-08 00:30:28 UTC (rev 258087)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2020-03-08 00:33:56 UTC (rev 258088)
@@ -165,6 +165,11 @@
#import <WebCore/TouchAction.h>
#endif
+#if USE(DICTATION_ALTERNATIVES)
+#import "UIKitSPI.h"
+#import <WebCore/TextAlternativeWithRange.h>
+#endif
+
#if HAVE(LINK_PREVIEW) && USE(UICONTEXTMENU)
static NSString * const webkitShowLinkPreviewsPreferenceKey = @"WebKitShowLinkPreviews";
#endif
@@ -4742,6 +4747,22 @@
_page->insertTextAsync(aStringValue, WebKit::EditingRange(), WTFMove(options));
}
+#if USE(DICTATION_ALTERNATIVES)
+
+- (void)insertText:(NSString *)aStringValue alternatives:(NSArray<NSString *> *)alternatives style:(UITextAlternativeStyle)style
+{
+ if (!alternatives.count)
+ [self insertText:aStringValue];
+ else {
+ BOOL isLowConfidence = style == UITextAlternativeStyleLowConfidence;
+ auto textAlternatives = adoptNS([[NSTextAlternatives alloc] initWithPrimaryString:aStringValue alternativeStrings:alternatives isLowConfidence:isLowConfidence]);
+ WebCore::TextAlternativeWithRange textAlternativeWithRange { textAlternatives.get(), NSMakeRange(0, aStringValue.length) };
+ _page->insertDictatedTextAsync(aStringValue, WebKit::EditingRange { }, { textAlternativeWithRange }, false /* registerUndoGroup */);
+ }
+}
+
+#endif
+
- (BOOL)hasText
{
auto& editorState = _page->editorState();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes