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 // A ChromeView that implements one download on the Download shelf. | 5 // A ChromeView 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_VIEWS_DOWNLOAD_ITEM_VIEW_H__ | 16 #ifndef CHROME_BROWSER_VIEWS_DOWNLOAD_ITEM_VIEW_H__ |
17 #define CHROME_BROWSER_VIEWS_DOWNLOAD_ITEM_VIEW_H__ | 17 #define CHROME_BROWSER_VIEWS_DOWNLOAD_ITEM_VIEW_H__ |
18 | 18 |
19 #include <string> | 19 #include <string> |
20 | 20 |
21 #include "base/basictypes.h" | 21 #include "base/basictypes.h" |
22 #include "base/scoped_ptr.h" | 22 #include "base/scoped_ptr.h" |
23 #include "base/timer.h" | 23 #include "base/timer.h" |
24 #include "chrome/common/slide_animation.h" | 24 #include "chrome/common/slide_animation.h" |
25 #include "chrome/browser/cancelable_request.h" | 25 #include "chrome/browser/cancelable_request.h" |
26 #include "chrome/browser/download/download_manager.h" | 26 #include "chrome/browser/download/download_manager.h" |
27 #include "chrome/browser/icon_manager.h" | 27 #include "chrome/browser/icon_manager.h" |
28 #include "chrome/views/event.h" | 28 #include "chrome/views/event.h" |
| 29 #include "chrome/views/native_button.h" |
29 #include "chrome/views/view.h" | 30 #include "chrome/views/view.h" |
30 #include "chrome/views/label.h" | |
31 | 31 |
| 32 namespace ChromeViews { |
| 33 class Label; |
| 34 } |
32 class DownloadShelfView; | 35 class DownloadShelfView; |
33 class SkBitmap; | 36 class SkBitmap; |
34 | 37 |
35 class DownloadItemView : public ChromeViews::View, | 38 class DownloadItemView : public ChromeViews::NativeButton::Listener, |
| 39 public ChromeViews::View, |
36 public DownloadItem::Observer, | 40 public DownloadItem::Observer, |
37 public AnimationDelegate { | 41 public AnimationDelegate { |
38 public: | 42 public: |
39 // This class provides functions which have different behaviors between | 43 // This class provides functions which have different behaviors between |
40 // download and saving page. | 44 // download and saving page. |
41 class BaseDownloadItemModel { | 45 class BaseDownloadItemModel { |
42 public: | 46 public: |
43 // Cancel the task corresponding to the item. | 47 // Cancel the task corresponding to the item. |
44 virtual void CancelTask() = 0; | 48 virtual void CancelTask() = 0; |
45 | 49 |
46 // Get the status text to display. | 50 // Get the status text to display. |
47 virtual std::wstring GetStatusText() = 0; | 51 virtual std::wstring GetStatusText() = 0; |
48 }; | 52 }; |
49 | 53 |
50 DownloadItemView(DownloadItem* download, | 54 DownloadItemView(DownloadItem* download, |
51 DownloadShelfView* parent, | 55 DownloadShelfView* parent, |
52 BaseDownloadItemModel* model); | 56 BaseDownloadItemModel* model); |
53 virtual ~DownloadItemView(); | 57 virtual ~DownloadItemView(); |
54 | 58 |
55 // DownloadObserver method | 59 // DownloadObserver method |
56 virtual void OnDownloadUpdated(DownloadItem* download); | 60 virtual void OnDownloadUpdated(DownloadItem* download); |
57 | 61 |
58 // View overrides | 62 // View overrides |
| 63 virtual void Layout(); |
59 virtual void Paint(ChromeCanvas* canvas); | 64 virtual void Paint(ChromeCanvas* canvas); |
60 virtual void GetPreferredSize(CSize *out); | 65 virtual void GetPreferredSize(CSize *out); |
61 virtual void OnMouseExited(const ChromeViews::MouseEvent& event); | 66 virtual void OnMouseExited(const ChromeViews::MouseEvent& event); |
62 virtual void OnMouseMoved(const ChromeViews::MouseEvent& event); | 67 virtual void OnMouseMoved(const ChromeViews::MouseEvent& event); |
63 virtual bool OnMousePressed(const ChromeViews::MouseEvent& event); | 68 virtual bool OnMousePressed(const ChromeViews::MouseEvent& event); |
64 virtual void OnMouseReleased(const ChromeViews::MouseEvent& event, | 69 virtual void OnMouseReleased(const ChromeViews::MouseEvent& event, |
65 bool canceled); | 70 bool canceled); |
66 virtual bool OnMouseDragged(const ChromeViews::MouseEvent& event); | 71 virtual bool OnMouseDragged(const ChromeViews::MouseEvent& event); |
| 72 virtual void DidChangeBounds(const CRect& previous, const CRect& current); |
| 73 |
| 74 // NativeButton::Listener implementation. |
| 75 virtual void ButtonPressed(ChromeViews::NativeButton* sender); |
67 | 76 |
68 // AnimationDelegate implementation. | 77 // AnimationDelegate implementation. |
69 virtual void AnimationProgressed(const Animation* animation); | 78 virtual void AnimationProgressed(const Animation* animation); |
70 | 79 |
71 // Timer callback for handling animations | 80 // Timer callback for handling animations |
72 void UpdateDownloadProgress(); | 81 void UpdateDownloadProgress(); |
73 void StartDownloadProgress(); | 82 void StartDownloadProgress(); |
74 void StopDownloadProgress(); | 83 void StopDownloadProgress(); |
75 | 84 |
76 // IconManager::Client interface. | 85 // IconManager::Client interface. |
77 void OnExtractIconComplete(IconManager::Handle handle, SkBitmap* icon_bitmap); | 86 void OnExtractIconComplete(IconManager::Handle handle, SkBitmap* icon_bitmap); |
78 | 87 |
79 private: | 88 private: |
80 enum State { | 89 enum State { |
81 NORMAL = 0, | 90 NORMAL = 0, |
82 HOT, | 91 HOT, |
83 PUSHED, | 92 PUSHED, |
| 93 DANGEROUS |
84 }; | 94 }; |
85 | 95 |
86 // The image set associated with the part containing the icon and text. | 96 // The image set associated with the part containing the icon and text. |
87 struct BodyImageSet { | 97 struct BodyImageSet { |
88 SkBitmap* top_left; | 98 SkBitmap* top_left; |
89 SkBitmap* left; | 99 SkBitmap* left; |
90 SkBitmap* bottom_left; | 100 SkBitmap* bottom_left; |
91 SkBitmap* top; | 101 SkBitmap* top; |
92 SkBitmap* center; | 102 SkBitmap* center; |
93 SkBitmap* bottom; | 103 SkBitmap* bottom; |
(...skipping 20 matching lines...) Expand all Loading... |
114 const SkBitmap* center_bitmap, | 124 const SkBitmap* center_bitmap, |
115 const SkBitmap* bottom_bitmap, | 125 const SkBitmap* bottom_bitmap, |
116 int x, | 126 int x, |
117 int y, | 127 int y, |
118 int height, | 128 int height, |
119 int width); | 129 int width); |
120 | 130 |
121 // Sets the state and triggers a repaint. | 131 // Sets the state and triggers a repaint. |
122 void SetState(State body_state, State drop_down_state); | 132 void SetState(State body_state, State drop_down_state); |
123 | 133 |
| 134 // Whether we are in the dangerous mode. |
| 135 bool IsDangerousMode() { return body_state_ == DANGEROUS; } |
| 136 |
| 137 // Reverts from dangerous mode to normal download mode. |
| 138 void ClearDangerousMode(); |
| 139 |
| 140 // Sets |size| with the size of the Save and Discard buttons (they have the |
| 141 // same size). |
| 142 void GetButtonSize(CSize* size); |
| 143 |
| 144 // Sizes the dangerous download label to a minimum width available using 2 |
| 145 // lines. The size is computed only the first time this method is invoked |
| 146 // and simply returned on subsequent calls. |
| 147 void SizeLabelToMinWidth(); |
| 148 |
124 // The different images used for the background. | 149 // The different images used for the background. |
125 BodyImageSet normal_body_image_set_; | 150 BodyImageSet normal_body_image_set_; |
126 BodyImageSet hot_body_image_set_; | 151 BodyImageSet hot_body_image_set_; |
127 BodyImageSet pushed_body_image_set_; | 152 BodyImageSet pushed_body_image_set_; |
| 153 BodyImageSet dangerous_mode_body_image_set_; |
128 DropDownImageSet normal_drop_down_image_set_; | 154 DropDownImageSet normal_drop_down_image_set_; |
129 DropDownImageSet hot_drop_down_image_set_; | 155 DropDownImageSet hot_drop_down_image_set_; |
130 DropDownImageSet pushed_drop_down_image_set_; | 156 DropDownImageSet pushed_drop_down_image_set_; |
131 | 157 |
| 158 // The warning icon showns for dangerous downloads. |
| 159 SkBitmap* warning_icon_; |
| 160 |
132 // The model we query for display information | 161 // The model we query for display information |
133 DownloadItem* download_; | 162 DownloadItem* download_; |
134 | 163 |
135 // Our parent view that owns us. | 164 // Our parent view that owns us. |
136 DownloadShelfView* parent_; | 165 DownloadShelfView* parent_; |
137 | 166 |
138 // Elements of our particular download | 167 // Elements of our particular download |
139 std::wstring file_name_; | |
140 std::wstring status_text_; | 168 std::wstring status_text_; |
141 bool show_status_text_; | 169 bool show_status_text_; |
142 | 170 |
143 // The font used to print the file name and status. | 171 // The font used to print the file name and status. |
144 ChromeFont font_; | 172 ChromeFont font_; |
145 | 173 |
146 // The current state (normal, hot or pushed) of the body and drop-down. | 174 // The current state (normal, hot or pushed) of the body and drop-down. |
147 State body_state_; | 175 State body_state_; |
148 State drop_down_state_; | 176 State drop_down_state_; |
149 | 177 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 // Hover animations for our body and drop buttons. | 210 // Hover animations for our body and drop buttons. |
183 scoped_ptr<SlideAnimation> body_hover_animation_; | 211 scoped_ptr<SlideAnimation> body_hover_animation_; |
184 scoped_ptr<SlideAnimation> drop_hover_animation_; | 212 scoped_ptr<SlideAnimation> drop_hover_animation_; |
185 | 213 |
186 // Animation for download complete. | 214 // Animation for download complete. |
187 scoped_ptr<SlideAnimation> complete_animation_; | 215 scoped_ptr<SlideAnimation> complete_animation_; |
188 | 216 |
189 // Progress animation | 217 // Progress animation |
190 base::RepeatingTimer<DownloadItemView> progress_timer_; | 218 base::RepeatingTimer<DownloadItemView> progress_timer_; |
191 | 219 |
| 220 // Dangerous mode buttons. |
| 221 ChromeViews::NativeButton* save_button_; |
| 222 ChromeViews::NativeButton* discard_button_; |
| 223 |
| 224 // Dangerous mode label. |
| 225 ChromeViews::Label* dangerous_download_label_; |
| 226 |
| 227 // Whether the dangerous mode label has been sized yet. |
| 228 bool dangerous_download_label_sized_; |
| 229 |
| 230 // The size of the buttons. Cached so animation works when hidden. |
| 231 CSize cached_button_size_; |
| 232 |
192 DISALLOW_EVIL_CONSTRUCTORS(DownloadItemView); | 233 DISALLOW_EVIL_CONSTRUCTORS(DownloadItemView); |
193 }; | 234 }; |
194 | 235 |
195 #endif // CHROME_BROWSER_VIEWS_DOWNLOAD_ITEM_VIEW_H__ | 236 #endif // CHROME_BROWSER_VIEWS_DOWNLOAD_ITEM_VIEW_H__ |
196 | 237 |
OLD | NEW |