Index: chrome/browser/ui/gtk/website_settings/website_settings_popup_gtk.cc |
diff --git a/chrome/browser/ui/gtk/website_settings_popup_gtk.cc b/chrome/browser/ui/gtk/website_settings/website_settings_popup_gtk.cc |
similarity index 76% |
rename from chrome/browser/ui/gtk/website_settings_popup_gtk.cc |
rename to chrome/browser/ui/gtk/website_settings/website_settings_popup_gtk.cc |
index ab63632c8f11b42e2aa29fd3bf30c851142ee6b3..be7529c234f85fd2498f249a0a4f79274aa03904 100644 |
--- a/chrome/browser/ui/gtk/website_settings_popup_gtk.cc |
+++ b/chrome/browser/ui/gtk/website_settings/website_settings_popup_gtk.cc |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/ui/gtk/website_settings_popup_gtk.h" |
+#include "chrome/browser/ui/gtk/website_settings/website_settings_popup_gtk.h" |
#include "base/i18n/rtl.h" |
#include "base/string_number_conversions.h" |
@@ -17,6 +17,7 @@ |
#include "chrome/browser/ui/gtk/gtk_util.h" |
#include "chrome/browser/ui/gtk/gtk_theme_service.h" |
#include "chrome/browser/ui/gtk/location_bar_view_gtk.h" |
+#include "chrome/browser/ui/gtk/website_settings/permission_selector.h" |
#include "chrome/browser/ui/tab_contents/tab_contents.h" |
#include "chrome/browser/ui/website_settings/website_settings.h" |
#include "chrome/browser/ui/website_settings/website_settings_utils.h" |
@@ -39,6 +40,17 @@ namespace { |
// is selected. |
const GdkColor kBackgroundColor = GDK_COLOR_RGB(0xff, 0xff, 0xff); |
+GtkWidget* CreateTextLabel(const std::string& text, |
+ int width, |
+ GtkThemeService* theme_service) { |
+ GtkWidget* label = theme_service->BuildLabel(text, ui::kGdkBlack); |
+ if (width > 0) |
+ gtk_util::SetLabelWidth(label, width); |
+ gtk_label_set_selectable(GTK_LABEL(label), TRUE); |
+ gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR); |
+ return label; |
+} |
+ |
class InternalPageInfoPopupGtk : public BubbleDelegateGtk { |
public: |
explicit InternalPageInfoPopupGtk(gfx::NativeWindow parent, |
@@ -290,6 +302,16 @@ GtkWidget* WebsiteSettingsPopupGtk::CreateSection(std::string section_title, |
} |
+void WebsiteSettingsPopupGtk::OnPermissionChanged( |
+ PermissionSelector* selector) { |
+ presenter_->OnSitePermissionChanged(selector->type(), |
+ selector->setting()); |
+} |
+ |
+void WebsiteSettingsPopupGtk::OnComboboxShown() { |
+ bubble_->HandlePointerAndKeyboardUngrabbedByContent(); |
+} |
+ |
void WebsiteSettingsPopupGtk::SetCookieInfo( |
const CookieInfoList& cookie_info_list) { |
DCHECK(cookies_section_contents_); |
@@ -299,21 +321,29 @@ void WebsiteSettingsPopupGtk::SetCookieInfo( |
for (CookieInfoList::const_iterator it = cookie_info_list.begin(); |
it != cookie_info_list.end(); |
++it) { |
+ // Create the cookies info box. |
GtkWidget* cookies_info = gtk_hbox_new(FALSE, 0); |
- GtkWidget* label = CreateTextLabel(it->cookie_source, 200); |
- gtk_box_pack_start(GTK_BOX(cookies_info), label, FALSE, FALSE, 0); |
- std::string allowed_count = base::IntToString(it->allowed); |
- std::string blocked_count = base::IntToString(it->blocked); |
- // TODO(markusheintz): Add a localized label here once we decided how this |
- // information should be displayed. |
- std::string info_str = " (" + allowed_count + " allowed / " |
- + blocked_count + " blocked)"; |
+ // Add the icon to the cookies info box |
+ GdkPixbuf* pixbuf = WebsiteSettingsUI::GetPermissionIcon( |
+ CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_ALLOW).ToGdkPixbuf(); |
+ GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); |
+ gtk_misc_set_alignment(GTK_MISC(image), 0, 0); |
+ gtk_box_pack_start(GTK_BOX(cookies_info), image, FALSE, FALSE, 0); |
+ |
+ // Add the allowed and blocked cookies counts to the cookies info box. |
+ std::string info_str = l10n_util::GetStringFUTF8( |
+ IDS_WEBSITE_SETTINGS_SITE_DATA_STATS_LINE, |
+ UTF8ToUTF16(it->cookie_source), |
+ base::IntToString16(it->allowed), |
+ base::IntToString16(it->blocked)); |
GtkWidget* info = theme_service_->BuildLabel(info_str, ui::kGdkBlack); |
gtk_label_set_selectable(GTK_LABEL(info), TRUE); |
- gtk_box_pack_start(GTK_BOX(cookies_info), info, FALSE, FALSE, 0); |
+ const int kPadding = 4; |
+ gtk_box_pack_start(GTK_BOX(cookies_info), info, FALSE, FALSE, kPadding); |
+ // Add the cookies info box to the section box. |
gtk_box_pack_start(GTK_BOX(cookies_section_contents_), |
cookies_info, |
FALSE, FALSE, 0); |
@@ -335,15 +365,6 @@ void WebsiteSettingsPopupGtk::SetCookieInfo( |
gtk_widget_show_all(cookies_section_contents_); |
} |
-GtkWidget* WebsiteSettingsPopupGtk::CreateTextLabel(const std::string& text, |
- int width) { |
- GtkWidget* label = theme_service_->BuildLabel(text, ui::kGdkBlack); |
- gtk_util::SetLabelWidth(label, width); |
- gtk_label_set_selectable(GTK_LABEL(label), TRUE); |
- gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR); |
- return label; |
-} |
- |
void WebsiteSettingsPopupGtk::SetIdentityInfo( |
const IdentityInfo& identity_info) { |
// Create popup header. |
@@ -374,7 +395,8 @@ void WebsiteSettingsPopupGtk::SetIdentityInfo( |
l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_IDENTITY_NOT_VERIFIED); |
break; |
} |
- GtkWidget* status_label = CreateTextLabel(identity_status_text, 400); |
+ GtkWidget* status_label = |
+ CreateTextLabel(identity_status_text, 400, theme_service_); |
gtk_box_pack_start( |
GTK_BOX(header_box_), status_label, FALSE, FALSE, 0); |
gtk_widget_show_all(header_box_); |
@@ -385,7 +407,8 @@ void WebsiteSettingsPopupGtk::SetIdentityInfo( |
// Create identity section. |
GtkWidget* identity_description = |
- CreateTextLabel(identity_info.identity_status_description, 300); |
+ CreateTextLabel(identity_info.identity_status_description, 300, |
+ theme_service_); |
GtkWidget* identity_box = gtk_vbox_new(FALSE, ui::kControlSpacing); |
gtk_box_pack_start(GTK_BOX(identity_box), identity_description, FALSE, FALSE, |
0); |
@@ -401,9 +424,11 @@ void WebsiteSettingsPopupGtk::SetIdentityInfo( |
gtk_box_pack_start(GTK_BOX(identity_box), link_hbox, FALSE, FALSE, 0); |
} |
+ |
// Create connection section. |
GtkWidget* connection_description = |
- CreateTextLabel(identity_info.connection_status_description, 300); |
+ CreateTextLabel(identity_info.connection_status_description, 300, |
+ theme_service_); |
GtkWidget* connection_box = gtk_vbox_new(FALSE, ui::kControlSpacing); |
gtk_box_pack_start(GTK_BOX(connection_box), connection_description, FALSE, |
FALSE, 0); |
@@ -436,7 +461,8 @@ void WebsiteSettingsPopupGtk::SetFirstVisit(const string16& first_visit) { |
DCHECK(first_visit_contents_); |
ClearContainer(first_visit_contents_); |
- GtkWidget* first_visit_label = CreateTextLabel(UTF16ToUTF8(first_visit), 400); |
+ GtkWidget* first_visit_label = CreateTextLabel(UTF16ToUTF8(first_visit), 400, |
+ theme_service_); |
gtk_box_pack_start( |
GTK_BOX(first_visit_contents_), first_visit_label, FALSE, FALSE, 0); |
gtk_widget_show_all(first_visit_contents_); |
@@ -446,91 +472,22 @@ void WebsiteSettingsPopupGtk::SetPermissionInfo( |
const PermissionInfoList& permission_info_list) { |
DCHECK(permissions_section_contents_); |
ClearContainer(permissions_section_contents_); |
+ // Clear the map since the UI is reconstructed. |
+ selectors_.clear(); |
for (PermissionInfoList::const_iterator permission = |
permission_info_list.begin(); |
permission != permission_info_list.end(); |
++permission) { |
- // Add a label for the permission type. |
- GtkWidget* label = CreateTextLabel(UTF16ToUTF8( |
- WebsiteSettingsUI::PermissionTypeToUIString(permission->type)), 250); |
- GtkWidget* hbox = gtk_hbox_new(FALSE, 0); |
- gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); |
- |
- GtkListStore* store = |
- gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT); |
- GtkTreeIter iter; |
- // Add option for permission "Global Default" to the combobox model. |
- std::string setting_str; |
- switch (permission->default_setting) { |
- case CONTENT_SETTING_ALLOW: |
- setting_str = l10n_util::GetStringUTF8( |
- IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_ALLOW); |
- break; |
- case CONTENT_SETTING_BLOCK: |
- setting_str = l10n_util::GetStringUTF8( |
- IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_BLOCK); |
- break; |
- case CONTENT_SETTING_ASK: |
- setting_str = l10n_util::GetStringUTF8( |
- IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_ASK); |
- break; |
- default: |
- break; |
- } |
- gtk_list_store_append(store, &iter); |
- gtk_list_store_set(store, &iter, 0, setting_str.c_str(), 1, |
- CONTENT_SETTING_DEFAULT, 2, permission->type, -1); |
- GtkWidget* combo_box = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)); |
- // Add option for permission "Allow" to the combobox model. |
- setting_str = l10n_util::GetStringUTF8( |
- IDS_WEBSITE_SETTINGS_MENU_ITEM_ALLOW); |
- gtk_list_store_append(store, &iter); |
- gtk_list_store_set(store, &iter, 0, setting_str.c_str(), 1, |
- CONTENT_SETTING_ALLOW, 2, permission->type, -1); |
- // The content settings type fullscreen does not support the concept of |
- // blocking. |
- if (permission->type != CONTENT_SETTINGS_TYPE_FULLSCREEN) { |
- // Add option for permission "BLOCK" to the combobox model. |
- setting_str = l10n_util::GetStringUTF8( |
- IDS_WEBSITE_SETTINGS_MENU_ITEM_BLOCK); |
- gtk_list_store_append(store, &iter); |
- gtk_list_store_set(store, &iter, 0, setting_str.c_str(), 1, |
- CONTENT_SETTING_BLOCK, 2, permission->type, -1); |
- } |
- // Remove reference to the store to prevent leaking. |
- g_object_unref(G_OBJECT(store)); |
- |
- GtkCellRenderer* cell = gtk_cell_renderer_text_new(); |
- gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), cell, TRUE ); |
- gtk_cell_layout_set_attributes( |
- GTK_CELL_LAYOUT(combo_box), cell, "text", 0, NULL); |
- |
- // Select the combobox entry for the currently configured permission value. |
- int active = -1; |
- switch (permission->setting) { |
- case CONTENT_SETTING_DEFAULT: active = 0; |
- break; |
- case CONTENT_SETTING_ALLOW: active = 1; |
- break; |
- case CONTENT_SETTING_BLOCK: active = 2; |
- break; |
- default: |
- NOTREACHED() << "Bad content setting:" << permission->setting; |
- break; |
- } |
- gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), active); |
- |
- // Add change listener to the combobox. |
- g_signal_connect(combo_box, "changed", |
- G_CALLBACK(OnPermissionChangedThunk), this); |
- // Once the popup (window) for a combobox is shown, the bubble container |
- // (window) loses it's focus. Therefore it necessary to reset the focus to |
- // the bubble container after the combobox popup is closed. |
- g_signal_connect(combo_box, "notify::popup-shown", |
- G_CALLBACK(OnComboBoxShownThunk), this); |
- gtk_box_pack_start(GTK_BOX(hbox), combo_box, FALSE, FALSE, 0); |
- |
+ PermissionSelector* selector = |
+ new PermissionSelector( |
+ theme_service_, |
+ permission->type, |
+ permission->setting, |
+ permission->default_setting); |
+ selector->AddObserver(this); |
+ GtkWidget* hbox = selector->CreateUI(); |
+ selectors_.push_back(selector); |
gtk_box_pack_start(GTK_BOX(permissions_section_contents_), hbox, FALSE, |
FALSE, 0); |
} |
@@ -549,19 +506,6 @@ void WebsiteSettingsPopupGtk::SetPermissionInfo( |
gtk_widget_show_all(permissions_section_contents_); |
} |
-void WebsiteSettingsPopupGtk::OnComboBoxShown(GtkWidget* widget, |
- GParamSpec* property) { |
- // GtkComboBox grabs the keyboard and pointer when it displays its popup, |
- // which steals the grabs that BubbleGtk had installed. When the popup is |
- // hidden, we notify BubbleGtk so it can try to reacquire the grabs |
- // (otherwise, GTK won't activate our widgets when the user clicks in them). |
- gboolean popup_shown = FALSE; |
- g_object_get(G_OBJECT(GTK_COMBO_BOX(widget)), "popup-shown", &popup_shown, |
- NULL); |
- if (!popup_shown) |
- bubble_->HandlePointerAndKeyboardUngrabbedByContent(); |
-} |
- |
void WebsiteSettingsPopupGtk::OnCookiesLinkClicked(GtkWidget* widget) { |
new CollectedCookiesGtk(GTK_WINDOW(parent_), |
tab_contents_); |
@@ -580,22 +524,6 @@ void WebsiteSettingsPopupGtk::OnPermissionsSettingsLinkClicked( |
bubble_->Close(); |
} |
-void WebsiteSettingsPopupGtk::OnPermissionChanged(GtkWidget* widget) { |
- GtkTreeIter it; |
- bool has_active = gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &it); |
- DCHECK(has_active); |
- GtkTreeModel* store = |
- GTK_TREE_MODEL(gtk_combo_box_get_model(GTK_COMBO_BOX(widget))); |
- |
- int value = -1; |
- int type = -1; |
- gtk_tree_model_get(store, &it, 1, &value, 2, &type, -1); |
- |
- if (presenter_.get()) |
- presenter_->OnSitePermissionChanged(ContentSettingsType(type), |
- ContentSetting(value)); |
-} |
- |
void WebsiteSettingsPopupGtk::OnViewCertLinkClicked(GtkWidget* widget) { |
DCHECK_NE(cert_id_, 0); |
ShowCertificateViewerByID( |