OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 G_CALLBACK(OnButtonPressThunk), this); | 192 G_CALLBACK(OnButtonPressThunk), this); |
193 GTK_WIDGET_UNSET_FLAGS(body_.get(), GTK_CAN_FOCUS); | 193 GTK_WIDGET_UNSET_FLAGS(body_.get(), GTK_CAN_FOCUS); |
194 // Remove internal padding on the button. | 194 // Remove internal padding on the button. |
195 GtkRcStyle* no_padding_style = gtk_rc_style_new(); | 195 GtkRcStyle* no_padding_style = gtk_rc_style_new(); |
196 no_padding_style->xthickness = 0; | 196 no_padding_style->xthickness = 0; |
197 no_padding_style->ythickness = 0; | 197 no_padding_style->ythickness = 0; |
198 gtk_widget_modify_style(body_.get(), no_padding_style); | 198 gtk_widget_modify_style(body_.get(), no_padding_style); |
199 g_object_unref(no_padding_style); | 199 g_object_unref(no_padding_style); |
200 | 200 |
201 name_label_ = gtk_label_new(NULL); | 201 name_label_ = gtk_label_new(NULL); |
202 // Left align and vertically center the labels. | |
203 gtk_misc_set_alignment(GTK_MISC(name_label_), 0, 0.5); | |
204 // Until we switch to vector graphics, force the font size. | |
205 gtk_util::ForceFontSizePixels(name_label_, kTextSize); | |
202 | 206 |
203 UpdateNameLabel(); | 207 UpdateNameLabel(); |
204 | 208 |
205 status_label_ = gtk_label_new(NULL); | 209 status_label_ = NULL; |
206 g_signal_connect(status_label_, "destroy", | |
207 G_CALLBACK(gtk_widget_destroyed), &status_label_); | |
208 // Left align and vertically center the labels. | |
209 gtk_misc_set_alignment(GTK_MISC(name_label_), 0, 0.5); | |
210 gtk_misc_set_alignment(GTK_MISC(status_label_), 0, 0.5); | |
211 // Until we switch to vector graphics, force the font size. | |
212 gtk_util::ForceFontSizePixels(name_label_, kTextSize); | |
213 gtk_util::ForceFontSizePixels(status_label_, kTextSize); | |
214 | 210 |
215 // Stack the labels on top of one another. | 211 // Stack the labels on top of one another. |
216 GtkWidget* text_stack = gtk_vbox_new(FALSE, 0); | 212 text_stack_ = gtk_vbox_new(FALSE, 0); |
217 gtk_box_pack_start(GTK_BOX(text_stack), name_label_, TRUE, TRUE, 0); | 213 gtk_box_pack_start(GTK_BOX(text_stack_), name_label_, TRUE, TRUE, 0); |
218 gtk_box_pack_start(GTK_BOX(text_stack), status_label_, FALSE, FALSE, 0); | |
219 | 214 |
220 // We use a GtkFixed because we don't want it to have its own window. | 215 // We use a GtkFixed because we don't want it to have its own window. |
221 // This choice of widget is not critically important though. | 216 // This choice of widget is not critically important though. |
222 progress_area_.Own(gtk_fixed_new()); | 217 progress_area_.Own(gtk_fixed_new()); |
223 gtk_widget_set_size_request(progress_area_.get(), | 218 gtk_widget_set_size_request(progress_area_.get(), |
224 download_util::kSmallProgressIconSize, | 219 download_util::kSmallProgressIconSize, |
225 download_util::kSmallProgressIconSize); | 220 download_util::kSmallProgressIconSize); |
226 gtk_widget_set_app_paintable(progress_area_.get(), TRUE); | 221 gtk_widget_set_app_paintable(progress_area_.get(), TRUE); |
227 g_signal_connect(progress_area_.get(), "expose-event", | 222 g_signal_connect(progress_area_.get(), "expose-event", |
228 G_CALLBACK(OnProgressAreaExposeThunk), this); | 223 G_CALLBACK(OnProgressAreaExposeThunk), this); |
229 | 224 |
230 // Put the download progress icon on the left of the labels. | 225 // Put the download progress icon on the left of the labels. |
231 GtkWidget* body_hbox = gtk_hbox_new(FALSE, 0); | 226 GtkWidget* body_hbox = gtk_hbox_new(FALSE, 0); |
232 gtk_container_add(GTK_CONTAINER(body_.get()), body_hbox); | 227 gtk_container_add(GTK_CONTAINER(body_.get()), body_hbox); |
233 gtk_box_pack_start(GTK_BOX(body_hbox), progress_area_.get(), FALSE, FALSE, 0); | 228 gtk_box_pack_start(GTK_BOX(body_hbox), progress_area_.get(), FALSE, FALSE, 0); |
234 gtk_box_pack_start(GTK_BOX(body_hbox), text_stack, TRUE, TRUE, 0); | 229 gtk_box_pack_start(GTK_BOX(body_hbox), text_stack_, TRUE, TRUE, 0); |
235 | 230 |
236 menu_button_ = gtk_button_new(); | 231 menu_button_ = gtk_button_new(); |
237 gtk_widget_set_app_paintable(menu_button_, TRUE); | 232 gtk_widget_set_app_paintable(menu_button_, TRUE); |
238 GTK_WIDGET_UNSET_FLAGS(menu_button_, GTK_CAN_FOCUS); | 233 GTK_WIDGET_UNSET_FLAGS(menu_button_, GTK_CAN_FOCUS); |
239 g_signal_connect(menu_button_, "expose-event", | 234 g_signal_connect(menu_button_, "expose-event", |
240 G_CALLBACK(OnExposeThunk), this); | 235 G_CALLBACK(OnExposeThunk), this); |
241 g_signal_connect(menu_button_, "button-press-event", | 236 g_signal_connect(menu_button_, "button-press-event", |
242 G_CALLBACK(OnMenuButtonPressEventThunk), this); | 237 G_CALLBACK(OnMenuButtonPressEventThunk), this); |
243 g_object_set_data(G_OBJECT(menu_button_), "left-align-popup", | 238 g_object_set_data(G_OBJECT(menu_button_), "left-align-popup", |
244 reinterpret_cast<void*>(true)); | 239 reinterpret_cast<void*>(true)); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 download_complete_ = true; | 407 download_complete_ = true; |
413 break; | 408 break; |
414 case DownloadItem::IN_PROGRESS: | 409 case DownloadItem::IN_PROGRESS: |
415 get_download()->is_paused() ? | 410 get_download()->is_paused() ? |
416 StopDownloadProgress() : StartDownloadProgress(); | 411 StopDownloadProgress() : StartDownloadProgress(); |
417 break; | 412 break; |
418 default: | 413 default: |
419 NOTREACHED(); | 414 NOTREACHED(); |
420 } | 415 } |
421 | 416 |
422 // Now update the status label. We may have already removed it; if so, we | |
423 // do nothing. | |
424 if (!status_label_) { | |
425 return; | |
426 } | |
427 | |
428 status_text_ = UTF16ToUTF8(download_model_->GetStatusText()); | 417 status_text_ = UTF16ToUTF8(download_model_->GetStatusText()); |
429 // Remove the status text label. | |
430 if (status_text_.empty()) { | |
431 gtk_widget_destroy(status_label_); | |
432 return; | |
433 } | |
434 | |
435 UpdateStatusLabel(status_text_); | 418 UpdateStatusLabel(status_text_); |
436 } | 419 } |
437 | 420 |
438 void DownloadItemGtk::AnimationProgressed(const ui::Animation* animation) { | 421 void DownloadItemGtk::AnimationProgressed(const ui::Animation* animation) { |
439 if (animation == &complete_animation_) { | 422 if (animation == &complete_animation_) { |
440 gtk_widget_queue_draw(progress_area_.get()); | 423 gtk_widget_queue_draw(progress_area_.get()); |
441 } else { | 424 } else { |
442 DCHECK(animation == new_item_animation_.get()); | 425 DCHECK(animation == new_item_animation_.get()); |
443 if (IsDangerous()) { | 426 if (IsDangerous()) { |
444 int progress = static_cast<int>((dangerous_hbox_full_width_ - | 427 int progress = static_cast<int>((dangerous_hbox_full_width_ - |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
561 GdkColor color = theme_service_->GetGdkColor( | 544 GdkColor color = theme_service_->GetGdkColor( |
562 ThemeService::COLOR_BOOKMARK_TEXT); | 545 ThemeService::COLOR_BOOKMARK_TEXT); |
563 gtk_util::SetLabelColor( | 546 gtk_util::SetLabelColor( |
564 name_label_, | 547 name_label_, |
565 theme_service_->UsingNativeTheme() ? NULL : &color); | 548 theme_service_->UsingNativeTheme() ? NULL : &color); |
566 gtk_label_set_text(GTK_LABEL(name_label_), | 549 gtk_label_set_text(GTK_LABEL(name_label_), |
567 UTF16ToUTF8(elided_filename).c_str()); | 550 UTF16ToUTF8(elided_filename).c_str()); |
568 } | 551 } |
569 | 552 |
570 void DownloadItemGtk::UpdateStatusLabel(const std::string& status_text) { | 553 void DownloadItemGtk::UpdateStatusLabel(const std::string& status_text) { |
571 if (!status_label_) | 554 // If |status_text| is empty, only |name_label_| is displayed at the |
555 // vertical center of |text_stack_|. Otherwise, |name_label_| is displayed | |
556 // on the upper half of |text_stack_| and |status_label_| is displayed | |
557 // on the lower half of |text_stack_|. | |
558 if (status_text.empty() && status_label_) { | |
559 gtk_widget_destroy(status_label_); | |
572 return; | 560 return; |
561 } | |
562 if (!status_label_) { | |
563 status_label_ = gtk_label_new(NULL); | |
564 g_signal_connect(status_label_, "destroy", | |
565 G_CALLBACK(gtk_widget_destroyed), &status_label_); | |
566 // Left align and vertically center the labels. | |
567 gtk_misc_set_alignment(GTK_MISC(status_label_), 0, 0.5); | |
568 // Until we switch to vector graphics, force the font size. | |
569 gtk_util::ForceFontSizePixels(status_label_, kTextSize); | |
570 | |
571 gtk_box_pack_start(GTK_BOX(text_stack_), status_label_, FALSE, FALSE, 0); | |
572 gtk_widget_show_all(hbox_.get()); | |
573 } | |
573 | 574 |
574 GdkColor text_color; | 575 GdkColor text_color; |
575 if (!theme_service_->UsingNativeTheme()) { | 576 if (!theme_service_->UsingNativeTheme()) { |
576 SkColor color = theme_service_->GetColor( | 577 SkColor color = theme_service_->GetColor( |
577 ThemeService::COLOR_BOOKMARK_TEXT); | 578 ThemeService::COLOR_BOOKMARK_TEXT); |
578 if (color_utils::RelativeLuminance(color) > 0.5) { | 579 if (color_utils::RelativeLuminance(color) > 0.5) { |
579 color = SkColorSetRGB( | 580 color = SkColorSetRGB( |
580 static_cast<int>(kDownloadItemLuminanceMod * | 581 static_cast<int>(kDownloadItemLuminanceMod * |
581 SkColorGetR(color)), | 582 SkColorGetR(color)), |
582 static_cast<int>(kDownloadItemLuminanceMod * | 583 static_cast<int>(kDownloadItemLuminanceMod * |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
839 gtk_container_propagate_expose(GTK_CONTAINER(widget), child, e); | 840 gtk_container_propagate_expose(GTK_CONTAINER(widget), child, e); |
840 | 841 |
841 return TRUE; | 842 return TRUE; |
842 } | 843 } |
843 | 844 |
844 void DownloadItemGtk::OnClick(GtkWidget* widget) { | 845 void DownloadItemGtk::OnClick(GtkWidget* widget) { |
845 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download", | 846 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download", |
846 base::Time::Now() - creation_time_); | 847 base::Time::Now() - creation_time_); |
847 get_download()->OpenDownload(); | 848 get_download()->OpenDownload(); |
848 parent_shelf_->ItemOpened(); | 849 parent_shelf_->ItemOpened(); |
850 parent_shelf_->CheckForFilesRemoval(); | |
Randy Smith (Not in Mondays)
2011/05/13 20:45:32
As mentioned elsewhere, I don't think this belongs
haraken1
2011/05/16 11:42:27
I removed it.
| |
849 } | 851 } |
850 | 852 |
851 gboolean DownloadItemGtk::OnButtonPress(GtkWidget* button, | 853 gboolean DownloadItemGtk::OnButtonPress(GtkWidget* button, |
852 GdkEventButton* event) { | 854 GdkEventButton* event) { |
853 if (event->type == GDK_BUTTON_PRESS && event->button == 3) { | 855 if (event->type == GDK_BUTTON_PRESS && event->button == 3) { |
854 ShowPopupMenu(NULL, event); | 856 ShowPopupMenu(NULL, event); |
857 parent_shelf_->CheckForFilesRemoval(); | |
855 return TRUE; | 858 return TRUE; |
856 } | 859 } |
857 | 860 parent_shelf_->CheckForFilesRemoval(); |
858 return FALSE; | 861 return FALSE; |
859 } | 862 } |
860 | 863 |
861 gboolean DownloadItemGtk::OnProgressAreaExpose(GtkWidget* widget, | 864 gboolean DownloadItemGtk::OnProgressAreaExpose(GtkWidget* widget, |
862 GdkEventExpose* event) { | 865 GdkEventExpose* event) { |
863 // Create a transparent canvas. | 866 // Create a transparent canvas. |
864 gfx::CanvasSkiaPaint canvas(event, false); | 867 gfx::CanvasSkiaPaint canvas(event, false); |
865 if (complete_animation_.is_animating()) { | 868 if (complete_animation_.is_animating()) { |
866 if (get_download()->IsInterrupted()) { | 869 if (get_download()->IsInterrupted()) { |
867 download_util::PaintDownloadInterrupted(&canvas, | 870 download_util::PaintDownloadInterrupted(&canvas, |
(...skipping 25 matching lines...) Expand all Loading... | |
893 | 896 |
894 return TRUE; | 897 return TRUE; |
895 } | 898 } |
896 | 899 |
897 gboolean DownloadItemGtk::OnMenuButtonPressEvent(GtkWidget* button, | 900 gboolean DownloadItemGtk::OnMenuButtonPressEvent(GtkWidget* button, |
898 GdkEventButton* event) { | 901 GdkEventButton* event) { |
899 if (event->type == GDK_BUTTON_PRESS && event->button == 1) { | 902 if (event->type == GDK_BUTTON_PRESS && event->button == 1) { |
900 ShowPopupMenu(button, event); | 903 ShowPopupMenu(button, event); |
901 menu_showing_ = true; | 904 menu_showing_ = true; |
902 gtk_widget_queue_draw(button); | 905 gtk_widget_queue_draw(button); |
906 parent_shelf_->CheckForFilesRemoval(); | |
903 return TRUE; | 907 return TRUE; |
904 } | 908 } |
905 | 909 parent_shelf_->CheckForFilesRemoval(); |
906 return FALSE; | 910 return FALSE; |
907 } | 911 } |
908 | 912 |
909 void DownloadItemGtk::ShowPopupMenu(GtkWidget* button, | 913 void DownloadItemGtk::ShowPopupMenu(GtkWidget* button, |
910 GdkEventButton* event) { | 914 GdkEventButton* event) { |
911 // Stop any completion animation. | 915 // Stop any completion animation. |
912 if (complete_animation_.is_animating()) | 916 if (complete_animation_.is_animating()) |
913 complete_animation_.End(); | 917 complete_animation_.End(); |
914 | 918 |
915 if (!menu_.get()) | 919 if (!menu_.get()) |
(...skipping 16 matching lines...) Expand all Loading... | |
932 get_download()->DangerousDownloadValidated(); | 936 get_download()->DangerousDownloadValidated(); |
933 } | 937 } |
934 | 938 |
935 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { | 939 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { |
936 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", | 940 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", |
937 base::Time::Now() - creation_time_); | 941 base::Time::Now() - creation_time_); |
938 if (get_download()->IsPartialDownload()) | 942 if (get_download()->IsPartialDownload()) |
939 get_download()->Cancel(true); | 943 get_download()->Cancel(true); |
940 get_download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 944 get_download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
941 } | 945 } |
OLD | NEW |