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