diff options
author | andybons@chromium.org <andybons@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-18 22:40:00 +0000 |
---|---|---|
committer | andybons@chromium.org <andybons@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-18 22:40:00 +0000 |
commit | 41e4a1db55ae404445a3b70a4b266709a5dddb1b (patch) | |
tree | 90c01a43cd75791ba45e89cbf7e2f5ac789ee28b /chrome | |
parent | 03bbb08c93cf7fd64ac0cc29f43f760af3c8888e (diff) | |
download | chromium_src-41e4a1db55ae404445a3b70a4b266709a5dddb1b.zip chromium_src-41e4a1db55ae404445a3b70a4b266709a5dddb1b.tar.gz chromium_src-41e4a1db55ae404445a3b70a4b266709a5dddb1b.tar.bz2 |
[Mac] Implements popups for Page Actions, plus fixes a leak within the Browser Action popup class.
BUG=12281
TEST=Install the RSS feed page action extension. Go to a site with multiple feeds on the page, like http://ask.metafilter.com, observe a popup upon clicking the page action icon.
Review URL: http://codereview.chromium.org/500138
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34992 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
4 files changed, 38 insertions, 13 deletions
diff --git a/chrome/browser/cocoa/extensions/browser_actions_controller.mm b/chrome/browser/cocoa/extensions/browser_actions_controller.mm index 2549267..66b0d5b 100644 --- a/chrome/browser/cocoa/extensions/browser_actions_controller.mm +++ b/chrome/browser/cocoa/extensions/browser_actions_controller.mm @@ -441,11 +441,10 @@ class ExtensionsServiceObserverBridge : public NotificationObserver { // Adjust the anchor point to be at the center of the browser action button. arrowPoint.x += kBrowserActionWidth / 2; - popupController_ = - [[ExtensionPopupController showURL:action->popup_url() - inBrowser:browser_ - anchoredAt:arrowPoint - arrowLocation:kTopRight] retain]; + popupController_ = [ExtensionPopupController showURL:action->popup_url() + inBrowser:browser_ + anchoredAt:arrowPoint + arrowLocation:kTopRight]; } else { ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted( profile_, action->extension_id(), browser_); diff --git a/chrome/browser/cocoa/location_bar_view_mac.h b/chrome/browser/cocoa/location_bar_view_mac.h index 45a891a..c2af2dd 100644 --- a/chrome/browser/cocoa/location_bar_view_mac.h +++ b/chrome/browser/cocoa/location_bar_view_mac.h @@ -23,6 +23,7 @@ @class AutocompleteTextField; class BubblePositioner; class CommandUpdater; +@class ExtensionPopupController; class Profile; class ToolbarModel; @@ -83,6 +84,7 @@ class LocationBarViewMac : public AutocompleteEditController, virtual std::wstring GetTitle() const; NSImage* GetTabButtonImage(); + AutocompleteTextField* GetAutocompleteTextField() { return field_; } // Internals of OnChanged(), pulled out for purposes of unit // testing. Sets up |field| based on the parameters, which are @@ -207,6 +209,7 @@ class LocationBarViewMac : public AutocompleteEditController, virtual void Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details); + void HidePopup(); // The location bar view that owns us. LocationBarViewMac* owner_; @@ -222,6 +225,9 @@ class LocationBarViewMac : public AutocompleteEditController, typedef std::map<std::string, SkBitmap> PageActionMap; PageActionMap page_action_icons_; + // The controller for the popup displayed if a page action has one. Weak. + ExtensionPopupController* popupController_; + // The object that is waiting for the image loading to complete // asynchronously. ImageLoadingTracker* tracker_; diff --git a/chrome/browser/cocoa/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar_view_mac.mm index fbe9f09..ced4a82 100644 --- a/chrome/browser/cocoa/location_bar_view_mac.mm +++ b/chrome/browser/cocoa/location_bar_view_mac.mm @@ -17,6 +17,7 @@ #import "chrome/browser/cocoa/autocomplete_text_field.h" #import "chrome/browser/cocoa/autocomplete_text_field_cell.h" #include "chrome/browser/cocoa/event_utils.h" +#import "chrome/browser/cocoa/extensions/extension_popup_controller.h" #include "chrome/browser/command_updater.h" #include "chrome/browser/extensions/extension_browser_event_router.h" #include "chrome/browser/extensions/extensions_service.h" @@ -518,7 +519,22 @@ LocationBarViewMac::PageActionImageView::~PageActionImageView() { // popup depending on the Page Action. bool LocationBarViewMac::PageActionImageView::OnMousePressed(NSRect bounds) { if (page_action_->has_popup()) { - NOTIMPLEMENTED(); + AutocompleteTextField* textField = owner_->GetAutocompleteTextField(); + NSWindow* window = [textField window]; + NSRect relativeBounds = [[window contentView] convertRect:bounds + fromView:textField]; + NSPoint arrowPoint = [window convertBaseToScreen:NSMakePoint( + NSMinX(relativeBounds), + NSMinY(relativeBounds))]; + + // Adjust the anchor point to be at the center of the page action icon. + arrowPoint.x += [GetImage() size].width / 2; + + popupController_ = + [ExtensionPopupController showURL:page_action_->popup_url() + inBrowser:BrowserList::GetLastActive() + anchoredAt:arrowPoint + arrowLocation:kTopRight]; } else { ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted( profile_, page_action_->extension_id(), page_action_->id(), @@ -607,11 +623,10 @@ void LocationBarViewMac::PageActionImageView::Observe( switch (type.value) { case NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE: // If we aren't the host of the popup, then disregard the notification. - //if (!popup_ || Details<ExtensionHost>(popup_->host()) != details) - // return; - - //HidePopup(); - NOTIMPLEMENTED(); + if (popupController_ && + Details<ExtensionHost>([popupController_ host]) == details) { + HidePopup(); + } break; default: NOTREACHED() << "Unexpected notification"; @@ -619,6 +634,11 @@ void LocationBarViewMac::PageActionImageView::Observe( } } +void LocationBarViewMac::PageActionImageView::HidePopup() { + [popupController_ close]; + popupController_ = nil; +} + // PageActionViewList----------------------------------------------------------- void LocationBarViewMac::PageActionViewList::DeleteAll() { diff --git a/chrome/browser/extensions/extension_browser_event_router.cc b/chrome/browser/extensions/extension_browser_event_router.cc index 0fe39a9..af03497 100644 --- a/chrome/browser/extensions/extension_browser_event_router.cc +++ b/chrome/browser/extensions/extension_browser_event_router.cc @@ -212,8 +212,8 @@ void ExtensionBrowserEventRouter::OnBrowserSetLastActive( } void ExtensionBrowserEventRouter::TabCreatedAt(TabContents* contents, - int index, - bool foreground) { + int index, + bool foreground) { DispatchEventWithTab(contents->profile(), events::kOnTabCreated, contents); RegisterForTabNotifications(contents); |