Changeset 241180 in webkit
- Timestamp:
- Feb 7, 2019 5:45:42 PM (5 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r241171 r241180 1 2019-02-07 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [iOS] [WK2] Modernize code for applying autocorrection 4 https://bugs.webkit.org/show_bug.cgi?id=194397 5 6 Reviewed by Tim Horton. 7 8 * UIProcess/ios/WKContentViewInteraction.h: 9 * UIProcess/ios/WKContentViewInteraction.mm: 10 (-[WKContentView requestAutocorrectionRectsForString:withCompletionHandler:]): 11 (-[WKContentView applyAutocorrection:toString:withCompletionHandler:]): 12 13 Use BlockPtr instead of temporarily storing the completion handler. 14 15 * WebProcess/WebPage/WebPage.h: 16 * WebProcess/WebPage/WebPage.messages.in: 17 18 Change a LegacySync to Delayed. 19 20 * WebProcess/WebPage/ios/WebPageIOS.mm: 21 (WebKit::WebPage::applyAutocorrection): 22 (WebKit::WebPage::syncApplyAutocorrection): 23 (WebKit::WebPage::applyAutocorrectionInternal): 24 1 25 2019-02-07 Wenson Hsieh <wenson_hsieh@apple.com> 2 26 -
trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
r241146 r241180 176 176 CGRect textFirstRect; 177 177 CGRect textLastRect; 178 UIWKAutocorrectionCompletionHandler autocorrectionHandler;179 178 }; 180 179 -
trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
r241171 r241180 3218 3218 { 3219 3219 if (!input || ![input length]) { 3220 completionHandler(nil); 3221 return; 3222 } 3223 3224 RetainPtr<WKContentView> view = self; 3225 _autocorrectionData.autocorrectionHandler = [completionHandler copy]; 3226 _page->requestAutocorrectionData(input, [view](const Vector<WebCore::FloatRect>& rects, const String& fontName, double fontSize, uint64_t traits, WebKit::CallbackBase::Error) { 3220 if (completionHandler) 3221 completionHandler(nil); 3222 return; 3223 } 3224 3225 _page->requestAutocorrectionData(input, [view = retainPtr(self), completion = makeBlockPtr(completionHandler)](auto& rects, auto& fontName, double fontSize, uint64_t traits, auto) { 3227 3226 CGRect firstRect = CGRectZero; 3228 3227 CGRect lastRect = CGRectZero; … … 3238 3237 view->_autocorrectionData.textLastRect = lastRect; 3239 3238 3240 view->_autocorrectionData.autocorrectionHandler(rects.size() ? [WKAutocorrectionRects autocorrectionRectsWithRects:firstRect lastRect:lastRect] : nil); 3241 [view->_autocorrectionData.autocorrectionHandler release]; 3242 view->_autocorrectionData.autocorrectionHandler = nil; 3239 if (completion) 3240 completion(rects.size() ? [WKAutocorrectionRects autocorrectionRectsWithRects:firstRect lastRect:lastRect] : nil); 3243 3241 }); 3244 3242 } … … 3382 3380 3383 3381 if (useSyncRequest) { 3384 completionHandler(_page->applyAutocorrection(correction, input) ? [WKAutocorrectionRects autocorrectionRectsWithRects:_autocorrectionData.textFirstRect lastRect:_autocorrectionData.textLastRect] : nil); 3385 return; 3386 } 3387 _autocorrectionData.autocorrectionHandler = [completionHandler copy]; 3388 RetainPtr<WKContentView> view = self; 3389 _page->applyAutocorrection(correction, input, [view](const String& string, WebKit::CallbackBase::Error error) { 3390 view->_autocorrectionData.autocorrectionHandler(!string.isNull() ? [WKAutocorrectionRects autocorrectionRectsWithRects:view->_autocorrectionData.textFirstRect lastRect:view->_autocorrectionData.textLastRect] : nil); 3391 [view->_autocorrectionData.autocorrectionHandler release]; 3392 view->_autocorrectionData.autocorrectionHandler = nil; 3382 if (completionHandler) 3383 completionHandler(_page->applyAutocorrection(correction, input) ? [WKAutocorrectionRects autocorrectionRectsWithRects:_autocorrectionData.textFirstRect lastRect:_autocorrectionData.textLastRect] : nil); 3384 return; 3385 } 3386 3387 _page->applyAutocorrection(correction, input, [view = retainPtr(self), completion = makeBlockPtr(completionHandler)](auto& string, auto error) { 3388 if (completion) 3389 completion(!string.isNull() ? [WKAutocorrectionRects autocorrectionRectsWithRects:view->_autocorrectionData.textFirstRect lastRect:view->_autocorrectionData.textLastRect] : nil); 3393 3390 }); 3394 3391 } -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.h
r241146 r241180 647 647 void requestAutocorrectionData(const String& textForAutocorrection, CallbackID); 648 648 void applyAutocorrection(const String& correction, const String& originalText, CallbackID); 649 void syncApplyAutocorrection(const String& correction, const String& originalText, bool& correctionApplied);649 void syncApplyAutocorrection(const String& correction, const String& originalText, CompletionHandler<void(bool)>&&); 650 650 void requestAutocorrectionContext(CallbackID); 651 651 void autocorrectionContextSync(CompletionHandler<void(WebAutocorrectionContext&&)>&&); … … 1192 1192 InteractionInformationAtPosition positionInformation(const InteractionInformationRequest&); 1193 1193 WebAutocorrectionContext autocorrectionContext(); 1194 bool applyAutocorrectionInternal(const String& correction, const String& originalText); 1194 1195 #endif 1195 1196 -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in
r241146 r241180 78 78 RequestAutocorrectionData(String textForAutocorrection, WebKit::CallbackID callbackID) 79 79 ApplyAutocorrection(String correction, String originalText, WebKit::CallbackID callbackID) 80 SyncApplyAutocorrection(String correction, String originalText) -> (bool autocorrectionApplied) LegacySync80 SyncApplyAutocorrection(String correction, String originalText) -> (bool autocorrectionApplied) Delayed 81 81 RequestAutocorrectionContext(WebKit::CallbackID callbackID) 82 82 AutocorrectionContextSync() -> (struct WebKit::WebAutocorrectionContext context) Delayed -
trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
r241146 r241180 1890 1890 void WebPage::applyAutocorrection(const String& correction, const String& originalText, CallbackID callbackID) 1891 1891 { 1892 bool correctionApplied; 1893 syncApplyAutocorrection(correction, originalText, correctionApplied); 1894 send(Messages::WebPageProxy::StringCallback(correctionApplied ? correction : String(), callbackID)); 1892 send(Messages::WebPageProxy::StringCallback(applyAutocorrectionInternal(correction, originalText) ? correction : String(), callbackID)); 1895 1893 } 1896 1894 … … 1913 1911 } 1914 1912 1915 void WebPage::syncApplyAutocorrection(const String& correction, const String& originalText, bool& correctionApplied) 1916 { 1917 correctionApplied = false; 1918 1919 Frame& frame = m_page->focusController().focusedOrMainFrame(); 1913 void WebPage::syncApplyAutocorrection(const String& correction, const String& originalText, CompletionHandler<void(bool)>&& reply) 1914 { 1915 reply(applyAutocorrectionInternal(correction, originalText)); 1916 } 1917 1918 bool WebPage::applyAutocorrectionInternal(const String& correction, const String& originalText) 1919 { 1920 auto& frame = m_page->focusController().focusedOrMainFrame(); 1920 1921 if (!frame.selection().isCaretOrRange()) 1921 return ;1922 return false; 1922 1923 1923 1924 RefPtr<Range> range; … … 1952 1953 // Range selection. 1953 1954 range = frame.selection().toNormalizedRange(); 1954 if (!range) { 1955 correctionApplied = false; 1956 return; 1957 } 1955 if (!range) 1956 return false; 1957 1958 1958 textForRange = plainTextReplacingNoBreakSpace(range.get()); 1959 1959 } 1960 1960 1961 if (textForRange != originalText) { 1962 correctionApplied = false; 1963 return; 1964 } 1961 if (textForRange != originalText) 1962 return false; 1965 1963 1966 1964 // Correctly determine affinity, using logic currently only present in VisiblePosition … … 1974 1972 else 1975 1973 frame.editor().deleteWithDirection(DirectionBackward, CharacterGranularity, false, true); 1976 correctionApplied =true;1974 return true; 1977 1975 } 1978 1976
Note: See TracChangeset
for help on using the changeset viewer.