Commit 42f3f2e6 authored by Robbie Gibson's avatar Robbie Gibson Committed by Commit Bot

[iOS] Remove boolean return from Omnibox OnCopy

The boolean looks like it was needed because there was a bug in iOS 4
that didn't allow for this custom copy behavior. Now, the underlying
OnCopy method never returns false, and iOS 4 is no longer supported,
so this doesn't need t return a boolean. The copy will always happen.

Bug: 866446
Change-Id: I11f3b90b191d10442ab513d377756cacbfb898e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1869005
Commit-Queue: Robbie Gibson <rkgibson@google.com>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709060}
parent 78abc7fa
...@@ -25,7 +25,7 @@ class OmniboxTextChangeDelegate { ...@@ -25,7 +25,7 @@ class OmniboxTextChangeDelegate {
// Called when the Omnibox text field returns. (The "go" button is tapped.) // Called when the Omnibox text field returns. (The "go" button is tapped.)
virtual void OnAccept() = 0; virtual void OnAccept() = 0;
// Called when the Omnibox text field should copy. // Called when the Omnibox text field should copy.
virtual bool OnCopy() = 0; virtual void OnCopy() = 0;
// Clear the Omnibox text. // Clear the Omnibox text.
virtual void ClearText() = 0; virtual void ClearText() = 0;
// Called when the Omnibox text field should paste. // Called when the Omnibox text field should paste.
......
...@@ -10,11 +10,8 @@ ...@@ -10,11 +10,8 @@
@protocol OmniboxTextFieldDelegate<UITextFieldDelegate> @protocol OmniboxTextFieldDelegate<UITextFieldDelegate>
@optional @optional
// Called when the OmniboxTextFieldIOS performs a copy operation. Returns YES // Called when the OmniboxTextFieldIOS performs a copy operation.
// if the delegate handled the copy operation itself. If the delegate returns - (void)onCopy;
// NO, the field must perform the copy. Some platforms (iOS 4) do not expose an
// API that allows the delegate to handle the copy.
- (BOOL)onCopy;
// Called before the OmniboxTextFieldIOS performs a paste operation. // Called before the OmniboxTextFieldIOS performs a paste operation.
- (void)willPaste; - (void)willPaste;
......
...@@ -668,16 +668,13 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation"; ...@@ -668,16 +668,13 @@ NSString* const kOmniboxFadeAnimationKey = @"OmniboxFadeAnimation";
// preprending http:// to the copied URL if needed. // preprending http:// to the copied URL if needed.
- (void)copy:(id)sender { - (void)copy:(id)sender {
id<OmniboxTextFieldDelegate> delegate = [self delegate]; id<OmniboxTextFieldDelegate> delegate = [self delegate];
BOOL handled = NO;
// Must test for the onCopy method, since it's optional. // Must test for the onCopy method, since it's optional.
if ([delegate respondsToSelector:@selector(onCopy)]) if ([delegate respondsToSelector:@selector(onCopy)]) {
handled = [delegate onCopy]; [delegate onCopy];
} else {
// iOS 4 doesn't expose an API that allows the delegate to handle the copy
// operation, so let the superclass perform the copy if the delegate couldn't.
if (!handled)
[super copy:sender]; [super copy:sender];
}
} }
- (void)cut:(id)sender { - (void)cut:(id)sender {
......
...@@ -179,7 +179,7 @@ TEST_F(OmniboxTextFieldTest, CopyInPreedit) { ...@@ -179,7 +179,7 @@ TEST_F(OmniboxTextFieldTest, CopyInPreedit) {
[textfield_ becomeFirstResponder]; [textfield_ becomeFirstResponder];
[textfield_ enterPreEditState]; [textfield_ enterPreEditState];
EXPECT_TRUE([textfield_ canPerformAction:@selector(copy:) withSender:nil]); EXPECT_TRUE([textfield_ canPerformAction:@selector(copy:) withSender:nil]);
OCMExpect([delegateMock onCopy]).andReturn(YES); [delegateMock onCopy];
[textfield_ copy:nil]; [textfield_ copy:nil];
EXPECT_TRUE([textfield_.text isEqualToString:testString]); EXPECT_TRUE([textfield_.text isEqualToString:testString]);
[delegateMock verify]; [delegateMock verify];
...@@ -193,7 +193,7 @@ TEST_F(OmniboxTextFieldTest, CutInPreedit) { ...@@ -193,7 +193,7 @@ TEST_F(OmniboxTextFieldTest, CutInPreedit) {
[textfield_ becomeFirstResponder]; [textfield_ becomeFirstResponder];
[textfield_ enterPreEditState]; [textfield_ enterPreEditState];
EXPECT_TRUE([textfield_ canPerformAction:@selector(cut:) withSender:nil]); EXPECT_TRUE([textfield_ canPerformAction:@selector(cut:) withSender:nil]);
OCMExpect([delegateMock onCopy]).andReturn(YES); [delegateMock onCopy];
[textfield_ cut:nil]; [textfield_ cut:nil];
EXPECT_TRUE([textfield_.text isEqualToString:@""]); EXPECT_TRUE([textfield_.text isEqualToString:@""]);
[delegateMock verify]; [delegateMock verify];
......
...@@ -230,9 +230,9 @@ const CGFloat kClearButtonSize = 28.0f; ...@@ -230,9 +230,9 @@ const CGFloat kClearButtonSize = 28.0f;
return YES; return YES;
} }
- (BOOL)onCopy { - (void)onCopy {
DCHECK(_textChangeDelegate); DCHECK(_textChangeDelegate);
return _textChangeDelegate->OnCopy(); _textChangeDelegate->OnCopy();
} }
- (void)willPaste { - (void)willPaste {
......
...@@ -99,7 +99,7 @@ class OmniboxViewIOS : public OmniboxView, ...@@ -99,7 +99,7 @@ class OmniboxViewIOS : public OmniboxView,
void OnDidChange(bool processing_user_input) override; void OnDidChange(bool processing_user_input) override;
void OnWillEndEditing() override; void OnWillEndEditing() override;
void OnAccept() override; void OnAccept() override;
bool OnCopy() override; void OnCopy() override;
void ClearText() override; void ClearText() override;
void WillPaste() override; void WillPaste() override;
void OnDeleteBackward() override; void OnDeleteBackward() override;
......
...@@ -482,7 +482,7 @@ void OmniboxViewIOS::OnClear() { ...@@ -482,7 +482,7 @@ void OmniboxViewIOS::OnClear() {
[field_ exitPreEditState]; [field_ exitPreEditState];
} }
bool OmniboxViewIOS::OnCopy() { void OmniboxViewIOS::OnCopy() {
omnibox_interacted_while_focused_ = YES; omnibox_interacted_while_focused_ = YES;
UIPasteboard* board = [UIPasteboard generalPasteboard]; UIPasteboard* board = [UIPasteboard generalPasteboard];
NSString* selectedText = nil; NSString* selectedText = nil;
...@@ -521,7 +521,6 @@ bool OmniboxViewIOS::OnCopy() { ...@@ -521,7 +521,6 @@ bool OmniboxViewIOS::OnCopy() {
[item setObject:net::NSURLWithGURL(url) forKey:(NSString*)kUTTypeURL]; [item setObject:net::NSURLWithGURL(url) forKey:(NSString*)kUTTypeURL];
board.items = [NSArray arrayWithObject:item]; board.items = [NSArray arrayWithObject:item];
return true;
} }
void OmniboxViewIOS::WillPaste() { void OmniboxViewIOS::WillPaste() {
......
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