Commit 09528663 authored by Mark Cogan's avatar Mark Cogan Committed by Commit Bot

[iOS] Remove IsRefreshInfobarEnabled()

This CL removes the IsRefreshInfobarEnabled() flag function and refactors code around its use.

Bug: 884722
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I90dea9cf5e196f455eda1fe516140daa8ad68a8c
Reviewed-on: https://chromium-review.googlesource.com/1245366
Commit-Queue: Mark Cogan <marq@chromium.org>
Reviewed-by: default avatarPeter Lee <pkl@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594654}
parent b0a1ee9e
......@@ -84,8 +84,6 @@ source_set("autofill_ui") {
"//ios/chrome/browser/ui/colors",
"//ios/chrome/browser/ui/image_util",
"//ios/chrome/browser/ui/infobars",
"//ios/chrome/browser/ui/infobars/resources:infobar_close",
"//ios/chrome/browser/ui/infobars/resources:infobar_shadow",
"//ios/chrome/browser/ui/util",
"//ios/chrome/common",
"//ios/third_party/material_components_ios",
......
......@@ -32,14 +32,8 @@ NSString* const kSaveCardInfobarViewUploadAccessibilityID =
namespace {
// Returns whether the UI Refresh Infobar will be used.
using ::IsRefreshInfobarEnabled;
// Returns the image for the infobar close button.
UIImage* InfoBarCloseImage() {
if (!IsRefreshInfobarEnabled()) {
return [UIImage imageNamed:@"infobar_close"];
}
ui::ResourceBundle& resourceBundle = ui::ResourceBundle::GetSharedInstance();
return resourceBundle.GetNativeImageNamed(IDR_IOS_INFOBAR_CLOSE).ToUIImage();
}
......
......@@ -63,9 +63,7 @@ const CGFloat kButtonCornerRadius = 8.0;
// Returns the font for the infobar message.
UIFont* InfoBarMessageFont() {
return IsRefreshInfobarEnabled()
? [UIFont preferredFontForTextStyle:UIFontTextStyleBody]
: [MDCTypography subheadFont];
return [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
}
} // namespace
......@@ -200,20 +198,6 @@ UIFont* InfoBarMessageFont() {
id<LayoutGuideProvider> safeAreaLayoutGuide =
SafeAreaLayoutGuideForView(self);
// The drop shadow is at the top of the view, placed outside of its bounds.
if (!IsRefreshInfobarEnabled()) {
UIImage* shadowImage = [UIImage imageNamed:@"infobar_shadow"];
UIImageView* shadowView = [[UIImageView alloc] initWithImage:shadowImage];
shadowView.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:shadowView];
[NSLayoutConstraint activateConstraints:@[
[self.leadingAnchor constraintEqualToAnchor:shadowView.leadingAnchor],
[self.trailingAnchor constraintEqualToAnchor:shadowView.trailingAnchor],
[self.topAnchor constraintEqualToAnchor:shadowView.topAnchor
constant:shadowView.image.size.height],
]];
}
// Add the icon. The icon is fixed to the top leading corner of the infobar.
// |iconContainerView| is used here because the AutoLayout constraints for
// UIImageView would get ignored otherwise.
......@@ -224,9 +208,7 @@ UIFont* InfoBarMessageFont() {
iconContainerView.translatesAutoresizingMaskIntoConstraints = NO;
iconContainerView.clipsToBounds = YES;
UIImageView* iconImageView = [[UIImageView alloc] initWithImage:self.icon];
if (IsRefreshInfobarEnabled()) {
iconImageView.tintColor = UIColorFromRGB(kIconTintColor);
}
iconImageView.tintColor = UIColorFromRGB(kIconTintColor);
[iconContainerView addSubview:iconImageView];
AddSameConstraints(iconContainerView, iconImageView);
[self addSubview:iconContainerView];
......@@ -284,9 +266,7 @@ UIFont* InfoBarMessageFont() {
// Add the close button. The close button is fixed to the trailing edge of the
// infobar since it cannot expand.
DCHECK(self.closeButtonImage);
UIButton* closeButton =
[UIButton buttonWithType:IsRefreshInfobarEnabled() ? UIButtonTypeSystem
: UIButtonTypeCustom];
UIButton* closeButton = [UIButton buttonWithType:UIButtonTypeSystem];
closeButton.translatesAutoresizingMaskIntoConstraints = NO;
[closeButton setImage:self.closeButtonImage forState:UIControlStateNormal];
closeButton.contentEdgeInsets =
......@@ -296,10 +276,8 @@ UIFont* InfoBarMessageFont() {
action:@selector(didTapClose)
forControlEvents:UIControlEventTouchUpInside];
[closeButton setAccessibilityLabel:l10n_util::GetNSString(IDS_CLOSE)];
if (IsRefreshInfobarEnabled()) {
closeButton.tintColor = [UIColor blackColor];
closeButton.alpha = 0.20;
}
closeButton.tintColor = [UIColor blackColor];
closeButton.alpha = 0.20;
// Prevent the button from shrinking or expanding horizontally.
[closeButton
setContentCompressionResistancePriority:UILayoutPriorityRequired
......@@ -628,14 +606,11 @@ UIFont* InfoBarMessageFont() {
action:action
forControlEvents:UIControlEventTouchUpInside];
[button setUnderlyingColorHint:[UIColor blackColor]];
if (IsRefreshInfobarEnabled()) {
button.uppercaseTitle = NO;
button.layer.cornerRadius = kButtonCornerRadius;
[button
setTitleFont:[UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]
forState:UIControlStateNormal];
}
button.uppercaseTitle = NO;
button.layer.cornerRadius = kButtonCornerRadius;
[button
setTitleFont:[UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]
forState:UIControlStateNormal];
if (palette) {
button.hasOpaqueBackground = YES;
......
......@@ -16,7 +16,6 @@ source_set("infobars") {
"resources:infobar_close",
"resources:infobar_downloading",
"resources:infobar_popup_blocker",
"resources:infobar_shadow",
"resources:infobar_warning",
"//base",
"//base:i18n",
......
......@@ -59,33 +59,7 @@ struct LayoutMetrics {
CGFloat horizontal_space_between_icon_and_text;
};
// This defines the layout metrics for Chrome iOS legacy UI.
// Some layout metrics defined as constants are inter-related.
const CGFloat kCloseButtonInnerPadding = 16.0;
const CGFloat kButtonsMarginTop = kCloseButtonInnerPadding;
const CGFloat kLabelMarginTop = kButtonsMarginTop + 5.0; // Baseline lowered.
const LayoutMetrics kLayoutMetricsLegacy = {
20.0, // left_margin_on_first_line_when_icon_absent
30.0, // minimum_space_between_right_and_left_aligned_widgets
10.0, // right_margin
10.0, // space_between_widgets
kCloseButtonInnerPadding,
36.0, // button_height
16.0, // button_margin
8.0, // extra_button_margin_on_single_line
8.0, // button_spacing
8.0, // button_width_units
kButtonsMarginTop,
16.0, // close_button_margin_left
5.0, // label_line_spacing
22.0, // label_margin_bottom
8.0, // extra_margin_between_label_and_button
kLabelMarginTop,
68.0, // minimum_infobar_height
16.0 // horizontal_space_between_icon_and_text
};
const LayoutMetrics kLayoutMetricsPhase1 = {
const LayoutMetrics kLayoutMetrics = {
20.0, // left_margin_on_first_line_when_icon_absent
30.0, // minimum_space_between_right_and_left_aligned_widgets
10.0, // right_margin
......@@ -106,12 +80,6 @@ const LayoutMetrics kLayoutMetricsPhase1 = {
16.0 // horizontal_space_between_icon_and_text
};
// Returns the layout metrics data structure. Returned value is never nil.
const LayoutMetrics* InfoBarLayoutMetrics() {
return IsRefreshInfobarEnabled() ? &kLayoutMetricsPhase1
: &kLayoutMetricsLegacy;
}
// Color in RGB to be used as background of secondary actions button.
const int kButton2TitleColor = 0x4285f4;
// Corner radius for action buttons.
......@@ -123,30 +91,22 @@ enum InfoBarButtonPosition { ON_FIRST_LINE, CENTER, LEFT, RIGHT };
// Returns the font for the Infobar's main body text.
UIFont* InfoBarLabelFont() {
return IsRefreshInfobarEnabled()
? [UIFont preferredFontForTextStyle:UIFontTextStyleBody]
: [MDCTypography subheadFont];
return [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
}
// Returns the font for the Infobar's toggle switch's (if one exists) body text.
// This text label is usually of a slightly smaller font size relative to
// InfoBarLabelFont().
UIFont* InfoBarSwitchLabelFont() {
return IsRefreshInfobarEnabled()
? [UIFont preferredFontForTextStyle:UIFontTextStyleBody]
: [MDCTypography body1Font];
return [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
}
// Returns the font for the label on Infobar's action buttons.
UIFont* InfoBarButtonLabelFont() {
DCHECK(IsRefreshInfobarEnabled());
return [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
}
UIImage* InfoBarCloseImage() {
if (!IsRefreshInfobarEnabled()) {
return [UIImage imageNamed:@"infobar_close"];
}
ui::ResourceBundle& resourceBundle = ui::ResourceBundle::GetSharedInstance();
return resourceBundle.GetNativeImageNamed(IDR_IOS_INFOBAR_CLOSE).ToUIImage();
}
......@@ -182,7 +142,7 @@ UIImage* InfoBarCloseImage() {
}
- (id)initWithLabel:(NSString*)labelText isOn:(BOOL)isOn {
metrics_ = InfoBarLayoutMetrics();
metrics_ = &kLayoutMetrics;
// Creates switch and label.
UILabel* tempLabel = [[UILabel alloc] initWithFrame:CGRectZero];
......@@ -351,13 +311,7 @@ UIImage* InfoBarCloseImage() {
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
metrics_ = InfoBarLayoutMetrics();
if (!IsRefreshInfobarEnabled()) {
// Make the drop shadow.
UIImage* shadowImage = [UIImage imageNamed:@"infobar_shadow"];
shadow_ = [[UIImageView alloc] initWithImage:shadowImage];
[self addSubview:shadow_];
}
metrics_ = &kLayoutMetrics;
[self setAccessibilityViewIsModal:YES];
}
return self;
......@@ -777,9 +731,7 @@ UIImage* InfoBarCloseImage() {
action:(SEL)action {
DCHECK(!closeButton_);
UIImage* image = InfoBarCloseImage();
closeButton_ =
[UIButton buttonWithType:IsRefreshInfobarEnabled() ? UIButtonTypeSystem
: UIButtonTypeCustom];
closeButton_ = [UIButton buttonWithType:UIButtonTypeSystem];
[closeButton_ setExclusiveTouch:YES];
[closeButton_ setImage:image forState:UIControlStateNormal];
[closeButton_ addTarget:target
......@@ -787,10 +739,8 @@ UIImage* InfoBarCloseImage() {
forControlEvents:UIControlEventTouchUpInside];
[closeButton_ setTag:tag];
[closeButton_ setAccessibilityLabel:l10n_util::GetNSString(IDS_CLOSE)];
if (IsRefreshInfobarEnabled()) {
closeButton_.tintColor = [UIColor blackColor];
closeButton_.alpha = 0.20;
}
closeButton_.tintColor = [UIColor blackColor];
closeButton_.alpha = 0.20;
[self addSubview:closeButton_];
}
......@@ -809,9 +759,7 @@ UIImage* InfoBarCloseImage() {
[imageView_ removeFromSuperview];
}
imageView_ = [[UIImageView alloc] initWithImage:image];
if (IsRefreshInfobarEnabled()) {
imageView_.tintColor = UIColorFromRGB(kLeftIconTintColor);
}
imageView_.tintColor = UIColorFromRGB(kLeftIconTintColor);
[self addSubview:imageView_];
}
......@@ -964,12 +912,9 @@ UIImage* InfoBarCloseImage() {
target:(id)target
action:(SEL)action {
MDCFlatButton* button = [[MDCFlatButton alloc] init];
if (IsRefreshInfobarEnabled()) {
button.uppercaseTitle = NO;
button.layer.cornerRadius = kButtonCornerRadius;
[button setTitleFont:InfoBarButtonLabelFont()
forState:UIControlStateNormal];
}
button.uppercaseTitle = NO;
button.layer.cornerRadius = kButtonCornerRadius;
[button setTitleFont:InfoBarButtonLabelFont() forState:UIControlStateNormal];
button.inkColor = [[palette tint300] colorWithAlphaComponent:0.5f];
[button setBackgroundColor:[palette tint500] forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor colorWithWhite:0.8f alpha:1.0f]
......
......@@ -22,14 +22,6 @@ imageset("infobar_downloading") {
]
}
imageset("infobar_shadow") {
sources = [
"infobar_shadow.imageset/Contents.json",
"infobar_shadow.imageset/infobar_shadow.png",
"infobar_shadow.imageset/infobar_shadow@2x.png",
]
}
imageset("infobar_close") {
sources = [
"infobar_close.imageset/Contents.json",
......
{
"images": [
{
"idiom": "universal",
"scale": "1x",
"filename": "infobar_shadow.png"
},
{
"idiom": "universal",
"scale": "2x",
"filename": "infobar_shadow@2x.png"
}
],
"info": {
"version": 1,
"author": "xcode"
}
}
......@@ -39,10 +39,6 @@ CGFloat CurrentScreenWidth();
// Returns true if the device is an iPhone X.
bool IsIPhoneX();
// Returns whether the UI Refresh Infobar will be used.
// TODO (crbug.com/884722): Remove all use of this flag.
bool IsRefreshInfobarEnabled();
// Returns whether the UI Refresh Location Bar will be used.
// TODO (crbug.com/884723): Remove all use of this flag.
bool IsRefreshLocationBarEnabled();
......
......@@ -58,10 +58,6 @@ bool IsIPhoneX() {
(height == 2436 || height == 2688 || height == 1792));
}
bool IsRefreshInfobarEnabled() {
return true;
}
bool IsRefreshLocationBarEnabled() {
return true;
}
......
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