Commit 346ea857 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Further refactoring of DownloadItemView::Paint().

Bug: none
Change-Id: I48a4c36c96f3c92afa5e34cf43b9901af358d2d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2350133Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797579}
parent 5ee77c39
...@@ -571,29 +571,16 @@ void DownloadItemView::OnPaintBackground(gfx::Canvas* canvas) { ...@@ -571,29 +571,16 @@ void DownloadItemView::OnPaintBackground(gfx::Canvas* canvas) {
} }
void DownloadItemView::OnPaint(gfx::Canvas* canvas) { void DownloadItemView::OnPaint(gfx::Canvas* canvas) {
// TODO(pkasting): Refactor to simplify.
OnPaintBackground(canvas); OnPaintBackground(canvas);
const bool use_new_warnings = UseNewWarnings(); const bool use_new_warnings = UseNewWarnings();
if (mode_ != Mode::kNormal && !use_new_warnings) {
const gfx::ImageSkia icon = ui::ThemedVectorIcon(GetIcon().GetVectorIcon())
.GetImageSkia(GetNativeTheme());
const int icon_x =
GetMirroredXWithWidthInView(kStartPadding, icon.size().width());
const int icon_y = CenterY(icon.size().height());
canvas->DrawImageInt(icon, icon_x, icon_y);
OnPaintBorder(canvas);
return;
}
const gfx::Image* const file_icon_image = const gfx::Image* const file_icon_image =
g_browser_process->icon_manager()->LookupIconFromFilepath( g_browser_process->icon_manager()->LookupIconFromFilepath(
model_->GetTargetFilePath(), IconLoader::SMALL); model_->GetTargetFilePath(), IconLoader::SMALL);
const gfx::ImageSkia* file_icon = const gfx::ImageSkia* file_icon = (file_icon_image && mode_ == Mode::kNormal)
file_icon_image ? file_icon_image->ToImageSkia() : nullptr; ? file_icon_image->ToImageSkia()
: nullptr;
// Paint download progress. // Paint download progress.
// TODO(pkasting): Use a child view to display this. // TODO(pkasting): Use a child view to display this.
...@@ -630,8 +617,8 @@ void DownloadItemView::OnPaint(gfx::Canvas* canvas) { ...@@ -630,8 +617,8 @@ void DownloadItemView::OnPaint(gfx::Canvas* canvas) {
file_icon = &file_icon_; file_icon = &file_icon_;
} }
// Draw the file icon.
if (file_icon) { if (file_icon) {
// Draw the file icon.
const int offset = (progress_bounds.height() - file_icon->height()) / 2; const int offset = (progress_bounds.height() - file_icon->height()) / 2;
cc::PaintFlags flags; cc::PaintFlags flags;
// Use an alpha to make the image look disabled. // Use an alpha to make the image look disabled.
...@@ -639,19 +626,18 @@ void DownloadItemView::OnPaint(gfx::Canvas* canvas) { ...@@ -639,19 +626,18 @@ void DownloadItemView::OnPaint(gfx::Canvas* canvas) {
flags.setAlpha(120); flags.setAlpha(120);
canvas->DrawImageInt(*file_icon, progress_x + offset, progress_y + offset, canvas->DrawImageInt(*file_icon, progress_x + offset, progress_y + offset,
flags); flags);
}
// Overlay the warning icon if appropriate. // Overlay the warning icon if appropriate.
if (mode_ != Mode::kNormal) { if (mode_ != Mode::kNormal) {
constexpr int kDangerIconOffset = 8; const int offset = use_new_warnings ? 8 : 0;
const gfx::ImageSkia icon = const gfx::ImageSkia icon = ui::ThemedVectorIcon(GetIcon().GetVectorIcon())
ui::ThemedVectorIcon(GetIcon().GetVectorIcon()) .GetImageSkia(GetNativeTheme());
.GetImageSkia(GetNativeTheme()); const int icon_x =
const int icon_x = GetMirroredXWithWidthInView(kStartPadding, icon.size().width()) +
GetMirroredXWithWidthInView(kStartPadding, icon.size().width()) + offset;
kDangerIconOffset; const int icon_y = CenterY(icon.size().height()) + offset;
const int icon_y = CenterY(icon.size().height()) + kDangerIconOffset; canvas->DrawImageInt(icon, icon_x, icon_y);
canvas->DrawImageInt(icon, icon_x, icon_y);
}
} }
OnPaintBorder(canvas); OnPaintBorder(canvas);
......
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