Commit 3658ad31 authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] Add infobarActionInProgress property to InfobarCoordinator

This new property will be important for Infobars whose actions
will take some time and require the banner persisting to visualize
that process.

This change also adds InfobarTranslateCoordinator as implementing
InfobarCoordinatorImplementation.

Bug: 1014959
Change-Id: Iaa21fd9f3025e9797f9d0b63f6337efd0e3cb89a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1899635
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713300}
parent 69ab65d4
...@@ -103,10 +103,14 @@ ...@@ -103,10 +103,14 @@
// NO-OP. // NO-OP.
} }
- (void)dismissBannerWhenInteractionIsFinished { - (void)dismissBannerIfReady {
[self.bannerViewController dismissWhenInteractionIsFinished]; [self.bannerViewController dismissWhenInteractionIsFinished];
} }
- (BOOL)infobarActionInProgress {
return NO;
}
- (void)performInfobarAction { - (void)performInfobarAction {
self.confirmInfobarDelegate->Accept(); self.confirmInfobarDelegate->Accept();
self.infobarAccepted = YES; self.infobarAccepted = YES;
......
...@@ -66,10 +66,6 @@ enum class InfobarBannerPresentationState; ...@@ -66,10 +66,6 @@ enum class InfobarBannerPresentationState;
// Present the InfobarModal using |self.baseViewController|. // Present the InfobarModal using |self.baseViewController|.
- (void)presentInfobarModal; - (void)presentInfobarModal;
// Dismisses the InfobarBanner after the user is no longer interacting with it.
// e.g. No in progress touch gestures,etc. The dismissal will be animated.
- (void)dismissInfobarBannerAfterInteraction;
// Dismisses the InfobarBanner immediately, if none is being presented // Dismisses the InfobarBanner immediately, if none is being presented
// |completion| will still run. // |completion| will still run.
- (void)dismissInfobarBannerAnimated:(BOOL)animated - (void)dismissInfobarBannerAnimated:(BOOL)animated
......
...@@ -159,7 +159,7 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0; ...@@ -159,7 +159,7 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0;
} }
__weak InfobarCoordinator* weakSelf = self; __weak InfobarCoordinator* weakSelf = self;
self.dismissBannerBlock = ^(void) { self.dismissBannerBlock = ^(void) {
[weakSelf dismissInfobarBannerAfterInteraction]; [weakSelf dismissInfobarBannerIfReady];
weakSelf.dismissBannerBlock = nil; weakSelf.dismissBannerBlock = nil;
}; };
dispatch_after(popTime, dispatch_get_main_queue(), self.dismissBannerBlock); dispatch_after(popTime, dispatch_get_main_queue(), self.dismissBannerBlock);
...@@ -193,12 +193,6 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0; ...@@ -193,12 +193,6 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0;
} }
} }
- (void)dismissInfobarBannerAfterInteraction {
if (!self.modalTransitionDriver) {
[self dismissBannerWhenInteractionIsFinished];
}
}
- (void)dismissInfobarBannerAnimated:(BOOL)animated - (void)dismissInfobarBannerAnimated:(BOOL)animated
completion:(void (^)())completion { completion:(void (^)())completion {
[self dismissInfobarBanner:self animated:animated completion:completion]; [self dismissInfobarBanner:self animated:animated completion:completion];
...@@ -285,7 +279,13 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0; ...@@ -285,7 +279,13 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0;
self.bannerTransitionDriver = nil; self.bannerTransitionDriver = nil;
animatedFullscreenDisabler_ = nullptr; animatedFullscreenDisabler_ = nullptr;
[self infobarWasDismissed]; [self infobarWasDismissed];
[self.infobarContainer childCoordinatorBannerWasDismissed:self]; if (!self.infobarActionInProgress) {
// Only inform InfobarContainer that the Infobar banner presentation is
// finished if it is not still executing the Infobar action. That way, the
// container won't start presenting a queued Infobar's banner when the
// current Infobar hasn't finished.
[self.infobarContainer childCoordinatorBannerFinishedPresented:self];
}
} }
#pragma mark InfobarBannerPositioner #pragma mark InfobarBannerPositioner
...@@ -398,10 +398,15 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0; ...@@ -398,10 +398,15 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0;
NOTREACHED() << "Subclass must implement."; NOTREACHED() << "Subclass must implement.";
} }
- (void)dismissBannerWhenInteractionIsFinished { - (void)dismissBannerIfReady {
NOTREACHED() << "Subclass must implement."; NOTREACHED() << "Subclass must implement.";
} }
- (BOOL)infobarActionInProgress {
NOTREACHED() << "Subclass must implement.";
return NO;
}
- (void)performInfobarAction { - (void)performInfobarAction {
NOTREACHED() << "Subclass must implement."; NOTREACHED() << "Subclass must implement.";
} }
...@@ -421,6 +426,15 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0; ...@@ -421,6 +426,15 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0;
#pragma mark - Private #pragma mark - Private
// Dismisses the Infobar banner if it is ready. i.e. the user is no longer
// interacting with it or the Infobar action is still in progress. The dismissal
// will be animated.
- (void)dismissInfobarBannerIfReady {
if (!self.modalTransitionDriver) {
[self dismissBannerIfReady];
}
}
// |presentingViewController| presents the InfobarModal using |driver|. If // |presentingViewController| presents the InfobarModal using |driver|. If
// Modal is presented successfully |completion| will be executed. // Modal is presented successfully |completion| will be executed.
- (void)presentInfobarModalFrom:(UIViewController*)presentingViewController - (void)presentInfobarModalFrom:(UIViewController*)presentingViewController
......
...@@ -26,9 +26,15 @@ ...@@ -26,9 +26,15 @@
// Performs any actions related to an Infobar Modal presentation. // Performs any actions related to an Infobar Modal presentation.
- (void)infobarModalPresentedFromBanner:(BOOL)presentedFromBanner; - (void)infobarModalPresentedFromBanner:(BOOL)presentedFromBanner;
// Dismisses the InfobarBanner once there's no interaction in progress. An // Dismisses the InfobarBanner if not currently being used. A user could be
// interaction is any user initiated behavior with the Banner. // interacting with the banner or the Infobar may still be using the banner to
- (void)dismissBannerWhenInteractionIsFinished; // present information (i.e. infobarActionInProgress is YES).
- (void)dismissBannerIfReady;
// YES if the infobar action has been started and has not finished yet (i.e.
// Translate is in progress). If the Infobar action is not async, this should
// most likely always return NO.
- (BOOL)infobarActionInProgress;
// Performs the main Infobar action. e.g. "Save Password", "Restore",etc. // Performs the main Infobar action. e.g. "Save Password", "Restore",etc.
- (void)performInfobarAction; - (void)performInfobarAction;
......
...@@ -171,10 +171,14 @@ ...@@ -171,10 +171,14 @@
self.passwordInfoBarDelegate->InfobarPresenting(NO /*automatic*/); self.passwordInfoBarDelegate->InfobarPresenting(NO /*automatic*/);
} }
- (void)dismissBannerWhenInteractionIsFinished { - (void)dismissBannerIfReady {
[self.bannerViewController dismissWhenInteractionIsFinished]; [self.bannerViewController dismissWhenInteractionIsFinished];
} }
- (BOOL)infobarActionInProgress {
return NO;
}
- (void)performInfobarAction { - (void)performInfobarAction {
self.passwordInfoBarDelegate->Accept(); self.passwordInfoBarDelegate->Accept();
self.infobarAccepted = YES; self.infobarAccepted = YES;
......
...@@ -129,10 +129,14 @@ ...@@ -129,10 +129,14 @@
// between automatic and manual presentation. // between automatic and manual presentation.
} }
- (void)dismissBannerWhenInteractionIsFinished { - (void)dismissBannerIfReady {
[self.bannerViewController dismissWhenInteractionIsFinished]; [self.bannerViewController dismissWhenInteractionIsFinished];
} }
- (BOOL)infobarActionInProgress {
return NO;
}
- (void)infobarBannerWillBeDismissed:(BOOL)userInitiated { - (void)infobarBannerWillBeDismissed:(BOOL)userInitiated {
// TODO(crbug.com/1014652): Record metrics here if there's a distinction // TODO(crbug.com/1014652): Record metrics here if there's a distinction
// between ignoring or dismissing the Infobar. // between ignoring or dismissing the Infobar.
......
...@@ -47,6 +47,9 @@ ...@@ -47,6 +47,9 @@
// Tracks user actions taken throughout Translate lifetime. // Tracks user actions taken throughout Translate lifetime.
@property(nonatomic, assign) UserAction userAction; @property(nonatomic, assign) UserAction userAction;
// YES if translate is currently in progress
@property(nonatomic, assign) BOOL translateInProgress;
@end @end
@implementation TranslateInfobarCoordinator @implementation TranslateInfobarCoordinator
...@@ -54,6 +57,8 @@ ...@@ -54,6 +57,8 @@
@synthesize bannerViewController = _bannerViewController; @synthesize bannerViewController = _bannerViewController;
// Synthesize since readonly property from superclass is changed to readwrite. // Synthesize since readonly property from superclass is changed to readwrite.
@synthesize modalViewController = _modalViewController; @synthesize modalViewController = _modalViewController;
// Synthesized from InfobarCoordinatorImplementation
@synthesize translateInProgress = _translateInProgress;
- (instancetype)initWithInfoBarDelegate: - (instancetype)initWithInfoBarDelegate:
(translate::TranslateInfoBarDelegate*)infoBarDelegate { (translate::TranslateInfoBarDelegate*)infoBarDelegate {
...@@ -142,8 +147,15 @@ ...@@ -142,8 +147,15 @@
// TODO(crbug.com/1014959): implement // TODO(crbug.com/1014959): implement
} }
- (void)dismissBannerWhenInteractionIsFinished { - (void)dismissBannerIfReady {
[self.bannerViewController dismissWhenInteractionIsFinished]; if (!self.translateInProgress) {
// Only attempt to dismiss banner if Translate is not in progress.
[self.bannerViewController dismissWhenInteractionIsFinished];
}
}
- (BOOL)infobarActionInProgress {
return self.translateInProgress;
} }
- (void)infobarBannerWillBeDismissed:(BOOL)userInitiated { - (void)infobarBannerWillBeDismissed:(BOOL)userInitiated {
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
@protocol InfobarContainer @protocol InfobarContainer
// Informs the InfobarContainerCoordinator that |infobarCoordinator| has // Informs the InfobarContainerCoordinator that |infobarCoordinator| has
// dismissed its banner. // finished presenting its banner(s).
- (void)childCoordinatorBannerWasDismissed: - (void)childCoordinatorBannerFinishedPresented:
(InfobarCoordinator*)infobarCoordinator; (InfobarCoordinator*)infobarCoordinator;
// Informs the InfobarContainerCoordinator that |infobarCoordinator| has // Informs the InfobarContainerCoordinator that |infobarCoordinator| has
......
...@@ -245,7 +245,7 @@ ...@@ -245,7 +245,7 @@
#pragma mark InfobarContainer #pragma mark InfobarContainer
- (void)childCoordinatorBannerWasDismissed: - (void)childCoordinatorBannerFinishedPresented:
(InfobarCoordinator*)infobarCoordinator { (InfobarCoordinator*)infobarCoordinator {
InfobarCoordinator* coordinator = InfobarCoordinator* coordinator =
[self.infobarCoordinatorsToPresent firstObject]; [self.infobarCoordinatorsToPresent firstObject];
......
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