Diff
Modified: trunk/Source/WebKit/ChangeLog (241179 => 241180)
--- trunk/Source/WebKit/ChangeLog 2019-02-08 01:30:19 UTC (rev 241179)
+++ trunk/Source/WebKit/ChangeLog 2019-02-08 01:45:42 UTC (rev 241180)
@@ -1,5 +1,29 @@
2019-02-07 Wenson Hsieh <wenson_hs...@apple.com>
+ [iOS] [WK2] Modernize code for applying autocorrection
+ https://bugs.webkit.org/show_bug.cgi?id=194397
+
+ Reviewed by Tim Horton.
+
+ * UIProcess/ios/WKContentViewInteraction.h:
+ * UIProcess/ios/WKContentViewInteraction.mm:
+ (-[WKContentView requestAutocorrectionRectsForString:withCompletionHandler:]):
+ (-[WKContentView applyAutocorrection:toString:withCompletionHandler:]):
+
+ Use BlockPtr instead of temporarily storing the completion handler.
+
+ * WebProcess/WebPage/WebPage.h:
+ * WebProcess/WebPage/WebPage.messages.in:
+
+ Change a LegacySync to Delayed.
+
+ * WebProcess/WebPage/ios/WebPageIOS.mm:
+ (WebKit::WebPage::applyAutocorrection):
+ (WebKit::WebPage::syncApplyAutocorrection):
+ (WebKit::WebPage::applyAutocorrectionInternal):
+
+2019-02-07 Wenson Hsieh <wenson_hs...@apple.com>
+
[iOS] Clicking links in Safari using Apple Pencil is much more difficult after r238475
https://bugs.webkit.org/show_bug.cgi?id=194415
<rdar://problem/47550281>
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (241179 => 241180)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h 2019-02-08 01:30:19 UTC (rev 241179)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h 2019-02-08 01:45:42 UTC (rev 241180)
@@ -175,7 +175,6 @@
uint64_t fontTraits;
CGRect textFirstRect;
CGRect textLastRect;
- UIWKAutocorrectionCompletionHandler autocorrectionHandler;
};
}
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (241179 => 241180)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2019-02-08 01:30:19 UTC (rev 241179)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2019-02-08 01:45:42 UTC (rev 241180)
@@ -3217,13 +3217,12 @@
- (void)requestAutocorrectionRectsForString:(NSString *)input withCompletionHandler:(void (^)(UIWKAutocorrectionRects *rectsForInput))completionHandler
{
if (!input || ![input length]) {
- completionHandler(nil);
+ if (completionHandler)
+ completionHandler(nil);
return;
}
- RetainPtr<WKContentView> view = self;
- _autocorrectionData.autocorrectionHandler = [completionHandler copy];
- _page->requestAutocorrectionData(input, [view](const Vector<WebCore::FloatRect>& rects, const String& fontName, double fontSize, uint64_t traits, WebKit::CallbackBase::Error) {
+ _page->requestAutocorrectionData(input, [view = retainPtr(self), completion = makeBlockPtr(completionHandler)](auto& rects, auto& fontName, double fontSize, uint64_t traits, auto) {
CGRect firstRect = CGRectZero;
CGRect lastRect = CGRectZero;
if (rects.size()) {
@@ -3237,9 +3236,8 @@
view->_autocorrectionData.textFirstRect = firstRect;
view->_autocorrectionData.textLastRect = lastRect;
- view->_autocorrectionData.autocorrectionHandler(rects.size() ? [WKAutocorrectionRects autocorrectionRectsWithRects:firstRect lastRect:lastRect] : nil);
- [view->_autocorrectionData.autocorrectionHandler release];
- view->_autocorrectionData.autocorrectionHandler = nil;
+ if (completion)
+ completion(rects.size() ? [WKAutocorrectionRects autocorrectionRectsWithRects:firstRect lastRect:lastRect] : nil);
});
}
@@ -3381,15 +3379,14 @@
const bool useSyncRequest = true;
if (useSyncRequest) {
- completionHandler(_page->applyAutocorrection(correction, input) ? [WKAutocorrectionRects autocorrectionRectsWithRects:_autocorrectionData.textFirstRect lastRect:_autocorrectionData.textLastRect] : nil);
+ if (completionHandler)
+ completionHandler(_page->applyAutocorrection(correction, input) ? [WKAutocorrectionRects autocorrectionRectsWithRects:_autocorrectionData.textFirstRect lastRect:_autocorrectionData.textLastRect] : nil);
return;
}
- _autocorrectionData.autocorrectionHandler = [completionHandler copy];
- RetainPtr<WKContentView> view = self;
- _page->applyAutocorrection(correction, input, [view](const String& string, WebKit::CallbackBase::Error error) {
- view->_autocorrectionData.autocorrectionHandler(!string.isNull() ? [WKAutocorrectionRects autocorrectionRectsWithRects:view->_autocorrectionData.textFirstRect lastRect:view->_autocorrectionData.textLastRect] : nil);
- [view->_autocorrectionData.autocorrectionHandler release];
- view->_autocorrectionData.autocorrectionHandler = nil;
+
+ _page->applyAutocorrection(correction, input, [view = retainPtr(self), completion = makeBlockPtr(completionHandler)](auto& string, auto error) {
+ if (completion)
+ completion(!string.isNull() ? [WKAutocorrectionRects autocorrectionRectsWithRects:view->_autocorrectionData.textFirstRect lastRect:view->_autocorrectionData.textLastRect] : nil);
});
}
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (241179 => 241180)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2019-02-08 01:30:19 UTC (rev 241179)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2019-02-08 01:45:42 UTC (rev 241180)
@@ -646,7 +646,7 @@
void replaceSelectedText(const String& oldText, const String& newText);
void requestAutocorrectionData(const String& textForAutocorrection, CallbackID);
void applyAutocorrection(const String& correction, const String& originalText, CallbackID);
- void syncApplyAutocorrection(const String& correction, const String& originalText, bool& correctionApplied);
+ void syncApplyAutocorrection(const String& correction, const String& originalText, CompletionHandler<void(bool)>&&);
void requestAutocorrectionContext(CallbackID);
void autocorrectionContextSync(CompletionHandler<void(WebAutocorrectionContext&&)>&&);
void getPositionInformation(const InteractionInformationRequest&, CompletionHandler<void(InteractionInformationAtPosition&&)>&&);
@@ -1191,6 +1191,7 @@
void sendPositionInformation(InteractionInformationAtPosition&&);
InteractionInformationAtPosition positionInformation(const InteractionInformationRequest&);
WebAutocorrectionContext autocorrectionContext();
+ bool applyAutocorrectionInternal(const String& correction, const String& originalText);
#endif
#if PLATFORM(IOS_FAMILY) && ENABLE(DATA_INTERACTION)
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (241179 => 241180)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in 2019-02-08 01:30:19 UTC (rev 241179)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in 2019-02-08 01:45:42 UTC (rev 241180)
@@ -77,7 +77,7 @@
ReplaceSelectedText(String oldText, String newText)
RequestAutocorrectionData(String textForAutocorrection, WebKit::CallbackID callbackID)
ApplyAutocorrection(String correction, String originalText, WebKit::CallbackID callbackID)
- SyncApplyAutocorrection(String correction, String originalText) -> (bool autocorrectionApplied) LegacySync
+ SyncApplyAutocorrection(String correction, String originalText) -> (bool autocorrectionApplied) Delayed
RequestAutocorrectionContext(WebKit::CallbackID callbackID)
AutocorrectionContextSync() -> (struct WebKit::WebAutocorrectionContext context) Delayed
GetPositionInformation(struct WebKit::InteractionInformationRequest request) -> (struct WebKit::InteractionInformationAtPosition information) Delayed
Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (241179 => 241180)
--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2019-02-08 01:30:19 UTC (rev 241179)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2019-02-08 01:45:42 UTC (rev 241180)
@@ -1889,9 +1889,7 @@
void WebPage::applyAutocorrection(const String& correction, const String& originalText, CallbackID callbackID)
{
- bool correctionApplied;
- syncApplyAutocorrection(correction, originalText, correctionApplied);
- send(Messages::WebPageProxy::StringCallback(correctionApplied ? correction : String(), callbackID));
+ send(Messages::WebPageProxy::StringCallback(applyAutocorrectionInternal(correction, originalText) ? correction : String(), callbackID));
}
Seconds WebPage::eventThrottlingDelay() const
@@ -1912,13 +1910,16 @@
return std::min(m_estimatedLatency * 2, 1_s);
}
-void WebPage::syncApplyAutocorrection(const String& correction, const String& originalText, bool& correctionApplied)
+void WebPage::syncApplyAutocorrection(const String& correction, const String& originalText, CompletionHandler<void(bool)>&& reply)
{
- correctionApplied = false;
+ reply(applyAutocorrectionInternal(correction, originalText));
+}
- Frame& frame = m_page->focusController().focusedOrMainFrame();
+bool WebPage::applyAutocorrectionInternal(const String& correction, const String& originalText)
+{
+ auto& frame = m_page->focusController().focusedOrMainFrame();
if (!frame.selection().isCaretOrRange())
- return;
+ return false;
RefPtr<Range> range;
String textForRange;
@@ -1951,17 +1952,14 @@
} else {
// Range selection.
range = frame.selection().toNormalizedRange();
- if (!range) {
- correctionApplied = false;
- return;
- }
+ if (!range)
+ return false;
+
textForRange = plainTextReplacingNoBreakSpace(range.get());
}
- if (textForRange != originalText) {
- correctionApplied = false;
- return;
- }
+ if (textForRange != originalText)
+ return false;
// Correctly determine affinity, using logic currently only present in VisiblePosition
EAffinity affinity = DOWNSTREAM;
@@ -1973,7 +1971,7 @@
frame.editor().insertText(correction, 0, originalText.isEmpty() ? TextEventInputKeyboard : TextEventInputAutocompletion);
else
frame.editor().deleteWithDirection(DirectionBackward, CharacterGranularity, false, true);
- correctionApplied = true;
+ return true;
}
WebAutocorrectionContext WebPage::autocorrectionContext()