Commit 3765c417 authored by Jean-François Geyelin's avatar Jean-François Geyelin Committed by Commit Bot

[iOS] Factor out Keyboard Accessory View button creation.

Those buttons will eventually be used both in a Keyboard Accessory View (KAV)
(on iPhone) and as UITextInputAssistantItems (on iPad).

The toolbar_assistive_keyboard_views.* files are in their own directory.
A follow up CL will move all the code for the KAV in that directory.

Bug: None
Change-Id: I430791e16aaab98e1dce92f311e85f600370f420
Reviewed-on: https://chromium-review.googlesource.com/567509
Commit-Queue: Jean-François Geyelin <jif@chromium.org>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#486622}
parent a2405664
......@@ -6,6 +6,8 @@ source_set("toolbar") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"keyboard_accessory_view_delegate.h",
"keyboard_assist/toolbar_assistive_keyboard_views.h",
"keyboard_assist/toolbar_assistive_keyboard_views.mm",
"new_keyboard_accessory_view.h",
"new_keyboard_accessory_view.mm",
"new_tab_button.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.
#ifndef IOS_CHROME_BROWSER_UI_TOOLBAR_KEYBOARD_ASSIST_ASSISTIVE_KEYBOARD_VIEWS_H_
#define IOS_CHROME_BROWSER_UI_TOOLBAR_KEYBOARD_ASSIST_ASSISTIVE_KEYBOARD_VIEWS_H_
#import <UIKit/UIKIt.h>
@protocol KeyboardAccessoryViewDelegate;
NSArray<UIButton*>* ToolbarAssistiveKeyboardLeadingButtons(
id<KeyboardAccessoryViewDelegate> delegate);
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_KEYBOARD_ASSIST_ASSISTIVE_KEYBOARD_VIEWS_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_views.h"
#import "ios/chrome/browser/ui/toolbar/keyboard_accessory_view_delegate.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
UIButton* ButtonWitIcon(NSString* iconName) {
const CGFloat kButtonShadowOpacity = 0.35;
const CGFloat kButtonShadowRadius = 1.0;
const CGFloat kButtonShadowVerticalOffset = 1.0;
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTranslatesAutoresizingMaskIntoConstraints:NO];
UIImage* icon = [UIImage imageNamed:iconName];
[button setImage:icon forState:UIControlStateNormal];
button.layer.shadowColor = [UIColor blackColor].CGColor;
button.layer.shadowOffset = CGSizeMake(0, kButtonShadowVerticalOffset);
button.layer.shadowOpacity = kButtonShadowOpacity;
button.layer.shadowRadius = kButtonShadowRadius;
return button;
}
} // namespace
NSArray<UIButton*>* ToolbarAssistiveKeyboardLeadingButtons(
id<KeyboardAccessoryViewDelegate> delegate) {
UIButton* voiceSearchButton =
ButtonWitIcon(@"keyboard_accessory_voice_search");
[voiceSearchButton addTarget:delegate
action:@selector(keyboardAccessoryVoiceSearchTouchDown:)
forControlEvents:UIControlEventTouchDown];
SetA11yLabelAndUiAutomationName(voiceSearchButton,
IDS_IOS_KEYBOARD_ACCESSORY_VIEW_VOICE_SEARCH,
@"Voice Search");
[voiceSearchButton
addTarget:delegate
action:@selector(keyboardAccessoryVoiceSearchTouchUpInside:)
forControlEvents:UIControlEventTouchUpInside];
UIButton* cameraButton = ButtonWitIcon(@"keyboard_accessory_qr_scanner");
[cameraButton addTarget:delegate
action:@selector(keyboardAccessoryCameraSearchTouchUpInside:)
forControlEvents:UIControlEventTouchUpInside];
SetA11yLabelAndUiAutomationName(
cameraButton, IDS_IOS_KEYBOARD_ACCESSORY_VIEW_QR_CODE_SEARCH,
@"QR code Search");
return @[ voiceSearchButton, cameraButton ];
}
......@@ -10,9 +10,9 @@
#include "ios/chrome/browser/experimental_flags.h"
#include "ios/chrome/browser/ui/commands/ios_command_ids.h"
#include "ios/chrome/browser/ui/rtl_geometry.h"
#import "ios/chrome/browser/ui/toolbar/keyboard_assist/toolbar_assistive_keyboard_views.h"
#include "ios/chrome/browser/ui/ui_util.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -27,8 +27,6 @@
- (void)keyboardButtonPressed:(NSString*)title;
// Creates a button shortcut for |title|.
- (UIView*)shortcutButtonWithTitle:(NSString*)title;
// Creates a button with an icon based on |iconName|.
- (UIButton*)iconButton:(NSString*)iconName;
@end
......@@ -77,34 +75,16 @@
}
[self addSubview:shortcutStackView];
// Create buttons for voice search and camera search.
UIButton* voiceSearchButton =
[self iconButton:@"keyboard_accessory_voice_search"];
[voiceSearchButton addTarget:_delegate
action:@selector(keyboardAccessoryVoiceSearchTouchDown:)
forControlEvents:UIControlEventTouchDown];
SetA11yLabelAndUiAutomationName(voiceSearchButton,
IDS_IOS_KEYBOARD_ACCESSORY_VIEW_VOICE_SEARCH,
@"Voice Search");
[voiceSearchButton
addTarget:_delegate
action:@selector(keyboardAccessoryVoiceSearchTouchUpInside:)
forControlEvents:UIControlEventTouchUpInside];
UIButton* cameraButton = [self iconButton:@"keyboard_accessory_qr_scanner"];
[cameraButton addTarget:_delegate
action:@selector(keyboardAccessoryCameraSearchTouchUpInside:)
forControlEvents:UIControlEventTouchUpInside];
SetA11yLabelAndUiAutomationName(
cameraButton, IDS_IOS_KEYBOARD_ACCESSORY_VIEW_QR_CODE_SEARCH,
@"QR code Search");
// Create and add a stackview containing containing the buttons for voice
// search and camera search.
// Create and add a stackview containing the leading assistive buttons, i.e.
// Voice search and camera search.
NSArray<UIButton*>* leadingButtons =
ToolbarAssistiveKeyboardLeadingButtons(_delegate);
UIStackView* searchStackView = [[UIStackView alloc] init];
searchStackView.translatesAutoresizingMaskIntoConstraints = NO;
searchStackView.spacing = kBetweenSearchButtonSpacing;
[searchStackView addArrangedSubview:voiceSearchButton];
[searchStackView addArrangedSubview:cameraButton];
for (UIButton* button in leadingButtons) {
[searchStackView addArrangedSubview:button];
}
[self addSubview:searchStackView];
// Position the stack views.
......@@ -151,22 +131,6 @@
return button;
}
- (UIButton*)iconButton:(NSString*)iconName {
const CGFloat kButtonShadowOpacity = 0.35;
const CGFloat kButtonShadowRadius = 1.0;
const CGFloat kButtonShadowVerticalOffset = 1.0;
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTranslatesAutoresizingMaskIntoConstraints:NO];
UIImage* icon = [UIImage imageNamed:iconName];
[button setImage:icon forState:UIControlStateNormal];
button.layer.shadowColor = [UIColor blackColor].CGColor;
button.layer.shadowOffset = CGSizeMake(0, kButtonShadowVerticalOffset);
button.layer.shadowOpacity = kButtonShadowOpacity;
button.layer.shadowRadius = kButtonShadowRadius;
return button;
}
- (BOOL)enableInputClicksWhenVisible {
return YES;
}
......
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