diff options
| author | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-12 02:23:09 +0000 |
|---|---|---|
| committer | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-12 02:23:09 +0000 |
| commit | 22f649e079ecab148c43314569a3ab74d1d9d8b8 (patch) | |
| tree | be954776ee92906f63c77d49de4840df8f0ac92d | |
| parent | 58c3a0962bb4dbd76bb556f036372f980467af71 (diff) | |
| download | chromium_src-22f649e079ecab148c43314569a3ab74d1d9d8b8.zip chromium_src-22f649e079ecab148c43314569a3ab74d1d9d8b8.tar.gz chromium_src-22f649e079ecab148c43314569a3ab74d1d9d8b8.tar.bz2 | |
[Mac] Fix the positioning of the page info bubble.
BUG=57306
TEST=Click the lock icon. Page info bubble positioned underneath it.
Review URL: http://codereview.chromium.org/3532021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62230 0039d316-1c4b-4281-b951-d872f2087c98
| -rw-r--r-- | chrome/browser/cocoa/base_bubble_controller.h | 1 | ||||
| -rw-r--r-- | chrome/browser/cocoa/base_bubble_controller.mm | 38 | ||||
| -rw-r--r-- | chrome/browser/cocoa/page_info_bubble_controller.mm | 63 |
3 files changed, 66 insertions, 36 deletions
diff --git a/chrome/browser/cocoa/base_bubble_controller.h b/chrome/browser/cocoa/base_bubble_controller.h index b00e49c..fc63f0f 100644 --- a/chrome/browser/cocoa/base_bubble_controller.h +++ b/chrome/browser/cocoa/base_bubble_controller.h @@ -27,6 +27,7 @@ } @property (nonatomic, readonly) NSWindow* parentWindow; +@property (nonatomic, assign) NSPoint anchorPoint; @property (nonatomic, readonly) InfoBubbleView* bubble; // Creates a bubble. |nibPath| is just the basename, e.g. @"FirstRunBubble". diff --git a/chrome/browser/cocoa/base_bubble_controller.mm b/chrome/browser/cocoa/base_bubble_controller.mm index 9cebc61..a67bc64 100644 --- a/chrome/browser/cocoa/base_bubble_controller.mm +++ b/chrome/browser/cocoa/base_bubble_controller.mm @@ -12,9 +12,14 @@ #import "chrome/browser/cocoa/info_bubble_view.h" #include "grit/generated_resources.h" +@interface BaseBubbleController (Private) +- (void)updateOriginFromAnchor; +@end + @implementation BaseBubbleController @synthesize parentWindow = parentWindow_; +@synthesize anchorPoint = anchor_; @synthesize bubble = bubble_; - (id)initWithWindowNibPath:(NSString*)nibPath @@ -92,6 +97,11 @@ [super dealloc]; } +- (void)setAnchorPoint:(NSPoint)anchor { + anchor_ = anchor; + [self updateOriginFromAnchor]; +} + - (void)parentWindowWillClose:(NSNotification*)notification { [self close]; } @@ -110,16 +120,7 @@ // showWindow:. Thus, we have our own version. - (void)showWindow:(id)sender { NSWindow* window = [self window]; // completes nib load - - NSPoint origin = anchor_; - NSSize offsets = NSMakeSize(info_bubble::kBubbleArrowXOffset + - info_bubble::kBubbleArrowWidth / 2.0, 0); - offsets = [[parentWindow_ contentView] convertSize:offsets toView:nil]; - origin.x += offsets.width; - if ([bubble_ arrowLocation] == info_bubble::kTopRight) - origin.x -= NSWidth([window frame]); - origin.y -= NSHeight([window frame]); - [window setFrameOrigin:origin]; + [self updateOriginFromAnchor]; [parentWindow_ addChildWindow:window ordered:NSWindowAbove]; [window makeKeyAndOrderFront:self]; } @@ -148,4 +149,21 @@ // undone. That's ok. [self close]; } + +// Takes the |anchor_| point and adjusts the window's origin accordingly. +- (void)updateOriginFromAnchor { + NSWindow* window = [self window]; + NSPoint origin = anchor_; + NSSize offsets = NSMakeSize(info_bubble::kBubbleArrowXOffset + + 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; + } else { + origin.x -= offsets.width; + } + origin.y -= NSHeight([window frame]); + [window setFrameOrigin:origin]; +} + @end // BaseBubbleController diff --git a/chrome/browser/cocoa/page_info_bubble_controller.mm b/chrome/browser/cocoa/page_info_bubble_controller.mm index b8c4af3..a2cc34f 100644 --- a/chrome/browser/cocoa/page_info_bubble_controller.mm +++ b/chrome/browser/cocoa/page_info_bubble_controller.mm @@ -41,6 +41,8 @@ atOffset:(CGFloat)offset; - (CGFloat)addSeparatorToSubviews:(NSMutableArray*)subviews atOffset:(CGFloat)offset; +- (NSPoint)anchorPointForWindowWithHeight:(CGFloat)bubbleHeight + parentWindow:(NSWindow*)parent; @end namespace { @@ -73,22 +75,6 @@ const CGFloat kTextXPosition = kTextXPositionNoImage + kImageSize + const CGFloat kTextWidth = kWindowWidth - (kImageSize + kImageSpacing + kFramePadding * 2); -// Takes in the bubble's height and the parent window, which should be a -// BrowserWindow, and gets the proper anchor point for the bubble. The point is -// in screen coordinates. -NSPoint AnchorPointFromParentWindow(NSWindow* parent, CGFloat bubbleHeight) { - BrowserWindowController* controller = [parent windowController]; - NSPoint origin = NSZeroPoint; - if ([controller isKindOfClass:[BrowserWindowController class]]) { - LocationBarViewMac* location_bar = [controller locationBarBridge]; - if (location_bar) { - NSPoint arrowTip = location_bar->GetPageInfoBubblePoint(); - origin = [parent convertBaseToScreen:arrowTip]; - origin.y -= bubbleHeight; - } - } - return origin; -} // Bridge that listens for change notifications from the model. class PageInfoModelBubbleBridge : public PageInfoModel::PageInfoModelObserver { @@ -97,7 +83,12 @@ class PageInfoModelBubbleBridge : public PageInfoModel::PageInfoModelObserver { // PageInfoModelObserver implementation. virtual void ModelChanged() { - [controller_ performLayout]; + // Delay performing layout by a second so that all the animations from + // InfoBubbleWindow and origin updates from BaseBubbleController finish, so + // that we don't all race trying to change the frame's origin. + [controller_ performSelector:@selector(performLayout) + withObject:nil + afterDelay:1.0]; } // Sets the controller. @@ -140,7 +131,7 @@ void ShowPageInfoBubble(gfx::NativeWindow parent, modelObserver:(PageInfoModel::PageInfoModelObserver*)bridge parentWindow:(NSWindow*)parentWindow { // Use an arbitrary height because it will be changed by the bridge. - NSRect contentRect = NSMakeRect(0, 0, kWindowWidth, 50); + NSRect contentRect = NSMakeRect(0, 0, kWindowWidth, 0); // Create an empty window into which content is placed. scoped_nsobject<InfoBubbleWindow> window( [[InfoBubbleWindow alloc] initWithContentRect:contentRect @@ -148,10 +139,9 @@ void ShowPageInfoBubble(gfx::NativeWindow parent, backing:NSBackingStoreBuffered defer:NO]); - NSPoint anchorPoint = AnchorPointFromParentWindow(parentWindow, 0); if ((self = [super initWithWindow:window.get() parentWindow:parentWindow - anchoredAt:anchorPoint])) { + anchoredAt:NSZeroPoint])) { model_.reset(model); bridge_.reset(bridge); [[self bubble] setArrowLocation:info_bubble::kTopLeft]; @@ -235,21 +225,25 @@ void ShowPageInfoBubble(gfx::NativeWindow parent, offset += kFramePadding; - // TODO(rsesek): Remove constant value to account for http://crbug.com/57306. - NSRect windowFrame = NSMakeRect(0, 0, kWindowWidth, 50); + NSRect windowFrame = NSMakeRect(0, 0, kWindowWidth, 0); windowFrame.size.height += offset; windowFrame.size = [[[self window] contentView] convertSize:windowFrame.size toView:nil]; - // Just setting |size| will cause the window to grow upwards. Shift the - // origin up by grow amount, which causes the window to grow downwards. - windowFrame.origin = AnchorPointFromParentWindow([self parentWindow], - NSHeight(windowFrame)); + // Adjust the origin by the difference in height. + windowFrame.origin = [[self window] frame].origin; + windowFrame.origin.y -= NSHeight(windowFrame) - + NSHeight([[self window] frame]); // Resize the window. Only animate if the window is visible, otherwise it // could be "growing" while it's opening, looking awkward. [[self window] setFrame:windowFrame display:YES animate:[[self window] isVisible]]; + + NSPoint anchorPoint = + [self anchorPointForWindowWithHeight:NSHeight(windowFrame) + parentWindow:[self parentWindow]]; + [self setAnchorPoint:anchorPoint]; } // Creates the button with a given |frame| that, when clicked, will show the @@ -395,4 +389,21 @@ void ShowPageInfoBubble(gfx::NativeWindow parent, return kVerticalSpacing; } +// Takes in the bubble's height and the parent window, which should be a +// BrowserWindow, and gets the proper anchor point for the bubble. The returned +// point is in screen coordinates. +- (NSPoint)anchorPointForWindowWithHeight:(CGFloat)bubbleHeight + parentWindow:(NSWindow*)parent { + BrowserWindowController* controller = [parent windowController]; + NSPoint origin = NSZeroPoint; + if ([controller isKindOfClass:[BrowserWindowController class]]) { + LocationBarViewMac* locationBar = [controller locationBarBridge]; + if (locationBar) { + NSPoint bubblePoint = locationBar->GetPageInfoBubblePoint(); + origin = [parent convertBaseToScreen:bubblePoint]; + } + } + return origin; +} + @end |
