Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10264)

Unified Diff: chrome/browser/ui/views/browser_action_view.cc

Issue 10700007: Page actions behave as disableable browser actions when script badges are enabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);

Powered by Google App Engine
This is Rietveld 408576698