Commit fd8eed83 authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Commit Bot

Remove obsolete files in autofill.

Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I7f2df29563db41980615d9b8949de9bf6479f87e
Reviewed-on: https://chromium-review.googlesource.com/1161918Reviewed-by: default avatarElodie Banel <lod@chromium.org>
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580512}
parent 76d39f0f
...@@ -6,8 +6,6 @@ import("//ios/web/js_compile.gni") ...@@ -6,8 +6,6 @@ import("//ios/web/js_compile.gni")
source_set("manual_fill") { source_set("manual_fill") {
sources = [ sources = [
"accessory_provider.h",
"accessory_provider.mm",
"passwords_fetcher.h", "passwords_fetcher.h",
"passwords_fetcher.mm", "passwords_fetcher.mm",
] ]
...@@ -19,7 +17,6 @@ source_set("manual_fill") { ...@@ -19,7 +17,6 @@ source_set("manual_fill") {
"//ios/chrome/browser/autofill:autofill_shared", "//ios/chrome/browser/autofill:autofill_shared",
"//ios/chrome/browser/browser_state:browser_state", "//ios/chrome/browser/browser_state:browser_state",
"//ios/chrome/browser/passwords:passwords", "//ios/chrome/browser/passwords:passwords",
"//ios/chrome/browser/ui/autofill/manual_fill",
] ]
libs = [ "UIKit.framework" ] libs = [ "UIKit.framework" ]
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
......
// Copyright 2018 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_AUTOFILL_MANUAL_FILL_ACCESSORY_PROVIDER_H_
#define IOS_CHROME_BROWSER_AUTOFILL_MANUAL_FILL_ACCESSORY_PROVIDER_H_
#import "ios/chrome/browser/autofill/form_input_accessory_view_provider.h"
// Returns a default keyboard accessory view with entry points to manual
// fallbacks for form filling.
@interface ManualFillAccessoryProvider
: NSObject<FormInputAccessoryViewProvider>
@end
#endif // IOS_CHROME_BROWSER_AUTOFILL_MANUAL_FILL_ACCESSORY_PROVIDER_H_
// Copyright 2018 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/autofill/manual_fill/accessory_provider.h"
#include "base/feature_list.h"
#import "base/mac/foundation_util.h"
#include "components/autofill/core/common/autofill_features.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/keyboard_accessory_view.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface ManualFillAccessoryProvider ()
// The default accesory view to return in the update block.
@property(nonatomic, readonly) ManualFillKeyboardAccessoryView* accessoryView;
// Callback to update the accessory view.
@property(nonatomic, copy)
AccessoryViewReadyCompletion accessoryViewUpdateBlock;
@end
@implementation ManualFillAccessoryProvider
@synthesize accessoryViewDelegate = _accessoryViewDelegate;
@synthesize accessoryView = _accessoryView;
@synthesize accessoryViewUpdateBlock = _accessoryViewUpdateBlock;
#pragma mark - FormInputAccessoryViewProvider
- (void)retrieveAccessoryViewForForm:(const web::FormActivityParams&)params
webState:(web::WebState*)webState
accessoryViewUpdateBlock:
(AccessoryViewReadyCompletion)accessoryViewUpdateBlock {
DCHECK(accessoryViewUpdateBlock);
BOOL isManualFillEnabled =
base::FeatureList::IsEnabled(autofill::features::kAutofillManualFallback);
if (!isManualFillEnabled) {
accessoryViewUpdateBlock(nil, self);
return;
}
accessoryViewUpdateBlock(self.accessoryView, self);
self.accessoryViewUpdateBlock = accessoryViewUpdateBlock;
}
- (void)inputAccessoryViewControllerDidReset:
(FormInputAccessoryViewController*)controller {
self.accessoryViewUpdateBlock = nil;
}
- (void)resizeAccessoryView {
DCHECK(_accessoryViewUpdateBlock);
self.accessoryViewUpdateBlock(self.accessoryView, self);
}
#pragma mark - Getters
- (ManualFillKeyboardAccessoryView*)accessoryView {
if (!_accessoryView) {
_accessoryView =
[[ManualFillKeyboardAccessoryView alloc] initWithDelegate:nil];
}
return _accessoryView;
}
@end
// Copyright 2018 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_AUTOFILL_MANUAL_FILL_INPUT_ASSISTANT_MANUAL_FILL_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_AUTOFILL_MANUAL_FILL_INPUT_ASSISTANT_MANUAL_FILL_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/autofill/manual_fill/manual_fill_view_controller.h"
// This class allows the user to manual fill data by adding input assistant
// items to the first responder. Which then uses pop overs to show the
// available options. Currently the `inputAssistantItem` property is only
// available on iPads.
@interface InputAssistantManualFillViewController : ManualFillViewController
@end
#endif // IOS_CHROME_BROWSER_AUTOFILL_MANUAL_FILL_INPUT_ASSISTANT_MANUAL_FILL_VIEW_CONTROLLER_H_
// Copyright 2018 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/autofill/manual_fill/input_assistant_manual_fill_view_controller.h"
#import <WebKit/WebKit.h>
#import "ios/chrome/browser/autofill/manual_fill/password_picker_view_controller.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface InputAssistantManualfillViewController ()
/// The view controller presented or nil if none.
@property(nonatomic, weak) UIViewController* presentedPickerViewController;
@end
@implementation InputAssistantManualfillViewController
@synthesize presentedPickerViewController = _presentedPickerViewController;
#pragma mark - Life Cycle
- (void)viewDidLoad {
[super viewDidLoad];
NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self
selector:@selector(handleKeyboardWillChangeFrame:)
name:UIKeyboardWillChangeFrameNotification
object:nil];
}
#pragma mark - Keyboard Notifications
- (void)handleKeyboardWillChangeFrame:(NSNotification*)notification {
// TODO:(javierrobles) state why this needs to be in this notification.
[self overrideAccessories];
}
#pragma mark - ManualFillContentDelegate
- (void)userDidPickContent:(NSString*)content {
UIViewController* presentingViewController =
self.presentedPickerViewController.presentingViewController;
[presentingViewController dismissViewControllerAnimated:YES completion:nil];
[self fillLastSelectedFieldWithString:content];
// This code jump by to the next field by invoking a method on an Apple's owned
// bar button.
// TODO:(javierrobles) use the action instead of NSSelectorFromString.
// TODO:(javierrobles) add safety.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[[self.lastFirstResponder inputAssistantItem]
.trailingBarButtonGroups[1]
.barButtonItems.firstObject.target
performSelector:NSSelectorFromString(@"_nextTapped:")
withObject:nil];
#pragma clang diagnostic pop
}
#pragma mark Private Helpers
// Sets the accessory items of the keyboard to the custom options we want to
// show to the user. In this case an icon for passwords, an icon for addresses
// and a last one for credit cards.
- (void)overrideAccessories {
UIImage* keyImage = [UIImage imageNamed:@"ic_vpn_key"];
UIBarButtonItem* itemOne =
[[UIBarButtonItem alloc] initWithImage:keyImage
style:UIBarButtonItemStylePlain
target:self
action:@selector(presentCredentials:)];
UIImage* accountImage = [UIImage imageNamed:@"ic_account_circle"];
UIBarButtonItem* itemTwo =
[[UIBarButtonItem alloc] initWithImage:accountImage
style:UIBarButtonItemStylePlain
target:self
action:@selector(presentAddresses:)];
UIImage* creditCardImage = [UIImage imageNamed:@"ic_credit_card"];
UIBarButtonItem* itemThree =
[[UIBarButtonItem alloc] initWithImage:creditCardImage
style:UIBarButtonItemStylePlain
target:self
action:@selector(presentCards:)];
UIBarButtonItem* itemChoose =
[[UIBarButtonItem alloc] initWithTitle:@"Manual Fill"
style:UIBarButtonItemStylePlain
target:nil
action:nil];
UIBarButtonItemGroup* group = [[UIBarButtonItemGroup alloc]
initWithBarButtonItems:@[ itemOne, itemTwo, itemThree ]
representativeItem:itemChoose];
UITextInputAssistantItem* item =
[manual_fill::GetFirstResponderSubview(self.view) inputAssistantItem];
item.leadingBarButtonGroups = @[ group ];
}
// Presents the options for the manual fill as a popover.
//
// @param sender The item requesting the pop over, used for positioning.
- (void)presentPopOverForSender:(UIBarButtonItem*)sender {
[self updateActiveFieldID];
self.lastFirstResponder = manual_fill::GetFirstResponderSubview(self.view);
// TODO:(javierrobles) Test this on iOS 10.
// TODO:(javierrobles) Support / dismiss on rotation.
UIViewController* presenter;
UIView* buttonView;
id view = [sender valueForKey:@"view"];
if ([view isKindOfClass:[UIView class]]) {
buttonView = view;
presenter = buttonView.window.rootViewController;
while (presenter.childViewControllers.count) {
presenter = presenter.childViewControllers.firstObject;
}
}
if (!presenter) {
// TODO:(javierrobles) log an error.
return;
}
// TODO:(javierrobles) support addresses and credit cards.
PasswordPickerViewController* passwordPickerViewController =
[[PasswordPickerViewController alloc] initWithDelegate:self];
passwordPickerViewController.modalPresentationStyle =
UIModalPresentationPopover;
[presenter presentViewController:passwordPickerViewController
animated:YES
completion:nil];
UIPopoverPresentationController* presentationController =
passwordPickerViewController.popoverPresentationController;
presentationController.permittedArrowDirections =
UIPopoverArrowDirectionDown | UIPopoverArrowDirectionUp;
presentationController.sourceView = buttonView;
presentationController.sourceRect = buttonView.bounds;
self.presentedPickerViewController = passwordPickerViewController;
}
// Called when the user presses the "key" button. Causing a list of credentials
// to be shown.
//
// @param sender The bar button item pressed.
- (void)presentCredentials:(UIBarButtonItem*)sender {
[self presentPopOverForSender:sender];
}
// Called when the user presses the "account" button. Causing a list of
// addresses to be shown.
//
// @param sender The bar button item pressed.
- (void)presentAddresses:(UIBarButtonItem*)sender {
[self presentPopOverForSender:sender];
}
// Called when the user presses the "card" button. Causing a list of credit
// cards to be shown.
//
// @param sender The bar button item pressed.
- (void)presentCards:(UIBarButtonItem*)sender {
[self presentPopOverForSender:sender];
}
@end
// Copyright 2018 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_AUTOFILL_MANUAL_FILL_KEYBOARD_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_AUTOFILL_MANUAL_FILL_KEYBOARD_VIEW_CONTROLLER_H_
#import "ios/chrome/browser/autofill/manual_fill/manual_fill_view_controller.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/keyboard_accessory_view.h"
// Subclass of `ManualFillViewController` with the code that is specific for
// devices with no undocked keyboard.
@interface ManualFillKeyboardViewController
: ManualFillViewController<KeyboardAccessoryViewDelegate>
@end
#endif // IOS_CHROME_BROWSER_AUTOFILL_MANUAL_FILL_KEYBOARD_VIEW_CONTROLLER_H_
// Copyright 2018 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_AUTOFILL_MANUAL_FILL_MANUAL_FILL_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_AUTOFILL_MANUAL_FILL_MANUAL_FILL_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
#import <WebKit/WebKit.h>
namespace manual_fill {
// Searches for the first responder in the passed view hierarchy.
//
// @param view The view where the search is going to be done.
// @return The first responder or `nil` if it wasn't found.
UIView* GetFirstResponderSubview(UIView* view);
} // namespace manual_fill
// Protocol to pass any user choice in a picker to be filled.
@protocol ManualFillContentDelegate<NSObject>
// Called after the user manually selects an element to be used as the input.
//
// @param content The string that is interesting to the user in the current
// context.
- (void)userDidPickContent:(NSString*)content;
@end
// View Controller with the common logic for managing the manual fill views. As
// well as sending user input to the web view. Meant to be subclassed.
@interface ManualFillViewController
: UIViewController<ManualFillContentDelegate>
// The web view to test the prototype.
@property(nonatomic, readonly) WKWebView* webView;
// The last known first responder.
@property(nonatomic) UIView* lastFirstResponder;
// Asynchronously updates the activeFieldID to the current active element.
// Must be called before the web view resigns first responder.
- (void)updateActiveFieldID;
// Tries to inject the passed string into the web view last focused field.
//
// @param string The content to be injected. Must be JS encoded.
- (void)fillLastSelectedFieldWithString:(NSString*)string;
// Calls JS `focus()` on the last active element in an attemp to highlight it.
- (void)callFocusOnLastActiveField;
@end
#endif // IOS_CHROME_BROWSER_AUTOFILL_MANUAL_FILL_MANUAL_FILL_VIEW_CONTROLLER_H_
// Copyright 2018 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/autofill/manual_fill/manual_fill_view_controller.h"
#import <WebKit/WebKit.h>
#import "ios/chrome/common/ui_util/constraints_ui_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace manual_fill {
UIView* GetFirstResponderSubview(UIView* view) {
if ([view isFirstResponder])
return view;
for (UIView* subview in [view subviews]) {
UIView* firstResponder = GetFirstResponderSubview(subview);
if (firstResponder)
return firstResponder;
}
return nil;
}
} // namespace manual_fill
@interface ManualfillViewController ()
// The last recorded active field identifier, used to interact with the web
// view (i.e. overwrite the input of the field).
@property(nonatomic, strong) NSString* activeFieldID;
@end
@implementation ManualfillViewController
@synthesize activeFieldID = _activeFieldID;
@synthesize lastFirstResponder = _lastFirstResponder;
@synthesize webView = _webView;
- (void)viewDidLoad {
[super viewDidLoad];
_webView = [[WKWebView alloc] initWithFrame:self.view.bounds
configuration:[self webViewConfiguration]];
[self.view addSubview:self.webView];
self.webView.translatesAutoresizingMaskIntoConstraints = NO;
AddSameConstraints(self.webView, self.view);
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSURL* signupURL = [NSURL URLWithString:@"https://appleid.apple.com/account"];
NSURLRequest* request = [NSURLRequest requestWithURL:signupURL];
[self.webView loadRequest:request];
}
#pragma mark - ManualFillContentDelegate
- (void)userDidPickContent:(NSString*)content {
// No-op. Subclasess can override.
}
#pragma mark - Document Interaction
- (void)updateActiveFieldID {
__weak __typeof(self) weakSelf = self;
NSString* javaScriptQuery = @"__gCrWeb.manualFill.activeElementId()";
[self.webView evaluateJavaScript:javaScriptQuery
completionHandler:^(id result, NSError* error) {
NSLog(@"result: %@", [result description]);
weakSelf.activeFieldID = result;
[weakSelf callFocusOnLastActiveField];
}];
}
- (void)fillLastSelectedFieldWithString:(NSString*)string {
NSString* javaScriptQuery =
[NSString stringWithFormat:
@"__gCrWeb.manualFill.setValueForElementId(\"%@\", \"%@\")",
string, self.activeFieldID];
[self.webView evaluateJavaScript:javaScriptQuery completionHandler:nil];
}
- (void)callFocusOnLastActiveField {
NSString* javaScriptQuery =
[NSString stringWithFormat:@"document.getElementById(\"%@\").focus()",
self.activeFieldID];
[self.webView evaluateJavaScript:javaScriptQuery completionHandler:nil];
}
#pragma mark JS Injection
// Returns an NSString with the contents of the files passed. It is assumed the
// files are of type ".js" and they are in the main bundle.
- (NSString*)joinedJSFilesWithFilenames:(NSArray<NSString*>*)filenames {
NSMutableString* fullScript = [NSMutableString string];
for (NSString* filename in filenames) {
NSString* path =
[[NSBundle mainBundle] pathForResource:filename ofType:@"js"];
NSData* scriptData = [[NSData alloc] initWithContentsOfFile:path];
NSString* scriptString =
[[NSString alloc] initWithData:scriptData
encoding:NSUTF8StringEncoding];
[fullScript appendFormat:@"%@\n", scriptString];
}
return fullScript;
}
- (NSString*)earlyJSStringMainFrame {
NSArray* filenames = @[
@"main_frame_web_bundle", @"chrome_bundle_main_frame",
@"manual_fill_controller"
];
return [self joinedJSFilesWithFilenames:filenames];
}
- (NSString*)earlyJSStringAllFrames {
NSArray* filenames = @[
@"all_frames_web_bundle",
@"chrome_bundle_all_frames",
];
return [self joinedJSFilesWithFilenames:filenames];
}
// Returns a WKWebViewConfiguration with early scripts for the main frame and
// for all frames.
- (WKWebViewConfiguration*)webViewConfiguration {
WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init];
WKUserScript* userScriptAllFrames = [[WKUserScript alloc]
initWithSource:[self earlyJSStringAllFrames]
injectionTime:WKUserScriptInjectionTimeAtDocumentStart
forMainFrameOnly:NO];
[configuration.userContentController addUserScript:userScriptAllFrames];
WKUserScript* userScriptMainFrame = [[WKUserScript alloc]
initWithSource:[self earlyJSStringMainFrame]
injectionTime:WKUserScriptInjectionTimeAtDocumentStart
forMainFrameOnly:YES];
[configuration.userContentController addUserScript:userScriptMainFrame];
return configuration;
}
@end
// Copyright 2018 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_AUTOFILL_MANUAL_FILL_PASSWORD_PICKER_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_AUTOFILL_MANUAL_FILL_PASSWORD_PICKER_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
@protocol ManualFillContentDelegate;
// This class presents a list of usernames and passwords in a collection view.
@interface PasswordPickerViewController
: UICollectionViewController<UICollectionViewDelegateFlowLayout>
// Unavailable. Use `initWithDelegate:`.
- (instancetype)init NS_UNAVAILABLE;
// Unavailable. Use `initWithDelegate:`.
- (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout*)layout
NS_UNAVAILABLE;
// Unavailable. Use `initWithDelegate:`.
- (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE;
// Unavailable. Use `initWithDelegate:`.
- (instancetype)initWithNibName:(NSString*)nibNameOrNil
bundle:(NSBundle*)nibBundleOrNil NS_UNAVAILABLE;
// Instances an object with the desired delegate.
//
// @param delegate The object interested in the user selection from the
// presented options.
// @return A fresh object with the passed delegate.
- (instancetype)initWithDelegate:(id<ManualFillContentDelegate>)delegate
NS_DESIGNATED_INITIALIZER;
@end
#endif // IOS_CHROME_BROWSER_AUTOFILL_MANUAL_FILL_PASSWORD_PICKER_VIEW_CONTROLLER_H_
// Copyright 2018 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/autofill/manual_fill/password_picker_view_controller.h"
#import "ios/chrome/browser/autofill/manual_fill/manual_fill_view_controller.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// The width for the cells in this collection view.
static CGFloat CellWitdth = 200.0;
// The height for the cells in this collection view.
static CGFloat CellHeight = 60.0;
// The reuse identifier for UICollectionViewCells in this collection.
static NSString* CellReuseId = @"CellReuseId";
} // namespace
@interface PasswordPickerViewController ()
// The content to display in the collection view.
@property(nonatomic) NSArray<NSString*>* content;
// The delegate in charge of using the content selected by the user.
@property(nonatomic, readonly, weak) id<ManualFillContentDelegate> delegate;
@end
@implementation PasswordPickerViewController
@synthesize content = _content;
@synthesize delegate = _delegate;
- (instancetype)initWithDelegate:(id<ManualFillContentDelegate>)delegate {
_delegate = delegate;
UICollectionViewFlowLayout* flowLayout =
[[UICollectionViewFlowLayout alloc] init];
flowLayout.minimumInteritemSpacing = 0;
flowLayout.minimumLineSpacing = 1;
flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
flowLayout.estimatedItemSize = CGSizeMake(CellWitdth, CellHeight);
return [super initWithCollectionViewLayout:flowLayout];
}
- (void)viewDidLoad {
[super viewDidLoad];
// TODO:(javierrobles) abstract this color. It was taken arbitrarly.
self.collectionView.backgroundColor = [UIColor colorWithRed:250.0 / 255.0
green:250.0 / 255.0
blue:250.0 / 255.0
alpha:1.0];
[self.collectionView registerClass:[UICollectionViewCell class]
forCellWithReuseIdentifier:CellReuseId];
if (@available(iOS 11.0, *)) {
self.collectionView.contentInsetAdjustmentBehavior =
UIScrollViewContentInsetAdjustmentAlways;
}
self.content = @[ @"Username", @"********" ];
}
- (CGSize)preferredContentSize {
return CGSizeMake(250, 144);
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:
(UICollectionView*)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView*)collectionView
numberOfItemsInSection:(NSInteger)section {
return [self.content count];
}
- (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView
cellForItemAtIndexPath:(NSIndexPath*)indexPath {
// TODO:(javierrobles) create a custom cell supporting a label.
UICollectionViewCell* cell =
[collectionView dequeueReusableCellWithReuseIdentifier:CellReuseId
forIndexPath:indexPath];
UILabel* titleLabel = [[UILabel alloc]
initWithFrame:CGRectMake(0.0, 0.0, CellWitdth, CellHeight)];
titleLabel.text = _content[indexPath.item];
[cell.contentView addSubview:titleLabel];
return cell;
}
#pragma mark - UICollectionViewDelegateFlowLayout
- (UIEdgeInsets)collectionView:(UICollectionView*)collectionView
layout:(UICollectionViewLayout*)collectionViewLayout
insetForSectionAtIndex:(NSInteger)section {
CGFloat horizontalInset =
(collectionView.bounds.size.width - CellWitdth) / 2.0;
return UIEdgeInsetsMake(0.0, horizontalInset, 0.0, horizontalInset);
}
- (void)collectionView:(UICollectionView*)collectionView
didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
UICollectionViewCell* cell =
[collectionView cellForItemAtIndexPath:indexPath];
UIView* firstSubview = cell.contentView.subviews.firstObject;
if ([firstSubview isKindOfClass:[UILabel class]]) {
[self.delegate userDidPickContent:((UILabel*)firstSubview).text];
}
}
@end
// Copyright 2018 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.
goog.provide('__crWeb.manualFill');
/* Beginning of anonymous object. */
(function() {
/**
* Namespace for this file. It depends on |__gCrWeb| having already been
* injected.
*/
__gCrWeb.manualFill = {};
__gCrWeb['manualFill'] = __gCrWeb.manualFill;
/**
* Returns the identifier to be used with `setValueForElementId`.
*
* @return {string} The id of the active element.
*/
__gCrWeb.manualFill.activeElementId = function() {
var activeElementId = document.activeElement.id;
return activeElementId;
};
/**
* Sets the value passed for the element with the identifier passed.
*
* @param {string} value The input to set in the element with the identifier.
* @param {string} identifier The identifier of the element, found with
* `activeElementId`.
*/
__gCrWeb.manualFill.setValueForElementId = function(value, identifier) {
if (!identifier) {
return
}
var field = document.getElementById(identifier);
if (!field) {
return;
}
if (!value || value.length === 0) {
return;
}
__gCrWeb.fill.setInputElementValue(value, field);
};
}()); // End of anonymous object
...@@ -8,8 +8,6 @@ source_set("manual_fill") { ...@@ -8,8 +8,6 @@ source_set("manual_fill") {
sources = [ sources = [
"keyboard_accessory_view.h", "keyboard_accessory_view.h",
"keyboard_accessory_view.mm", "keyboard_accessory_view.mm",
"keyboard_background_view.h",
"keyboard_background_view.mm",
] ]
deps = [ deps = [
"//base", "//base",
......
// Copyright 2018 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_AUTOFILL_MANUAL_FILL_KEYBOARD_BACKGROUND_VIEW_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_KEYBOARD_BACKGROUND_VIEW_H_
#import <UIKit/UIKit.h>
@protocol ManualFillKeyboardAccessoryViewDelegate;
// View to show behind the keyboard. It contains an Accessory View and a
// Container for more detailed content.
@interface KeyboardBackgroundView : UIView
// View to contain a picker (addresses, credit cards or credentials) for the
// user.
@property(nonatomic, strong) UIView* containerView;
// Unavailable. Use `initWithDelegate:`.
- (instancetype)init NS_UNAVAILABLE;
// Unavailable. Use `initWithDelegate:`.
- (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE;
// Unavailable. Use `initWithDelegate:`.
- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
// Unavailable. Use `initWithDelegate:`.
- (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE;
// Instances an object with the desired delegate.
//
// @param delegate The delegate for this object.
// @return A fresh object with the passed delegate.
- (instancetype)initWithDelegate:
(id<ManualFillKeyboardAccessoryViewDelegate>)delegate
NS_DESIGNATED_INITIALIZER;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_KEYBOARD_BACKGROUND_VIEW_H_
// Copyright 2018 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/autofill/manual_fill/keyboard_background_view.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/keyboard_accessory_view.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation KeyboardBackgroundView
@synthesize containerView = _containerView;
- (instancetype)initWithDelegate:
(id<ManualFillKeyboardAccessoryViewDelegate>)delegate {
self = [super initWithFrame:CGRectZero];
if (self) {
// TODO:(javierrobles) abstract this color to a constant.
self.backgroundColor = [UIColor colorWithRed:245.0 / 255.0
green:245.0 / 255.0
blue:245.0 / 255.0
alpha:1.0];
ManualFillKeyboardAccessoryView* toolbar =
[[ManualFillKeyboardAccessoryView alloc] initWithDelegate:delegate];
toolbar.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:toolbar];
UIView* containerView = [[UIView alloc] init];
containerView.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:containerView];
_containerView = containerView;
[NSLayoutConstraint activateConstraints:@[
[toolbar.leadingAnchor constraintEqualToAnchor:self.leadingAnchor
constant:0.0],
[toolbar.trailingAnchor constraintEqualToAnchor:self.trailingAnchor],
[toolbar.topAnchor constraintEqualToAnchor:self.topAnchor],
[toolbar.heightAnchor constraintEqualToConstant:44],
[containerView.topAnchor constraintEqualToAnchor:toolbar.bottomAnchor],
[containerView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor],
[containerView.leadingAnchor constraintEqualToAnchor:self.leadingAnchor],
[containerView.trailingAnchor
constraintEqualToAnchor:self.trailingAnchor],
]];
}
return self;
}
@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