| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 body_.Own(gtk_button_new()); | 109 body_.Own(gtk_button_new()); |
| 110 gtk_widget_set_app_paintable(body_.get(), TRUE); | 110 gtk_widget_set_app_paintable(body_.get(), TRUE); |
| 111 UpdateTooltip(); | 111 UpdateTooltip(); |
| 112 | 112 |
| 113 g_signal_connect(body_.get(), "expose-event", | 113 g_signal_connect(body_.get(), "expose-event", |
| 114 G_CALLBACK(OnExposeThunk), this); | 114 G_CALLBACK(OnExposeThunk), this); |
| 115 g_signal_connect(body_.get(), "clicked", | 115 g_signal_connect(body_.get(), "clicked", |
| 116 G_CALLBACK(OnClickThunk), this); | 116 G_CALLBACK(OnClickThunk), this); |
| 117 g_signal_connect(body_.get(), "button-press-event", | 117 g_signal_connect(body_.get(), "button-press-event", |
| 118 G_CALLBACK(OnButtonPressThunk), this); | 118 G_CALLBACK(OnButtonPressThunk), this); |
| 119 GTK_WIDGET_UNSET_FLAGS(body_.get(), GTK_CAN_FOCUS); | 119 gtk_widget_set_can_focus(body_.get(), FALSE); |
| 120 // Remove internal padding on the button. | 120 // Remove internal padding on the button. |
| 121 GtkRcStyle* no_padding_style = gtk_rc_style_new(); | 121 GtkRcStyle* no_padding_style = gtk_rc_style_new(); |
| 122 no_padding_style->xthickness = 0; | 122 no_padding_style->xthickness = 0; |
| 123 no_padding_style->ythickness = 0; | 123 no_padding_style->ythickness = 0; |
| 124 gtk_widget_modify_style(body_.get(), no_padding_style); | 124 gtk_widget_modify_style(body_.get(), no_padding_style); |
| 125 g_object_unref(no_padding_style); | 125 g_object_unref(no_padding_style); |
| 126 | 126 |
| 127 name_label_ = gtk_label_new(NULL); | 127 name_label_ = gtk_label_new(NULL); |
| 128 // Left align and vertically center the labels. | 128 // Left align and vertically center the labels. |
| 129 gtk_misc_set_alignment(GTK_MISC(name_label_), 0, 0.5); | 129 gtk_misc_set_alignment(GTK_MISC(name_label_), 0, 0.5); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 149 G_CALLBACK(OnProgressAreaExposeThunk), this); | 149 G_CALLBACK(OnProgressAreaExposeThunk), this); |
| 150 | 150 |
| 151 // Put the download progress icon on the left of the labels. | 151 // Put the download progress icon on the left of the labels. |
| 152 GtkWidget* body_hbox = gtk_hbox_new(FALSE, 0); | 152 GtkWidget* body_hbox = gtk_hbox_new(FALSE, 0); |
| 153 gtk_container_add(GTK_CONTAINER(body_.get()), body_hbox); | 153 gtk_container_add(GTK_CONTAINER(body_.get()), body_hbox); |
| 154 gtk_box_pack_start(GTK_BOX(body_hbox), progress_area_.get(), FALSE, FALSE, 0); | 154 gtk_box_pack_start(GTK_BOX(body_hbox), progress_area_.get(), FALSE, FALSE, 0); |
| 155 gtk_box_pack_start(GTK_BOX(body_hbox), text_stack_, TRUE, TRUE, 0); | 155 gtk_box_pack_start(GTK_BOX(body_hbox), text_stack_, TRUE, TRUE, 0); |
| 156 | 156 |
| 157 menu_button_ = gtk_button_new(); | 157 menu_button_ = gtk_button_new(); |
| 158 gtk_widget_set_app_paintable(menu_button_, TRUE); | 158 gtk_widget_set_app_paintable(menu_button_, TRUE); |
| 159 GTK_WIDGET_UNSET_FLAGS(menu_button_, GTK_CAN_FOCUS); | 159 gtk_widget_set_can_focus(menu_button_, FALSE); |
| 160 g_signal_connect(menu_button_, "expose-event", | 160 g_signal_connect(menu_button_, "expose-event", |
| 161 G_CALLBACK(OnExposeThunk), this); | 161 G_CALLBACK(OnExposeThunk), this); |
| 162 g_signal_connect(menu_button_, "button-press-event", | 162 g_signal_connect(menu_button_, "button-press-event", |
| 163 G_CALLBACK(OnMenuButtonPressEventThunk), this); | 163 G_CALLBACK(OnMenuButtonPressEventThunk), this); |
| 164 g_object_set_data(G_OBJECT(menu_button_), "left-align-popup", | 164 g_object_set_data(G_OBJECT(menu_button_), "left-align-popup", |
| 165 reinterpret_cast<void*>(true)); | 165 reinterpret_cast<void*>(true)); |
| 166 | 166 |
| 167 GtkWidget* shelf_hbox = parent_shelf->GetHBox(); | 167 GtkWidget* shelf_hbox = parent_shelf->GetHBox(); |
| 168 hbox_.Own(gtk_hbox_new(FALSE, 0)); | 168 hbox_.Own(gtk_hbox_new(FALSE, 0)); |
| 169 g_signal_connect(hbox_.get(), "expose-event", | 169 g_signal_connect(hbox_.get(), "expose-event", |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 | 709 |
| 710 GtkAllocation right_allocation = menu_button_->allocation; | 710 GtkAllocation right_allocation = menu_button_->allocation; |
| 711 GdkRectangle right_clip = { | 711 GdkRectangle right_clip = { |
| 712 right_allocation.x, right_allocation.y, | 712 right_allocation.x, right_allocation.y, |
| 713 right_allocation.width, right_allocation.height | 713 right_allocation.width, right_allocation.height |
| 714 }; | 714 }; |
| 715 | 715 |
| 716 GtkShadowType body_shadow = | 716 GtkShadowType body_shadow = |
| 717 GTK_BUTTON(body_.get())->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT; | 717 GTK_BUTTON(body_.get())->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT; |
| 718 gtk_paint_box(style, widget->window, | 718 gtk_paint_box(style, widget->window, |
| 719 static_cast<GtkStateType>(GTK_WIDGET_STATE(body_.get())), | 719 gtk_widget_get_state(body_.get()), |
| 720 body_shadow, | 720 body_shadow, |
| 721 &left_clip, widget, "button", | 721 &left_clip, widget, "button", |
| 722 x, y, width, height); | 722 x, y, width, height); |
| 723 | 723 |
| 724 GtkShadowType menu_shadow = | 724 GtkShadowType menu_shadow = |
| 725 GTK_BUTTON(menu_button_)->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT; | 725 GTK_BUTTON(menu_button_)->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT; |
| 726 gtk_paint_box(style, widget->window, | 726 gtk_paint_box(style, widget->window, |
| 727 static_cast<GtkStateType>(GTK_WIDGET_STATE(menu_button_)), | 727 gtk_widget_get_state(menu_button_), |
| 728 menu_shadow, | 728 menu_shadow, |
| 729 &right_clip, widget, "button", | 729 &right_clip, widget, "button", |
| 730 x, y, width, height); | 730 x, y, width, height); |
| 731 | 731 |
| 732 // Doing the math to reverse engineer where we should be drawing our line | 732 // Doing the math to reverse engineer where we should be drawing our line |
| 733 // is hard and relies on copying GTK internals, so instead steal the | 733 // is hard and relies on copying GTK internals, so instead steal the |
| 734 // allocation of the gtk arrow which is close enough (and will error on | 734 // allocation of the gtk arrow which is close enough (and will error on |
| 735 // the conservative side). | 735 // the conservative side). |
| 736 GtkAllocation arrow_allocation = arrow_->allocation; | 736 GtkAllocation arrow_allocation = arrow_->allocation; |
| 737 gtk_paint_vline(style, widget->window, | 737 gtk_paint_vline(style, widget->window, |
| 738 static_cast<GtkStateType>(GTK_WIDGET_STATE(widget)), | 738 gtk_widget_get_state(widget), |
| 739 &e->area, widget, "button", | 739 &e->area, widget, "button", |
| 740 arrow_allocation.y, | 740 arrow_allocation.y, |
| 741 arrow_allocation.y + arrow_allocation.height, | 741 arrow_allocation.y + arrow_allocation.height, |
| 742 left_allocation.x + left_allocation.width); | 742 left_allocation.x + left_allocation.width); |
| 743 } | 743 } |
| 744 } | 744 } |
| 745 return FALSE; | 745 return FALSE; |
| 746 } | 746 } |
| 747 | 747 |
| 748 gboolean DownloadItemGtk::OnExpose(GtkWidget* widget, GdkEventExpose* e) { | 748 gboolean DownloadItemGtk::OnExpose(GtkWidget* widget, GdkEventExpose* e) { |
| 749 if (!theme_service_->UsingNativeTheme()) { | 749 if (!theme_service_->UsingNativeTheme()) { |
| 750 bool is_body = widget == body_.get(); | 750 bool is_body = widget == body_.get(); |
| 751 | 751 |
| 752 NineBox* nine_box = NULL; | 752 NineBox* nine_box = NULL; |
| 753 // If true, this widget is |body_|, otherwise it is |menu_button_|. | 753 // If true, this widget is |body_|, otherwise it is |menu_button_|. |
| 754 if (GTK_WIDGET_STATE(widget) == GTK_STATE_PRELIGHT) | 754 if (gtk_widget_get_state(widget) == GTK_STATE_PRELIGHT) |
| 755 nine_box = is_body ? body_nine_box_prelight_ : menu_nine_box_prelight_; | 755 nine_box = is_body ? body_nine_box_prelight_ : menu_nine_box_prelight_; |
| 756 else if (GTK_WIDGET_STATE(widget) == GTK_STATE_ACTIVE) | 756 else if (gtk_widget_get_state(widget) == GTK_STATE_ACTIVE) |
| 757 nine_box = is_body ? body_nine_box_active_ : menu_nine_box_active_; | 757 nine_box = is_body ? body_nine_box_active_ : menu_nine_box_active_; |
| 758 else | 758 else |
| 759 nine_box = is_body ? body_nine_box_normal_ : menu_nine_box_normal_; | 759 nine_box = is_body ? body_nine_box_normal_ : menu_nine_box_normal_; |
| 760 | 760 |
| 761 // When the button is showing, we want to draw it as active. We have to do | 761 // When the button is showing, we want to draw it as active. We have to do |
| 762 // this explicitly because the button's state will be NORMAL while the menu | 762 // this explicitly because the button's state will be NORMAL while the menu |
| 763 // has focus. | 763 // has focus. |
| 764 if (!is_body && menu_showing_) | 764 if (!is_body && menu_showing_) |
| 765 nine_box = menu_nine_box_active_; | 765 nine_box = menu_nine_box_active_; |
| 766 | 766 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 get_download()->DangerousDownloadValidated(); | 863 get_download()->DangerousDownloadValidated(); |
| 864 } | 864 } |
| 865 | 865 |
| 866 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { | 866 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { |
| 867 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", | 867 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", |
| 868 base::Time::Now() - creation_time_); | 868 base::Time::Now() - creation_time_); |
| 869 if (get_download()->IsPartialDownload()) | 869 if (get_download()->IsPartialDownload()) |
| 870 get_download()->Cancel(true); | 870 get_download()->Cancel(true); |
| 871 get_download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 871 get_download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
| 872 } | 872 } |
| OLD | NEW |