diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-16 16:07:45 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-16 16:07:45 +0000 |
commit | 1812da22819f3112a6551c8332e175f5a3387300 (patch) | |
tree | f3f6d7388e41ddee92b28c3a16f6b22abd0159a4 /chrome/browser/ui/cocoa | |
parent | 3ac71bf7f18b40dc499b92e5c7cb6424a3f1871f (diff) | |
download | chromium_src-1812da22819f3112a6551c8332e175f5a3387300.zip chromium_src-1812da22819f3112a6551c8332e175f5a3387300.tar.gz chromium_src-1812da22819f3112a6551c8332e175f5a3387300.tar.bz2 |
Only close popup bubble when a tab switch happens.
BUG=127471
TEST=as in bug
Review URL: https://chromiumcodereview.appspot.com/10392108
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137433 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/cocoa')
4 files changed, 34 insertions, 36 deletions
diff --git a/chrome/browser/ui/cocoa/base_bubble_controller.h b/chrome/browser/ui/cocoa/base_bubble_controller.h index 46b1de1..12a438c 100644 --- a/chrome/browser/ui/cocoa/base_bubble_controller.h +++ b/chrome/browser/ui/cocoa/base_bubble_controller.h @@ -7,11 +7,8 @@ #import "base/mac/cocoa_protocols.h" #include "base/memory/scoped_ptr.h" -namespace BaseBubbleControllerInternal { -class Bridge; -} - @class InfoBubbleView; +class TabStripModelObserverBridge; // Base class for bubble controllers. Manages a xib that contains an // InfoBubbleWindow which contains an InfoBubbleView. Contains code to close @@ -29,8 +26,8 @@ class Bridge; NSWindow* parentWindow_; // weak NSPoint anchor_; IBOutlet InfoBubbleView* bubble_; // to set arrow position - // Bridge that listens for notifications. - scoped_ptr<BaseBubbleControllerInternal::Bridge> baseBridge_; + // Bridge for tab change notifications. + scoped_ptr<TabStripModelObserverBridge> tabStripObserverBridge_; // Non-nil only on 10.7+. Both weak, owned by AppKit. // A local event tap that will dismiss the bubble when a click is delivered diff --git a/chrome/browser/ui/cocoa/base_bubble_controller.mm b/chrome/browser/ui/cocoa/base_bubble_controller.mm index 08b3912..9ac3749 100644 --- a/chrome/browser/ui/cocoa/base_bubble_controller.mm +++ b/chrome/browser/ui/cocoa/base_bubble_controller.mm @@ -10,16 +10,18 @@ #include "base/mac/mac_util.h" #include "base/memory/scoped_nsobject.h" #include "base/string_util.h" +#import "chrome/browser/ui/cocoa/browser_window_controller.h" #import "chrome/browser/ui/cocoa/info_bubble_view.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" -#include "content/public/browser/notification_service.h" -#include "content/public/browser/notification_types.h" +#import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" @interface BaseBubbleController (Private) - (void)updateOriginFromAnchor; +- (void)activateTabWithContents:(TabContentsWrapper*)newContents + previousContents:(TabContentsWrapper*)oldContents + atIndex:(NSInteger)index + userGesture:(bool)wasUserGesture; @end #if !defined(MAC_OS_X_VERSION_10_6) || \ @@ -44,31 +46,6 @@ typedef unsigned long long NSEventMask; @end #endif // MAC_OS_X_VERSION_10_6 -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 content::NotificationObserver { - public: - explicit Bridge(BaseBubbleController* controller) : controller_(controller) { - registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_HIDDEN, - content::NotificationService::AllSources()); - } - - // content::NotificationObserver: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - [controller_ close]; - } - - private: - BaseBubbleController* controller_; // Weak, owns this. - content::NotificationRegistrar registrar_; -}; - -} // namespace BaseBubbleControllerInternal - @implementation BaseBubbleController @synthesize parentWindow = parentWindow_; @@ -142,7 +119,14 @@ class Bridge : public content::NotificationObserver { DCHECK(bubble_); DCHECK_EQ(self, [[self window] delegate]); - baseBridge_.reset(new BaseBubbleControllerInternal::Bridge(self)); + BrowserWindowController* bwc = + [BrowserWindowController browserWindowControllerForWindow:parentWindow_]; + if (bwc) { + TabStripController* tabStripController = [bwc tabStripController]; + TabStripModel* tabStripModel = [tabStripController tabStripModel]; + tabStripObserverBridge_.reset(new TabStripModelObserverBridge(tabStripModel, + self)); + } [bubble_ setArrowLocation:info_bubble::kTopRight]; } @@ -205,6 +189,8 @@ class Bridge : public content::NotificationObserver { resignationObserver_ = nil; } + tabStripObserverBridge_.reset(); + [[[self window] parentWindow] removeChildWindow:[self window]]; [super close]; } @@ -305,4 +291,12 @@ class Bridge : public content::NotificationObserver { [window setFrameOrigin:origin]; } +- (void)activateTabWithContents:(TabContentsWrapper*)newContents + previousContents:(TabContentsWrapper*)oldContents + atIndex:(NSInteger)index + userGesture:(bool)wasUserGesture { + // The user switched tabs; close. + [self close]; +} + @end // BaseBubbleController diff --git a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.h b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.h index 3c365f6..18b6753 100644 --- a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.h +++ b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.h @@ -161,6 +161,9 @@ class TabStripModel; browser:(Browser*)browser delegate:(id<TabStripControllerDelegate>)delegate; +// Returns the model behind this controller. +- (TabStripModel*)tabStripModel; + // Return the view for the currently active tab. - (NSView*)activeTabView; diff --git a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm index c1bb28d..3cee8a5 100644 --- a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm +++ b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm @@ -1584,6 +1584,10 @@ private: [view setFrame:frame]; } +- (TabStripModel*)tabStripModel { + return tabStripModel_; +} + - (NSView*)activeTabView { int activeIndex = tabStripModel_->active_index(); // Take closing tabs into account. They can't ever be selected. |