(GTK only) Add icons to the "Permissions" tab of the Website Settings UI.


BUG=140450
TBR=ben@chromium.org


Review URL: https://chromiumcodereview.appspot.com/10827374

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152220 0039d316-1c4b-4281-b951-d872f2087c98
parent d031a26f
......@@ -73,7 +73,7 @@
#include "chrome/browser/ui/gtk/tabs/tab_strip_gtk.h"
#include "chrome/browser/ui/gtk/task_manager_gtk.h"
#include "chrome/browser/ui/gtk/update_recommended_dialog.h"
#include "chrome/browser/ui/gtk/website_settings_popup_gtk.h"
#include "chrome/browser/ui/gtk/website_settings/website_settings_popup_gtk.h"
#include "chrome/browser/ui/omnibox/location_bar.h"
#include "chrome/browser/ui/omnibox/omnibox_view.h"
#include "chrome/browser/ui/page_info_bubble.h"
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// 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/permission_selector.h"
#include <gtk/gtk.h>
#include "base/compiler_specific.h"
#include "chrome/browser/ui/gtk/gtk_theme_service.h"
#include "chrome/browser/ui/gtk/gtk_util.h"
#include "chrome/browser/ui/website_settings/website_settings_ui.h"
#include "grit/generated_resources.h"
#include "ui/base/gtk/gtk_hig_constants.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/image/image.h"
namespace {
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;
}
} // namespace
PermissionSelector::PermissionSelector(GtkThemeService* theme_service,
ContentSettingsType type,
ContentSetting setting,
ContentSetting default_setting)
: theme_service_(theme_service),
type_(type),
setting_(setting),
default_setting_(default_setting),
icon_(NULL) {
DCHECK_NE(default_setting, CONTENT_SETTING_DEFAULT);
}
PermissionSelector::~PermissionSelector() {
}
GtkWidget* PermissionSelector::CreateUI() {
// Create permission info box.
const int kChildSpacing = 4;
GtkWidget* hbox = gtk_hbox_new(FALSE, kChildSpacing);
// Add permission type icon.
GdkPixbuf* pixbuf = WebsiteSettingsUI::GetPermissionIcon(
type_, setting_).ToGdkPixbuf();
icon_ = gtk_image_new_from_pixbuf(pixbuf);
gtk_box_pack_start(GTK_BOX(hbox), icon_, FALSE, FALSE, 0);
// Add a label for the permission type.
GtkWidget* label = CreateTextLabel(
l10n_util::GetStringFUTF8(
IDS_WEBSITE_SETTINGS_PERMISSION_TYPE,
WebsiteSettingsUI::PermissionTypeToUIString(type_)),
0,
theme_service_);
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
GtkListStore* store =
gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
GtkTreeIter iter;
// Add option for permission "Global Default" to the combobox model.
std::string setting_str = l10n_util::GetStringFUTF8(
IDS_WEBSITE_SETTINGS_DEFAULT_PERMISSION_LABEL,
WebsiteSettingsUI::PermissionValueToUIString(default_setting_));
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, setting_str.c_str(), 1,
CONTENT_SETTING_DEFAULT, -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::GetStringFUTF8(
IDS_WEBSITE_SETTINGS_PERMISSION_LABEL,
WebsiteSettingsUI::PermissionValueToUIString(CONTENT_SETTING_ALLOW));
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, setting_str.c_str(), 1,
CONTENT_SETTING_ALLOW, -1);
// The content settings type fullscreen does not support the concept of
// blocking.
if (type_ != CONTENT_SETTINGS_TYPE_FULLSCREEN) {
// Add option for permission "BLOCK" to the combobox model.
setting_str = l10n_util::GetStringFUTF8(
IDS_WEBSITE_SETTINGS_PERMISSION_LABEL,
WebsiteSettingsUI::PermissionValueToUIString(CONTENT_SETTING_BLOCK));
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, setting_str.c_str(), 1,
CONTENT_SETTING_BLOCK, -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 (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:" << 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);
return hbox;
}
void PermissionSelector::AddObserver(PermissionSelectorObserver* observer) {
observer_list_.AddObserver(observer);
}
void PermissionSelector::OnPermissionChanged(GtkWidget* widget) {
// Get the selected setting.
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;
gtk_tree_model_get(store, &it, 1, &value, -1);
setting_ = ContentSetting(value);
// Change the permission icon according the the selected setting.
GdkPixbuf* pixbuf = WebsiteSettingsUI::GetPermissionIcon(
type_, setting_).ToGdkPixbuf();
gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), pixbuf);
FOR_EACH_OBSERVER(PermissionSelectorObserver,
observer_list_,
OnPermissionChanged(this));
}
void PermissionSelector::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).
// When then combobox popup is closed we notify the
// |PermissionSelectorObserver|s so that BubbleGtk can grab the keyboard and
// pointer.
gboolean popup_shown = FALSE;
g_object_get(G_OBJECT(GTK_COMBO_BOX(widget)), "popup-shown", &popup_shown,
NULL);
if (!popup_shown) {
FOR_EACH_OBSERVER(PermissionSelectorObserver,
observer_list_,
OnComboboxShown());
}
}
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_H_
#define CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_H_
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/observer_list.h"
#include "chrome/browser/ui/gtk/website_settings/permission_selector_observer.h"
#include "chrome/common/content_settings.h"
#include "chrome/common/content_settings_types.h"
#include "ui/base/gtk/gtk_signal.h"
class GtkThemeService;
typedef struct _GParamSpec GParamSpec;
typedef struct _GtkWidget GtkWidget;
// The class |PermissionSelector| allows to change the permission |setting| of a
// given permission |type|.
class PermissionSelector {
public:
// Creates a |PermissionSelector| for the given permission |type|. |setting|
// is the current permissions setting. It is possible to pass
// |CONTENT_SETTING_DEFAULT| as value for |setting|. |default_setting| is the
// effective default setting for the given permission |type|. It is not
// allowed to pass |CONTENT_SETTING_DEFAULT| as value for |default_setting|.
PermissionSelector(GtkThemeService* theme_service_,
ContentSettingsType type,
ContentSetting setting,
ContentSetting default_setting);
~PermissionSelector();
// Creates the UI for the |PermissionSelector| and returns the widget that
// contains the UI elements. The ownership of the widget is transfered to the
// caller.
GtkWidget* CreateUI();
// Adds an |observer|.
void AddObserver(PermissionSelectorObserver* observer);
// Returns the current permission setting.
ContentSetting setting() const { return setting_; }
// Returns the permissions type.
ContentSettingsType type() const { return type_; }
private:
CHROMEGTK_CALLBACK_0(PermissionSelector, void, OnPermissionChanged);
CHROMEGTK_CALLBACK_1(PermissionSelector, void, OnComboBoxShown, GParamSpec*);
GtkThemeService* theme_service_;
// The permission type.
ContentSettingsType type_;
// The current permission setting.
ContentSetting setting_;
// The effective default setting. This is required to create the proper UI
// string for the default setting.
ContentSetting default_setting_;
// The permission type icon. The icon is changed depending on the selected
// setting.
// Owned by the widget hierarchy created by the CreateUI method.
GtkWidget* icon_;
ObserverList<PermissionSelectorObserver, false> observer_list_;
DISALLOW_COPY_AND_ASSIGN(PermissionSelector);
};
#endif // CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_H_
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_OBSERVER_H_
#define CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_OBSERVER_H_
class PermissionSelector;
class PermissionSelectorObserver {
public:
// This method is called when a permission setting is changed by a
// |selector|.
virtual void OnPermissionChanged(PermissionSelector* selector) = 0;
// GtkComboBox grabs the keyboard and pointer when it displays its popup,
// which steals the grabs that BubbleGtk had installed. When the combobox
// 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).
// OnComboboxShown is called when a combobox popup is closed.
virtual void OnComboboxShown() = 0;
protected:
virtual ~PermissionSelectorObserver() {}
};
#endif // CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_OBSERVER_H_
......@@ -2,20 +2,23 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_POPUP_GTK_H_
#define CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_POPUP_GTK_H_
#ifndef CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_WEBSITE_SETTINGS_POPUP_GTK_H_
#define CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_WEBSITE_SETTINGS_POPUP_GTK_H_
#include <gtk/gtk.h>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "chrome/browser/ui/gtk/bubble/bubble_gtk.h"
#include "chrome/browser/ui/gtk/website_settings/permission_selector_observer.h"
#include "chrome/browser/ui/website_settings/website_settings_ui.h"
class Browser;
class GtkThemeService;
class GURL;
class PermissionSelector;
class Profile;
class TabContents;
class WebsiteSettings;
......@@ -26,6 +29,7 @@ struct SSLStatus;
// GTK implementation of the website settings UI.
class WebsiteSettingsPopupGtk : public WebsiteSettingsUI,
public PermissionSelectorObserver,
public BubbleDelegateGtk {
public:
// Creates a |WebsiteSettingsPopupGtk| and displays the UI. The |url|
......@@ -54,6 +58,10 @@ class WebsiteSettingsPopupGtk : public WebsiteSettingsUI,
virtual void SetIdentityInfo(const IdentityInfo& identity_info) OVERRIDE;
virtual void SetFirstVisit(const string16& first_visit) OVERRIDE;
// PermissionSelectorObserver implementations.
virtual void OnPermissionChanged(PermissionSelector* selector) OVERRIDE;
virtual void OnComboboxShown() OVERRIDE;
// BubbleDelegateGtk implementation.
virtual void BubbleClosing(BubbleGtk* bubble, bool closed_by_escape) OVERRIDE;
......@@ -66,9 +74,6 @@ class WebsiteSettingsPopupGtk : public WebsiteSettingsUI,
// Removes all children of |container|.
void ClearContainer(GtkWidget* container);
// Creates a label that contains the given |text| and has the given |width|.
GtkWidget* CreateTextLabel(const std::string& text, int width);
// Creates a popup section and returns a virtual box that contains the
// section content.
GtkWidget* CreateSection(std::string section_title,
......@@ -76,11 +81,8 @@ class WebsiteSettingsPopupGtk : public WebsiteSettingsUI,
// Callbacks for the link buttons.
CHROMEGTK_CALLBACK_0(WebsiteSettingsPopupGtk, void, OnCookiesLinkClicked);
CHROMEGTK_CALLBACK_0(WebsiteSettingsPopupGtk, void, OnPermissionChanged);
CHROMEGTK_CALLBACK_0(WebsiteSettingsPopupGtk, void,
OnPermissionsSettingsLinkClicked);
CHROMEGTK_CALLBACK_1(WebsiteSettingsPopupGtk, void, OnComboBoxShown,
GParamSpec*);
CHROMEGTK_CALLBACK_0(WebsiteSettingsPopupGtk, void, OnViewCertLinkClicked);
// Parent window.
......@@ -129,7 +131,11 @@ class WebsiteSettingsPopupGtk : public WebsiteSettingsUI,
// |presenter_|. The |presenter_| handles these events and updates the UI.
scoped_ptr<WebsiteSettings> presenter_;
// The permission selectors that allow the user to change individual
// permissions.
ScopedVector<PermissionSelector> selectors_;
DISALLOW_COPY_AND_ASSIGN(WebsiteSettingsPopupGtk);
};
#endif // CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_POPUP_GTK_H_
#endif // CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_WEBSITE_SETTINGS_POPUP_GTK_H_
......@@ -320,10 +320,9 @@ void PermissionSelectorView::SelectionChanged() {
// Update the menu button text to reflect the new setting.
menu_button_->SetText(WebsiteSettingsUI::PermissionActionToUIString(
menu_button_model_->current_setting(),
menu_button_model_->default_setting(),
content_settings::SETTING_SOURCE_USER));
menu_button_model_->current_setting(),
menu_button_model_->default_setting(),
content_settings::SETTING_SOURCE_USER));
FOR_EACH_OBSERVER(PermissionSelectorViewObserver,
observer_list_,
......
......@@ -3334,8 +3334,11 @@
'browser/ui/gtk/web_dialog_gtk.h',
'browser/ui/gtk/web_intent_picker_gtk.cc',
'browser/ui/gtk/web_intent_picker_gtk.h',
'browser/ui/gtk/website_settings_popup_gtk.cc',
'browser/ui/gtk/website_settings_popup_gtk.h',
'browser/ui/gtk/website_settings/permission_selector.cc',
'browser/ui/gtk/website_settings/permission_selector.h',
'browser/ui/gtk/website_settings/permission_selector_observer.h',
'browser/ui/gtk/website_settings/website_settings_popup_gtk.cc',
'browser/ui/gtk/website_settings/website_settings_popup_gtk.h',
'browser/ui/gtk/zoom_bubble_gtk.cc',
'browser/ui/gtk/zoom_bubble_gtk.h',
'browser/ui/hung_plugin_tab_helper.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment