| OLD | NEW |
| 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" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 [cell setExtensionAction:extension->browser_action()]; | 128 [cell setExtensionAction:extension->browser_action()]; |
| 129 [cell | 129 [cell |
| 130 accessibilitySetOverrideValue:base::SysUTF8ToNSString(extension->name()) | 130 accessibilitySetOverrideValue:base::SysUTF8ToNSString(extension->name()) |
| 131 forAttribute:NSAccessibilityDescriptionAttribute]; | 131 forAttribute:NSAccessibilityDescriptionAttribute]; |
| 132 [cell setImageID:IDR_BROWSER_ACTION | 132 [cell setImageID:IDR_BROWSER_ACTION |
| 133 forButtonState:image_button_cell::kDefaultState]; | 133 forButtonState:image_button_cell::kDefaultState]; |
| 134 [cell setImageID:IDR_BROWSER_ACTION_H | 134 [cell setImageID:IDR_BROWSER_ACTION_H |
| 135 forButtonState:image_button_cell::kHoverState]; | 135 forButtonState:image_button_cell::kHoverState]; |
| 136 [cell setImageID:IDR_BROWSER_ACTION_P | 136 [cell setImageID:IDR_BROWSER_ACTION_P |
| 137 forButtonState:image_button_cell::kPressedState]; | 137 forButtonState:image_button_cell::kPressedState]; |
| 138 [cell setImageID:IDR_BROWSER_ACTION |
| 139 forButtonState:image_button_cell::kDisabledState]; |
| 138 | 140 |
| 139 [self setTitle:@""]; | 141 [self setTitle:@""]; |
| 140 [self setButtonType:NSMomentaryChangeButton]; | 142 [self setButtonType:NSMomentaryChangeButton]; |
| 141 [self setShowsBorderOnlyWhileMouseInside:YES]; | 143 [self setShowsBorderOnlyWhileMouseInside:YES]; |
| 142 | 144 |
| 143 [self setMenu:[[[ExtensionActionContextMenu alloc] | 145 [self setMenu:[[[ExtensionActionContextMenu alloc] |
| 144 initWithExtension:extension | 146 initWithExtension:extension |
| 145 browser:browser | 147 browser:browser |
| 146 extensionAction:extension->browser_action()] autorelease]]; | 148 extensionAction:extension->browser_action()] autorelease]]; |
| 147 | 149 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 } | 250 } |
| 249 | 251 |
| 250 gfx::Image image = iconFactoryBridge_->GetIcon(tabId_); | 252 gfx::Image image = iconFactoryBridge_->GetIcon(tabId_); |
| 251 | 253 |
| 252 if (!image.IsEmpty()) | 254 if (!image.IsEmpty()) |
| 253 [self setImage:image.ToNSImage()]; | 255 [self setImage:image.ToNSImage()]; |
| 254 | 256 |
| 255 [[self cell] setTabId:tabId_]; | 257 [[self cell] setTabId:tabId_]; |
| 256 | 258 |
| 257 bool enabled = extension_->browser_action()->GetIsVisible(tabId_); | 259 bool enabled = extension_->browser_action()->GetIsVisible(tabId_); |
| 258 [self setEnabled:enabled ? YES : NO]; | 260 [self setEnabled:enabled]; |
| 259 | 261 |
| 260 [self setNeedsDisplay:YES]; | 262 [self setNeedsDisplay:YES]; |
| 261 } | 263 } |
| 262 | 264 |
| 263 - (BOOL)isAnimating { | 265 - (BOOL)isAnimating { |
| 264 return [moveAnimation_ isAnimating]; | 266 return [moveAnimation_ isAnimating]; |
| 265 } | 267 } |
| 266 | 268 |
| 267 - (NSImage*)compositedImage { | 269 - (NSImage*)compositedImage { |
| 268 NSRect bounds = [self bounds]; | 270 NSRect bounds = [self bounds]; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 - (void)drawBadgeWithinFrame:(NSRect)frame { | 304 - (void)drawBadgeWithinFrame:(NSRect)frame { |
| 303 gfx::CanvasSkiaPaint canvas(frame, false); | 305 gfx::CanvasSkiaPaint canvas(frame, false); |
| 304 canvas.set_composite_alpha(true); | 306 canvas.set_composite_alpha(true); |
| 305 gfx::Rect boundingRect(NSRectToCGRect(frame)); | 307 gfx::Rect boundingRect(NSRectToCGRect(frame)); |
| 306 extensionAction_->PaintBadge(&canvas, boundingRect, tabId_); | 308 extensionAction_->PaintBadge(&canvas, boundingRect, tabId_); |
| 307 } | 309 } |
| 308 | 310 |
| 309 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 311 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 310 gfx::ScopedNSGraphicsContextSaveGState scopedGState; | 312 gfx::ScopedNSGraphicsContextSaveGState scopedGState; |
| 311 [super drawWithFrame:cellFrame inView:controlView]; | 313 [super drawWithFrame:cellFrame inView:controlView]; |
| 314 bool enabled = extensionAction_->GetIsVisible(tabId_); |
| 312 const NSSize imageSize = self.image.size; | 315 const NSSize imageSize = self.image.size; |
| 313 const NSRect imageRect = | 316 const NSRect imageRect = |
| 314 NSMakeRect(std::floor((NSWidth(cellFrame) - imageSize.width) / 2.0), | 317 NSMakeRect(std::floor((NSWidth(cellFrame) - imageSize.width) / 2.0), |
| 315 std::floor((NSHeight(cellFrame) - imageSize.height) / 2.0), | 318 std::floor((NSHeight(cellFrame) - imageSize.height) / 2.0), |
| 316 imageSize.width, imageSize.height); | 319 imageSize.width, imageSize.height); |
| 317 [self.image drawInRect:imageRect | 320 [self.image drawInRect:imageRect |
| 318 fromRect:NSZeroRect | 321 fromRect:NSZeroRect |
| 319 operation:NSCompositeSourceOver | 322 operation:NSCompositeSourceOver |
| 320 fraction:1.0 | 323 fraction:enabled ? 1.0 : 0.4 |
| 321 respectFlipped:YES | 324 respectFlipped:YES |
| 322 hints:nil]; | 325 hints:nil]; |
| 323 | 326 |
| 324 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; | 327 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; |
| 325 [self drawBadgeWithinFrame:cellFrame]; | 328 [self drawBadgeWithinFrame:cellFrame]; |
| 326 } | 329 } |
| 327 | 330 |
| 328 @end | 331 @end |
| OLD | NEW |