-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Downloads] Refactor downloads animation code
This refactors the current download animation (small down-arrow that moves towards the download shelf), in preparation for reusing the code for a new animation for the new download bubble UI. Bug: 1410789 Change-Id: I54df7222b3742ebd818460e1b1f062d0b994da61 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4210433 Reviewed-by: Xinghui Lu <xinghuilu@chromium.org> Commit-Queue: Lily Chen <chlily@chromium.org> Cr-Commit-Position: refs/heads/main@{#1100563}
- Loading branch information
Showing
10 changed files
with
204 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
chrome/browser/ui/views/download/download_shelf_started_animation_views.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/ui/views/download/download_shelf_started_animation_views.h" | ||
|
||
#include "base/i18n/rtl.h" | ||
#include "base/time/time.h" | ||
#include "chrome/app/vector_icons/vector_icons.h" | ||
#include "chrome/browser/ui/color/chrome_color_id.h" | ||
#include "chrome/browser/ui/views/download/download_started_animation_views.h" | ||
#include "ui/base/metadata/metadata_header_macros.h" | ||
#include "ui/base/metadata/metadata_impl_macros.h" | ||
#include "ui/gfx/geometry/rect.h" | ||
#include "ui/gfx/paint_vector_icon.h" | ||
|
||
DownloadShelfStartedAnimationViews::DownloadShelfStartedAnimationViews( | ||
content::WebContents* web_contents) | ||
: DownloadStartedAnimationViews( | ||
web_contents, | ||
base::Milliseconds(600), | ||
ui::ImageModel::FromVectorIcon( | ||
kFileDownloadShelfIcon, | ||
kColorDownloadStartedAnimationForeground, | ||
72)) {} | ||
|
||
int DownloadShelfStartedAnimationViews::GetX() const { | ||
// Align the image with the bottom left of the web contents (so that it | ||
// points to the newly created download). | ||
return base::i18n::IsRTL() | ||
? web_contents_bounds().right() - GetPreferredSize().width() | ||
: web_contents_bounds().x(); | ||
} | ||
|
||
int DownloadShelfStartedAnimationViews::GetY() const { | ||
int height = GetPreferredSize().height(); | ||
return static_cast<int>(web_contents_bounds().bottom() - height - | ||
height * (1 - GetCurrentValue())); | ||
} | ||
|
||
float DownloadShelfStartedAnimationViews::GetOpacity() const { | ||
// Start at zero, peak halfway and end at zero. | ||
return static_cast<float>( | ||
std::min(1.0 - pow(GetCurrentValue() - 0.5, 2) * 4.0, 1.0)); | ||
} | ||
|
||
BEGIN_METADATA(DownloadShelfStartedAnimationViews, | ||
DownloadStartedAnimationViews) | ||
END_METADATA |
30 changes: 30 additions & 0 deletions
30
chrome/browser/ui/views/download/download_shelf_started_animation_views.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_SHELF_STARTED_ANIMATION_VIEWS_H_ | ||
#define CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_SHELF_STARTED_ANIMATION_VIEWS_H_ | ||
|
||
#include "chrome/browser/ui/views/download/download_started_animation_views.h" | ||
#include "ui/base/metadata/metadata_header_macros.h" | ||
|
||
class DownloadShelfStartedAnimationViews | ||
: public DownloadStartedAnimationViews { | ||
public: | ||
METADATA_HEADER(DownloadShelfStartedAnimationViews); | ||
explicit DownloadShelfStartedAnimationViews( | ||
content::WebContents* web_contents); | ||
DownloadShelfStartedAnimationViews( | ||
const DownloadShelfStartedAnimationViews&) = delete; | ||
DownloadShelfStartedAnimationViews& operator=( | ||
const DownloadShelfStartedAnimationViews&) = delete; | ||
~DownloadShelfStartedAnimationViews() override = default; | ||
|
||
private: | ||
// DownloadStartedAnimationViews | ||
int GetX() const override; | ||
int GetY() const override; | ||
float GetOpacity() const override; | ||
}; | ||
|
||
#endif // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_SHELF_STARTED_ANIMATION_VIEWS_H_ |
17 changes: 17 additions & 0 deletions
17
chrome/browser/ui/views/download/download_started_animation.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/ui/download/download_started_animation.h" | ||
|
||
#include "chrome/browser/ui/views/download/download_shelf_started_animation_views.h" | ||
|
||
namespace content { | ||
class WebContents; | ||
} // namespace content | ||
|
||
// static | ||
void DownloadStartedAnimation::Show(content::WebContents* web_contents) { | ||
// The animation will delete itself when it's finished. | ||
new DownloadShelfStartedAnimationViews(web_contents); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.