WebKit Bugzilla
Attachment 361409 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]
Patch
bug-194397-20190207101146.patch (text/plain), 10.91 KB, created by
Wenson Hsieh
on 2019-02-07 10:11:47 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Wenson Hsieh
Created:
2019-02-07 10:11:47 PST
Size:
10.91 KB
patch
obsolete
>Subversion Revision: 241111 >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index d46b2721039142fd78bb1a5474b43309beb309fe..2d14a68234924eb33223ac70cecf4c24e1c286b5 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 NOBODY (OOPS!). >+ >+ * 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] [WK2] Modernize autocorrection context code >diff --git a/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h b/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h >index 842107cb9aaa18cdd68a8bb8b1bb2f4cefaa90bd..587194d7c1a453b4e314065fa9a4569c3a4c38a4 100644 >--- a/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h >+++ b/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h >@@ -176,7 +176,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 3f62ab6729bfa01d7b90aece7cc3cf39965143a0..1db731f34b8a8b869bbc76d59f49cd826f28a831 100644 >--- a/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm >+++ b/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm >@@ -3259,13 +3259,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()) { >@@ -3279,9 +3278,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); > }); > } > >@@ -3423,15 +3421,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 d63f2329c8251eecf27707a7affb2a5b28d98bef..6649314683a32a4f7714dae7a7fed0ecb5c7eb09 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 getAutocorrectionContext(CompletionHandler<void(WebAutocorrectionContext&&)>&&); > void getPositionInformation(const InteractionInformationRequest&, CompletionHandler<void(InteractionInformationAtPosition&&)>&&); >@@ -1193,6 +1193,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 03f1ab4157a91a2b2a13457413444ff19f3cbb04..ebd08f5a99710878f9808e78ce01b41a1813463a 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) > GetAutocorrectionContext() -> (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 aec4e931cc0fdab9a2eb07a2646dfc74e5221f74..ff28c9f7de0e87fa799096a416a713f4f46673d2 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
Flags:
thorton
:
review+
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 194397
: 361409 |
361459