Commit bc35d04e authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

Move ToolbarAssistiveKeyboardDelegate to its own object

ToolbarAssistiveKeyboardDelegate was implemented by the
WebToolbarController. This CL moves the implementation to a separate
object. It will allow the implementation to be moved to the omnibox
folder once it is refactored.

Bug: 784785
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I94c0fde654fe7b84332226f5d2d2827ade248651
Reviewed-on: https://chromium-review.googlesource.com/768735Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517372}
parent 703e7ee3
...@@ -6,6 +6,7 @@ source_set("keyboard_assist") { ...@@ -6,6 +6,7 @@ source_set("keyboard_assist") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
sources = [ sources = [
"toolbar_assistive_keyboard_delegate.h", "toolbar_assistive_keyboard_delegate.h",
"toolbar_assistive_keyboard_delegate.mm",
"toolbar_assistive_keyboard_views.h", "toolbar_assistive_keyboard_views.h",
"toolbar_assistive_keyboard_views.mm", "toolbar_assistive_keyboard_views.mm",
"toolbar_assistive_keyboard_views_utils.h", "toolbar_assistive_keyboard_views_utils.h",
...@@ -27,8 +28,11 @@ source_set("keyboard_assist") { ...@@ -27,8 +28,11 @@ source_set("keyboard_assist") {
"//ios/chrome/browser/ui", "//ios/chrome/browser/ui",
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/external_search:features", "//ios/chrome/browser/ui/external_search:features",
"//ios/chrome/browser/ui/omnibox:omnibox_internal",
"//ios/chrome/browser/ui/toolbar/public",
"//ios/public/provider/chrome/browser", "//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/external_search", "//ios/public/provider/chrome/browser/external_search",
"//ios/public/provider/chrome/browser/voice",
"//ui/base", "//ui/base",
"//ui/gfx", "//ui/gfx",
] ]
......
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
#import <UIKit/UIKIt.h> #import <UIKit/UIKIt.h>
@protocol ApplicationCommands;
@protocol BrowserCommands;
@class OmniboxTextFieldIOS;
// Delegate protocol for the KeyboardAccessoryView. // Delegate protocol for the KeyboardAccessoryView.
@protocol ToolbarAssistiveKeyboardDelegate @protocol ToolbarAssistiveKeyboardDelegate
...@@ -27,4 +31,14 @@ ...@@ -27,4 +31,14 @@
@end @end
// TODO(crbug.com/784819): Move this code to omnibox.
// Implementation of the ToolbarAssistiveKeyboardDelegate.
@interface ToolbarAssistiveKeyboardDelegateImpl
: NSObject<ToolbarAssistiveKeyboardDelegate>
@property(nonatomic, weak) id<ApplicationCommands, BrowserCommands> dispatcher;
@property(nonatomic, weak) OmniboxTextFieldIOS* omniboxTextField;
@end
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_KEYBOARD_ASSIST_TOOLBAR_ASSISTIVE_KEYBOARD_DELEGATE_H_ #endif // IOS_CHROME_BROWSER_UI_TOOLBAR_KEYBOARD_ASSIST_TOOLBAR_ASSISTIVE_KEYBOARD_DELEGATE_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/toolbar/keyboard_assist/toolbar_assistive_keyboard_delegate.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h"
#import "ios/chrome/browser/ui/commands/external_search_commands.h"
#import "ios/chrome/browser/ui/commands/start_voice_search_command.h"
#import "ios/chrome/browser/ui/omnibox/omnibox_text_field_ios.h"
#import "ios/chrome/browser/ui/toolbar/public/web_toolbar_controller_constants.h"
#import "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/public/provider/chrome/browser/voice/voice_search_provider.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation ToolbarAssistiveKeyboardDelegateImpl
@synthesize dispatcher = _dispatcher;
@synthesize omniboxTextField = _omniboxTextField;
#pragma mark - Public
- (void)keyboardAccessoryVoiceSearchTouchDown:(UIView*)view {
if (ios::GetChromeBrowserProvider()
->GetVoiceSearchProvider()
->IsVoiceSearchEnabled()) {
[self.dispatcher preloadVoiceSearch];
}
}
- (void)keyboardAccessoryVoiceSearchTouchUpInside:(UIView*)view {
if (ios::GetChromeBrowserProvider()
->GetVoiceSearchProvider()
->IsVoiceSearchEnabled()) {
base::RecordAction(base::UserMetricsAction("MobileCustomRowVoiceSearch"));
StartVoiceSearchCommand* command =
[[StartVoiceSearchCommand alloc] initWithOriginView:view];
[self.dispatcher startVoiceSearch:command];
}
}
- (void)keyboardAccessoryCameraSearchTouchUp {
base::RecordAction(base::UserMetricsAction("MobileCustomRowCameraSearch"));
[self.dispatcher showQRScanner];
}
- (void)keyboardAccessoryExternalSearchTouchUp {
[self.dispatcher launchExternalSearch];
}
- (void)keyPressed:(NSString*)title {
NSString* text = [self updateTextForDotCom:title];
[self.omniboxTextField insertTextWhileEditing:text];
}
#pragma mark - Private
// Insert 'com' without the period if cursor is directly after a period.
- (NSString*)updateTextForDotCom:(NSString*)text {
if ([text isEqualToString:kDotComTLD]) {
UITextRange* textRange = [self.omniboxTextField selectedTextRange];
NSInteger pos = [self.omniboxTextField
offsetFromPosition:[self.omniboxTextField beginningOfDocument]
toPosition:textRange.start];
if (pos > 0 &&
[[self.omniboxTextField text] characterAtIndex:pos - 1] == '.')
return [kDotComTLD substringFromIndex:1];
}
return text;
}
@end
...@@ -102,7 +102,6 @@ using ios::material::TimingFunction; ...@@ -102,7 +102,6 @@ using ios::material::TimingFunction;
@interface WebToolbarController ()<DropAndNavigateDelegate, @interface WebToolbarController ()<DropAndNavigateDelegate,
LocationBarDelegate, LocationBarDelegate,
OmniboxPopupPositioner, OmniboxPopupPositioner,
ToolbarAssistiveKeyboardDelegate,
ToolbarViewDelegate> { ToolbarViewDelegate> {
// Top-level view for web content. // Top-level view for web content.
UIView* _webToolbar; UIView* _webToolbar;
...@@ -159,6 +158,8 @@ using ios::material::TimingFunction; ...@@ -159,6 +158,8 @@ using ios::material::TimingFunction;
// The current browser state. // The current browser state.
ios::ChromeBrowserState* _browserState; // weak ios::ChromeBrowserState* _browserState; // weak
ToolbarAssistiveKeyboardDelegateImpl* _keyboardDelegate;
} }
// Accessor for cancel button. Handles lazy initialization. // Accessor for cancel button. Handles lazy initialization.
...@@ -227,8 +228,6 @@ using ios::material::TimingFunction; ...@@ -227,8 +228,6 @@ using ios::material::TimingFunction;
// restore the omnibox's background image. // restore the omnibox's background image.
- (void)animationDidStop:(CAAnimation*)anim finished:(BOOL)flag; - (void)animationDidStop:(CAAnimation*)anim finished:(BOOL)flag;
- (void)updateSnapshotWithWidth:(CGFloat)width forced:(BOOL)force; - (void)updateSnapshotWithWidth:(CGFloat)width forced:(BOOL)force;
// Insert 'com' without the period if cursor is directly after a period.
- (NSString*)updateTextForDotCom:(NSString*)text;
// Updates all buttons visibility, including the parent class buttons. // Updates all buttons visibility, including the parent class buttons.
- (void)updateToolbarButtons; - (void)updateToolbarButtons;
@end @end
...@@ -276,6 +275,9 @@ using ios::material::TimingFunction; ...@@ -276,6 +275,9 @@ using ios::material::TimingFunction;
font:[MDCTypography subheadFont] font:[MDCTypography subheadFont]
textColor:textColor textColor:textColor
tintColor:tintColor]; tintColor:tintColor];
_keyboardDelegate = [[ToolbarAssistiveKeyboardDelegateImpl alloc] init];
_keyboardDelegate.dispatcher = dispatcher;
_keyboardDelegate.omniboxTextField = _locationBarView.textField;
// Disable default drop interactions on the omnibox. // Disable default drop interactions on the omnibox.
// TODO(crbug.com/739903): Handle drop events once Chrome iOS is built with // TODO(crbug.com/739903): Handle drop events once Chrome iOS is built with
...@@ -523,7 +525,8 @@ using ios::material::TimingFunction; ...@@ -523,7 +525,8 @@ using ios::material::TimingFunction;
[self.view addSubview:_determinateProgressView]; [self.view addSubview:_determinateProgressView];
} }
ConfigureAssistiveKeyboardViews(_locationBarView.textField, kDotComTLD, self); ConfigureAssistiveKeyboardViews(_locationBarView.textField, kDotComTLD,
_keyboardDelegate);
// Add the handler to preload voice search when the voice search button is // Add the handler to preload voice search when the voice search button is
// tapped, but only if voice search is enabled. // tapped, but only if voice search is enabled.
...@@ -1062,42 +1065,6 @@ using ios::material::TimingFunction; ...@@ -1062,42 +1065,6 @@ using ios::material::TimingFunction;
} }
} }
#pragma mark -
#pragma mark ToolbarAssistiveKeyboardDelegate
- (void)keyboardAccessoryVoiceSearchTouchDown:(UIView*)view {
if (ios::GetChromeBrowserProvider()
->GetVoiceSearchProvider()
->IsVoiceSearchEnabled()) {
[self preloadVoiceSearch:view];
}
}
- (void)keyboardAccessoryVoiceSearchTouchUpInside:(UIView*)view {
if (ios::GetChromeBrowserProvider()
->GetVoiceSearchProvider()
->IsVoiceSearchEnabled()) {
base::RecordAction(UserMetricsAction("MobileCustomRowVoiceSearch"));
StartVoiceSearchCommand* command =
[[StartVoiceSearchCommand alloc] initWithOriginView:view];
[self.dispatcher startVoiceSearch:command];
}
}
- (void)keyboardAccessoryCameraSearchTouchUp {
base::RecordAction(UserMetricsAction("MobileCustomRowCameraSearch"));
[self.dispatcher showQRScanner];
}
- (void)keyboardAccessoryExternalSearchTouchUp {
[self.dispatcher launchExternalSearch];
}
- (void)keyPressed:(NSString*)title {
NSString* text = [self updateTextForDotCom:title];
[_locationBarView.textField insertTextWhileEditing:text];
}
#pragma mark - TabHistory Requirements #pragma mark - TabHistory Requirements
- (CGPoint)originPointForToolbarButton:(ToolbarButtonType)toolbarButton { - (CGPoint)originPointForToolbarButton:(ToolbarButtonType)toolbarButton {
...@@ -2344,19 +2311,6 @@ using ios::material::TimingFunction; ...@@ -2344,19 +2311,6 @@ using ios::material::TimingFunction;
} }
} }
- (NSString*)updateTextForDotCom:(NSString*)text {
if ([text isEqualToString:kDotComTLD]) {
UITextRange* textRange = [_locationBarView.textField selectedTextRange];
NSInteger pos = [_locationBarView.textField
offsetFromPosition:[_locationBarView.textField beginningOfDocument]
toPosition:textRange.start];
if (pos > 0 &&
[[_locationBarView.textField text] characterAtIndex:pos - 1] == '.')
return [kDotComTLD substringFromIndex:1];
}
return text;
}
- (void)loadURLForQuery:(NSString*)query { - (void)loadURLForQuery:(NSString*)query {
GURL searchURL; GURL searchURL;
metrics::OmniboxInputType type = AutocompleteInput::Parse( metrics::OmniboxInputType type = AutocompleteInput::Parse(
......
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