diff options
author | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-03 23:27:04 +0000 |
---|---|---|
committer | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-03 23:27:04 +0000 |
commit | 12ef7b2086502503aa70cc6353a388f140381f06 (patch) | |
tree | 2eca40cb7ab8674217509aacc602571b0bdaf470 | |
parent | 096033ff2561408e18518c216d1bda06500a734e (diff) | |
download | chromium_src-12ef7b2086502503aa70cc6353a388f140381f06.zip chromium_src-12ef7b2086502503aa70cc6353a388f140381f06.tar.gz chromium_src-12ef7b2086502503aa70cc6353a388f140381f06.tar.bz2 |
[Mac] Adjust browser-action and content-setting popup points
Adjust the browser-action popup point to leave the top border of the
window 2px below the bottom border of the Omnibox. This matches the
Omnibox popup, the bookmark popup, and page-action popups.
Likewise content-setting popup.
BUG=50575
TEST=The popup is spaced correctly.
Review URL: http://codereview.chromium.org/3054040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54839 0039d316-1c4b-4281-b951-d872f2087c98
3 files changed, 37 insertions, 17 deletions
diff --git a/chrome/browser/cocoa/extensions/browser_actions_controller.mm b/chrome/browser/cocoa/extensions/browser_actions_controller.mm index cded5e9..8295ee9 100644 --- a/chrome/browser/cocoa/extensions/browser_actions_controller.mm +++ b/chrome/browser/cocoa/extensions/browser_actions_controller.mm @@ -57,6 +57,10 @@ const CGFloat kBrowserActionButtonPadding = 2.0; // pixel of internal padding, this needs an extra pixel. const CGFloat kBrowserActionLeftPadding = kBrowserActionButtonPadding + 1.0; +// How far to inset from the bottom of the view to get the top border +// of the popup 2px below the bottom of the Omnibox. +const CGFloat kBrowserActionBubbleYOffset = 3.0; + } // namespace @interface BrowserActionsController(Private) @@ -374,24 +378,20 @@ class ExtensionsServiceObserverBridge : public NotificationObserver, - (NSPoint)popupPointForBrowserAction:(Extension*)extension { if (!extension->browser_action()) return NSZeroPoint; - BrowserActionButton* button = [self buttonForExtension:extension]; + + NSButton* button = [self buttonForExtension:extension]; if (!button) return NSZeroPoint; - NSView* view = button; - BOOL isHidden = [hiddenButtons_ containsObject:button]; - if (isHidden) - view = chevronMenuButton_.get(); - - NSPoint arrowPoint = [view frame].origin; - // Adjust the anchor point to be at the center of the browser action button - // or chevron. - arrowPoint.x += NSWidth([view frame]) / 2; - // Move the arrow up a bit in the case that it's pointing to the chevron. - if (isHidden) - arrowPoint.y += NSHeight([view frame]) / 4; + if ([hiddenButtons_ containsObject:button]) + button = chevronMenuButton_.get(); - return [[view superview] convertPoint:arrowPoint toView:nil]; + // Anchor point just above the center of the bottom. + const NSRect bounds = [button bounds]; + DCHECK([button isFlipped]); + NSPoint anchor = NSMakePoint(NSMidX(bounds), + NSMaxY(bounds) - kBrowserActionBubbleYOffset); + return [button convertPoint:anchor toView:nil]; } - (BOOL)chevronIsHidden { diff --git a/chrome/browser/cocoa/location_bar/content_setting_decoration.h b/chrome/browser/cocoa/location_bar/content_setting_decoration.h index 9a1afed..bc571d1 100644 --- a/chrome/browser/cocoa/location_bar/content_setting_decoration.h +++ b/chrome/browser/cocoa/location_bar/content_setting_decoration.h @@ -34,6 +34,11 @@ class ContentSettingDecoration : public ImageDecoration { virtual NSString* GetToolTip(); private: + // Helper to get where the bubble point should land. Similar to + // |PageActionDecoration| or |StarDecoration| (|LocationBarViewMac| + // calls those). + NSPoint GetBubblePointInFrame(NSRect frame); + void SetToolTip(NSString* tooltip); scoped_ptr<ContentSettingImageModel> content_setting_image_model_; diff --git a/chrome/browser/cocoa/location_bar/content_setting_decoration.mm b/chrome/browser/cocoa/location_bar/content_setting_decoration.mm index 6f2b8a3..790b5c2 100644 --- a/chrome/browser/cocoa/location_bar/content_setting_decoration.mm +++ b/chrome/browser/cocoa/location_bar/content_setting_decoration.mm @@ -17,6 +17,14 @@ #include "chrome/common/pref_names.h" #include "net/base/net_util.h" +namespace { + +// How far to offset up from the bottom of the view to get the top +// border of the popup 2px below the bottom of the Omnibox. +const CGFloat kPopupPointYOffset = 2.0; + +} // namespace + ContentSettingDecoration::ContentSettingDecoration( ContentSettingsType settings_type, LocationBarViewMac* owner, @@ -45,6 +53,12 @@ void ContentSettingDecoration::UpdateFromTabContents( } } +NSPoint ContentSettingDecoration::GetBubblePointInFrame(NSRect frame) { + const NSRect draw_frame = GetDrawRectInFrame(frame); + return NSMakePoint(NSMidX(draw_frame), + NSMaxY(draw_frame) - kPopupPointYOffset); +} + bool ContentSettingDecoration::OnMousePressed(NSRect frame) { // Get host. This should be shared on linux/win/osx medium-term. TabContents* tabContents = @@ -61,10 +75,11 @@ bool ContentSettingDecoration::OnMousePressed(NSRect frame) { // Find point for bubble's arrow in screen coordinates. // TODO(shess): |owner_| is only being used to fetch |field|. - // Consider passing in |control_view|. + // Consider passing in |control_view|. Or refactoring to be + // consistent with other decorations (which don't currently bring up + // their bubble directly). AutocompleteTextField* field = owner_->GetAutocompleteTextField(); - frame = GetDrawRectInFrame(frame); - NSPoint anchor = NSMakePoint(NSMidX(frame) + 1, NSMaxY(frame)); + NSPoint anchor = GetBubblePointInFrame(frame); anchor = [field convertPoint:anchor toView:nil]; anchor = [[field window] convertBaseToScreen:anchor]; |