Commit 2793af96 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Use programmatic vector images for the download UI icons.

Vector graphics will allow to implement scale animation without scaling
the image. This change introduces the animation, but breaks certain
things which will be fixed in follow up CLs:
 - no blue checkmark or red error icons
 - progress bar does not have download track anymore
 - progress bar radius is bigger

Bug: 820178
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I3baa17a2a65b113714bee01bc082edae95953573
Reviewed-on: https://chromium-review.googlesource.com/964593
Commit-Queue: Eugene But <eugenebut@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543853}
parent be59f2ae
...@@ -5,11 +5,16 @@ ...@@ -5,11 +5,16 @@
source_set("download") { source_set("download") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
sources = [ sources = [
"download_manager_animation_constants.h",
"download_manager_animation_constants.mm",
"download_manager_consumer.h", "download_manager_consumer.h",
"download_manager_coordinator.h", "download_manager_coordinator.h",
"download_manager_coordinator.mm", "download_manager_coordinator.mm",
"download_manager_mediator.h", "download_manager_mediator.h",
"download_manager_mediator.mm", "download_manager_mediator.mm",
"download_manager_state.h",
"download_manager_state_view.h",
"download_manager_state_view.mm",
"download_manager_view_controller.h", "download_manager_view_controller.h",
"download_manager_view_controller.mm", "download_manager_view_controller.mm",
"legacy_download_manager_controller.h", "legacy_download_manager_controller.h",
...@@ -20,11 +25,7 @@ source_set("download") { ...@@ -20,11 +25,7 @@ source_set("download") {
"radial_progress_view.mm", "radial_progress_view.mm",
] ]
deps = [ deps = [
"resources:download_done",
"resources:download_error",
"resources:download_file",
"resources:download_manager_controller_xib", "resources:download_manager_controller_xib",
"resources:download_progress",
"resources:error_icon", "resources:error_icon",
"resources:file_icon_body", "resources:file_icon_body",
"resources:file_icon_fold", "resources:file_icon_fold",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_DOWNLOAD_DOWNLOAD_MANAGER_ANIMATION_CONSTANTS_H_
#define IOS_CHROME_BROWSER_UI_DOWNLOAD_DOWNLOAD_MANAGER_ANIMATION_CONSTANTS_H_
#import <Foundation/Foundation.h>
// Duration for all animations used in Download Manager.
extern const NSTimeInterval kDownloadManagerAnimationDuration;
#endif // IOS_CHROME_BROWSER_UI_DOWNLOAD_DOWNLOAD_MANAGER_ANIMATION_CONSTANTS_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ios/chrome/browser/ui/download/download_manager_animation_constants.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
const NSTimeInterval kDownloadManagerAnimationDuration = 0.2;
...@@ -7,16 +7,7 @@ ...@@ -7,16 +7,7 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, DownloadManagerState) { #import "ios/chrome/browser/ui/download/download_manager_state.h"
// Download has not started yet.
kDownloadManagerStateNotStarted = 0,
// Download is actively progressing.
kDownloadManagerStateInProgress,
// Download is completely finished without errors.
kDownloadManagerStateSucceeded,
// Download has failed with an error.
kDownloadManagerStateFailed,
};
// Consumer for the download manager mediator. // Consumer for the download manager mediator.
@protocol DownloadManagerConsumer @protocol DownloadManagerConsumer
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_DOWNLOAD_DOWNLOAD_MANAGER_STATE_H_
#define IOS_CHROME_BROWSER_UI_DOWNLOAD_DOWNLOAD_MANAGER_STATE_H_
typedef NS_ENUM(NSInteger, DownloadManagerState) {
// Download has not started yet.
kDownloadManagerStateNotStarted = 0,
// Download is actively progressing.
kDownloadManagerStateInProgress,
// Download is completely finished without errors.
kDownloadManagerStateSucceeded,
// Download has failed with an error.
kDownloadManagerStateFailed,
};
#endif // IOS_CHROME_BROWSER_UI_DOWNLOAD_DOWNLOAD_MANAGER_STATE_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_DOWNLOAD_DOWNLOAD_MANAGER_STATE_VIEW_H_
#define IOS_CHROME_BROWSER_UI_DOWNLOAD_DOWNLOAD_MANAGER_STATE_VIEW_H_
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/download/download_manager_state.h"
// View that display relevant icon for DownloadManagerState. This view have
// fixed size which can not be changed. In "not started" state the icon will be
// an arrow pointing to the ground. In "in progress" state the icon will be a
// small document icon. In "succeeded" state the icon will be a large document
// icon with blue checkmark badge. In "failed" state the icon will be a large
// document icon with red error badge.
@interface DownloadManagerStateView : UIView
// Changes the icon appropriate for the given state.
@property(nonatomic) DownloadManagerState state;
// Color for download icon in "not started" state.
@property(nonatomic) UIColor* downloadColor;
// Color for document icon in "in progress", "succeeded" and "failed" states.
@property(nonatomic) UIColor* documentColor;
// Allows setting the state with animation.
- (void)setState:(DownloadManagerState)state animated:(BOOL)animated;
@end
#endif // IOS_CHROME_BROWSER_UI_DOWNLOAD_DOWNLOAD_MANAGER_STATE_VIEW_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/download/download_manager_state_view.h"
#import <QuartzCore/QuartzCore.h>
#include "base/mac/foundation_util.h"
#include "ios/chrome/browser/ui/download/download_manager_animation_constants.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Using fixed size allows to achieve pixel perfect image.
const CGFloat kViewSize = 28;
// Stroke line width.
const CGFloat kLineWidth = 1;
// The scale of "in progress" icon.
const CGFloat kInProgressScale = 0.65f;
} // namespace
@interface DownloadManagerStateView ()
// CALayer that backs this view up.
@property(nonatomic, readonly) CAShapeLayer* shapeLayer;
@end
@implementation DownloadManagerStateView
@synthesize state = _state;
@synthesize downloadColor = _downloadColor;
@synthesize documentColor = _documentColor;
#pragma mark - UIView overrides
+ (Class)layerClass {
return [CAShapeLayer class];
}
- (void)setBounds:(CGRect)bounds {
[super setBounds:bounds];
[self updateUIAnimated:NO];
}
- (CGSize)intrinsicContentSize {
return CGSizeMake(kViewSize, kViewSize);
}
#pragma mark - Public
- (void)setState:(DownloadManagerState)state {
[self setState:state animated:NO];
}
- (void)setState:(DownloadManagerState)state animated:(BOOL)animated {
if (_state != state) {
_state = state;
[self updateUIAnimated:animated];
}
}
#pragma mark - Private
- (void)updateUIAnimated:(BOOL)animated {
NSTimeInterval animationDuration =
animated ? kDownloadManagerAnimationDuration : 0.0;
switch (_state) {
case kDownloadManagerStateNotStarted:
self.shapeLayer.path = self.downloadPath.CGPath;
self.shapeLayer.fillColor = self.downloadColor.CGColor;
self.shapeLayer.strokeColor = self.downloadColor.CGColor;
self.shapeLayer.transform = CATransform3DIdentity;
break;
case kDownloadManagerStateSucceeded:
case kDownloadManagerStateFailed: {
self.shapeLayer.path = self.documentPath.CGPath;
self.shapeLayer.fillColor = self.documentColor.CGColor;
self.shapeLayer.strokeColor = self.documentColor.CGColor;
if (!CATransform3DIsIdentity(self.shapeLayer.transform)) {
[UIView animateWithDuration:animationDuration
animations:^{
self.shapeLayer.transform = CATransform3DIdentity;
}];
}
break;
}
case kDownloadManagerStateInProgress:
self.shapeLayer.path = self.documentPath.CGPath;
self.shapeLayer.fillColor = self.documentColor.CGColor;
self.shapeLayer.strokeColor = self.documentColor.CGColor;
self.shapeLayer.transform = CATransform3DScale(
CATransform3DIdentity, kInProgressScale, kInProgressScale, 1);
break;
}
self.shapeLayer.lineWidth = kLineWidth;
}
- (UIBezierPath*)documentPath {
const CGFloat kVerticalMargin = 4; // top and bottom margins
const CGFloat kAspectRatio = 0.82; // height is bigger than width
// The constants below define the area where document icon is drawn.
const CGFloat minY = CGRectGetMinY(self.bounds);
const CGFloat maxY = CGRectGetMaxY(self.bounds);
const CGFloat top = minY + kVerticalMargin + kLineWidth / 2;
const CGFloat bottom = maxY - kVerticalMargin - kLineWidth / 2;
const CGFloat horizontalMargin =
round((bottom - top) * (1 - kAspectRatio) / 2) + kVerticalMargin;
const CGFloat minX = CGRectGetMinX(self.bounds);
const CGFloat maxX = CGRectGetMaxX(self.bounds);
const CGFloat left = minX + horizontalMargin + kLineWidth / 2;
const CGFloat right = maxX - horizontalMargin - kLineWidth / 2;
// All corners except top-right are rounded.
const CGFloat kRadius = 1;
// Top-right corner is folded and not rounded.
const CGFloat cornerSize = (right - left) * 0.45;
UIBezierPath* path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(right - cornerSize, top)];
[path addLineToPoint:CGPointMake(left + kRadius, top)];
[path addArcWithCenter:CGPointMake(left + kRadius, top + kRadius)
radius:kRadius
startAngle:-M_PI_2
endAngle:M_PI
clockwise:NO];
[path addLineToPoint:CGPointMake(left, bottom - kRadius)];
[path addArcWithCenter:CGPointMake(left + kRadius, bottom - kRadius)
radius:kRadius
startAngle:M_PI
endAngle:M_PI_2
clockwise:NO];
[path addLineToPoint:CGPointMake(right - kRadius, bottom)];
[path addArcWithCenter:CGPointMake(right - kRadius, bottom - kRadius)
radius:kRadius
startAngle:M_PI_2
endAngle:0
clockwise:NO];
[path addLineToPoint:CGPointMake(right, top + cornerSize)];
[path addLineToPoint:CGPointMake(right - cornerSize, top + cornerSize)];
[path closePath];
[path addLineToPoint:CGPointMake(right - cornerSize + kLineWidth, top)];
[path addLineToPoint:CGPointMake(right, top + cornerSize - kLineWidth)];
[path addLineToPoint:CGPointMake(right, top + cornerSize)];
return path;
}
- (UIBezierPath*)downloadPath {
const CGFloat horizontalMargin = 6; // left and right margins
const CGFloat topMargin = 4;
const CGFloat bottomMargin = 5;
// The constants below define the area where arrow icon is drawn.
const CGFloat minX = CGRectGetMinX(self.bounds);
const CGFloat maxX = CGRectGetMaxX(self.bounds);
const CGFloat midX = CGRectGetMidX(self.bounds);
const CGFloat left = minX + horizontalMargin + kLineWidth / 2;
const CGFloat right = maxX - horizontalMargin - kLineWidth / 2;
const CGFloat minY = CGRectGetMinY(self.bounds);
const CGFloat maxY = CGRectGetMaxY(self.bounds);
const CGFloat top = minY + topMargin + kLineWidth / 2;
const CGFloat bottom = maxY - bottomMargin - kLineWidth / 2;
const CGFloat width = (right - left);
const CGFloat height = (bottom - top);
// Top part of download icon has a pointing down arrow.
const CGFloat arrowWidth = round(width * 0.4); // does not include the tip
const CGFloat arrowHeight = round(height * 0.80); // includes arrow tip
const CGFloat arrowMid = top + arrowHeight / 2;
// Bottom part of download icon has a rect, which symbolizes ground.
const CGFloat groundHeight = 1;
CGRect ground = CGRectMake(left, bottom - groundHeight, width, groundHeight);
UIBezierPath* path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(midX + arrowWidth / 2, top)];
[path addLineToPoint:CGPointMake(midX - arrowWidth / 2, top)];
[path addLineToPoint:CGPointMake(midX - arrowWidth / 2, arrowMid)];
[path addLineToPoint:CGPointMake(left, arrowMid)];
[path addLineToPoint:CGPointMake(midX, top + arrowHeight)];
[path addLineToPoint:CGPointMake(right, arrowMid)];
[path addLineToPoint:CGPointMake(midX + arrowWidth / 2, arrowMid)];
[path closePath];
[path appendPath:[UIBezierPath bezierPathWithRect:ground]];
return path;
}
- (CAShapeLayer*)shapeLayer {
return base::mac::ObjCCastStrict<CAShapeLayer>(self.layer);
}
@end
...@@ -9,12 +9,7 @@ ...@@ -9,12 +9,7 @@
#import "ios/chrome/browser/ui/download/download_manager_consumer.h" #import "ios/chrome/browser/ui/download/download_manager_consumer.h"
// Image names for different download states. @class DownloadManagerStateView;
extern NSString* const kDownloadManagerNotStartedImage;
extern NSString* const kDownloadManagerInProgressImage;
extern NSString* const kDownloadManagerSucceededImage;
extern NSString* const kDownloadManagerFailedImage;
@class DownloadManagerViewController; @class DownloadManagerViewController;
@class RadialProgressView; @class RadialProgressView;
...@@ -55,7 +50,7 @@ extern NSString* const kDownloadManagerFailedImage; ...@@ -55,7 +50,7 @@ extern NSString* const kDownloadManagerFailedImage;
@property(nonatomic, readonly) UIButton* closeButton; @property(nonatomic, readonly) UIButton* closeButton;
// Icon that represents the current download status. // Icon that represents the current download status.
@property(nonatomic, readonly) UIImageView* statusIcon; @property(nonatomic, readonly) DownloadManagerStateView* stateIcon;
// Label that describes the current download status. // Label that describes the current download status.
@property(nonatomic, readonly) UILabel* statusLabel; @property(nonatomic, readonly) UILabel* statusLabel;
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/ui/download/download_manager_animation_constants.h"
#import "ios/chrome/browser/ui/download/download_manager_state_view.h"
#import "ios/chrome/browser/ui/download/radial_progress_view.h" #import "ios/chrome/browser/ui/download/radial_progress_view.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h" #import "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/chrome/browser/ui/util/named_guide.h" #import "ios/chrome/browser/ui/util/named_guide.h"
...@@ -21,11 +23,6 @@ ...@@ -21,11 +23,6 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
NSString* const kDownloadManagerNotStartedImage = @"download_file";
NSString* const kDownloadManagerInProgressImage = @"download_progress";
NSString* const kDownloadManagerSucceededImage = @"download_done";
NSString* const kDownloadManagerFailedImage = @"download_error";
namespace { namespace {
// Layout Guide name for action button UILayoutGuide. // Layout Guide name for action button UILayoutGuide.
GuideName* const kActionButtonGuide = @"kDownloadManagerActionButtonGuide"; GuideName* const kActionButtonGuide = @"kDownloadManagerActionButtonGuide";
...@@ -48,7 +45,7 @@ NSString* GetSizeString(long long size_in_bytes) { ...@@ -48,7 +45,7 @@ NSString* GetSizeString(long long size_in_bytes) {
@interface DownloadManagerViewController () { @interface DownloadManagerViewController () {
UIButton* _closeButton; UIButton* _closeButton;
UIImageView* _statusIcon; DownloadManagerStateView* _stateIcon;
UILabel* _statusLabel; UILabel* _statusLabel;
UIButton* _actionButton; UIButton* _actionButton;
UIButton* _installDriveButton; UIButton* _installDriveButton;
...@@ -117,7 +114,7 @@ NSString* GetSizeString(long long size_in_bytes) { ...@@ -117,7 +114,7 @@ NSString* GetSizeString(long long size_in_bytes) {
[self.view addSubview:self.downloadControlsRow]; [self.view addSubview:self.downloadControlsRow];
[self.view addSubview:self.installDriveControlsRow]; [self.view addSubview:self.installDriveControlsRow];
[self.downloadControlsRow addSubview:self.closeButton]; [self.downloadControlsRow addSubview:self.closeButton];
[self.downloadControlsRow addSubview:self.statusIcon]; [self.downloadControlsRow addSubview:self.stateIcon];
[self.downloadControlsRow addSubview:self.statusLabel]; [self.downloadControlsRow addSubview:self.statusLabel];
[self.downloadControlsRow addSubview:self.progressView]; [self.downloadControlsRow addSubview:self.progressView];
[self.downloadControlsRow addSubview:self.actionButton]; [self.downloadControlsRow addSubview:self.actionButton];
...@@ -193,11 +190,10 @@ NSString* GetSizeString(long long size_in_bytes) { ...@@ -193,11 +190,10 @@ NSString* GetSizeString(long long size_in_bytes) {
]]; ]];
// status icon constraints. // status icon constraints.
UIImageView* statusIcon = self.statusIcon; DownloadManagerStateView* stateIcon = self.stateIcon;
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
[statusIcon.centerYAnchor [stateIcon.centerYAnchor constraintEqualToAnchor:downloadRow.centerYAnchor],
constraintEqualToAnchor:downloadRow.centerYAnchor], [stateIcon.leadingAnchor
[statusIcon.leadingAnchor
constraintEqualToAnchor:downloadRow.layoutMarginsGuide.leadingAnchor], constraintEqualToAnchor:downloadRow.layoutMarginsGuide.leadingAnchor],
]]; ]];
...@@ -205,11 +201,11 @@ NSString* GetSizeString(long long size_in_bytes) { ...@@ -205,11 +201,11 @@ NSString* GetSizeString(long long size_in_bytes) {
RadialProgressView* progressView = self.progressView; RadialProgressView* progressView = self.progressView;
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
[progressView.leadingAnchor [progressView.leadingAnchor
constraintEqualToAnchor:statusIcon.leadingAnchor], constraintEqualToAnchor:stateIcon.leadingAnchor],
[progressView.trailingAnchor [progressView.trailingAnchor
constraintEqualToAnchor:statusIcon.trailingAnchor], constraintEqualToAnchor:stateIcon.trailingAnchor],
[progressView.topAnchor constraintEqualToAnchor:statusIcon.topAnchor], [progressView.topAnchor constraintEqualToAnchor:stateIcon.topAnchor],
[progressView.bottomAnchor constraintEqualToAnchor:statusIcon.bottomAnchor], [progressView.bottomAnchor constraintEqualToAnchor:stateIcon.bottomAnchor],
]]; ]];
// status label constraints. // status label constraints.
...@@ -218,7 +214,7 @@ NSString* GetSizeString(long long size_in_bytes) { ...@@ -218,7 +214,7 @@ NSString* GetSizeString(long long size_in_bytes) {
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
[statusLabel.centerYAnchor [statusLabel.centerYAnchor
constraintEqualToAnchor:downloadRow.centerYAnchor], constraintEqualToAnchor:downloadRow.centerYAnchor],
[statusLabel.leadingAnchor constraintEqualToAnchor:statusIcon.trailingAnchor [statusLabel.leadingAnchor constraintEqualToAnchor:stateIcon.trailingAnchor
constant:kElementMargin], constant:kElementMargin],
[statusLabel.trailingAnchor [statusLabel.trailingAnchor
constraintLessThanOrEqualToAnchor:actionButton.leadingAnchor constraintLessThanOrEqualToAnchor:actionButton.leadingAnchor
...@@ -318,7 +314,7 @@ NSString* GetSizeString(long long size_in_bytes) { ...@@ -318,7 +314,7 @@ NSString* GetSizeString(long long size_in_bytes) {
- (void)setState:(DownloadManagerState)state { - (void)setState:(DownloadManagerState)state {
if (_state != state) { if (_state != state) {
_state = state; _state = state;
[self updateStatusIcon]; [self updateStateIcon];
[self updateStatusLabel]; [self updateStatusLabel];
[self updateActionButton]; [self updateActionButton];
[self updateProgressView]; [self updateProgressView];
...@@ -331,7 +327,7 @@ NSString* GetSizeString(long long size_in_bytes) { ...@@ -331,7 +327,7 @@ NSString* GetSizeString(long long size_in_bytes) {
_installDriveButtonVisible = visible; _installDriveButtonVisible = visible;
__weak DownloadManagerViewController* weakSelf = self; __weak DownloadManagerViewController* weakSelf = self;
[UIView animateWithDuration:animated ? 0.2 : 0.0 [UIView animateWithDuration:animated ? kDownloadManagerAnimationDuration : 0.0
animations:^{ animations:^{
DownloadManagerViewController* strongSelf = weakSelf; DownloadManagerViewController* strongSelf = weakSelf;
[strongSelf updateInstallDriveControlsRow]; [strongSelf updateInstallDriveControlsRow];
...@@ -395,13 +391,15 @@ NSString* GetSizeString(long long size_in_bytes) { ...@@ -395,13 +391,15 @@ NSString* GetSizeString(long long size_in_bytes) {
return _closeButton; return _closeButton;
} }
- (UIImageView*)statusIcon { - (DownloadManagerStateView*)stateIcon {
if (!_statusIcon) { if (!_stateIcon) {
_statusIcon = [[UIImageView alloc] initWithFrame:CGRectZero]; _stateIcon = [[DownloadManagerStateView alloc] initWithFrame:CGRectZero];
_statusIcon.translatesAutoresizingMaskIntoConstraints = NO; _stateIcon.translatesAutoresizingMaskIntoConstraints = NO;
[self updateStatusIcon]; _stateIcon.downloadColor = [MDCPalette bluePalette].tint600;
_stateIcon.documentColor = [MDCPalette greyPalette].tint700;
[self updateStateIcon];
} }
return _statusIcon; return _stateIcon;
} }
- (UILabel*)statusLabel { - (UILabel*)statusLabel {
...@@ -480,7 +478,7 @@ NSString* GetSizeString(long long size_in_bytes) { ...@@ -480,7 +478,7 @@ NSString* GetSizeString(long long size_in_bytes) {
_progressView = [[RadialProgressView alloc] initWithFrame:CGRectZero]; _progressView = [[RadialProgressView alloc] initWithFrame:CGRectZero];
_progressView.translatesAutoresizingMaskIntoConstraints = NO; _progressView.translatesAutoresizingMaskIntoConstraints = NO;
_progressView.lineWidth = 2; _progressView.lineWidth = 2;
_progressView.tintColor = [MDCPalette bluePalette].tint500; _progressView.tintColor = [MDCPalette bluePalette].tint600;
[self updateProgressView]; [self updateProgressView];
} }
return _progressView; return _progressView;
...@@ -593,25 +591,9 @@ NSString* GetSizeString(long long size_in_bytes) { ...@@ -593,25 +591,9 @@ NSString* GetSizeString(long long size_in_bytes) {
self.widthConstraint.active = YES; self.widthConstraint.active = YES;
} }
// Updates status icon image depending on |state|. // Updates state icon depending.
- (void)updateStatusIcon { - (void)updateStateIcon {
NSString* imageName = nil; [self.stateIcon setState:_state animated:YES];
switch (_state) {
case kDownloadManagerStateNotStarted:
imageName = kDownloadManagerNotStartedImage;
break;
case kDownloadManagerStateInProgress:
imageName = kDownloadManagerInProgressImage;
break;
case kDownloadManagerStateSucceeded:
imageName = kDownloadManagerSucceededImage;
break;
case kDownloadManagerStateFailed:
imageName = kDownloadManagerFailedImage;
break;
}
DCHECK(imageName);
self.statusIcon.image = [UIImage imageNamed:imageName];
} }
// Updates status label text depending on |state|. // Updates status label text depending on |state|.
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/download/download_manager_state_view.h"
#import "ios/chrome/browser/ui/download/radial_progress_view.h" #import "ios/chrome/browser/ui/download/radial_progress_view.h"
#include "testing/gtest_mac.h" #include "testing/gtest_mac.h"
#include "testing/platform_test.h" #include "testing/platform_test.h"
...@@ -35,8 +36,7 @@ TEST_F(DownloadManagerViewControllerTest, NotStartedWithLongFileName) { ...@@ -35,8 +36,7 @@ TEST_F(DownloadManagerViewControllerTest, NotStartedWithLongFileName) {
view_controller_.statusLabel.text); view_controller_.statusLabel.text);
EXPECT_NSEQ(@"Download", [view_controller_.actionButton EXPECT_NSEQ(@"Download", [view_controller_.actionButton
titleForState:UIControlStateNormal]); titleForState:UIControlStateNormal]);
EXPECT_NSEQ([UIImage imageNamed:kDownloadManagerNotStartedImage], EXPECT_EQ(kDownloadManagerStateNotStarted, view_controller_.stateIcon.state);
view_controller_.statusIcon.image);
EXPECT_TRUE(view_controller_.progressView.hidden); EXPECT_TRUE(view_controller_.progressView.hidden);
} }
...@@ -51,8 +51,7 @@ TEST_F(DownloadManagerViewControllerTest, ...@@ -51,8 +51,7 @@ TEST_F(DownloadManagerViewControllerTest,
EXPECT_NSEQ(@"file.zip - 1.05 GB", view_controller_.statusLabel.text); EXPECT_NSEQ(@"file.zip - 1.05 GB", view_controller_.statusLabel.text);
EXPECT_NSEQ(@"Download", [view_controller_.actionButton EXPECT_NSEQ(@"Download", [view_controller_.actionButton
titleForState:UIControlStateNormal]); titleForState:UIControlStateNormal]);
EXPECT_NSEQ([UIImage imageNamed:kDownloadManagerNotStartedImage], EXPECT_EQ(kDownloadManagerStateNotStarted, view_controller_.stateIcon.state);
view_controller_.statusIcon.image);
EXPECT_TRUE(view_controller_.progressView.hidden); EXPECT_TRUE(view_controller_.progressView.hidden);
} }
...@@ -66,8 +65,7 @@ TEST_F(DownloadManagerViewControllerTest, InProgressWithLongFileName) { ...@@ -66,8 +65,7 @@ TEST_F(DownloadManagerViewControllerTest, InProgressWithLongFileName) {
EXPECT_NSEQ(@"Downloading… Zero KB/10 KB", view_controller_.statusLabel.text); EXPECT_NSEQ(@"Downloading… Zero KB/10 KB", view_controller_.statusLabel.text);
EXPECT_TRUE(view_controller_.actionButton.hidden); EXPECT_TRUE(view_controller_.actionButton.hidden);
EXPECT_NSEQ([UIImage imageNamed:kDownloadManagerInProgressImage], EXPECT_EQ(kDownloadManagerStateInProgress, view_controller_.stateIcon.state);
view_controller_.statusIcon.image);
EXPECT_FALSE(view_controller_.progressView.hidden); EXPECT_FALSE(view_controller_.progressView.hidden);
EXPECT_EQ(0.0f, view_controller_.progressView.progress); EXPECT_EQ(0.0f, view_controller_.progressView.progress);
} }
...@@ -84,8 +82,7 @@ TEST_F(DownloadManagerViewControllerTest, ...@@ -84,8 +82,7 @@ TEST_F(DownloadManagerViewControllerTest,
EXPECT_NSEQ(@"Downloading… 900 bytes", view_controller_.statusLabel.text); EXPECT_NSEQ(@"Downloading… 900 bytes", view_controller_.statusLabel.text);
EXPECT_TRUE(view_controller_.actionButton.hidden); EXPECT_TRUE(view_controller_.actionButton.hidden);
EXPECT_NSEQ([UIImage imageNamed:kDownloadManagerInProgressImage], EXPECT_EQ(kDownloadManagerStateInProgress, view_controller_.stateIcon.state);
view_controller_.statusIcon.image);
EXPECT_FALSE(view_controller_.progressView.hidden); EXPECT_FALSE(view_controller_.progressView.hidden);
EXPECT_EQ(0.9f, view_controller_.progressView.progress); EXPECT_EQ(0.9f, view_controller_.progressView.progress);
} }
...@@ -99,8 +96,7 @@ TEST_F(DownloadManagerViewControllerTest, SuceededWithWithLongFileName) { ...@@ -99,8 +96,7 @@ TEST_F(DownloadManagerViewControllerTest, SuceededWithWithLongFileName) {
EXPECT_NSEQ(@"file.txt", view_controller_.statusLabel.text); EXPECT_NSEQ(@"file.txt", view_controller_.statusLabel.text);
EXPECT_NSEQ(@"Open in…", [view_controller_.actionButton EXPECT_NSEQ(@"Open in…", [view_controller_.actionButton
titleForState:UIControlStateNormal]); titleForState:UIControlStateNormal]);
EXPECT_NSEQ([UIImage imageNamed:kDownloadManagerSucceededImage], EXPECT_EQ(kDownloadManagerStateSucceeded, view_controller_.stateIcon.state);
view_controller_.statusIcon.image);
EXPECT_TRUE(view_controller_.progressView.hidden); EXPECT_TRUE(view_controller_.progressView.hidden);
} }
...@@ -113,8 +109,7 @@ TEST_F(DownloadManagerViewControllerTest, Failed) { ...@@ -113,8 +109,7 @@ TEST_F(DownloadManagerViewControllerTest, Failed) {
EXPECT_NSEQ(@"Couldn't Download", view_controller_.statusLabel.text); EXPECT_NSEQ(@"Couldn't Download", view_controller_.statusLabel.text);
EXPECT_NSEQ(@"Try Again", [view_controller_.actionButton EXPECT_NSEQ(@"Try Again", [view_controller_.actionButton
titleForState:UIControlStateNormal]); titleForState:UIControlStateNormal]);
EXPECT_NSEQ([UIImage imageNamed:kDownloadManagerFailedImage], EXPECT_EQ(kDownloadManagerStateFailed, view_controller_.stateIcon.state);
view_controller_.statusIcon.image);
EXPECT_TRUE(view_controller_.progressView.hidden); EXPECT_TRUE(view_controller_.progressView.hidden);
} }
......
...@@ -9,42 +9,6 @@ bundle_data_ib_file("download_manager_controller_xib") { ...@@ -9,42 +9,6 @@ bundle_data_ib_file("download_manager_controller_xib") {
source = "DownloadManagerController.xib" source = "DownloadManagerController.xib"
} }
imageset("download_done") {
sources = [
"download_done.imageset/Contents.json",
"download_done.imageset/download_done.png",
"download_done.imageset/download_done@2x.png",
"download_done.imageset/download_done@3x.png",
]
}
imageset("download_error") {
sources = [
"download_error.imageset/Contents.json",
"download_error.imageset/download_error.png",
"download_error.imageset/download_error@2x.png",
"download_error.imageset/download_error@3x.png",
]
}
imageset("download_file") {
sources = [
"download_file.imageset/Contents.json",
"download_file.imageset/download_file.png",
"download_file.imageset/download_file@2x.png",
"download_file.imageset/download_file@3x.png",
]
}
imageset("download_progress") {
sources = [
"download_progress.imageset/Contents.json",
"download_progress.imageset/download_progress.png",
"download_progress.imageset/download_progress@2x.png",
"download_progress.imageset/download_progress@3x.png",
]
}
imageset("error_icon") { imageset("error_icon") {
sources = [ sources = [
"error_icon.imageset/Contents.json", "error_icon.imageset/Contents.json",
......
{
"images" : [
{
"idiom" : "universal",
"filename" : "download_done.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "download_done@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "download_done@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "download_error.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "download_error@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "download_error@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "download_file.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "download_file@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "download_file@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "download_progress.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "download_progress@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "download_progress@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
...@@ -14,7 +14,7 @@ const base::Feature kSlimNavigationManager{"SlimNavigationManager", ...@@ -14,7 +14,7 @@ const base::Feature kSlimNavigationManager{"SlimNavigationManager",
base::FEATURE_DISABLED_BY_DEFAULT}; base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kNewFileDownload{"NewFileDownload", const base::Feature kNewFileDownload{"NewFileDownload",
base::FEATURE_DISABLED_BY_DEFAULT}; base::FEATURE_ENABLED_BY_DEFAULT};
const base::Feature kWKHTTPSystemCookieStore{"WKHTTPSystemCookieStore", const base::Feature kWKHTTPSystemCookieStore{"WKHTTPSystemCookieStore",
base::FEATURE_ENABLED_BY_DEFAULT}; base::FEATURE_ENABLED_BY_DEFAULT};
......
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