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

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

Issue 2346043002: Delete old (pre-MD) download shelf view code. (Closed)
Patch Set: gotta git add Created 4 years, 3 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
« no previous file with comments | « chrome/browser/ui/BUILD.gn ('k') | chrome/browser/ui/views/download/download_item_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 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 ChromeView 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.
11 // 11 //
12 // The DownloadItemView lives in the Browser, and has a corresponding 12 // The DownloadItemView lives in the Browser, and has a corresponding
13 // DownloadController that receives / writes data which lives in the 13 // DownloadController that receives / writes data which lives in the
14 // Renderer. 14 // Renderer.
15 15
16 #ifndef CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H__ 16 #ifndef CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H_
17 #define CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H__ 17 #define CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H_
18 18
19 #include <memory> 19 #include <memory>
20 #include <string> 20 #include <string>
21 21
22 #include "base/macros.h" 22 #include "base/macros.h"
23 #include "base/memory/weak_ptr.h" 23 #include "base/memory/weak_ptr.h"
24 #include "base/strings/string_util.h" 24 #include "base/strings/string_util.h"
25 #include "base/task/cancelable_task_tracker.h" 25 #include "base/task/cancelable_task_tracker.h"
26 #include "base/time/time.h" 26 #include "base/time/time.h"
27 #include "base/timer/timer.h" 27 #include "base/timer/timer.h"
28 #include "chrome/browser/download/download_item_model.h" 28 #include "chrome/browser/download/download_item_model.h"
29 #include "chrome/browser/icon_manager.h" 29 #include "chrome/browser/icon_manager.h"
30 #include "content/public/browser/download_item.h" 30 #include "content/public/browser/download_item.h"
31 #include "content/public/browser/download_manager.h" 31 #include "content/public/browser/download_manager.h"
32 #include "ui/gfx/animation/animation_delegate.h" 32 #include "ui/gfx/animation/animation_delegate.h"
33 #include "ui/gfx/font_list.h" 33 #include "ui/gfx/font_list.h"
34 #include "ui/views/animation/ink_drop_host_view.h"
34 #include "ui/views/context_menu_controller.h" 35 #include "ui/views/context_menu_controller.h"
35 #include "ui/views/controls/button/button.h" 36 #include "ui/views/controls/button/vector_icon_button_delegate.h"
36 #include "ui/views/view.h"
37 37
38 class DownloadShelfView; 38 class DownloadShelfView;
39 class DownloadShelfContextMenuView; 39 class DownloadShelfContextMenuView;
40 40
41 namespace extensions { 41 namespace extensions {
42 class ExperienceSamplingEvent; 42 class ExperienceSamplingEvent;
43 } 43 }
44 44
45 namespace gfx { 45 namespace gfx {
46 class Image; 46 class Image;
47 class ImageSkia; 47 class ImageSkia;
48 class SlideAnimation; 48 class SlideAnimation;
49 } 49 }
50 50
51 namespace ui {
52 class ThemeProvider;
53 }
54
51 namespace views { 55 namespace views {
56 class ImageButton;
52 class Label; 57 class Label;
53 class LabelButton; 58 class LabelButton;
54 } 59 }
55 60
56 class DownloadItemView : public views::ButtonListener, 61 // Represents a single download item on the download shelf. Encompasses an icon,
57 public views::View, 62 // text, malicious download warnings, etc.
63 class DownloadItemView : public views::InkDropHostView,
64 public views::VectorIconButtonDelegate,
58 public views::ContextMenuController, 65 public views::ContextMenuController,
59 public content::DownloadItem::Observer, 66 public content::DownloadItem::Observer,
60 public gfx::AnimationDelegate { 67 public gfx::AnimationDelegate {
61 public: 68 public:
62 DownloadItemView(content::DownloadItem* download, DownloadShelfView* parent); 69 DownloadItemView(content::DownloadItem* download, DownloadShelfView* parent);
63 ~DownloadItemView() override; 70 ~DownloadItemView() override;
64 71
65 // Timer callback for handling animations 72 // Timer callback for handling animations
66 void UpdateDownloadProgress(); 73 void UpdateDownloadProgress();
67 void StartDownloadProgress(); 74 void StartDownloadProgress();
68 void StopDownloadProgress(); 75 void StopDownloadProgress();
69 76
77 // Returns the base color for text on this download item, based on |theme|.
78 static SkColor GetTextColorForThemeProvider(const ui::ThemeProvider* theme);
79
70 // IconManager::Client interface. 80 // IconManager::Client interface.
71 void OnExtractIconComplete(gfx::Image* icon); 81 void OnExtractIconComplete(gfx::Image* icon);
72 82
73 // Returns the DownloadItem model object belonging to this item. 83 // Returns the DownloadItem model object belonging to this item.
74 content::DownloadItem* download() { return model_.download(); } 84 content::DownloadItem* download() { return model_.download(); }
75 85
76 // DownloadItem::Observer methods 86 // DownloadItem::Observer methods
77 void OnDownloadUpdated(content::DownloadItem* download) override; 87 void OnDownloadUpdated(content::DownloadItem* download) override;
78 void OnDownloadOpened(content::DownloadItem* download) override; 88 void OnDownloadOpened(content::DownloadItem* download) override;
79 void OnDownloadDestroyed(content::DownloadItem* download) override; 89 void OnDownloadDestroyed(content::DownloadItem* download) override;
80 90
81 // Overridden from views::View: 91 // Overridden from views::View:
82 void Layout() override; 92 void Layout() override;
83 gfx::Size GetPreferredSize() const override; 93 gfx::Size GetPreferredSize() const override;
84 bool OnMousePressed(const ui::MouseEvent& event) override; 94 bool OnMousePressed(const ui::MouseEvent& event) override;
85 bool OnMouseDragged(const ui::MouseEvent& event) override; 95 bool OnMouseDragged(const ui::MouseEvent& event) override;
86 void OnMouseReleased(const ui::MouseEvent& event) override; 96 void OnMouseReleased(const ui::MouseEvent& event) override;
87 void OnMouseCaptureLost() override; 97 void OnMouseCaptureLost() override;
88 void OnMouseMoved(const ui::MouseEvent& event) override;
89 void OnMouseExited(const ui::MouseEvent& event) override;
90 bool OnKeyPressed(const ui::KeyEvent& event) override; 98 bool OnKeyPressed(const ui::KeyEvent& event) override;
91 bool GetTooltipText(const gfx::Point& p, 99 bool GetTooltipText(const gfx::Point& p,
92 base::string16* tooltip) const override; 100 base::string16* tooltip) const override;
93 void GetAccessibleState(ui::AXViewState* state) override; 101 void GetAccessibleState(ui::AXViewState* state) override;
94 void OnThemeChanged() override; 102 void OnThemeChanged() override;
95 103
104 // Overridden from view::InkDropHostView:
105 void AddInkDropLayer(ui::Layer* ink_drop_layer) override;
106 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
107 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
108 const override;
109
96 // Overridden from ui::EventHandler: 110 // Overridden from ui::EventHandler:
97 void OnGestureEvent(ui::GestureEvent* event) override; 111 void OnGestureEvent(ui::GestureEvent* event) override;
98 112
99 // Overridden from views::ContextMenuController. 113 // Overridden from views::ContextMenuController.
100 void ShowContextMenuForView(View* source, 114 void ShowContextMenuForView(View* source,
101 const gfx::Point& point, 115 const gfx::Point& point,
102 ui::MenuSourceType source_type) override; 116 ui::MenuSourceType source_type) override;
103 117
104 // ButtonListener implementation. 118 // VectorIconButtonDelegate implementation.
105 void ButtonPressed(views::Button* sender, const ui::Event& event) override; 119 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
120 SkColor GetVectorIconBaseColor() const override;
106 121
107 // gfx::AnimationDelegate implementation. 122 // gfx::AnimationDelegate implementation.
108 void AnimationProgressed(const gfx::Animation* animation) override; 123 void AnimationProgressed(const gfx::Animation* animation) override;
109 124
110 protected: 125 protected:
111 // Overridden from views::View: 126 // Overridden from views::View:
112 void OnPaint(gfx::Canvas* canvas) override; 127 void OnPaint(gfx::Canvas* canvas) override;
113 void OnPaintBackground(gfx::Canvas* canvas) override;
114 void OnFocus() override; 128 void OnFocus() override;
115 void OnBlur() override; 129 void OnBlur() override;
116 130
117 private: 131 private:
118 enum State { 132 enum State { NORMAL = 0, HOT, PUSHED };
119 NORMAL = 0, 133 class DropDownButton;
120 HOT,
121 PUSHED
122 };
123 134
124 enum Mode { 135 enum Mode {
125 NORMAL_MODE = 0, // Showing download item. 136 NORMAL_MODE = 0, // Showing download item.
126 DANGEROUS_MODE, // Displaying the dangerous download warning. 137 DANGEROUS_MODE, // Displaying the dangerous download warning.
127 MALICIOUS_MODE // Displaying the malicious download warning. 138 MALICIOUS_MODE // Displaying the malicious download warning.
128 };
129
130 // The image set associated with the part containing the icon and text.
131 struct BodyImageSet {
132 gfx::ImageSkia* top_left;
133 gfx::ImageSkia* left;
134 gfx::ImageSkia* bottom_left;
135 gfx::ImageSkia* top;
136 gfx::ImageSkia* center;
137 gfx::ImageSkia* bottom;
138 gfx::ImageSkia* top_right;
139 gfx::ImageSkia* right;
140 gfx::ImageSkia* bottom_right;
141 };
142
143 // The image set associated with the drop-down button on the right.
144 struct DropDownImageSet {
145 gfx::ImageSkia* top;
146 gfx::ImageSkia* center;
147 gfx::ImageSkia* bottom;
148 }; 139 };
149 140
150 void OpenDownload(); 141 void OpenDownload();
151 142
152 // Submits the downloaded file to the safebrowsing download feedback service. 143 // Submits the downloaded file to the safebrowsing download feedback service.
153 // Returns whether submission was successful. On successful submission, 144 // Returns whether submission was successful. On successful submission,
154 // |this| and the DownloadItem will have been deleted. 145 // |this| and the DownloadItem will have been deleted.
155 bool SubmitDownloadToFeedbackService(); 146 bool SubmitDownloadToFeedbackService();
156 147
157 // If the user has |enabled| uploading, calls SubmitDownloadToFeedbackService. 148 // If the user has |enabled| uploading, calls SubmitDownloadToFeedbackService.
158 // Otherwise, it simply removes the DownloadItem without uploading. 149 // Otherwise, it simply removes the DownloadItem without uploading.
159 void PossiblySubmitDownloadToFeedbackService(bool enabled); 150 void PossiblySubmitDownloadToFeedbackService(bool enabled);
160 151
152 // This function calculates the vertical coordinate to draw the file name text
153 // relative to local bounds.
154 int GetYForFilenameText() const;
155
156 // Painting of various download item bits.
157 void DrawStatusText(gfx::Canvas* canvas);
158 void DrawFilename(gfx::Canvas* canvas);
159 void DrawIcon(gfx::Canvas* canvas);
160
161 void LoadIcon(); 161 void LoadIcon();
162 void LoadIconIfItemPathChanged(); 162 void LoadIconIfItemPathChanged();
163 163
164 // Update the button colors based on the current theme. 164 // Update the button colors based on the current theme.
165 void UpdateColorsFromTheme(); 165 void UpdateColorsFromTheme();
166 166
167 // Shows the context menu at the specified location. |point| is in the view's 167 // Shows the context menu at the specified location. |point| is in the view's
168 // coordinate system. 168 // coordinate system.
169 void ShowContextMenuImpl(const gfx::Point& point, 169 void ShowContextMenuImpl(const gfx::Rect& rect,
170 ui::MenuSourceType source_type); 170 ui::MenuSourceType source_type);
171 171
172 // Common code for handling pointer events (i.e. mouse or gesture). 172 // Common code for handling pointer events (i.e. mouse or gesture).
173 void HandlePressEvent(const ui::LocatedEvent& event, bool active_event); 173 void HandlePressEvent(const ui::LocatedEvent& event, bool active_event);
174 void HandleClickEvent(const ui::LocatedEvent& event, bool active_event); 174 void HandleClickEvent(const ui::LocatedEvent& event, bool active_event);
175 175
176 // Convenience method to paint the 3 vertical images (bottom, middle, top)
177 // that form the background.
178 void PaintImages(gfx::Canvas* canvas,
179 const gfx::ImageSkia* top_image,
180 const gfx::ImageSkia* center_image,
181 const gfx::ImageSkia* bottom_image,
182 int x,
183 int y,
184 int height,
185 int width);
186
187 // Sets the state and triggers a repaint. 176 // Sets the state and triggers a repaint.
188 void SetState(State body_state, State drop_down_state); 177 void SetDropdownState(State new_state);
189 178
190 // Whether we are in the dangerous mode. 179 // Whether we are in the dangerous mode.
191 bool IsShowingWarningDialog() const { 180 bool IsShowingWarningDialog() const {
192 return mode_ == DANGEROUS_MODE || mode_ == MALICIOUS_MODE; 181 return mode_ == DANGEROUS_MODE || mode_ == MALICIOUS_MODE;
193 } 182 }
194 183
195 // Clears or shows the warning dialog as per the state of |model_|. 184 // Clears or shows the warning dialog as per the state of |model_|.
196 void ToggleWarningDialog(); 185 void ToggleWarningDialog();
197 186
198 // Reverts from dangerous mode to normal download mode. 187 // Reverts from dangerous mode to normal download mode.
199 void ClearWarningDialog(); 188 void ClearWarningDialog();
200 189
201 // Start displaying the dangerous download warning or the malicious download 190 // Start displaying the dangerous download warning or the malicious download
202 // warning. 191 // warning.
203 void ShowWarningDialog(); 192 void ShowWarningDialog();
204 193
194 // Returns the current warning icon (should only be called when the view is
195 // actually showing a warning).
196 gfx::ImageSkia GetWarningIcon();
197
205 // Sets |size| with the size of the Save and Discard buttons (they have the 198 // Sets |size| with the size of the Save and Discard buttons (they have the
206 // same size). 199 // same size).
207 gfx::Size GetButtonSize() const; 200 gfx::Size GetButtonSize() const;
208 201
209 // Sizes the dangerous download label to a minimum width available using 2 202 // Sizes the dangerous download label to a minimum width available using 2
210 // lines. The size is computed only the first time this method is invoked 203 // lines. The size is computed only the first time this method is invoked
211 // and simply returned on subsequent calls. 204 // and simply returned on subsequent calls.
212 void SizeLabelToMinWidth(); 205 void SizeLabelToMinWidth();
213 206
214 // Reenables the item after it has been disabled when a user clicked it to 207 // Reenables the item after it has been disabled when a user clicked it to
215 // open the downloaded file. 208 // open the downloaded file.
216 void Reenable(); 209 void Reenable();
217 210
218 // Releases drop down button after showing a context menu. 211 // Releases drop down button after showing a context menu.
219 void ReleaseDropDown(); 212 void ReleaseDropdown();
220
221 // Given |x|, returns whether |x| is within the x coordinate range of
222 // the drop-down button or not.
223 bool InDropDownButtonXCoordinateRange(int x);
224 213
225 // Update the accessible name to reflect the current state of the control, 214 // Update the accessible name to reflect the current state of the control,
226 // so that screenreaders can access the filename, status text, and 215 // so that screenreaders can access the filename, status text, and
227 // dangerous download warning message (if any). 216 // dangerous download warning message (if any).
228 void UpdateAccessibleName(); 217 void UpdateAccessibleName();
229 218
230 // Update the location of the drop down button.
231 void UpdateDropDownButtonPosition();
232
233 // Show/Hide/Reset |animation| based on the state transition specified by 219 // Show/Hide/Reset |animation| based on the state transition specified by
234 // |from| and |to|. 220 // |from| and |to|.
235 void AnimateStateTransition(State from, State to, 221 void AnimateStateTransition(State from,
222 State to,
236 gfx::SlideAnimation* animation); 223 gfx::SlideAnimation* animation);
237 224
238 // Callback for |progress_timer_|. 225 // Callback for |progress_timer_|.
239 void ProgressTimerFired(); 226 void ProgressTimerFired();
240 227
241 // The different images used for the background. 228 // Returns the base text color.
242 BodyImageSet normal_body_image_set_; 229 SkColor GetTextColor() const;
243 BodyImageSet hot_body_image_set_;
244 BodyImageSet pushed_body_image_set_;
245 BodyImageSet dangerous_mode_body_image_set_;
246 BodyImageSet malicious_mode_body_image_set_;
247 DropDownImageSet normal_drop_down_image_set_;
248 DropDownImageSet hot_drop_down_image_set_;
249 DropDownImageSet pushed_drop_down_image_set_;
250 230
251 // The warning icon showns for dangerous downloads. 231 // Returns a slightly dimmed version of the base text color.
252 const gfx::ImageSkia* warning_icon_; 232 SkColor GetDimmedTextColor() const;
253 233
254 // The download shelf that owns us. 234 // The download shelf that owns us.
255 DownloadShelfView* shelf_; 235 DownloadShelfView* shelf_;
256 236
257 // Elements of our particular download 237 // Elements of our particular download
258 base::string16 status_text_; 238 base::string16 status_text_;
259 239
260 // The font list used to print the file name and status. 240 // The font list used to print the file name and warning text.
261 gfx::FontList font_list_; 241 gfx::FontList font_list_;
262 242
243 // The font list used to print the status text below the file name.
244 gfx::FontList status_font_list_;
245
263 // The tooltip. Only displayed when not showing a warning dialog. 246 // The tooltip. Only displayed when not showing a warning dialog.
264 base::string16 tooltip_text_; 247 base::string16 tooltip_text_;
265 248
266 // The current state (normal, hot or pushed) of the body and drop-down. 249 // The current state (normal, hot or pushed) of the body and drop-down.
267 State body_state_; 250 State dropdown_state_;
268 State drop_down_state_;
269 251
270 // Mode of the download item view. 252 // Mode of the download item view.
271 Mode mode_; 253 Mode mode_;
272 254
273 // When download progress last began animating (pausing and resuming will 255 // When download progress last began animating (pausing and resuming will
274 // update this). Used for downloads of unknown size. 256 // update this). Used for downloads of unknown size.
275 base::TimeTicks progress_start_time_; 257 base::TimeTicks progress_start_time_;
276 258
277 // Keeps the amount of time spent already animating. Used to keep track of 259 // Keeps the amount of time spent already animating. Used to keep track of
278 // total active time for downloads of unknown size. 260 // total active time for downloads of unknown size.
279 base::TimeDelta previous_progress_elapsed_; 261 base::TimeDelta previous_progress_elapsed_;
280 262
281 // The left and right x coordinates of the drop-down button.
282 int drop_down_x_left_;
283 int drop_down_x_right_;
284
285 // Used when we are showing the menu to show the drop-down as pressed.
286 bool drop_down_pressed_;
287
288 // The height of the box formed by the background images and its labels.
289 int box_height_;
290
291 // The y coordinate of the box formed by the background images and its labels.
292 int box_y_;
293
294 // Whether we are dragging the download button. 263 // Whether we are dragging the download button.
295 bool dragging_; 264 bool dragging_;
296 265
297 // Whether we are tracking a possible drag. 266 // Whether we are tracking a possible drag.
298 bool starting_drag_; 267 bool starting_drag_;
299 268
300 // Position that a possible drag started at. 269 // Position that a possible drag started at.
301 gfx::Point drag_start_point_; 270 gfx::Point drag_start_point_;
302 271
303 // For canceling an in progress icon request. 272 // For canceling an in progress icon request.
304 base::CancelableTaskTracker cancelable_task_tracker_; 273 base::CancelableTaskTracker cancelable_task_tracker_;
305 274
306 // A model class to control the status text we display. 275 // A model class to control the status text we display.
307 DownloadItemModel model_; 276 DownloadItemModel model_;
308 277
309 // Hover animations for our body and drop buttons.
310 std::unique_ptr<gfx::SlideAnimation> body_hover_animation_;
311 std::unique_ptr<gfx::SlideAnimation> drop_hover_animation_;
312
313 // Animation for download complete. 278 // Animation for download complete.
314 std::unique_ptr<gfx::SlideAnimation> complete_animation_; 279 std::unique_ptr<gfx::SlideAnimation> complete_animation_;
315 280
316 // Progress animation 281 // Progress animation
317 base::RepeatingTimer progress_timer_; 282 base::RepeatingTimer progress_timer_;
318 283
319 // Dangerous mode buttons. 284 // Dangerous mode buttons.
320 views::LabelButton* save_button_; 285 views::LabelButton* save_button_;
321 views::LabelButton* discard_button_; 286 views::LabelButton* discard_button_;
322 287
288 // The drop down button.
289 DropDownButton* dropdown_button_;
290
323 // Dangerous mode label. 291 // Dangerous mode label.
324 views::Label* dangerous_download_label_; 292 views::Label* dangerous_download_label_;
325 293
326 // Whether the dangerous mode label has been sized yet. 294 // Whether the dangerous mode label has been sized yet.
327 bool dangerous_download_label_sized_; 295 bool dangerous_download_label_sized_;
328 296
329 // Whether we are currently disabled as part of opening the downloaded file. 297 // Whether we are currently disabled as part of opening the downloaded file.
330 bool disabled_while_opening_; 298 bool disabled_while_opening_;
331 299
332 // The time at which this view was created. 300 // The time at which this view was created.
(...skipping 17 matching lines...) Expand all
350 // and the user's decisions about it. 318 // and the user's decisions about it.
351 std::unique_ptr<extensions::ExperienceSamplingEvent> sampling_event_; 319 std::unique_ptr<extensions::ExperienceSamplingEvent> sampling_event_;
352 320
353 // Method factory used to delay reenabling of the item when opening the 321 // Method factory used to delay reenabling of the item when opening the
354 // downloaded file. 322 // downloaded file.
355 base::WeakPtrFactory<DownloadItemView> weak_ptr_factory_; 323 base::WeakPtrFactory<DownloadItemView> weak_ptr_factory_;
356 324
357 DISALLOW_COPY_AND_ASSIGN(DownloadItemView); 325 DISALLOW_COPY_AND_ASSIGN(DownloadItemView);
358 }; 326 };
359 327
360 #endif // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H__ 328 #endif // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/BUILD.gn ('k') | chrome/browser/ui/views/download/download_item_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698