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 13 matching lines...) Expand all Loading... |
24 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" | 24 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" |
25 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
26 #include "ui/gfx/canvas_skia_paint.h" | 26 #include "ui/gfx/canvas_skia_paint.h" |
27 #include "ui/gfx/image/image.h" | 27 #include "ui/gfx/image/image.h" |
28 #include "ui/gfx/rect.h" | 28 #include "ui/gfx/rect.h" |
29 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 29 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
30 #include "ui/gfx/size.h" | 30 #include "ui/gfx/size.h" |
31 | 31 |
32 using extensions::Extension; | 32 using extensions::Extension; |
33 | 33 |
34 NSString* const kBrowserActionButtonUpdatedNotification = | |
35 @"BrowserActionButtonUpdatedNotification"; | |
36 | |
37 NSString* const kBrowserActionButtonDraggingNotification = | 34 NSString* const kBrowserActionButtonDraggingNotification = |
38 @"BrowserActionButtonDraggingNotification"; | 35 @"BrowserActionButtonDraggingNotification"; |
39 NSString* const kBrowserActionButtonDragEndNotification = | 36 NSString* const kBrowserActionButtonDragEndNotification = |
40 @"BrowserActionButtonDragEndNotification"; | 37 @"BrowserActionButtonDragEndNotification"; |
41 | 38 |
42 static const CGFloat kBrowserActionBadgeOriginYOffset = 5; | 39 static const CGFloat kBrowserActionBadgeOriginYOffset = 5; |
43 | 40 |
44 namespace { | 41 namespace { |
45 const CGFloat kAnimationDuration = 0.2; | 42 const CGFloat kAnimationDuration = 0.2; |
46 } // anonymous namespace | 43 } // anonymous namespace |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 } else if (defaultIcon_) { | 267 } else if (defaultIcon_) { |
271 [self setImage:defaultIcon_]; | 268 [self setImage:defaultIcon_]; |
272 } | 269 } |
273 | 270 |
274 [[self cell] setTabId:tabId_]; | 271 [[self cell] setTabId:tabId_]; |
275 | 272 |
276 bool enabled = extension_->browser_action()->GetIsVisible(tabId_); | 273 bool enabled = extension_->browser_action()->GetIsVisible(tabId_); |
277 [self setEnabled:enabled ? YES : NO]; | 274 [self setEnabled:enabled ? YES : NO]; |
278 | 275 |
279 [self setNeedsDisplay:YES]; | 276 [self setNeedsDisplay:YES]; |
280 | |
281 [[NSNotificationCenter defaultCenter] | |
282 postNotificationName:kBrowserActionButtonUpdatedNotification | |
283 object:self]; | |
284 } | 277 } |
285 | 278 |
286 - (BOOL)isAnimating { | 279 - (BOOL)isAnimating { |
287 return [moveAnimation_ isAnimating]; | 280 return [moveAnimation_ isAnimating]; |
288 } | 281 } |
289 | 282 |
290 - (NSImage*)compositedImage { | 283 - (NSImage*)compositedImage { |
291 NSRect bounds = [self bounds]; | 284 NSRect bounds = [self bounds]; |
292 NSImage* image = [[[NSImage alloc] initWithSize:bounds.size] autorelease]; | 285 NSImage* image = [[[NSImage alloc] initWithSize:bounds.size] autorelease]; |
293 [image lockFocus]; | 286 [image lockFocus]; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 } | 322 } |
330 | 323 |
331 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 324 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
332 gfx::ScopedNSGraphicsContextSaveGState scopedGState; | 325 gfx::ScopedNSGraphicsContextSaveGState scopedGState; |
333 [super drawInteriorWithFrame:cellFrame inView:controlView]; | 326 [super drawInteriorWithFrame:cellFrame inView:controlView]; |
334 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; | 327 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; |
335 [self drawBadgeWithinFrame:cellFrame]; | 328 [self drawBadgeWithinFrame:cellFrame]; |
336 } | 329 } |
337 | 330 |
338 @end | 331 @end |
OLD | NEW |