diff options
| author | Ben Murdoch <benm@google.com> | 2010-11-18 18:32:45 +0000 |
|---|---|---|
| committer | Ben Murdoch <benm@google.com> | 2010-11-18 18:38:07 +0000 |
| commit | 513209b27ff55e2841eac0e4120199c23acce758 (patch) | |
| tree | aeba30bb08c5f47c57003544e378a377c297eee6 /chrome/browser/cocoa/base_bubble_controller.mm | |
| parent | 164f7496de0fbee436b385a79ead9e3cb81a50c1 (diff) | |
| download | external_chromium-513209b27ff55e2841eac0e4120199c23acce758.zip external_chromium-513209b27ff55e2841eac0e4120199c23acce758.tar.gz external_chromium-513209b27ff55e2841eac0e4120199c23acce758.tar.bz2 | |
Merge Chromium at r65505: Initial merge by git.
Change-Id: I31d8f1d8cd33caaf7f47ffa7350aef42d5fbdb45
Diffstat (limited to 'chrome/browser/cocoa/base_bubble_controller.mm')
| -rw-r--r-- | chrome/browser/cocoa/base_bubble_controller.mm | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/chrome/browser/cocoa/base_bubble_controller.mm b/chrome/browser/cocoa/base_bubble_controller.mm index a67bc64..e9804c5 100644 --- a/chrome/browser/cocoa/base_bubble_controller.mm +++ b/chrome/browser/cocoa/base_bubble_controller.mm @@ -10,12 +10,41 @@ #include "base/scoped_nsobject.h" #include "base/string_util.h" #import "chrome/browser/cocoa/info_bubble_view.h" +#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" +#include "chrome/common/notification_service.h" +#include "chrome/common/notification_type.h" #include "grit/generated_resources.h" @interface BaseBubbleController (Private) - (void)updateOriginFromAnchor; @end +namespace BaseBubbleControllerInternal { + +// This bridge listens for notifications so that the bubble closes when a user +// switches tabs (including by opening a new one). +class Bridge : public NotificationObserver { + public: + explicit Bridge(BaseBubbleController* controller) : controller_(controller) { + registrar_.Add(this, NotificationType::TAB_CONTENTS_HIDDEN, + NotificationService::AllSources()); + } + + // NotificationObserver: + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + [controller_ close]; + } + + private: + BaseBubbleController* controller_; // Weak, owns this. + NotificationRegistrar registrar_; +}; + +} // namespace BaseBubbleControllerInternal + @implementation BaseBubbleController @synthesize parentWindow = parentWindow_; @@ -62,6 +91,7 @@ if ((self = [super initWithWindow:theWindow])) { parentWindow_ = parentWindow; anchor_ = anchoredAt; + DCHECK(![[self window] delegate]); [theWindow setDelegate:self]; @@ -88,6 +118,8 @@ DCHECK(bubble_); DCHECK_EQ(self, [[self window] delegate]); + base_bridge_.reset(new BaseBubbleControllerInternal::Bridge(self)); + [bubble_ setBubbleType:info_bubble::kWhiteInfoBubble]; [bubble_ setArrowLocation:info_bubble::kTopRight]; } @@ -158,7 +190,7 @@ info_bubble::kBubbleArrowWidth / 2.0, 0); offsets = [[parentWindow_ contentView] convertSize:offsets toView:nil]; if ([bubble_ arrowLocation] == info_bubble::kTopRight) { - origin.x -= NSWidth([window frame]) + offsets.width; + origin.x -= NSWidth([window frame]) - offsets.width; } else { origin.x -= offsets.width; } |
