Commit add28426 authored by Elodie Banel's avatar Elodie Banel Committed by Commit Bot

Remove dead left/right frame code in FormInputAccessoryView.

Follow up to https://chromium-review.googlesource.com/c/chromium/src/+/721325

Bug: none
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I9caba1853bb8df851ceea954da9a222b82d6f3f3
Reviewed-on: https://chromium-review.googlesource.com/758653Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Commit-Queue: Elodie Banel <lod@chromium.org>
Cr-Commit-Position: refs/heads/master@{#515915}
parent fd687b32
......@@ -14,20 +14,14 @@
// way of the playInputClick method.
@interface FormInputAccessoryView : UIView<UIInputViewAudioFeedback>
// Initializes with |delegate|.
- (instancetype)initWithDelegate:(id<FormInputAccessoryViewDelegate>)delegate;
// Sets up the view with the given |customView|. Navigation controls are shown
// and use |delegate| for actions.
- (void)setUpWithNavigationDelegate:(id<FormInputAccessoryViewDelegate>)delegate
customView:(UIView*)customView;
// Initializes with |frame| to show |customView|. Navigation controls are not
// Sets up the view with the given |customView|. Navigation controls are not
// shown.
- (instancetype)initWithFrame:(CGRect)frame customView:(UIView*)customView;
// Initializes the view with the given |customView|.
// If the size of |rightFrame| is non-zero, the view will be split into two
// parts with |leftFrame| and |rightFrame|. Otherwise the Autofill view will
// be shown in |leftFrame|.
- (void)initializeViewWithCustomView:(UIView*)customView
leftFrame:(CGRect)leftFrame
rightFrame:(CGRect)rightFrame;
- (void)setUpWithCustomView:(UIView*)customView;
@end
......
......@@ -24,9 +24,6 @@ namespace {
// The alpha value of the background color.
const CGFloat kBackgroundColorAlpha = 1.0;
// Horizontal margin around the custom view.
const CGFloat kCustomViewHorizontalMargin = 2;
// The width of the separators of the previous and next buttons.
const CGFloat kNavigationButtonSeparatorWidth = 1;
......@@ -36,17 +33,13 @@ const CGFloat kNavigationAreaSeparatorShadowWidth = 2;
// The width of the navigation area / custom view separator asset.
const CGFloat kNavigationAreaSeparatorWidth = 1;
// Returns YES if the keyboard close button should be shown on the accessory.
BOOL ShouldShowCloseButton() {
return !IsIPadIdiom();
}
} // namespace
@interface FormInputAccessoryView ()
// Returns a view that shows navigation buttons.
- (UIView*)viewForNavigationButtons;
- (UIView*)viewForNavigationButtonsUsingDelegate:
(id<FormInputAccessoryViewDelegate>)delegate;
// Adds a navigation button for Autofill in |view| that has |normalImage| for
// state UIControlStateNormal, a |pressedImage| for states
......@@ -71,36 +64,19 @@ BOOL ShouldShowCloseButton() {
@end
@implementation FormInputAccessoryView {
// Delegate of this view.
__weak id<FormInputAccessoryViewDelegate> _delegate;
}
- (instancetype)initWithDelegate:(id<FormInputAccessoryViewDelegate>)delegate {
DCHECK(delegate);
self = [super initWithFrame:CGRectZero];
if (self) {
_delegate = delegate;
}
return self;
}
@implementation FormInputAccessoryView
- (instancetype)initWithFrame:(CGRect)frame customView:(UIView*)customView {
self = [super initWithFrame:frame];
if (self) {
customView.frame =
CGRectMake(0, 0, CGRectGetWidth(frame), CGRectGetHeight(frame));
- (void)setUpWithCustomView:(UIView*)customView {
[self addSubview:customView];
customView.translatesAutoresizingMaskIntoConstraints = NO;
AddSameConstraints(self, customView);
[[self class] addBackgroundImageInView:self
withImageName:@"autofill_keyboard_background"];
}
return self;
}
- (void)initializeViewWithCustomView:(UIView*)customView
leftFrame:(CGRect)leftFrame
rightFrame:(CGRect)rightFrame {
- (void)setUpWithNavigationDelegate:(id<FormInputAccessoryViewDelegate>)delegate
customView:(UIView*)customView {
self.translatesAutoresizingMaskIntoConstraints = NO;
UIView* customViewContainer = [[UIView alloc] init];
customViewContainer.translatesAutoresizingMaskIntoConstraints = NO;
......@@ -113,56 +89,10 @@ BOOL ShouldShowCloseButton() {
customView.translatesAutoresizingMaskIntoConstraints = NO;
AddSameConstraints(customViewContainer, customView);
UIView* navViewContent = [self viewForNavigationButtons];
UIView* navViewContent =
[self viewForNavigationButtonsUsingDelegate:delegate];
[navView addSubview:navViewContent];
bool splitKeyboard = CGRectGetWidth(rightFrame) != 0;
if (splitKeyboard) {
NSString* navViewBackgroundImageName = nil;
NSString* customViewContainerBackgroundImageName = nil;
BOOL isRTL = base::i18n::IsRTL();
if (isRTL) {
navView.frame = leftFrame;
navViewBackgroundImageName = @"autofill_keyboard_background_left";
customViewContainer.frame = rightFrame;
customViewContainerBackgroundImageName =
@"autofill_keyboard_background_right";
} else {
customViewContainer.frame = leftFrame;
customViewContainerBackgroundImageName =
@"autofill_keyboard_background_left";
navView.frame = rightFrame;
navViewBackgroundImageName = @"autofill_keyboard_background_right";
}
[[self class]
addBackgroundImageInView:customViewContainer
withImageName:customViewContainerBackgroundImageName];
[[self class] addBackgroundImageInView:navView
withImageName:navViewBackgroundImageName];
[NSLayoutConstraint activateConstraints:@[
[navViewContent.topAnchor constraintEqualToAnchor:navView.topAnchor],
[navViewContent.bottomAnchor
constraintEqualToAnchor:navView.bottomAnchor],
[navViewContent.leadingAnchor
constraintGreaterThanOrEqualToAnchor:navView.leadingAnchor],
[navViewContent.trailingAnchor
constraintEqualToAnchor:navView.trailingAnchor],
[customView.topAnchor
constraintEqualToAnchor:customViewContainer.topAnchor],
[customView.bottomAnchor
constraintEqualToAnchor:customViewContainer.bottomAnchor],
[customView.leadingAnchor
constraintGreaterThanOrEqualToAnchor:customViewContainer
.leadingAnchor],
[customView.trailingAnchor
constraintEqualToAnchor:customViewContainer.trailingAnchor
constant:kCustomViewHorizontalMargin],
]];
} else {
AddSameConstraints(navView, navViewContent);
[[self class] addBackgroundImageInView:self
......@@ -184,7 +114,6 @@ BOOL ShouldShowCloseButton() {
[navView.topAnchor constraintEqualToAnchor:layoutGuide.topAnchor],
[navView.bottomAnchor constraintEqualToAnchor:layoutGuide.bottomAnchor],
]];
}
}
#pragma mark -
......@@ -202,7 +131,8 @@ UIImage* ButtonImage(NSString* name) {
return StretchableImageFromUIImage(rawImage, 1, 0);
}
- (UIView*)viewForNavigationButtons {
- (UIView*)viewForNavigationButtonsUsingDelegate:
(id<FormInputAccessoryViewDelegate>)delegate {
UIView* navView = [[UIView alloc] init];
navView.translatesAutoresizingMaskIntoConstraints = NO;
......@@ -214,7 +144,7 @@ UIImage* ButtonImage(NSString* name) {
addKeyboardNavButtonWithNormalImage:ButtonImage(@"autofill_prev")
pressedImage:ButtonImage(@"autofill_prev_pressed")
disabledImage:ButtonImage(@"autofill_prev_inactive")
target:_delegate
target:delegate
action:@selector
(selectPreviousElementWithButtonPress)
enabled:NO
......@@ -232,7 +162,7 @@ UIImage* ButtonImage(NSString* name) {
addKeyboardNavButtonWithNormalImage:ButtonImage(@"autofill_next")
pressedImage:ButtonImage(@"autofill_next_pressed")
disabledImage:ButtonImage(@"autofill_next_inactive")
target:_delegate
target:delegate
action:@selector
(selectNextElementWithButtonPress)
enabled:NO
......@@ -240,41 +170,22 @@ UIImage* ButtonImage(NSString* name) {
[nextButton setAccessibilityLabel:l10n_util::GetNSString(
IDS_IOS_AUTOFILL_ACCNAME_NEXT_FIELD)];
[_delegate fetchPreviousAndNextElementsPresenceWithCompletionHandler:
^(BOOL hasPreviousElement, BOOL hasNextElement) {
[delegate fetchPreviousAndNextElementsPresenceWithCompletionHandler:^(
BOOL hasPreviousElement, BOOL hasNextElement) {
previousButton.enabled = hasPreviousElement;
nextButton.enabled = hasNextElement;
}];
NSString* horizontalConstraint =
@"H:|[separator1(==areaSeparatorWidth)][previousButton]["
@"separator2(==buttonSeparatorWidth)][nextButton]";
NSMutableArray<NSString*>* constraints =
[NSMutableArray arrayWithObjects:@"V:|-(topPadding)-[separator1]|",
@"V:|-(topPadding)-[previousButton]|",
@"V:|-(topPadding)-[previousButton]|",
@"V:|-(topPadding)-[separator2]|",
@"V:|-(topPadding)-[nextButton]|", nil];
NSMutableDictionary* views = [NSMutableDictionary
dictionaryWithObjectsAndKeys:separator, @"separator1", previousButton,
@"previousButton", internalSeparator,
@"separator2", nextButton, @"nextButton",
nil];
if (ShouldShowCloseButton()) {
// Add internal separator.
UIView* internalSeparator2 =
[[self class] createImageViewWithImageName:@"autofill_middle_sep"
inView:navView];
UIButton* closeButton =
[self addKeyboardNavButtonWithNormalImage:ButtonImage(@"autofill_close")
pressedImage:ButtonImage(
@"autofill_close_pressed")
UIButton* closeButton = [self
addKeyboardNavButtonWithNormalImage:ButtonImage(@"autofill_close")
pressedImage:ButtonImage(@"autofill_close_pressed")
disabledImage:nil
target:_delegate
target:delegate
action:@selector
(closeKeyboardWithButtonPress)
enabled:YES
......@@ -283,27 +194,32 @@ UIImage* ButtonImage(NSString* name) {
setAccessibilityLabel:l10n_util::GetNSString(
IDS_IOS_AUTOFILL_ACCNAME_HIDE_KEYBOARD)];
[views setObject:internalSeparator2 forKey:@"internalSeparator2"];
[views setObject:closeButton forKey:@"closeButton"];
[constraints addObject:@"V:|-(topPadding)-[closeButton]|"];
[constraints addObject:@"V:|-(topPadding)-[internalSeparator2]|"];
horizontalConstraint =
[horizontalConstraint stringByAppendingString:
@"[internalSeparator2(buttonSeparatorWidth)]["
@"closeButton]"];
}
[constraints addObject:[horizontalConstraint stringByAppendingString:@"|"]];
NSDictionary* metrics = @{
ApplyVisualConstraintsWithMetrics(
@[
(@"H:|[separator1(==areaSeparatorWidth)][previousButton][separator2(=="
@"buttonSeparatorWidth)][nextButton][internalSeparator2("
@"buttonSeparatorWidth)][closeButton]|"),
@"V:|-(topPadding)-[separator1]|",
@"V:|-(topPadding)-[previousButton]|",
@"V:|-(topPadding)-[previousButton]|",
@"V:|-(topPadding)-[separator2]|", @"V:|-(topPadding)-[nextButton]|",
@"V:|-(topPadding)-[internalSeparator2]|",
@"V:|-(topPadding)-[closeButton]|"
],
@{
@"separator1" : separator,
@"previousButton" : previousButton,
@"separator2" : internalSeparator,
@"nextButton" : nextButton,
@"internalSeparator2" : internalSeparator2,
@"closeButton" : closeButton
},
@{
@"areaSeparatorWidth" : @(kNavigationAreaSeparatorWidth),
@"buttonSeparatorWidth" : @(kNavigationButtonSeparatorWidth),
@"topPadding" : @(1)
};
ApplyVisualConstraintsWithMetrics(constraints, views, metrics);
});
return navView;
}
......
......@@ -121,43 +121,6 @@ NSArray* FindDescendantToolbarItemsForActionName(
return toolbarItems;
}
// Computes the frame of each part of the accessory view of the keyboard. It is
// assumed that the keyboard has either two parts (when it is split) or one part
// (when it is merged).
//
// If there are two parts, the frame of the left part is returned in
// |leftFrame| and the frame of the right part is returned in |rightFrame|.
// If there is only one part, the frame is returned in |leftFrame| and
// |rightFrame| has size zero.
//
// Heuristics are used to compute this information. It returns false if the
// number of |inputAccessoryView.subviews| is not 2.
bool ComputeFramesOfKeyboardParts(UIView* inputAccessoryView,
CGRect* leftFrame,
CGRect* rightFrame) {
// It is observed (on iOS 6) there are always two subviews in the original
// input accessory view. When the keyboard is split, each subview represents
// one part of the accesssary view of the keyboard. When the keyboard is
// merged, one subview has the same frame as that of the whole accessory view
// and the other has zero size with the screen width as origin.x.
// The computation here is based on this observation.
NSArray* subviews = inputAccessoryView.subviews;
if (subviews.count != 2)
return false;
CGRect first_frame = static_cast<UIView*>(subviews[0]).frame;
CGRect second_frame = static_cast<UIView*>(subviews[1]).frame;
if (CGRectGetMinX(first_frame) < CGRectGetMinX(second_frame) ||
CGRectGetWidth(second_frame) == 0) {
*leftFrame = first_frame;
*rightFrame = second_frame;
} else {
*rightFrame = first_frame;
*leftFrame = second_frame;
}
return true;
}
} // namespace
@interface FormInputAccessoryViewController ()
......@@ -321,8 +284,8 @@ bool ComputeFramesOfKeyboardParts(UIView* inputAccessoryView,
- (void)showCustomInputAccessoryView:(UIView*)view {
DCHECK(view);
if (IsIPadIdiom()) {
// On iPads running iOS 9 or later, there's no inputAccessoryView available
// so we attach the custom view directly to the keyboard view instead.
// On iPad, there's no inputAccessoryView available, so we attach the custom
// view directly to the keyboard view instead.
[_customAccessoryView removeFromSuperview];
// If the keyboard isn't visible don't show the custom view.
......@@ -346,30 +309,26 @@ bool ComputeFramesOfKeyboardParts(UIView* inputAccessoryView,
}
_suggestionsHaveBeenShown = YES;
_customAccessoryView = [[FormInputAccessoryView alloc] init];
[_customAccessoryView setUpWithCustomView:view];
CGFloat height = autofill::kInputAccessoryHeight;
CGRect contentFrame = self.webViewProxy.frame;
CGRect frame = CGRectMake(contentFrame.origin.x, -height,
_customAccessoryView.frame = CGRectMake(contentFrame.origin.x, -height,
contentFrame.size.width, height);
_customAccessoryView =
[[FormInputAccessoryView alloc] initWithFrame:frame customView:view];
UIView* keyboardView = [self getKeyboardView];
DCHECK(keyboardView);
[keyboardView addSubview:_customAccessoryView];
} else {
// On all other versions, the custom view replaces the default UI of the
// On iPhone, the custom view replaces the default UI of the
// inputAccessoryView.
[self restoreDefaultInputAccessoryView];
CGRect leftFrame;
CGRect rightFrame;
UIView* inputAccessoryView = [self.webViewProxy keyboardAccessory];
if (ComputeFramesOfKeyboardParts(inputAccessoryView, &leftFrame,
&rightFrame)) {
if (inputAccessoryView) {
[self hideSubviewsInOriginalAccessoryView:inputAccessoryView];
_customAccessoryView =
[[FormInputAccessoryView alloc] initWithDelegate:self];
[_customAccessoryView initializeViewWithCustomView:view
leftFrame:leftFrame
rightFrame:rightFrame];
_customAccessoryView = [[FormInputAccessoryView alloc] init];
[_customAccessoryView setUpWithNavigationDelegate:self customView:view];
[inputAccessoryView addSubview:_customAccessoryView];
AddSameConstraints(_customAccessoryView, inputAccessoryView);
}
......
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