Chromium Code Reviews| Index: chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc |
| diff --git a/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc b/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc |
| index b8114dcd8cd29647aa8f93ab510c88375979ea62..a76d34125f5ed2222e1a44e2633ec2bedbd42301 100644 |
| --- a/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc |
| +++ b/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc |
| @@ -23,6 +23,7 @@ |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_tabstrip.h" |
| #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
| +#include "chrome/browser/ui/gtk/custom_button.h" |
| #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h" |
| #include "chrome/browser/ui/gtk/gtk_chrome_button.h" |
| #include "chrome/browser/ui/gtk/gtk_chrome_shrinkable_hbox.h" |
| @@ -47,6 +48,7 @@ |
| #include "ui/gfx/canvas_skia_paint.h" |
| #include "ui/gfx/gtk_util.h" |
| #include "ui/gfx/image/image.h" |
| +#include "ui/gfx/image/image_skia_operations.h" |
| using extensions::Extension; |
| @@ -124,7 +126,7 @@ class BrowserActionButton : public content::NotificationObserver, |
| signals_.Connect(button(), "clicked", |
| G_CALLBACK(OnClicked), this); |
| signals_.Connect(button(), "drag-begin", |
| - G_CALLBACK(&OnDragBegin), this); |
| + G_CALLBACK(OnDragBegin), this); |
| signals_.ConnectAfter(widget(), "expose-event", |
| G_CALLBACK(OnExposeEvent), this); |
| if (toolbar_->browser()->window()) { |
| @@ -218,11 +220,18 @@ class BrowserActionButton : public content::NotificationObserver, |
| else |
| gtk_widget_set_tooltip_text(button(), tooltip.c_str()); |
| - gfx::Image image = icon_factory_.GetIcon(tab_id); |
| - if (!image.IsEmpty()) |
| - SetImage(image.ToGdkPixbuf()); |
| - bool enabled = extension_->browser_action()->GetIsVisible(tab_id); |
| - gtk_widget_set_sensitive(button(), enabled); |
| + enabled_ = extension_->browser_action()->GetIsVisible(tab_id); |
| + if (!enabled_) |
| + button_->SetPaintOverride(GTK_STATE_INSENSITIVE); |
| + else |
| + button_->UnsetPaintOverride(); |
| + |
| + gfx::ImageSkia image = icon_factory_.GetIcon(tab_id).AsImageSkia(); |
| + if (!image.isNull()) { |
| + if (!enabled_) |
| + image = gfx::ImageSkiaOperations::CreateTransparentImage(image, .25); |
| + SetImage(gfx::Image(image).ToGdkPixbuf()); |
| + } |
| gtk_widget_queue_draw(button()); |
| } |
| @@ -263,6 +272,8 @@ class BrowserActionButton : public content::NotificationObserver, |
| // MenuGtk::Delegate implementation. |
| virtual void StoppedShowing() { |
| button_->UnsetPaintOverride(); |
| + if (!enabled_) |
|
Evan Stade
2012/09/21 12:35:12
why not
if (enabled_)
Unset
else
SetPaintOver
Yoyo Zhou
2012/09/21 18:20:09
Done.
|
| + button_->SetPaintOverride(GTK_STATE_INSENSITIVE); |
| // If the context menu was showing for the overflow menu, re-assert the |
| // grab that was shadowed. |
| @@ -295,22 +306,23 @@ class BrowserActionButton : public content::NotificationObserver, |
| static gboolean OnButtonPress(GtkWidget* widget, |
| GdkEventButton* event, |
| - BrowserActionButton* action) { |
| + BrowserActionButton* button) { |
| if (event->button != 3) |
| return FALSE; |
| - MenuGtk* menu = action->GetContextMenu(); |
| + MenuGtk* menu = button->GetContextMenu(); |
| if (!menu) |
| return FALSE; |
| - action->button_->SetPaintOverride(GTK_STATE_ACTIVE); |
| + button->button_->SetPaintOverride(GTK_STATE_ACTIVE); |
| menu->PopupForWidget(widget, event->button, event->time); |
| return TRUE; |
| } |
| - static void OnClicked(GtkWidget* widget, BrowserActionButton* action) { |
| - action->Activate(widget); |
| + static void OnClicked(GtkWidget* widget, BrowserActionButton* button) { |
| + if (button->enabled_) |
| + button->Activate(widget); |
| } |
| static gboolean OnExposeEvent(GtkWidget* widget, |
| @@ -430,6 +442,10 @@ class BrowserActionButton : public content::NotificationObserver, |
| // The button for this browser action. |
| scoped_ptr<CustomDrawButton> button_; |
| + // Whether the browser action is enabled (equivalent to whether a page action |
| + // is visible). |
| + bool enabled_; |
| + |
| // The top level widget (parent of |button_|). |
| ui::OwnedWidgetGtk alignment_; |