Commit 82e163da authored by Stepan Khapugin's avatar Stepan Khapugin Committed by Commit Bot

[iOS] Add scribble support to omnibox.

Adds scribble support to the omnibox (not location bar).

Bug: 1098342
Change-Id: If9c1ead2506a77767d4a16a811e26f79ddfe9b89
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2340914
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarRobbie Gibson <rkgibson@google.com>
Cr-Commit-Position: refs/heads/master@{#796402}
parent e7d2227d
...@@ -42,6 +42,11 @@ const CGFloat kClearButtonSize = 28.0f; ...@@ -42,6 +42,11 @@ const CGFloat kClearButtonSize = 28.0f;
} // namespace } // namespace
#if defined(__IPHONE_14_0)
@interface OmniboxViewController (Scribble) <UIScribbleInteractionDelegate>
@end
#endif // defined(__IPHONE14_0)
@interface OmniboxViewController () <OmniboxTextFieldDelegate> { @interface OmniboxViewController () <OmniboxTextFieldDelegate> {
// Weak, acts as a delegate // Weak, acts as a delegate
OmniboxTextChangeDelegate* _textChangeDelegate; OmniboxTextChangeDelegate* _textChangeDelegate;
...@@ -122,6 +127,13 @@ const CGFloat kClearButtonSize = 28.0f; ...@@ -122,6 +127,13 @@ const CGFloat kClearButtonSize = 28.0f;
SetA11yLabelAndUiAutomationName(self.textField, IDS_ACCNAME_LOCATION, SetA11yLabelAndUiAutomationName(self.textField, IDS_ACCNAME_LOCATION,
@"Address"); @"Address");
#if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0
if (@available(iOS 14, *)) {
[self.textField
addInteraction:[[UIScribbleInteraction alloc] initWithDelegate:self]];
}
#endif // defined(__IPHONE_14_0)
} }
- (void)viewDidLoad { - (void)viewDidLoad {
...@@ -227,6 +239,17 @@ const CGFloat kClearButtonSize = 28.0f; ...@@ -227,6 +239,17 @@ const CGFloat kClearButtonSize = 28.0f;
return self.view.textField; return self.view.textField;
} }
- (void)prepareOmniboxForScribble {
[self.textField exitPreEditState];
[self.textField setText:[[NSAttributedString alloc] initWithString:@""]
userTextLength:0];
self.textField.placeholder = nil;
}
- (void)cleanupOmniboxAfterScribble {
self.textField.placeholder = l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT);
}
#pragma mark - OmniboxTextFieldDelegate #pragma mark - OmniboxTextFieldDelegate
- (BOOL)textField:(UITextField*)textField - (BOOL)textField:(UITextField*)textField
...@@ -588,4 +611,29 @@ const CGFloat kClearButtonSize = 28.0f; ...@@ -588,4 +611,29 @@ const CGFloat kClearButtonSize = 28.0f;
})); }));
} }
#pragma mark - UIScribbleInteractionDelegate
#if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0
- (void)scribbleInteractionWillBeginWriting:(UIScribbleInteraction*)interaction
API_AVAILABLE(ios(14.0)) {
if (self.textField.isPreEditing) {
[self.textField exitPreEditState];
[self.textField setText:[[NSAttributedString alloc] initWithString:@""]
userTextLength:0];
}
[self.textField clearAutocompleteText];
}
- (void)scribbleInteractionDidFinishWriting:(UIScribbleInteraction*)interaction
API_AVAILABLE(ios(14.0)) {
[self cleanupOmniboxAfterScribble];
// Dismiss any inline autocomplete. The user expectation is to not have it.
[self.textField clearAutocompleteText];
}
#endif // defined(__IPHONE_14_0)
@end @end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment