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

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

Issue 2744463002: Add VectorIconButton functionality to ImageButton. (Closed)
Patch Set: check details 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 38
39 class DownloadShelfView; 39 class DownloadShelfView;
40 class DownloadShelfContextMenuView; 40 class DownloadShelfContextMenuView;
41 41
42 namespace extensions { 42 namespace extensions {
43 class ExperienceSamplingEvent; 43 class ExperienceSamplingEvent;
44 } 44 }
45 45
46 namespace gfx { 46 namespace gfx {
47 class Image; 47 class Image;
48 class ImageSkia; 48 class ImageSkia;
49 class SlideAnimation; 49 class SlideAnimation;
50 } 50 }
51 51
52 namespace ui { 52 namespace ui {
53 class ThemeProvider; 53 class ThemeProvider;
54 } 54 }
55 55
56 namespace views { 56 namespace views {
57 class ImageButton;
57 class Label; 58 class Label;
58 class MdTextButton; 59 class MdTextButton;
60 class ViewHierarchyChangedDetails;
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.
81 void OnExtractIconComplete(gfx::Image* icon); 82 void OnExtractIconComplete(gfx::Image* icon);
82 83
83 // Returns the DownloadItem model object belonging to this item. 84 // Returns the DownloadItem model object belonging to this item.
84 content::DownloadItem* download() { return model_.download(); } 85 content::DownloadItem* download() { return model_.download(); }
85 86
86 // Submits download to download feedback service if the user has approved and 87 // Submits download to download feedback service if the user has approved and
87 // the download is suitable for submission, then apply |download_command|. 88 // 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. 89 // If user hasn't seen SBER opt-in text before, show SBER opt-in dialog first.
89 void MaybeSubmitDownloadToFeedbackService( 90 void MaybeSubmitDownloadToFeedbackService(
90 DownloadCommands::Command download_command); 91 DownloadCommands::Command download_command);
91 92
92 // DownloadItem::Observer methods 93 // content::DownloadItem::Observer:
93 void OnDownloadUpdated(content::DownloadItem* download) override; 94 void OnDownloadUpdated(content::DownloadItem* download) override;
94 void OnDownloadOpened(content::DownloadItem* download) override; 95 void OnDownloadOpened(content::DownloadItem* download) override;
95 void OnDownloadDestroyed(content::DownloadItem* download) override; 96 void OnDownloadDestroyed(content::DownloadItem* download) override;
96 97
97 // Overridden from views::View: 98 // views::View:
98 void Layout() override; 99 void Layout() override;
99 gfx::Size GetPreferredSize() const override; 100 gfx::Size GetPreferredSize() const override;
100 bool OnMousePressed(const ui::MouseEvent& event) override; 101 bool OnMousePressed(const ui::MouseEvent& event) override;
101 bool OnMouseDragged(const ui::MouseEvent& event) override; 102 bool OnMouseDragged(const ui::MouseEvent& event) override;
102 void OnMouseReleased(const ui::MouseEvent& event) override; 103 void OnMouseReleased(const ui::MouseEvent& event) override;
103 void OnMouseCaptureLost() override; 104 void OnMouseCaptureLost() override;
104 bool OnKeyPressed(const ui::KeyEvent& event) override; 105 bool OnKeyPressed(const ui::KeyEvent& event) override;
105 bool GetTooltipText(const gfx::Point& p, 106 bool GetTooltipText(const gfx::Point& p,
106 base::string16* tooltip) const override; 107 base::string16* tooltip) const override;
107 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; 108 void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
108 void OnThemeChanged() override; 109 void OnThemeChanged() override;
110 void ViewHierarchyChanged(
111 const ViewHierarchyChangedDetails& details) override;
109 112
110 // Overridden from view::InkDropHostView: 113 // view::InkDropHostView:
111 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; 114 void AddInkDropLayer(ui::Layer* ink_drop_layer) override;
112 std::unique_ptr<views::InkDrop> CreateInkDrop() override; 115 std::unique_ptr<views::InkDrop> CreateInkDrop() override;
113 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override; 116 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
114 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() 117 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
115 const override; 118 const override;
116 119
117 // Overridden from ui::EventHandler: 120 // ui::EventHandler:
118 void OnGestureEvent(ui::GestureEvent* event) override; 121 void OnGestureEvent(ui::GestureEvent* event) override;
119 122
120 // Overridden from views::ContextMenuController. 123 // views::ContextMenuController.
121 void ShowContextMenuForView(View* source, 124 void ShowContextMenuForView(View* source,
122 const gfx::Point& point, 125 const gfx::Point& point,
123 ui::MenuSourceType source_type) override; 126 ui::MenuSourceType source_type) override;
124 127
125 // VectorIconButtonDelegate implementation. 128 // views::ButtonListener:
126 void ButtonPressed(views::Button* sender, const ui::Event& event) override; 129 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
127 SkColor GetVectorIconBaseColor() const override;
128 130
129 // gfx::AnimationDelegate implementation. 131 // gfx::AnimationDelegate implementation.
130 void AnimationProgressed(const gfx::Animation* animation) override; 132 void AnimationProgressed(const gfx::Animation* animation) override;
131 133
132 protected: 134 protected:
133 // Overridden from views::View: 135 // views::View:
134 void OnPaint(gfx::Canvas* canvas) override; 136 void OnPaint(gfx::Canvas* canvas) override;
135 void OnFocus() override; 137 void OnFocus() override;
136 void OnBlur() override; 138 void OnBlur() override;
137 139
138 private: 140 private:
139 FRIEND_TEST_ALL_PREFIXES(DownloadItemViewDangerousDownloadLabelTest, 141 FRIEND_TEST_ALL_PREFIXES(DownloadItemViewDangerousDownloadLabelTest,
140 AdjustTextAndGetSize); 142 AdjustTextAndGetSize);
141 143
142 enum State { NORMAL = 0, HOT, PUSHED }; 144 enum State { NORMAL = 0, HOT, PUSHED };
143 class DropDownButton;
144 145
145 enum Mode { 146 enum Mode {
146 NORMAL_MODE = 0, // Showing download item. 147 NORMAL_MODE = 0, // Showing download item.
147 DANGEROUS_MODE, // Displaying the dangerous download warning. 148 DANGEROUS_MODE, // Displaying the dangerous download warning.
148 MALICIOUS_MODE // Displaying the malicious download warning. 149 MALICIOUS_MODE // Displaying the malicious download warning.
149 }; 150 };
150 151
151 void OpenDownload(); 152 void OpenDownload();
152 153
153 // Submits the downloaded file to the safebrowsing download feedback service. 154 // Submits the downloaded file to the safebrowsing download feedback service.
(...skipping 16 matching lines...) Expand all
170 void DrawStatusText(gfx::Canvas* canvas); 171 void DrawStatusText(gfx::Canvas* canvas);
171 void DrawFilename(gfx::Canvas* canvas); 172 void DrawFilename(gfx::Canvas* canvas);
172 void DrawIcon(gfx::Canvas* canvas); 173 void DrawIcon(gfx::Canvas* canvas);
173 174
174 void LoadIcon(); 175 void LoadIcon();
175 void LoadIconIfItemPathChanged(); 176 void LoadIconIfItemPathChanged();
176 177
177 // Update the button colors based on the current theme. 178 // Update the button colors based on the current theme.
178 void UpdateColorsFromTheme(); 179 void UpdateColorsFromTheme();
179 180
181 void UpdateDropdownButton();
182
180 // Shows the context menu at the specified location. |point| is in the view's 183 // Shows the context menu at the specified location. |point| is in the view's
181 // coordinate system. 184 // coordinate system.
182 void ShowContextMenuImpl(const gfx::Rect& rect, 185 void ShowContextMenuImpl(const gfx::Rect& rect,
183 ui::MenuSourceType source_type); 186 ui::MenuSourceType source_type);
184 187
185 // Common code for handling pointer events (i.e. mouse or gesture). 188 // Common code for handling pointer events (i.e. mouse or gesture).
186 void HandlePressEvent(const ui::LocatedEvent& event, bool active_event); 189 void HandlePressEvent(const ui::LocatedEvent& event, bool active_event);
187 void HandleClickEvent(const ui::LocatedEvent& event, bool active_event); 190 void HandleClickEvent(const ui::LocatedEvent& event, bool active_event);
188 191
189 // Sets the state and triggers a repaint. 192 // Sets the state and triggers a repaint.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 std::unique_ptr<gfx::SlideAnimation> complete_animation_; 301 std::unique_ptr<gfx::SlideAnimation> complete_animation_;
299 302
300 // Progress animation 303 // Progress animation
301 base::RepeatingTimer progress_timer_; 304 base::RepeatingTimer progress_timer_;
302 305
303 // Dangerous mode buttons. 306 // Dangerous mode buttons.
304 views::MdTextButton* save_button_; 307 views::MdTextButton* save_button_;
305 views::MdTextButton* discard_button_; 308 views::MdTextButton* discard_button_;
306 309
307 // The drop down button. 310 // The drop down button.
308 DropDownButton* dropdown_button_; 311 views::ImageButton* dropdown_button_;
309 312
310 // Dangerous mode label. 313 // Dangerous mode label.
311 views::Label* dangerous_download_label_; 314 views::Label* dangerous_download_label_;
312 315
313 // Whether the dangerous mode label has been sized yet. 316 // Whether the dangerous mode label has been sized yet.
314 bool dangerous_download_label_sized_; 317 bool dangerous_download_label_sized_;
315 318
316 // Whether we are currently disabled as part of opening the downloaded file. 319 // Whether we are currently disabled as part of opening the downloaded file.
317 bool disabled_while_opening_; 320 bool disabled_while_opening_;
318 321
(...skipping 19 matching lines...) Expand all
338 std::unique_ptr<extensions::ExperienceSamplingEvent> sampling_event_; 341 std::unique_ptr<extensions::ExperienceSamplingEvent> sampling_event_;
339 342
340 // Method factory used to delay reenabling of the item when opening the 343 // Method factory used to delay reenabling of the item when opening the
341 // downloaded file. 344 // downloaded file.
342 base::WeakPtrFactory<DownloadItemView> weak_ptr_factory_; 345 base::WeakPtrFactory<DownloadItemView> weak_ptr_factory_;
343 346
344 DISALLOW_COPY_AND_ASSIGN(DownloadItemView); 347 DISALLOW_COPY_AND_ASSIGN(DownloadItemView);
345 }; 348 };
346 349
347 #endif // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H_ 350 #endif // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698