OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/ui/views/download/download_item_view.h" | 5 #include "chrome/browser/ui/views/download/download_item_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 // TODO(paulg): These may need to be adjusted when download progress | 43 // TODO(paulg): These may need to be adjusted when download progress |
44 // animation is added, and also possibly to take into account | 44 // animation is added, and also possibly to take into account |
45 // different screen resolutions. | 45 // different screen resolutions. |
46 static const int kTextWidth = 140; // Pixels | 46 static const int kTextWidth = 140; // Pixels |
47 static const int kDangerousTextWidth = 200; // Pixels | 47 static const int kDangerousTextWidth = 200; // Pixels |
48 static const int kHorizontalTextPadding = 2; // Pixels | 48 static const int kHorizontalTextPadding = 2; // Pixels |
49 static const int kVerticalPadding = 3; // Pixels | 49 static const int kVerticalPadding = 3; // Pixels |
50 static const int kVerticalTextSpacer = 2; // Pixels | 50 static const int kVerticalTextSpacer = 2; // Pixels |
51 static const int kVerticalTextPadding = 2; // Pixels | 51 static const int kVerticalTextPadding = 2; // Pixels |
| 52 static const int kTooltipMaxWidth = 800; // Pixels |
52 | 53 |
53 // We add some padding before the left image so that the progress animation icon | 54 // We add some padding before the left image so that the progress animation icon |
54 // hides the corners of the left image. | 55 // hides the corners of the left image. |
55 static const int kLeftPadding = 0; // Pixels. | 56 static const int kLeftPadding = 0; // Pixels. |
56 | 57 |
57 // The space between the Save and Discard buttons when prompting for a dangerous | 58 // The space between the Save and Discard buttons when prompting for a dangerous |
58 // download. | 59 // download. |
59 static const int kButtonPadding = 5; // Pixels. | 60 static const int kButtonPadding = 5; // Pixels. |
60 | 61 |
61 // The space on the left and right side of the dangerous download label. | 62 // The space on the left and right side of the dangerous download label. |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_RIGHT_TOP_NO_DD), | 178 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_RIGHT_TOP_NO_DD), |
178 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE_NO_DD), | 179 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE_NO_DD), |
179 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM_NO_DD) | 180 rb.GetBitmapNamed(IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM_NO_DD) |
180 }; | 181 }; |
181 dangerous_mode_body_image_set_ = dangerous_mode_body_image_set; | 182 dangerous_mode_body_image_set_ = dangerous_mode_body_image_set; |
182 | 183 |
183 malicious_mode_body_image_set_ = normal_body_image_set; | 184 malicious_mode_body_image_set_ = normal_body_image_set; |
184 | 185 |
185 LoadIcon(); | 186 LoadIcon(); |
186 | 187 |
187 // Initial tooltip value. | |
188 tooltip_text_ = download_->GetFileNameToReportUser().LossyDisplayName(); | |
189 | |
190 font_ = rb.GetFont(ui::ResourceBundle::BaseFont); | 188 font_ = rb.GetFont(ui::ResourceBundle::BaseFont); |
191 box_height_ = std::max<int>(2 * kVerticalPadding + font_.GetHeight() + | 189 box_height_ = std::max<int>(2 * kVerticalPadding + font_.GetHeight() + |
192 kVerticalTextPadding + font_.GetHeight(), | 190 kVerticalTextPadding + font_.GetHeight(), |
193 2 * kVerticalPadding + | 191 2 * kVerticalPadding + |
194 normal_body_image_set_.top_left->height() + | 192 normal_body_image_set_.top_left->height() + |
195 normal_body_image_set_.bottom_left->height()); | 193 normal_body_image_set_.bottom_left->height()); |
196 | 194 |
197 if (download_util::kSmallProgressIconSize > box_height_) | 195 if (download_util::kSmallProgressIconSize > box_height_) |
198 box_y_ = (download_util::kSmallProgressIconSize - box_height_) / 2; | 196 box_y_ = (download_util::kSmallProgressIconSize - box_height_) / 2; |
199 else | 197 else |
200 box_y_ = kVerticalPadding; | 198 box_y_ = kVerticalPadding; |
201 | 199 |
202 body_hover_animation_.reset(new ui::SlideAnimation(this)); | 200 body_hover_animation_.reset(new ui::SlideAnimation(this)); |
203 drop_hover_animation_.reset(new ui::SlideAnimation(this)); | 201 drop_hover_animation_.reset(new ui::SlideAnimation(this)); |
204 | 202 |
205 UpdateDropDownButtonPosition(); | 203 UpdateDropDownButtonPosition(); |
206 | 204 |
| 205 tooltip_text_ = model_->GetTooltipText(font_, kTooltipMaxWidth); |
| 206 |
207 if (model_->IsDangerous()) | 207 if (model_->IsDangerous()) |
208 ShowWarningDialog(); | 208 ShowWarningDialog(); |
209 | 209 |
210 UpdateAccessibleName(); | 210 UpdateAccessibleName(); |
211 set_accessibility_focusable(true); | 211 set_accessibility_focusable(true); |
212 | 212 |
213 // Set up our animation. | 213 // Set up our animation. |
214 StartDownloadProgress(); | 214 StartDownloadProgress(); |
215 } | 215 } |
216 | 216 |
(...skipping 30 matching lines...) Expand all Loading... |
247 parent()->SchedulePaint(); | 247 parent()->SchedulePaint(); |
248 } | 248 } |
249 | 249 |
250 // DownloadObserver interface. | 250 // DownloadObserver interface. |
251 | 251 |
252 // Update the progress graphic on the icon and our text status label | 252 // Update the progress graphic on the icon and our text status label |
253 // to reflect our current bytes downloaded, time remaining. | 253 // to reflect our current bytes downloaded, time remaining. |
254 void DownloadItemView::OnDownloadUpdated(DownloadItem* download) { | 254 void DownloadItemView::OnDownloadUpdated(DownloadItem* download) { |
255 DCHECK(download == download_); | 255 DCHECK(download == download_); |
256 | 256 |
257 string16 old_tip = tooltip_text_; | |
258 content::DownloadInterruptReason reason = download_->GetLastReason(); | |
259 | |
260 if ((download_->GetState() == DownloadItem::INTERRUPTED) && | |
261 (reason != content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED)) { | |
262 // Use two lines: The file name, and the message. | |
263 tooltip_text_ = download_->GetFileNameToReportUser().LossyDisplayName(); | |
264 tooltip_text_ += ASCIIToUTF16("\n"); | |
265 // The message is localized. | |
266 tooltip_text_ += DownloadItemModel::InterruptReasonMessage(reason); | |
267 } else { | |
268 tooltip_text_ = download_->GetFileNameToReportUser().LossyDisplayName(); | |
269 } | |
270 | |
271 if (IsShowingWarningDialog() && !model_->IsDangerous()) { | 257 if (IsShowingWarningDialog() && !model_->IsDangerous()) { |
272 // We have been approved. | 258 // We have been approved. |
273 ClearWarningDialog(); | 259 ClearWarningDialog(); |
274 } else if (!IsShowingWarningDialog() && model_->IsDangerous()) { | 260 } else if (!IsShowingWarningDialog() && model_->IsDangerous()) { |
275 ShowWarningDialog(); | 261 ShowWarningDialog(); |
276 // Force the shelf to layout again as our size has changed. | 262 // Force the shelf to layout again as our size has changed. |
277 parent_->Layout(); | 263 parent_->Layout(); |
278 SchedulePaint(); | 264 SchedulePaint(); |
279 } else { | 265 } else { |
280 string16 status_text = model_->GetStatusText(); | 266 string16 status_text = model_->GetStatusText(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 break; | 298 break; |
313 case DownloadItem::REMOVING: | 299 case DownloadItem::REMOVING: |
314 parent_->RemoveDownloadView(this); // This will delete us! | 300 parent_->RemoveDownloadView(this); // This will delete us! |
315 return; | 301 return; |
316 default: | 302 default: |
317 NOTREACHED(); | 303 NOTREACHED(); |
318 } | 304 } |
319 status_text_ = status_text; | 305 status_text_ = status_text; |
320 } | 306 } |
321 | 307 |
322 if (old_tip != tooltip_text_) | 308 string16 new_tip = model_->GetTooltipText(font_, kTooltipMaxWidth); |
| 309 if (new_tip != tooltip_text_) { |
| 310 tooltip_text_ = new_tip; |
323 TooltipTextChanged(); | 311 TooltipTextChanged(); |
| 312 } |
324 | 313 |
325 UpdateAccessibleName(); | 314 UpdateAccessibleName(); |
326 | 315 |
327 // We use the parent's (DownloadShelfView's) SchedulePaint, since there | 316 // We use the parent's (DownloadShelfView's) SchedulePaint, since there |
328 // are spaces between each DownloadItemView that the parent is responsible | 317 // are spaces between each DownloadItemView that the parent is responsible |
329 // for painting. | 318 // for painting. |
330 parent()->SchedulePaint(); | 319 parent()->SchedulePaint(); |
331 } | 320 } |
332 | 321 |
333 void DownloadItemView::OnDownloadOpened(DownloadItem* download) { | 322 void DownloadItemView::OnDownloadOpened(DownloadItem* download) { |
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1188 // Drop down button is glued to the left of the download shelf. | 1177 // Drop down button is glued to the left of the download shelf. |
1189 drop_down_x_left_ = 0; | 1178 drop_down_x_left_ = 0; |
1190 drop_down_x_right_ = normal_drop_down_image_set_.top->width(); | 1179 drop_down_x_right_ = normal_drop_down_image_set_.top->width(); |
1191 } else { | 1180 } else { |
1192 // Drop down button is glued to the right of the download shelf. | 1181 // Drop down button is glued to the right of the download shelf. |
1193 drop_down_x_left_ = | 1182 drop_down_x_left_ = |
1194 size.width() - normal_drop_down_image_set_.top->width(); | 1183 size.width() - normal_drop_down_image_set_.top->width(); |
1195 drop_down_x_right_ = size.width(); | 1184 drop_down_x_right_ = size.width(); |
1196 } | 1185 } |
1197 } | 1186 } |
OLD | NEW |