summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/base_bubble_controller.mm
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/cocoa/base_bubble_controller.mm')
-rw-r--r--chrome/browser/cocoa/base_bubble_controller.mm34
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;
}