Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1619)

Side by Side Diff: chrome/browser/ui/views/download/download_item_view.h

Issue 2744463002: Add VectorIconButton functionality to ImageButton. (Closed)
Patch Set: wip: address high-level comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // A view that implements one download on the Download shelf. 5 // A view that implements one download on the Download shelf.
6 // Each DownloadItemView contains an application icon, a text label 6 // Each DownloadItemView contains an application icon, a text label
7 // indicating the download's file name, a text label indicating the 7 // indicating the download's file name, a text label indicating the
8 // download's status (such as the number of bytes downloaded so far) 8 // download's status (such as the number of bytes downloaded so far)
9 // and a button for canceling an in progress download, or opening 9 // and a button for canceling an in progress download, or opening
10 // the completed download. 10 // the completed download.
(...skipping 16 matching lines...) Expand all
27 #include "base/timer/timer.h" 27 #include "base/timer/timer.h"
28 #include "chrome/browser/download/download_commands.h" 28 #include "chrome/browser/download/download_commands.h"
29 #include "chrome/browser/download/download_item_model.h" 29 #include "chrome/browser/download/download_item_model.h"
30 #include "chrome/browser/icon_manager.h" 30 #include "chrome/browser/icon_manager.h"
31 #include "content/public/browser/download_item.h" 31 #include "content/public/browser/download_item.h"
32 #include "content/public/browser/download_manager.h" 32 #include "content/public/browser/download_manager.h"
33 #include "ui/gfx/animation/animation_delegate.h" 33 #include "ui/gfx/animation/animation_delegate.h"
34 #include "ui/gfx/font_list.h" 34 #include "ui/gfx/font_list.h"
35 #include "ui/views/animation/ink_drop_host_view.h" 35 #include "ui/views/animation/ink_drop_host_view.h"
36 #include "ui/views/context_menu_controller.h" 36 #include "ui/views/context_menu_controller.h"
37 #include "ui/views/controls/button/vector_icon_button_delegate.h" 37 #include "ui/views/controls/button/button.h"
38 #include "ui/views/controls/button/vector_icon_image_updater.h"
38 39
39 class DownloadShelfView; 40 class DownloadShelfView;
40 class DownloadShelfContextMenuView; 41 class DownloadShelfContextMenuView;
41 42
42 namespace extensions { 43 namespace extensions {
43 class ExperienceSamplingEvent; 44 class ExperienceSamplingEvent;
44 } 45 }
45 46
46 namespace gfx { 47 namespace gfx {
47 class Image; 48 class Image;
48 class ImageSkia; 49 class ImageSkia;
49 class SlideAnimation; 50 class SlideAnimation;
50 } 51 }
51 52
52 namespace ui { 53 namespace ui {
53 class ThemeProvider; 54 class ThemeProvider;
54 } 55 }
55 56
56 namespace views { 57 namespace views {
58 class ImageButton;
57 class Label; 59 class Label;
58 class MdTextButton; 60 class MdTextButton;
59 } 61 }
60 62
61 // Represents a single download item on the download shelf. Encompasses an icon, 63 // Represents a single download item on the download shelf. Encompasses an icon,
62 // text, malicious download warnings, etc. 64 // text, malicious download warnings, etc.
63 class DownloadItemView : public views::InkDropHostView, 65 class DownloadItemView : public views::InkDropHostView,
64 public views::VectorIconButtonDelegate, 66 public views::ButtonListener,
65 public views::ContextMenuController, 67 public views::ContextMenuController,
66 public content::DownloadItem::Observer, 68 public content::DownloadItem::Observer,
67 public gfx::AnimationDelegate { 69 public gfx::AnimationDelegate {
68 public: 70 public:
69 DownloadItemView(content::DownloadItem* download, DownloadShelfView* parent); 71 DownloadItemView(content::DownloadItem* download, DownloadShelfView* parent);
70 ~DownloadItemView() override; 72 ~DownloadItemView() override;
71 73
72 // Timer callback for handling animations 74 // Timer callback for handling animations
73 void UpdateDownloadProgress(); 75 void UpdateDownloadProgress();
74 void StartDownloadProgress(); 76 void StartDownloadProgress();
75 void StopDownloadProgress(); 77 void StopDownloadProgress();
76 78
77 // Returns the base color for text on this download item, based on |theme|. 79 // Returns the base color for text on this download item, based on |theme|.
78 static SkColor GetTextColorForThemeProvider(const ui::ThemeProvider* theme); 80 static SkColor GetTextColorForThemeProvider(const ui::ThemeProvider* theme);
79 81
80 // IconManager::Client interface. 82 // IconManager::Client:
81 void OnExtractIconComplete(gfx::Image* icon); 83 void OnExtractIconComplete(gfx::Image* icon);
82 84
83 // Returns the DownloadItem model object belonging to this item. 85 // Returns the DownloadItem model object belonging to this item.
84 content::DownloadItem* download() { return model_.download(); } 86 content::DownloadItem* download() { return model_.download(); }
85 87
86 // Submits download to download feedback service if the user has approved and 88 // Submits download to download feedback service if the user has approved and
87 // the download is suitable for submission, then apply |download_command|. 89 // the download is suitable for submission, then apply |download_command|.
88 // If user hasn't seen SBER opt-in text before, show SBER opt-in dialog first. 90 // If user hasn't seen SBER opt-in text before, show SBER opt-in dialog first.
89 void MaybeSubmitDownloadToFeedbackService( 91 void MaybeSubmitDownloadToFeedbackService(
90 DownloadCommands::Command download_command); 92 DownloadCommands::Command download_command);
91 93
92 // DownloadItem::Observer methods 94 // DownloadItem::Observer:
93 void OnDownloadUpdated(content::DownloadItem* download) override; 95 void OnDownloadUpdated(content::DownloadItem* download) override;
94 void OnDownloadOpened(content::DownloadItem* download) override; 96 void OnDownloadOpened(content::DownloadItem* download) override;
95 void OnDownloadDestroyed(content::DownloadItem* download) override; 97 void OnDownloadDestroyed(content::DownloadItem* download) override;
96 98
97 // Overridden from views::View: 99 // views::View:
98 void Layout() override; 100 void Layout() override;
99 gfx::Size GetPreferredSize() const override; 101 gfx::Size GetPreferredSize() const override;
100 bool OnMousePressed(const ui::MouseEvent& event) override; 102 bool OnMousePressed(const ui::MouseEvent& event) override;
101 bool OnMouseDragged(const ui::MouseEvent& event) override; 103 bool OnMouseDragged(const ui::MouseEvent& event) override;
102 void OnMouseReleased(const ui::MouseEvent& event) override; 104 void OnMouseReleased(const ui::MouseEvent& event) override;
103 void OnMouseCaptureLost() override; 105 void OnMouseCaptureLost() override;
104 bool OnKeyPressed(const ui::KeyEvent& event) override; 106 bool OnKeyPressed(const ui::KeyEvent& event) override;
105 bool GetTooltipText(const gfx::Point& p, 107 bool GetTooltipText(const gfx::Point& p,
106 base::string16* tooltip) const override; 108 base::string16* tooltip) const override;
107 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; 109 void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
108 void OnThemeChanged() override; 110 void OnThemeChanged() override;
109 111
110 // Overridden from view::InkDropHostView: 112 // view::InkDropHostView:
111 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; 113 void AddInkDropLayer(ui::Layer* ink_drop_layer) override;
112 std::unique_ptr<views::InkDrop> CreateInkDrop() override; 114 std::unique_ptr<views::InkDrop> CreateInkDrop() override;
113 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override; 115 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
114 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() 116 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
115 const override; 117 const override;
116 118
117 // Overridden from ui::EventHandler: 119 // ui::EventHandler:
118 void OnGestureEvent(ui::GestureEvent* event) override; 120 void OnGestureEvent(ui::GestureEvent* event) override;
119 121
120 // Overridden from views::ContextMenuController. 122 // views::ContextMenuController:
121 void ShowContextMenuForView(View* source, 123 void ShowContextMenuForView(View* source,
122 const gfx::Point& point, 124 const gfx::Point& point,
123 ui::MenuSourceType source_type) override; 125 ui::MenuSourceType source_type) override;
124 126
125 // VectorIconButtonDelegate implementation. 127 // views::ButtonListener:
126 void ButtonPressed(views::Button* sender, const ui::Event& event) override; 128 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
127 SkColor GetVectorIconBaseColor() const override;
128 129
129 // gfx::AnimationDelegate implementation. 130 // gfx::AnimationDelegate:
130 void AnimationProgressed(const gfx::Animation* animation) override; 131 void AnimationProgressed(const gfx::Animation* animation) override;
131 132
132 protected: 133 protected:
133 // Overridden from views::View: 134 // views::View:
134 void OnPaint(gfx::Canvas* canvas) override; 135 void OnPaint(gfx::Canvas* canvas) override;
135 void OnFocus() override; 136 void OnFocus() override;
136 void OnBlur() override; 137 void OnBlur() override;
137 138
138 private: 139 private:
139 FRIEND_TEST_ALL_PREFIXES(DownloadItemViewDangerousDownloadLabelTest, 140 FRIEND_TEST_ALL_PREFIXES(DownloadItemViewDangerousDownloadLabelTest,
140 AdjustTextAndGetSize); 141 AdjustTextAndGetSize);
141 142
143 class DropDownButtonImageUpdater : public views::VectorIconImageUpdater {
144 public:
145 DropDownButtonImageUpdater(const gfx::VectorIcon& icon,
146 const DownloadItemView* parent);
147
148 protected:
149 // views::VectorIconImageUpdater:
150 SkColor GetVectorIconColor() const override;
151
152 private:
153 const DownloadItemView* parent_;
154 };
155
142 enum State { NORMAL = 0, HOT, PUSHED }; 156 enum State { NORMAL = 0, HOT, PUSHED };
143 class DropDownButton; 157 class DropDownButton;
144 158
145 enum Mode { 159 enum Mode {
146 NORMAL_MODE = 0, // Showing download item. 160 NORMAL_MODE = 0, // Showing download item.
147 DANGEROUS_MODE, // Displaying the dangerous download warning. 161 DANGEROUS_MODE, // Displaying the dangerous download warning.
148 MALICIOUS_MODE // Displaying the malicious download warning. 162 MALICIOUS_MODE // Displaying the malicious download warning.
149 }; 163 };
150 164
151 void OpenDownload(); 165 void OpenDownload();
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 std::unique_ptr<gfx::SlideAnimation> complete_animation_; 312 std::unique_ptr<gfx::SlideAnimation> complete_animation_;
299 313
300 // Progress animation 314 // Progress animation
301 base::RepeatingTimer progress_timer_; 315 base::RepeatingTimer progress_timer_;
302 316
303 // Dangerous mode buttons. 317 // Dangerous mode buttons.
304 views::MdTextButton* save_button_; 318 views::MdTextButton* save_button_;
305 views::MdTextButton* discard_button_; 319 views::MdTextButton* discard_button_;
306 320
307 // The drop down button. 321 // The drop down button.
308 DropDownButton* dropdown_button_; 322 views::ImageButton* dropdown_button_;
309 323
310 // Dangerous mode label. 324 // Dangerous mode label.
311 views::Label* dangerous_download_label_; 325 views::Label* dangerous_download_label_;
312 326
313 // Whether the dangerous mode label has been sized yet. 327 // Whether the dangerous mode label has been sized yet.
314 bool dangerous_download_label_sized_; 328 bool dangerous_download_label_sized_;
315 329
316 // Whether we are currently disabled as part of opening the downloaded file. 330 // Whether we are currently disabled as part of opening the downloaded file.
317 bool disabled_while_opening_; 331 bool disabled_while_opening_;
318 332
(...skipping 11 matching lines...) Expand all
330 344
331 // The icon loaded in the download shelf is based on the file path of the 345 // The icon loaded in the download shelf is based on the file path of the
332 // item. Store the path used, so that we can detect a change in the path 346 // item. Store the path used, so that we can detect a change in the path
333 // and reload the icon. 347 // and reload the icon.
334 base::FilePath last_download_item_path_; 348 base::FilePath last_download_item_path_;
335 349
336 // ExperienceSampling: This tracks dangerous/malicious downloads warning UI 350 // ExperienceSampling: This tracks dangerous/malicious downloads warning UI
337 // and the user's decisions about it. 351 // and the user's decisions about it.
338 std::unique_ptr<extensions::ExperienceSamplingEvent> sampling_event_; 352 std::unique_ptr<extensions::ExperienceSamplingEvent> sampling_event_;
339 353
354 // TODO: finish comment. This class is not the owner.
355 DropDownButtonImageUpdater* button_image_updater_;
356
340 // Method factory used to delay reenabling of the item when opening the 357 // Method factory used to delay reenabling of the item when opening the
341 // downloaded file. 358 // downloaded file.
342 base::WeakPtrFactory<DownloadItemView> weak_ptr_factory_; 359 base::WeakPtrFactory<DownloadItemView> weak_ptr_factory_;
343 360
344 DISALLOW_COPY_AND_ASSIGN(DownloadItemView); 361 DISALLOW_COPY_AND_ASSIGN(DownloadItemView);
345 }; 362 };
346 363
347 #endif // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H_ 364 #endif // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698