- Revision
- 258919
- Author
- [email protected]
- Date
- 2020-03-24 10:57:41 -0700 (Tue, 24 Mar 2020)
Log Message
[iOS][WK2] Set text trait isSingleLineDocument
https://bugs.webkit.org/show_bug.cgi?id=209391
<rdar://problem/60705870>
Reviewed by Darin Adler.
Source/WebKit:
Set the SPI text trait isSingleLineDocument to NO if the focused element is
a <textarea> or contenteditable element because these elements support multi-
line text. For all other elements, consider them single line text fields and
return YES.
Note that I chose to go with the above criterion because it is simple. In reality,
it is possible to make a <textarea> or contenteditable behave like a single-line
document, but it requires going out of your way to to do so and may involve
platform-specific heuristics. See <https://bugs.webkit.org/show_bug.cgi?id=209391#c9>
for more details. For now, let's try something simple.
* Platform/spi/ios/UIKitSPI.h: Expose more SPI.
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView textInputTraits]):
Tools:
Add a test.
* TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/ios/UIKitSPI.h: Expose more SPI.
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (258918 => 258919)
--- trunk/Source/WebKit/ChangeLog 2020-03-24 17:53:38 UTC (rev 258918)
+++ trunk/Source/WebKit/ChangeLog 2020-03-24 17:57:41 UTC (rev 258919)
@@ -1,3 +1,26 @@
+2020-03-24 Daniel Bates <[email protected]>
+
+ [iOS][WK2] Set text trait isSingleLineDocument
+ https://bugs.webkit.org/show_bug.cgi?id=209391
+ <rdar://problem/60705870>
+
+ Reviewed by Darin Adler.
+
+ Set the SPI text trait isSingleLineDocument to NO if the focused element is
+ a <textarea> or contenteditable element because these elements support multi-
+ line text. For all other elements, consider them single line text fields and
+ return YES.
+
+ Note that I chose to go with the above criterion because it is simple. In reality,
+ it is possible to make a <textarea> or contenteditable behave like a single-line
+ document, but it requires going out of your way to to do so and may involve
+ platform-specific heuristics. See <https://bugs.webkit.org/show_bug.cgi?id=209391#c9>
+ for more details. For now, let's try something simple.
+
+ * Platform/spi/ios/UIKitSPI.h: Expose more SPI.
+ * UIProcess/ios/WKContentViewInteraction.mm:
+ (-[WKContentView textInputTraits]):
+
2020-03-24 Diego Pino Garcia <[email protected]>
REGRESSION(r258871): [GTK] test bot exiting early due to too many crashes
Modified: trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h (258918 => 258919)
--- trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h 2020-03-24 17:53:38 UTC (rev 258918)
+++ trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h 2020-03-24 17:57:41 UTC (rev 258919)
@@ -442,6 +442,7 @@
@property (nonatomic, retain) UIColor *insertionPointColor;
@property (nonatomic, retain) UIColor *selectionBarColor;
@property (nonatomic, retain) UIColor *selectionHighlightColor;
+@property (nonatomic, readwrite) BOOL isSingleLineDocument;
@end
@protocol UITextInputDelegatePrivate
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (258918 => 258919)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2020-03-24 17:53:38 UTC (rev 258918)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2020-03-24 17:57:41 UTC (rev 258919)
@@ -43,6 +43,7 @@
#import "SmartMagnificationController.h"
#import "TextChecker.h"
#import "TextInputSPI.h"
+#import "UIKitSPI.h"
#import "UserInterfaceIdiom.h"
#import "VersionChecks.h"
#import "WKActionSheetAssistant.h"
@@ -163,7 +164,6 @@
#endif
#if USE(DICTATION_ALTERNATIVES)
-#import "UIKitSPI.h"
#import <WebCore/TextAlternativeWithRange.h>
#endif
@@ -4977,6 +4977,35 @@
[_traits setTextContentType:contentTypeFromFieldName(_focusedElementInformation.autofillFieldName)];
+ switch (_focusedElementInformation.elementType) {
+ case WebKit::InputType::ContentEditable:
+ case WebKit::InputType::TextArea:
+ [_traits setIsSingleLineDocument:NO];
+ break;
+#if ENABLE(INPUT_TYPE_COLOR)
+ case WebKit::InputType::Color:
+#endif
+ case WebKit::InputType::Date:
+ case WebKit::InputType::DateTime:
+ case WebKit::InputType::DateTimeLocal:
+ case WebKit::InputType::Drawing:
+ case WebKit::InputType::Email:
+ case WebKit::InputType::Month:
+ case WebKit::InputType::None:
+ case WebKit::InputType::Number:
+ case WebKit::InputType::NumberPad:
+ case WebKit::InputType::Password:
+ case WebKit::InputType::Phone:
+ case WebKit::InputType::Search:
+ case WebKit::InputType::Select:
+ case WebKit::InputType::Text:
+ case WebKit::InputType::Time:
+ case WebKit::InputType::URL:
+ case WebKit::InputType::Week:
+ [_traits setIsSingleLineDocument:YES];
+ break;
+ }
+
[self _updateInteractionTintColor];
return _traits.get();
Modified: trunk/Tools/ChangeLog (258918 => 258919)
--- trunk/Tools/ChangeLog 2020-03-24 17:53:38 UTC (rev 258918)
+++ trunk/Tools/ChangeLog 2020-03-24 17:57:41 UTC (rev 258919)
@@ -1,3 +1,17 @@
+2020-03-24 Daniel Bates <[email protected]>
+
+ [iOS][WK2] Set text trait isSingleLineDocument
+ https://bugs.webkit.org/show_bug.cgi?id=209391
+ <rdar://problem/60705870>
+
+ Reviewed by Darin Adler.
+
+ Add a test.
+
+ * TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
+ (TestWebKitAPI::TEST):
+ * TestWebKitAPI/ios/UIKitSPI.h: Expose more SPI.
+
2020-03-24 Alex Christensen <[email protected]>
Unreviewed, reverting r258862.
Modified: trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm (258918 => 258919)
--- trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm 2020-03-24 17:53:38 UTC (rev 258918)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm 2020-03-24 17:57:41 UTC (rev 258919)
@@ -437,6 +437,28 @@
[webView waitForSelectionViewRectsToBecome:expectedSelectionRects];
}
+TEST(KeyboardInputTests, IsSingleLineDocument)
+{
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+ auto inputDelegate = adoptNS([[TestInputDelegate alloc] init]);
+ [inputDelegate setFocusStartsInputSessionPolicyHandler:[&] (WKWebView *, id <_WKFocusedElementInfo>) { return _WKFocusStartsInputSessionPolicyAllow; }];
+ [webView _setInputDelegate:inputDelegate.get()];
+
+ [webView synchronouslyLoadHTMLString:@"<body><input id='first' type='text'><textarea id='second'></textarea><div id='third' contenteditable='true'></div></body>"];
+
+ // Text field
+ [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"document.getElementById('first').focus()"];
+ EXPECT_TRUE([webView textInputContentView].textInputTraits.isSingleLineDocument);
+
+ // Text area
+ [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"document.getElementById('second').focus()"];
+ EXPECT_FALSE([webView textInputContentView].textInputTraits.isSingleLineDocument);
+
+ // Content editable
+ [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"document.getElementById('third').focus()"];
+ EXPECT_FALSE([webView textInputContentView].textInputTraits.isSingleLineDocument);
+}
+
TEST(KeyboardInputTests, KeyboardTypeForInput)
{
auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
Modified: trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h (258918 => 258919)
--- trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h 2020-03-24 17:53:38 UTC (rev 258918)
+++ trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h 2020-03-24 17:57:41 UTC (rev 258919)
@@ -70,9 +70,15 @@
@property (nonatomic, copy) NSString *displayText;
@end
-@interface UITextInputTraits : NSObject <UITextInputTraits>
+@protocol UITextInputTraits_Private <NSObject, UITextInputTraits>
+@property (nonatomic, readonly) UIColor *insertionPointColor;
+@property (nonatomic, readonly) UIColor *selectionBarColor;
+@property (nonatomic, readwrite) BOOL isSingleLineDocument;
@end
+@interface UITextInputTraits : NSObject <UITextInputTraits, UITextInputTraits_Private, NSCopying>
+@end
+
@protocol UIDragInteractionDelegate_ForWebKitOnly <UIDragInteractionDelegate>
@optional
- (void)_dragInteraction:(UIDragInteraction *)interaction prepareForSession:(id<UIDragSession>)session completion:(void(^)(void))completion;
@@ -79,11 +85,6 @@
- (void)_dragInteraction:(UIDragInteraction *)interaction itemsForAddingToSession:(id <UIDragSession>)session withTouchAtPoint:(CGPoint)point completion:(void(^)(NSArray<UIDragItem *> *))completion;
@end
-@protocol UITextInputTraits_Private <NSObject, UITextInputTraits>
-@property (nonatomic, readonly) UIColor *insertionPointColor;
-@property (nonatomic, readonly) UIColor *selectionBarColor;
-@end
-
@class WebEvent;
@class UITextInputArrowKeyHistory;