chromium/chrome/browser/ui/views/download/download_item_view.cc

// Copyright 2012 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_item_view.h"

#include <stdint.h>

#include <algorithm>
#include <array>
#include <cmath>
#include <memory>
#include <numbers>
#include <numeric>
#include <vector>

#include "base/containers/fixed_flat_map.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/ranges/functional.h"
#include "base/task/single_thread_task_runner.h"
#include "build/build_config.h"
#include "build/buildflag.h"
#include "cc/paint/paint_flags.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/chrome_download_manager_delegate.h"
#include "chrome/browser/download/download_stats.h"
#include "chrome/browser/download/drag_download_item.h"
#include "chrome/browser/enterprise/connectors/common.h"
#include "chrome/browser/enterprise/connectors/connectors_service.h"
#include "chrome/browser/icon_manager.h"
#include "chrome/browser/safe_browsing/advanced_protection_status_manager.h"
#include "chrome/browser/safe_browsing/advanced_protection_status_manager_factory.h"
#include "chrome/browser/safe_browsing/download_protection/download_protection_service.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/browser/ui/tab_modal_confirm_dialog.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/views/chrome_typography.h"
#include "chrome/browser/ui/views/download/download_shelf_view.h"
#include "chrome/browser/ui/views/safe_browsing/deep_scanning_modal_dialog.h"
#include "chrome/browser/ui/views/safe_browsing/prompt_for_scanning_modal_dialog.h"
#include "chrome/grit/generated_resources.h"
#include "components/download/public/common/download_danger_type.h"
#include "components/download/public/common/download_item.h"
#include "components/safe_browsing/buildflags.h"
#include "components/url_formatter/elide_url.h"
#include "components/vector_icons/vector_icons.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkScalar.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/time_format.h"
#include "ui/base/menu_source_utils.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/text/bytes_formatting.h"
#include "ui/base/themed_vector_icon.h"
#include "ui/base/ui_base_types.h"
#include "ui/color/color_id.h"
#include "ui/color/color_provider.h"
#include "ui/compositor/layer.h"
#include "ui/display/screen.h"
#include "ui/events/event.h"
#include "ui/gfx/animation/tween.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/skia_conversions.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/range/range.h"
#include "ui/gfx/text_constants.h"
#include "ui/gfx/text_elider.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/animation/ink_drop_host.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/image_button_factory.h"
#include "ui/views/controls/button/md_text_button.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/progress_ring_utils.h"
#include "ui/views/controls/styled_label.h"
#include "ui/views/style/typography.h"
#include "ui/views/style/typography_provider.h"
#include "ui/views/vector_icons.h"
#include "ui/views/widget/root_view.h"
#include "ui/views/widget/widget.h"
#include "url/gurl.h"
#include "url/url_constants.h"

namespace {

// TODO(pkasting): Replace bespoke constants in file with standard metrics from
// e.g. LayoutProvider.

constexpr int kTextWidth =;

// Padding before the icon and at end of the item.
constexpr int kStartPadding =;
constexpr int kEndPadding =;

// Horizontal padding between progress indicator and filename/status text.
constexpr int kProgressTextPadding =;

// The space between the Save and Discard buttons when prompting for a
// dangerous download.
constexpr int kSaveDiscardButtonPadding =;

// The space on the right side of the dangerous download label.
constexpr int kLabelPadding =;

// Size of the space used for the progress indicator.
constexpr int kProgressIndicatorSize =;

// The vertical distance between the item's visual upper bound (as delineated
// by the separator on the right) and the edge of the shelf.
constexpr int kTopBottomPadding =;

// The minimum vertical padding above and below contents of the download item.
// This is only used when the text size is large.
constexpr int kMinimumVerticalPadding =;

// A stub subclass of Button that has no visuals.
class TransparentButton : public views::Button {};

BEGIN_METADATA()

int GetFilenameStyle(const views::Label& label) {}

int GetFilenameStyle(const views::StyledLabel& label) {}

void StyleFilename(views::Label& label, size_t pos, size_t len) {}

void StyleFilename(views::StyledLabel& label, size_t pos, size_t len) {}

// Whether we are warning about a dangerous/malicious download.
bool is_download_warning(download::DownloadItemMode mode) {}

// Whether we are in the insecure download mode.
bool is_insecure(download::DownloadItemMode mode) {}

// Whether a warning label is visible.
bool has_warning_label(download::DownloadItemMode mode) {}

float GetDPIScaleForView(views::View* view) {}
}  // namespace

class DownloadItemView::ContextMenuButton : public views::ImageButton {};

BEGIN_METADATA()
END_METADATA

DownloadItemView::DownloadItemView(DownloadUIModel::DownloadUIModelPtr model,
                                   DownloadShelfView* shelf,
                                   views::View* accessible_alert)
    :{}

DownloadItemView::~DownloadItemView() = default;

void DownloadItemView::AddedToWidget() {}

void DownloadItemView::Layout(PassKey) {}

bool DownloadItemView::OnMouseDragged(const ui::MouseEvent& event) {}

void DownloadItemView::OnMouseCaptureLost() {}

std::u16string DownloadItemView::GetTooltipText(const gfx::Point& p) const {}

void DownloadItemView::GetAccessibleNodeData(ui::AXNodeData* node_data) {}

void DownloadItemView::ShowContextMenuForViewImpl(
    View* source,
    const gfx::Point& point,
    ui::MenuSourceType source_type) {}

void DownloadItemView::OnDownloadUpdated() {}

void DownloadItemView::OnDownloadOpened() {}

void DownloadItemView::OnDownloadDestroyed(const ContentId& id) {}

void DownloadItemView::AnimationProgressed(const gfx::Animation* animation) {}

void DownloadItemView::AnimationEnded(const gfx::Animation* animation) {}

gfx::Size DownloadItemView::CalculatePreferredSize(
    const views::SizeBounds& /*available_size*/) const {}

void DownloadItemView::OnPaintBackground(gfx::Canvas* canvas) {}

void DownloadItemView::OnPaint(gfx::Canvas* canvas) {}

void DownloadItemView::OnThemeChanged() {}

// ui::LayerDelegate:
void DownloadItemView::OnDeviceScaleFactorChanged(
    float old_device_scale_factor,
    float new_device_scale_factor) {}

void DownloadItemView::SetMode(download::DownloadItemMode mode) {}

download::DownloadItemMode DownloadItemView::GetMode() const {}

void DownloadItemView::UpdateFilePathAndIcons() {}

void DownloadItemView::StartLoadIcons() {}

void DownloadItemView::UpdateLabels() {}

void DownloadItemView::UpdateButtons() {}

void DownloadItemView::UpdateAccessibleAlertAndAnimationsForNormalMode() {}

void DownloadItemView::UpdateAccessibleAlert(
    const std::u16string& accessible_alert_text) {}

void DownloadItemView::UpdateAnimationForDeepScanningMode() {}

std::u16string DownloadItemView::GetInProgressAccessibleAlertText() const {}

void DownloadItemView::AnnounceAccessibleAlert() {}

void DownloadItemView::OnFileIconLoaded(IconLoader::IconSize icon_size,
                                        gfx::Image icon_bitmap) {}

void DownloadItemView::PaintDownloadProgress(
    gfx::Canvas* canvas,
    const gfx::RectF& bounds,
    const base::TimeDelta& indeterminate_progress_time,
    int percent_done) const {}

ui::ImageModel DownloadItemView::GetIcon() const {}

gfx::RectF DownloadItemView::GetIconBounds() const {}

std::pair<std::u16string, int> DownloadItemView::GetStatusTextAndStyle() const {}

gfx::Size DownloadItemView::GetButtonSize() const {}

std::u16string DownloadItemView::ElidedFilename(
    const views::Label& label) const {}

std::u16string DownloadItemView::ElidedFilename(
    const views::StyledLabel& label) const {}

int DownloadItemView::CenterY(int element_height) const {}

int DownloadItemView::GetLabelWidth(const views::StyledLabel& label) const {}

void DownloadItemView::SetDropdownPressed(bool pressed) {}

bool DownloadItemView::GetDropdownPressed() const {}

void DownloadItemView::UpdateDropdownButtonImage() {}

void DownloadItemView::OpenButtonPressed() {}

void DownloadItemView::DropdownButtonPressed(const ui::Event& event) {}

void DownloadItemView::ReviewButtonPressed() {}

void DownloadItemView::ShowOpenDialog(content::WebContents* web_contents) {}

void DownloadItemView::ShowContextMenuImpl(const gfx::Rect& rect,
                                           ui::MenuSourceType source_type) {}

void DownloadItemView::OpenDownloadDuringAsyncScanning() {}

void DownloadItemView::ExecuteCommand(DownloadCommands::Command command) {}

std::u16string DownloadItemView::GetStatusTextForTesting() const {}

void DownloadItemView::OpenItemForTesting() {}

DEFINE_ENUM_CONVERTERS()

BEGIN_METADATA()