Index: chrome/browser/ui/views/browser_action_view.cc |
diff --git a/chrome/browser/ui/views/browser_action_view.cc b/chrome/browser/ui/views/browser_action_view.cc |
index 073d80ecd18bf62997aba32f48ff18d7913c87d3..95cfb5937dd0622780552d3ca46022e69f5b1516 100644 |
--- a/chrome/browser/ui/views/browser_action_view.cc |
+++ b/chrome/browser/ui/views/browser_action_view.cc |
@@ -21,11 +21,27 @@ |
#include "ui/base/l10n/l10n_util.h" |
#include "ui/base/resource/resource_bundle.h" |
#include "ui/gfx/canvas.h" |
+#include "ui/gfx/skbitmap_operations.h" |
#include "ui/views/controls/menu/menu_model_adapter.h" |
#include "ui/views/controls/menu/menu_runner.h" |
using extensions::Extension; |
+namespace { |
+ |
+SkBitmap TransparentizeImage(const SkBitmap& image) { |
+ // Same parameters as for disabled extension icons. |
+ // 40% lightness matches Mac. |
+ SkBitmap alpha; |
+ alpha.setConfig(SkBitmap::kARGB_8888_Config, image.width(), image.height()); |
+ alpha.allocPixels(); |
+ alpha.eraseColor(0x40000000); |
not at google - send to devlin
2012/07/12 01:07:29
0x40 isn't 40% alpha, it's 25% alpha? Or am I goin
Yoyo Zhou
2012/07/12 01:33:27
Yup, 25% alpha. I was trying to find some good SkC
|
+ |
+ return SkBitmapOperations::CreateMaskedBitmap(image, alpha); |
+} |
+ |
+} // namespace |
+ |
//////////////////////////////////////////////////////////////////////////////// |
// BrowserActionButton |
@@ -121,10 +137,17 @@ void BrowserActionButton::UpdateState() { |
if (tab_id < 0) |
return; |
+ SetState(IsEnabled(tab_id) ? |
+ views::CustomButton::BS_NORMAL : |
not at google - send to devlin
2012/07/12 01:07:29
This should be PUSHED If it's pushed; can use the
Yoyo Zhou
2012/07/12 01:33:27
Done.
|
+ views::CustomButton::BS_DISABLED); |
+ |
SkBitmap icon(browser_action()->GetIcon(tab_id)); |
if (icon.isNull()) |
icon = default_icon_; |
if (!icon.isNull()) { |
+ // if (!enabled()) |
+ if (!browser_action()->GetIsVisible(tab_id)) |
+ icon = TransparentizeImage(icon); |
SkPaint paint; |
paint.setXfermode(SkXfermode::Create(SkXfermode::kSrcOver_Mode)); |
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
@@ -162,6 +185,7 @@ void BrowserActionButton::UpdateState() { |
name = UTF8ToUTF16(extension()->name()); |
SetTooltipText(name); |
SetAccessibleName(name); |
+ |
parent()->SchedulePaint(); |
} |
@@ -298,6 +322,10 @@ void BrowserActionButton::SetButtonNotPushed() { |
menu_visible_ = false; |
} |
+bool BrowserActionButton::IsEnabled(int tab_id) const { |
+ return browser_action_->GetIsVisible(tab_id); |
+} |
+ |
BrowserActionButton::~BrowserActionButton() { |
} |
@@ -361,6 +389,10 @@ gfx::Canvas* BrowserActionView::GetIconWithBadge() { |
if (icon.isNull()) |
icon = button_->default_icon(); |
+ // Gray out the icon if our button is disabled. |
+ if (!button_->IsEnabled(tab_id)) |
+ icon = TransparentizeImage(icon); |
+ |
gfx::Canvas* canvas = new gfx::Canvas(icon, false); |
if (tab_id >= 0) { |