Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1215)

Unified Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.mm

Issue 9703084: [Mac] Make BookmarkBubbleController is-a BaseBubbleController. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.mm
diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.mm
index 61e51ac245cb50bc28d58345192c4e9fbc88deef..04112a5d13833a538e557210baffbf19ca98675b 100644
--- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.mm
+++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.mm
@@ -70,7 +70,6 @@ void BookmarkBubbleNotificationBridge::Observe(
@interface BookmarkBubbleController (PrivateAPI)
- (void)updateBookmarkNode;
- (void)fillInFolderList;
-- (void)parentWindowWillClose:(NSNotification*)notification;
@end
@implementation BookmarkBubbleController
@@ -91,26 +90,19 @@ void BookmarkBubbleNotificationBridge::Observe(
model:(BookmarkModel*)model
node:(const BookmarkNode*)node
alreadyBookmarked:(BOOL)alreadyBookmarked {
- NSString* nibPath =
- [base::mac::FrameworkBundle() pathForResource:@"BookmarkBubble"
- ofType:@"nib"];
- if ((self = [super initWithWindowNibPath:nibPath owner:self])) {
- parentWindow_ = parentWindow;
+ if ((self = [super initWithWindowNibPath:@"BookmarkBubble"
+ parentWindow:parentWindow
+ anchoredAt:NSZeroPoint])) {
model_ = model;
node_ = node;
alreadyBookmarked_ = alreadyBookmarked;
-
- // Watch to see if the parent window closes, and if so, close this one.
- NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
- [center addObserver:self
- selector:@selector(parentWindowWillClose:)
- name:NSWindowWillCloseNotification
- object:parentWindow_];
}
return self;
}
- (void)awakeFromNib {
+ [super awakeFromNib];
+
// Check if NSTextFieldCell supports the method. This check is in place as
// only 10.6 and greater support the setUsesSingleLineMode method.
// TODO(kushi.p): Remove this when the project hits a 10.6+ only state.
@@ -121,11 +113,6 @@ void BookmarkBubbleNotificationBridge::Observe(
}
}
-- (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- [super dealloc];
-}
-
// If this is a new bookmark somewhere visible (e.g. on the bookmark
// bar), pulse it. Else, call ourself recursively with our parent
// until we find something visible to pulse.
@@ -177,42 +164,37 @@ void BookmarkBubbleNotificationBridge::Observe(
[self close];
}
-- (void)parentWindowWillClose:(NSNotification*)notification {
- [self close];
-}
-
- (void)windowWillClose:(NSNotification*)notification {
// We caught a close so we don't need to watch for the parent closing.
- [[NSNotificationCenter defaultCenter] removeObserver:self];
bookmark_observer_.reset(NULL);
chrome_observer_.reset(NULL);
[self stopPulsingBookmarkButton];
- [self autorelease];
+ [super windowWillClose:notification];
}
-// We want this to be a child of a browser window. addChildWindow:
-// (called from this function) will bring the window on-screen;
-// unfortunately, [NSWindowController showWindow:] will also bring it
-// on-screen (but will cause unexpected changes to the window's
-// position). We cannot have an addChildWindow: and a subsequent
-// showWindow:. Thus, we have our own version.
+// Override -[BaseBubbleController showWindow:] to tweak bubble location and
+// set up UI elements.
- (void)showWindow:(id)sender {
+ NSWindow* window = [self window]; // Force load the NIB.
+ NSWindow* parentWindow = self.parentWindow;
BrowserWindowController* bwc =
- [BrowserWindowController browserWindowControllerForWindow:parentWindow_];
+ [BrowserWindowController browserWindowControllerForWindow:parentWindow];
[bwc lockBarVisibilityForOwner:self withAnimation:NO delay:NO];
- NSWindow* window = [self window]; // completes nib load
- [bubble_ setArrowLocation:info_bubble::kTopRight];
+
+ InfoBubbleView* bubble = self.bubble;
+ [bubble setArrowLocation:info_bubble::kTopRight];
+
// Insure decent positioning even in the absence of a browser controller,
// which will occur for some unit tests.
- NSPoint arrowtip = bwc ? [bwc bookmarkBubblePoint] :
+ NSPoint arrowTip = bwc ? [bwc bookmarkBubblePoint] :
NSMakePoint([window frame].size.width, [window frame].size.height);
- NSPoint origin = [parentWindow_ convertBaseToScreen:arrowtip];
- NSPoint bubbleArrowtip = [bubble_ arrowTip];
- bubbleArrowtip = [bubble_ convertPoint:bubbleArrowtip toView:nil];
- origin.y -= bubbleArrowtip.y;
- origin.x -= bubbleArrowtip.x;
- [window setFrameOrigin:origin];
- [parentWindow_ addChildWindow:window ordered:NSWindowAbove];
+ arrowTip = [parentWindow convertBaseToScreen:arrowTip];
+ NSPoint bubbleArrowTip = [bubble arrowTip];
+ bubbleArrowTip = [bubble convertPoint:bubbleArrowTip toView:nil];
+ arrowTip.y -= bubbleArrowTip.y;
+ arrowTip.x -= bubbleArrowTip.x;
+ [window setFrameOrigin:arrowTip];
+
// Default is IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK; "Bookmark".
// If adding for the 1st time the string becomes "Bookmark Added!"
if (!alreadyBookmarked_) {
@@ -237,24 +219,13 @@ void BookmarkBubbleNotificationBridge::Observe(
// Pulse something interesting on the bookmark bar.
[self startPulsingBookmarkButton:node_];
+ [parentWindow addChildWindow:window ordered:NSWindowAbove];
[window makeKeyAndOrderFront:self];
}
- (void)close {
- [[BrowserWindowController browserWindowControllerForWindow:parentWindow_]
+ [[BrowserWindowController browserWindowControllerForWindow:self.parentWindow]
releaseBarVisibilityForOwner:self withAnimation:YES delay:NO];
- [parentWindow_ removeChildWindow:[self window]];
-
- // If you quit while the bubble is open, sometimes we get a
- // DidResignKey before we get our parent's WindowWillClose and
- // sometimes not. We protect against a multiple close (or reference
- // to parentWindow_ at a bad time) by clearing it out once we're
- // done, and by removing ourself from future notifications.
- [[NSNotificationCenter defaultCenter]
- removeObserver:self
- name:NSWindowWillCloseNotification
- object:parentWindow_];
- parentWindow_ = nil;
[super close];
}
@@ -304,7 +275,7 @@ void BookmarkBubbleNotificationBridge::Observe(
// It is possible that due to model change our parent window has been closed
// but the popup is still showing and able to notify the controller of a
// folder change. We ignore the sender in this case.
- if (!parentWindow_)
+ if (!self.parentWindow)
return;
NSMenuItem* selected = [folderPopUpButton_ selectedItem];
ChooseAnotherFolder* chooseItem = [[self class] chooseAnotherFolderObject];
@@ -382,7 +353,7 @@ void BookmarkBubbleNotificationBridge::Observe(
@end // BookmarkBubbleController
-@implementation BookmarkBubbleController(ExposedForUnitTesting)
+@implementation BookmarkBubbleController (ExposedForUnitTesting)
+ (NSString*)chooseAnotherFolderString {
return l10n_util::GetNSStringWithFixup(

Powered by Google App Engine
This is Rietveld 408576698