summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk
diff options
context:
space:
mode:
authorbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-05 11:40:08 +0000
committerbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-05 11:40:08 +0000
commit352104ee28f47810b5d2dc5fd6193c60d2cd2e95 (patch)
tree1d4d26928b9951a3d5f54688c550835740849837 /chrome/browser/gtk
parentff039f0833a278d7ca80aeb8987e73b6c258f305 (diff)
downloadchromium_src-352104ee28f47810b5d2dc5fd6193c60d2cd2e95.zip
chromium_src-352104ee28f47810b5d2dc5fd6193c60d2cd2e95.tar.gz
chromium_src-352104ee28f47810b5d2dc5fd6193c60d2cd2e95.tar.bz2
Renames ContentBlockedImageView to ContentSettingImageView.
Adds ContentSettingImageModel to provide icon and tooltips for platform-specific ContentBlockedImageView. (in preparation for: http://codereview.chromium.org/650180/show ) TEST=chrome/browser/content_setting_image_model_unittest.cc Review URL: http://codereview.chromium.org/660279 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40732 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r--chrome/browser/gtk/browser_toolbar_gtk.cc2
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.cc108
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.h33
3 files changed, 65 insertions, 78 deletions
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc
index 9df751f..08ef507 100644
--- a/chrome/browser/gtk/browser_toolbar_gtk.cc
+++ b/chrome/browser/gtk/browser_toolbar_gtk.cc
@@ -248,7 +248,7 @@ void BrowserToolbarGtk::Init(Profile* profile,
// Because the above does a recursive show all on all widgets we need to
// update the icon visibility to hide them.
- location_bar_->UpdateContentBlockedIcons();
+ location_bar_->UpdateContentSettingsIcons();
SetViewIDs();
}
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc
index b622115..ed0cda4 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/gtk/location_bar_view_gtk.cc
@@ -20,6 +20,7 @@
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/command_updater.h"
+#include "chrome/browser/content_setting_image_model.h"
#include "chrome/browser/extensions/extension_accessibility_api_constants.h"
#include "chrome/browser/extensions/extension_action_context_menu_model.h"
#include "chrome/browser/extensions/extension_browser_event_router.h"
@@ -170,7 +171,7 @@ LocationBarViewGtk::LocationBarViewGtk(
LocationBarViewGtk::~LocationBarViewGtk() {
// All of our widgets should have be children of / owned by the alignment.
hbox_.Destroy();
- content_blocking_hbox_.Destroy();
+ content_setting_hbox_.Destroy();
page_action_hbox_.Destroy();
}
@@ -327,20 +328,19 @@ void LocationBarViewGtk::Init(bool popup_window_mode) {
gtk_box_pack_end(GTK_BOX(hbox_.get()), security_icon_event_box_,
FALSE, FALSE, 0);
- content_blocking_hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding));
- gtk_widget_set_name(content_blocking_hbox_.get(),
- "chrome-content-blocking-hbox");
- gtk_box_pack_end(GTK_BOX(hbox_.get()), content_blocking_hbox_.get(),
+ content_setting_hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding));
+ gtk_widget_set_name(content_setting_hbox_.get(),
+ "chrome-content-setting-hbox");
+ gtk_box_pack_end(GTK_BOX(hbox_.get()), content_setting_hbox_.get(),
FALSE, FALSE, 0);
for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
- ContentBlockedViewGtk* content_blocked_view =
- new ContentBlockedViewGtk(static_cast<ContentSettingsType>(i), this,
- profile_);
- content_blocked_views_.push_back(content_blocked_view);
- gtk_box_pack_end(GTK_BOX(content_blocking_hbox_.get()),
- content_blocked_view->widget(), FALSE, FALSE, 0);
- content_blocked_view->SetVisible(false);
+ ContentSettingImageViewGtk* content_setting_view =
+ new ContentSettingImageViewGtk(
+ static_cast<ContentSettingsType>(i), this, profile_);
+ content_setting_views_.push_back(content_setting_view);
+ gtk_box_pack_end(GTK_BOX(content_setting_hbox_.get()),
+ content_setting_view->widget(), FALSE, FALSE, 0);
}
page_action_hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding));
@@ -395,7 +395,7 @@ GtkWidget* LocationBarViewGtk::GetPageActionWidget(
void LocationBarViewGtk::Update(const TabContents* contents) {
SetSecurityIcon(toolbar_model_->GetIcon());
- UpdateContentBlockedIcons();
+ UpdateContentSettingsIcons();
UpdatePageActions();
SetInfoText();
location_entry_->Update(contents);
@@ -537,24 +537,23 @@ void LocationBarViewGtk::FocusSearch() {
location_entry_->SetForcedQuery();
}
-void LocationBarViewGtk::UpdateContentBlockedIcons() {
+void LocationBarViewGtk::UpdateContentSettingsIcons() {
const TabContents* tab_contents = GetTabContents();
bool any_visible = false;
- for (ScopedVector<ContentBlockedViewGtk>::iterator i(
- content_blocked_views_.begin());
- i != content_blocked_views_.end(); ++i) {
- bool is_visible = (!toolbar_model_->input_in_progress() && tab_contents) ?
- tab_contents->IsContentBlocked((*i)->content_type()) : false;
- any_visible = is_visible || any_visible;
- (*i)->SetVisible(is_visible);
+ for (ScopedVector<ContentSettingImageViewGtk>::iterator i(
+ content_setting_views_.begin());
+ i != content_setting_views_.end(); ++i) {
+ (*i)->UpdateFromTabContents(
+ toolbar_model_->input_in_progress() ? NULL : tab_contents);
+ any_visible = (*i)->IsVisible() || any_visible;
}
// If there are no visible content things, hide the top level box so it
// doesn't mess with padding.
if (any_visible)
- gtk_widget_show(content_blocking_hbox_.get());
+ gtk_widget_show(content_setting_hbox_.get());
else
- gtk_widget_hide(content_blocking_hbox_.get());
+ gtk_widget_hide(content_setting_hbox_.get());
}
void LocationBarViewGtk::UpdatePageActions() {
@@ -952,12 +951,14 @@ void LocationBarViewGtk::AdjustChildrenVisibility() {
}
////////////////////////////////////////////////////////////////////////////////
-// LocationBarViewGtk::ContentBlockedViewGtk
-LocationBarViewGtk::ContentBlockedViewGtk::ContentBlockedViewGtk(
+// LocationBarViewGtk::ContentSettingImageViewGtk
+LocationBarViewGtk::ContentSettingImageViewGtk::ContentSettingImageViewGtk(
ContentSettingsType content_type,
const LocationBarViewGtk* parent,
Profile* profile)
- : content_type_(content_type),
+ : content_setting_image_model_(
+ ContentSettingImageModel::CreateContentSettingImageModel(
+ content_type)),
parent_(parent),
profile_(profile),
info_bubble_(NULL) {
@@ -970,35 +971,10 @@ LocationBarViewGtk::ContentBlockedViewGtk::ContentBlockedViewGtk(
image_.Own(gtk_image_new());
gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get());
-
- static const int kIconIDs[CONTENT_SETTINGS_NUM_TYPES] = {
- IDR_BLOCKED_COOKIES,
- IDR_BLOCKED_IMAGES,
- IDR_BLOCKED_JAVASCRIPT,
- IDR_BLOCKED_PLUGINS,
- IDR_BLOCKED_POPUPS,
- };
- DCHECK_EQ(arraysize(kIconIDs),
- static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES));
- gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()),
- ResourceBundle::GetSharedInstance().GetPixbufNamed(
- kIconIDs[content_type]));
-
- static const int kTooltipIDs[CONTENT_SETTINGS_NUM_TYPES] = {
- IDS_BLOCKED_COOKIES_TITLE,
- IDS_BLOCKED_IMAGES_TITLE,
- IDS_BLOCKED_JAVASCRIPT_TITLE,
- IDS_BLOCKED_PLUGINS_TITLE,
- IDS_BLOCKED_POPUPS_TOOLTIP,
- };
- DCHECK_EQ(arraysize(kTooltipIDs),
- static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES));
- gtk_widget_set_tooltip_text(
- widget(),
- l10n_util::GetStringUTF8(kTooltipIDs[content_type_]).c_str());
+ gtk_widget_hide(widget());
}
-LocationBarViewGtk::ContentBlockedViewGtk::~ContentBlockedViewGtk() {
+LocationBarViewGtk::ContentSettingImageViewGtk::~ContentSettingImageViewGtk() {
image_.Destroy();
event_box_.Destroy();
@@ -1006,14 +982,25 @@ LocationBarViewGtk::ContentBlockedViewGtk::~ContentBlockedViewGtk() {
info_bubble_->Close();
}
-void LocationBarViewGtk::ContentBlockedViewGtk::SetVisible(bool visible) {
- if (visible)
+void LocationBarViewGtk::ContentSettingImageViewGtk::UpdateFromTabContents(
+ const TabContents* tab_contents) {
+ int old_icon = content_setting_image_model_->get_icon();
+ content_setting_image_model_->UpdateFromTabContents(tab_contents);
+ if (content_setting_image_model_->is_visible()) {
+ if (old_icon != content_setting_image_model_->get_icon()) {
+ gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()),
+ ResourceBundle::GetSharedInstance().GetPixbufNamed(
+ content_setting_image_model_->get_icon()));
+ }
+ gtk_widget_set_tooltip_text(widget(),
+ content_setting_image_model_->get_tooltip().c_str());
gtk_widget_show(widget());
- else
+ } else {
gtk_widget_hide(widget());
+ }
}
-gboolean LocationBarViewGtk::ContentBlockedViewGtk::OnButtonPressed(
+gboolean LocationBarViewGtk::ContentSettingImageViewGtk::OnButtonPressed(
GtkWidget* sender, GdkEvent* event) {
gfx::Rect bounds =
gtk_util::GetWidgetRectRelativeToToplevel(sender);
@@ -1030,12 +1017,13 @@ gboolean LocationBarViewGtk::ContentBlockedViewGtk::OnButtonPressed(
GtkWindow* toplevel = GTK_WINDOW(gtk_widget_get_toplevel(sender));
info_bubble_ = new ContentBlockedBubbleGtk(
- toplevel, bounds, this, content_type_, url.host(), display_host, profile_,
- tab_contents);
+ toplevel, bounds, this,
+ content_setting_image_model_->get_content_settings_type(), url.host(),
+ display_host, profile_, tab_contents);
return TRUE;
}
-void LocationBarViewGtk::ContentBlockedViewGtk::InfoBubbleClosing(
+void LocationBarViewGtk::ContentSettingImageViewGtk::InfoBubbleClosing(
InfoBubbleGtk* info_bubble,
bool closed_by_escape) {
info_bubble_ = NULL;
diff --git a/chrome/browser/gtk/location_bar_view_gtk.h b/chrome/browser/gtk/location_bar_view_gtk.h
index dcd6a26..c0da0c7 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.h
+++ b/chrome/browser/gtk/location_bar_view_gtk.h
@@ -32,6 +32,7 @@ class BubblePositioner;
class Browser;
class CommandUpdater;
class ContentBlockedBubbleGtk;
+class ContentSettingImageModel;
class ExtensionAction;
class ExtensionActionContextMenuModel;
class GtkThemeProvider;
@@ -99,7 +100,7 @@ class LocationBarViewGtk : public AutocompleteEditController,
virtual void AcceptInputWithDisposition(WindowOpenDisposition);
virtual void FocusLocation();
virtual void FocusSearch();
- virtual void UpdateContentBlockedIcons();
+ virtual void UpdateContentSettingsIcons();
virtual void UpdatePageActions();
virtual void InvalidatePageActions();
virtual void SaveStateToContents(TabContents* contents);
@@ -126,25 +127,24 @@ class LocationBarViewGtk : public AutocompleteEditController,
static const GdkColor kBackgroundColorByLevel[3];
private:
- class ContentBlockedViewGtk : public InfoBubbleGtkDelegate {
+ class ContentSettingImageViewGtk : public InfoBubbleGtkDelegate {
public:
- ContentBlockedViewGtk(ContentSettingsType content_type,
- const LocationBarViewGtk* parent,
- Profile* profile);
- virtual ~ContentBlockedViewGtk();
+ ContentSettingImageViewGtk(ContentSettingsType content_type,
+ const LocationBarViewGtk* parent,
+ Profile* profile);
+ virtual ~ContentSettingImageViewGtk();
GtkWidget* widget() { return event_box_.get(); }
- ContentSettingsType content_type() const { return content_type_; }
void set_profile(Profile* profile) { profile_ = profile; }
bool IsVisible() { return GTK_WIDGET_VISIBLE(widget()); }
- void SetVisible(bool visible);
+ void UpdateFromTabContents(const TabContents* tab_contents);
private:
static gboolean OnButtonPressedThunk(GtkWidget* sender,
GdkEvent* event,
- ContentBlockedViewGtk* view) {
+ ContentSettingImageViewGtk* view) {
return view->OnButtonPressed(sender, event);
}
gboolean OnButtonPressed(GtkWidget* sender, GdkEvent* event);
@@ -153,13 +153,12 @@ class LocationBarViewGtk : public AutocompleteEditController,
virtual void InfoBubbleClosing(InfoBubbleGtk* info_bubble,
bool closed_by_escape);
- // The widgets for this content blocked view.
+ scoped_ptr<ContentSettingImageModel> content_setting_image_model_;
+
+ // The widgets for this content settings view.
OwnedWidgetGtk event_box_;
OwnedWidgetGtk image_;
- // The type of content handled by this view.
- ContentSettingsType content_type_;
-
// The owning LocationBarViewGtk.
const LocationBarViewGtk* parent_;
@@ -169,7 +168,7 @@ class LocationBarViewGtk : public AutocompleteEditController,
// The currently shown info bubble if any.
ContentBlockedBubbleGtk* info_bubble_;
- DISALLOW_COPY_AND_ASSIGN(ContentBlockedViewGtk);
+ DISALLOW_COPY_AND_ASSIGN(ContentSettingImageViewGtk);
};
class PageActionViewGtk : public ImageLoadingTracker::Observer {
@@ -313,9 +312,9 @@ class LocationBarViewGtk : public AutocompleteEditController,
// Toolbar info text (EV cert info).
GtkWidget* info_label_;
- // Content blocking icons.
- OwnedWidgetGtk content_blocking_hbox_;
- ScopedVector<ContentBlockedViewGtk> content_blocked_views_;
+ // Content setting icons.
+ OwnedWidgetGtk content_setting_hbox_;
+ ScopedVector<ContentSettingImageViewGtk> content_setting_views_;
// Extension page action icons.
OwnedWidgetGtk page_action_hbox_;