Title: [258085] trunk/Source
Revision
258085
Author
[email protected]
Date
2020-03-07 16:26:17 -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 Wenson Hsieh.

Part 1

Source/WebCore:

Rename editing/mac/AlternativeTextUIController.{h, mm} to editing/cocoa/AlternativeTextUIController.{h, mm}
as it can be shared by both Mac and iOS. I also took this opportunity to do some very minor modernization
and cleanup to these files: use =default constructors and put the * on the right side for Objective-C types.

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.

* SourcesCocoa.txt:
* WebCore.xcodeproj/project.pbxproj:
* editing/cocoa/AlternativeTextContextController.h:
* editing/cocoa/AlternativeTextContextController.mm: Added.
(WebCore::AlternativeTextContextController::addAlternatives):
(WebCore::AlternativeTextContextController::alternativesForContext):
(WebCore::AlternativeTextContextController::removeAlternativesForContext):
(WebCore::AlternativeTextContextController::clear):
* editing/cocoa/AlternativeTextUIController.h: Renamed from Source/WebCore/editing/mac/AlternativeTextUIController.h.
* editing/cocoa/AlternativeTextUIController.mm: Renamed from Source/WebCore/editing/mac/AlternativeTextUIController.mm.
(WebCore::AlternativeTextUIController::addAlternatives):
(WebCore::AlternativeTextUIController::alternativesForContext):
(WebCore::AlternativeTextUIController::clear):
(WebCore::AlternativeTextUIController::showAlternatives):
(WebCore::AlternativeTextUIController::handleAcceptedAlternative):
(WebCore::AlternativeTextUIController::dismissAlternatives):
(WebCore::AlternativeTextUIController::removeAlternatives):

Source/WebCore/PAL:

Expose some more SPI.

* pal/spi/ios/UIKitSPI.h:

Source/WebKit:

Move some of the PageClientMac dictation alternatives code to PageClientImplCocoa so that it
can be shared with iOS.

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.

* UIProcess/Cocoa/PageClientImplCocoa.h:
(WebKit::PageClientImplCocoa::PageClientImplCocoa): Deleted; moved to be out-of-line to avoid
needing to #include AlternativeTextUIController.h from this file. Declare out-of-line destructor
for the same reason.
* UIProcess/Cocoa/PageClientImplCocoa.mm:
(WebKit::PageClientImplCocoa::PageClientImplCocoa): Moved from PageClientImplCocoa.h.
(WebKit::PageClientImplCocoa::pageClosed):
(WebKit::PageClientImplCocoa::addDictationAlternatives): Moved from PageClientImplMac.mm.
(WebKit::PageClientImplCocoa::removeDictationAlternatives): Ditto.
(WebKit::PageClientImplCocoa::dictationAlternatives): Ditto.
* UIProcess/PageClient.h:
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::showDictationAlternativeUI): Added; stub function.
(WebKit::PageClientImpl::pageClosed): Deleted; now we will use the base class implementation.
* UIProcess/mac/PageClientImplMac.h:
* UIProcess/mac/PageClientImplMac.mm:
(WebKit::PageClientImpl::PageClientImpl): Moved AlternativeTextUIController logic from here to PageClientImplCocoa::PageClientImplCocoa().
(WebKit::PageClientImpl::pageClosed): Moved AlternativeTextUIController logic from here to PageClientImplCocoa::pageClosed()
so it can be shared and modified this function to call the base class implementation.
(WebKit::PageClientImpl::~PageClientImpl): Deleted; moved to PageClientImplCocoa.mm.
(WebKit::PageClientImpl::addDictationAlternatives): Deleted; moved to PageClientImplCocoa.mm.
(WebKit::PageClientImpl::removeDictationAlternatives): Deleted; moved to PageClientImplCocoa.mm.
(WebKit::PageClientImpl::dictationAlternatives): Deleted; moved to PageClientImplCocoa.mm.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (258084 => 258085)


--- trunk/Source/WebCore/ChangeLog	2020-03-08 00:14:50 UTC (rev 258084)
+++ trunk/Source/WebCore/ChangeLog	2020-03-08 00:26:17 UTC (rev 258085)
@@ -1,3 +1,39 @@
+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 Wenson Hsieh.
+
+        Part 1
+
+        Rename editing/mac/AlternativeTextUIController.{h, mm} to editing/cocoa/AlternativeTextUIController.{h, mm}
+        as it can be shared by both Mac and iOS. I also took this opportunity to do some very minor modernization
+        and cleanup to these files: use =default constructors and put the * on the right side for Objective-C types.
+
+        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.
+
+        * SourcesCocoa.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * editing/cocoa/AlternativeTextContextController.h:
+        * editing/cocoa/AlternativeTextContextController.mm: Added.
+        (WebCore::AlternativeTextContextController::addAlternatives):
+        (WebCore::AlternativeTextContextController::alternativesForContext):
+        (WebCore::AlternativeTextContextController::removeAlternativesForContext):
+        (WebCore::AlternativeTextContextController::clear):
+        * editing/cocoa/AlternativeTextUIController.h: Renamed from Source/WebCore/editing/mac/AlternativeTextUIController.h.
+        * editing/cocoa/AlternativeTextUIController.mm: Renamed from Source/WebCore/editing/mac/AlternativeTextUIController.mm.
+        (WebCore::AlternativeTextUIController::addAlternatives):
+        (WebCore::AlternativeTextUIController::alternativesForContext):
+        (WebCore::AlternativeTextUIController::clear):
+        (WebCore::AlternativeTextUIController::showAlternatives):
+        (WebCore::AlternativeTextUIController::handleAcceptedAlternative):
+        (WebCore::AlternativeTextUIController::dismissAlternatives):
+        (WebCore::AlternativeTextUIController::removeAlternatives):
+
 2020-03-07  Fujii Hironori  <[email protected]>
 
         [CMake][Win] GenerateSettings.rb are invoked twice in WebCoreBindings.vcxproj and WebCoreTestSupportBindings.vcxproj

Modified: trunk/Source/WebCore/PAL/ChangeLog (258084 => 258085)


--- trunk/Source/WebCore/PAL/ChangeLog	2020-03-08 00:14:50 UTC (rev 258084)
+++ trunk/Source/WebCore/PAL/ChangeLog	2020-03-08 00:26:17 UTC (rev 258085)
@@ -1,3 +1,17 @@
+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 Wenson Hsieh.
+
+        Part 1
+
+        Expose some more SPI.
+
+        * pal/spi/ios/UIKitSPI.h:
+
 2020-03-05  Sam Weinig  <[email protected]>
 
         Move _javascript_Core related feature defines from FeatureDefines.xcconfig to PlatformEnableCocoa.h

Modified: trunk/Source/WebCore/PAL/pal/spi/ios/UIKitSPI.h (258084 => 258085)


--- trunk/Source/WebCore/PAL/pal/spi/ios/UIKitSPI.h	2020-03-08 00:14:50 UTC (rev 258084)
+++ trunk/Source/WebCore/PAL/pal/spi/ios/UIKitSPI.h	2020-03-08 00:26:17 UTC (rev 258085)
@@ -32,6 +32,7 @@
 #if USE(APPLE_INTERNAL_SDK)
 
 #import <UIKit/NSParagraphStyle_Private.h>
+#import <UIKit/NSTextAlternatives.h>
 #import <UIKit/NSTextAttachment_Private.h>
 #import <UIKit/NSTextList.h>
 #import <UIKit/UIApplicationSceneConstants.h>
@@ -98,6 +99,10 @@
 - (NSString *)markerForItemNumber:(NSInteger)itemNum;
 @end
 
+@interface NSTextAlternatives : NSObject
+@property (readonly) NSArray<NSString *> *alternativeStrings;
+@end
+
 @interface UIApplication ()
 - (BOOL)_isClassic;
 + (UIApplicationSceneClassicMode)_classicMode;

Modified: trunk/Source/WebCore/SourcesCocoa.txt (258084 => 258085)


--- trunk/Source/WebCore/SourcesCocoa.txt	2020-03-08 00:14:50 UTC (rev 258084)
+++ trunk/Source/WebCore/SourcesCocoa.txt	2020-03-08 00:26:17 UTC (rev 258085)
@@ -79,6 +79,8 @@
 editing/SelectionRectGatherer.cpp
 editing/SmartReplaceCF.cpp
 
+editing/cocoa/AlternativeTextContextController.mm
+editing/cocoa/AlternativeTextUIController.mm
 editing/cocoa/AutofillElements.cpp
 editing/cocoa/DataDetection.mm
 editing/cocoa/DictionaryLookup.mm
@@ -94,7 +96,6 @@
 editing/ios/DictationCommandIOS.cpp
 editing/ios/EditorIOS.mm
 
-editing/mac/AlternativeTextUIController.mm
 editing/mac/DictionaryLookupLegacy.mm
 editing/mac/EditorMac.mm
 editing/mac/FrameSelectionMac.mm

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (258084 => 258085)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-03-08 00:14:50 UTC (rev 258084)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-03-08 00:26:17 UTC (rev 258085)
@@ -4242,6 +4242,7 @@
 		CE1A501F22D5350900CBC927 /* DOMTimerHoldingTank.h in Headers */ = {isa = PBXBuildFile; fileRef = CE1A501D22D5350900CBC927 /* DOMTimerHoldingTank.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		CE212158240DBEB9006ED443 /* TextPlaceholderElement.h in Headers */ = {isa = PBXBuildFile; fileRef = CE212153240DBD30006ED443 /* TextPlaceholderElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		CE2849871CA360DF00B4A57F /* ContentSecurityPolicyDirectiveNames.h in Headers */ = {isa = PBXBuildFile; fileRef = CE2849861CA360DF00B4A57F /* ContentSecurityPolicyDirectiveNames.h */; };
+		CE45946F24123C960078019F /* AlternativeTextContextController.h in Headers */ = {isa = PBXBuildFile; fileRef = CE45946424121A050078019F /* AlternativeTextContextController.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		CE5169E721F1B84700EA4F78 /* ColorIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = CE5169E521F1B84700EA4F78 /* ColorIOS.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		CE5FA255209E48C50051D700 /* ContentSecurityPolicyClient.h in Headers */ = {isa = PBXBuildFile; fileRef = CE5FA253209E48C50051D700 /* ContentSecurityPolicyClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		CE6DADFA1C591E6A003F6A88 /* ContentSecurityPolicyResponseHeaders.h in Headers */ = {isa = PBXBuildFile; fileRef = CE6DADF81C591E6A003F6A88 /* ContentSecurityPolicyResponseHeaders.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -14149,6 +14150,8 @@
 		CE212154240DBD30006ED443 /* TextPlaceholderElement.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TextPlaceholderElement.cpp; sourceTree = "<group>"; };
 		CE2849861CA360DF00B4A57F /* ContentSecurityPolicyDirectiveNames.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ContentSecurityPolicyDirectiveNames.h; path = csp/ContentSecurityPolicyDirectiveNames.h; sourceTree = "<group>"; };
 		CE2849881CA3614600B4A57F /* ContentSecurityPolicyDirectiveNames.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ContentSecurityPolicyDirectiveNames.cpp; path = csp/ContentSecurityPolicyDirectiveNames.cpp; sourceTree = "<group>"; };
+		CE45946424121A050078019F /* AlternativeTextContextController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AlternativeTextContextController.h; sourceTree = "<group>"; };
+		CE45946524121A050078019F /* AlternativeTextContextController.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AlternativeTextContextController.mm; sourceTree = "<group>"; };
 		CE5169E521F1B84700EA4F78 /* ColorIOS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorIOS.h; sourceTree = "<group>"; };
 		CE5169E621F1B84700EA4F78 /* ColorIOS.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ColorIOS.mm; sourceTree = "<group>"; };
 		CE5CB1B314EDAB6F00BB2795 /* EventSender.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventSender.h; sourceTree = "<group>"; };
@@ -21291,6 +21294,10 @@
 		7C3E510718DF8F1200C112F7 /* cocoa */ = {
 			isa = PBXGroup;
 			children = (
+				CE45946424121A050078019F /* AlternativeTextContextController.h */,
+				CE45946524121A050078019F /* AlternativeTextContextController.mm */,
+				CE7B2DAF1586ABAD0098B3FA /* AlternativeTextUIController.h */,
+				CE7B2DB01586ABAD0098B3FA /* AlternativeTextUIController.mm */,
 				5CCC270722D53B6900964FA0 /* AutofillElements.cpp */,
 				5CCC270622D53B6800964FA0 /* AutofillElements.h */,
 				C5227DEF1C3C6DD700F5ED54 /* DataDetection.h */,
@@ -27327,8 +27334,6 @@
 		ED501DC90B249F3900AE18D9 /* mac */ = {
 			isa = PBXGroup;
 			children = (
-				CE7B2DAF1586ABAD0098B3FA /* AlternativeTextUIController.h */,
-				CE7B2DB01586ABAD0098B3FA /* AlternativeTextUIController.mm */,
 				937FF3D41A1012D6008EBA31 /* DictionaryLookup.h */,
 				442956CA218A6D300080DB54 /* DictionaryLookupLegacy.mm */,
 				ED501DC50B249F2900AE18D9 /* EditorMac.mm */,
@@ -29025,6 +29030,7 @@
 				83BB5C881D5D6F45005A71F4 /* AllDescendantsCollection.h in Headers */,
 				7299BC6723D6A53200CC6883 /* AlphaPremultiplication.h in Headers */,
 				CEDA12D7152CA1CB00D9E08D /* AlternativeTextClient.h in Headers */,
+				CE45946F24123C960078019F /* AlternativeTextContextController.h in Headers */,
 				CE08C3D2152B599A0021B8C2 /* AlternativeTextController.h in Headers */,
 				CE7B2DB31586ABAD0098B3FA /* AlternativeTextUIController.h in Headers */,
 				FD31603E12B0267600C1A359 /* AnalyserNode.h in Headers */,
@@ -31549,6 +31555,7 @@
 				A17D275E1EAC579800BF01E7 /* MediaSelectionOption.h in Headers */,
 				C9027F421B1D0AD200BFBFEF /* MediaSession.h in Headers */,
 				C9F87CFE1B28F40E00979B83 /* MediaSessionEvents.h in Headers */,
+				414460A22412994500814BE7 /* MediaSessionIdentifier.h in Headers */,
 				C96F5EC81B5872260091EA9D /* MediaSessionInterruptionProvider.h in Headers */,
 				C96F5EC51B5872260091EA9D /* MediaSessionInterruptionProviderMac.h in Headers */,
 				C90F65561B2253BE002163A1 /* MediaSessionManager.h in Headers */,
@@ -32803,7 +32810,6 @@
 				CE212158240DBEB9006ED443 /* TextPlaceholderElement.h in Headers */,
 				93F198F608245E59001E9ABC /* TextResourceDecoder.h in Headers */,
 				A824B4650E2EF2EA0081A7B7 /* TextRun.h in Headers */,
-				414460A22412994500814BE7 /* MediaSessionIdentifier.h in Headers */,
 				448B1B7A0F3A2F9B0047A9E2 /* TextSizeAdjustment.h in Headers */,
 				9759E94014EF1CF80026A2DD /* TextTrack.h in Headers */,
 				9759E94314EF1CF80026A2DD /* TextTrackCue.h in Headers */,

Copied: trunk/Source/WebCore/editing/cocoa/AlternativeTextContextController.h (from rev 258084, trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h) (0 => 258085)


--- trunk/Source/WebCore/editing/cocoa/AlternativeTextContextController.h	                        (rev 0)
+++ trunk/Source/WebCore/editing/cocoa/AlternativeTextContextController.h	2020-03-08 00:26:17 UTC (rev 258085)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2012, 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(DICTATION_ALTERNATIVES)
+
+#import <wtf/Forward.h>
+#import <wtf/HashMap.h>
+
+OBJC_CLASS NSTextAlternatives;
+
+namespace WebCore {
+
+class AlternativeTextContextController {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    WEBCORE_EXPORT AlternativeTextContextController();
+    WEBCORE_EXPORT ~AlternativeTextContextController();
+
+    uint64_t addAlternatives(const RetainPtr<NSTextAlternatives>&);
+
+    void clear();
+
+    NSTextAlternatives *alternativesForContext(uint64_t context);
+
+    void removeAlternativesForContext(uint64_t context);
+
+    static constexpr uint64_t invalidContext = 0;
+
+private:
+    HashMap<uint64_t, RetainPtr<NSTextAlternatives>> m_alternativesObjectMap;
+};
+
+} // namespace WebCore
+
+#endif // USE(DICTATION_ALTERNATIVES)

Added: trunk/Source/WebCore/editing/cocoa/AlternativeTextContextController.mm (0 => 258085)


--- trunk/Source/WebCore/editing/cocoa/AlternativeTextContextController.mm	                        (rev 0)
+++ trunk/Source/WebCore/editing/cocoa/AlternativeTextContextController.mm	2020-03-08 00:26:17 UTC (rev 258085)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2012, 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "AlternativeTextContextController.h"
+
+#if USE(DICTATION_ALTERNATIVES)
+
+#import <wtf/RetainPtr.h>
+
+#if USE(APPKit)
+#import <AppKit/NSTextAlternatives.h>
+#elif PLATFORM(IOS_FAMILY)
+#import <pal/spi/ios/UIKitSPI.h>
+#endif
+
+namespace WebCore {
+
+AlternativeTextContextController::AlternativeTextContextController() = default;
+
+AlternativeTextContextController::~AlternativeTextContextController() = default;
+
+uint64_t AlternativeTextContextController::addAlternatives(const RetainPtr<NSTextAlternatives>& alternatives)
+{
+    uint64_t context = reinterpret_cast<uint64_t>(alternatives.get());
+    if (!context)
+        return invalidContext;
+    if (alternativesForContext(context))
+        return context;
+    auto result = m_alternativesObjectMap.add(context, alternatives);
+    return result.isNewEntry ? context : invalidContext;
+}
+
+NSTextAlternatives *AlternativeTextContextController::alternativesForContext(uint64_t context)
+{
+    return m_alternativesObjectMap.get(context).get();
+}
+
+void AlternativeTextContextController::removeAlternativesForContext(uint64_t context)
+{
+    m_alternativesObjectMap.remove(context);
+}
+
+void AlternativeTextContextController::clear()
+{
+    m_alternativesObjectMap.clear();
+}
+
+} // namespace WebCore
+
+#endif // USE(DICTATION_ALTERNATIVES)

Copied: trunk/Source/WebCore/editing/cocoa/AlternativeTextUIController.h (from rev 258084, trunk/Source/WebCore/editing/mac/AlternativeTextUIController.h) (0 => 258085)


--- trunk/Source/WebCore/editing/cocoa/AlternativeTextUIController.h	                        (rev 0)
+++ trunk/Source/WebCore/editing/cocoa/AlternativeTextUIController.h	2020-03-08 00:26:17 UTC (rev 258085)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(DICTATION_ALTERNATIVES)
+
+#import "AlternativeTextContextController.h"
+#import <wtf/RetainPtr.h>
+
+OBJC_CLASS NSTextAlternatives;
+OBJC_CLASS NSView;
+
+namespace WebCore {
+
+class FloatRect;
+
+class AlternativeTextUIController {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    AlternativeTextUIController() = default;
+
+    WEBCORE_EXPORT uint64_t addAlternatives(const RetainPtr<NSTextAlternatives>&); // Returns a context ID.
+
+    WEBCORE_EXPORT void clear();
+
+    using AcceptanceHandler = void (^)(NSString *);
+    WEBCORE_EXPORT void showAlternatives(NSView *, const FloatRect& boundingBoxOfPrimaryString, uint64_t context, AcceptanceHandler);
+
+    void WEBCORE_EXPORT removeAlternatives(uint64_t context);
+
+    WEBCORE_EXPORT Vector<String> alternativesForContext(uint64_t context);
+
+private:
+#if USE(APPKIT)
+    void handleAcceptedAlternative(NSString *, uint64_t context, NSTextAlternatives *);
+    void dismissAlternatives();
+
+    RetainPtr<NSView> m_view;
+#endif
+    AlternativeTextContextController m_contextController;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(DICTATION_ALTERNATIVES)

Copied: trunk/Source/WebCore/editing/cocoa/AlternativeTextUIController.mm (from rev 258084, trunk/Source/WebCore/editing/mac/AlternativeTextUIController.mm) (0 => 258085)


--- trunk/Source/WebCore/editing/cocoa/AlternativeTextUIController.mm	                        (rev 0)
+++ trunk/Source/WebCore/editing/cocoa/AlternativeTextUIController.mm	2020-03-08 00:26:17 UTC (rev 258085)
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2012, 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "AlternativeTextUIController.h"
+
+#if USE(DICTATION_ALTERNATIVES)
+
+#import <WebCore/FloatRect.h>
+
+#if USE(APPKIT)
+#import <AppKit/NSSpellChecker.h>
+#import <AppKit/NSTextAlternatives.h>
+#import <AppKit/NSView.h>
+#elif PLATFORM(IOS_FAMILY)
+#import <pal/spi/ios/UIKitSPI.h>
+#endif
+
+namespace WebCore {
+
+uint64_t AlternativeTextUIController::addAlternatives(const RetainPtr<NSTextAlternatives>& alternatives)
+{
+    return m_contextController.addAlternatives(alternatives);
+}
+
+Vector<String> AlternativeTextUIController::alternativesForContext(uint64_t context)
+{
+    NSTextAlternatives *textAlternatives = m_contextController.alternativesForContext(context);
+    Vector<String> alternativeStrings;
+    alternativeStrings.reserveInitialCapacity(textAlternatives.alternativeStrings.count);
+    for (NSString *string in textAlternatives.alternativeStrings)
+        alternativeStrings.uncheckedAppend(string);
+    return alternativeStrings;
+}
+
+void AlternativeTextUIController::clear()
+{
+    return m_contextController.clear();
+}
+
+void AlternativeTextUIController::showAlternatives(NSView *view, const FloatRect& boundingBoxOfPrimaryString, uint64_t context, AcceptanceHandler acceptanceHandler)
+{
+#if USE(APPKIT)
+    dismissAlternatives();
+    if (!view)
+        return;
+
+    m_view = view;
+
+    NSTextAlternatives *alternatives = m_contextController.alternativesForContext(context);
+    if (!alternatives)
+        return;
+
+    [[NSSpellChecker sharedSpellChecker] showCorrectionIndicatorOfType:NSCorrectionIndicatorTypeGuesses primaryString:alternatives.primaryString alternativeStrings:alternatives.alternativeStrings forStringInRect:boundingBoxOfPrimaryString view:m_view.get() completionHandler:^(NSString *acceptedString) {
+        if (acceptedString) {
+            handleAcceptedAlternative(acceptedString, context, alternatives);
+            acceptanceHandler(acceptedString);
+        }
+    }];
+#else
+    UNUSED_PARAM(view);
+    UNUSED_PARAM(boundingBoxOfPrimaryString);
+    UNUSED_PARAM(context);
+    UNUSED_PARAM(acceptanceHandler);
+#endif
+}
+
+#if USE(APPKIT)
+
+void AlternativeTextUIController::handleAcceptedAlternative(NSString *acceptedAlternative, uint64_t context, NSTextAlternatives *alternatives)
+{
+    [alternatives noteSelectedAlternativeString:acceptedAlternative];
+    m_contextController.removeAlternativesForContext(context);
+    m_view = nullptr;
+}
+
+void AlternativeTextUIController::dismissAlternatives()
+{
+    if (m_view)
+        [[NSSpellChecker sharedSpellChecker] dismissCorrectionIndicatorForView:m_view.get()];
+}
+
+#endif
+
+void AlternativeTextUIController::removeAlternatives(uint64_t context)
+{
+    m_contextController.removeAlternativesForContext(context);
+}
+
+} // namespace WebCore
+
+#endif // USE(DICTATION_ALTERNATIVES)

Deleted: trunk/Source/WebCore/editing/mac/AlternativeTextUIController.h (258084 => 258085)


--- trunk/Source/WebCore/editing/mac/AlternativeTextUIController.h	2020-03-08 00:14:50 UTC (rev 258084)
+++ trunk/Source/WebCore/editing/mac/AlternativeTextUIController.h	2020-03-08 00:26:17 UTC (rev 258085)
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#include "AlternativeTextClient.h"
-#include "FloatRect.h"
-#include <wtf/HashMap.h>
-#include <wtf/RetainPtr.h>
-
-#if USE(DICTATION_ALTERNATIVES)
-OBJC_CLASS NSTextAlternatives;
-OBJC_CLASS NSView;
-
-namespace WebCore {
-
-class AlternativeTextUIController {
-    WTF_MAKE_FAST_ALLOCATED;
-public:
-    AlternativeTextUIController() { }
-    // Returns a context ID.
-    WEBCORE_EXPORT uint64_t addAlternatives(const RetainPtr<NSTextAlternatives>&);
-    WEBCORE_EXPORT void clear();
-    WEBCORE_EXPORT void showAlternatives(NSView*, const FloatRect& boundingBoxOfPrimaryString, uint64_t context, void(^acceptanceHandler)(NSString*));
-    void WEBCORE_EXPORT removeAlternatives(uint64_t context);
-    WEBCORE_EXPORT Vector<String> alternativesForContext(uint64_t context);
-
-private:
-    void handleAcceptedAlternative(NSString* acceptedAlternative, uint64_t context, NSTextAlternatives*);
-
-    void dismissAlternatives();
-
-    class AlernativeTextContextController {
-        WTF_MAKE_FAST_ALLOCATED;
-    public:
-        AlernativeTextContextController() { }
-        uint64_t addAlternatives(const RetainPtr<NSTextAlternatives>&);
-        void clear();
-        NSTextAlternatives* alternativesForContext(uint64_t context);
-        void removeAlternativesForContext(uint64_t context);
-        static const uint64_t invalidContext = 0;
-    private:
-        typedef HashMap<uint64_t, RetainPtr<NSTextAlternatives>> HashMapType;
-        HashMapType m_alternativesObjectMap;
-    };
-
-    AlernativeTextContextController m_contextController;
-    RetainPtr<NSView> m_view;
-};
-
-} // namespace WebCore
-
-#endif // ENABLE(DICTATION_ALTERNATIVES)

Deleted: trunk/Source/WebCore/editing/mac/AlternativeTextUIController.mm (258084 => 258085)


--- trunk/Source/WebCore/editing/mac/AlternativeTextUIController.mm	2020-03-08 00:14:50 UTC (rev 258084)
+++ trunk/Source/WebCore/editing/mac/AlternativeTextUIController.mm	2020-03-08 00:26:17 UTC (rev 258085)
@@ -1,120 +0,0 @@
-/*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import "config.h"
-#import "AlternativeTextUIController.h"
-
-#if USE(DICTATION_ALTERNATIVES)
-#import <AppKit/NSSpellChecker.h>
-#import <AppKit/NSTextAlternatives.h>
-#import <AppKit/NSView.h>
-
-namespace WebCore {
-
-uint64_t AlternativeTextUIController::AlernativeTextContextController::addAlternatives(const RetainPtr<NSTextAlternatives>& alternatives)
-{
-    uint64_t context = reinterpret_cast<uint64_t>(alternatives.get());
-    if (!context)
-        return invalidContext;
-    if (alternativesForContext(context))
-        return context;
-
-    HashMapType::AddResult result = m_alternativesObjectMap.add(context, alternatives);
-    return result.isNewEntry ? context : invalidContext;
-}
-
-NSTextAlternatives* AlternativeTextUIController::AlernativeTextContextController::alternativesForContext(uint64_t context)
-{
-    return m_alternativesObjectMap.get(context).get();
-}
-
-void AlternativeTextUIController::AlernativeTextContextController::removeAlternativesForContext(uint64_t context)
-{
-    m_alternativesObjectMap.remove(context);
-}
-
-void AlternativeTextUIController::AlernativeTextContextController::clear()
-{
-    m_alternativesObjectMap.clear();
-}
-
-uint64_t AlternativeTextUIController::addAlternatives(const RetainPtr<NSTextAlternatives>& alternatives)
-{
-    return m_contextController.addAlternatives(alternatives);
-}
-
-Vector<String> AlternativeTextUIController::alternativesForContext(uint64_t context)
-{
-    NSTextAlternatives* textAlternatives = m_contextController.alternativesForContext(context);
-    Vector<String> alternativeStrings;
-    for (NSString* string in textAlternatives.alternativeStrings)
-        alternativeStrings.append(string);
-    return alternativeStrings;
-}
-
-void AlternativeTextUIController::clear()
-{
-    return m_contextController.clear();
-}
-
-void AlternativeTextUIController::showAlternatives(NSView* view, const FloatRect& boundingBoxOfPrimaryString, uint64_t context, void(^acceptanceHandler)(NSString*))
-{
-    dismissAlternatives();
-    if (!view)
-        return;
-
-    m_view = view;
-    NSTextAlternatives* alternatives = m_contextController.alternativesForContext(context);
-    if (!alternatives)
-        return;
-
-    [[NSSpellChecker sharedSpellChecker] showCorrectionIndicatorOfType:NSCorrectionIndicatorTypeGuesses primaryString:alternatives.primaryString alternativeStrings:alternatives.alternativeStrings forStringInRect:boundingBoxOfPrimaryString view:m_view.get() completionHandler:^(NSString* acceptedString) {
-        if (acceptedString) {
-            handleAcceptedAlternative(acceptedString, context, alternatives);
-            acceptanceHandler(acceptedString);
-        }
-    }];
-}
-
-void AlternativeTextUIController::handleAcceptedAlternative(NSString* acceptedAlternative, uint64_t context, NSTextAlternatives* alternatives)
-{
-    [alternatives noteSelectedAlternativeString:acceptedAlternative];
-    m_contextController.removeAlternativesForContext(context);
-    m_view.clear();
-}
-
-void AlternativeTextUIController::dismissAlternatives()
-{
-    if (!m_view)
-        return;
-    [[NSSpellChecker sharedSpellChecker] dismissCorrectionIndicatorForView:m_view.get()];
-}
-
-void AlternativeTextUIController::removeAlternatives(uint64_t context)
-{
-    m_contextController.removeAlternativesForContext(context);
-}
-}
-#endif // USE(DICTATION_ALTERNATIVES)

Modified: trunk/Source/WebKit/ChangeLog (258084 => 258085)


--- trunk/Source/WebKit/ChangeLog	2020-03-08 00:14:50 UTC (rev 258084)
+++ trunk/Source/WebKit/ChangeLog	2020-03-08 00:26:17 UTC (rev 258085)
@@ -1,3 +1,45 @@
+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 Wenson Hsieh.
+
+        Part 1
+
+        Move some of the PageClientMac dictation alternatives code to PageClientImplCocoa so that it
+        can be shared with iOS.
+
+        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.
+
+        * UIProcess/Cocoa/PageClientImplCocoa.h:
+        (WebKit::PageClientImplCocoa::PageClientImplCocoa): Deleted; moved to be out-of-line to avoid
+        needing to #include AlternativeTextUIController.h from this file. Declare out-of-line destructor
+        for the same reason.
+        * UIProcess/Cocoa/PageClientImplCocoa.mm:
+        (WebKit::PageClientImplCocoa::PageClientImplCocoa): Moved from PageClientImplCocoa.h.
+        (WebKit::PageClientImplCocoa::pageClosed):
+        (WebKit::PageClientImplCocoa::addDictationAlternatives): Moved from PageClientImplMac.mm.
+        (WebKit::PageClientImplCocoa::removeDictationAlternatives): Ditto.
+        (WebKit::PageClientImplCocoa::dictationAlternatives): Ditto.
+        * UIProcess/PageClient.h:
+        * UIProcess/ios/PageClientImplIOS.h:
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::showDictationAlternativeUI): Added; stub function.
+        (WebKit::PageClientImpl::pageClosed): Deleted; now we will use the base class implementation.
+        * UIProcess/mac/PageClientImplMac.h:
+        * UIProcess/mac/PageClientImplMac.mm:
+        (WebKit::PageClientImpl::PageClientImpl): Moved AlternativeTextUIController logic from here to PageClientImplCocoa::PageClientImplCocoa().
+        (WebKit::PageClientImpl::pageClosed): Moved AlternativeTextUIController logic from here to PageClientImplCocoa::pageClosed()
+        so it can be shared and modified this function to call the base class implementation.
+        (WebKit::PageClientImpl::~PageClientImpl): Deleted; moved to PageClientImplCocoa.mm.
+        (WebKit::PageClientImpl::addDictationAlternatives): Deleted; moved to PageClientImplCocoa.mm.
+        (WebKit::PageClientImpl::removeDictationAlternatives): Deleted; moved to PageClientImplCocoa.mm.
+        (WebKit::PageClientImpl::dictationAlternatives): Deleted; moved to PageClientImplCocoa.mm.
+
 2020-03-07  Eric Carlson  <[email protected]>
 
         Implement setWirelessPlaybackTarget, performTaskAtMediaTime, and wouldTaintOrigin in GPUProcess

Modified: trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h (258084 => 258085)


--- trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h	2020-03-08 00:14:50 UTC (rev 258084)
+++ trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h	2020-03-08 00:26:17 UTC (rev 258085)
@@ -26,8 +26,10 @@
 #pragma once
 
 #include "PageClient.h"
+#include <wtf/Forward.h>
 #include <wtf/WeakObjCPtr.h>
 
+@class NSTextAlternatives;
 @class WKWebView;
 
 namespace API {
@@ -34,12 +36,19 @@
 class Attachment;
 }
 
+namespace WebCore {
+class AlternativeTextUIController;
+}
+
 namespace WebKit {
 
 class PageClientImplCocoa : public PageClient {
 public:
-    PageClientImplCocoa(WKWebView *webView)
-        : m_webView(webView) { }
+    PageClientImplCocoa(WKWebView *);
+    virtual ~PageClientImplCocoa();
+
+    void pageClosed() override;
+
     void isPlayingAudioWillChange() final;
     void isPlayingAudioDidChange() final;
 
@@ -53,8 +62,17 @@
     NSSet *serializableFileWrapperClasses() const final;
 #endif
 
+#if USE(DICTATION_ALTERNATIVES)
+    uint64_t addDictationAlternatives(const RetainPtr<NSTextAlternatives>&) final;
+    void removeDictationAlternatives(uint64_t dictationContext) final;
+    Vector<String> dictationAlternatives(uint64_t dictationContext) final;
+#endif
+
 protected:
     WeakObjCPtr<WKWebView> m_webView;
+#if USE(DICTATION_ALTERNATIVES)
+    std::unique_ptr<WebCore::AlternativeTextUIController> m_alternativeTextUIController;
+#endif
 };
 
 }

Modified: trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm (258084 => 258085)


--- trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm	2020-03-08 00:14:50 UTC (rev 258084)
+++ trunk/Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm	2020-03-08 00:26:17 UTC (rev 258085)
@@ -29,9 +29,24 @@
 #import "WKWebViewConfigurationPrivate.h"
 #import "WKWebViewInternal.h"
 #import "WKWebViewPrivateForTesting.h"
+#import <wtf/Vector.h>
 
+#if USE(DICTATION_ALTERNATIVES)
+#import <WebCore/AlternativeTextUIController.h>
+#endif
+
 namespace WebKit {
 
+PageClientImplCocoa::PageClientImplCocoa(WKWebView *webView)
+    : m_webView { webView }
+#if USE(DICTATION_ALTERNATIVES)
+    , m_alternativeTextUIController { makeUnique<AlternativeTextUIController>() }
+#endif
+{
+}
+
+PageClientImplCocoa::~PageClientImplCocoa() = default;
+
 void PageClientImplCocoa::isPlayingAudioWillChange()
 {
     [m_webView willChangeValueForKey:NSStringFromSelector(@selector(_isPlayingAudio))];
@@ -80,5 +95,32 @@
 }
 
 #endif
+
+void PageClientImplCocoa::pageClosed()
+{
+#if USE(DICTATION_ALTERNATIVES)
+    m_alternativeTextUIController->clear();
+#endif
+}
+
+#if USE(DICTATION_ALTERNATIVES)
+
+uint64_t PageClientImplCocoa::addDictationAlternatives(const RetainPtr<NSTextAlternatives>& alternatives)
+{
+    return m_alternativeTextUIController->addAlternatives(alternatives);
+}
+
+void PageClientImplCocoa::removeDictationAlternatives(uint64_t dictationContext)
+{
+    m_alternativeTextUIController->removeAlternatives(dictationContext);
+}
+
+Vector<String> PageClientImplCocoa::dictationAlternatives(uint64_t dictationContext)
+{
+    return m_alternativeTextUIController->alternativesForContext(dictationContext);
+}
+
+#endif
+
     
 }

Modified: trunk/Source/WebKit/UIProcess/PageClient.h (258084 => 258085)


--- trunk/Source/WebKit/UIProcess/PageClient.h	2020-03-08 00:14:50 UTC (rev 258084)
+++ trunk/Source/WebKit/UIProcess/PageClient.h	2020-03-08 00:26:17 UTC (rev 258085)
@@ -353,6 +353,13 @@
 
     virtual void takeFocus(WebCore::FocusDirection) { }
 
+#if USE(DICTATION_ALTERNATIVES)
+    virtual uint64_t addDictationAlternatives(const RetainPtr<NSTextAlternatives>&) = 0;
+    virtual void removeDictationAlternatives(uint64_t dictationContext) = 0;
+    virtual void showDictationAlternativeUI(const WebCore::FloatRect& boundingBoxOfDictatedText, uint64_t dictationContext) = 0;
+    virtual Vector<String> dictationAlternatives(uint64_t dictationContext) = 0;
+#endif
+
 #if PLATFORM(MAC)
     virtual void pluginFocusOrWindowFocusChanged(uint64_t pluginComplexTextInputIdentifier, bool pluginHasFocusAndWindowHasFocus) = 0;
     virtual void setPluginComplexTextInputState(uint64_t pluginComplexTextInputIdentifier, PluginComplexTextInputState) = 0;
@@ -376,18 +383,12 @@
     virtual NSView *inspectorAttachmentView() = 0;
     virtual _WKRemoteObjectRegistry *remoteObjectRegistry() = 0;
 
-#if USE(APPKIT)
     virtual void intrinsicContentSizeDidChange(const WebCore::IntSize& intrinsicContentSize) = 0;
-#if USE(DICTATION_ALTERNATIVES)
-    virtual uint64_t addDictationAlternatives(const RetainPtr<NSTextAlternatives>&) = 0;
-    virtual void removeDictationAlternatives(uint64_t dictationContext) = 0;
-    virtual void showDictationAlternativeUI(const WebCore::FloatRect& boundingBoxOfDictatedText, uint64_t dictationContext) = 0;
-    virtual Vector<String> dictationAlternatives(uint64_t dictationContext) = 0;
-#endif // USE(DICTATION_ALTERNATIVES)
+
 #if USE(INSERTION_UNDO_GROUPING)
     virtual void registerInsertionUndoGrouping() = 0;
-#endif // USE(INSERTION_UNDO_GROUPING)
-#endif // USE(APPKIT)
+#endif
+
     virtual void setEditableElementIsFocused(bool) = 0;
 #endif // PLATFORM(MAC)
 

Modified: trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h (258084 => 258085)


--- trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h	2020-03-08 00:14:50 UTC (rev 258084)
+++ trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h	2020-03-08 00:26:17 UTC (rev 258085)
@@ -32,6 +32,7 @@
 #import <wtf/RetainPtr.h>
 #import <wtf/WeakObjCPtr.h>
 
+OBJC_CLASS NSTextAlternatives;
 OBJC_CLASS WKContentView;
 OBJC_CLASS WKEditorUndoTarget;
 
@@ -77,7 +78,6 @@
 #if ENABLE(GPU_PROCESS)
     void gpuProcessCrashed() override;
 #endif
-    void pageClosed() override;
     void preferencesDidChange() override;
     void toolTipChanged(const String&, const String&) override;
     void decidePolicyForGeolocationPermissionRequest(WebFrameProxy&, const FrameInfoData&, Function<void(bool)>&) override;
@@ -262,6 +262,10 @@
     WTF::Optional<unsigned> activeTouchIdentifierForGestureRecognizer(UIGestureRecognizer*) override;
 #endif
 
+#if USE(DICTATION_ALTERNATIVES)
+    void showDictationAlternativeUI(const WebCore::FloatRect&, uint64_t dictationContext) override;
+#endif
+
     WeakObjCPtr<WKContentView> m_contentView;
     RetainPtr<WKEditorUndoTarget> m_undoTarget;
 };

Modified: trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm (258084 => 258085)


--- trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm	2020-03-08 00:14:50 UTC (rev 258084)
+++ trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm	2020-03-08 00:26:17 UTC (rev 258085)
@@ -233,11 +233,6 @@
 }
 #endif
 
-void PageClientImpl::pageClosed()
-{
-    notImplemented();
-}
-
 void PageClientImpl::preferencesDidChange()
 {
     notImplemented();
@@ -963,6 +958,15 @@
     [m_contentView _handleAutocorrectionContext:context];
 }
 
+#if USE(DICTATION_ALTERNATIVES)
+
+void PageClientImpl::showDictationAlternativeUI(const WebCore::FloatRect&, uint64_t)
+{
+    notImplemented();
+}
+
+#endif
+
 } // namespace WebKit
 
 #endif // PLATFORM(IOS_FAMILY)

Modified: trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h (258084 => 258085)


--- trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h	2020-03-08 00:14:50 UTC (rev 258084)
+++ trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h	2020-03-08 00:26:17 UTC (rev 258085)
@@ -32,7 +32,7 @@
 #include "WebFullScreenManagerProxy.h"
 #include <WebCore/DOMPasteAccess.h>
 #include <wtf/CompletionHandler.h>
-#include <wtf/RetainPtr.h>
+#include <wtf/Forward.h>
 
 @class WKEditorUndoTarget;
 @class WKView;
@@ -180,11 +180,9 @@
     void intrinsicContentSizeDidChange(const WebCore::IntSize& intrinsicContentSize) override;
 
 #if USE(DICTATION_ALTERNATIVES)
-    uint64_t addDictationAlternatives(const RetainPtr<NSTextAlternatives>&) override;
-    void removeDictationAlternatives(uint64_t dictationContext) override;
     void showDictationAlternativeUI(const WebCore::FloatRect& boundingBoxOfDictatedText, uint64_t dictationContext) override;
-    Vector<String> dictationAlternatives(uint64_t dictationContext) override;
 #endif
+
     void setEditableElementIsFocused(bool) override;
 
 #if USE(INSERTION_UNDO_GROUPING)
@@ -267,9 +265,6 @@
 #if USE(AUTOCORRECTION_PANEL)
     CorrectionPanel m_correctionPanel;
 #endif
-#if USE(DICTATION_ALTERNATIVES)
-    std::unique_ptr<WebCore::AlternativeTextUIController> m_alternativeTextUIController;
-#endif
 
     bool m_shouldSuppressFirstResponderChanges { false };
 };

Modified: trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm (258084 => 258085)


--- trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm	2020-03-08 00:14:50 UTC (rev 258084)
+++ trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm	2020-03-08 00:26:17 UTC (rev 258085)
@@ -79,13 +79,10 @@
 #import <WebCore/ValidationBubble.h>
 #import <WebCore/WebCoreCALayerExtras.h>
 #import <wtf/ProcessPrivilege.h>
+#import <wtf/RetainPtr.h>
 #import <wtf/text/CString.h>
 #import <wtf/text/WTFString.h>
 
-#if USE(DICTATION_ALTERNATIVES)
-#import <AppKit/NSTextAlternatives.h>
-#endif
-
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
 #include <WebCore/WebMediaSessionManager.h>
 #endif
@@ -103,20 +100,16 @@
 #endif
 
 namespace WebKit {
+
 using namespace WebCore;
 
-PageClientImpl::PageClientImpl(NSView* view, WKWebView *webView)
+PageClientImpl::PageClientImpl(NSView *view, WKWebView *webView)
     : PageClientImplCocoa(webView)
     , m_view(view)
-#if USE(DICTATION_ALTERNATIVES)
-    , m_alternativeTextUIController(makeUnique<AlternativeTextUIController>())
-#endif
 {
 }
 
-PageClientImpl::~PageClientImpl()
-{
-}
+PageClientImpl::~PageClientImpl() = default;
 
 void PageClientImpl::setImpl(WebViewImpl& impl)
 {
@@ -266,9 +259,7 @@
 void PageClientImpl::pageClosed()
 {
     m_impl->pageClosed();
-#if USE(DICTATION_ALTERNATIVES)
-    m_alternativeTextUIController->clear();
-#endif
+    PageClientImplCocoa::pageClosed();
 }
 
 void PageClientImpl::didRelaunchProcess()
@@ -684,16 +675,7 @@
 }
 
 #if USE(DICTATION_ALTERNATIVES)
-uint64_t PageClientImpl::addDictationAlternatives(const RetainPtr<NSTextAlternatives>& alternatives)
-{
-    return m_alternativeTextUIController->addAlternatives(alternatives);
-}
 
-void PageClientImpl::removeDictationAlternatives(uint64_t dictationContext)
-{
-    m_alternativeTextUIController->removeAlternatives(dictationContext);
-}
-
 void PageClientImpl::showDictationAlternativeUI(const WebCore::FloatRect& boundingBoxOfDictatedText, uint64_t dictationContext)
 {
     if (!isViewVisible() || !isViewInWindow())
@@ -703,10 +685,6 @@
     });
 }
 
-Vector<String> PageClientImpl::dictationAlternatives(uint64_t dictationContext)
-{
-    return m_alternativeTextUIController->alternativesForContext(dictationContext);
-}
 #endif
 
 void PageClientImpl::setEditableElementIsFocused(bool editableElementIsFocused)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to