| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/common/extensions/extension_action.h" | 17 #include "chrome/common/extensions/extension_action.h" |
| 17 #include "chrome/common/extensions/extension_resource.h" | 18 #include "chrome/common/extensions/extension_resource.h" |
| 18 #include "content/common/notification_observer.h" | 19 #include "content/common/notification_observer.h" |
| 19 #include "content/common/notification_registrar.h" | 20 #include "content/common/notification_registrar.h" |
| 20 #include "content/common/notification_source.h" | 21 #include "content/common/notification_source.h" |
| 21 #include "content/common/notification_type.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/gfx/canvas_skia_paint.h" | 24 #include "ui/gfx/canvas_skia_paint.h" |
| 25 #include "ui/gfx/rect.h" | 25 #include "ui/gfx/rect.h" |
| 26 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 26 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 27 #include "ui/gfx/size.h" | 27 #include "ui/gfx/size.h" |
| 28 | 28 |
| 29 NSString* const kBrowserActionButtonUpdatedNotification = | 29 NSString* const kBrowserActionButtonUpdatedNotification = |
| 30 @"BrowserActionButtonUpdatedNotification"; | 30 @"BrowserActionButtonUpdatedNotification"; |
| 31 | 31 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 51 tracker_(this) { | 51 tracker_(this) { |
| 52 // The Browser Action API does not allow the default icon path to be | 52 // The Browser Action API does not allow the default icon path to be |
| 53 // changed at runtime, so we can load this now and cache it. | 53 // changed at runtime, so we can load this now and cache it. |
| 54 std::string path = extension->browser_action()->default_icon_path(); | 54 std::string path = extension->browser_action()->default_icon_path(); |
| 55 if (!path.empty()) { | 55 if (!path.empty()) { |
| 56 tracker_.LoadImage(extension, extension->GetResource(path), | 56 tracker_.LoadImage(extension, extension->GetResource(path), |
| 57 gfx::Size(Extension::kBrowserActionIconMaxSize, | 57 gfx::Size(Extension::kBrowserActionIconMaxSize, |
| 58 Extension::kBrowserActionIconMaxSize), | 58 Extension::kBrowserActionIconMaxSize), |
| 59 ImageLoadingTracker::DONT_CACHE); | 59 ImageLoadingTracker::DONT_CACHE); |
| 60 } | 60 } |
| 61 registrar_.Add(this, NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, | 61 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, |
| 62 Source<ExtensionAction>(extension->browser_action())); | 62 Source<ExtensionAction>(extension->browser_action())); |
| 63 } | 63 } |
| 64 | 64 |
| 65 ~ExtensionImageTrackerBridge() {} | 65 ~ExtensionImageTrackerBridge() {} |
| 66 | 66 |
| 67 // ImageLoadingTracker::Observer implementation. | 67 // ImageLoadingTracker::Observer implementation. |
| 68 void OnImageLoaded(SkBitmap* image, const ExtensionResource& resource, | 68 void OnImageLoaded(SkBitmap* image, const ExtensionResource& resource, |
| 69 int index) { | 69 int index) { |
| 70 if (image) | 70 if (image) |
| 71 [owner_ setDefaultIcon:gfx::SkBitmapToNSImage(*image)]; | 71 [owner_ setDefaultIcon:gfx::SkBitmapToNSImage(*image)]; |
| 72 [owner_ updateState]; | 72 [owner_ updateState]; |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Overridden from NotificationObserver. | 75 // Overridden from NotificationObserver. |
| 76 void Observe(NotificationType type, | 76 void Observe(int type, |
| 77 const NotificationSource& source, | 77 const NotificationSource& source, |
| 78 const NotificationDetails& details) { | 78 const NotificationDetails& details) { |
| 79 if (type == NotificationType::EXTENSION_BROWSER_ACTION_UPDATED) | 79 if (type == chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED) |
| 80 [owner_ updateState]; | 80 [owner_ updateState]; |
| 81 else | 81 else |
| 82 NOTREACHED(); | 82 NOTREACHED(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 private: | 85 private: |
| 86 // Weak. Owns us. | 86 // Weak. Owns us. |
| 87 BrowserActionButton* owner_; | 87 BrowserActionButton* owner_; |
| 88 | 88 |
| 89 // Loads the button's icons for us on the file thread. | 89 // Loads the button's icons for us on the file thread. |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 } | 313 } |
| 314 | 314 |
| 315 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 315 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 316 gfx::ScopedNSGraphicsContextSaveGState scopedGState; | 316 gfx::ScopedNSGraphicsContextSaveGState scopedGState; |
| 317 [super drawInteriorWithFrame:cellFrame inView:controlView]; | 317 [super drawInteriorWithFrame:cellFrame inView:controlView]; |
| 318 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; | 318 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; |
| 319 [self drawBadgeWithinFrame:cellFrame]; | 319 [self drawBadgeWithinFrame:cellFrame]; |
| 320 } | 320 } |
| 321 | 321 |
| 322 @end | 322 @end |
| OLD | NEW |