Chromium Code Reviews| 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 cd1600b8e90bb61531468f9f45f34d9fa7f7d1a2..f0c5d9cab48dd124380b021e424454ea97a2476c 100644 |
| --- a/chrome/browser/ui/views/browser_action_view.cc |
| +++ b/chrome/browser/ui/views/browser_action_view.cc |
| @@ -20,11 +20,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) { |
|
sky
2012/07/16 15:43:46
How about MakeTransparent and add a description.
Yoyo Zhou
2012/07/16 17:45:45
Done.
|
| + // 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(SkColorSetARGB(64, 0, 0, 0)); |
| + |
| + return SkBitmapOperations::CreateMaskedBitmap(image, alpha); |
| +} |
| + |
| +} // namespace |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // BrowserActionButton |
| @@ -120,10 +136,21 @@ void BrowserActionButton::UpdateState() { |
| if (tab_id < 0) |
| return; |
| + if (!IsEnabled(tab_id)) { |
| + SetState(views::CustomButton::BS_DISABLED); |
| + } else { |
| + SetState(menu_visible_ ? |
| + views::CustomButton::BS_NORMAL : |
| + views::CustomButton::BS_PUSHED); |
| + } |
| + |
| SkBitmap icon(browser_action()->GetIcon(tab_id)); |
| if (icon.isNull()) |
| icon = default_icon_; |
| if (!icon.isNull()) { |
| + // if (!enabled()) |
|
sky
2012/07/16 15:43:46
Remove commented out line.
Yoyo Zhou
2012/07/16 17:45:45
Done.
|
| + if (!browser_action()->GetIsVisible(tab_id)) |
| + icon = TransparentizeImage(icon); |
| SkPaint paint; |
| paint.setXfermode(SkXfermode::Create(SkXfermode::kSrcOver_Mode)); |
| ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| @@ -161,6 +188,7 @@ void BrowserActionButton::UpdateState() { |
| name = UTF8ToUTF16(extension()->name()); |
| SetTooltipText(name); |
| SetAccessibleName(name); |
| + |
| parent()->SchedulePaint(); |
| } |
| @@ -297,6 +325,10 @@ void BrowserActionButton::SetButtonNotPushed() { |
| menu_visible_ = false; |
| } |
| +bool BrowserActionButton::IsEnabled(int tab_id) const { |
| + return browser_action_->GetIsVisible(tab_id); |
| +} |
| + |
| BrowserActionButton::~BrowserActionButton() { |
| } |
| @@ -360,6 +392,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(gfx::ImageSkiaRep(icon, ui::SCALE_FACTOR_100P), false); |