- Revision
- 241614
- Author
- [email protected]
- Date
- 2019-02-15 13:35:52 -0800 (Fri, 15 Feb 2019)
Log Message
[iOS] WKWebView callout bar is missing Change Writing Direction item
https://bugs.webkit.org/show_bug.cgi?id=190015
<rdar://problem/44810366>
Reviewed by Tim Horton.
Source/WebKit:
Support -makeTextWritingDirectionLeftToRight: and -makeTextWritingDirectionRightToLeft: in WKWebView on iOS.
To match behavior in native UITextViews on iOS, we implement these methods by changing the *base* writing
direction, rather than the text writing direction (this is in contrast to macOS, which has different
NSResponder methods for changing the base writing direction as opposed to the text writing direction).
Additionally fixes the implementation of -makeTextWritingDirectionNatural:, which currently attempts to change
the text writing direction instead of the base writing direction.
* Platform/spi/ios/UIKitSPI.h:
Add a forward declaration for keyboards SPI to determine whether the user has an active RTL keyboard.
* Shared/EditorState.cpp:
(WebKit::EditorState::PostLayoutData::encode const):
(WebKit::EditorState::PostLayoutData::decode):
(WebKit::operator<<):
* Shared/EditorState.h:
Plumb the base writing direction to the UI process through EditorState.
* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView makeTextWritingDirectionNaturalForWebView:]):
(-[WKContentView makeTextWritingDirectionLeftToRightForWebView:]):
(-[WKContentView makeTextWritingDirectionRightToLeftForWebView:]):
Implement the new SPI (see above for more details).
(-[WKContentView canPerformActionForWebView:withSender:]):
Implement -canPerformAction: for LTR and RTL actions. To match existing UIWebView behavior, we only enable
these actions if either the base writing direction is RTL, or the user has an active RTL keyboard. This means,
for instance, that in the case where a user with only an English keyboard is editing LTR content, we would never
show an option to convert to RTL.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::editorState const):
Tools:
Make an existing API test that exercises platform SPI to change the inline text writing direction run only on
macOS, and add a new API test that uses similarly named SPI on iOS to change the base writing direction.
* TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm:
(TestWebKitAPI::TEST):
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (241613 => 241614)
--- trunk/Source/WebKit/ChangeLog 2019-02-15 21:34:19 UTC (rev 241613)
+++ trunk/Source/WebKit/ChangeLog 2019-02-15 21:35:52 UTC (rev 241614)
@@ -1,3 +1,49 @@
+2019-02-15 Wenson Hsieh <[email protected]>
+
+ [iOS] WKWebView callout bar is missing Change Writing Direction item
+ https://bugs.webkit.org/show_bug.cgi?id=190015
+ <rdar://problem/44810366>
+
+ Reviewed by Tim Horton.
+
+ Support -makeTextWritingDirectionLeftToRight: and -makeTextWritingDirectionRightToLeft: in WKWebView on iOS.
+ To match behavior in native UITextViews on iOS, we implement these methods by changing the *base* writing
+ direction, rather than the text writing direction (this is in contrast to macOS, which has different
+ NSResponder methods for changing the base writing direction as opposed to the text writing direction).
+
+ Additionally fixes the implementation of -makeTextWritingDirectionNatural:, which currently attempts to change
+ the text writing direction instead of the base writing direction.
+
+ * Platform/spi/ios/UIKitSPI.h:
+
+ Add a forward declaration for keyboards SPI to determine whether the user has an active RTL keyboard.
+
+ * Shared/EditorState.cpp:
+ (WebKit::EditorState::PostLayoutData::encode const):
+ (WebKit::EditorState::PostLayoutData::decode):
+ (WebKit::operator<<):
+ * Shared/EditorState.h:
+
+ Plumb the base writing direction to the UI process through EditorState.
+
+ * UIProcess/ios/WKContentViewInteraction.h:
+ * UIProcess/ios/WKContentViewInteraction.mm:
+ (-[WKContentView makeTextWritingDirectionNaturalForWebView:]):
+ (-[WKContentView makeTextWritingDirectionLeftToRightForWebView:]):
+ (-[WKContentView makeTextWritingDirectionRightToLeftForWebView:]):
+
+ Implement the new SPI (see above for more details).
+
+ (-[WKContentView canPerformActionForWebView:withSender:]):
+
+ Implement -canPerformAction: for LTR and RTL actions. To match existing UIWebView behavior, we only enable
+ these actions if either the base writing direction is RTL, or the user has an active RTL keyboard. This means,
+ for instance, that in the case where a user with only an English keyboard is editing LTR content, we would never
+ show an option to convert to RTL.
+
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::editorState const):
+
2019-02-15 Alex Christensen <[email protected]>
Make WebPaymentCoordinatorProxy more robust and modern
Modified: trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h (241613 => 241614)
--- trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h 2019-02-15 21:34:19 UTC (rev 241613)
+++ trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h 2019-02-15 21:35:52 UTC (rev 241614)
@@ -1143,6 +1143,7 @@
BOOL UIKeyboardEnabledInputModesAllowOneToManyShortcuts(void);
BOOL UIKeyboardEnabledInputModesAllowChineseTransliterationForText(NSString *);
+BOOL UIKeyboardIsRightToLeftInputModeActive(void);
extern const float UITableCellDefaultFontSize;
extern const float UITableViewCellDefaultFontSize;
Modified: trunk/Source/WebKit/Shared/EditorState.cpp (241613 => 241614)
--- trunk/Source/WebKit/Shared/EditorState.cpp 2019-02-15 21:34:19 UTC (rev 241613)
+++ trunk/Source/WebKit/Shared/EditorState.cpp 2019-02-15 21:35:52 UTC (rev 241614)
@@ -111,12 +111,13 @@
#if PLATFORM(IOS_FAMILY) || PLATFORM(GTK)
encoder << caretRectAtStart;
#endif
-#if PLATFORM(IOS_FAMILY) || PLATFORM(MAC)
+#if PLATFORM(COCOA)
encoder << focusedElementRect;
encoder << selectedTextLength;
encoder << textAlignment;
encoder << textColor;
encoder << enclosingListType;
+ encoder << baseWritingDirection;
#endif
#if PLATFORM(IOS_FAMILY)
encoder << caretRectAtEnd;
@@ -153,7 +154,7 @@
if (!decoder.decode(result.caretRectAtStart))
return false;
#endif
-#if PLATFORM(IOS_FAMILY) || PLATFORM(MAC)
+#if PLATFORM(COCOA)
if (!decoder.decode(result.focusedElementRect))
return false;
if (!decoder.decode(result.selectedTextLength))
@@ -164,6 +165,8 @@
return false;
if (!decoder.decode(result.enclosingListType))
return false;
+ if (!decoder.decode(result.baseWritingDirection))
+ return false;
#endif
#if PLATFORM(IOS_FAMILY)
if (!decoder.decode(result.caretRectAtEnd))
@@ -264,7 +267,7 @@
if (editorState.postLayoutData().caretRectAtStart != IntRect())
ts.dumpProperty("caretRectAtStart", editorState.postLayoutData().caretRectAtStart);
#endif
-#if PLATFORM(IOS_FAMILY) || PLATFORM(MAC)
+#if PLATFORM(COCOA)
if (editorState.postLayoutData().focusedElementRect != IntRect())
ts.dumpProperty("focusedElementRect", editorState.postLayoutData().focusedElementRect);
if (editorState.postLayoutData().selectedTextLength)
@@ -275,7 +278,9 @@
ts.dumpProperty("textColor", editorState.postLayoutData().textColor);
if (editorState.postLayoutData().enclosingListType != NoList)
ts.dumpProperty("enclosingListType", editorState.postLayoutData().enclosingListType);
-#endif
+ if (editorState.postLayoutData().baseWritingDirection != WebCore::WritingDirection::Natural)
+ ts.dumpProperty("baseWritingDirection", static_cast<uint8_t>(editorState.postLayoutData().baseWritingDirection));
+#endif // PLATFORM(COCOA)
#if PLATFORM(IOS_FAMILY)
if (editorState.postLayoutData().caretRectAtEnd != IntRect())
ts.dumpProperty("caretRectAtEnd", editorState.postLayoutData().caretRectAtEnd);
Modified: trunk/Source/WebKit/Shared/EditorState.h (241613 => 241614)
--- trunk/Source/WebKit/Shared/EditorState.h 2019-02-15 21:34:19 UTC (rev 241613)
+++ trunk/Source/WebKit/Shared/EditorState.h 2019-02-15 21:35:52 UTC (rev 241614)
@@ -29,6 +29,7 @@
#include <WebCore/Color.h>
#include <WebCore/FontAttributes.h>
#include <WebCore/IntRect.h>
+#include <WebCore/WritingDirection.h>
#include <wtf/text/WTFString.h>
#if PLATFORM(IOS_FAMILY)
@@ -88,12 +89,13 @@
#if PLATFORM(IOS_FAMILY) || PLATFORM(GTK)
WebCore::IntRect caretRectAtStart;
#endif
-#if PLATFORM(IOS_FAMILY) || PLATFORM(MAC)
+#if PLATFORM(COCOA)
WebCore::IntRect focusedElementRect;
uint64_t selectedTextLength { 0 };
uint32_t textAlignment { NoAlignment };
WebCore::Color textColor { WebCore::Color::black };
uint32_t enclosingListType { NoList };
+ WebCore::WritingDirection baseWritingDirection { WebCore::WritingDirection::Natural };
#endif
#if PLATFORM(IOS_FAMILY)
WebCore::IntRect caretRectAtEnd;
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (241613 => 241614)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h 2019-02-15 21:34:19 UTC (rev 241613)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h 2019-02-15 21:35:52 UTC (rev 241614)
@@ -131,7 +131,9 @@
M(increaseSize) \
M(decreaseSize) \
M(pasteAndMatchStyle) \
- M(makeTextWritingDirectionNatural)
+ M(makeTextWritingDirectionNatural) \
+ M(makeTextWritingDirectionLeftToRight) \
+ M(makeTextWritingDirectionRightToLeft)
#define FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(M) \
M(_alignCenter) \
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (241613 => 241614)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2019-02-15 21:34:19 UTC (rev 241613)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2019-02-15 21:35:52 UTC (rev 241614)
@@ -2471,9 +2471,21 @@
- (void)makeTextWritingDirectionNaturalForWebView:(id)sender
{
- _page->executeEditCommand("makeTextWritingDirectionNatural"_s);
+ // Match platform behavior on iOS as well as legacy WebKit behavior by modifying the
+ // base (paragraph) writing direction rather than the inline direction.
+ _page->setBaseWritingDirection(WebCore::WritingDirection::Natural);
}
+- (void)makeTextWritingDirectionLeftToRightForWebView:(id)sender
+{
+ _page->setBaseWritingDirection(WebCore::WritingDirection::LeftToRight);
+}
+
+- (void)makeTextWritingDirectionRightToLeftForWebView:(id)sender
+{
+ _page->setBaseWritingDirection(WebCore::WritingDirection::RightToLeft);
+}
+
- (BOOL)isReplaceAllowed
{
return _page->editorState().postLayoutData().isReplaceAllowed;
@@ -2798,6 +2810,24 @@
if (action == @selector(replace:))
return editorState.isContentEditable && !editorState.isInPasswordField;
+ if (action == @selector(makeTextWritingDirectionLeftToRight:) || action == @selector(makeTextWritingDirectionRightToLeft:)) {
+ if (!editorState.isContentEditable)
+ return NO;
+
+ auto baseWritingDirection = editorState.postLayoutData().baseWritingDirection;
+ if (baseWritingDirection == WebCore::WritingDirection::LeftToRight && !UIKeyboardIsRightToLeftInputModeActive()) {
+ // A keyboard is considered "active" if it is available for the user to switch to. As such, this check prevents
+ // text direction actions from showing up in the case where a user has only added left-to-right keyboards, and
+ // is also not editing right-to-left content.
+ return NO;
+ }
+
+ if (action == @selector(makeTextWritingDirectionLeftToRight:))
+ return baseWritingDirection != WebCore::WritingDirection::LeftToRight;
+
+ return baseWritingDirection != WebCore::WritingDirection::RightToLeft;
+ }
+
return [super canPerformAction:action withSender:sender];
}
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (241613 => 241614)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2019-02-15 21:34:19 UTC (rev 241613)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2019-02-15 21:35:52 UTC (rev 241614)
@@ -1022,6 +1022,8 @@
else
ASSERT_NOT_REACHED();
}
+
+ postLayoutData.baseWritingDirection = editor.baseWritingDirectionForSelectionStart();
}
#endif
}
Modified: trunk/Tools/ChangeLog (241613 => 241614)
--- trunk/Tools/ChangeLog 2019-02-15 21:34:19 UTC (rev 241613)
+++ trunk/Tools/ChangeLog 2019-02-15 21:35:52 UTC (rev 241614)
@@ -1,3 +1,17 @@
+2019-02-15 Wenson Hsieh <[email protected]>
+
+ [iOS] WKWebView callout bar is missing Change Writing Direction item
+ https://bugs.webkit.org/show_bug.cgi?id=190015
+ <rdar://problem/44810366>
+
+ Reviewed by Tim Horton.
+
+ Make an existing API test that exercises platform SPI to change the inline text writing direction run only on
+ macOS, and add a new API test that uses similarly named SPI on iOS to change the base writing direction.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm:
+ (TestWebKitAPI::TEST):
+
2019-02-15 Chris Dumez <[email protected]>
Regression(PSON) Navigating quickly back and forth can lead to getting 'about:blank' in the backforward list
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm (241613 => 241614)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm 2019-02-15 21:34:19 UTC (rev 241613)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm 2019-02-15 21:35:52 UTC (rev 241614)
@@ -258,16 +258,32 @@
EXPECT_WK_STREQ("WebKit", [destination stringByEvaluatingJavaScript:@"getSelection().toString()"]);
}
-TEST(WKWebViewEditActions, ModifyTextWritingDirection)
+#if PLATFORM(IOS_FAMILY)
+
+TEST(WKWebViewEditActions, ModifyBaseWritingDirection)
{
- auto webView = webViewForEditActionTesting(@"<div id='text' style='direction: rtl; unicode-bidi: bidi-override;'>WebKit</div>");
- [webView selectAll:nil];
+ auto webView = webViewForEditActionTesting(@"<meta charset='utf8'><p id='english'>Hello world</p><p id='hebrew'>מקור השם עברית</p>");
+
+ [webView evaluateJavaScript:@"getSelection().setPosition(english)" completionHandler:nil];
+ [webView makeTextWritingDirectionRightToLeft:nil];
+ [webView waitForNextPresentationUpdate];
+ EXPECT_WK_STREQ("rtl", [webView stringByEvaluatingJavaScript:@"getComputedStyle(english).direction"]);
+ EXPECT_FALSE([webView canPerformAction:@selector(makeTextWritingDirectionRightToLeft:) withSender:nil]);
+ EXPECT_TRUE([webView canPerformAction:@selector(makeTextWritingDirectionLeftToRight:) withSender:nil]);
+
+ [webView evaluateJavaScript:@"getSelection().setPosition(hebrew)" completionHandler:nil];
+ [webView makeTextWritingDirectionLeftToRight:nil];
+ [webView waitForNextPresentationUpdate];
+ EXPECT_WK_STREQ("ltr", [webView stringByEvaluatingJavaScript:@"getComputedStyle(hebrew).direction"]);
+ EXPECT_FALSE([webView canPerformAction:@selector(makeTextWritingDirectionLeftToRight:) withSender:nil]);
+
+ [webView evaluateJavaScript:@"getSelection().setPosition(english)" completionHandler:nil];
[webView makeTextWritingDirectionNatural:nil];
- EXPECT_WK_STREQ("normal", [webView stringByEvaluatingJavaScript:@"getComputedStyle(text).unicodeBidi"]);
+ [webView waitForNextPresentationUpdate];
+ EXPECT_WK_STREQ("ltr", [webView stringByEvaluatingJavaScript:@"getComputedStyle(english).direction"]);
+ EXPECT_FALSE([webView canPerformAction:@selector(makeTextWritingDirectionLeftToRight:) withSender:nil]);
}
-#if PLATFORM(IOS_FAMILY)
-
TEST(WKWebViewEditActions, ChangeFontSize)
{
auto webView = webViewForEditActionTesting();
@@ -328,8 +344,18 @@
EXPECT_WK_STREQ("italic", [webView stylePropertyAtSelectionStart:@"font-style"]);
}
-#endif // PLATFORM(IOS_FAMILY)
+#else
+TEST(WKWebViewEditActions, ModifyTextWritingDirection)
+{
+ auto webView = webViewForEditActionTesting(@"<div id='text' style='direction: rtl; unicode-bidi: bidi-override;'>WebKit</div>");
+ [webView selectAll:nil];
+ [webView makeTextWritingDirectionNatural:nil];
+ EXPECT_WK_STREQ("normal", [webView stringByEvaluatingJavaScript:@"getComputedStyle(text).unicodeBidi"]);
+}
+
+#endif
+
} // namespace TestWebKitAPI
#endif // WK_API_ENABLED