From 41e4a1db55ae404445a3b70a4b266709a5dddb1b Mon Sep 17 00:00:00 2001 From: "andybons@chromium.org" Date: Fri, 18 Dec 2009 22:40:00 +0000 Subject: [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 --- .../cocoa/extensions/browser_actions_controller.mm | 9 +++--- chrome/browser/cocoa/location_bar_view_mac.h | 6 ++++ chrome/browser/cocoa/location_bar_view_mac.mm | 32 ++++++++++++++++++---- .../extensions/extension_browser_event_router.cc | 4 +-- 4 files changed, 38 insertions(+), 13 deletions(-) (limited to 'chrome') 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 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(popup_->host()) != details) - // return; - - //HidePopup(); - NOTIMPLEMENTED(); + if (popupController_ && + Details([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); -- cgit v1.1