summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/app/generated_resources.grd5
-rw-r--r--chrome/browser/dom_ui/downloads_ui.cc1
-rw-r--r--chrome/browser/download/download_manager.cc4
-rw-r--r--chrome/browser/download/download_manager.h8
-rw-r--r--chrome/browser/download/download_util.cc6
-rw-r--r--chrome/browser/gtk/download_item_gtk.h1
-rw-r--r--chrome/browser/views/download_item_view.cc61
-rw-r--r--chrome/browser/views/download_item_view.h12
8 files changed, 84 insertions, 14 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index b645645..9613e4551 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -1235,7 +1235,10 @@ each locale. -->
desc="Status that the file download will be opened when the download completes.">
Opening when complete
</message>
-
+ <message name="IDS_DOWNLOAD_STATUS_OPENING"
+ desc="Temporary status shown when a user has clicked to open a downloaded file.">
+ Opening <ph name="FILE">$1<ex>image.jpg</ex></ph>...
+ </message>
<message name="IDS_DOWNLOAD_STATUS_COMPLETE"
desc="Size and units downloaded.">
<ph name="DOWNLOAD_SIZE">$1<ex>54kB</ex></ph>, Complete
diff --git a/chrome/browser/dom_ui/downloads_ui.cc b/chrome/browser/dom_ui/downloads_ui.cc
index 009d65b..3e52879 100644
--- a/chrome/browser/dom_ui/downloads_ui.cc
+++ b/chrome/browser/dom_ui/downloads_ui.cc
@@ -128,6 +128,7 @@ class DownloadsDOMHandler : public DOMMessageHandler,
// DownloadItem::Observer interface
virtual void OnDownloadUpdated(DownloadItem* download);
+ virtual void OnDownloadOpened(DownloadItem* download) { }
// DownloadManager::Observer interface
virtual void ModelChanged();
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc
index 34fe0cf..04c6aeb 100644
--- a/chrome/browser/download/download_manager.cc
+++ b/chrome/browser/download/download_manager.cc
@@ -187,6 +187,10 @@ void DownloadItem::UpdateObservers() {
FOR_EACH_OBSERVER(Observer, observers_, OnDownloadUpdated(this));
}
+void DownloadItem::NotifyObserversDownloadOpened() {
+ FOR_EACH_OBSERVER(Observer, observers_, OnDownloadOpened(this));
+}
+
// If we've received more data than we were expecting (bad server info?), revert
// to 'unknown size mode'.
void DownloadItem::UpdateSize(int64 bytes_so_far) {
diff --git a/chrome/browser/download/download_manager.h b/chrome/browser/download/download_manager.h
index c013f0c..5f73b22 100644
--- a/chrome/browser/download/download_manager.h
+++ b/chrome/browser/download/download_manager.h
@@ -100,6 +100,9 @@ class DownloadItem {
class Observer {
public:
virtual void OnDownloadUpdated(DownloadItem* download) = 0;
+
+ // Called when a downloaded file has been opened.
+ virtual void OnDownloadOpened(DownloadItem* download) = 0;
};
// Constructing from persistent store:
@@ -126,9 +129,12 @@ class DownloadItem {
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
- // Notify our observers periodically
+ // Notifies our observers periodically.
void UpdateObservers();
+ // Notifies our observers the downloaded file has been opened.
+ void NotifyObserversDownloadOpened();
+
// Received a new chunk of data
void Update(int64 bytes_so_far);
diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc
index ad670ab..9b6da6b 100644
--- a/chrome/browser/download/download_util.cc
+++ b/chrome/browser/download/download_util.cc
@@ -48,10 +48,12 @@ bool CanOpenDownload(DownloadItem* download) {
}
void OpenDownload(DownloadItem* download) {
- if (download->state() == DownloadItem::IN_PROGRESS)
+ if (download->state() == DownloadItem::IN_PROGRESS) {
download->set_open_when_complete(!download->open_when_complete());
- else if (download->state() == DownloadItem::COMPLETE)
+ } else if (download->state() == DownloadItem::COMPLETE) {
+ download->NotifyObserversDownloadOpened();
download->manager()->OpenDownload(download, NULL);
+ }
}
// Download progress painting --------------------------------------------------
diff --git a/chrome/browser/gtk/download_item_gtk.h b/chrome/browser/gtk/download_item_gtk.h
index 9495a97..4c6bd76 100644
--- a/chrome/browser/gtk/download_item_gtk.h
+++ b/chrome/browser/gtk/download_item_gtk.h
@@ -26,6 +26,7 @@ class DownloadItemGtk : DownloadItem::Observer {
// DownloadItem::Observer implementation
virtual void OnDownloadUpdated(DownloadItem* download);
+ virtual void OnDownloadOpened(DownloadItem* download) { }
private:
static void InitNineBoxes();
diff --git a/chrome/browser/views/download_item_view.cc b/chrome/browser/views/download_item_view.cc
index 9865d5d..d66a53e 100644
--- a/chrome/browser/views/download_item_view.cc
+++ b/chrome/browser/views/download_item_view.cc
@@ -52,11 +52,16 @@ static const int kButtonPadding = 5; // Pixels.
static const int kLabelPadding = 4; // Pixels.
static const SkColor kFileNameColor = SkColorSetRGB(87, 108, 149);
+static const SkColor kFileNameDisabledColor = SkColorSetRGB(171, 192, 212);
static const SkColor kStatusColor = SkColorSetRGB(123, 141, 174);
// How long the 'download complete' animation should last for.
static const int kCompleteAnimationDurationMs = 2500;
+// How long we keep the item disabled after the user clicked it to open the
+// downloaded item.
+static const int kDisabledOnOpenDuration = 3000;
+
// DownloadShelfContextMenuWin -------------------------------------------------
class DownloadShelfContextMenuWin : public DownloadShelfContextMenu,
@@ -136,7 +141,9 @@ DownloadItemView::DownloadItemView(DownloadItem* download,
save_button_(NULL),
discard_button_(NULL),
dangerous_download_label_(NULL),
- dangerous_download_label_sized_(false) {
+ dangerous_download_label_sized_(false),
+ reenable_method_factory_(this),
+ disabled_while_opening_(false) {
// TODO(idana) Bug# 1163334
//
// We currently do not mirror each download item on the download shelf (even
@@ -364,6 +371,15 @@ void DownloadItemView::OnDownloadUpdated(DownloadItem* download) {
GetParent()->SchedulePaint();
}
+void DownloadItemView::OnDownloadOpened(DownloadItem* download) {
+ disabled_while_opening_ = true;
+ SetEnabled(false);
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ reenable_method_factory_.NewRunnableMethod(&DownloadItemView::Reenable),
+ kDisabledOnOpenDuration);
+}
+
// View overrides
// In dangerous mode we have to layout our buttons.
@@ -514,16 +530,24 @@ void DownloadItemView::Paint(ChromeCanvas* canvas) {
// Last value of x was the end of the right image, just before the button.
// Note that in dangerous mode we use a label (as the text is multi-line).
if (!IsDangerousMode()) {
- std::wstring filename =
- gfx::ElideFilename(download_->GetFileName().ToWStringHack(),
- font_,
- kTextWidth);
+ std::wstring filename;
+ if (!disabled_while_opening_) {
+ filename = gfx::ElideFilename(download_->GetFileName().ToWStringHack(),
+ font_, kTextWidth);
+ } else {
+ filename =
+ l10n_util::GetStringF(IDS_DOWNLOAD_STATUS_OPENING,
+ download_->GetFileName().ToWStringHack());
+ filename = gfx::ElideFilename(filename, font_, kTextWidth);
+ }
if (show_status_text_) {
int y = box_y_ + kVerticalPadding;
// Draw the file's name.
- canvas->DrawStringInt(filename, font_, kFileNameColor,
+ canvas->DrawStringInt(filename, font_,
+ IsEnabled() ? kFileNameColor :
+ kFileNameDisabledColor,
download_util::kSmallProgressIconSize, y,
kTextWidth, font_.height());
@@ -536,7 +560,9 @@ void DownloadItemView::Paint(ChromeCanvas* canvas) {
int y = box_y_ + (box_height_ - font_.height()) / 2;
// Draw the file's name.
- canvas->DrawStringInt(filename, font_, kFileNameColor,
+ canvas->DrawStringInt(filename, font_,
+ IsEnabled() ? kFileNameColor :
+ kFileNameDisabledColor,
download_util::kSmallProgressIconSize, y,
kTextWidth, font_.height());
}
@@ -569,9 +595,19 @@ void DownloadItemView::Paint(ChromeCanvas* canvas) {
}
// Draw the icon image.
- canvas->DrawBitmapInt(*icon,
- download_util::kSmallProgressIconOffset,
- download_util::kSmallProgressIconOffset);
+ if (IsEnabled()) {
+ canvas->DrawBitmapInt(*icon,
+ download_util::kSmallProgressIconOffset,
+ download_util::kSmallProgressIconOffset);
+ } else {
+ // Use an alpha to make the image look disabled.
+ SkPaint paint;
+ paint.setAlpha(120);
+ canvas->DrawBitmapInt(*icon,
+ download_util::kSmallProgressIconOffset,
+ download_util::kSmallProgressIconOffset,
+ paint);
+ }
}
}
@@ -880,3 +916,8 @@ void DownloadItemView::SizeLabelToMinWidth() {
dangerous_download_label_->SetBounds(0, 0, size.width(), size.height());
dangerous_download_label_sized_ = true;
}
+
+void DownloadItemView::Reenable() {
+ disabled_while_opening_ = false;
+ SetEnabled(true); // Triggers a repaint.
+}
diff --git a/chrome/browser/views/download_item_view.h b/chrome/browser/views/download_item_view.h
index d266935..4cd805f 100644
--- a/chrome/browser/views/download_item_view.h
+++ b/chrome/browser/views/download_item_view.h
@@ -50,6 +50,7 @@ class DownloadItemView : public views::ButtonListener,
// DownloadObserver method
virtual void OnDownloadUpdated(DownloadItem* download);
+ virtual void OnDownloadOpened(DownloadItem* download);
// View overrides
virtual void Layout();
@@ -136,6 +137,10 @@ class DownloadItemView : public views::ButtonListener,
// and simply returned on subsequent calls.
void SizeLabelToMinWidth();
+ // Reenables the item after it has been disabled when a user clicked it to
+ // open the downloaded file.
+ void Reenable();
+
// The different images used for the background.
BodyImageSet normal_body_image_set_;
BodyImageSet hot_body_image_set_;
@@ -220,6 +225,13 @@ class DownloadItemView : public views::ButtonListener,
// The size of the buttons. Cached so animation works when hidden.
gfx::Size cached_button_size_;
+ // Whether we are currently disabled as part of opening the downloaded file.
+ bool disabled_while_opening_;
+
+ // Method factory used to delay reenabling of the item when opening the
+ // downloaded file.
+ ScopedRunnableMethodFactory<DownloadItemView> reenable_method_factory_;
+
DISALLOW_COPY_AND_ASSIGN(DownloadItemView);
};