Changeset 282247 in webkit
- Timestamp:
- Sep 9, 2021, 5:15:44 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (modified) (2 diffs)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/ios/AutocorrectionTestsIOS.mm (modified) (3 diffs)
-
Tools/TestWebKitAPI/ios/UIKitSPI.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r282236 r282247 1 2021-09-09 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [Mac Catalyst] Korean characters do not combine correctly in editable fields in WKWebView 4 https://bugs.webkit.org/show_bug.cgi?id=230122 5 rdar://79062204 6 7 Reviewed by Devin Rousso. 8 9 When using Korean input method (e.g. 2-set Korean) to type into editable input fields in WKWebView on Catalyst, 10 character combination is broken. While this is partly due to a WebKit-specific UIKit bug (see rdar://82938391), 11 this is also broken due to the fact that WKContentView reports a UIWKAutocorrectionContext with a 12 `contextBeforeSelection` that starts with a newline (\n); this causes UIKit to believe that the text selection 13 range when a single character has been typed is `NSRange { 2, 0 }` instead of `NSRange { 1, 0 }`, due to the 14 extra newline. This subsequently causes character combination logic to proceed with a range that is off by one 15 character, which leads to characters not being combined (or the wrong characters being combined). 16 17 To address this, we simply avoid including the leading newline in the case where the starting position for the 18 "context before selection" is exactly at the first position inside the editable root. 19 20 Test: AutocorrectionTests.AutocorrectionContextDoesNotIncludeNewlineInTextField 21 22 * WebProcess/WebPage/ios/WebPageIOS.mm: 23 (WebKit::WebPage::autocorrectionContext): 24 25 Also drive-by fix a typo in "minContextLenght" while I'm here, and rename `currentPosition` to 26 `contextStartPosition`, to better describe the purpose of this local variable. 27 1 28 2021-09-09 Fujii Hironori <Hironori.Fujii@sony.com> 2 29 -
trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
r282191 r282247 2501 2501 VisiblePosition endPosition = frame->selection().selection().end(); 2502 2502 const unsigned minContextWordCount = 3; 2503 const unsigned minContextLeng ht= 12;2503 const unsigned minContextLength = 12; 2504 2504 const unsigned maxContextLength = 30; 2505 2505 … … 2516 2516 } 2517 2517 } else { 2518 if (startPosition != startOfEditableContent(startPosition)) { 2519 VisiblePosition currentPosition = startPosition; 2518 auto firstPositionInEditableContent = startOfEditableContent(startPosition); 2519 if (startPosition != firstPositionInEditableContent) { 2520 VisiblePosition contextStartPosition = startPosition; 2520 2521 VisiblePosition previousPosition; 2521 2522 unsigned totalContextLength = 0; 2522 2523 for (unsigned i = 0; i < minContextWordCount; ++i) { 2523 if (contextBefore.length() >= minContextLeng ht)2524 if (contextBefore.length() >= minContextLength) 2524 2525 break; 2525 previousPosition = startOfWord(positionOfNextBoundaryOfGranularity(c urrentPosition, TextGranularity::WordGranularity, SelectionDirection::Backward));2526 previousPosition = startOfWord(positionOfNextBoundaryOfGranularity(contextStartPosition, TextGranularity::WordGranularity, SelectionDirection::Backward)); 2526 2527 if (previousPosition.isNull()) 2527 2528 break; 2528 String currentWord = plainTextForContext(makeSimpleRange(previousPosition, c urrentPosition));2529 String currentWord = plainTextForContext(makeSimpleRange(previousPosition, contextStartPosition)); 2529 2530 totalContextLength += currentWord.length(); 2530 2531 if (totalContextLength >= maxContextLength) 2531 2532 break; 2532 c urrentPosition = previousPosition;2533 contextStartPosition = previousPosition; 2533 2534 } 2534 if (c urrentPosition.isNotNull() && currentPosition != startPosition) {2535 contextBefore = plainTextForContext(makeSimpleRange(c urrentPosition, startPosition));2536 if (atBoundaryOfGranularity(c urrentPosition, TextGranularity::ParagraphGranularity, SelectionDirection::Backward))2535 if (contextStartPosition.isNotNull() && contextStartPosition != startPosition) { 2536 contextBefore = plainTextForContext(makeSimpleRange(contextStartPosition, startPosition)); 2537 if (atBoundaryOfGranularity(contextStartPosition, TextGranularity::ParagraphGranularity, SelectionDirection::Backward) && firstPositionInEditableContent != contextStartPosition) 2537 2538 contextBefore = makeString("\n "_s, contextBefore); 2538 2539 } -
trunk/Tools/ChangeLog
r282218 r282247 1 2021-09-09 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [Mac Catalyst] Korean characters do not combine correctly in editable fields in WKWebView 4 https://bugs.webkit.org/show_bug.cgi?id=230122 5 rdar://79062204 6 7 Reviewed by Devin Rousso. 8 9 Add a new API test to exercise the change. See WebKit/ChangeLog for more information. 10 11 * TestWebKitAPI/Tests/ios/AutocorrectionTestsIOS.mm: 12 (-[TestWKWebView synchronouslyRequestAutocorrectionContext]): 13 (TEST): 14 * TestWebKitAPI/ios/UIKitSPI.h: 15 1 16 2021-09-09 Chris Dumez <cdumez@apple.com> 2 17 -
trunk/Tools/TestWebKitAPI/Tests/ios/AutocorrectionTestsIOS.mm
r260367 r282247 37 37 @interface TestWKWebView (AutocorrectionTests) 38 38 - (UIWKAutocorrectionRects *)autocorrectionRectsForString:(NSString *)string; 39 - (UIWKAutocorrectionContext *)synchronouslyRequestAutocorrectionContext; 39 40 @end 40 41 … … 47 48 [self.textInputContentView requestAutocorrectionRectsForString:string withCompletionHandler:[&] (UIWKAutocorrectionRects *rects) { 48 49 result = rects; 50 done = true; 51 }]; 52 TestWebKitAPI::Util::run(&done); 53 return result.autorelease(); 54 } 55 56 - (UIWKAutocorrectionContext *)synchronouslyRequestAutocorrectionContext 57 { 58 RetainPtr<UIWKAutocorrectionContext> result; 59 bool done = false; 60 [self.textInputContentView requestAutocorrectionContextWithCompletionHandler:[&] (UIWKAutocorrectionContext *context) { 61 result = context; 49 62 done = true; 50 63 }]; … … 105 118 [webView _close]; 106 119 107 bool done = false; 108 [contentView requestAutocorrectionContextWithCompletionHandler:[&] (UIWKAutocorrectionContext *) { 109 done = true; 110 }]; 111 TestWebKitAPI::Util::run(&done); 120 // This test just verifies that attempting to request an autocorrection context in this state 121 // does not trigger a crash or hang, and also still invokes the given completion handler. 122 [webView synchronouslyRequestAutocorrectionContext]; 123 } 124 125 TEST(AutocorrectionTests, AutocorrectionContextDoesNotIncludeNewlineInTextField) 126 { 127 auto webView = adoptNS([[TestWKWebView alloc] init]); 128 [webView synchronouslyLoadTestPageNamed:@"autofocused-text-input"]; 129 130 RetainPtr contextBeforeTyping = [webView synchronouslyRequestAutocorrectionContext]; 131 EXPECT_EQ(0U, [contextBeforeTyping contextBeforeSelection].length); 132 EXPECT_EQ(0U, [contextBeforeTyping selectedText].length); 133 EXPECT_EQ(0U, [contextBeforeTyping contextAfterSelection].length); 134 135 [[webView textInputContentView] insertText:@"a"]; 136 [webView waitForNextPresentationUpdate]; 137 138 RetainPtr contextAfterTyping = [webView synchronouslyRequestAutocorrectionContext]; 139 EXPECT_WK_STREQ(@"a", [contextAfterTyping contextBeforeSelection]); 140 EXPECT_EQ(0U, [contextAfterTyping selectedText].length); 141 EXPECT_EQ(0U, [contextAfterTyping contextAfterSelection].length); 112 142 } 113 143 -
trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h
r281468 r282247 184 184 185 185 @interface UIWKAutocorrectionContext : NSObject 186 @property (nonatomic, copy) NSString *contextBeforeSelection; 187 @property (nonatomic, copy) NSString *selectedText; 188 @property (nonatomic, copy) NSString *contextAfterSelection; 186 189 @end 187 190
Note:
See TracChangeset
for help on using the changeset viewer.