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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 } | 166 } |
167 | 167 |
168 return self; | 168 return self; |
169 } | 169 } |
170 | 170 |
171 - (BOOL)acceptsFirstResponder { | 171 - (BOOL)acceptsFirstResponder { |
172 return YES; | 172 return YES; |
173 } | 173 } |
174 | 174 |
175 - (void)mouseDown:(NSEvent*)theEvent { | 175 - (void)mouseDown:(NSEvent*)theEvent { |
176 [[self cell] setHighlighted:YES]; | 176 if ([self isEnabled]) |
| 177 [[self cell] setHighlighted:YES]; |
177 dragCouldStart_ = YES; | 178 dragCouldStart_ = YES; |
178 } | 179 } |
179 | 180 |
180 - (void)mouseDragged:(NSEvent*)theEvent { | 181 - (void)mouseDragged:(NSEvent*)theEvent { |
181 if (!dragCouldStart_) | 182 if (!dragCouldStart_) |
182 return; | 183 return; |
183 | 184 |
184 if (!isBeingDragged_) { | 185 if (!isBeingDragged_) { |
185 // The start of a drag. Position the button above all others. | 186 // The start of a drag. Position the button above all others. |
186 [[self superview] addSubview:self positioned:NSWindowAbove relativeTo:nil]; | 187 [[self superview] addSubview:self positioned:NSWindowAbove relativeTo:nil]; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 } | 250 } |
250 | 251 |
251 - (void)setTabSpecificIcon:(NSImage*)image { | 252 - (void)setTabSpecificIcon:(NSImage*)image { |
252 tabSpecificIcon_.reset([image retain]); | 253 tabSpecificIcon_.reset([image retain]); |
253 } | 254 } |
254 | 255 |
255 - (void)updateState { | 256 - (void)updateState { |
256 if (tabId_ < 0) | 257 if (tabId_ < 0) |
257 return; | 258 return; |
258 | 259 |
259 std::string tooltip = extension_->browser_action()->GetTitle(tabId_); | 260 ExtensionAction* browser_action = extension_->browser_action(); |
| 261 CHECK(browser_action); |
| 262 |
| 263 [self setEnabled:browser_action->GetIsVisible(tabId_)]; |
| 264 |
| 265 std::string tooltip = browser_action->GetTitle(tabId_); |
260 if (tooltip.empty()) { | 266 if (tooltip.empty()) { |
261 [self setToolTip:nil]; | 267 [self setToolTip:nil]; |
262 } else { | 268 } else { |
263 [self setToolTip:base::SysUTF8ToNSString(tooltip)]; | 269 [self setToolTip:base::SysUTF8ToNSString(tooltip)]; |
264 } | 270 } |
265 | 271 |
266 SkBitmap image = extension_->browser_action()->GetIcon(tabId_); | 272 SkBitmap image = browser_action->GetIcon(tabId_); |
267 if (!image.isNull()) { | 273 if (!image.isNull()) { |
268 [self setTabSpecificIcon:gfx::SkBitmapToNSImage(image)]; | 274 [self setTabSpecificIcon:gfx::SkBitmapToNSImage(image)]; |
269 [self setImage:tabSpecificIcon_]; | 275 [self setImage:tabSpecificIcon_]; |
270 } else if (defaultIcon_) { | 276 } else if (defaultIcon_) { |
271 [self setImage:defaultIcon_]; | 277 [self setImage:defaultIcon_]; |
272 } | 278 } |
273 | 279 |
274 [[self cell] setTabId:tabId_]; | 280 [[self cell] setTabId:tabId_]; |
275 | 281 |
276 [self setNeedsDisplay:YES]; | 282 [self setNeedsDisplay:YES]; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 } | 332 } |
327 | 333 |
328 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 334 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
329 gfx::ScopedNSGraphicsContextSaveGState scopedGState; | 335 gfx::ScopedNSGraphicsContextSaveGState scopedGState; |
330 [super drawInteriorWithFrame:cellFrame inView:controlView]; | 336 [super drawInteriorWithFrame:cellFrame inView:controlView]; |
331 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; | 337 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; |
332 [self drawBadgeWithinFrame:cellFrame]; | 338 [self drawBadgeWithinFrame:cellFrame]; |
333 } | 339 } |
334 | 340 |
335 @end | 341 @end |
OLD | NEW |