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/content_setting_bubble_gtk.h" | 5 #include "chrome/browser/ui/gtk/content_setting_bubble_gtk.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/content_settings/host_content_settings_map.h" | 13 #include "chrome/browser/content_settings/host_content_settings_map.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 15 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
16 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" | 16 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" |
17 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 17 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
18 #include "chrome/browser/ui/gtk/gtk_util.h" | 18 #include "chrome/browser/ui/gtk/gtk_util.h" |
19 #include "chrome/common/content_settings.h" | 19 #include "chrome/common/content_settings.h" |
20 #include "content/browser/tab_contents/tab_contents.h" | 20 #include "content/browser/tab_contents/tab_contents.h" |
21 #include "content/common/content_notification_types.h" | 21 #include "content/common/content_notification_types.h" |
22 #include "content/common/notification_source.h" | 22 #include "content/common/notification_source.h" |
23 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
24 #include "grit/ui_resources.h" | 24 #include "grit/ui_resources.h" |
25 #include "ui/base/gtk/gtk_hig_constants.h" | |
26 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
27 #include "ui/base/text/text_elider.h" | 26 #include "ui/base/text/text_elider.h" |
28 #include "ui/gfx/gtk_util.h" | 27 #include "ui/gfx/gtk_util.h" |
29 #include "webkit/plugins/npapi/plugin_list.h" | 28 #include "webkit/plugins/npapi/plugin_list.h" |
30 | 29 |
31 namespace { | 30 namespace { |
32 | 31 |
33 // Padding between content and edge of bubble. | 32 // Padding between content and edge of bubble. |
34 const int kContentBorder = 7; | 33 const int kContentBorder = 7; |
35 | 34 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 const NotificationSource& source, | 81 const NotificationSource& source, |
83 const NotificationDetails& details) { | 82 const NotificationDetails& details) { |
84 DCHECK(type == content::NOTIFICATION_TAB_CONTENTS_DESTROYED); | 83 DCHECK(type == content::NOTIFICATION_TAB_CONTENTS_DESTROYED); |
85 DCHECK(source == Source<TabContents>(tab_contents_)); | 84 DCHECK(source == Source<TabContents>(tab_contents_)); |
86 tab_contents_ = NULL; | 85 tab_contents_ = NULL; |
87 } | 86 } |
88 | 87 |
89 void ContentSettingBubbleGtk::BuildBubble() { | 88 void ContentSettingBubbleGtk::BuildBubble() { |
90 GtkThemeService* theme_provider = GtkThemeService::GetFrom(profile_); | 89 GtkThemeService* theme_provider = GtkThemeService::GetFrom(profile_); |
91 | 90 |
92 GtkWidget* bubble_content = gtk_vbox_new(FALSE, ui::kControlSpacing); | 91 GtkWidget* bubble_content = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); |
93 gtk_container_set_border_width(GTK_CONTAINER(bubble_content), kContentBorder); | 92 gtk_container_set_border_width(GTK_CONTAINER(bubble_content), kContentBorder); |
94 | 93 |
95 const ContentSettingBubbleModel::BubbleContent& content = | 94 const ContentSettingBubbleModel::BubbleContent& content = |
96 content_setting_bubble_model_->bubble_content(); | 95 content_setting_bubble_model_->bubble_content(); |
97 if (!content.title.empty()) { | 96 if (!content.title.empty()) { |
98 // Add the content label. | 97 // Add the content label. |
99 GtkWidget* label = gtk_label_new(content.title.c_str()); | 98 GtkWidget* label = gtk_label_new(content.title.c_str()); |
100 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | 99 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); |
101 gtk_box_pack_start(GTK_BOX(bubble_content), label, FALSE, FALSE, 0); | 100 gtk_box_pack_start(GTK_BOX(bubble_content), label, FALSE, FALSE, 0); |
102 } | 101 } |
103 | 102 |
104 const std::set<std::string>& plugins = content.resource_identifiers; | 103 const std::set<std::string>& plugins = content.resource_identifiers; |
105 if (!plugins.empty()) { | 104 if (!plugins.empty()) { |
106 GtkWidget* list_content = gtk_vbox_new(FALSE, ui::kControlSpacing); | 105 GtkWidget* list_content = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); |
107 | 106 |
108 for (std::set<std::string>::const_iterator it = plugins.begin(); | 107 for (std::set<std::string>::const_iterator it = plugins.begin(); |
109 it != plugins.end(); ++it) { | 108 it != plugins.end(); ++it) { |
110 std::string name = UTF16ToUTF8( | 109 std::string name = UTF16ToUTF8( |
111 webkit::npapi::PluginList::Singleton()->GetPluginGroupName(*it)); | 110 webkit::npapi::PluginList::Singleton()->GetPluginGroupName(*it)); |
112 if (name.empty()) | 111 if (name.empty()) |
113 name = *it; | 112 name = *it; |
114 | 113 |
115 GtkWidget* label = gtk_label_new(BuildElidedText(name).c_str()); | 114 GtkWidget* label = gtk_label_new(BuildElidedText(name).c_str()); |
116 GtkWidget* label_box = gtk_hbox_new(FALSE, 0); | 115 GtkWidget* label_box = gtk_hbox_new(FALSE, 0); |
117 gtk_box_pack_start(GTK_BOX(label_box), label, FALSE, FALSE, 0); | 116 gtk_box_pack_start(GTK_BOX(label_box), label, FALSE, FALSE, 0); |
118 | 117 |
119 gtk_box_pack_start(GTK_BOX(list_content), | 118 gtk_box_pack_start(GTK_BOX(list_content), |
120 label_box, | 119 label_box, |
121 FALSE, FALSE, 0); | 120 FALSE, FALSE, 0); |
122 } | 121 } |
123 gtk_box_pack_start(GTK_BOX(bubble_content), list_content, FALSE, FALSE, | 122 gtk_box_pack_start(GTK_BOX(bubble_content), list_content, FALSE, FALSE, |
124 ui::kControlSpacing); | 123 gtk_util::kControlSpacing); |
125 } | 124 } |
126 | 125 |
127 if (content_setting_bubble_model_->content_type() == | 126 if (content_setting_bubble_model_->content_type() == |
128 CONTENT_SETTINGS_TYPE_POPUPS) { | 127 CONTENT_SETTINGS_TYPE_POPUPS) { |
129 const std::vector<ContentSettingBubbleModel::PopupItem>& popup_items = | 128 const std::vector<ContentSettingBubbleModel::PopupItem>& popup_items = |
130 content.popup_items; | 129 content.popup_items; |
131 GtkWidget* table = gtk_table_new(popup_items.size(), 2, FALSE); | 130 GtkWidget* table = gtk_table_new(popup_items.size(), 2, FALSE); |
132 int row = 0; | 131 int row = 0; |
133 for (std::vector<ContentSettingBubbleModel::PopupItem>::const_iterator | 132 for (std::vector<ContentSettingBubbleModel::PopupItem>::const_iterator |
134 i(popup_items.begin()); i != popup_items.end(); ++i, ++row) { | 133 i(popup_items.begin()); i != popup_items.end(); ++i, ++row) { |
135 GtkWidget* image = gtk_image_new(); | 134 GtkWidget* image = gtk_image_new(); |
136 if (!i->bitmap.empty()) { | 135 if (!i->bitmap.empty()) { |
137 GdkPixbuf* icon_pixbuf = gfx::GdkPixbufFromSkBitmap(&i->bitmap); | 136 GdkPixbuf* icon_pixbuf = gfx::GdkPixbufFromSkBitmap(&i->bitmap); |
138 gtk_image_set_from_pixbuf(GTK_IMAGE(image), icon_pixbuf); | 137 gtk_image_set_from_pixbuf(GTK_IMAGE(image), icon_pixbuf); |
139 g_object_unref(icon_pixbuf); | 138 g_object_unref(icon_pixbuf); |
140 | 139 |
141 // We stuff the image in an event box so we can trap mouse clicks on the | 140 // We stuff the image in an event box so we can trap mouse clicks on the |
142 // image (and launch the popup). | 141 // image (and launch the popup). |
143 GtkWidget* event_box = gtk_event_box_new(); | 142 GtkWidget* event_box = gtk_event_box_new(); |
144 gtk_container_add(GTK_CONTAINER(event_box), image); | 143 gtk_container_add(GTK_CONTAINER(event_box), image); |
145 | 144 |
146 popup_icons_[event_box] = i -popup_items.begin(); | 145 popup_icons_[event_box] = i -popup_items.begin(); |
147 g_signal_connect(event_box, "button_press_event", | 146 g_signal_connect(event_box, "button_press_event", |
148 G_CALLBACK(OnPopupIconButtonPressThunk), this); | 147 G_CALLBACK(OnPopupIconButtonPressThunk), this); |
149 gtk_table_attach(GTK_TABLE(table), event_box, 0, 1, row, row + 1, | 148 gtk_table_attach(GTK_TABLE(table), event_box, 0, 1, row, row + 1, |
150 GTK_FILL, GTK_FILL, ui::kControlSpacing / 2, | 149 GTK_FILL, GTK_FILL, gtk_util::kControlSpacing / 2, |
151 ui::kControlSpacing / 2); | 150 gtk_util::kControlSpacing / 2); |
152 } | 151 } |
153 | 152 |
154 GtkWidget* button = gtk_chrome_link_button_new( | 153 GtkWidget* button = gtk_chrome_link_button_new( |
155 BuildElidedText(i->title).c_str()); | 154 BuildElidedText(i->title).c_str()); |
156 popup_links_[button] = i -popup_items.begin(); | 155 popup_links_[button] = i -popup_items.begin(); |
157 g_signal_connect(button, "clicked", G_CALLBACK(OnPopupLinkClickedThunk), | 156 g_signal_connect(button, "clicked", G_CALLBACK(OnPopupLinkClickedThunk), |
158 this); | 157 this); |
159 gtk_table_attach(GTK_TABLE(table), button, 1, 2, row, row + 1, | 158 gtk_table_attach(GTK_TABLE(table), button, 1, 2, row, row + 1, |
160 GTK_FILL, GTK_FILL, ui::kControlSpacing / 2, | 159 GTK_FILL, GTK_FILL, gtk_util::kControlSpacing / 2, |
161 ui::kControlSpacing / 2); | 160 gtk_util::kControlSpacing / 2); |
162 } | 161 } |
163 | 162 |
164 gtk_box_pack_start(GTK_BOX(bubble_content), table, FALSE, FALSE, 0); | 163 gtk_box_pack_start(GTK_BOX(bubble_content), table, FALSE, FALSE, 0); |
165 } | 164 } |
166 | 165 |
167 const ContentSettingBubbleModel::RadioGroup& radio_group = | 166 const ContentSettingBubbleModel::RadioGroup& radio_group = |
168 content.radio_group; | 167 content.radio_group; |
169 for (ContentSettingBubbleModel::RadioItems::const_iterator i = | 168 for (ContentSettingBubbleModel::RadioItems::const_iterator i = |
170 radio_group.radio_items.begin(); | 169 radio_group.radio_items.begin(); |
171 i != radio_group.radio_items.end(); ++i) { | 170 i != radio_group.radio_items.end(); ++i) { |
(...skipping 15 matching lines...) Expand all Loading... |
187 for (std::vector<GtkWidget*>::const_iterator i = radio_group_gtk_.begin(); | 186 for (std::vector<GtkWidget*>::const_iterator i = radio_group_gtk_.begin(); |
188 i != radio_group_gtk_.end(); ++i) { | 187 i != radio_group_gtk_.end(); ++i) { |
189 // We can attach signal handlers now that all defaults are set. | 188 // We can attach signal handlers now that all defaults are set. |
190 g_signal_connect(*i, "toggled", G_CALLBACK(OnRadioToggledThunk), this); | 189 g_signal_connect(*i, "toggled", G_CALLBACK(OnRadioToggledThunk), this); |
191 } | 190 } |
192 | 191 |
193 for (std::vector<ContentSettingBubbleModel::DomainList>::const_iterator i = | 192 for (std::vector<ContentSettingBubbleModel::DomainList>::const_iterator i = |
194 content.domain_lists.begin(); | 193 content.domain_lists.begin(); |
195 i != content.domain_lists.end(); ++i) { | 194 i != content.domain_lists.end(); ++i) { |
196 // Put each list into its own vbox to allow spacing between lists. | 195 // Put each list into its own vbox to allow spacing between lists. |
197 GtkWidget* list_content = gtk_vbox_new(FALSE, ui::kControlSpacing); | 196 GtkWidget* list_content = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); |
198 | 197 |
199 GtkWidget* label = gtk_label_new(BuildElidedText(i->title).c_str()); | 198 GtkWidget* label = gtk_label_new(BuildElidedText(i->title).c_str()); |
200 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | 199 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); |
201 GtkWidget* label_box = gtk_hbox_new(FALSE, 0); | 200 GtkWidget* label_box = gtk_hbox_new(FALSE, 0); |
202 gtk_box_pack_start(GTK_BOX(label_box), label, FALSE, FALSE, 0); | 201 gtk_box_pack_start(GTK_BOX(label_box), label, FALSE, FALSE, 0); |
203 gtk_box_pack_start(GTK_BOX(list_content), label_box, FALSE, FALSE, 0); | 202 gtk_box_pack_start(GTK_BOX(list_content), label_box, FALSE, FALSE, 0); |
204 for (std::set<std::string>::const_iterator j = i->hosts.begin(); | 203 for (std::set<std::string>::const_iterator j = i->hosts.begin(); |
205 j != i->hosts.end(); ++j) { | 204 j != i->hosts.end(); ++j) { |
206 gtk_box_pack_start(GTK_BOX(list_content), | 205 gtk_box_pack_start(GTK_BOX(list_content), |
207 gtk_util::IndentWidget(gtk_util::CreateBoldLabel(*j)), | 206 gtk_util::IndentWidget(gtk_util::CreateBoldLabel(*j)), |
208 FALSE, FALSE, 0); | 207 FALSE, FALSE, 0); |
209 } | 208 } |
210 gtk_box_pack_start(GTK_BOX(bubble_content), list_content, FALSE, FALSE, | 209 gtk_box_pack_start(GTK_BOX(bubble_content), list_content, FALSE, FALSE, |
211 ui::kControlSpacing); | 210 gtk_util::kControlSpacing); |
212 } | 211 } |
213 | 212 |
214 if (!content.custom_link.empty()) { | 213 if (!content.custom_link.empty()) { |
215 GtkWidget* custom_link_box = gtk_hbox_new(FALSE, 0); | 214 GtkWidget* custom_link_box = gtk_hbox_new(FALSE, 0); |
216 GtkWidget* custom_link = NULL; | 215 GtkWidget* custom_link = NULL; |
217 if (content.custom_link_enabled) { | 216 if (content.custom_link_enabled) { |
218 custom_link = gtk_chrome_link_button_new(content.custom_link.c_str()); | 217 custom_link = gtk_chrome_link_button_new(content.custom_link.c_str()); |
219 g_signal_connect(custom_link, "clicked", | 218 g_signal_connect(custom_link, "clicked", |
220 G_CALLBACK(OnCustomLinkClickedThunk), this); | 219 G_CALLBACK(OnCustomLinkClickedThunk), this); |
221 } else { | 220 } else { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 | 301 |
303 void ContentSettingBubbleGtk::OnCustomLinkClicked(GtkWidget* button) { | 302 void ContentSettingBubbleGtk::OnCustomLinkClicked(GtkWidget* button) { |
304 content_setting_bubble_model_->OnCustomLinkClicked(); | 303 content_setting_bubble_model_->OnCustomLinkClicked(); |
305 Close(); | 304 Close(); |
306 } | 305 } |
307 | 306 |
308 void ContentSettingBubbleGtk::OnManageLinkClicked(GtkWidget* button) { | 307 void ContentSettingBubbleGtk::OnManageLinkClicked(GtkWidget* button) { |
309 content_setting_bubble_model_->OnManageLinkClicked(); | 308 content_setting_bubble_model_->OnManageLinkClicked(); |
310 Close(); | 309 Close(); |
311 } | 310 } |
OLD | NEW |