Title: [201347] trunk/Source/WebKit2
- Revision
- 201347
- Author
- [email protected]
- Date
- 2016-05-24 13:22:17 -0700 (Tue, 24 May 2016)
Log Message
[iOS] Allow clients to override the type of an input field
https://bugs.webkit.org/show_bug.cgi?id=157995
Patch by Chelsea Pugh <[email protected]> on 2016-05-24
Reviewed by Dan Bernstein.
* UIProcess/API/Cocoa/_WKFormInputSession.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKFormInputSession textContentType]): Getter for textContentType.
(-[WKFormInputSession setTextContentType:]): Set the textContentType and reload
input views.
(contentTypeFromFieldName): Factor out switch statement to get text content type
from autofill field name into its own function.
(-[WKContentView textInputTraits]): If the client has set a text content type,
set the traits' content type to that. Otherwise, set the text content type if
there is one based on the assisted node information's autofill field name. If
neither the form input session nor the assisted node info yields a text content
type, set the text content type to nil, its default value.
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (201346 => 201347)
--- trunk/Source/WebKit2/ChangeLog 2016-05-24 20:02:31 UTC (rev 201346)
+++ trunk/Source/WebKit2/ChangeLog 2016-05-24 20:22:17 UTC (rev 201347)
@@ -1,3 +1,23 @@
+2016-05-24 Chelsea Pugh <[email protected]>
+
+ [iOS] Allow clients to override the type of an input field
+ https://bugs.webkit.org/show_bug.cgi?id=157995
+
+ Reviewed by Dan Bernstein.
+
+ * UIProcess/API/Cocoa/_WKFormInputSession.h:
+ * UIProcess/ios/WKContentViewInteraction.mm:
+ (-[WKFormInputSession textContentType]): Getter for textContentType.
+ (-[WKFormInputSession setTextContentType:]): Set the textContentType and reload
+ input views.
+ (contentTypeFromFieldName): Factor out switch statement to get text content type
+ from autofill field name into its own function.
+ (-[WKContentView textInputTraits]): If the client has set a text content type,
+ set the traits' content type to that. Otherwise, set the text content type if
+ there is one based on the assisted node information's autofill field name. If
+ neither the form input session nor the assisted node info yields a text content
+ type, set the text content type to nil, its default value.
+
2016-05-24 Chris Dumez <[email protected]>
Use lambda capture with initializer instead of StringCapture
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKFormInputSession.h (201346 => 201347)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKFormInputSession.h 2016-05-24 20:02:31 UTC (rev 201346)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKFormInputSession.h 2016-05-24 20:22:17 UTC (rev 201347)
@@ -43,6 +43,7 @@
@property (nonatomic, strong) UIView *customInputView WK_AVAILABLE(NA, WK_IOS_TBA);
@property (nonatomic, copy) NSArray<UITextSuggestion *> *suggestions WK_AVAILABLE(NA, WK_IOS_TBA);
@property (nonatomic) BOOL accessoryViewShouldNotShow WK_AVAILABLE(NA, WK_IOS_TBA);
+@property (nonatomic, copy) NSString *textContentType WK_AVAILABLE(NA, WK_IOS_TBA);
#endif
@end
Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (201346 => 201347)
--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm 2016-05-24 20:02:31 UTC (rev 201346)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm 2016-05-24 20:22:17 UTC (rev 201347)
@@ -264,6 +264,7 @@
RetainPtr<WKFocusedElementInfo> _focusedElementInfo;
RetainPtr<UIView> _customInputView;
RetainPtr<NSArray<UITextSuggestion *>> _suggestions;
+ RetainPtr<NSString> _textContentType;
BOOL _accessoryViewShouldNotShow;
}
@@ -351,6 +352,20 @@
#endif
}
+- (NSString *)textContentType
+{
+ return _textContentType.get();
+}
+
+- (void)setTextContentType:(NSString *)textContentType
+{
+ if (textContentType == _textContentType || [textContentType isEqualToString:_textContentType.get()])
+ return;
+
+ _textContentType = adoptNS([textContentType copy]);
+ [_contentView reloadInputViews];
+}
+
- (void)invalidate
{
_contentView = nil;
@@ -2875,109 +2890,50 @@
return UITextAutocapitalizationTypeSentences;
}
-// UITextInputPrivate protocol
-// Direct access to the (private) UITextInputTraits object.
-- (UITextInputTraits *)textInputTraits
+#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 100000
+static NSString *contentTypeFromFieldName(WebCore::AutofillFieldName fieldName)
{
- if (!_traits)
- _traits = adoptNS([[UITextInputTraits alloc] init]);
-
- [_traits setSecureTextEntry:_assistedNodeInformation.elementType == InputType::Password];
- [_traits setShortcutConversionType:_assistedNodeInformation.elementType == InputType::Password ? UITextShortcutConversionTypeNo : UITextShortcutConversionTypeDefault];
-
- if (!_assistedNodeInformation.formAction.isEmpty())
- [_traits setReturnKeyType:(_assistedNodeInformation.elementType == InputType::Search) ? UIReturnKeySearch : UIReturnKeyGo];
-
- if (_assistedNodeInformation.elementType == InputType::Password || _assistedNodeInformation.elementType == InputType::Email || _assistedNodeInformation.elementType == InputType::URL || _assistedNodeInformation.formAction.contains("login")) {
- [_traits setAutocapitalizationType:UITextAutocapitalizationTypeNone];
- [_traits setAutocorrectionType:UITextAutocorrectionTypeNo];
- } else {
- [_traits setAutocapitalizationType:toUITextAutocapitalize(_assistedNodeInformation.autocapitalizeType)];
- [_traits setAutocorrectionType:_assistedNodeInformation.isAutocorrect ? UITextAutocorrectionTypeYes : UITextAutocorrectionTypeNo];
- }
-
- switch (_assistedNodeInformation.elementType) {
- case InputType::Phone:
- [_traits setKeyboardType:UIKeyboardTypePhonePad];
- break;
- case InputType::URL:
- [_traits setKeyboardType:UIKeyboardTypeURL];
- break;
- case InputType::Email:
- [_traits setKeyboardType:UIKeyboardTypeEmailAddress];
- break;
- case InputType::Number:
- [_traits setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];
- break;
- case InputType::NumberPad:
- [_traits setKeyboardType:UIKeyboardTypeNumberPad];
- break;
- default:
- [_traits setKeyboardType:UIKeyboardTypeDefault];
- }
-
-#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 100000
- switch (_assistedNodeInformation.autofillFieldName) {
+ switch (fieldName) {
case WebCore::AutofillFieldName::Name:
- [_traits setTextContentType:UITextContentTypeName];
- break;
+ return UITextContentTypeName;
case WebCore::AutofillFieldName::HonorificPrefix:
- [_traits setTextContentType:UITextContentTypeNamePrefix];
- break;
+ return UITextContentTypeNamePrefix;
case WebCore::AutofillFieldName::GivenName:
- [_traits setTextContentType:UITextContentTypeMiddleName];
- break;
+ return UITextContentTypeMiddleName;
case WebCore::AutofillFieldName::AdditionalName:
- [_traits setTextContentType:UITextContentTypeMiddleName];
- break;
+ return UITextContentTypeMiddleName;
case WebCore::AutofillFieldName::FamilyName:
- [_traits setTextContentType:UITextContentTypeFamilyName];
- break;
+ return UITextContentTypeFamilyName;
case WebCore::AutofillFieldName::HonorificSuffix:
- [_traits setTextContentType:UITextContentTypeNameSuffix];
- break;
+ return UITextContentTypeNameSuffix;
case WebCore::AutofillFieldName::Nickname:
- [_traits setTextContentType:UITextContentTypeNickname];
- break;
+ return UITextContentTypeNickname;
case WebCore::AutofillFieldName::OrganizationTitle:
- [_traits setTextContentType:UITextContentTypeJobTitle];
- break;
+ return UITextContentTypeJobTitle;
case WebCore::AutofillFieldName::Organization:
- [_traits setTextContentType:UITextContentTypeOrganizationName];
- break;
+ return UITextContentTypeOrganizationName;
case WebCore::AutofillFieldName::StreetAddress:
- [_traits setTextContentType:UITextContentTypeFullStreetAddress];
- break;
+ return UITextContentTypeFullStreetAddress;
case WebCore::AutofillFieldName::AddressLine1:
- [_traits setTextContentType:UITextContentTypeStreetAddressLine1];
- break;
+ return UITextContentTypeStreetAddressLine1;
case WebCore::AutofillFieldName::AddressLine2:
- [_traits setTextContentType:UITextContentTypeStreetAddressLine2];
- break;
+ return UITextContentTypeStreetAddressLine2;
case WebCore::AutofillFieldName::AddressLevel3:
- [_traits setTextContentType:UITextContentTypeSublocality];
- break;
+ return UITextContentTypeSublocality;
case WebCore::AutofillFieldName::AddressLevel2:
- [_traits setTextContentType:UITextContentTypeAddressCity];
- break;
+ return UITextContentTypeAddressCity;
case WebCore::AutofillFieldName::AddressLevel1:
- [_traits setTextContentType:UITextContentTypeAddressState];
- break;
+ return UITextContentTypeAddressState;
case WebCore::AutofillFieldName::CountryName:
- [_traits setTextContentType:UITextContentTypeCountryName];
- break;
+ return UITextContentTypeCountryName;
case WebCore::AutofillFieldName::PostalCode:
- [_traits setTextContentType:UITextContentTypePostalCode];
- break;
+ return UITextContentTypePostalCode;
case WebCore::AutofillFieldName::Tel:
- [_traits setTextContentType:UITextContentTypeTelephoneNumber];
- break;
+ return UITextContentTypeTelephoneNumber;
case WebCore::AutofillFieldName::Email:
- [_traits setTextContentType:UITextContentTypeEmailAddress];
- break;
+ return UITextContentTypeEmailAddress;
case WebCore::AutofillFieldName::URL:
- [_traits setTextContentType:UITextContentTypeURL];
- break;
+ return UITextContentTypeURL;
case WebCore::AutofillFieldName::None:
case WebCore::AutofillFieldName::Username:
case WebCore::AutofillFieldName::NewPassword:
@@ -3014,8 +2970,59 @@
case WebCore::AutofillFieldName::Impp:
break;
};
+
+ return nil;
+}
#endif
+// UITextInputPrivate protocol
+// Direct access to the (private) UITextInputTraits object.
+- (UITextInputTraits *)textInputTraits
+{
+ if (!_traits)
+ _traits = adoptNS([[UITextInputTraits alloc] init]);
+
+ [_traits setSecureTextEntry:_assistedNodeInformation.elementType == InputType::Password];
+ [_traits setShortcutConversionType:_assistedNodeInformation.elementType == InputType::Password ? UITextShortcutConversionTypeNo : UITextShortcutConversionTypeDefault];
+
+ if (!_assistedNodeInformation.formAction.isEmpty())
+ [_traits setReturnKeyType:(_assistedNodeInformation.elementType == InputType::Search) ? UIReturnKeySearch : UIReturnKeyGo];
+
+ if (_assistedNodeInformation.elementType == InputType::Password || _assistedNodeInformation.elementType == InputType::Email || _assistedNodeInformation.elementType == InputType::URL || _assistedNodeInformation.formAction.contains("login")) {
+ [_traits setAutocapitalizationType:UITextAutocapitalizationTypeNone];
+ [_traits setAutocorrectionType:UITextAutocorrectionTypeNo];
+ } else {
+ [_traits setAutocapitalizationType:toUITextAutocapitalize(_assistedNodeInformation.autocapitalizeType)];
+ [_traits setAutocorrectionType:_assistedNodeInformation.isAutocorrect ? UITextAutocorrectionTypeYes : UITextAutocorrectionTypeNo];
+ }
+
+ switch (_assistedNodeInformation.elementType) {
+ case InputType::Phone:
+ [_traits setKeyboardType:UIKeyboardTypePhonePad];
+ break;
+ case InputType::URL:
+ [_traits setKeyboardType:UIKeyboardTypeURL];
+ break;
+ case InputType::Email:
+ [_traits setKeyboardType:UIKeyboardTypeEmailAddress];
+ break;
+ case InputType::Number:
+ [_traits setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];
+ break;
+ case InputType::NumberPad:
+ [_traits setKeyboardType:UIKeyboardTypeNumberPad];
+ break;
+ default:
+ [_traits setKeyboardType:UIKeyboardTypeDefault];
+ }
+
+#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 100000
+ if (NSString *textContentType = [_formInputSession textContentType])
+ [_traits setTextContentType:textContentType];
+ else
+ [_traits setTextContentType:contentTypeFromFieldName(_assistedNodeInformation.autofillFieldName)];
+#endif
+
return _traits.get();
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes