Diff
Modified: trunk/Source/WebCore/ChangeLog (258085 => 258086)
--- trunk/Source/WebCore/ChangeLog 2020-03-08 00:26:17 UTC (rev 258085)
+++ trunk/Source/WebCore/ChangeLog 2020-03-08 00:27:55 UTC (rev 258086)
@@ -6,6 +6,27 @@
Reviewed by Wenson Hsieh.
+ Part 2
+
+ Include UIKitSPI.h in TextAlternativeWithRange.mm to get the definition of NSTextAlternatives
+ when building for iOS. Also while I am here, fix up some code style issues and use uniform
+ initializer syntax.
+
+ 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.
+
+ * editing/mac/TextAlternativeWithRange.mm:
+ (WebCore::TextAlternativeWithRange::TextAlternativeWithRange):
+
+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}
Modified: trunk/Source/WebCore/PAL/pal/spi/cocoa/NSAttributedStringSPI.h (258085 => 258086)
--- trunk/Source/WebCore/PAL/pal/spi/cocoa/NSAttributedStringSPI.h 2020-03-08 00:26:17 UTC (rev 258085)
+++ trunk/Source/WebCore/PAL/pal/spi/cocoa/NSAttributedStringSPI.h 2020-03-08 00:27:55 UTC (rev 258086)
@@ -95,6 +95,8 @@
#define NSBackgroundColorDocumentAttribute getNSBackgroundColorDocumentAttribute()
SOFT_LINK_CONSTANT(UIFoundation, NSMarkedClauseSegmentAttributeName, NSString *)
#define NSMarkedClauseSegmentAttributeName getNSMarkedClauseSegmentAttributeName()
+SOFT_LINK_CONSTANT(UIFoundation, NSTextAlternativesAttributeName, NSString *)
+#define NSTextAlternativesAttributeName getNSTextAlternativesAttributeName()
// We don't softlink NSSuperscriptAttributeName because UIFoundation stopped exporting it.
// This attribute is being deprecated at the API level, but internally UIFoundation
Modified: trunk/Source/WebCore/editing/mac/TextAlternativeWithRange.mm (258085 => 258086)
--- trunk/Source/WebCore/editing/mac/TextAlternativeWithRange.mm 2020-03-08 00:26:17 UTC (rev 258085)
+++ trunk/Source/WebCore/editing/mac/TextAlternativeWithRange.mm 2020-03-08 00:27:55 UTC (rev 258086)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * 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
@@ -26,13 +26,19 @@
#import "TextAlternativeWithRange.h"
#if USE(DICTATION_ALTERNATIVES)
+
+#if USE(APPKIT)
#import <AppKit/NSTextAlternatives.h>
+#elif PLATFORM(IOS_FAMILY)
+#import <pal/spi/cocoa/NSAttributedStringSPI.h>
+#import <pal/spi/ios/UIKitSPI.h>
+#endif
namespace WebCore {
-TextAlternativeWithRange::TextAlternativeWithRange(NSTextAlternatives* anAlternatives, NSRange aRange)
-: range(aRange)
-, alternatives(anAlternatives)
+TextAlternativeWithRange::TextAlternativeWithRange(NSTextAlternatives *anAlternatives, NSRange aRange)
+ : range { aRange }
+ , alternatives { anAlternatives }
{
}
@@ -49,5 +55,7 @@
effectiveRange.location = NSMaxRange(effectiveRange);
} while (effectiveRange.location < length);
}
-}
-#endif
+
+} // namespace WebCore
+
+#endif // USE(DICTATION_ALTERNATIVES)
Modified: trunk/Source/WebKit/ChangeLog (258085 => 258086)
--- trunk/Source/WebKit/ChangeLog 2020-03-08 00:26:17 UTC (rev 258085)
+++ trunk/Source/WebKit/ChangeLog 2020-03-08 00:27:55 UTC (rev 258086)
@@ -6,6 +6,37 @@
Reviewed by Wenson Hsieh.
+ Part 2
+
+ Move insertDictatedTextAsync() from the Mac-specific implementation files to Cocoa-specific
+ implementation files as it can be shared by both Mac and iOS. I did very minor C++ modernization:
+ just more uses of auto and uniform initializer syntax.
+
+ 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/WebPageProxyCocoa.mm:
+ (WebKit::WebPageProxy::insertDictatedTextAsync):
+ * UIProcess/WebPageProxy.cpp:
+ * UIProcess/WebPageProxy.h:
+ * UIProcess/mac/WebPageProxyMac.mm:
+ (WebKit::WebPageProxy::insertDictatedTextAsync): Deleted.
+ * WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
+ (WebKit::WebPage::insertDictatedTextAsync):
+ * WebProcess/WebPage/WebPage.h:
+ * WebProcess/WebPage/WebPage.messages.in:
+ * WebProcess/WebPage/mac/WebPageMac.mm:
+ (WebKit::WebPage::insertDictatedTextAsync): Deleted.
+
+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
Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm (258085 => 258086)
--- trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm 2020-03-08 00:26:17 UTC (rev 258085)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm 2020-03-08 00:27:55 UTC (rev 258086)
@@ -29,6 +29,7 @@
#import "APIAttachment.h"
#import "APIUIClient.h"
#import "DataDetectionResult.h"
+#import "InsertTextOptions.h"
#import "LoadParameters.h"
#import "PageClient.h"
#import "SafeBrowsingSPI.h"
@@ -44,6 +45,10 @@
#import <wtf/BlockPtr.h>
#import <wtf/cf/TypeCastsCF.h>
+#if USE(DICTATION_ALTERNATIVES)
+#import <WebCore/TextAlternativeWithRange.h>
+#endif
+
namespace WebKit {
using namespace WebCore;
@@ -161,6 +166,7 @@
pageClient().startDrag(dragItem, dragImageHandle);
}
+// FIXME: Move these functions to WebPageProxyIOS.mm.
#if PLATFORM(IOS_FAMILY)
void WebPageProxy::setPromisedDataForImage(const String&, const SharedMemory::Handle&, uint64_t, const String&, const String&, const String&, const String&, const String&, const SharedMemory::Handle&, uint64_t)
@@ -225,6 +231,36 @@
process().send(Messages::WebPage::PerformDictionaryLookupOfCurrentSelection(), m_webPageID);
}
+
+void WebPageProxy::insertDictatedTextAsync(const String& text, const EditingRange& replacementRange, const Vector<TextAlternativeWithRange>& dictationAlternativesWithRange, bool registerUndoGroup)
+{
+#if USE(DICTATION_ALTERNATIVES)
+ if (!hasRunningProcess())
+ return;
+
+ Vector<DictationAlternative> dictationAlternatives;
+ for (const auto& alternativeWithRange : dictationAlternativesWithRange) {
+ uint64_t dictationContext = pageClient().addDictationAlternatives(alternativeWithRange.alternatives);
+ if (dictationContext)
+ dictationAlternatives.append(DictationAlternative(alternativeWithRange.range.location, alternativeWithRange.range.length, dictationContext));
+ }
+
+ if (dictationAlternatives.isEmpty()) {
+ InsertTextOptions options;
+ options.registerUndoGroup = registerUndoGroup;
+
+ insertTextAsync(text, replacementRange, WTFMove(options));
+ return;
+ }
+
+ process().send(Messages::WebPage::InsertDictatedTextAsync { text, replacementRange, dictationAlternatives, registerUndoGroup }, m_webPageID);
+#else
+ InsertTextOptions options;
+ options.registerUndoGroup = registerUndoGroup;
+
+ insertTextAsync(text, replacementRange, WTFMove(options));
+#endif
+}
#if ENABLE(APPLE_PAY)
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (258085 => 258086)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2020-03-08 00:26:17 UTC (rev 258085)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2020-03-08 00:27:55 UTC (rev 258086)
@@ -8526,6 +8526,7 @@
send(Messages::WebPage::ChangeFont(WTFMove(changes)));
}
+// FIXME: Move these functions to WebPageProxyCocoa.mm.
#if PLATFORM(COCOA)
void WebPageProxy::setTextAsync(const String& text)
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (258085 => 258086)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.h 2020-03-08 00:26:17 UTC (rev 258085)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h 2020-03-08 00:27:55 UTC (rev 258086)
@@ -853,7 +853,10 @@
CALayer *acceleratedCompositingRootLayer() const;
void setTextAsync(const String&);
- void insertTextAsync(const String& text, const EditingRange& replacementRange, InsertTextOptions&&);
+
+ void insertTextAsync(const String&, const EditingRange& replacementRange, InsertTextOptions&&);
+ void insertDictatedTextAsync(const String&, const EditingRange& replacementRange, const Vector<WebCore::TextAlternativeWithRange>&, bool registerUndoGroup);
+
void hasMarkedText(CompletionHandler<void(bool)>&&);
void getMarkedRangeAsync(WTF::Function<void (EditingRange, CallbackBase::Error)>&&);
void getSelectedRangeAsync(WTF::Function<void (EditingRange, CallbackBase::Error)>&&);
@@ -871,7 +874,6 @@
void changeFont(WebCore::FontChanges&&);
#if PLATFORM(MAC)
- void insertDictatedTextAsync(const String& text, const EditingRange& replacementRange, const Vector<WebCore::TextAlternativeWithRange>& dictationAlternatives, bool registerUndoGroup);
void attributedSubstringForCharacterRangeAsync(const EditingRange&, WTF::Function<void (const AttributedString&, const EditingRange&, CallbackBase::Error)>&&);
void fontAtSelection(Function<void(const FontInfo&, double, bool, CallbackBase::Error)>&&);
Modified: trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm (258085 => 258086)
--- trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm 2020-03-08 00:26:17 UTC (rev 258085)
+++ trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm 2020-03-08 00:27:55 UTC (rev 258086)
@@ -184,37 +184,6 @@
process().send(Messages::WebPage::SetMainFrameIsScrollable(isScrollable), m_webPageID);
}
-void WebPageProxy::insertDictatedTextAsync(const String& text, const EditingRange& replacementRange, const Vector<TextAlternativeWithRange>& dictationAlternativesWithRange, bool registerUndoGroup)
-{
-#if USE(DICTATION_ALTERNATIVES)
- if (!hasRunningProcess())
- return;
-
- Vector<DictationAlternative> dictationAlternatives;
-
- for (const TextAlternativeWithRange& alternativeWithRange : dictationAlternativesWithRange) {
- uint64_t dictationContext = pageClient().addDictationAlternatives(alternativeWithRange.alternatives);
- if (dictationContext)
- dictationAlternatives.append(DictationAlternative(alternativeWithRange.range.location, alternativeWithRange.range.length, dictationContext));
- }
-
- if (dictationAlternatives.isEmpty()) {
- InsertTextOptions options;
- options.registerUndoGroup = registerUndoGroup;
-
- insertTextAsync(text, replacementRange, WTFMove(options));
- return;
- }
-
- process().send(Messages::WebPage::InsertDictatedTextAsync(text, replacementRange, dictationAlternatives, registerUndoGroup), m_webPageID);
-#else
- InsertTextOptions options;
- options.registerUndoGroup = registerUndoGroup;
-
- insertTextAsync(text, replacementRange, WTFMove(options));
-#endif
-}
-
void WebPageProxy::attributedSubstringForCharacterRangeAsync(const EditingRange& range, WTF::Function<void (const AttributedString&, const EditingRange&, CallbackBase::Error)>&& callbackFunction)
{
if (!hasRunningProcess()) {
Modified: trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm (258085 => 258086)
--- trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm 2020-03-08 00:26:17 UTC (rev 258085)
+++ trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm 2020-03-08 00:27:55 UTC (rev 258086)
@@ -186,6 +186,24 @@
return dictionaryPopupInfo;
}
+void WebPage::insertDictatedTextAsync(const String& text, const EditingRange& replacementEditingRange, const Vector<WebCore::DictationAlternative>& dictationAlternativeLocations, bool registerUndoGroup)
+{
+ auto& frame = m_page->focusController().focusedOrMainFrame();
+ Ref<Frame> protector { frame };
+
+ if (replacementEditingRange.location != notFound) {
+ auto replacementRange = EditingRange::toRange(frame, replacementEditingRange);
+ if (replacementRange)
+ frame.selection().setSelection(VisibleSelection { *replacementRange, SEL_DEFAULT_AFFINITY });
+ }
+
+ if (registerUndoGroup)
+ send(Messages::WebPageProxy::RegisterInsertionUndoGrouping { });
+
+ ASSERT(!frame.editor().hasComposition());
+ frame.editor().insertDictatedText(text, dictationAlternativeLocations, nullptr /* triggeringEvent */);
+}
+
void WebPage::accessibilityTransferRemoteToken(RetainPtr<NSData> remoteToken)
{
IPC::DataReference dataToken = IPC::DataReference(reinterpret_cast<const uint8_t*>([remoteToken bytes]), [remoteToken length]);
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (258085 => 258086)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2020-03-08 00:26:17 UTC (rev 258085)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2020-03-08 00:27:55 UTC (rev 258086)
@@ -845,10 +845,11 @@
void shouldDelayWindowOrderingEvent(const WebKit::WebMouseEvent&, CompletionHandler<void(bool)>&&);
void acceptsFirstMouse(int eventNumber, const WebKit::WebMouseEvent&, CompletionHandler<void(bool)>&&);
bool performNonEditingBehaviorForSelector(const String&, WebCore::KeyboardEvent*);
+
+ void insertDictatedTextAsync(const String& text, const EditingRange& replacementRange, const Vector<WebCore::DictationAlternative>& dictationAlternativeLocations, bool registerUndoGroup = false);
#endif
#if PLATFORM(MAC)
- void insertDictatedTextAsync(const String& text, const EditingRange& replacementRange, const Vector<WebCore::DictationAlternative>& dictationAlternativeLocations, bool registerUndoGroup = false);
void attributedSubstringForCharacterRangeAsync(const EditingRange&, CallbackID);
void fontAtSelection(CallbackID);
#endif
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (258085 => 258086)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in 2020-03-08 00:26:17 UTC (rev 258085)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in 2020-03-08 00:27:55 UTC (rev 258086)
@@ -451,7 +451,10 @@
AcceptsFirstMouse(int eventNumber, WebKit::WebMouseEvent event) -> (bool result) Synchronous
SetTextAsync(String text)
+
InsertTextAsync(String text, struct WebKit::EditingRange replacementRange, struct WebKit::InsertTextOptions options)
+ InsertDictatedTextAsync(String text, struct WebKit::EditingRange replacementRange, Vector<WebCore::DictationAlternative> dictationAlternatives, bool registerUndoGroup)
+
HasMarkedText() -> (bool hasMarkedText) Async
GetMarkedRangeAsync(WebKit::CallbackID callbackID)
GetSelectedRangeAsync(WebKit::CallbackID callbackID)
@@ -461,7 +464,6 @@
ConfirmCompositionAsync()
#endif
#if PLATFORM(MAC)
- InsertDictatedTextAsync(String text, struct WebKit::EditingRange replacementRange, Vector<WebCore::DictationAlternative> dictationAlternatives, bool registerUndoGroup)
AttributedSubstringForCharacterRangeAsync(struct WebKit::EditingRange range, WebKit::CallbackID callbackID);
FontAtSelection(WebKit::CallbackID callbackID)
#endif
Modified: trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm (258085 => 258086)
--- trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm 2020-03-08 00:26:17 UTC (rev 258085)
+++ trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm 2020-03-08 00:27:55 UTC (rev 258086)
@@ -320,25 +320,6 @@
}
}
-void WebPage::insertDictatedTextAsync(const String& text, const EditingRange& replacementEditingRange, const Vector<WebCore::DictationAlternative>& dictationAlternativeLocations, bool registerUndoGroup)
-{
- Frame& frame = m_page->focusController().focusedOrMainFrame();
-
- Ref<Frame> protector(frame);
-
- if (replacementEditingRange.location != notFound) {
- RefPtr<Range> replacementRange = EditingRange::toRange(frame, replacementEditingRange);
- if (replacementRange)
- frame.selection().setSelection(VisibleSelection(*replacementRange, SEL_DEFAULT_AFFINITY));
- }
-
- if (registerUndoGroup)
- send(Messages::WebPageProxy::RegisterInsertionUndoGrouping());
-
- ASSERT(!frame.editor().hasComposition());
- frame.editor().insertDictatedText(text, dictationAlternativeLocations, nullptr);
-}
-
void WebPage::attributedSubstringForCharacterRangeAsync(const EditingRange& editingRange, CallbackID callbackID)
{
Frame& frame = m_page->focusController().focusedOrMainFrame();