Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: chrome/browser/gtk/download_item_gtk.cc

Issue 1528032: Add download item tooltips on linux/win. (Closed)
Patch Set: fix compile Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/gtk/download_item_gtk.h ('k') | chrome/browser/views/download_item_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/gtk/download_item_gtk.h" 5 #include "chrome/browser/gtk/download_item_gtk.h"
6 6
7 #include "app/gtk_util.h" 7 #include "app/gtk_util.h"
8 #include "app/l10n_util.h" 8 #include "app/l10n_util.h"
9 #include "app/menus/simple_menu_model.h" 9 #include "app/menus/simple_menu_model.h"
10 #include "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 // bitmap that we use to draw it, i.e. 16, but can be more. 42 // bitmap that we use to draw it, i.e. 16, but can be more.
43 const int kMenuButtonWidth = 16; 43 const int kMenuButtonWidth = 16;
44 44
45 // Padding on left and right of items in dangerous download prompt. 45 // Padding on left and right of items in dangerous download prompt.
46 const int kDangerousElementPadding = 3; 46 const int kDangerousElementPadding = 3;
47 47
48 // Amount of space we allot to showing the filename. If the filename is too wide 48 // Amount of space we allot to showing the filename. If the filename is too wide
49 // it will be elided. 49 // it will be elided.
50 const int kTextWidth = 140; 50 const int kTextWidth = 140;
51 51
52 // We only cap the size of the tooltip so we don't crash.
53 const int kTooltipMaxWidth = 1000;
54
52 // The minimum width we will ever draw the download item. Used as a lower bound 55 // The minimum width we will ever draw the download item. Used as a lower bound
53 // during animation. This number comes from the width of the images used to 56 // during animation. This number comes from the width of the images used to
54 // make the download item. 57 // make the download item.
55 const int kMinDownloadItemWidth = download_util::kSmallProgressIconSize; 58 const int kMinDownloadItemWidth = download_util::kSmallProgressIconSize;
56 59
57 // New download item animation speed in milliseconds. 60 // New download item animation speed in milliseconds.
58 const int kNewItemAnimationDurationMs = 800; 61 const int kNewItemAnimationDurationMs = 800;
59 62
60 // How long the 'download complete' animation should last for. 63 // How long the 'download complete' animation should last for.
61 const int kCompleteAnimationDurationMs = 2500; 64 const int kCompleteAnimationDurationMs = 2500;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 progress_angle_(download_util::kStartAngleDegrees), 149 progress_angle_(download_util::kStartAngleDegrees),
147 download_model_(download_model), 150 download_model_(download_model),
148 dangerous_prompt_(NULL), 151 dangerous_prompt_(NULL),
149 dangerous_label_(NULL), 152 dangerous_label_(NULL),
150 icon_(NULL), 153 icon_(NULL),
151 creation_time_(base::Time::Now()) { 154 creation_time_(base::Time::Now()) {
152 LoadIcon(); 155 LoadIcon();
153 156
154 body_.Own(gtk_button_new()); 157 body_.Own(gtk_button_new());
155 gtk_widget_set_app_paintable(body_.get(), TRUE); 158 gtk_widget_set_app_paintable(body_.get(), TRUE);
159 UpdateTooltip();
156 160
157 g_signal_connect(body_.get(), "expose-event", 161 g_signal_connect(body_.get(), "expose-event",
158 G_CALLBACK(OnExpose), this); 162 G_CALLBACK(OnExpose), this);
159 g_signal_connect(body_.get(), "clicked", 163 g_signal_connect(body_.get(), "clicked",
160 G_CALLBACK(OnClick), this); 164 G_CALLBACK(OnClick), this);
161 GTK_WIDGET_UNSET_FLAGS(body_.get(), GTK_CAN_FOCUS); 165 GTK_WIDGET_UNSET_FLAGS(body_.get(), GTK_CAN_FOCUS);
162 // Remove internal padding on the button. 166 // Remove internal padding on the button.
163 GtkRcStyle* no_padding_style = gtk_rc_style_new(); 167 GtkRcStyle* no_padding_style = gtk_rc_style_new();
164 no_padding_style->xthickness = 0; 168 no_padding_style->xthickness = 0;
165 no_padding_style->ythickness = 0; 169 no_padding_style->ythickness = 0;
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 329
326 // We may free some shelf space for showing more download items. 330 // We may free some shelf space for showing more download items.
327 parent_shelf_->MaybeShowMoreDownloadItems(); 331 parent_shelf_->MaybeShowMoreDownloadItems();
328 } 332 }
329 333
330 if (download->full_path() != icon_filepath_) { 334 if (download->full_path() != icon_filepath_) {
331 // Turns out the file path is "unconfirmed %d.download" for dangerous 335 // Turns out the file path is "unconfirmed %d.download" for dangerous
332 // downloads. When the download is confirmed, the file is renamed on 336 // downloads. When the download is confirmed, the file is renamed on
333 // another thread, so reload the icon if the download filename changes. 337 // another thread, so reload the icon if the download filename changes.
334 LoadIcon(); 338 LoadIcon();
339
340 UpdateTooltip();
335 } 341 }
336 342
337 switch (download->state()) { 343 switch (download->state()) {
338 case DownloadItem::REMOVING: 344 case DownloadItem::REMOVING:
339 parent_shelf_->RemoveDownloadItem(this); // This will delete us! 345 parent_shelf_->RemoveDownloadItem(this); // This will delete us!
340 return; 346 return;
341 case DownloadItem::CANCELLED: 347 case DownloadItem::CANCELLED:
342 StopDownloadProgress(); 348 StopDownloadProgress();
343 gtk_widget_queue_draw(progress_area_.get()); 349 gtk_widget_queue_draw(progress_area_.get());
344 break; 350 break;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 480
475 void DownloadItemGtk::LoadIcon() { 481 void DownloadItemGtk::LoadIcon() {
476 icon_consumer_.CancelAllRequests(); 482 icon_consumer_.CancelAllRequests();
477 IconManager* im = g_browser_process->icon_manager(); 483 IconManager* im = g_browser_process->icon_manager();
478 icon_filepath_ = get_download()->full_path(); 484 icon_filepath_ = get_download()->full_path();
479 im->LoadIcon(icon_filepath_, 485 im->LoadIcon(icon_filepath_,
480 IconLoader::SMALL, &icon_consumer_, 486 IconLoader::SMALL, &icon_consumer_,
481 NewCallback(this, &DownloadItemGtk::OnLoadIconComplete)); 487 NewCallback(this, &DownloadItemGtk::OnLoadIconComplete));
482 } 488 }
483 489
490 void DownloadItemGtk::UpdateTooltip() {
491 std::wstring elided_filename = gfx::ElideFilename(
492 get_download()->GetFileName(),
493 gfx::Font(), kTooltipMaxWidth);
494 gtk_widget_set_tooltip_text(body_.get(), WideToUTF8(elided_filename).c_str());
495 }
496
484 void DownloadItemGtk::UpdateNameLabel() { 497 void DownloadItemGtk::UpdateNameLabel() {
485 // TODO(estade): This is at best an educated guess, since we don't actually 498 // TODO(estade): This is at best an educated guess, since we don't actually
486 // use gfx::Font() to draw the text. This is why we need to add so 499 // use gfx::Font() to draw the text. This is why we need to add so
487 // much padding when we set the size request. We need to either use gfx::Font 500 // much padding when we set the size request. We need to either use gfx::Font
488 // or somehow extend TextElider. 501 // or somehow extend TextElider.
489 std::wstring elided_filename = gfx::ElideFilename( 502 std::wstring elided_filename = gfx::ElideFilename(
490 get_download()->GetFileName(), 503 get_download()->GetFileName(),
491 gfx::Font(), kTextWidth); 504 gfx::Font(), kTextWidth);
492 505
493 GdkColor color = theme_provider_->GetGdkColor( 506 GdkColor color = theme_provider_->GetGdkColor(
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 865
853 // static 866 // static
854 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button, 867 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button,
855 DownloadItemGtk* item) { 868 DownloadItemGtk* item) {
856 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", 869 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download",
857 base::Time::Now() - item->creation_time_); 870 base::Time::Now() - item->creation_time_);
858 if (item->get_download()->state() == DownloadItem::IN_PROGRESS) 871 if (item->get_download()->state() == DownloadItem::IN_PROGRESS)
859 item->get_download()->Cancel(true); 872 item->get_download()->Cancel(true);
860 item->get_download()->Remove(true); 873 item->get_download()->Remove(true);
861 } 874 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/download_item_gtk.h ('k') | chrome/browser/views/download_item_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698