Changeset 244473 in webkit
- Timestamp:
- Apr 19, 2019 4:48:41 PM (5 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r244472 r244473 1 2019-04-19 Daniel Bates <dabates@apple.com> 2 3 -[WKAutocorrectionContext emptyAutocorrectionContext:] generates invalid empty context 4 https://bugs.webkit.org/show_bug.cgi?id=197119 5 6 Reviewed by Wenson Hsieh. 7 8 Use the existing EditingRange type to represent the location and length of the marked text 9 range for an autocorrection instead of managing integers. This type avoid the need to handle 10 the special case for an empty range represented as NSMakeRange(NSNotFound, 0). Currently 11 WKAutocorrectionContext incorrectly represents the empty range as NSMakeRange(WTF::notFound, 0). 12 13 While I am here, simplify the existing WebAutocorrectionContext encoder/decoder code and rename 14 +[WKAutocorrectionContext autocorrectionContextWithContext:] to +autocorrectionContextWithWebContext 15 to better reflect the expected source of the conversion: a Web-type. 16 17 * Shared/ios/WebAutocorrectionContext.h: 18 (WebKit::WebAutocorrectionContext::encode const): Reformat while I am here to make this logic easy 19 to amend without losing SVN history. 20 (WebKit::WebAutocorrectionContext::decode): Simplify the code while I am here. 21 * UIProcess/ios/WKContentViewInteraction.mm: 22 (-[WKContentView _handleAutocorrectionContext:]): Update for renaming. 23 (+[WKAutocorrectionContext emptyAutocorrectionContext]): Update for renaming. 24 (+[WKAutocorrectionContext autocorrectionContextWithWebContext:]): Renamed; formerly named autocorrectionContextWithContext. 25 (+[WKAutocorrectionContext autocorrectionContextWithContext:]): Deleted. 26 * WebProcess/WebPage/ios/WebPageIOS.mm: 27 (WebKit::WebPage::autocorrectionContext): Update to make use of EditingRange. Also instantiate 28 the struct and return it, initializing its fields individually instead of using the constructor to 29 make this code less error prone. It's easy to introduce an error with the constructor notation when 30 amending the the struct because so many of the arguments are of the same data type. Individually 31 initializing the struct fields makes it less likely for an ordering mistake to be introduced. 32 1 33 2019-04-19 Dean Jackson <dino@apple.com> 2 34 -
trunk/Source/WebKit/Shared/ios/WebAutocorrectionContext.h
r241146 r244473 27 27 28 28 #include "Decoder.h" 29 #include "EditingRange.h" 29 30 #include "Encoder.h" 30 #include <wtf/NotFound.h>31 31 #include <wtf/Optional.h> 32 32 #include <wtf/text/WTFString.h> … … 39 39 String selectedText; 40 40 String contextAfter; 41 uint64_t location { notFound }; 42 uint64_t length { 0 }; 41 EditingRange markedTextRange; 43 42 44 43 template<class Encoder> void encode(Encoder&) const; … … 46 45 }; 47 46 48 template<class Encoder> inlinevoid WebAutocorrectionContext::encode(Encoder& encoder) const47 template<class Encoder> void WebAutocorrectionContext::encode(Encoder& encoder) const 49 48 { 50 encoder << contextBefore << markedText << selectedText << contextAfter << location << length; 49 encoder << contextBefore; 50 encoder << markedText; 51 encoder << selectedText; 52 encoder << contextAfter; 53 encoder << markedTextRange; 51 54 } 52 55 53 template<class Decoder> inlineOptional<WebAutocorrectionContext> WebAutocorrectionContext::decode(Decoder& decoder)56 template<class Decoder> Optional<WebAutocorrectionContext> WebAutocorrectionContext::decode(Decoder& decoder) 54 57 { 55 Optional<String> contextBefore; 56 decoder >> contextBefore; 57 if (!contextBefore) 58 WebAutocorrectionContext correction; 59 if (!decoder.decode(correction.contextBefore)) 58 60 return WTF::nullopt; 59 60 Optional<String> markedText; 61 decoder >> markedText; 62 if (!markedText) 61 if (!decoder.decode(correction.markedText)) 63 62 return WTF::nullopt; 64 65 Optional<String> selectedText; 66 decoder >> selectedText; 67 if (!selectedText) 63 if (!decoder.decode(correction.selectedText)) 68 64 return WTF::nullopt; 69 70 Optional<String> contextAfter; 71 decoder >> contextAfter; 72 if (!contextAfter) 65 if (!decoder.decode(correction.contextAfter)) 73 66 return WTF::nullopt; 74 75 Optional<uint64_t> location; 76 decoder >> location; 77 if (!location) 67 if (!decoder.decode(correction.markedTextRange)) 78 68 return WTF::nullopt; 79 80 Optional<uint64_t> length; 81 decoder >> length; 82 if (!length) 83 return WTF::nullopt; 84 85 return {{ WTFMove(*contextBefore), WTFMove(*markedText), WTFMove(*selectedText), WTFMove(*contextAfter), WTFMove(*location), WTFMove(*length) }}; 69 return correction; 86 70 } 87 71 -
trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
r244471 r244473 291 291 @interface WKAutocorrectionContext : UIWKAutocorrectionContext 292 292 + (WKAutocorrectionContext *)emptyAutocorrectionContext; 293 + (WKAutocorrectionContext *)autocorrectionContextWith Context:(const WebKit::WebAutocorrectionContext&)context;293 + (WKAutocorrectionContext *)autocorrectionContextWithWebContext:(const WebKit::WebAutocorrectionContext&)context; 294 294 @end 295 295 … … 3719 3719 - (void)_handleAutocorrectionContext:(const WebKit::WebAutocorrectionContext&)context 3720 3720 { 3721 [self _invokePendingAutocorrectionContextHandler:[WKAutocorrectionContext autocorrectionContextWith Context:context]];3721 [self _invokePendingAutocorrectionContextHandler:[WKAutocorrectionContext autocorrectionContextWithWebContext:context]]; 3722 3722 } 3723 3723 … … 7687 7687 + (WKAutocorrectionContext *)emptyAutocorrectionContext 7688 7688 { 7689 return [self autocorrectionContextWithContext:WebKit::WebAutocorrectionContext { }]; 7690 } 7691 7692 + (WKAutocorrectionContext *)autocorrectionContextWithContext:(const WebKit::WebAutocorrectionContext&)webContext 7693 { 7694 WKAutocorrectionContext *context = [[WKAutocorrectionContext alloc] init]; 7695 7696 if (!webContext.contextBefore.isEmpty()) 7697 context.contextBeforeSelection = webContext.contextBefore; 7698 if (!webContext.selectedText.isEmpty()) 7699 context.selectedText = webContext.selectedText; 7700 if (!webContext.markedText.isEmpty()) 7701 context.markedText = webContext.markedText; 7702 if (!webContext.contextAfter.isEmpty()) 7703 context.contextAfterSelection = webContext.contextAfter; 7704 context.rangeInMarkedText = NSMakeRange(webContext.location, webContext.length); 7705 return [context autorelease]; 7689 return [self autocorrectionContextWithWebContext:WebKit::WebAutocorrectionContext { }]; 7690 } 7691 7692 + (WKAutocorrectionContext *)autocorrectionContextWithWebContext:(const WebKit::WebAutocorrectionContext&)webCorrection 7693 { 7694 auto correction = adoptNS([[WKAutocorrectionContext alloc] init]); 7695 [correction setContextBeforeSelection:nsStringNilIfEmpty(webCorrection.contextBefore)]; 7696 [correction setSelectedText:nsStringNilIfEmpty(webCorrection.selectedText)]; 7697 [correction setMarkedText:nsStringNilIfEmpty(webCorrection.markedText)]; 7698 [correction setContextAfterSelection:nsStringNilIfEmpty(webCorrection.contextAfter)]; 7699 [correction setRangeInMarkedText:webCorrection.markedTextRange]; 7700 return correction.autorelease(); 7706 7701 } 7707 7702 -
trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
r244457 r244473 2181 2181 String selectedText; 2182 2182 String contextAfter; 2183 uint64_t location = NSNotFound; 2184 uint64_t length = 0; 2183 EditingRange markedTextRange; 2185 2184 2186 2185 auto& frame = m_page->focusController().focusedOrMainFrame(); … … 2206 2205 markedText = markedTextBefore + selectedText + markedTextAfter; 2207 2206 if (!markedText.isEmpty()) { 2208 location = markedTextBefore.length();2209 length = selectedText.length();2207 markedTextRange.location = markedTextBefore.length(); 2208 markedTextRange.length = selectedText.length(); 2210 2209 } 2211 2210 } else { … … 2241 2240 } 2242 2241 } 2243 return { WTFMove(contextBefore), WTFMove(markedText), WTFMove(selectedText), WTFMove(contextAfter), location, length }; 2242 2243 WebAutocorrectionContext correction; 2244 correction.contextBefore = WTFMove(contextBefore); 2245 correction.markedText = WTFMove(markedText); 2246 correction.selectedText = WTFMove(selectedText); 2247 correction.contextAfter = WTFMove(contextAfter); 2248 correction.markedTextRange = WTFMove(markedTextRange); 2249 return correction; 2244 2250 } 2245 2251
Note: See TracChangeset
for help on using the changeset viewer.