OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; | 102 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; |
103 | 103 |
104 protected: | 104 protected: |
105 // Overridden from views::View: | 105 // Overridden from views::View: |
106 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 106 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
107 | 107 |
108 private: | 108 private: |
109 enum State { | 109 enum State { |
110 NORMAL = 0, | 110 NORMAL = 0, |
111 HOT, | 111 HOT, |
112 PUSHED, | 112 PUSHED |
113 DANGEROUS | 113 }; |
| 114 |
| 115 enum Mode { |
| 116 NORMAL_MODE = 0, // Showing download item. |
| 117 DANGEROUS_MODE, // Displaying the dangerous download warning. |
| 118 MALICIOUS_MODE // Displaying the malicious download warning. |
114 }; | 119 }; |
115 | 120 |
116 // The image set associated with the part containing the icon and text. | 121 // The image set associated with the part containing the icon and text. |
117 struct BodyImageSet { | 122 struct BodyImageSet { |
118 SkBitmap* top_left; | 123 SkBitmap* top_left; |
119 SkBitmap* left; | 124 SkBitmap* left; |
120 SkBitmap* bottom_left; | 125 SkBitmap* bottom_left; |
121 SkBitmap* top; | 126 SkBitmap* top; |
122 SkBitmap* center; | 127 SkBitmap* center; |
123 SkBitmap* bottom; | 128 SkBitmap* bottom; |
(...skipping 22 matching lines...) Expand all Loading... |
146 const SkBitmap* bottom_bitmap, | 151 const SkBitmap* bottom_bitmap, |
147 int x, | 152 int x, |
148 int y, | 153 int y, |
149 int height, | 154 int height, |
150 int width); | 155 int width); |
151 | 156 |
152 // Sets the state and triggers a repaint. | 157 // Sets the state and triggers a repaint. |
153 void SetState(State body_state, State drop_down_state); | 158 void SetState(State body_state, State drop_down_state); |
154 | 159 |
155 // Whether we are in the dangerous mode. | 160 // Whether we are in the dangerous mode. |
156 bool IsDangerousMode() { return body_state_ == DANGEROUS; } | 161 bool IsShowingWarningDialog() { |
| 162 return mode_ == DANGEROUS_MODE || mode_ == MALICIOUS_MODE; |
| 163 } |
157 | 164 |
158 // Reverts from dangerous mode to normal download mode. | 165 // Reverts from dangerous mode to normal download mode. |
159 void ClearDangerousMode(); | 166 void ClearWarningDialog(); |
160 | 167 |
161 // Start displaying the dangerous download warning. | 168 // Start displaying the dangerous download warning or the malicious download |
162 void EnterDangerousMode(); | 169 // warning. |
| 170 void ShowWarningDialog(); |
163 | 171 |
164 // Sets |size| with the size of the Save and Discard buttons (they have the | 172 // Sets |size| with the size of the Save and Discard buttons (they have the |
165 // same size). | 173 // same size). |
166 gfx::Size GetButtonSize(); | 174 gfx::Size GetButtonSize(); |
167 | 175 |
168 // Sizes the dangerous download label to a minimum width available using 2 | 176 // Sizes the dangerous download label to a minimum width available using 2 |
169 // lines. The size is computed only the first time this method is invoked | 177 // lines. The size is computed only the first time this method is invoked |
170 // and simply returned on subsequent calls. | 178 // and simply returned on subsequent calls. |
171 void SizeLabelToMinWidth(); | 179 void SizeLabelToMinWidth(); |
172 | 180 |
173 // Reenables the item after it has been disabled when a user clicked it to | 181 // Reenables the item after it has been disabled when a user clicked it to |
174 // open the downloaded file. | 182 // open the downloaded file. |
175 void Reenable(); | 183 void Reenable(); |
176 | 184 |
| 185 // Releases drop down button after showing a context menu. |
| 186 void ReleaseDropDown(); |
| 187 |
177 // Given |x|, returns whether |x| is within the x coordinate range of | 188 // Given |x|, returns whether |x| is within the x coordinate range of |
178 // the drop-down button or not. | 189 // the drop-down button or not. |
179 bool InDropDownButtonXCoordinateRange(int x); | 190 bool InDropDownButtonXCoordinateRange(int x); |
180 | 191 |
181 // Update the accessible name to reflect the current state of the control, | 192 // Update the accessible name to reflect the current state of the control, |
182 // so that screenreaders can access the filename, status text, and | 193 // so that screenreaders can access the filename, status text, and |
183 // dangerous download warning message (if any). | 194 // dangerous download warning message (if any). |
184 void UpdateAccessibleName(); | 195 void UpdateAccessibleName(); |
185 | 196 |
| 197 // Update the location of the drop down button. |
| 198 void UpdateDropDownButtonPosition(); |
| 199 |
186 // The different images used for the background. | 200 // The different images used for the background. |
187 BodyImageSet normal_body_image_set_; | 201 BodyImageSet normal_body_image_set_; |
188 BodyImageSet hot_body_image_set_; | 202 BodyImageSet hot_body_image_set_; |
189 BodyImageSet pushed_body_image_set_; | 203 BodyImageSet pushed_body_image_set_; |
190 BodyImageSet dangerous_mode_body_image_set_; | 204 BodyImageSet dangerous_mode_body_image_set_; |
| 205 BodyImageSet malicious_mode_body_image_set_; |
191 DropDownImageSet normal_drop_down_image_set_; | 206 DropDownImageSet normal_drop_down_image_set_; |
192 DropDownImageSet hot_drop_down_image_set_; | 207 DropDownImageSet hot_drop_down_image_set_; |
193 DropDownImageSet pushed_drop_down_image_set_; | 208 DropDownImageSet pushed_drop_down_image_set_; |
194 | 209 |
195 // The warning icon showns for dangerous downloads. | 210 // The warning icon showns for dangerous downloads. |
196 const SkBitmap* warning_icon_; | 211 const SkBitmap* warning_icon_; |
197 | 212 |
198 // The model we query for display information | 213 // The model we query for display information |
199 DownloadItem* download_; | 214 DownloadItem* download_; |
200 | 215 |
201 // Our parent view that owns us. | 216 // Our parent view that owns us. |
202 DownloadShelfView* parent_; | 217 DownloadShelfView* parent_; |
203 | 218 |
204 // Elements of our particular download | 219 // Elements of our particular download |
205 string16 status_text_; | 220 string16 status_text_; |
206 | 221 |
207 // The font used to print the file name and status. | 222 // The font used to print the file name and status. |
208 gfx::Font font_; | 223 gfx::Font font_; |
209 | 224 |
210 // The tooltip. | 225 // The tooltip. |
211 string16 tooltip_text_; | 226 string16 tooltip_text_; |
212 | 227 |
213 // The current state (normal, hot or pushed) of the body and drop-down. | 228 // The current state (normal, hot or pushed) of the body and drop-down. |
214 State body_state_; | 229 State body_state_; |
215 State drop_down_state_; | 230 State drop_down_state_; |
216 | 231 |
| 232 // Mode of the download item view. |
| 233 Mode mode_; |
| 234 |
217 // In degrees, for downloads with no known total size. | 235 // In degrees, for downloads with no known total size. |
218 int progress_angle_; | 236 int progress_angle_; |
219 | 237 |
220 // The left and right x coordinates of the drop-down button. | 238 // The left and right x coordinates of the drop-down button. |
221 int drop_down_x_left_; | 239 int drop_down_x_left_; |
222 int drop_down_x_right_; | 240 int drop_down_x_right_; |
223 | 241 |
224 // Used when we are showing the menu to show the drop-down as pressed. | 242 // Used when we are showing the menu to show the drop-down as pressed. |
225 bool drop_down_pressed_; | 243 bool drop_down_pressed_; |
226 | 244 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 gfx::Size cached_button_size_; | 289 gfx::Size cached_button_size_; |
272 | 290 |
273 // Whether we are currently disabled as part of opening the downloaded file. | 291 // Whether we are currently disabled as part of opening the downloaded file. |
274 bool disabled_while_opening_; | 292 bool disabled_while_opening_; |
275 | 293 |
276 // The time at which this view was created. | 294 // The time at which this view was created. |
277 base::Time creation_time_; | 295 base::Time creation_time_; |
278 | 296 |
279 // Method factory used to delay reenabling of the item when opening the | 297 // Method factory used to delay reenabling of the item when opening the |
280 // downloaded file. | 298 // downloaded file. |
281 base::WeakPtrFactory<DownloadItemView> reenable_method_factory_; | 299 base::WeakPtrFactory<DownloadItemView> weak_ptr_factory_; |
282 | 300 |
283 // The currently running download context menu. | 301 // The currently running download context menu. |
284 scoped_ptr<DownloadShelfContextMenuView> context_menu_; | 302 scoped_ptr<DownloadShelfContextMenuView> context_menu_; |
285 | 303 |
286 // The name of this view as reported to assistive technology. | 304 // The name of this view as reported to assistive technology. |
287 string16 accessible_name_; | 305 string16 accessible_name_; |
288 | 306 |
289 // The icon loaded in the download shelf is based on the file path of the | 307 // The icon loaded in the download shelf is based on the file path of the |
290 // item. Store the path used, so that we can detect a change in the path | 308 // item. Store the path used, so that we can detect a change in the path |
291 // and reload the icon. | 309 // and reload the icon. |
292 FilePath last_download_item_path_; | 310 FilePath last_download_item_path_; |
293 | 311 |
294 DISALLOW_COPY_AND_ASSIGN(DownloadItemView); | 312 DISALLOW_COPY_AND_ASSIGN(DownloadItemView); |
295 }; | 313 }; |
296 | 314 |
297 #endif // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H__ | 315 #endif // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H__ |
OLD | NEW |