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 int border_width = GTK_CONTAINER(widget)->border_width; | 705 int border_width = GTK_CONTAINER(widget)->border_width; |
704 int x = widget->allocation.x + border_width; | 706 int x = widget->allocation.x + border_width; |
705 int y = widget->allocation.y + border_width; | 707 int y = widget->allocation.y + border_width; |
706 int width = widget->allocation.width - border_width * 2; | 708 int width = widget->allocation.width - border_width * 2; |
707 int height = widget->allocation.height - border_width * 2; | 709 int height = widget->allocation.height - border_width * 2; |
708 | 710 |
709 if (IsDangerous()) { | 711 if (IsDangerous()) { |
710 // Draw a simple frame around the area when we're displaying the warning. | 712 // Draw a simple frame around the area when we're displaying the warning. |
711 gtk_paint_shadow(widget->style, widget->window, | 713 gtk_paint_shadow(widget->style, widget->window, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 &e->area, widget, "button", | 763 &e->area, widget, "button", |
762 arrow_allocation.y, | 764 arrow_allocation.y, |
763 arrow_allocation.y + arrow_allocation.height, | 765 arrow_allocation.y + arrow_allocation.height, |
764 left_allocation.x + left_allocation.width); | 766 left_allocation.x + left_allocation.width); |
765 } | 767 } |
766 } | 768 } |
767 return FALSE; | 769 return FALSE; |
768 } | 770 } |
769 | 771 |
770 gboolean DownloadItemGtk::OnExpose(GtkWidget* widget, GdkEventExpose* e) { | 772 gboolean DownloadItemGtk::OnExpose(GtkWidget* widget, GdkEventExpose* e) { |
| 773 TRACE_EVENT0("ui::gtk", "DownloadItemGtk::OnExpose"); |
771 if (!theme_service_->UsingNativeTheme()) { | 774 if (!theme_service_->UsingNativeTheme()) { |
772 bool is_body = widget == body_.get(); | 775 bool is_body = widget == body_.get(); |
773 | 776 |
774 NineBox* nine_box = NULL; | 777 NineBox* nine_box = NULL; |
775 // If true, this widget is |body_|, otherwise it is |menu_button_|. | 778 // If true, this widget is |body_|, otherwise it is |menu_button_|. |
776 if (gtk_widget_get_state(widget) == GTK_STATE_PRELIGHT) | 779 if (gtk_widget_get_state(widget) == GTK_STATE_PRELIGHT) |
777 nine_box = is_body ? body_nine_box_prelight_ : menu_nine_box_prelight_; | 780 nine_box = is_body ? body_nine_box_prelight_ : menu_nine_box_prelight_; |
778 else if (gtk_widget_get_state(widget) == GTK_STATE_ACTIVE) | 781 else if (gtk_widget_get_state(widget) == GTK_STATE_ACTIVE) |
779 nine_box = is_body ? body_nine_box_active_ : menu_nine_box_active_; | 782 nine_box = is_body ? body_nine_box_active_ : menu_nine_box_active_; |
780 else | 783 else |
(...skipping 26 matching lines...) Expand all Loading... |
807 GdkEventButton* event) { | 810 GdkEventButton* event) { |
808 if (event->type == GDK_BUTTON_PRESS && event->button == 3) { | 811 if (event->type == GDK_BUTTON_PRESS && event->button == 3) { |
809 ShowPopupMenu(NULL, event); | 812 ShowPopupMenu(NULL, event); |
810 return TRUE; | 813 return TRUE; |
811 } | 814 } |
812 return FALSE; | 815 return FALSE; |
813 } | 816 } |
814 | 817 |
815 gboolean DownloadItemGtk::OnProgressAreaExpose(GtkWidget* widget, | 818 gboolean DownloadItemGtk::OnProgressAreaExpose(GtkWidget* widget, |
816 GdkEventExpose* event) { | 819 GdkEventExpose* event) { |
| 820 TRACE_EVENT0("ui::gtk", "DownloadItemGtk::OnProgressAreaExpose"); |
817 // Create a transparent canvas. | 821 // Create a transparent canvas. |
818 gfx::CanvasSkiaPaint canvas(event, false); | 822 gfx::CanvasSkiaPaint canvas(event, false); |
819 if (complete_animation_.is_animating()) { | 823 if (complete_animation_.is_animating()) { |
820 if (get_download()->IsInterrupted()) { | 824 if (get_download()->IsInterrupted()) { |
821 download_util::PaintDownloadInterrupted(&canvas, | 825 download_util::PaintDownloadInterrupted(&canvas, |
822 widget->allocation.x, widget->allocation.y, | 826 widget->allocation.x, widget->allocation.y, |
823 complete_animation_.GetCurrentValue(), | 827 complete_animation_.GetCurrentValue(), |
824 download_util::SMALL); | 828 download_util::SMALL); |
825 } else { | 829 } else { |
826 download_util::PaintDownloadComplete(&canvas, | 830 download_util::PaintDownloadComplete(&canvas, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 if (complete_animation_.is_animating()) | 869 if (complete_animation_.is_animating()) |
866 complete_animation_.End(); | 870 complete_animation_.End(); |
867 | 871 |
868 if (!menu_.get()) | 872 if (!menu_.get()) |
869 menu_.reset(new DownloadShelfContextMenuGtk(download_model_.get(), this)); | 873 menu_.reset(new DownloadShelfContextMenuGtk(download_model_.get(), this)); |
870 menu_->Popup(button, event); | 874 menu_->Popup(button, event); |
871 } | 875 } |
872 | 876 |
873 gboolean DownloadItemGtk::OnDangerousPromptExpose(GtkWidget* widget, | 877 gboolean DownloadItemGtk::OnDangerousPromptExpose(GtkWidget* widget, |
874 GdkEventExpose* event) { | 878 GdkEventExpose* event) { |
| 879 TRACE_EVENT0("ui::gtk", "DownloadItemGtk::OnDangerousPromptExpose"); |
875 if (!theme_service_->UsingNativeTheme()) { | 880 if (!theme_service_->UsingNativeTheme()) { |
876 // The hbox renderer will take care of the border when in GTK mode. | 881 // The hbox renderer will take care of the border when in GTK mode. |
877 dangerous_nine_box_->RenderToWidget(widget); | 882 dangerous_nine_box_->RenderToWidget(widget); |
878 } | 883 } |
879 return FALSE; // Continue propagation. | 884 return FALSE; // Continue propagation. |
880 } | 885 } |
881 | 886 |
882 void DownloadItemGtk::OnDangerousAccept(GtkWidget* button) { | 887 void DownloadItemGtk::OnDangerousAccept(GtkWidget* button) { |
883 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", | 888 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", |
884 base::Time::Now() - creation_time_); | 889 base::Time::Now() - creation_time_); |
885 get_download()->DangerousDownloadValidated(); | 890 get_download()->DangerousDownloadValidated(); |
886 } | 891 } |
887 | 892 |
888 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { | 893 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { |
889 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", | 894 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", |
890 base::Time::Now() - creation_time_); | 895 base::Time::Now() - creation_time_); |
891 if (get_download()->IsPartialDownload()) | 896 if (get_download()->IsPartialDownload()) |
892 get_download()->Cancel(true); | 897 get_download()->Cancel(true); |
893 get_download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 898 get_download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
894 } | 899 } |
OLD | NEW |