Diff
Modified: trunk/Source/WebKit/ChangeLog (241145 => 241146)
--- trunk/Source/WebKit/ChangeLog 2019-02-07 22:52:15 UTC (rev 241145)
+++ trunk/Source/WebKit/ChangeLog 2019-02-07 22:56:58 UTC (rev 241146)
@@ -1,3 +1,54 @@
+2019-02-07 Wenson Hsieh <wenson_hs...@apple.com>
+
+ [iOS] [WK2] Modernize autocorrection context code
+ https://bugs.webkit.org/show_bug.cgi?id=194373
+
+ Reviewed by Tim Horton.
+
+ * Shared/ios/WebAutocorrectionContext.h: Added.
+ (WebKit::WebAutocorrectionContext::encode const):
+ (WebKit::WebAutocorrectionContext::decode):
+
+ Introduce a WebAutocorrectionContext struct that encapsulates the individual pieces of autocorrection context.
+ Change to use this instead of a long list of arguments when propagating autocorrection context information over
+ IPC.
+
+ * UIProcess/AutoCorrectionCallback.h:
+ * UIProcess/WebPageProxy.h:
+ * UIProcess/WebPageProxy.messages.in:
+ * UIProcess/ios/WKContentViewInteraction.h:
+ * UIProcess/ios/WKContentViewInteraction.mm:
+ (-[WKContentView requestAutocorrectionContextWithCompletionHandler:]):
+ (+[WKAutocorrectionContext autocorrectionContextWithContext:]):
+ (+[WKAutocorrectionContext autocorrectionContextWithData:markedText:selectedText:afterText:selectedRangeInMarkedText:]): Deleted.
+
+ Change this constructor to take an entire WebAutocorrectionContext.
+
+ * UIProcess/ios/WebPageProxyIOS.mm:
+ (WebKit::WebPageProxy::autocorrectionContextCallback):
+ (WebKit::WebPageProxy::requestAutocorrectionContext):
+ (WebKit::WebPageProxy::autocorrectionContextSync):
+ (WebKit::WebPageProxy::getAutocorrectionContext): Deleted.
+ * WebKit.xcodeproj/project.pbxproj:
+ * WebProcess/WebPage/WebPage.h:
+ * WebProcess/WebPage/WebPage.messages.in:
+
+ Use Delayed instead of LegacySync.
+
+ * WebProcess/WebPage/ios/WebPageIOS.mm:
+ (WebKit::WebPage::autocorrectionContext):
+
+ Renamed from computeAutocorrectionContext. This is now a private method on WebPage that uses the focused or main
+ frame to compute and return a WebAutocorrectionContext.
+
+ (WebKit::WebPage::requestAutocorrectionContext):
+ (WebKit::WebPage::autocorrectionContextSync):
+
+ Renamed getAutocorrectionContext to autocorrectionContextSync.
+
+ (WebKit::computeAutocorrectionContext): Deleted.
+ (WebKit::WebPage::getAutocorrectionContext): Deleted.
+
2019-02-07 Youenn Fablet <you...@apple.com>
Simplify applyConstraints callbacks
Added: trunk/Source/WebKit/Shared/ios/WebAutocorrectionContext.h (0 => 241146)
--- trunk/Source/WebKit/Shared/ios/WebAutocorrectionContext.h (rev 0)
+++ trunk/Source/WebKit/Shared/ios/WebAutocorrectionContext.h 2019-02-07 22:56:58 UTC (rev 241146)
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2019 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 "Decoder.h"
+#include "Encoder.h"
+#include <wtf/NotFound.h>
+#include <wtf/Optional.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebKit {
+
+struct WebAutocorrectionContext {
+ String contextBefore;
+ String markedText;
+ String selectedText;
+ String contextAfter;
+ uint64_t location { notFound };
+ uint64_t length { 0 };
+
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static Optional<WebAutocorrectionContext> decode(Decoder&);
+};
+
+template<class Encoder> inline void WebAutocorrectionContext::encode(Encoder& encoder) const
+{
+ encoder << contextBefore << markedText << selectedText << contextAfter << location << length;
+}
+
+template<class Decoder> inline Optional<WebAutocorrectionContext> WebAutocorrectionContext::decode(Decoder& decoder)
+{
+ Optional<String> contextBefore;
+ decoder >> contextBefore;
+ if (!contextBefore)
+ return WTF::nullopt;
+
+ Optional<String> markedText;
+ decoder >> markedText;
+ if (!markedText)
+ return WTF::nullopt;
+
+ Optional<String> selectedText;
+ decoder >> selectedText;
+ if (!selectedText)
+ return WTF::nullopt;
+
+ Optional<String> contextAfter;
+ decoder >> contextAfter;
+ if (!contextAfter)
+ return WTF::nullopt;
+
+ Optional<uint64_t> location;
+ decoder >> location;
+ if (!location)
+ return WTF::nullopt;
+
+ Optional<uint64_t> length;
+ decoder >> length;
+ if (!length)
+ return WTF::nullopt;
+
+ return {{ WTFMove(*contextBefore), WTFMove(*markedText), WTFMove(*selectedText), WTFMove(*contextAfter), WTFMove(*location), WTFMove(*length) }};
+}
+
+} // namespace WebKit
Modified: trunk/Source/WebKit/UIProcess/AutoCorrectionCallback.h (241145 => 241146)
--- trunk/Source/WebKit/UIProcess/AutoCorrectionCallback.h 2019-02-07 22:52:15 UTC (rev 241145)
+++ trunk/Source/WebKit/UIProcess/AutoCorrectionCallback.h 2019-02-07 22:56:58 UTC (rev 241146)
@@ -34,8 +34,10 @@
namespace WebKit {
+struct WebAutocorrectionContext;
+
typedef GenericCallback<const Vector<WebCore::FloatRect>&, const String&, double, uint64_t> AutocorrectionDataCallback;
-typedef GenericCallback<const String&, const String&, const String&, const String&, uint64_t, uint64_t> AutocorrectionContextCallback;
+typedef GenericCallback<const WebAutocorrectionContext&> AutocorrectionContextCallback;
typedef GenericCallback<const String&, const String&, const String&> SelectionContextCallback;
} // namespace WebKit
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (241145 => 241146)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.h 2019-02-07 22:52:15 UTC (rev 241145)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h 2019-02-07 22:56:58 UTC (rev 241146)
@@ -102,6 +102,10 @@
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>
+#if PLATFORM(IOS_FAMILY)
+#include "WebAutocorrectionContext.h"
+#endif
+
OBJC_CLASS NSView;
OBJC_CLASS _WKRemoteObjectRegistry;
@@ -640,8 +644,8 @@
void requestAutocorrectionData(const String& textForAutocorrection, WTF::Function<void (const Vector<WebCore::FloatRect>&, const String&, double, uint64_t, CallbackBase::Error)>&&);
void applyAutocorrection(const String& correction, const String& originalText, WTF::Function<void (const String&, CallbackBase::Error)>&&);
bool applyAutocorrection(const String& correction, const String& originalText);
- void requestAutocorrectionContext(WTF::Function<void (const String&, const String&, const String&, const String&, uint64_t, uint64_t, CallbackBase::Error)>&&);
- void getAutocorrectionContext(String& contextBefore, String& markedText, String& selectedText, String& contextAfter, uint64_t& location, uint64_t& length);
+ void requestAutocorrectionContext(Function<void(const WebAutocorrectionContext&, CallbackBase::Error)>&&);
+ WebAutocorrectionContext autocorrectionContextSync();
void requestDictationContext(WTF::Function<void (const String&, const String&, const String&, CallbackBase::Error)>&&);
void replaceDictatedText(const String& oldText, const String& newText);
void replaceSelectedText(const String& oldText, const String& newText);
@@ -1761,7 +1765,7 @@
void gestureCallback(const WebCore::IntPoint&, uint32_t gestureType, uint32_t gestureState, uint32_t flags, CallbackID);
void touchesCallback(const WebCore::IntPoint&, uint32_t touches, uint32_t flags, CallbackID);
void autocorrectionDataCallback(const Vector<WebCore::FloatRect>&, const String& fontName, float fontSize, uint64_t fontTraits, CallbackID);
- void autocorrectionContextCallback(const String& beforeText, const String& markedText, const String& selectedText, const String& afterText, uint64_t location, uint64_t length, CallbackID);
+ void autocorrectionContextCallback(const WebAutocorrectionContext&, CallbackID);
void selectionContextCallback(const String& selectedText, const String& beforeText, const String& afterText, CallbackID);
void interpretKeyEvent(const EditorState&, bool isCharEvent, bool& handled);
void showPlaybackTargetPicker(bool hasVideo, const WebCore::IntRect& elementRect, WebCore::RouteSharingPolicy, const String&);
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (241145 => 241146)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in 2019-02-07 22:52:15 UTC (rev 241145)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in 2019-02-07 22:56:58 UTC (rev 241146)
@@ -188,7 +188,7 @@
GestureCallback(WebCore::IntPoint point, uint32_t gestureType, uint32_t gestureState, uint32_t flags, WebKit::CallbackID callbackID)
TouchesCallback(WebCore::IntPoint point, uint32_t touches, uint32_t flags, WebKit::CallbackID callbackID)
AutocorrectionDataCallback(Vector<WebCore::FloatRect> textRects, String fontName, double fontSize, uint64_t traits, WebKit::CallbackID callbackID)
- AutocorrectionContextCallback(String beforeText, String markedText, String selectedText, String afterText, uint64_t location, uint64_t length, WebKit::CallbackID callbackID)
+ AutocorrectionContextCallback(struct WebKit::WebAutocorrectionContext context, WebKit::CallbackID callbackID)
SelectionContextCallback(String selectedText, String beforeText, String afterText, WebKit::CallbackID callbackID)
InterpretKeyEvent(struct WebKit::EditorState state, bool isCharEvent) -> (bool handled) LegacySync
DidReceivePositionInformation(struct WebKit::InteractionInformationAtPosition information)
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (241145 => 241146)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h 2019-02-07 22:52:15 UTC (rev 241145)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h 2019-02-07 22:56:58 UTC (rev 241146)
@@ -176,7 +176,6 @@
CGRect textFirstRect;
CGRect textLastRect;
UIWKAutocorrectionCompletionHandler autocorrectionHandler;
- UIWKAutocorrectionContextHandler autocorrectionContextHandler;
};
}
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (241145 => 241146)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2019-02-07 22:52:15 UTC (rev 241145)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2019-02-07 22:56:58 UTC (rev 241146)
@@ -64,6 +64,7 @@
#import "WKWebViewConfigurationPrivate.h"
#import "WKWebViewInternal.h"
#import "WKWebViewPrivate.h"
+#import "WebAutocorrectionContext.h"
#import "WebDataListSuggestionsDropdownIOS.h"
#import "WebEvent.h"
#import "WebIOSEventFactory.h"
@@ -271,7 +272,7 @@
@end
@interface WKAutocorrectionContext : UIWKAutocorrectionContext
-+ (WKAutocorrectionContext *)autocorrectionContextWithData:(NSString *)beforeText markedText:(NSString *)markedText selectedText:(NSString *)selectedText afterText:(NSString *)afterText selectedRangeInMarkedText:(NSRange)range;
++ (WKAutocorrectionContext *)autocorrectionContextWithContext:(const WebKit::WebAutocorrectionContext&)context;
@end
@interface UITextInteractionAssistant (UITextInteractionAssistant_Internal)
@@ -3393,25 +3394,20 @@
- (void)requestAutocorrectionContextWithCompletionHandler:(void (^)(UIWKAutocorrectionContext *autocorrectionContext))completionHandler
{
+ if (!completionHandler)
+ return;
+
// FIXME: Remove the synchronous call when <rdar://problem/16207002> is fixed.
const bool useSyncRequest = true;
if (useSyncRequest) {
- String beforeText;
- String markedText;
- String selectedText;
- String afterText;
- uint64_t location;
- uint64_t length;
- _page->getAutocorrectionContext(beforeText, markedText, selectedText, afterText, location, length);
- completionHandler([WKAutocorrectionContext autocorrectionContextWithData:beforeText markedText:markedText selectedText:selectedText afterText:afterText selectedRangeInMarkedText:NSMakeRange(location, length)]);
- } else {
- _autocorrectionData.autocorrectionContextHandler = [completionHandler copy];
- RetainPtr<WKContentView> view = self;
- _page->requestAutocorrectionContext([view](const String& beforeText, const String& markedText, const String& selectedText, const String& afterText, uint64_t location, uint64_t length, WebKit::CallbackBase::Error) {
- view->_autocorrectionData.autocorrectionContextHandler([WKAutocorrectionContext autocorrectionContextWithData:beforeText markedText:markedText selectedText:selectedText afterText:afterText selectedRangeInMarkedText:NSMakeRange(location, length)]);
- });
+ completionHandler([WKAutocorrectionContext autocorrectionContextWithContext:_page->autocorrectionContextSync()]);
+ return;
}
+
+ _page->requestAutocorrectionContext([protectedSelf = retainPtr(self), completion = makeBlockPtr(completionHandler)] (auto& context, auto) {
+ completion([WKAutocorrectionContext autocorrectionContextWithContext:context]);
+ });
}
// UIWebFormAccessoryDelegate
@@ -7093,19 +7089,19 @@
@implementation WKAutocorrectionContext
-+ (WKAutocorrectionContext *)autocorrectionContextWithData:(NSString *)beforeText markedText:(NSString *)markedText selectedText:(NSString *)selectedText afterText:(NSString *)afterText selectedRangeInMarkedText:(NSRange)range
++ (WKAutocorrectionContext *)autocorrectionContextWithContext:(const WebKit::WebAutocorrectionContext&)webContext
{
WKAutocorrectionContext *context = [[WKAutocorrectionContext alloc] init];
- if ([beforeText length])
- context.contextBeforeSelection = beforeText;
- if ([selectedText length])
- context.selectedText = selectedText;
- if ([markedText length])
- context.markedText = markedText;
- if ([afterText length])
- context.contextAfterSelection = afterText;
- context.rangeInMarkedText = range;
+ if (!webContext.contextBefore.isEmpty())
+ context.contextBeforeSelection = webContext.contextBefore;
+ if (!webContext.selectedText.isEmpty())
+ context.selectedText = webContext.selectedText;
+ if (!webContext.markedText.isEmpty())
+ context.markedText = webContext.markedText;
+ if (!webContext.contextAfter.isEmpty())
+ context.contextAfterSelection = webContext.contextAfter;
+ context.rangeInMarkedText = NSMakeRange(webContext.location, webContext.length);
return [context autorelease];
}
Modified: trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm (241145 => 241146)
--- trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm 2019-02-07 22:52:15 UTC (rev 241145)
+++ trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm 2019-02-07 22:56:58 UTC (rev 241146)
@@ -46,6 +46,7 @@
#import "VideoFullscreenManagerProxy.h"
#import "ViewUpdateDispatcherMessages.h"
#import "WKBrowsingContextControllerInternal.h"
+#import "WebAutocorrectionContext.h"
#import "WebPageMessages.h"
#import "WebProcessProxy.h"
#import <WebCore/FrameView.h>
@@ -166,7 +167,7 @@
callback->performCallbackWithReturnValue(selectedText, beforeText, afterText);
}
-void WebPageProxy::autocorrectionContextCallback(const String& beforeText, const String& markedText, const String& selectedText, const String& afterText, uint64_t location, uint64_t length, CallbackID callbackID)
+void WebPageProxy::autocorrectionContextCallback(const WebAutocorrectionContext& context, CallbackID callbackID)
{
auto callback = m_callbacks.take<AutocorrectionContextCallback>(callbackID);
if (!callback) {
@@ -174,7 +175,7 @@
return;
}
- callback->performCallbackWithReturnValue(beforeText, markedText, selectedText, afterText, location, length);
+ callback->performCallbackWithReturnValue(context);
}
void WebPageProxy::selectionRectsCallback(const Vector<WebCore::SelectionRect>& selectionRects, CallbackID callbackID)
@@ -566,20 +567,22 @@
m_process->send(Messages::WebPage::RequestDictationContext(callbackID), m_pageID);
}
-void WebPageProxy::requestAutocorrectionContext(WTF::Function<void (const String&, const String&, const String&, const String&, uint64_t, uint64_t, CallbackBase::Error)>&& callbackFunction)
+void WebPageProxy::requestAutocorrectionContext(Function<void(const WebAutocorrectionContext&, CallbackBase::Error)>&& callback)
{
if (!isValid()) {
- callbackFunction(String(), String(), String(), String(), 0, 0, CallbackBase::Error::Unknown);
+ callback({ }, CallbackBase::Error::OwnerWasInvalidated);
return;
}
- auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
+ auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivityToken());
m_process->send(Messages::WebPage::RequestAutocorrectionContext(callbackID), m_pageID);
}
-void WebPageProxy::getAutocorrectionContext(String& beforeContext, String& markedText, String& selectedText, String& afterContext, uint64_t& location, uint64_t& length)
+WebAutocorrectionContext WebPageProxy::autocorrectionContextSync()
{
- m_process->sendSync(Messages::WebPage::GetAutocorrectionContext(), Messages::WebPage::GetAutocorrectionContext::Reply(beforeContext, markedText, selectedText, afterContext, location, length), m_pageID);
+ WebAutocorrectionContext context;
+ m_process->sendSync(Messages::WebPage::AutocorrectionContextSync(), Messages::WebPage::AutocorrectionContextSync::Reply(context), m_pageID);
+ return context;
}
void WebPageProxy::getSelectionContext(WTF::Function<void(const String&, const String&, const String&, CallbackBase::Error)>&& callbackFunction)
Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (241145 => 241146)
--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2019-02-07 22:52:15 UTC (rev 241145)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2019-02-07 22:56:58 UTC (rev 241146)
@@ -4510,6 +4510,7 @@
ECBFC1DB1E6A4D66000300C7 /* ExtraPublicSymbolsForTAPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ExtraPublicSymbolsForTAPI.h; sourceTree = "<group>"; };
F036978715F4BF0500C3A80E /* WebColorPicker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebColorPicker.cpp; sourceTree = "<group>"; };
F409BA171E6E64B3009DA28E /* WKDragDestinationAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKDragDestinationAction.h; sourceTree = "<group>"; };
+ F40D1B68220BDC0F00B49A01 /* WebAutocorrectionContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WebAutocorrectionContext.h; path = ios/WebAutocorrectionContext.h; sourceTree = "<group>"; };
F41056612130699A0092281D /* APIAttachmentCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = APIAttachmentCocoa.mm; sourceTree = "<group>"; };
F44291911FA59107002CC93E /* _WKAttachment.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = _WKAttachment.h; sourceTree = "<group>"; };
F44291931FA59311002CC93E /* _WKAttachment.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKAttachment.mm; sourceTree = "<group>"; };
@@ -5785,6 +5786,7 @@
2DA944981884E4F000ED86DB /* NativeWebTouchEventIOS.mm */,
A118A9EC1907AD6F00F7C92B /* QuickLookDocumentData.cpp */,
A118A9ED1907AD6F00F7C92B /* QuickLookDocumentData.h */,
+ F40D1B68220BDC0F00B49A01 /* WebAutocorrectionContext.h */,
F44DFEB01E9E752F0038D196 /* WebIconUtilities.h */,
F44DFEB11E9E752F0038D196 /* WebIconUtilities.mm */,
2DA944991884E4F000ED86DB /* WebIOSEventFactory.h */,
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (241145 => 241146)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2019-02-07 22:52:15 UTC (rev 241145)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2019-02-07 22:56:58 UTC (rev 241146)
@@ -250,6 +250,7 @@
struct InteractionInformationRequest;
struct LoadParameters;
struct PrintInfo;
+struct WebAutocorrectionContext;
struct WebPageCreationParameters;
struct WebPreferencesStore;
struct WebSelectionData;
@@ -647,7 +648,7 @@
void applyAutocorrection(const String& correction, const String& originalText, CallbackID);
void syncApplyAutocorrection(const String& correction, const String& originalText, bool& correctionApplied);
void requestAutocorrectionContext(CallbackID);
- void getAutocorrectionContext(String& beforeText, String& markedText, String& selectedText, String& afterText, uint64_t& location, uint64_t& length);
+ void autocorrectionContextSync(CompletionHandler<void(WebAutocorrectionContext&&)>&&);
void getPositionInformation(const InteractionInformationRequest&, CompletionHandler<void(InteractionInformationAtPosition&&)>&&);
void requestPositionInformation(const InteractionInformationRequest&);
void startInteractionWithElementAtPosition(const WebCore::IntPoint&);
@@ -1189,6 +1190,7 @@
void sendPositionInformation(InteractionInformationAtPosition&&);
InteractionInformationAtPosition positionInformation(const InteractionInformationRequest&);
+ WebAutocorrectionContext autocorrectionContext();
#endif
#if PLATFORM(IOS_FAMILY) && ENABLE(DATA_INTERACTION)
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (241145 => 241146)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in 2019-02-07 22:52:15 UTC (rev 241145)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in 2019-02-07 22:56:58 UTC (rev 241146)
@@ -79,7 +79,7 @@
ApplyAutocorrection(String correction, String originalText, WebKit::CallbackID callbackID)
SyncApplyAutocorrection(String correction, String originalText) -> (bool autocorrectionApplied) LegacySync
RequestAutocorrectionContext(WebKit::CallbackID callbackID)
- GetAutocorrectionContext() -> (String beforeContext, String markedText, String selectedText, String afterContext, uint64_t location, uint64_t length) LegacySync
+ AutocorrectionContextSync() -> (struct WebKit::WebAutocorrectionContext context) Delayed
GetPositionInformation(struct WebKit::InteractionInformationRequest request) -> (struct WebKit::InteractionInformationAtPosition information) Delayed
RequestPositionInformation(struct WebKit::InteractionInformationRequest request)
StartInteractionWithElementAtPosition(WebCore::IntPoint point)
Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (241145 => 241146)
--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2019-02-07 22:52:15 UTC (rev 241145)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2019-02-07 22:56:58 UTC (rev 241146)
@@ -45,6 +45,7 @@
#import "UserData.h"
#import "VisibleContentRectUpdateInfo.h"
#import "WKAccessibilityWebPageObjectIOS.h"
+#import "WebAutocorrectionContext.h"
#import "WebChromeClient.h"
#import "WebCoreArgumentCoders.h"
#import "WebFrame.h"
@@ -1975,13 +1976,19 @@
correctionApplied = true;
}
-static void computeAutocorrectionContext(Frame& frame, String& contextBefore, String& markedText, String& selectedText, String& contextAfter, uint64_t& location, uint64_t& length)
+WebAutocorrectionContext WebPage::autocorrectionContext()
{
+ String contextBefore;
+ String markedText;
+ String selectedText;
+ String contextAfter;
+ uint64_t location = NSNotFound;
+ uint64_t length = 0;
+
+ auto& frame = m_page->focusController().focusedOrMainFrame();
RefPtr<Range> range;
VisiblePosition startPosition = frame.selection().selection().start();
VisiblePosition endPosition = frame.selection().selection().end();
- location = NSNotFound;
- length = 0;
const unsigned minContextWordCount = 3;
const unsigned minContextLenght = 12;
const unsigned maxContextLength = 30;
@@ -2035,25 +2042,17 @@
contextAfter = plainTextReplacingNoBreakSpace(Range::create(*frame.document(), endPosition, nextPosition).ptr());
}
}
+ return { WTFMove(contextBefore), WTFMove(markedText), WTFMove(selectedText), WTFMove(contextAfter), location, length };
}
void WebPage::requestAutocorrectionContext(CallbackID callbackID)
{
- String contextBefore;
- String contextAfter;
- String selectedText;
- String markedText;
- uint64_t location;
- uint64_t length;
-
- computeAutocorrectionContext(m_page->focusController().focusedOrMainFrame(), contextBefore, markedText, selectedText, contextAfter, location, length);
-
- send(Messages::WebPageProxy::AutocorrectionContextCallback(contextBefore, markedText, selectedText, contextAfter, location, length, callbackID));
+ send(Messages::WebPageProxy::AutocorrectionContextCallback(autocorrectionContext(), callbackID));
}
-void WebPage::getAutocorrectionContext(String& contextBefore, String& markedText, String& selectedText, String& contextAfter, uint64_t& location, uint64_t& length)
+void WebPage::autocorrectionContextSync(CompletionHandler<void(WebAutocorrectionContext&&)>&& completionHandler)
{
- computeAutocorrectionContext(m_page->focusController().focusedOrMainFrame(), contextBefore, markedText, selectedText, contextAfter, location, length);
+ completionHandler(autocorrectionContext());
}
static HTMLAnchorElement* containingLinkElement(Element* element)