Chromium Code Reviews| 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 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 693 IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE, | 693 IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE, |
| 694 IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE, | 694 IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE, |
| 695 IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE_NO_DD, | 695 IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE_NO_DD, |
| 696 IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM, | 696 IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM, |
| 697 IDR_DOWNLOAD_BUTTON_CENTER_BOTTOM, | 697 IDR_DOWNLOAD_BUTTON_CENTER_BOTTOM, |
| 698 IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM_NO_DD); | 698 IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM_NO_DD); |
| 699 } | 699 } |
| 700 | 700 |
| 701 gboolean DownloadItemGtk::OnHboxExpose(GtkWidget* widget, GdkEventExpose* e) { | 701 gboolean DownloadItemGtk::OnHboxExpose(GtkWidget* widget, GdkEventExpose* e) { |
| 702 if (theme_service_->UsingNativeTheme()) { | 702 if (theme_service_->UsingNativeTheme()) { |
| 703 int border_width = GTK_CONTAINER(widget)->border_width; | 703 GtkAllocation allocation; |
| 704 int x = widget->allocation.x + border_width; | 704 gtk_widget_get_allocation(widget, &allocation); |
| 705 int y = widget->allocation.y + border_width; | 705 int border_width = gtk_container_get_border_width(GTK_CONTAINER(widget)); |
| 706 int width = widget->allocation.width - border_width * 2; | 706 int x = allocation.x + border_width; |
| 707 int height = widget->allocation.height - border_width * 2; | 707 int y = allocation.y + border_width; |
| 708 int width = allocation.width - border_width * 2; | |
| 709 int height = 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, |
| 712 static_cast<GtkStateType>(widget->state), | 714 static_cast<GtkStateType>(widget->state), |
| 713 static_cast<GtkShadowType>(GTK_SHADOW_OUT), | 715 static_cast<GtkShadowType>(GTK_SHADOW_OUT), |
| 714 &e->area, widget, "frame", | 716 &e->area, widget, "frame", |
| 715 x, y, width, height); | 717 x, y, width, height); |
| 716 } else { | 718 } else { |
| 717 // Manually draw the GTK button border around the download item. We draw | 719 // Manually draw the GTK button border around the download item. We draw |
| 718 // the left part of the button (the file), a divider, and then the right | 720 // the left part of the button (the file), a divider, and then the right |
| 719 // part of the button (the menu). We can't draw a button on top of each | 721 // part of the button (the menu). We can't draw a button on top of each |
| 720 // other (*cough*Clearlooks*cough*) so instead, to draw the left part of | 722 // other (*cough*Clearlooks*cough*) so instead, to draw the left part of |
| 721 // the button, we instruct GTK to draw the entire button...with a | 723 // the button, we instruct GTK to draw the entire button...with a |
| 722 // doctored clip rectangle to the left part of the button sans | 724 // doctored clip rectangle to the left part of the button sans |
| 723 // separator. We then repeat this for the right button. | 725 // separator. We then repeat this for the right button. |
| 724 GtkStyle* style = body_.get()->style; | 726 GtkStyle* style = body_.get()->style; |
| 725 | 727 |
| 726 GtkAllocation left_allocation = body_.get()->allocation; | 728 GtkAllocation left_clip; |
| 727 GdkRectangle left_clip = { | 729 gtk_widget_get_allocation(body_.get(), &left_clip); |
| 728 left_allocation.x, left_allocation.y, | |
| 729 left_allocation.width, left_allocation.height | |
| 730 }; | |
| 731 | 730 |
| 732 GtkAllocation right_allocation = menu_button_->allocation; | 731 GtkAllocation right_clip; |
| 733 GdkRectangle right_clip = { | 732 gtk_widget_get_allocation(menu_button_, &right_clip); |
| 734 right_allocation.x, right_allocation.y, | |
| 735 right_allocation.width, right_allocation.height | |
| 736 }; | |
| 737 | 733 |
| 738 GtkShadowType body_shadow = | 734 GtkShadowType body_shadow = |
| 739 GTK_BUTTON(body_.get())->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT; | 735 GTK_BUTTON(body_.get())->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT; |
| 740 gtk_paint_box(style, widget->window, | 736 gtk_paint_box(style, widget->window, |
| 741 gtk_widget_get_state(body_.get()), | 737 gtk_widget_get_state(body_.get()), |
| 742 body_shadow, | 738 body_shadow, |
| 743 &left_clip, widget, "button", | 739 &left_clip, widget, "button", |
|
Lei Zhang
2011/12/08 20:50:30
Is it ok to pass in a GtkAllocation instead of a G
Elliot Glaysher
2011/12/08 20:56:41
they are typedefs
| |
| 744 x, y, width, height); | 740 x, y, width, height); |
| 745 | 741 |
| 746 GtkShadowType menu_shadow = | 742 GtkShadowType menu_shadow = |
| 747 GTK_BUTTON(menu_button_)->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT; | 743 GTK_BUTTON(menu_button_)->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT; |
| 748 gtk_paint_box(style, widget->window, | 744 gtk_paint_box(style, widget->window, |
| 749 gtk_widget_get_state(menu_button_), | 745 gtk_widget_get_state(menu_button_), |
| 750 menu_shadow, | 746 menu_shadow, |
| 751 &right_clip, widget, "button", | 747 &right_clip, widget, "button", |
| 752 x, y, width, height); | 748 x, y, width, height); |
| 753 | 749 |
| 754 // Doing the math to reverse engineer where we should be drawing our line | 750 // Doing the math to reverse engineer where we should be drawing our line |
| 755 // is hard and relies on copying GTK internals, so instead steal the | 751 // is hard and relies on copying GTK internals, so instead steal the |
| 756 // allocation of the gtk arrow which is close enough (and will error on | 752 // allocation of the gtk arrow which is close enough (and will error on |
| 757 // the conservative side). | 753 // the conservative side). |
| 758 GtkAllocation arrow_allocation = arrow_->allocation; | 754 GtkAllocation arrow_allocation; |
| 755 gtk_widget_get_allocation(arrow_, &arrow_allocation); | |
| 759 gtk_paint_vline(style, widget->window, | 756 gtk_paint_vline(style, widget->window, |
| 760 gtk_widget_get_state(widget), | 757 gtk_widget_get_state(widget), |
| 761 &e->area, widget, "button", | 758 &e->area, widget, "button", |
| 762 arrow_allocation.y, | 759 arrow_allocation.y, |
| 763 arrow_allocation.y + arrow_allocation.height, | 760 arrow_allocation.y + arrow_allocation.height, |
| 764 left_allocation.x + left_allocation.width); | 761 left_clip.x + left_clip.width); |
| 765 } | 762 } |
| 766 } | 763 } |
| 767 return FALSE; | 764 return FALSE; |
| 768 } | 765 } |
| 769 | 766 |
| 770 gboolean DownloadItemGtk::OnExpose(GtkWidget* widget, GdkEventExpose* e) { | 767 gboolean DownloadItemGtk::OnExpose(GtkWidget* widget, GdkEventExpose* e) { |
| 771 if (!theme_service_->UsingNativeTheme()) { | 768 if (!theme_service_->UsingNativeTheme()) { |
| 772 bool is_body = widget == body_.get(); | 769 bool is_body = widget == body_.get(); |
| 773 | 770 |
| 774 NineBox* nine_box = NULL; | 771 NineBox* nine_box = NULL; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 807 GdkEventButton* event) { | 804 GdkEventButton* event) { |
| 808 if (event->type == GDK_BUTTON_PRESS && event->button == 3) { | 805 if (event->type == GDK_BUTTON_PRESS && event->button == 3) { |
| 809 ShowPopupMenu(NULL, event); | 806 ShowPopupMenu(NULL, event); |
| 810 return TRUE; | 807 return TRUE; |
| 811 } | 808 } |
| 812 return FALSE; | 809 return FALSE; |
| 813 } | 810 } |
| 814 | 811 |
| 815 gboolean DownloadItemGtk::OnProgressAreaExpose(GtkWidget* widget, | 812 gboolean DownloadItemGtk::OnProgressAreaExpose(GtkWidget* widget, |
| 816 GdkEventExpose* event) { | 813 GdkEventExpose* event) { |
| 814 GtkAllocation allocation; | |
| 815 gtk_widget_get_allocation(widget, &allocation); | |
| 816 | |
| 817 // Create a transparent canvas. | 817 // Create a transparent canvas. |
| 818 gfx::CanvasSkiaPaint canvas(event, false); | 818 gfx::CanvasSkiaPaint canvas(event, false); |
| 819 if (complete_animation_.is_animating()) { | 819 if (complete_animation_.is_animating()) { |
| 820 if (get_download()->IsInterrupted()) { | 820 if (get_download()->IsInterrupted()) { |
| 821 download_util::PaintDownloadInterrupted(&canvas, | 821 download_util::PaintDownloadInterrupted(&canvas, |
| 822 widget->allocation.x, widget->allocation.y, | 822 allocation.x, allocation.y, |
| 823 complete_animation_.GetCurrentValue(), | 823 complete_animation_.GetCurrentValue(), |
| 824 download_util::SMALL); | 824 download_util::SMALL); |
| 825 } else { | 825 } else { |
| 826 download_util::PaintDownloadComplete(&canvas, | 826 download_util::PaintDownloadComplete(&canvas, |
| 827 widget->allocation.x, widget->allocation.y, | 827 allocation.x, allocation.y, |
| 828 complete_animation_.GetCurrentValue(), | 828 complete_animation_.GetCurrentValue(), |
| 829 download_util::SMALL); | 829 download_util::SMALL); |
| 830 } | 830 } |
| 831 } else if (get_download()->IsInProgress()) { | 831 } else if (get_download()->IsInProgress()) { |
| 832 download_util::PaintDownloadProgress(&canvas, | 832 download_util::PaintDownloadProgress(&canvas, |
| 833 widget->allocation.x, widget->allocation.y, | 833 allocation.x, allocation.y, |
| 834 progress_angle_, | 834 progress_angle_, |
| 835 get_download()->PercentComplete(), | 835 get_download()->PercentComplete(), |
| 836 download_util::SMALL); | 836 download_util::SMALL); |
| 837 } | 837 } |
| 838 | 838 |
| 839 // |icon_small_| may be NULL if it is still loading. If the file is an | 839 // |icon_small_| may be NULL if it is still loading. If the file is an |
| 840 // unrecognized type then we will get back a generic system icon. Hence | 840 // unrecognized type then we will get back a generic system icon. Hence |
| 841 // there is no need to use the chromium-specific default download item icon. | 841 // there is no need to use the chromium-specific default download item icon. |
| 842 if (icon_small_) { | 842 if (icon_small_) { |
| 843 const int offset = download_util::kSmallProgressIconOffset; | 843 const int offset = download_util::kSmallProgressIconOffset; |
| 844 canvas.DrawBitmapInt(*icon_small_, | 844 canvas.DrawBitmapInt(*icon_small_, |
| 845 widget->allocation.x + offset, widget->allocation.y + offset); | 845 allocation.x + offset, allocation.y + offset); |
| 846 } | 846 } |
| 847 | 847 |
| 848 return TRUE; | 848 return TRUE; |
| 849 } | 849 } |
| 850 | 850 |
| 851 gboolean DownloadItemGtk::OnMenuButtonPressEvent(GtkWidget* button, | 851 gboolean DownloadItemGtk::OnMenuButtonPressEvent(GtkWidget* button, |
| 852 GdkEventButton* event) { | 852 GdkEventButton* event) { |
| 853 if (event->type == GDK_BUTTON_PRESS && event->button == 1) { | 853 if (event->type == GDK_BUTTON_PRESS && event->button == 1) { |
| 854 ShowPopupMenu(button, event); | 854 ShowPopupMenu(button, event); |
| 855 menu_showing_ = true; | 855 menu_showing_ = true; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 885 get_download()->DangerousDownloadValidated(); | 885 get_download()->DangerousDownloadValidated(); |
| 886 } | 886 } |
| 887 | 887 |
| 888 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { | 888 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { |
| 889 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", | 889 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", |
| 890 base::Time::Now() - creation_time_); | 890 base::Time::Now() - creation_time_); |
| 891 if (get_download()->IsPartialDownload()) | 891 if (get_download()->IsPartialDownload()) |
| 892 get_download()->Cancel(true); | 892 get_download()->Cancel(true); |
| 893 get_download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 893 get_download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
| 894 } | 894 } |
| OLD | NEW |