File: download_shelf_view.h

package info (click to toggle)
chromium 139.0.7258.138-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,120,676 kB
  • sloc: cpp: 35,100,869; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (126 lines) | stat: -rw-r--r-- 4,408 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// 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.

#ifndef CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_SHELF_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_SHELF_VIEW_H_

#include <memory>
#include <vector>

#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "chrome/browser/download/download_shelf.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/gfx/animation/slide_animation.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/views/accessible_pane_view.h"
#include "ui/views/animation/animation_delegate_views.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/mouse_watcher.h"
#include "ui/views/mouse_watcher_view_host.h"

class Browser;
class BrowserView;
class DownloadItemView;

namespace views {
class ImageButton;
class MdTextButton;
}  // namespace views

// DownloadShelfView is a view that contains individual views for each download,
// as well as a close button and a link to show all downloads.
//
// DownloadShelfView does not hold an infinite number of download views, rather
// it'll automatically remove views once a certain point is reached.
class DownloadShelfView : public DownloadShelf,
                          public views::AccessiblePaneView,
                          public views::AnimationDelegateViews,
                          public views::MouseWatcherListener {
  METADATA_HEADER(DownloadShelfView, views::AccessiblePaneView)

 public:
  DownloadShelfView(Browser* browser, BrowserView* parent);
  DownloadShelfView(const DownloadShelfView&) = delete;
  DownloadShelfView& operator=(const DownloadShelfView&) = delete;
  ~DownloadShelfView() override;

  // DownloadShelf:
  bool IsShowing() const override;
  bool IsClosing() const override;

  views::View* GetView() override;

  // views::AccessiblePaneView:
  // TODO(crbug.com/40648316): Replace these with a LayoutManager
  gfx::Size CalculatePreferredSize(
      const views::SizeBounds& /*available_size*/) const override;
  void Layout(PassKey) override;

  // views::AnimationDelegateViews:
  void AnimationProgressed(const gfx::Animation* animation) override;
  void AnimationEnded(const gfx::Animation* animation) override;

  // views::MouseWatcherListener:
  void MouseMovedOutOfHost() override;

  // Sent from the DownloadItemView when the user opens an item.
  void AutoClose();

  // Removes a specified download view. The supplied view is deleted after
  // it's removed.
  void RemoveDownloadView(views::View* view);

  // Updates |button| according to the active theme.
  void ConfigureButtonForTheme(views::MdTextButton* button);

  DownloadItemView* GetViewOfLastDownloadItemForTesting();

 protected:
  // DownloadShelf:
  void DoShowDownload(DownloadUIModel::DownloadUIModelPtr download) override;
  void DoOpen() override;
  void DoClose() override;
  void DoHide() override;
  void DoUnhide() override;

  // views::AccessiblePaneView:
  void OnPaintBorder(gfx::Canvas* canvas) override;
  void OnThemeChanged() override;
  views::View* GetDefaultFocusableChild() override;

 private:
  FRIEND_TEST_ALL_PREFIXES(DownloadShelfViewTest, ShowAllViewColors);

  // The animation for adding new items to the shelf.
  gfx::SlideAnimation new_item_animation_{this};

  // The show/hide animation for the shelf itself.
  gfx::SlideAnimation shelf_animation_{this};

  // The download views. These are also child Views, and deleted when
  // the DownloadShelfView is deleted.
  // TODO(pkasting): Remove this in favor of making these the children of a
  // nested view, so they can easily be laid out and iterated.
  std::vector<raw_ptr<DownloadItemView, VectorExperimental>> download_views_;

  // Button for showing all downloads (chrome://downloads).
  raw_ptr<views::MdTextButton> show_all_view_;

  // Button for closing the downloads. This is contained as a child, and
  // deleted by View.
  raw_ptr<views::ImageButton> close_button_;

  // Hidden view that will contain status text for immediate output by
  // screen readers.
  raw_ptr<views::View> accessible_alert_;

  // The window this shelf belongs to.
  raw_ptr<BrowserView> parent_;

  views::MouseWatcher mouse_watcher_{
      std::make_unique<views::MouseWatcherViewHost>(this, gfx::Insets()), this};
};

#endif  // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_SHELF_VIEW_H_