Commit 469da494 authored by Daniel Rubery's avatar Daniel Rubery Committed by Commit Bot

Add throbbing animation during deep scanning to indicate progress

Following UX feedback, we add an animation that runs during deep
scanning.

Screencast: https://screencast.googleplex.com/cast/NjI3ODYxNjQ2OTk5NTUyMHwzMTZhNTk3YS02ZA
Fixed: 1076092
Change-Id: I1b12fcb88409740842bf5aeed6d5927ab94533bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2367115
Commit-Queue: Daniel Rubery <drubery@chromium.org>
Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801603}
parent 6c94660c
......@@ -299,6 +299,9 @@ DownloadItemView::DownloadItemView(DownloadUIModel::DownloadUIModelPtr model,
complete_animation_.SetSlideDuration(base::TimeDelta::FromMilliseconds(2500));
complete_animation_.SetTweenType(gfx::Tween::LINEAR);
scanning_animation_.SetThrobDuration(base::TimeDelta::FromMilliseconds(2500));
scanning_animation_.SetTweenType(gfx::Tween::LINEAR);
// Further configure default state, e.g. child visibility.
OnDownloadUpdated();
}
......@@ -607,6 +610,15 @@ void DownloadItemView::OnPaint(gfx::Canvas* canvas) {
static_cast<uint8_t>(gfx::Tween::IntValueBetween(opacity, 0, 255)));
PaintDownloadProgress(canvas, progress_bounds, base::TimeDelta(), 100);
canvas->Restore();
} else if (scanning_animation_.is_animating()) {
DCHECK_EQ(Mode::kDeepScanning, mode_);
const double value = gfx::Tween::DoubleValueBetween(
scanning_animation_.GetCurrentValue(), 0, 2 * base::kPiDouble);
const double opacity = std::sin(value + base::kPiDouble / 2) / 2 + 0.5;
canvas->SaveLayerAlpha(
static_cast<uint8_t>(gfx::Tween::IntValueBetween(opacity, 0, 255)));
PaintDownloadProgress(canvas, GetIconBounds(), base::TimeDelta(), 100);
canvas->Restore();
} else if (use_new_warnings) {
file_icon = &file_icon_;
}
......@@ -624,14 +636,10 @@ void DownloadItemView::OnPaint(gfx::Canvas* canvas) {
// Overlay the warning icon if appropriate.
if (mode_ != Mode::kNormal) {
const int offset = use_new_warnings ? 8 : 0;
const gfx::ImageSkia icon = ui::ThemedVectorIcon(GetIcon().GetVectorIcon())
.GetImageSkia(GetNativeTheme());
const int icon_x =
GetMirroredXWithWidthInView(kStartPadding, icon.size().width()) +
offset;
const int icon_y = CenterY(icon.size().height()) + offset;
canvas->DrawImageInt(icon, icon_x, icon_y);
gfx::RectF bounds = GetIconBounds();
canvas->DrawImageInt(icon, bounds.x(), bounds.y());
}
OnPaintBorder(canvas);
......@@ -679,6 +687,7 @@ void DownloadItemView::UpdateMode(Mode mode) {
UpdateFilePathAndIcons();
UpdateLabels();
UpdateButtons();
UpdateAnimationForDeepScanningMode();
// Update the accessible name to contain the status text, filename, and
// warning message (if any). The name will be presented when the download item
......@@ -866,6 +875,15 @@ void DownloadItemView::UpdateAccessibleAlert(
}
}
void DownloadItemView::UpdateAnimationForDeepScanningMode() {
if (mode_ == Mode::kDeepScanning) {
// -1 to throb indefinitely.
scanning_animation_.StartThrobbing(-1);
} else {
scanning_animation_.End();
}
}
base::string16 DownloadItemView::GetInProgressAccessibleAlertText() const {
// If opening when complete or there is a warning, use the full status text.
if (model_->GetOpenWhenComplete() || has_warning_label(mode_))
......@@ -1024,6 +1042,17 @@ ui::ImageModel DownloadItemView::GetIcon() const {
return ui::ImageModel();
}
gfx::RectF DownloadItemView::GetIconBounds() const {
// TODO(drubery): When launching the new warnings, turn these numbers into
// appropriately named constants.
const int offset = UseNewWarnings() ? 8 : 0;
const gfx::Size size = GetIcon().Size();
const int icon_x =
GetMirroredXWithWidthInView(kStartPadding, size.width()) + offset;
const int icon_y = CenterY(size.height()) + offset;
return gfx::RectF(icon_x, icon_y, size.width(), size.height());
}
std::pair<base::string16, int> DownloadItemView::GetStatusTextAndStyle() const {
using DangerType = download::DownloadDangerType;
const auto type = model_->GetDangerType();
......
......@@ -25,6 +25,7 @@
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_types.h"
#include "ui/gfx/animation/slide_animation.h"
#include "ui/gfx/animation/throb_animation.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
......@@ -140,6 +141,10 @@ class DownloadItemView : public views::View,
// Update accessible status text, and announce it if desired.
void UpdateAccessibleAlert(const base::string16& alert);
// Updates the animation used during deep scanning. The animation is started
// or stopped depending on the current mode.
void UpdateAnimationForDeepScanningMode();
// Get the accessible alert text for a download that is currently in progress.
base::string16 GetInProgressAccessibleAlertText() const;
......@@ -162,6 +167,9 @@ class DownloadItemView : public views::View,
// When not in normal mode, returns the current help/warning/error icon.
ui::ImageModel GetIcon() const;
// When not in nromal mode, returns the bounds of the current icon.
gfx::RectF GetIconBounds() const;
// Returns the text and style to use for the status label.
std::pair<base::string16, int> GetStatusTextAndStyle() const;
......@@ -270,6 +278,8 @@ class DownloadItemView : public views::View,
gfx::SlideAnimation complete_animation_{this};
gfx::ThrobAnimation scanning_animation_{this};
// The tooltip. Only displayed when not showing a warning dialog.
base::string16 tooltip_text_;
......
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