OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef CHROME_BROWSER_VIEWS_DONWLOAD_TAB_VIEW_H__ | 5 #ifndef CHROME_BROWSER_VIEWS_DONWLOAD_TAB_VIEW_H__ |
6 #define CHROME_BROWSER_VIEWS_DONWLOAD_TAB_VIEW_H__ | 6 #define CHROME_BROWSER_VIEWS_DONWLOAD_TAB_VIEW_H__ |
7 | 7 |
8 #include "base/hash_tables.h" | 8 #include "base/hash_tables.h" |
9 #include "chrome/browser/cancelable_request.h" | 9 #include "chrome/browser/cancelable_request.h" |
10 #include "chrome/browser/download/download_manager.h" | 10 #include "chrome/browser/download/download_manager.h" |
11 #include "chrome/browser/download/download_util.h" | 11 #include "chrome/browser/download/download_util.h" |
12 #include "chrome/browser/icon_manager.h" | 12 #include "chrome/browser/icon_manager.h" |
13 #include "chrome/browser/native_ui_contents.h" | 13 #include "chrome/browser/native_ui_contents.h" |
14 #include "chrome/views/event.h" | 14 #include "chrome/views/event.h" |
15 #include "chrome/views/label.h" | 15 #include "chrome/views/label.h" |
16 #include "chrome/views/link.h" | 16 #include "chrome/views/link.h" |
17 #include "chrome/views/scroll_view.h" | 17 #include "chrome/views/scroll_view.h" |
18 | 18 |
19 class DownloadTabView; | 19 class DownloadTabView; |
20 class SkBitmap; | 20 class SkBitmap; |
21 class Task; | 21 class Task; |
22 | 22 |
23 namespace base { | 23 namespace base { |
24 class Timer; | 24 class Timer; |
25 } | 25 } |
26 | 26 |
27 class DownloadItemTabView : public ChromeViews::View, | 27 class DownloadItemTabView : public ChromeViews::View, |
28 public ChromeViews::LinkController { | 28 public ChromeViews::LinkController, |
| 29 public ChromeViews::NativeButton::Listener { |
29 public: | 30 public: |
30 DownloadItemTabView(); | 31 DownloadItemTabView(); |
31 virtual ~DownloadItemTabView(); | 32 virtual ~DownloadItemTabView(); |
32 | 33 |
33 // View overrides | 34 // View overrides |
34 virtual void Layout(); | 35 virtual void Layout(); |
35 virtual void Paint(ChromeCanvas* canvas); | 36 virtual void Paint(ChromeCanvas* canvas); |
36 void PaintBackground(ChromeCanvas* canvas); | 37 void PaintBackground(ChromeCanvas* canvas); |
37 virtual void GetPreferredSize(CSize* out); | 38 virtual void GetPreferredSize(CSize* out); |
38 virtual void DidChangeBounds(const CRect& previous, const CRect& current); | 39 virtual void DidChangeBounds(const CRect& previous, const CRect& current); |
39 virtual bool OnMousePressed(const ChromeViews::MouseEvent& event); | 40 virtual bool OnMousePressed(const ChromeViews::MouseEvent& event); |
40 virtual bool OnMouseDragged(const ChromeViews::MouseEvent& event); | 41 virtual bool OnMouseDragged(const ChromeViews::MouseEvent& event); |
41 | 42 |
42 // Mode specific layouts | 43 // Mode specific layouts |
43 void LayoutDate(); | 44 void LayoutDate(); |
44 void LayoutComplete(); | 45 void LayoutComplete(); |
45 void LayoutCancelled(); | 46 void LayoutCancelled(); |
46 void LayoutInProgress(); | 47 void LayoutInProgress(); |
| 48 void LayoutPromptDangerousDownload(); |
47 | 49 |
48 // LinkController overrides | 50 // LinkController overrides |
49 virtual void LinkActivated(ChromeViews::Link* source, int event_flags); | 51 virtual void LinkActivated(ChromeViews::Link* source, int event_flags); |
50 | 52 |
| 53 // NativeButton Listener overrides. |
| 54 virtual void ButtonPressed(ChromeViews::NativeButton* sender); |
| 55 |
51 // Used to set our model temporarily during layout and paint operations | 56 // Used to set our model temporarily during layout and paint operations |
52 void SetModel(DownloadItem* model, DownloadTabView* parent); | 57 void SetModel(DownloadItem* model, DownloadTabView* parent); |
53 | 58 |
54 private: | 59 private: |
55 // Our model. | 60 // Our model. |
56 DownloadItem* model_; | 61 DownloadItem* model_; |
57 | 62 |
58 // Containing view. | 63 // Containing view. |
59 DownloadTabView* parent_; | 64 DownloadTabView* parent_; |
60 | 65 |
| 66 // Whether we are the renderer for floating views. |
| 67 bool is_floating_view_renderer_; |
| 68 |
61 // Time display. | 69 // Time display. |
62 ChromeViews::Label* since_; | 70 ChromeViews::Label* since_; |
63 ChromeViews::Label* date_; | 71 ChromeViews::Label* date_; |
64 | 72 |
65 // The name of the file. Clicking this link will open the download. | 73 // The name of the file. Clicking this link will open the download. |
66 ChromeViews::Link* file_name_; | 74 ChromeViews::Link* file_name_; |
67 | 75 |
68 // The name of the downloaded URL. | 76 // The name of the downloaded URL. |
69 ChromeViews::Label* download_url_; | 77 ChromeViews::Label* download_url_; |
70 | 78 |
71 // The current status of the download. | 79 // The current status of the download. |
72 ChromeViews::Label* time_remaining_; | 80 ChromeViews::Label* time_remaining_; |
73 ChromeViews::Label* download_progress_; | 81 ChromeViews::Label* download_progress_; |
74 | 82 |
| 83 // The message warning of a dangerous download. |
| 84 ChromeViews::Label* dangerous_download_warning_; |
| 85 |
75 // Actions that can be initiated. | 86 // Actions that can be initiated. |
76 ChromeViews::Link* pause_; | 87 ChromeViews::Link* pause_; |
77 ChromeViews::Link* cancel_; | 88 ChromeViews::Link* cancel_; |
78 ChromeViews::Link* show_; | 89 ChromeViews::Link* show_; |
79 | 90 |
| 91 // The buttons used to prompt the user when a dangerous download has been |
| 92 // initiated. |
| 93 ChromeViews::NativeButton* save_button_; |
| 94 ChromeViews::NativeButton* discard_button_; |
| 95 |
80 DISALLOW_EVIL_CONSTRUCTORS(DownloadItemTabView); | 96 DISALLOW_EVIL_CONSTRUCTORS(DownloadItemTabView); |
81 }; | 97 }; |
82 | 98 |
83 | 99 |
84 // A view that manages each of the individual download views | 100 // A view that manages each of the individual download views |
85 // (DownloadItemTabView) in the destination tab. | 101 // (DownloadItemTabView) in the destination tab. |
86 class DownloadTabView : public ChromeViews::View, | 102 class DownloadTabView : public ChromeViews::View, |
87 public DownloadItem::Observer, | 103 public DownloadItem::Observer, |
88 public DownloadManager::Observer { | 104 public DownloadManager::Observer { |
89 public: | 105 public: |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // Creates and attaches to the view the floating view at |index|. | 163 // Creates and attaches to the view the floating view at |index|. |
148 ChromeViews::View* CreateFloatingViewForIndex(int index); | 164 ChromeViews::View* CreateFloatingViewForIndex(int index); |
149 | 165 |
150 // Utility functions for operating on DownloadItemTabViews by index. | 166 // Utility functions for operating on DownloadItemTabViews by index. |
151 void SchedulePaintForViewAtIndex(int index); | 167 void SchedulePaintForViewAtIndex(int index); |
152 int GetYPositionForIndex(int index); | 168 int GetYPositionForIndex(int index); |
153 | 169 |
154 // Initiates an asynchronous icon extraction. | 170 // Initiates an asynchronous icon extraction. |
155 void LoadIcon(DownloadItem* download); | 171 void LoadIcon(DownloadItem* download); |
156 | 172 |
157 // Clears the list of "in progress" downloads and removes the this | 173 // Clears the list of "in progress" downloads and removes this DownloadTabView |
158 // DownloadTabView from their observer list. | 174 // from their observer list. |
159 void ClearDownloadInProgress(); | 175 void ClearDownloadInProgress(); |
160 | 176 |
| 177 // Clears the list of dangerous downloads and removes this DownloadTabView |
| 178 // from their observer list. |
| 179 void ClearDangerousDownloads(); |
| 180 |
161 // Our model | 181 // Our model |
162 DownloadManager* model_; | 182 DownloadManager* model_; |
163 | 183 |
164 // For drawing individual download items | 184 // For drawing individual download items |
165 DownloadItemTabView download_renderer_; | 185 DownloadItemTabView download_renderer_; |
166 | 186 |
167 // The current set of visible DownloadItems for this view received from the | 187 // The current set of visible DownloadItems for this view received from the |
168 // DownloadManager. DownloadManager owns the DownloadItems. The vector is | 188 // DownloadManager. DownloadManager owns the DownloadItems. The vector is |
169 // kept in order, sorted by ascending start time. | 189 // kept in order, sorted by ascending start time. |
170 typedef std::vector<DownloadItem*> OrderedDownloads; | 190 typedef std::vector<DownloadItem*> OrderedDownloads; |
171 OrderedDownloads downloads_; | 191 OrderedDownloads downloads_; |
172 | 192 |
173 // Progress animations | 193 // Progress animations |
174 base::RepeatingTimer<DownloadTabView> progress_timer_; | 194 base::RepeatingTimer<DownloadTabView> progress_timer_; |
175 | 195 |
176 // Since this view manages the progress animation timers for all the floating | 196 // Since this view manages the progress animation timers for all the floating |
177 // views, we need to track the current in progress downloads. This container | 197 // views, we need to track the current in progress downloads. This container |
178 // does not own the DownloadItems. | 198 // does not own the DownloadItems. |
179 base::hash_set<DownloadItem*> in_progress_; | 199 base::hash_set<DownloadItem*> in_progress_; |
180 | 200 |
| 201 // Keeps track of the downloads we are an observer for as a consequence of |
| 202 // being a dangerous download. |
| 203 base::hash_set<DownloadItem*> dangerous_downloads_; |
| 204 |
181 // Provide a start position for downloads with no known size. | 205 // Provide a start position for downloads with no known size. |
182 int start_angle_; | 206 int start_angle_; |
183 | 207 |
184 ChromeViews::FixedRowHeightScrollHelper scroll_helper_; | 208 ChromeViews::FixedRowHeightScrollHelper scroll_helper_; |
185 | 209 |
186 // Keep track of the currently selected view, so that we can inform it when | 210 // Keep track of the currently selected view, so that we can inform it when |
187 // the user changes the selection. | 211 // the user changes the selection. |
188 int selected_index_; | 212 int selected_index_; |
189 | 213 |
190 // Text in the download search box input by the user. | 214 // Text in the download search box input by the user. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 // The view we return from GetView. The contents of this is the | 267 // The view we return from GetView. The contents of this is the |
244 // bookmarks_view_ | 268 // bookmarks_view_ |
245 SearchableUIContainer searchable_container_; | 269 SearchableUIContainer searchable_container_; |
246 | 270 |
247 DownloadTabView* download_tab_view_; | 271 DownloadTabView* download_tab_view_; |
248 | 272 |
249 DISALLOW_EVIL_CONSTRUCTORS(DownloadTabUI); | 273 DISALLOW_EVIL_CONSTRUCTORS(DownloadTabUI); |
250 }; | 274 }; |
251 | 275 |
252 #endif // CHROME_BROWSER_VIEWS_DONWLOAD_TAB_VIEW_H__ | 276 #endif // CHROME_BROWSER_VIEWS_DONWLOAD_TAB_VIEW_H__ |
OLD | NEW |