Commit 2a94be7a authored by Robbie Gibson's avatar Robbie Gibson Committed by Commit Bot

[iOS] Remove transparency on toolbars

Bug: 976643
Change-Id: I13e7f454112ddfa9eed2779290fefd8dcaeee8a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1691920Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarJavier Ernesto Flores Robles <javierrobles@chromium.org>
Commit-Queue: Robbie Gibson <rkgibson@google.com>
Cr-Commit-Position: refs/heads/master@{#676893}
parent 377104d0
......@@ -130,25 +130,14 @@ CGFloat IdentityDiscToolbarOffset(id<UITraitEnvironment> environment) {
// Fake Toolbar.
ToolbarButtonFactory* buttonFactory =
[[ToolbarButtonFactory alloc] initWithStyle:NORMAL];
UIBlurEffect* blurEffect = buttonFactory.toolbarConfiguration.blurEffect;
UIView* fakeToolbar = nil;
UIView* fakeToolbarContentView;
if (blurEffect) {
UIVisualEffectView* visualEffectView =
[[UIVisualEffectView alloc] initWithEffect:blurEffect];
fakeToolbar = visualEffectView;
fakeToolbarContentView = visualEffectView.contentView;
} else {
fakeToolbar = [[UIView alloc] init];
fakeToolbarContentView = fakeToolbar;
}
UIView* fakeToolbar = [[UIView alloc] init];
fakeToolbar.backgroundColor =
buttonFactory.toolbarConfiguration.blurBackgroundColor;
buttonFactory.toolbarConfiguration.backgroundColor;
[searchField insertSubview:fakeToolbar atIndex:0];
fakeToolbar.translatesAutoresizingMaskIntoConstraints = NO;
// Fake location bar.
[fakeToolbarContentView addSubview:self.fakeLocationBar];
[fakeToolbar addSubview:self.fakeLocationBar];
// Omnibox, used for animations.
// TODO(crbug.com/936811): See if it is possible to share some initialization
......@@ -335,7 +324,7 @@ CGFloat IdentityDiscToolbarOffset(id<UITraitEnvironment> environment) {
self.separator.alpha = percent;
}
// Grow the blur to cover the safeArea top.
// Grow the background to cover the safeArea top.
self.fakeToolbarTopConstraint.constant = -safeAreaInsets.top * percent;
CGFloat toolbarExpandedHeight = ToolbarHeight();
......
......@@ -45,20 +45,10 @@ const CGFloat kVerticalOffset = 6;
ToolbarConfiguration* configuration = [[ToolbarConfiguration alloc]
initWithStyle:incognito ? INCOGNITO : NORMAL];
UIBlurEffect* effect = [configuration blurEffect];
if (effect) {
UIVisualEffectView* effectView =
[[UIVisualEffectView alloc] initWithEffect:effect];
[effectView.contentView addSubview:viewController.view];
_popupContainerView = effectView;
} else {
UIView* containerView = [[UIView alloc] init];
[containerView addSubview:viewController.view];
_popupContainerView = containerView;
}
_popupContainerView.backgroundColor = [configuration blurBackgroundColor];
UIView* containerView = [[UIView alloc] init];
[containerView addSubview:viewController.view];
_popupContainerView = containerView;
_popupContainerView.backgroundColor = [configuration backgroundColor];
_popupContainerView.translatesAutoresizingMaskIntoConstraints = NO;
viewController.view.translatesAutoresizingMaskIntoConstraints = NO;
AddSameConstraints(viewController.view, _popupContainerView);
......
......@@ -7,6 +7,7 @@
#include "base/mac/foundation_util.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_controller.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h"
#import "ios/chrome/common/colors/UIColor+cr_semantic_colors.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -30,20 +31,12 @@
- (void)viewDidLoad {
[super viewDidLoad];
UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc]
initWithEffect:[UIBlurEffect
effectWithStyle:UIBlurEffectStyleExtraLight]];
self.navigationBar.translucent = YES;
self.navigationController.navigationBar.backgroundColor =
[UIColor clearColor];
[self.navigationController.navigationBar addSubview:visualEffectView];
self.navigationBar.translucent = NO;
self.navigationBar.barTintColor = UIColor.cr_systemBackgroundColor;
self.view.backgroundColor = UIColor.cr_systemBackgroundColor;
self.navigationBar.prefersLargeTitles = YES;
[self.toolbar setShadowImage:[UIImage new]
forToolbarPosition:UIBarPositionAny];
self.toolbar.translucent = YES;
[self.toolbar addSubview:visualEffectView];
self.toolbar.translucent = NO;
}
@end
......@@ -21,10 +21,6 @@
// Progress bar displayed below the toolbar.
@property(nonatomic, strong, readonly) MDCProgressView* progressBar;
// The blur visual effect view.
@property(nonatomic, strong, readonly) UIView* blur;
// Button to navigate back.
@property(nonatomic, strong, readonly) ToolbarButton* backButton;
// Buttons to navigate forward.
......
......@@ -59,15 +59,10 @@ const CGFloat kTabGridAnimationsTotalDuration = 0.5;
- (void)updateForSideSwipeSnapshotOnNTP:(BOOL)onNTP {
self.view.progressBar.hidden = YES;
self.view.progressBar.alpha = 0;
self.view.blur.hidden = YES;
self.view.backgroundColor =
self.buttonFactory.toolbarConfiguration.backgroundColor;
}
- (void)resetAfterSideSwipeSnapshot {
self.view.progressBar.alpha = 1;
self.view.blur.hidden = NO;
self.view.backgroundColor = [UIColor clearColor];
}
#pragma mark - UIViewController
......
......@@ -19,12 +19,6 @@
// Style of this configuration.
@property(nonatomic, assign) ToolbarStyle style;
// Blur effect for the toolbar background.
@property(nonatomic, readonly) UIBlurEffect* blurEffect;
// Background color of the blur effect.
@property(nonatomic, readonly) UIColor* blurBackgroundColor;
// Background color of the NTP. Used to do as if the toolbar was transparent and
// the NTP is visible behind it.
@property(nonatomic, readonly) UIColor* NTPBackgroundColor;
......@@ -51,10 +45,6 @@
// translucent.
- (UIColor*)locationBarBackgroundColorWithVisibility:(CGFloat)visibilityFactor;
// Vibrancy effect for the toolbar elements, based on the |blurEffect|. Returns
// nil of no vibrancy effect should be applied.
- (UIVisualEffect*)vibrancyEffectForBlurEffect:(UIBlurEffect*)blurEffect;
@end
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_BUTTONS_TOOLBAR_CONFIGURATION_H_
......@@ -26,32 +26,6 @@
return self;
}
- (UIBlurEffect*)blurEffect {
if (UIAccessibilityIsReduceTransparencyEnabled())
return nil;
switch (self.style) {
case NORMAL:
return [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
case INCOGNITO:
return [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
}
}
- (UIColor*)blurBackgroundColor {
if (UIAccessibilityIsReduceTransparencyEnabled()) {
switch (self.style) {
case NORMAL:
return
[UIColor colorWithWhite:kBlurBackgroundGrayscaleComponent alpha:1];
case INCOGNITO:
return UIColorFromRGB(kIncognitoToolbarBackgroundColor);
}
}
return [UIColor colorWithWhite:kBlurBackgroundGrayscaleComponent
alpha:kBlurBackgroundAlpha];
}
- (UIColor*)NTPBackgroundColor {
switch (self.style) {
case NORMAL:
......@@ -130,16 +104,4 @@
}
}
- (UIVisualEffect*)vibrancyEffectForBlurEffect:(UIBlurEffect*)blurEffect {
if (!blurEffect)
return nil;
switch (self.style) {
case NORMAL:
return [UIVibrancyEffect effectForBlurEffect:blurEffect];
case INCOGNITO:
return nil;
}
}
@end
......@@ -31,9 +31,6 @@
// ContentView of the vibrancy effect if there is one, self otherwise.
@property(nonatomic, strong) UIView* contentView;
// The blur visual effect view, redefined as readwrite.
@property(nonatomic, strong, readwrite) UIView* blur;
// Container for the location bar, redefined as readwrite.
@property(nonatomic, strong, readwrite) UIView* locationBarContainer;
// The height of the container for the location bar, redefined as readwrite.
......@@ -125,7 +122,6 @@
@synthesize expandedConstraints = _expandedConstraints;
@synthesize contractedConstraints = _contractedConstraints;
@synthesize contractedNoMarginConstraints = _contractedNoMarginConstraints;
@synthesize blur = _blur;
@synthesize contentView = _contentView;
#pragma mark - Public
......@@ -147,7 +143,7 @@
self.translatesAutoresizingMaskIntoConstraints = NO;
[self setUpBlurredBackground];
[self setUpToolbarBackground];
[self setUpLeadingStackView];
[self setUpTrailingStackView];
[self setUpCancelButton];
......@@ -157,11 +153,6 @@
[self setUpSeparator];
[self setUpConstraints];
// Make sure that the trait collection is taken into account.
if (@available(iOS 13, *)) {
[self updateLayoutForPreviousTraitCollection:nil];
}
}
- (void)addFakeOmniboxTarget {
......@@ -184,39 +175,14 @@
ToolbarExpandedHeight(self.traitCollection.preferredContentSizeCategory));
}
- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
[self updateLayoutForPreviousTraitCollection:previousTraitCollection];
}
#pragma mark - Setup
// Sets the blur effect on the toolbar background.
- (void)setUpBlurredBackground {
UIBlurEffect* blurEffect = self.buttonFactory.toolbarConfiguration.blurEffect;
if (blurEffect) {
self.blur = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
} else {
self.blur = [[UIView alloc] init];
}
self.blur.backgroundColor =
self.buttonFactory.toolbarConfiguration.blurBackgroundColor;
[self addSubview:self.blur];
// Sets up the toolbar background.
- (void)setUpToolbarBackground {
self.backgroundColor =
self.buttonFactory.toolbarConfiguration.backgroundColor;
self.contentView = self;
if (UIVisualEffect* vibrancy = [self.buttonFactory.toolbarConfiguration
vibrancyEffectForBlurEffect:blurEffect]) {
UIVisualEffectView* vibrancyView =
[[UIVisualEffectView alloc] initWithEffect:vibrancy];
self.contentView = vibrancyView.contentView;
[self addSubview:vibrancyView];
vibrancyView.translatesAutoresizingMaskIntoConstraints = NO;
AddSameConstraints(self, vibrancyView);
}
self.blur.translatesAutoresizingMaskIntoConstraints = NO;
AddSameConstraints(self.blur, self);
}
// Sets the cancel button to stop editing the location bar.
......@@ -470,19 +436,4 @@
- (ToolbarButton*)searchButton {
return nil;
}
#pragma mark - Private
- (void)updateLayoutForPreviousTraitCollection:
(UITraitCollection*)previousTraitCollection {
if (IsRegularXRegularSizeClass(self)) {
self.backgroundColor =
self.buttonFactory.toolbarConfiguration.backgroundColor;
self.blur.alpha = 0;
} else {
self.backgroundColor = [UIColor clearColor];
self.blur.alpha = 1;
}
}
@end
......@@ -31,9 +31,6 @@ const CGFloat kToolsMenuOffset = -7;
// Redefined as readwrite
@property(nonatomic, strong, readwrite) NSArray<ToolbarButton*>* allButtons;
// The blur visual effect view, redefined as readwrite.
@property(nonatomic, strong, readwrite) UIView* blur;
// Separator above the toolbar, redefined as readwrite.
@property(nonatomic, strong, readwrite) UIView* separator;
......@@ -63,7 +60,6 @@ const CGFloat kToolsMenuOffset = -7;
@synthesize toolsMenuButton = _toolsMenuButton;
@synthesize searchButton = _searchButton;
@synthesize tabGridButton = _tabGridButton;
@synthesize blur = _blur;
#pragma mark - Public
......@@ -106,30 +102,10 @@ const CGFloat kToolsMenuOffset = -7;
self.translatesAutoresizingMaskIntoConstraints = NO;
UIBlurEffect* blurEffect = self.buttonFactory.toolbarConfiguration.blurEffect;
if (blurEffect) {
self.blur = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
} else {
self.blur = [[UIView alloc] init];
}
self.blur.backgroundColor =
self.buttonFactory.toolbarConfiguration.blurBackgroundColor;
[self addSubview:self.blur];
self.blur.translatesAutoresizingMaskIntoConstraints = NO;
AddSameConstraints(self.blur, self);
self.backgroundColor =
self.buttonFactory.toolbarConfiguration.backgroundColor;
UIView* contentView = self;
UIVisualEffect* vibrancy = [self.buttonFactory.toolbarConfiguration
vibrancyEffectForBlurEffect:blurEffect];
if (vibrancy && IconForSearchButton() != ToolbarSearchButtonIconColorful) {
// Add vibrancy only if we have a vibrancy effect.
UIVisualEffectView* vibrancyView =
[[UIVisualEffectView alloc] initWithEffect:vibrancy];
[self addSubview:vibrancyView];
vibrancyView.translatesAutoresizingMaskIntoConstraints = NO;
AddSameConstraints(self, vibrancyView);
contentView = vibrancyView.contentView;
}
self.backButton = [self.buttonFactory backButton];
self.forwardButton = [self.buttonFactory forwardButton];
......
......@@ -81,18 +81,9 @@ CGFloat kFakeTextBoxWidth = 240;
ToolbarConfiguration* configuration =
[[ToolbarConfiguration alloc] initWithStyle:NORMAL];
UIBlurEffect* effect = [configuration blurEffect];
UIView* containerView;
if (effect) {
UIVisualEffectView* effectView =
[[UIVisualEffectView alloc] initWithEffect:effect];
[effectView.contentView addSubview:self.popupViewController.view];
containerView = effectView;
} else {
containerView = [[UIView alloc] init];
[containerView addSubview:self.popupViewController.view];
}
containerView.backgroundColor = [configuration blurBackgroundColor];
UIView* containerView = [[UIView alloc] init];
[containerView addSubview:self.popupViewController.view];
containerView.backgroundColor = [configuration backgroundColor];
containerView.translatesAutoresizingMaskIntoConstraints = NO;
self.popupViewController.view.translatesAutoresizingMaskIntoConstraints = NO;
AddSameConstraints(self.popupViewController.view, containerView);
......
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