#include "base/logging.h"
#include "base/strings/sys_string_conversions.h"
-#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_action.h"
#include "chrome/browser/extensions/extension_action_icon_factory.h"
#include "chrome/browser/extensions/extension_action_manager.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/cocoa/extensions/extension_action_context_menu_controller.h"
-#include "chrome/common/extensions/extension.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
-#include "content/public/browser/notification_source.h"
+#include "extensions/common/extension.h"
#include "grit/theme_resources.h"
#include "skia/ext/skia_utils_mac.h"
-#import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h"
-#include "ui/base/resource/resource_bundle.h"
+#import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h"
#include "ui/gfx/canvas_skia_paint.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/rect.h"
// A helper class to bridge the asynchronous Skia bitmap loading mechanism to
// the extension's button.
class ExtensionActionIconFactoryBridge
- : public content::NotificationObserver,
- public ExtensionActionIconFactory::Observer {
+ : public ExtensionActionIconFactory::Observer {
public:
ExtensionActionIconFactoryBridge(BrowserActionButton* owner,
Profile* profile,
: owner_(owner),
browser_action_([[owner cell] extensionAction]),
icon_factory_(profile, extension, browser_action_, this) {
- registrar_.Add(
- this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED,
- content::Source<ExtensionAction>(browser_action_));
}
virtual ~ExtensionActionIconFactoryBridge() {}
[owner_ updateState];
}
- // Overridden from content::NotificationObserver.
- virtual void Observe(
- int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE {
- if (type == chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED)
- [owner_ updateState];
- else
- NOTREACHED();
- }
-
gfx::Image GetIcon(int tabId) {
return icon_factory_.GetIcon(tabId);
}
// updates to the icon.
ExtensionActionIconFactory icon_factory_;
- // Used for registering to receive notifications and automatic clean up.
- content::NotificationRegistrar registrar_;
-
DISALLOW_COPY_AND_ASSIGN(ExtensionActionIconFactoryBridge);
};
ExtensionAction* browser_action =
extensions::ExtensionActionManager::Get(browser->profile())->
GetBrowserAction(*extension);
+ CHECK(browser_action)
+ << "Don't create a BrowserActionButton if there is no browser action.";
[cell setExtensionAction:browser_action];
[cell
accessibilitySetOverrideValue:base::SysUTF8ToNSString(extension->name())
}
- (void)mouseDown:(NSEvent*)theEvent {
- [[self cell] setHighlighted:YES];
- dragCouldStart_ = YES;
- dragStartPoint_ = [theEvent locationInWindow];
+ NSPoint location = [self convertPoint:[theEvent locationInWindow]
+ fromView:nil];
+ if (NSPointInRect(location, [self bounds])) {
+ [[self cell] setHighlighted:YES];
+ dragCouldStart_ = YES;
+ dragStartPoint_ = [theEvent locationInWindow];
+ }
}
- (void)mouseDragged:(NSEvent*)theEvent {
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
gfx::ScopedNSGraphicsContextSaveGState scopedGState;
[super drawWithFrame:cellFrame inView:controlView];
+ CHECK(extensionAction_);
bool enabled = extensionAction_->GetIsVisible(tabId_);
const NSSize imageSize = self.image.size;
const NSRect imageRect =