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" |
11 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
12 #include "chrome/browser/extensions/image_loading_tracker.h" | 12 #include "chrome/browser/extensions/image_loading_tracker.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 #import "chrome/browser/ui/cocoa/image_utils.h" | 14 #import "chrome/browser/ui/cocoa/image_utils.h" |
15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
16 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
17 #include "chrome/common/extensions/extension_action.h" | 17 #include "chrome/common/extensions/extension_action.h" |
18 #include "chrome/common/extensions/extension_resource.h" | 18 #include "chrome/common/extensions/extension_resource.h" |
19 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
20 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
21 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_source.h" |
22 #include "grit/theme_resources.h" | 22 #include "grit/theme_resources.h" |
23 #include "skia/ext/skia_utils_mac.h" | 23 #include "skia/ext/skia_utils_mac.h" |
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/image/image_skia.h" | |
29 #include "ui/gfx/image/image_skia_util_mac.h" | |
28 #include "ui/gfx/rect.h" | 30 #include "ui/gfx/rect.h" |
29 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 31 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
30 #include "ui/gfx/size.h" | 32 #include "ui/gfx/size.h" |
31 | 33 |
32 using extensions::Extension; | 34 using extensions::Extension; |
33 | 35 |
34 NSString* const kBrowserActionButtonDraggingNotification = | 36 NSString* const kBrowserActionButtonDraggingNotification = |
35 @"BrowserActionButtonDraggingNotification"; | 37 @"BrowserActionButtonDraggingNotification"; |
36 NSString* const kBrowserActionButtonDragEndNotification = | 38 NSString* const kBrowserActionButtonDragEndNotification = |
37 @"BrowserActionButtonDragEndNotification"; | 39 @"BrowserActionButtonDragEndNotification"; |
(...skipping 27 matching lines...) Expand all Loading... | |
65 this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, | 67 this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, |
66 content::Source<ExtensionAction>(browser_action_)); | 68 content::Source<ExtensionAction>(browser_action_)); |
67 } | 69 } |
68 | 70 |
69 ~ExtensionImageTrackerBridge() {} | 71 ~ExtensionImageTrackerBridge() {} |
70 | 72 |
71 // ImageLoadingTracker::Observer implementation. | 73 // ImageLoadingTracker::Observer implementation. |
72 void OnImageLoaded(const gfx::Image& image, | 74 void OnImageLoaded(const gfx::Image& image, |
73 const std::string& extension_id, | 75 const std::string& extension_id, |
74 int index) OVERRIDE { | 76 int index) OVERRIDE { |
75 browser_action_->CacheIcon(browser_action_->default_icon_path(), image); | 77 browser_action_->CacheIcon(browser_action_->default_icon_path(), |
78 *image.ToImageSkia()); | |
76 [owner_ updateState]; | 79 [owner_ updateState]; |
77 } | 80 } |
78 | 81 |
79 // Overridden from content::NotificationObserver. | 82 // Overridden from content::NotificationObserver. |
80 void Observe(int type, | 83 void Observe(int type, |
81 const content::NotificationSource& source, | 84 const content::NotificationSource& source, |
82 const content::NotificationDetails& details) { | 85 const content::NotificationDetails& details) { |
83 if (type == chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED) | 86 if (type == chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED) |
84 [owner_ updateState]; | 87 [owner_ updateState]; |
85 else | 88 else |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 if (tabId_ < 0) | 245 if (tabId_ < 0) |
243 return; | 246 return; |
244 | 247 |
245 std::string tooltip = extension_->browser_action()->GetTitle(tabId_); | 248 std::string tooltip = extension_->browser_action()->GetTitle(tabId_); |
246 if (tooltip.empty()) { | 249 if (tooltip.empty()) { |
247 [self setToolTip:nil]; | 250 [self setToolTip:nil]; |
248 } else { | 251 } else { |
249 [self setToolTip:base::SysUTF8ToNSString(tooltip)]; | 252 [self setToolTip:base::SysUTF8ToNSString(tooltip)]; |
250 } | 253 } |
251 | 254 |
252 gfx::Image image = extension_->browser_action()->GetIcon(tabId_); | 255 gfx::ImageSkia image = extension_->browser_action()->GetIcon(tabId_); |
253 if (!image.IsEmpty()) | 256 if (!image.empty()) |
254 [self setImage:image.ToNSImage()]; | 257 [self setImage:gfx::NSImageFromImageSkia(image)]; |
Robert Sesek
2012/08/07 21:44:24
Shouldn't this use gfx::Image because it's paintin
tbarzic
2012/08/07 22:29:52
wouldn't that do basically the same thing (convert
Robert Sesek
2012/08/08 16:02:06
Yes, that's what it would do. We've standardized o
tbarzic
2012/08/08 18:53:51
OK then.. Done.
| |
255 | 258 |
256 [[self cell] setTabId:tabId_]; | 259 [[self cell] setTabId:tabId_]; |
257 | 260 |
258 bool enabled = extension_->browser_action()->GetIsVisible(tabId_); | 261 bool enabled = extension_->browser_action()->GetIsVisible(tabId_); |
259 [self setEnabled:enabled ? YES : NO]; | 262 [self setEnabled:enabled ? YES : NO]; |
260 | 263 |
261 [self setNeedsDisplay:YES]; | 264 [self setNeedsDisplay:YES]; |
262 } | 265 } |
263 | 266 |
264 - (BOOL)isAnimating { | 267 - (BOOL)isAnimating { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 } | 310 } |
308 | 311 |
309 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 312 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
310 gfx::ScopedNSGraphicsContextSaveGState scopedGState; | 313 gfx::ScopedNSGraphicsContextSaveGState scopedGState; |
311 [super drawInteriorWithFrame:cellFrame inView:controlView]; | 314 [super drawInteriorWithFrame:cellFrame inView:controlView]; |
312 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; | 315 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; |
313 [self drawBadgeWithinFrame:cellFrame]; | 316 [self drawBadgeWithinFrame:cellFrame]; |
314 } | 317 } |
315 | 318 |
316 @end | 319 @end |
OLD | NEW |