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

Side by Side Diff: chrome/browser/ui/cocoa/extensions/browser_action_button.mm

Issue 10963016: Fix disabled browser action appearance on Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: a Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h" 5 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/sys_string_conversions.h" 11 #include "base/sys_string_conversions.h"
12 #include "chrome/browser/extensions/extension_action_icon_factory.h" 12 #include "chrome/browser/extensions/extension_action_icon_factory.h"
13 #include "chrome/browser/ui/cocoa/extensions/extension_action_context_menu.h" 13 #include "chrome/browser/ui/cocoa/extensions/extension_action_context_menu.h"
14 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
15 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
16 #include "chrome/common/extensions/extension_action.h" 16 #include "chrome/common/extensions/extension_action.h"
17 #include "chrome/common/extensions/extension_resource.h" 17 #include "chrome/common/extensions/extension_resource.h"
18 #include "content/public/browser/notification_observer.h" 18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h" 19 #include "content/public/browser/notification_registrar.h"
20 #include "content/public/browser/notification_source.h" 20 #include "content/public/browser/notification_source.h"
21 #include "grit/theme_resources.h" 21 #include "grit/theme_resources.h"
22 #include "skia/ext/skia_utils_mac.h" 22 #include "skia/ext/skia_utils_mac.h"
23 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" 23 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h"
24 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/gfx/canvas_skia_paint.h" 25 #include "ui/gfx/canvas_skia_paint.h"
26 #include "ui/gfx/image/image.h" 26 #include "ui/gfx/image/image.h"
27 #include "ui/gfx/image/image_skia_operations.h"
27 #include "ui/gfx/rect.h" 28 #include "ui/gfx/rect.h"
28 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 29 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
29 #include "ui/gfx/size.h" 30 #include "ui/gfx/size.h"
30 31
31 using extensions::Extension; 32 using extensions::Extension;
32 33
33 NSString* const kBrowserActionButtonDraggingNotification = 34 NSString* const kBrowserActionButtonDraggingNotification =
34 @"BrowserActionButtonDraggingNotification"; 35 @"BrowserActionButtonDraggingNotification";
35 NSString* const kBrowserActionButtonDragEndNotification = 36 NSString* const kBrowserActionButtonDragEndNotification =
36 @"BrowserActionButtonDragEndNotification"; 37 @"BrowserActionButtonDragEndNotification";
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 [cell setExtensionAction:extension->browser_action()]; 129 [cell setExtensionAction:extension->browser_action()];
129 [cell 130 [cell
130 accessibilitySetOverrideValue:base::SysUTF8ToNSString(extension->name()) 131 accessibilitySetOverrideValue:base::SysUTF8ToNSString(extension->name())
131 forAttribute:NSAccessibilityDescriptionAttribute]; 132 forAttribute:NSAccessibilityDescriptionAttribute];
132 [cell setImageID:IDR_BROWSER_ACTION 133 [cell setImageID:IDR_BROWSER_ACTION
133 forButtonState:image_button_cell::kDefaultState]; 134 forButtonState:image_button_cell::kDefaultState];
134 [cell setImageID:IDR_BROWSER_ACTION_H 135 [cell setImageID:IDR_BROWSER_ACTION_H
135 forButtonState:image_button_cell::kHoverState]; 136 forButtonState:image_button_cell::kHoverState];
136 [cell setImageID:IDR_BROWSER_ACTION_P 137 [cell setImageID:IDR_BROWSER_ACTION_P
137 forButtonState:image_button_cell::kPressedState]; 138 forButtonState:image_button_cell::kPressedState];
139 [cell setImageID:IDR_BROWSER_ACTION
140 forButtonState:image_button_cell::kDisabledState];
138 141
139 [self setTitle:@""]; 142 [self setTitle:@""];
140 [self setButtonType:NSMomentaryChangeButton]; 143 [self setButtonType:NSMomentaryChangeButton];
141 [self setShowsBorderOnlyWhileMouseInside:YES]; 144 [self setShowsBorderOnlyWhileMouseInside:YES];
142 145
143 [self setMenu:[[[ExtensionActionContextMenu alloc] 146 [self setMenu:[[[ExtensionActionContextMenu alloc]
144 initWithExtension:extension 147 initWithExtension:extension
145 browser:browser 148 browser:browser
146 extensionAction:extension->browser_action()] autorelease]]; 149 extensionAction:extension->browser_action()] autorelease]];
147 150
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 if (tabId_ < 0) 243 if (tabId_ < 0)
241 return; 244 return;
242 245
243 std::string tooltip = extension_->browser_action()->GetTitle(tabId_); 246 std::string tooltip = extension_->browser_action()->GetTitle(tabId_);
244 if (tooltip.empty()) { 247 if (tooltip.empty()) {
245 [self setToolTip:nil]; 248 [self setToolTip:nil];
246 } else { 249 } else {
247 [self setToolTip:base::SysUTF8ToNSString(tooltip)]; 250 [self setToolTip:base::SysUTF8ToNSString(tooltip)];
248 } 251 }
249 252
250 gfx::Image image = iconFactoryBridge_->GetIcon(tabId_); 253 gfx::ImageSkia image = iconFactoryBridge_->GetIcon(tabId_).AsImageSkia();
251 254
252 if (!image.IsEmpty()) 255 bool enabled = extension_->browser_action()->GetIsVisible(tabId_);
253 [self setImage:image.ToNSImage()]; 256 if (!image.isNull()) {
257 if (!enabled)
258 image = gfx::ImageSkiaOperations::CreateTransparentImage(image, 0.4);
259 [self setImage:gfx::Image(image).ToNSImage()];
Nico 2012/09/21 02:02:02 It looks like we're round-tripping to skia and bac
Yoyo Zhou 2012/09/21 18:04:59 Ah, I didn't realize this was something to avoid.
260 }
261
262 [self setEnabled:enabled ? YES : NO];
Nico 2012/09/21 02:02:02 just "enabled" is enough. Drop the ?YES:NO.
Yoyo Zhou 2012/09/21 18:04:59 Done.
254 263
255 [[self cell] setTabId:tabId_]; 264 [[self cell] setTabId:tabId_];
256 265
257 bool enabled = extension_->browser_action()->GetIsVisible(tabId_);
258 [self setEnabled:enabled ? YES : NO];
259
260 [self setNeedsDisplay:YES]; 266 [self setNeedsDisplay:YES];
261 } 267 }
262 268
263 - (BOOL)isAnimating { 269 - (BOOL)isAnimating {
264 return [moveAnimation_ isAnimating]; 270 return [moveAnimation_ isAnimating];
265 } 271 }
266 272
267 - (NSImage*)compositedImage { 273 - (NSImage*)compositedImage {
268 NSRect bounds = [self bounds]; 274 NSRect bounds = [self bounds];
269 NSImage* image = [[[NSImage alloc] initWithSize:bounds.size] autorelease]; 275 NSImage* image = [[[NSImage alloc] initWithSize:bounds.size] autorelease];
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 gfx::ScopedNSGraphicsContextSaveGState scopedGState; 316 gfx::ScopedNSGraphicsContextSaveGState scopedGState;
311 [super drawWithFrame:cellFrame inView:controlView]; 317 [super drawWithFrame:cellFrame inView:controlView];
312 const NSSize imageSize = self.image.size; 318 const NSSize imageSize = self.image.size;
313 const NSRect imageRect = 319 const NSRect imageRect =
314 NSMakeRect(std::floor((NSWidth(cellFrame) - imageSize.width) / 2.0), 320 NSMakeRect(std::floor((NSWidth(cellFrame) - imageSize.width) / 2.0),
315 std::floor((NSHeight(cellFrame) - imageSize.height) / 2.0), 321 std::floor((NSHeight(cellFrame) - imageSize.height) / 2.0),
316 imageSize.width, imageSize.height); 322 imageSize.width, imageSize.height);
317 [self.image drawInRect:imageRect 323 [self.image drawInRect:imageRect
318 fromRect:NSZeroRect 324 fromRect:NSZeroRect
319 operation:NSCompositeSourceOver 325 operation:NSCompositeSourceOver
320 fraction:1.0 326 fraction:1.0
Nico 2012/09/21 02:02:02 Can't you just change this to "enabled ? 1.0 : 0.4
Yoyo Zhou 2012/09/21 18:04:59 Done. Slightly scared by operator precendence.
321 respectFlipped:YES 327 respectFlipped:YES
322 hints:nil]; 328 hints:nil];
323 329
324 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; 330 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset;
325 [self drawBadgeWithinFrame:cellFrame]; 331 [self drawBadgeWithinFrame:cellFrame];
326 } 332 }
327 333
328 @end 334 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698