Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/gfx/canvas_paint.h" | 8 #include "app/gfx/canvas_paint.h" |
| 9 #include "app/gfx/font.h" | 9 #include "app/gfx/font.h" |
| 10 #include "app/gfx/text_elider.h" | 10 #include "app/gfx/text_elider.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 // bitmap that we use to draw it, i.e. 16, but can be more. | 35 // bitmap that we use to draw it, i.e. 16, but can be more. |
| 36 const int kMenuButtonWidth = 16; | 36 const int kMenuButtonWidth = 16; |
| 37 | 37 |
| 38 // Padding on left and right of items in dangerous download prompt. | 38 // Padding on left and right of items in dangerous download prompt. |
| 39 const int kDangerousElementPadding = 3; | 39 const int kDangerousElementPadding = 3; |
| 40 | 40 |
| 41 // Amount of space we allot to showing the filename. If the filename is too wide | 41 // Amount of space we allot to showing the filename. If the filename is too wide |
| 42 // it will be elided. | 42 // it will be elided. |
| 43 const int kTextWidth = 140; | 43 const int kTextWidth = 140; |
| 44 | 44 |
| 45 // Showing width of the dangerous file warning, in pixels. | |
|
Evan Martin
2009/07/13 21:22:33
"Showing width" is a bit of strange wording (?)
| |
| 46 const int kDangerousTextWidth = 350; | |
| 47 | |
| 45 // The minimum width we will ever draw the download item. Used as a lower bound | 48 // The minimum width we will ever draw the download item. Used as a lower bound |
| 46 // during animation. This number comes from the width of the images used to | 49 // during animation. This number comes from the width of the images used to |
| 47 // make the download item. | 50 // make the download item. |
| 48 const int kMinDownloadItemWidth = download_util::kSmallProgressIconSize; | 51 const int kMinDownloadItemWidth = download_util::kSmallProgressIconSize; |
| 49 | 52 |
| 50 const char* kLabelColorMarkup = "<span color='#%s'>%s</span>"; | 53 const char* kLabelColorMarkup = "<span color='#%s'>%s</span>"; |
| 51 const char* kFilenameColor = "576C95"; // 87, 108, 149 | 54 const char* kFilenameColor = "576C95"; // 87, 108, 149 |
| 52 const char* kStatusColor = "7B8DAE"; // 123, 141, 174 | 55 const char* kStatusColor = "7B8DAE"; // 123, 141, 174 |
| 53 | 56 |
| 54 // New download item animation speed in milliseconds. | 57 // New download item animation speed in milliseconds. |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 gtk_box_pack_end(GTK_BOX(dangerous_hbox_), empty_label_b, | 277 gtk_box_pack_end(GTK_BOX(dangerous_hbox_), empty_label_b, |
| 275 FALSE, FALSE, 0); | 278 FALSE, FALSE, 0); |
| 276 | 279 |
| 277 // Create the warning icon. | 280 // Create the warning icon. |
| 278 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 281 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 279 GdkPixbuf* download_pixbuf = rb.GetPixbufNamed(IDR_WARNING); | 282 GdkPixbuf* download_pixbuf = rb.GetPixbufNamed(IDR_WARNING); |
| 280 GtkWidget* dangerous_image = gtk_image_new_from_pixbuf(download_pixbuf); | 283 GtkWidget* dangerous_image = gtk_image_new_from_pixbuf(download_pixbuf); |
| 281 gtk_box_pack_start(GTK_BOX(dangerous_hbox_), dangerous_image, | 284 gtk_box_pack_start(GTK_BOX(dangerous_hbox_), dangerous_image, |
| 282 FALSE, FALSE, 0); | 285 FALSE, FALSE, 0); |
| 283 | 286 |
| 284 // Create the warning text. | 287 std::wstring elided_filename = gfx::ElideFilename( |
| 285 // TODO(estade): the encoding might not be UTF8. | 288 get_download()->original_name(), |
| 289 gfx::Font(), kTextWidth); | |
| 286 std::string dangerous_warning = | 290 std::string dangerous_warning = |
| 287 l10n_util::GetStringFUTF8(IDS_PROMPT_DANGEROUS_DOWNLOAD, | 291 l10n_util::GetStringFUTF8(IDS_PROMPT_DANGEROUS_DOWNLOAD, |
| 288 UTF8ToUTF16(get_download()->original_name().value())); | 292 WideToUTF16(elided_filename)); |
| 289 gchar* label_markup = | 293 gchar* label_markup = |
| 290 g_markup_printf_escaped(kLabelColorMarkup, kFilenameColor, | 294 g_markup_printf_escaped(kLabelColorMarkup, kFilenameColor, |
| 291 dangerous_warning.c_str()); | 295 dangerous_warning.c_str()); |
| 292 GtkWidget* dangerous_label = gtk_label_new(NULL); | 296 GtkWidget* dangerous_label = gtk_label_new(NULL); |
| 293 // Until we switch to vector graphics, force the font size. | 297 // Until we switch to vector graphics, force the font size. |
| 294 // 13.4px == 10pt @ 96dpi | 298 // 13.4px == 10pt @ 96dpi |
| 295 gtk_util::ForceFontSizePixels(dangerous_label, 13.4); | 299 gtk_util::ForceFontSizePixels(dangerous_label, 13.4); |
| 296 gtk_label_set_markup(GTK_LABEL(dangerous_label), label_markup); | 300 gtk_label_set_markup(GTK_LABEL(dangerous_label), label_markup); |
| 297 gtk_label_set_line_wrap(GTK_LABEL(dangerous_label), TRUE); | 301 gtk_label_set_line_wrap(GTK_LABEL(dangerous_label), TRUE); |
| 298 // We pass TRUE, TRUE so that the label will condense to less than its | 302 // We pass TRUE, TRUE so that the label will condense to less than its |
| 299 // request when the animation is going on. | 303 // request when the animation is going on. |
| 300 gtk_box_pack_start(GTK_BOX(dangerous_hbox_), dangerous_label, | 304 gtk_box_pack_start(GTK_BOX(dangerous_hbox_), dangerous_label, |
| 301 TRUE, TRUE, 0); | 305 TRUE, TRUE, 0); |
| 306 gtk_widget_set_size_request(dangerous_label, kDangerousTextWidth, -1); | |
| 302 g_free(label_markup); | 307 g_free(label_markup); |
| 303 | 308 |
| 304 // Create the ok button. | 309 // Create the ok button. |
| 305 GtkWidget* dangerous_accept = gtk_button_new_with_label( | 310 GtkWidget* dangerous_accept = gtk_button_new_with_label( |
| 306 l10n_util::GetStringUTF8(IDS_SAVE_DOWNLOAD).c_str()); | 311 l10n_util::GetStringUTF8(IDS_SAVE_DOWNLOAD).c_str()); |
| 307 g_signal_connect(dangerous_accept, "clicked", | 312 g_signal_connect(dangerous_accept, "clicked", |
| 308 G_CALLBACK(OnDangerousAccept), this); | 313 G_CALLBACK(OnDangerousAccept), this); |
| 309 gtk_util::CenterWidgetInHBox(dangerous_hbox_, dangerous_accept, false, 0); | 314 gtk_util::CenterWidgetInHBox(dangerous_hbox_, dangerous_accept, false, 0); |
| 310 | 315 |
| 311 // Create the nevermind button. | 316 // Create the nevermind button. |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 703 item->get_download()); | 708 item->get_download()); |
| 704 } | 709 } |
| 705 | 710 |
| 706 // static | 711 // static |
| 707 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button, | 712 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button, |
| 708 DownloadItemGtk* item) { | 713 DownloadItemGtk* item) { |
| 709 if (item->get_download()->state() == DownloadItem::IN_PROGRESS) | 714 if (item->get_download()->state() == DownloadItem::IN_PROGRESS) |
| 710 item->get_download()->Cancel(true); | 715 item->get_download()->Cancel(true); |
| 711 item->get_download()->Remove(true); | 716 item->get_download()->Remove(true); |
| 712 } | 717 } |
| OLD | NEW |