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/debug/trace_event.h" |
9 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
11 #include "base/time.h" | 12 #include "base/time.h" |
12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 15 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
15 #include "chrome/browser/download/download_item_model.h" | 16 #include "chrome/browser/download/download_item_model.h" |
16 #include "chrome/browser/download/download_util.h" | 17 #include "chrome/browser/download/download_util.h" |
17 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/gtk/custom_drag.h" | 19 #include "chrome/browser/ui/gtk/custom_drag.h" |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 IDR_DOWNLOAD_BUTTON_RIGHT_TOP_NO_DD, | 693 IDR_DOWNLOAD_BUTTON_RIGHT_TOP_NO_DD, |
693 IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE, | 694 IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE, |
694 IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE, | 695 IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE, |
695 IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE_NO_DD, | 696 IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE_NO_DD, |
696 IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM, | 697 IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM, |
697 IDR_DOWNLOAD_BUTTON_CENTER_BOTTOM, | 698 IDR_DOWNLOAD_BUTTON_CENTER_BOTTOM, |
698 IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM_NO_DD); | 699 IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM_NO_DD); |
699 } | 700 } |
700 | 701 |
701 gboolean DownloadItemGtk::OnHboxExpose(GtkWidget* widget, GdkEventExpose* e) { | 702 gboolean DownloadItemGtk::OnHboxExpose(GtkWidget* widget, GdkEventExpose* e) { |
| 703 TRACE_EVENT0("ui::gtk", "DownloadItemGtk::OnHboxExpose"); |
702 if (theme_service_->UsingNativeTheme()) { | 704 if (theme_service_->UsingNativeTheme()) { |
703 GtkAllocation allocation; | 705 GtkAllocation allocation; |
704 gtk_widget_get_allocation(widget, &allocation); | 706 gtk_widget_get_allocation(widget, &allocation); |
705 int border_width = gtk_container_get_border_width(GTK_CONTAINER(widget)); | 707 int border_width = gtk_container_get_border_width(GTK_CONTAINER(widget)); |
706 int x = allocation.x + border_width; | 708 int x = allocation.x + border_width; |
707 int y = allocation.y + border_width; | 709 int y = allocation.y + border_width; |
708 int width = allocation.width - border_width * 2; | 710 int width = allocation.width - border_width * 2; |
709 int height = allocation.height - border_width * 2; | 711 int height = allocation.height - border_width * 2; |
710 | 712 |
711 if (IsDangerous()) { | 713 if (IsDangerous()) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 &e->area, widget, "button", | 760 &e->area, widget, "button", |
759 arrow_allocation.y, | 761 arrow_allocation.y, |
760 arrow_allocation.y + arrow_allocation.height, | 762 arrow_allocation.y + arrow_allocation.height, |
761 left_clip.x + left_clip.width); | 763 left_clip.x + left_clip.width); |
762 } | 764 } |
763 } | 765 } |
764 return FALSE; | 766 return FALSE; |
765 } | 767 } |
766 | 768 |
767 gboolean DownloadItemGtk::OnExpose(GtkWidget* widget, GdkEventExpose* e) { | 769 gboolean DownloadItemGtk::OnExpose(GtkWidget* widget, GdkEventExpose* e) { |
| 770 TRACE_EVENT0("ui::gtk", "DownloadItemGtk::OnExpose"); |
768 if (!theme_service_->UsingNativeTheme()) { | 771 if (!theme_service_->UsingNativeTheme()) { |
769 bool is_body = widget == body_.get(); | 772 bool is_body = widget == body_.get(); |
770 | 773 |
771 NineBox* nine_box = NULL; | 774 NineBox* nine_box = NULL; |
772 // If true, this widget is |body_|, otherwise it is |menu_button_|. | 775 // If true, this widget is |body_|, otherwise it is |menu_button_|. |
773 if (gtk_widget_get_state(widget) == GTK_STATE_PRELIGHT) | 776 if (gtk_widget_get_state(widget) == GTK_STATE_PRELIGHT) |
774 nine_box = is_body ? body_nine_box_prelight_ : menu_nine_box_prelight_; | 777 nine_box = is_body ? body_nine_box_prelight_ : menu_nine_box_prelight_; |
775 else if (gtk_widget_get_state(widget) == GTK_STATE_ACTIVE) | 778 else if (gtk_widget_get_state(widget) == GTK_STATE_ACTIVE) |
776 nine_box = is_body ? body_nine_box_active_ : menu_nine_box_active_; | 779 nine_box = is_body ? body_nine_box_active_ : menu_nine_box_active_; |
777 else | 780 else |
(...skipping 26 matching lines...) Expand all Loading... |
804 GdkEventButton* event) { | 807 GdkEventButton* event) { |
805 if (event->type == GDK_BUTTON_PRESS && event->button == 3) { | 808 if (event->type == GDK_BUTTON_PRESS && event->button == 3) { |
806 ShowPopupMenu(NULL, event); | 809 ShowPopupMenu(NULL, event); |
807 return TRUE; | 810 return TRUE; |
808 } | 811 } |
809 return FALSE; | 812 return FALSE; |
810 } | 813 } |
811 | 814 |
812 gboolean DownloadItemGtk::OnProgressAreaExpose(GtkWidget* widget, | 815 gboolean DownloadItemGtk::OnProgressAreaExpose(GtkWidget* widget, |
813 GdkEventExpose* event) { | 816 GdkEventExpose* event) { |
| 817 TRACE_EVENT0("ui::gtk", "DownloadItemGtk::OnProgressAreaExpose"); |
| 818 |
814 GtkAllocation allocation; | 819 GtkAllocation allocation; |
815 gtk_widget_get_allocation(widget, &allocation); | 820 gtk_widget_get_allocation(widget, &allocation); |
816 | 821 |
817 // Create a transparent canvas. | 822 // Create a transparent canvas. |
818 gfx::CanvasSkiaPaint canvas(event, false); | 823 gfx::CanvasSkiaPaint canvas(event, false); |
819 if (complete_animation_.is_animating()) { | 824 if (complete_animation_.is_animating()) { |
820 if (get_download()->IsInterrupted()) { | 825 if (get_download()->IsInterrupted()) { |
821 download_util::PaintDownloadInterrupted(&canvas, | 826 download_util::PaintDownloadInterrupted(&canvas, |
822 allocation.x, allocation.y, | 827 allocation.x, allocation.y, |
823 complete_animation_.GetCurrentValue(), | 828 complete_animation_.GetCurrentValue(), |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 if (complete_animation_.is_animating()) | 870 if (complete_animation_.is_animating()) |
866 complete_animation_.End(); | 871 complete_animation_.End(); |
867 | 872 |
868 if (!menu_.get()) | 873 if (!menu_.get()) |
869 menu_.reset(new DownloadShelfContextMenuGtk(download_model_.get(), this)); | 874 menu_.reset(new DownloadShelfContextMenuGtk(download_model_.get(), this)); |
870 menu_->Popup(button, event); | 875 menu_->Popup(button, event); |
871 } | 876 } |
872 | 877 |
873 gboolean DownloadItemGtk::OnDangerousPromptExpose(GtkWidget* widget, | 878 gboolean DownloadItemGtk::OnDangerousPromptExpose(GtkWidget* widget, |
874 GdkEventExpose* event) { | 879 GdkEventExpose* event) { |
| 880 TRACE_EVENT0("ui::gtk", "DownloadItemGtk::OnDangerousPromptExpose"); |
875 if (!theme_service_->UsingNativeTheme()) { | 881 if (!theme_service_->UsingNativeTheme()) { |
876 // The hbox renderer will take care of the border when in GTK mode. | 882 // The hbox renderer will take care of the border when in GTK mode. |
877 dangerous_nine_box_->RenderToWidget(widget); | 883 dangerous_nine_box_->RenderToWidget(widget); |
878 } | 884 } |
879 return FALSE; // Continue propagation. | 885 return FALSE; // Continue propagation. |
880 } | 886 } |
881 | 887 |
882 void DownloadItemGtk::OnDangerousAccept(GtkWidget* button) { | 888 void DownloadItemGtk::OnDangerousAccept(GtkWidget* button) { |
883 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", | 889 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", |
884 base::Time::Now() - creation_time_); | 890 base::Time::Now() - creation_time_); |
885 get_download()->DangerousDownloadValidated(); | 891 get_download()->DangerousDownloadValidated(); |
886 } | 892 } |
887 | 893 |
888 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { | 894 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { |
889 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", | 895 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", |
890 base::Time::Now() - creation_time_); | 896 base::Time::Now() - creation_time_); |
891 if (get_download()->IsPartialDownload()) | 897 if (get_download()->IsPartialDownload()) |
892 get_download()->Cancel(true); | 898 get_download()->Cancel(true); |
893 get_download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 899 get_download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
894 } | 900 } |
OLD | NEW |