Chromium Code Reviews| 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/gtk/download/download_item_gtk.h" | 5 #include "chrome/browser/ui/gtk/download/download_item_gtk.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 // wrapping. | 51 // wrapping. |
| 52 const int kDangerousTextWidth = 200; | 52 const int kDangerousTextWidth = 200; |
| 53 | 53 |
| 54 // Amount of space we allot to showing the filename. If the filename is too wide | 54 // Amount of space we allot to showing the filename. If the filename is too wide |
| 55 // it will be elided. | 55 // it will be elided. |
| 56 const int kTextWidth = 140; | 56 const int kTextWidth = 140; |
| 57 | 57 |
| 58 // We only cap the size of the tooltip so we don't crash. | 58 // We only cap the size of the tooltip so we don't crash. |
| 59 const int kTooltipMaxWidth = 1000; | 59 const int kTooltipMaxWidth = 1000; |
| 60 | 60 |
| 61 // Used for wrapping the download error description, if necessary. | |
| 62 const int kToolTipErrorMessageMaxHeight = kTooltipMaxWidth / 4; | |
| 63 | |
| 61 // The minimum width we will ever draw the download item. Used as a lower bound | 64 // The minimum width we will ever draw the download item. Used as a lower bound |
| 62 // during animation. This number comes from the width of the images used to | 65 // during animation. This number comes from the width of the images used to |
| 63 // make the download item. | 66 // make the download item. |
| 64 const int kMinDownloadItemWidth = download_util::kSmallProgressIconSize; | 67 const int kMinDownloadItemWidth = download_util::kSmallProgressIconSize; |
| 65 | 68 |
| 66 // New download item animation speed in milliseconds. | 69 // New download item animation speed in milliseconds. |
| 67 const int kNewItemAnimationDurationMs = 800; | 70 const int kNewItemAnimationDurationMs = 800; |
| 68 | 71 |
| 69 // How long the 'download complete/interrupted' animation should last for. | 72 // How long the 'download complete/interrupted' animation should last for. |
| 70 const int kCompleteAnimationDurationMs = 2500; | 73 const int kCompleteAnimationDurationMs = 2500; |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 switch (download->GetState()) { | 331 switch (download->GetState()) { |
| 329 case DownloadItem::REMOVING: | 332 case DownloadItem::REMOVING: |
| 330 parent_shelf_->RemoveDownloadItem(this); // This will delete us! | 333 parent_shelf_->RemoveDownloadItem(this); // This will delete us! |
| 331 return; | 334 return; |
| 332 case DownloadItem::CANCELLED: | 335 case DownloadItem::CANCELLED: |
| 333 StopDownloadProgress(); | 336 StopDownloadProgress(); |
| 334 gtk_widget_queue_draw(progress_area_.get()); | 337 gtk_widget_queue_draw(progress_area_.get()); |
| 335 break; | 338 break; |
| 336 case DownloadItem::INTERRUPTED: | 339 case DownloadItem::INTERRUPTED: |
| 337 StopDownloadProgress(); | 340 StopDownloadProgress(); |
| 341 UpdateTooltip(); | |
| 338 | 342 |
| 339 complete_animation_.Show(); | 343 complete_animation_.Show(); |
| 340 break; | 344 break; |
| 341 case DownloadItem::COMPLETE: | 345 case DownloadItem::COMPLETE: |
| 342 // GetAutoOpened() may change after the download's initial transition to | 346 // GetAutoOpened() may change after the download's initial transition to |
| 343 // COMPLETE, so we check it before the idemopotency shield below. | 347 // COMPLETE, so we check it before the idemopotency shield below. |
| 344 if (download->GetAutoOpened()) { | 348 if (download->GetAutoOpened()) { |
| 345 parent_shelf_->RemoveDownloadItem(this); // This will delete us! | 349 parent_shelf_->RemoveDownloadItem(this); // This will delete us! |
| 346 return; | 350 return; |
| 347 } | 351 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 IconLoader::SMALL, &icon_consumer_, | 473 IconLoader::SMALL, &icon_consumer_, |
| 470 base::Bind(&DownloadItemGtk::OnLoadSmallIconComplete, | 474 base::Bind(&DownloadItemGtk::OnLoadSmallIconComplete, |
| 471 base::Unretained(this))); | 475 base::Unretained(this))); |
| 472 im->LoadIcon(icon_filepath_, | 476 im->LoadIcon(icon_filepath_, |
| 473 IconLoader::LARGE, &icon_consumer_, | 477 IconLoader::LARGE, &icon_consumer_, |
| 474 base::Bind(&DownloadItemGtk::OnLoadLargeIconComplete, | 478 base::Bind(&DownloadItemGtk::OnLoadLargeIconComplete, |
| 475 base::Unretained(this))); | 479 base::Unretained(this))); |
| 476 } | 480 } |
| 477 | 481 |
| 478 void DownloadItemGtk::UpdateTooltip() { | 482 void DownloadItemGtk::UpdateTooltip() { |
| 479 string16 elided_filename = ui::ElideFilename( | 483 string16 tooltip_text = ui::ElideFilename( |
| 480 get_download()->GetFileNameToReportUser(), | 484 get_download()->GetFileNameToReportUser(), gfx::Font(), kTooltipMaxWidth); |
|
asanka
2012/04/04 17:27:04
Can we move the tooltip generation logic into the
ahendrickson
2012/04/04 17:49:32
The logic is different on Windows vs Posix.
| |
| 481 gfx::Font(), kTooltipMaxWidth); | 485 |
| 482 gtk_widget_set_tooltip_text(body_.get(), | 486 if (get_download()->GetState() == content::DownloadItem::INTERRUPTED) { |
| 483 UTF16ToUTF8(elided_filename).c_str()); | 487 content::DownloadInterruptReason reason = get_download()->GetLastReason(); |
| 488 DCHECK(reason != 0); | |
| 489 | |
| 490 // Split up the error description string as necessary. | |
| 491 std::vector<string16> elidedMessages; | |
| 492 ui::ElideRectangleText( | |
| 493 DownloadItemModel::InterruptReasonMessage(reason), | |
| 494 gfx::Font(), | |
| 495 kTooltipMaxWidth, | |
| 496 kToolTipErrorMessageMaxHeight, | |
| 497 ui::IGNORE_LONG_WORDS, | |
| 498 &elidedMessages); | |
|
Nico
2012/04/04 17:50:06
Hm, maybe that should be on the downloads page ins
asanka
2012/04/05 19:08:34
This has changed in the latest patch set. Part of
| |
| 499 | |
| 500 string16 new_line = ASCIIToUTF16("\n"); | |
| 501 tooltip_text += new_line; | |
| 502 | |
| 503 for (size_t i = 0; i < elidedMessages.size(); ++i) { | |
| 504 tooltip_text += elidedMessages[i]; | |
| 505 tooltip_text += new_line; | |
| 506 } | |
| 507 | |
| 508 tooltip_text += download_model_->GetProgressText(); | |
| 509 } | |
| 510 | |
| 511 gtk_widget_set_tooltip_text(body_.get(), UTF16ToUTF8(tooltip_text).c_str()); | |
| 484 } | 512 } |
| 485 | 513 |
| 486 void DownloadItemGtk::UpdateNameLabel() { | 514 void DownloadItemGtk::UpdateNameLabel() { |
| 487 // TODO(estade): This is at best an educated guess, since we don't actually | 515 // TODO(estade): This is at best an educated guess, since we don't actually |
| 488 // use gfx::Font() to draw the text. This is why we need to add so | 516 // use gfx::Font() to draw the text. This is why we need to add so |
| 489 // much padding when we set the size request. We need to either use gfx::Font | 517 // much padding when we set the size request. We need to either use gfx::Font |
| 490 // or somehow extend TextElider. | 518 // or somehow extend TextElider. |
| 491 gfx::Font font = gfx::Font(); | 519 gfx::Font font = gfx::Font(); |
| 492 string16 filename; | 520 string16 filename; |
| 493 if (!disabled_while_opening_) { | 521 if (!disabled_while_opening_) { |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 918 get_download()->DangerousDownloadValidated(); | 946 get_download()->DangerousDownloadValidated(); |
| 919 } | 947 } |
| 920 | 948 |
| 921 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { | 949 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { |
| 922 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", | 950 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", |
| 923 base::Time::Now() - creation_time_); | 951 base::Time::Now() - creation_time_); |
| 924 if (get_download()->IsPartialDownload()) | 952 if (get_download()->IsPartialDownload()) |
| 925 get_download()->Cancel(true); | 953 get_download()->Cancel(true); |
| 926 get_download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 954 get_download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
| 927 } | 955 } |
| OLD | NEW |