Commit d2a27a19 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

Change the NewTabPageControllerDelegate method name

This CL changes the method name of NewTabPageControllerDelegate allowing
the NTP to change the color of the toolbar. The previous name of the
method was confusing.
Also, this method inverse the value of the argument (i.e. to display a
NTP-colored background on the toolbar, the value 1 needs to be passed,
instead of 0 before).

Bug: none
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: If19d37a8cb1a2f6761e7902b2a828955b73a7e41
Reviewed-on: https://chromium-review.googlesource.com/957093Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542116}
parent 7f71698b
......@@ -45,7 +45,7 @@ const CGFloat kDistanceToFadeToolbar = 50.0;
_loader = loader;
if (!IsIPadIdiom()) {
_toolbarDelegate = toolbarDelegate;
[_toolbarDelegate setToolbarBackgroundAlpha:0];
[_toolbarDelegate setToolbarBackgroundToIncognitoNTPColorWithAlpha:1];
}
}
return self;
......@@ -69,7 +69,7 @@ const CGFloat kDistanceToFadeToolbar = 50.0;
}
- (void)dealloc {
[_toolbarDelegate setToolbarBackgroundAlpha:1];
[_toolbarDelegate setToolbarBackgroundToIncognitoNTPColorWithAlpha:0];
[_incognitoView setDelegate:nil];
}
......@@ -79,12 +79,13 @@ const CGFloat kDistanceToFadeToolbar = 50.0;
}
- (void)wasShown {
CGFloat alpha = [self toolbarAlphaForScrollView:self.incognitoView];
[self.toolbarDelegate setToolbarBackgroundAlpha:alpha];
CGFloat alpha =
[self incognitoBackgroundAlphaForScrollView:self.incognitoView];
[self.toolbarDelegate setToolbarBackgroundToIncognitoNTPColorWithAlpha:alpha];
}
- (void)wasHidden {
[self.toolbarDelegate setToolbarBackgroundAlpha:1];
[self.toolbarDelegate setToolbarBackgroundToIncognitoNTPColorWithAlpha:0];
}
- (void)dismissModals {
......@@ -104,17 +105,18 @@ const CGFloat kDistanceToFadeToolbar = 50.0;
#pragma mark - UIScrollViewDelegate methods
- (void)scrollViewDidScroll:(UIScrollView*)scrollView {
CGFloat alpha = [self toolbarAlphaForScrollView:self.incognitoView];
[self.toolbarDelegate setToolbarBackgroundAlpha:alpha];
CGFloat alpha =
[self incognitoBackgroundAlphaForScrollView:self.incognitoView];
[self.toolbarDelegate setToolbarBackgroundToIncognitoNTPColorWithAlpha:alpha];
}
#pragma mark - Private
// Calculate the background alpha for the toolbar based on how much |scrollView|
// has scrolled up.
- (CGFloat)toolbarAlphaForScrollView:(UIScrollView*)scrollView {
CGFloat alpha = scrollView.contentOffset.y / kDistanceToFadeToolbar;
return MAX(MIN(alpha, 1), 0);
// Calculate the alpha for the toolbar background color of the NTP's color.
- (CGFloat)incognitoBackgroundAlphaForScrollView:(UIScrollView*)scrollView {
CGFloat alpha = (kDistanceToFadeToolbar - scrollView.contentOffset.y) /
kDistanceToFadeToolbar;
return MAX(alpha, 0);
}
@end
......@@ -7,8 +7,9 @@
// Delete for NTP and it's subclasses to communicate with the toolbar.
@protocol NewTabPageControllerDelegate
// Sets the alpha for the toolbar's background views.
- (void)setToolbarBackgroundAlpha:(CGFloat)alpha;
// Sets the background color of the toolbar to the color of the incognito NTP,
// with an |alpha|.
- (void)setToolbarBackgroundToIncognitoNTPColorWithAlpha:(CGFloat)alpha;
// Sets the toolbar location bar alpha and vertical offset based on |progress|.
- (void)setScrollProgressForTabletOmnibox:(CGFloat)progress;
@end
......
......@@ -87,7 +87,7 @@
#pragma mark - ToolbarCoordinating
- (void)setToolbarBackgroundAlpha:(CGFloat)alpha {
- (void)setToolbarBackgroundToIncognitoNTPColorWithAlpha:(CGFloat)alpha {
// TODO(crbug.com/803379): Implement that.
}
......
......@@ -128,7 +128,7 @@
#pragma mark - NewTabPageControllerDelegate
- (void)setToolbarBackgroundAlpha:(CGFloat)alpha {
- (void)setToolbarBackgroundToIncognitoNTPColorWithAlpha:(CGFloat)alpha {
// TODO(crbug.com/803379): Implement that.
}
......
......@@ -14,7 +14,8 @@
@interface ToolbarCoordinatorAdaptor ()<ToolbarCommands>
@property(nonatomic, strong)
NSMutableArray<id<ToolbarCoordinating, ToolbarCommands>>* coordinators;
NSMutableArray<id<NewTabPageControllerDelegate, ToolbarCommands>>*
coordinators;
// Coordinator for the toolsMenu.
@property(nonatomic, strong) ToolsMenuCoordinator* toolsMenuCoordinator;
@end
......@@ -44,20 +45,20 @@
}
- (void)addToolbarCoordinator:
(id<ToolbarCoordinating, ToolbarCommands>)toolbarCoordinator {
(id<NewTabPageControllerDelegate, ToolbarCommands>)toolbarCoordinator {
[self.coordinators addObject:toolbarCoordinator];
}
#pragma mark - NewTabPageControllerDelegate
- (void)setToolbarBackgroundAlpha:(CGFloat)alpha {
for (id<ToolbarCoordinating> coordinator in self.coordinators) {
[coordinator setToolbarBackgroundAlpha:alpha];
- (void)setToolbarBackgroundToIncognitoNTPColorWithAlpha:(CGFloat)alpha {
for (id<NewTabPageControllerDelegate> coordinator in self.coordinators) {
[coordinator setToolbarBackgroundToIncognitoNTPColorWithAlpha:alpha];
}
}
- (void)setScrollProgressForTabletOmnibox:(CGFloat)progress {
for (id<ToolbarCoordinating> coordinator in self.coordinators) {
for (id<NewTabPageControllerDelegate> coordinator in self.coordinators) {
[coordinator setScrollProgressForTabletOmnibox:progress];
}
}
......
......@@ -214,7 +214,7 @@ initWithToolsMenuConfigurationProvider:
if (!self.started)
return;
[self setToolbarBackgroundAlpha:1];
[self setToolbarBackgroundToIncognitoNTPColorWithAlpha:0];
self.started = NO;
self.delegate = nil;
[self.mediator disconnect];
......@@ -309,9 +309,8 @@ initWithToolsMenuConfigurationProvider:
#pragma mark - NewTabPageControllerDelegate
- (void)setToolbarBackgroundAlpha:(CGFloat)alpha {
[self.toolbarViewController
setBackgroundToIncognitoNTPColorWithAlpha:1 - alpha];
- (void)setToolbarBackgroundToIncognitoNTPColorWithAlpha:(CGFloat)alpha {
[self.toolbarViewController setBackgroundToIncognitoNTPColorWithAlpha:alpha];
}
- (void)setScrollProgressForTabletOmnibox:(CGFloat)progress {
......
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