diff options
6 files changed, 32 insertions, 16 deletions
diff --git a/chrome/browser/cocoa/bookmark_bubble_controller.h b/chrome/browser/cocoa/bookmark_bubble_controller.h index 68f835f..53baeb9 100644 --- a/chrome/browser/cocoa/bookmark_bubble_controller.h +++ b/chrome/browser/cocoa/bookmark_bubble_controller.h @@ -19,7 +19,6 @@ class BookmarkNode; @interface BookmarkBubbleController : NSWindowController<NSWindowDelegate> { @private NSWindow* parentWindow_; // weak - NSPoint topRightForBubble_; // Both weak; owned by the current browser's profile BookmarkModel* model_; // weak @@ -45,7 +44,6 @@ class BookmarkNode; // it desires it to be visible on the screen. It is not shown by the // init routine. Closing of the window happens implicitly on dealloc. - (id)initWithParentWindow:(NSWindow*)parentWindow - topRightForBubble:(NSPoint)topRightForBubble model:(BookmarkModel*)model node:(const BookmarkNode*)node alreadyBookmarked:(BOOL)alreadyBookmarked; diff --git a/chrome/browser/cocoa/bookmark_bubble_controller.mm b/chrome/browser/cocoa/bookmark_bubble_controller.mm index e59d1f6..c3b7cd0 100644 --- a/chrome/browser/cocoa/bookmark_bubble_controller.mm +++ b/chrome/browser/cocoa/bookmark_bubble_controller.mm @@ -7,6 +7,7 @@ #include "base/mac_util.h" #include "base/sys_string_conversions.h" #include "chrome/browser/bookmarks/bookmark_model.h" +#import "chrome/browser/cocoa/browser_window_controller.h" #import "chrome/browser/cocoa/info_bubble_view.h" #include "chrome/browser/metrics/user_metrics.h" #include "grit/generated_resources.h" @@ -39,7 +40,6 @@ } - (id)initWithParentWindow:(NSWindow*)parentWindow - topRightForBubble:(NSPoint)topRightForBubble model:(BookmarkModel*)model node:(const BookmarkNode*)node alreadyBookmarked:(BOOL)alreadyBookmarked { @@ -48,7 +48,6 @@ ofType:@"nib"]; if ((self = [super initWithWindowNibPath:nibPath owner:self])) { parentWindow_ = parentWindow; - topRightForBubble_ = topRightForBubble; model_ = model; node_ = node; alreadyBookmarked_ = alreadyBookmarked; @@ -95,8 +94,15 @@ // position). We cannot have an addChildWindow: and a subsequent // showWindow:. Thus, we have our own version. - (void)showWindow:(id)sender { + BrowserWindowController* bwc = + [BrowserWindowController browserWindowControllerForWindow:parentWindow_]; + [bwc lockBarVisibilityForOwner:self withAnimation:NO delay:NO]; NSWindow* window = [self window]; // completes nib load - NSPoint origin = [parentWindow_ convertBaseToScreen:topRightForBubble_]; + // Insure decent positioning even in the absence of a browser controller, + // which will occur for some unit tests. + NSPoint topRight = bwc ? [bwc topRightForBubble] : + NSMakePoint([window frame].size.width, [window frame].size.height); + NSPoint origin = [parentWindow_ convertBaseToScreen:topRight]; origin.y -= NSHeight([window frame]); origin.x -= NSWidth([window frame]); [window setFrameOrigin:origin]; @@ -125,6 +131,8 @@ } - (void)close { + [[BrowserWindowController browserWindowControllerForWindow:parentWindow_] + releaseBarVisibilityForOwner:self withAnimation:YES delay:NO]; [parentWindow_ removeChildWindow:[self window]]; // If you quit while the bubble is open, sometimes we get a diff --git a/chrome/browser/cocoa/bookmark_bubble_controller_unittest.mm b/chrome/browser/cocoa/bookmark_bubble_controller_unittest.mm index abc991c..556f228 100644 --- a/chrome/browser/cocoa/bookmark_bubble_controller_unittest.mm +++ b/chrome/browser/cocoa/bookmark_bubble_controller_unittest.mm @@ -8,6 +8,7 @@ #include "base/scoped_nsobject.h" #import "chrome/browser/cocoa/bookmark_bubble_controller.h" #include "chrome/browser/cocoa/browser_test_helper.h" +#include "chrome/browser/cocoa/browser_window_controller.h" #import "chrome/browser/cocoa/cocoa_test_helper.h" #import "chrome/browser/cocoa/info_bubble_window.h" #include "testing/gtest/include/gtest/gtest.h" @@ -29,7 +30,6 @@ class BookmarkBubbleControllerTest : public CocoaTest { // TODO(shess): Figure out why CocoaTest::TearDown() needs 3 // passes through the event loop to fully close out these windows. [controller_ close]; - controller_ = nil; CocoaTest::TearDown(); } @@ -42,7 +42,6 @@ class BookmarkBubbleControllerTest : public CocoaTest { } controller_ = [[BookmarkBubbleController alloc] initWithParentWindow:test_window() - topRightForBubble:TopRightForBubble() model:helper_.profile()->GetBookmarkModel() node:node alreadyBookmarked:YES]; @@ -60,10 +59,6 @@ class BookmarkBubbleControllerTest : public CocoaTest { bool IsWindowClosing() { return [static_cast<InfoBubbleWindow*>([controller_ window]) isClosing]; } - - NSPoint TopRightForBubble() { - return NSMakePoint(NSWidth([test_window() frame]) - 10, 300); - } }; // Confirm basics about the bubble window (e.g. that it is inside the @@ -334,7 +329,6 @@ TEST_F(BookmarkBubbleControllerTest, EscapeRemovesNewBookmark) { BookmarkBubbleController* controller = [[BookmarkBubbleController alloc] initWithParentWindow:test_window() - topRightForBubble:TopRightForBubble() model:helper_.profile()->GetBookmarkModel() node:node alreadyBookmarked:NO]; // The last param is the key difference. diff --git a/chrome/browser/cocoa/bookmark_editor_base_controller.mm b/chrome/browser/cocoa/bookmark_editor_base_controller.mm index 8ecbc47..017d477 100644 --- a/chrome/browser/cocoa/bookmark_editor_base_controller.mm +++ b/chrome/browser/cocoa/bookmark_editor_base_controller.mm @@ -14,6 +14,7 @@ #import "chrome/browser/cocoa/bookmark_all_tabs_controller.h" #import "chrome/browser/cocoa/bookmark_editor_controller.h" #import "chrome/browser/cocoa/bookmark_tree_browser_cell.h" +#import "chrome/browser/cocoa/browser_window_controller.h" #include "chrome/browser/profile.h" #include "grit/generated_resources.h" @@ -227,6 +228,10 @@ class BookmarkEditorBaseControllerBridge : public BookmarkModelObserver { // TODO(jrg): consider NSModalSession. - (void)runAsModalSheet { + // Lock down floating bar when in full-screen mode. Don't animate + // otherwise the pane will be misplaced. + [[BrowserWindowController browserWindowControllerForWindow:parentWindow_] + lockBarVisibilityForOwner:self withAnimation:NO delay:NO]; [NSApp beginSheet:[self window] modalForWindow:parentWindow_ modalDelegate:self @@ -268,6 +273,8 @@ class BookmarkEditorBaseControllerBridge : public BookmarkModelObserver { returnCode:(int)returnCode contextInfo:(void*)contextInfo { [sheet close]; + [[BrowserWindowController browserWindowControllerForWindow:parentWindow_] + releaseBarVisibilityForOwner:self withAnimation:YES delay:NO]; } - (void)windowWillClose:(NSNotification*)notification { diff --git a/chrome/browser/cocoa/browser_window_controller.h b/chrome/browser/cocoa/browser_window_controller.h index 373fe20..4568e6a 100644 --- a/chrome/browser/cocoa/browser_window_controller.h +++ b/chrome/browser/cocoa/browser_window_controller.h @@ -125,6 +125,10 @@ class TabStripModelObserverBridge; } // A convenience class method which gets the |BrowserWindowController| for a +// given window. This method returns nil if no window in the chain has a BWC. ++ (BrowserWindowController*)browserWindowControllerForWindow:(NSWindow*)window; + +// A convenience class method which gets the |BrowserWindowController| for a // given view. This is the controller for the window containing |view|, if it // is a BWC, or the first controller in the parent-window chain that is a // BWC. This method returns nil if no window in the chain has a BWC. @@ -240,6 +244,9 @@ class TabStripModelObserverBridge; // Gets the pattern phase for the window. - (NSPoint)themePatternPhase; +// Return a point suitable for the topRight for a bookmark bubble. +- (NSPoint)topRightForBubble; + @end // @interface BrowserWindowController diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index 91b891d..05edc1a 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -155,8 +155,7 @@ @implementation BrowserWindowController -+ (BrowserWindowController*)browserWindowControllerForView:(NSView*)view { - NSWindow* window = [view window]; ++ (BrowserWindowController*)browserWindowControllerForWindow:(NSWindow*)window { while (window) { id controller = [window windowController]; if ([controller isKindOfClass:[BrowserWindowController class]]) @@ -166,6 +165,11 @@ return nil; } ++ (BrowserWindowController*)browserWindowControllerForView:(NSView*)view { + NSWindow* window = [view window]; + return [BrowserWindowController browserWindowControllerForWindow:window]; +} + // Load the browser window nib and do any Cocoa-specific initialization. // Takes ownership of |browser|. Note that the nib also sets this controller // up as the window's delegate. @@ -1385,10 +1389,8 @@ if (!bookmarkBubbleController_) { BookmarkModel* model = browser_->profile()->GetBookmarkModel(); const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url); - NSPoint topRight = [self topRightForBubble]; bookmarkBubbleController_ = [[BookmarkBubbleController alloc] initWithParentWindow:[self window] - topRightForBubble:topRight model:model node:node alreadyBookmarked:alreadyMarked]; |