Commit 49b3ffb2 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Correct Download Manager presentation with UI Refresh flag enabled.

This CL presents Download Manager from _browserContainerViewController,
which means that UI shows up between Web Content and Secondary Toolbar
on z-axe. This is only done if UI Refresh flag is enabled.

Also extended Download Manager coordinator and view controller to support
bottomMarginHeightAnchor property. This property allows adding bottom
margin to download manager UI in order to present Download Manager
UI above Secondary Toolbar on y-axe.

Bug: 818264
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I373ecb6e9892bdc20ba720742d653471ff0a9bad
Reviewed-on: https://chromium-review.googlesource.com/1024641Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Eugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560672}
parent 0579ec8f
......@@ -1026,8 +1026,15 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
// DownloadManagerCoordinator must be created before
// DownloadManagerTabHelper.
_downloadManagerCoordinator =
[[DownloadManagerCoordinator alloc] initWithBaseViewController:self];
_browserContainerCoordinator = [[BrowserContainerCoordinator alloc]
initWithBaseViewController:self
browserState:browserState];
[_browserContainerCoordinator start];
_downloadManagerCoordinator = [[DownloadManagerCoordinator alloc]
initWithBaseViewController:IsUIRefreshPhase1Enabled()
? _browserContainerCoordinator
.viewController
: self];
_downloadManagerCoordinator.presenter =
[[VerticalAnimationContainer alloc] init];
......@@ -1632,10 +1639,6 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
// The WebView is overflowing its bounds to be displayed below the toolbars.
self.view.clipsToBounds = YES;
_browserContainerCoordinator = [[BrowserContainerCoordinator alloc]
initWithBaseViewController:self
browserState:self.browserState];
[_browserContainerCoordinator start];
UIViewController* containerViewController =
_browserContainerCoordinator.viewController;
[self addChildViewController:containerViewController];
......@@ -2290,6 +2293,8 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
// DownloadManagerCoordinator is already created.
DCHECK(_downloadManagerCoordinator);
_downloadManagerCoordinator.webStateList = [_model webStateList];
_downloadManagerCoordinator.bottomMarginHeightAnchor =
[NamedGuide guideWithName:kSecondaryToolbar view:self.view].heightAnchor;
if (IsUIRefreshPhase1Enabled()) {
self.popupMenuCoordinator = [[PopupMenuCoordinator alloc]
......
......@@ -32,6 +32,9 @@ class WebStateList;
// Needed to observe web state closing. Set to null when stop method is called.
@property(nonatomic) WebStateList* webStateList;
// Controls the height of the bottom margin.
@property(nonatomic) NSLayoutDimension* bottomMarginHeightAnchor;
// Underlying UIViewController presented by this coordinator.
@property(nonatomic, readonly) UIViewController* viewController;
......
......@@ -145,6 +145,7 @@ class UnopenedDownloadsTracker : public web::DownloadTaskObserver,
@synthesize animatesPresentation = _animatesPresentation;
@synthesize downloadTask = _downloadTask;
@synthesize webStateList = _webStateList;
@synthesize bottomMarginHeightAnchor = _bottomMarginHeightAnchor;
- (void)dealloc {
[[InstallationNotifier sharedInstance] unregisterForNotifications:self];
......@@ -155,6 +156,7 @@ class UnopenedDownloadsTracker : public web::DownloadTaskObserver,
_viewController = [[DownloadManagerViewController alloc] init];
_viewController.delegate = self;
_viewController.bottomMarginHeightAnchor = self.bottomMarginHeightAnchor;
_mediator.SetDownloadTask(_downloadTask);
_mediator.SetConsumer(_viewController);
......
......@@ -41,6 +41,9 @@
@property(nonatomic, weak) id<DownloadManagerViewControllerDelegate> delegate;
// Controls the height of the bottom margin.
@property(nonatomic) NSLayoutDimension* bottomMarginHeightAnchor;
@end
// All UI elements presend in view controller's view.
......
......@@ -77,11 +77,11 @@ NSString* GetSizeString(long long size_in_bytes) {
// Grey line which separates downloadControlsRow and installDriveControlsRow.
@property(nonatomic, readonly) UIView* horizontalLine;
// Represents constraint for self.view.bottomAnchor, which can either be
// Represents constraint for kBottomMarginGuide's topAnchor, which can either be
// constrained to installDriveControlsRow's bottomAnchor or to
// downloadControlsRow's bottomAnchor. Stored in a property to allow
// deactivating the old constraint.
@property(nonatomic) NSLayoutConstraint* bottomConstraint;
@property(nonatomic) NSLayoutConstraint* bottomMarginGuideTopConstraint;
// Represents constraint for self.view.widthAnchor, which is anchored to
// superview with different multipliers depending on size class. Stored in a
......@@ -103,16 +103,20 @@ NSString* GetSizeString(long long size_in_bytes) {
// UILayoutGuide for action button. Used in delegate callbacks.
@property(nonatomic) UILayoutGuide* actionButtonGuide;
// UILayoutGuide for adding bottom margin to Download Manager view.
@property(nonatomic) UILayoutGuide* bottomMarginGuide;
@end
@implementation DownloadManagerViewController
@synthesize delegate = _delegate;
@synthesize bottomMarginHeightAnchor = _bottomMarginHeightAnchor;
@synthesize background = _background;
@synthesize downloadControlsRow = _downloadControlsRow;
@synthesize installDriveControlsRow = _installDriveControlsRow;
@synthesize horizontalLine = _horizontalLine;
@synthesize bottomConstraint = _bottomConstraint;
@synthesize bottomMarginGuideTopConstraint = _bottomMarginGuideTopConstraint;
@synthesize viewWidthConstraint = _viewWidthConstraint;
@synthesize downloadControlsRowLeadingConstraint =
_downloadControlsRowLeadingConstraint;
......@@ -124,6 +128,7 @@ NSString* GetSizeString(long long size_in_bytes) {
_installDriveControlsRowTrailingConstraint;
@synthesize statusLabelTrailingConstraint = _statusLabelTrailingConstraint;
@synthesize actionButtonGuide = _actionButtonGuide;
@synthesize bottomMarginGuide = _bottomMarginGuide;
#pragma mark - UIViewController overrides
......@@ -145,6 +150,8 @@ NSString* GetSizeString(long long size_in_bytes) {
self.actionButtonGuide = [[UILayoutGuide alloc] init];
[self.view addLayoutGuide:self.actionButtonGuide];
self.bottomMarginGuide = [[UILayoutGuide alloc] init];
[self.view addLayoutGuide:self.bottomMarginGuide];
}
- (void)updateViewConstraints {
......@@ -155,7 +162,11 @@ NSString* GetSizeString(long long size_in_bytes) {
// self.view constraints.
UIView* view = self.view;
[self updateBottomConstraints];
UILayoutGuide* bottomMarginGuide = self.bottomMarginGuide;
[NSLayoutConstraint activateConstraints:@[
[view.bottomAnchor constraintEqualToAnchor:bottomMarginGuide.bottomAnchor],
]];
[self updateBottomMarginGuideTopConstraint];
// background constraints.
UIView* background = self.background;
......@@ -198,6 +209,18 @@ NSString* GetSizeString(long long size_in_bytes) {
[installDriveRow.heightAnchor constraintEqualToConstant:kRowHeight],
]];
// bottom margin row constraints.
if (_bottomMarginHeightAnchor) {
[NSLayoutConstraint activateConstraints:@[
[bottomMarginGuide.heightAnchor
constraintEqualToAnchor:_bottomMarginHeightAnchor],
]];
} else {
[NSLayoutConstraint activateConstraints:@[
[bottomMarginGuide.heightAnchor constraintEqualToConstant:0],
]];
}
// close button constraints.
[NSLayoutConstraint activateConstraints:@[
[closeButton.centerYAnchor
......@@ -356,7 +379,7 @@ NSString* GetSizeString(long long size_in_bytes) {
animations:^{
DownloadManagerViewController* strongSelf = weakSelf;
[strongSelf updateInstallDriveControlsRow];
[strongSelf updateBottomConstraints];
[strongSelf updateBottomMarginGuideTopConstraint];
[strongSelf.view.superview layoutIfNeeded];
}];
}
......@@ -564,22 +587,26 @@ NSString* GetSizeString(long long size_in_bytes) {
#pragma mark - UI Updates
// Updates and activates self.bottomConstraint. self.bottomConstraint
// constraints self.view.bottomAnchor to installDriveControlsRow's bottom
// if |_installDriveButtonVisible| is set to YES, otherwise
// self.view.bottomAnchor is constrained to downloadControlsRow's botttom. This
// resizes self.view to show or hide installDriveControlsRow view.
- (void)updateBottomConstraints {
self.bottomConstraint.active = NO;
NSLayoutYAxisAnchor* firstAnchor = self.view.layoutMarginsGuide.bottomAnchor;
// Updates and activates self.bottomMarginGuideTopConstraint.
// self.bottomMarginGuideTopConstraint constraints kBottomMarginGuide's
// topAnchor to installDriveControlsRow's bottom if |_installDriveButtonVisible|
// is set to YES, otherwise self.view.bottomAnchor is constrained to
// downloadControlsRow's bottom. This resizes self.view to show or hide
// installDriveControlsRow view.
- (void)updateBottomMarginGuideTopConstraint {
if (!self.viewLoaded) {
// This method will be called again when the view is loaded.
return;
}
self.bottomMarginGuideTopConstraint.active = NO;
NSLayoutYAxisAnchor* secondAnchor =
_installDriveButtonVisible ? self.installDriveControlsRow.bottomAnchor
: self.downloadControlsRow.bottomAnchor;
self.bottomConstraint = [firstAnchor constraintEqualToAnchor:secondAnchor];
self.bottomMarginGuideTopConstraint =
[self.bottomMarginGuide.topAnchor constraintEqualToAnchor:secondAnchor];
self.bottomConstraint.active = YES;
self.bottomMarginGuideTopConstraint.active = YES;
}
// Updates background image for the given UITraitCollection.
......
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