WebKit Bugzilla
Attachment 361459 Details for
Bug 194397
: [iOS] [WK2] Modernize code for applying autocorrection
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Rebase on trunk
bug-194397-20190207151304.patch (text/plain), 10.95 KB, created by
Wenson Hsieh
on 2019-02-07 15:13:05 PST
(
hide
)
Description:
Rebase on trunk
Filename:
MIME Type:
Creator:
Wenson Hsieh
Created:
2019-02-07 15:13:05 PST
Size:
10.95 KB
patch
obsolete
>Subversion Revision: 241040 >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index f3ef47a15a0f7b01d48af0831e49aca74e3d804f..bc9a5e512803857a1dfa373d76dee01737240f0f 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,27 @@ >+2019-02-07 Wenson Hsieh <wenson_hsieh@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_hsieh@apple.com> > > [iOS] Clicking links in Safari using Apple Pencil is much more difficult after r238475 >diff --git a/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h b/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h >index dc0d173c42363b20100a73ba65b9f3c8b6a65fc1..44c6bf7d7e009ec69a0cd6b6f94907aa2f7f89aa 100644 >--- a/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h >+++ b/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h >@@ -175,7 +175,6 @@ struct WKAutoCorrectionData { > uint64_t fontTraits; > CGRect textFirstRect; > CGRect textLastRect; >- UIWKAutocorrectionCompletionHandler autocorrectionHandler; > }; > > } >diff --git a/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm b/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm >index a4e7fc1c3e77672af31ce1af35e3d9ad39e127ed..680366457607e402d4fdcd47964f84ed72d54465 100644 >--- a/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm >+++ b/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm >@@ -3217,13 +3217,12 @@ - (const WebKit::WKAutoCorrectionData&)autocorrectionData > - (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 @@ - (void)requestAutocorrectionRectsForString:(NSString *)input withCompletionHand > 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 @@ - (void)applyAutocorrection:(NSString *)correction toString:(NSString *)input wi > 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); > }); > } > >diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.h b/Source/WebKit/WebProcess/WebPage/WebPage.h >index 63067fc2ba34804d1bae6cd91f1a67012f0b312f..6062ad88bc9c13cc1fcc60bd7225452bafd5e222 100644 >--- a/Source/WebKit/WebProcess/WebPage/WebPage.h >+++ b/Source/WebKit/WebProcess/WebPage/WebPage.h >@@ -646,7 +646,7 @@ public: > 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 @@ private: > 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) >diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.messages.in b/Source/WebKit/WebProcess/WebPage/WebPage.messages.in >index edd293e65778e5b69986e34757a8e8e6d3197cbc..a8c61769e5e74d214e8cef0a64158478b2301cea 100644 >--- a/Source/WebKit/WebProcess/WebPage/WebPage.messages.in >+++ b/Source/WebKit/WebProcess/WebPage/WebPage.messages.in >@@ -77,7 +77,7 @@ messages -> WebPage LegacyReceiver { > 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 >diff --git a/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm b/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm >index 917cfe3835d51fc1903dd32f4fec33a51dedd44f..7eb71ae912a93500b35893830b6e24a0636cd7ef 100644 >--- a/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm >+++ b/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm >@@ -1889,9 +1889,7 @@ void WebPage::requestAutocorrectionData(const String& textForAutocorrection, Cal > > 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 @@ Seconds WebPage::eventThrottlingDelay() const > 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 @@ void WebPage::syncApplyAutocorrection(const String& correction, const String& or > } 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 @@ void WebPage::syncApplyAutocorrection(const String& correction, const String& or > frame.editor().insertText(correction, 0, originalText.isEmpty() ? TextEventInputKeyboard : TextEventInputAutocompletion); > else > frame.editor().deleteWithDirection(DirectionBackward, CharacterGranularity, false, true); >- correctionApplied = true; >+ return true; > } > > WebAutocorrectionContext WebPage::autocorrectionContext()
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 194397
:
361409
| 361459