Changeset 241614 in webkit
- Timestamp:
- Feb 15, 2019 1:35:52 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r241611 r241614 1 2019-02-15 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [iOS] WKWebView callout bar is missing Change Writing Direction item 4 https://bugs.webkit.org/show_bug.cgi?id=190015 5 <rdar://problem/44810366> 6 7 Reviewed by Tim Horton. 8 9 Support -makeTextWritingDirectionLeftToRight: and -makeTextWritingDirectionRightToLeft: in WKWebView on iOS. 10 To match behavior in native UITextViews on iOS, we implement these methods by changing the *base* writing 11 direction, rather than the text writing direction (this is in contrast to macOS, which has different 12 NSResponder methods for changing the base writing direction as opposed to the text writing direction). 13 14 Additionally fixes the implementation of -makeTextWritingDirectionNatural:, which currently attempts to change 15 the text writing direction instead of the base writing direction. 16 17 * Platform/spi/ios/UIKitSPI.h: 18 19 Add a forward declaration for keyboards SPI to determine whether the user has an active RTL keyboard. 20 21 * Shared/EditorState.cpp: 22 (WebKit::EditorState::PostLayoutData::encode const): 23 (WebKit::EditorState::PostLayoutData::decode): 24 (WebKit::operator<<): 25 * Shared/EditorState.h: 26 27 Plumb the base writing direction to the UI process through EditorState. 28 29 * UIProcess/ios/WKContentViewInteraction.h: 30 * UIProcess/ios/WKContentViewInteraction.mm: 31 (-[WKContentView makeTextWritingDirectionNaturalForWebView:]): 32 (-[WKContentView makeTextWritingDirectionLeftToRightForWebView:]): 33 (-[WKContentView makeTextWritingDirectionRightToLeftForWebView:]): 34 35 Implement the new SPI (see above for more details). 36 37 (-[WKContentView canPerformActionForWebView:withSender:]): 38 39 Implement -canPerformAction: for LTR and RTL actions. To match existing UIWebView behavior, we only enable 40 these actions if either the base writing direction is RTL, or the user has an active RTL keyboard. This means, 41 for instance, that in the case where a user with only an English keyboard is editing LTR content, we would never 42 show an option to convert to RTL. 43 44 * WebProcess/WebPage/WebPage.cpp: 45 (WebKit::WebPage::editorState const): 46 1 47 2019-02-15 Alex Christensen <achristensen@webkit.org> 2 48 -
trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h
r241435 r241614 1144 1144 BOOL UIKeyboardEnabledInputModesAllowOneToManyShortcuts(void); 1145 1145 BOOL UIKeyboardEnabledInputModesAllowChineseTransliterationForText(NSString *); 1146 BOOL UIKeyboardIsRightToLeftInputModeActive(void); 1146 1147 1147 1148 extern const float UITableCellDefaultFontSize; -
trunk/Source/WebKit/Shared/EditorState.cpp
r239931 r241614 112 112 encoder << caretRectAtStart; 113 113 #endif 114 #if PLATFORM( IOS_FAMILY) || PLATFORM(MAC)114 #if PLATFORM(COCOA) 115 115 encoder << focusedElementRect; 116 116 encoder << selectedTextLength; … … 118 118 encoder << textColor; 119 119 encoder << enclosingListType; 120 encoder << baseWritingDirection; 120 121 #endif 121 122 #if PLATFORM(IOS_FAMILY) … … 154 155 return false; 155 156 #endif 156 #if PLATFORM( IOS_FAMILY) || PLATFORM(MAC)157 #if PLATFORM(COCOA) 157 158 if (!decoder.decode(result.focusedElementRect)) 158 159 return false; … … 164 165 return false; 165 166 if (!decoder.decode(result.enclosingListType)) 167 return false; 168 if (!decoder.decode(result.baseWritingDirection)) 166 169 return false; 167 170 #endif … … 265 268 ts.dumpProperty("caretRectAtStart", editorState.postLayoutData().caretRectAtStart); 266 269 #endif 267 #if PLATFORM( IOS_FAMILY) || PLATFORM(MAC)270 #if PLATFORM(COCOA) 268 271 if (editorState.postLayoutData().focusedElementRect != IntRect()) 269 272 ts.dumpProperty("focusedElementRect", editorState.postLayoutData().focusedElementRect); … … 276 279 if (editorState.postLayoutData().enclosingListType != NoList) 277 280 ts.dumpProperty("enclosingListType", editorState.postLayoutData().enclosingListType); 278 #endif 281 if (editorState.postLayoutData().baseWritingDirection != WebCore::WritingDirection::Natural) 282 ts.dumpProperty("baseWritingDirection", static_cast<uint8_t>(editorState.postLayoutData().baseWritingDirection)); 283 #endif // PLATFORM(COCOA) 279 284 #if PLATFORM(IOS_FAMILY) 280 285 if (editorState.postLayoutData().caretRectAtEnd != IntRect()) -
trunk/Source/WebKit/Shared/EditorState.h
r239931 r241614 30 30 #include <WebCore/FontAttributes.h> 31 31 #include <WebCore/IntRect.h> 32 #include <WebCore/WritingDirection.h> 32 33 #include <wtf/text/WTFString.h> 33 34 … … 89 90 WebCore::IntRect caretRectAtStart; 90 91 #endif 91 #if PLATFORM( IOS_FAMILY) || PLATFORM(MAC)92 #if PLATFORM(COCOA) 92 93 WebCore::IntRect focusedElementRect; 93 94 uint64_t selectedTextLength { 0 }; … … 95 96 WebCore::Color textColor { WebCore::Color::black }; 96 97 uint32_t enclosingListType { NoList }; 98 WebCore::WritingDirection baseWritingDirection { WebCore::WritingDirection::Natural }; 97 99 #endif 98 100 #if PLATFORM(IOS_FAMILY) -
trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
r241320 r241614 132 132 M(decreaseSize) \ 133 133 M(pasteAndMatchStyle) \ 134 M(makeTextWritingDirectionNatural) 134 M(makeTextWritingDirectionNatural) \ 135 M(makeTextWritingDirectionLeftToRight) \ 136 M(makeTextWritingDirectionRightToLeft) 135 137 136 138 #define FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(M) \ -
trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
r241435 r241614 2472 2472 - (void)makeTextWritingDirectionNaturalForWebView:(id)sender 2473 2473 { 2474 _page->executeEditCommand("makeTextWritingDirectionNatural"_s); 2474 // Match platform behavior on iOS as well as legacy WebKit behavior by modifying the 2475 // base (paragraph) writing direction rather than the inline direction. 2476 _page->setBaseWritingDirection(WebCore::WritingDirection::Natural); 2477 } 2478 2479 - (void)makeTextWritingDirectionLeftToRightForWebView:(id)sender 2480 { 2481 _page->setBaseWritingDirection(WebCore::WritingDirection::LeftToRight); 2482 } 2483 2484 - (void)makeTextWritingDirectionRightToLeftForWebView:(id)sender 2485 { 2486 _page->setBaseWritingDirection(WebCore::WritingDirection::RightToLeft); 2475 2487 } 2476 2488 … … 2798 2810 if (action == @selector(replace:)) 2799 2811 return editorState.isContentEditable && !editorState.isInPasswordField; 2812 2813 if (action == @selector(makeTextWritingDirectionLeftToRight:) || action == @selector(makeTextWritingDirectionRightToLeft:)) { 2814 if (!editorState.isContentEditable) 2815 return NO; 2816 2817 auto baseWritingDirection = editorState.postLayoutData().baseWritingDirection; 2818 if (baseWritingDirection == WebCore::WritingDirection::LeftToRight && !UIKeyboardIsRightToLeftInputModeActive()) { 2819 // A keyboard is considered "active" if it is available for the user to switch to. As such, this check prevents 2820 // text direction actions from showing up in the case where a user has only added left-to-right keyboards, and 2821 // is also not editing right-to-left content. 2822 return NO; 2823 } 2824 2825 if (action == @selector(makeTextWritingDirectionLeftToRight:)) 2826 return baseWritingDirection != WebCore::WritingDirection::LeftToRight; 2827 2828 return baseWritingDirection != WebCore::WritingDirection::RightToLeft; 2829 } 2800 2830 2801 2831 return [super canPerformAction:action withSender:sender]; -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp
r241574 r241614 1023 1023 ASSERT_NOT_REACHED(); 1024 1024 } 1025 1026 postLayoutData.baseWritingDirection = editor.baseWritingDirectionForSelectionStart(); 1025 1027 } 1026 1028 #endif -
trunk/Tools/ChangeLog
r241606 r241614 1 2019-02-15 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [iOS] WKWebView callout bar is missing Change Writing Direction item 4 https://bugs.webkit.org/show_bug.cgi?id=190015 5 <rdar://problem/44810366> 6 7 Reviewed by Tim Horton. 8 9 Make an existing API test that exercises platform SPI to change the inline text writing direction run only on 10 macOS, and add a new API test that uses similarly named SPI on iOS to change the base writing direction. 11 12 * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm: 13 (TestWebKitAPI::TEST): 14 1 15 2019-02-15 Chris Dumez <cdumez@apple.com> 2 16 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm
r238728 r241614 259 259 } 260 260 261 TEST(WKWebViewEditActions, ModifyTextWritingDirection) 262 { 263 auto webView = webViewForEditActionTesting(@"<div id='text' style='direction: rtl; unicode-bidi: bidi-override;'>WebKit</div>"); 264 [webView selectAll:nil]; 261 #if PLATFORM(IOS_FAMILY) 262 263 TEST(WKWebViewEditActions, ModifyBaseWritingDirection) 264 { 265 auto webView = webViewForEditActionTesting(@"<meta charset='utf8'><p id='english'>Hello world</p><p id='hebrew'>מקור השם עברית</p>"); 266 267 [webView evaluateJavaScript:@"getSelection().setPosition(english)" completionHandler:nil]; 268 [webView makeTextWritingDirectionRightToLeft:nil]; 269 [webView waitForNextPresentationUpdate]; 270 EXPECT_WK_STREQ("rtl", [webView stringByEvaluatingJavaScript:@"getComputedStyle(english).direction"]); 271 EXPECT_FALSE([webView canPerformAction:@selector(makeTextWritingDirectionRightToLeft:) withSender:nil]); 272 EXPECT_TRUE([webView canPerformAction:@selector(makeTextWritingDirectionLeftToRight:) withSender:nil]); 273 274 [webView evaluateJavaScript:@"getSelection().setPosition(hebrew)" completionHandler:nil]; 275 [webView makeTextWritingDirectionLeftToRight:nil]; 276 [webView waitForNextPresentationUpdate]; 277 EXPECT_WK_STREQ("ltr", [webView stringByEvaluatingJavaScript:@"getComputedStyle(hebrew).direction"]); 278 EXPECT_FALSE([webView canPerformAction:@selector(makeTextWritingDirectionLeftToRight:) withSender:nil]); 279 280 [webView evaluateJavaScript:@"getSelection().setPosition(english)" completionHandler:nil]; 265 281 [webView makeTextWritingDirectionNatural:nil]; 266 EXPECT_WK_STREQ("normal", [webView stringByEvaluatingJavaScript:@"getComputedStyle(text).unicodeBidi"]);267 } 268 269 #if PLATFORM(IOS_FAMILY) 282 [webView waitForNextPresentationUpdate]; 283 EXPECT_WK_STREQ("ltr", [webView stringByEvaluatingJavaScript:@"getComputedStyle(english).direction"]); 284 EXPECT_FALSE([webView canPerformAction:@selector(makeTextWritingDirectionLeftToRight:) withSender:nil]); 285 } 270 286 271 287 TEST(WKWebViewEditActions, ChangeFontSize) … … 329 345 } 330 346 331 #endif // PLATFORM(IOS_FAMILY) 347 #else 348 349 TEST(WKWebViewEditActions, ModifyTextWritingDirection) 350 { 351 auto webView = webViewForEditActionTesting(@"<div id='text' style='direction: rtl; unicode-bidi: bidi-override;'>WebKit</div>"); 352 [webView selectAll:nil]; 353 [webView makeTextWritingDirectionNatural:nil]; 354 EXPECT_WK_STREQ("normal", [webView stringByEvaluatingJavaScript:@"getComputedStyle(text).unicodeBidi"]); 355 } 356 357 #endif 332 358 333 359 } // namespace TestWebKitAPI
Note: See TracChangeset
for help on using the changeset viewer.