diff options
12 files changed, 66 insertions, 58 deletions
diff --git a/chrome/browser/cocoa/bookmark_bubble_controller.mm b/chrome/browser/cocoa/bookmark_bubble_controller.mm index 465691e..f34fa21 100644 --- a/chrome/browser/cocoa/bookmark_bubble_controller.mm +++ b/chrome/browser/cocoa/bookmark_bubble_controller.mm @@ -98,7 +98,7 @@ [BrowserWindowController browserWindowControllerForWindow:parentWindow_]; [bwc lockBarVisibilityForOwner:self withAnimation:NO delay:NO]; NSWindow* window = [self window]; // completes nib load - [bubble_ setArrowLocation:kTopRight]; + [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 pointForBubbleArrowTip] : diff --git a/chrome/browser/cocoa/content_blocked_bubble_controller.mm b/chrome/browser/cocoa/content_blocked_bubble_controller.mm index 8b88c0c..eb7df32 100644 --- a/chrome/browser/cocoa/content_blocked_bubble_controller.mm +++ b/chrome/browser/cocoa/content_blocked_bubble_controller.mm @@ -369,8 +369,8 @@ NSTextField* LabelWithFrame(NSString* text, const NSRect& frame) { DCHECK([self window]); DCHECK_EQ(self, [[self window] delegate]); - [bubble_ setBubbleType:kWhiteInfoBubble]; - [bubble_ setArrowLocation:kTopRight]; + [bubble_ setBubbleType:info_bubble::kWhiteInfoBubble]; + [bubble_ setArrowLocation:info_bubble::kTopRight]; // Adapt window size to bottom buttons. Do this before all other layouting. [self sizeToFitManageDoneButtons]; @@ -418,8 +418,8 @@ NSTextField* LabelWithFrame(NSString* text, const NSRect& frame) { NSWindow* window = [self window]; // completes nib load NSPoint origin = anchor_; - NSSize offsets = NSMakeSize(kBubbleArrowXOffset + kBubbleArrowWidth / 2.0, - 0); + NSSize offsets = NSMakeSize(info_bubble::kBubbleArrowXOffset + + info_bubble::kBubbleArrowWidth / 2.0, 0); offsets = [[parentWindow_ contentView] convertSize:offsets toView:nil]; origin.x -= NSWidth([window frame]) - offsets.width; origin.y -= NSHeight([window frame]); diff --git a/chrome/browser/cocoa/extension_installed_bubble_controller.h b/chrome/browser/cocoa/extension_installed_bubble_controller.h index d6ef22e..4947ae4 100644 --- a/chrome/browser/cocoa/extension_installed_bubble_controller.h +++ b/chrome/browser/cocoa/extension_installed_bubble_controller.h @@ -6,17 +6,17 @@ #define CHROME_BROWSER_COCOA_EXTENSION_INSTALLED_BUBBLE_CONTROLLER_H_ #import <Cocoa/Cocoa.h> + #import "base/cocoa_protocols_mac.h" #include "base/scoped_ptr.h" #import "chrome/browser/cocoa/browser_window_controller.h" -#import "chrome/browser/cocoa/info_bubble_view.h" #include "third_party/skia/include/core/SkBitmap.h" class Browser; class Extension; class ExtensionLoadedNotificationObserver; - @class HoverCloseButton; +@class InfoBubbleView; namespace extension_installed_bubble { diff --git a/chrome/browser/cocoa/extension_installed_bubble_controller.mm b/chrome/browser/cocoa/extension_installed_bubble_controller.mm index 3cfba62..805f3b5 100644 --- a/chrome/browser/cocoa/extension_installed_bubble_controller.mm +++ b/chrome/browser/cocoa/extension_installed_bubble_controller.mm @@ -234,8 +234,8 @@ class ExtensionLoadedNotificationObserver : public NotificationObserver { // Find window origin, taking into account bubble size and arrow location. NSPoint origin = [parentWindow_ convertBaseToScreen:[self calculateArrowPoint]]; - NSSize offsets = NSMakeSize(kBubbleArrowXOffset + kBubbleArrowWidth / 2.0, - 0); + NSSize offsets = NSMakeSize(info_bubble::kBubbleArrowXOffset + + info_bubble::kBubbleArrowWidth / 2.0, 0); offsets = [[window contentView] convertSize:offsets toView:nil]; origin.x -= NSWidth([window frame]) - offsets.width; origin.y -= NSHeight([window frame]); @@ -250,7 +250,7 @@ class ExtensionLoadedNotificationObserver : public NotificationObserver { // function is exposed for unit testing. - (NSWindow*)initializeWindow { NSWindow* window = [self window]; // completes nib load - [infoBubbleView_ setArrowLocation:kTopRight]; + [infoBubbleView_ setArrowLocation:info_bubble::kTopRight]; // Set appropriate icon, resizing if necessary. if ([icon_ size].width > extension_installed_bubble::kIconSize) { diff --git a/chrome/browser/cocoa/extensions/browser_actions_controller.mm b/chrome/browser/cocoa/extensions/browser_actions_controller.mm index b8e0762..d6582c3 100644 --- a/chrome/browser/cocoa/extensions/browser_actions_controller.mm +++ b/chrome/browser/cocoa/extensions/browser_actions_controller.mm @@ -702,7 +702,7 @@ class ExtensionsServiceObserverBridge : public NotificationObserver, [ExtensionPopupController showURL:popupUrl inBrowser:browser_ anchoredAt:arrowPoint - arrowLocation:kTopRight + arrowLocation:info_bubble::kTopRight devMode:NO]; } else { ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted( diff --git a/chrome/browser/cocoa/extensions/extension_action_context_menu.mm b/chrome/browser/cocoa/extensions/extension_action_context_menu.mm index c473e4e..95d2075 100644 --- a/chrome/browser/cocoa/extensions/extension_action_context_menu.mm +++ b/chrome/browser/cocoa/extensions/extension_action_context_menu.mm @@ -265,7 +265,7 @@ int CurrentTabId() { [ExtensionPopupController showURL:url inBrowser:BrowserList::GetLastActive() anchoredAt:popupPoint - arrowLocation:kTopRight + arrowLocation:info_bubble::kTopRight devMode:YES]; break; } diff --git a/chrome/browser/cocoa/extensions/extension_popup_controller.h b/chrome/browser/cocoa/extensions/extension_popup_controller.h index efb5c6d..ec31816 100644 --- a/chrome/browser/cocoa/extensions/extension_popup_controller.h +++ b/chrome/browser/cocoa/extensions/extension_popup_controller.h @@ -70,7 +70,8 @@ class NotificationRegistrar; + (ExtensionPopupController*)showURL:(GURL)url inBrowser:(Browser*)browser anchoredAt:(NSPoint)anchoredAt - arrowLocation:(BubbleArrowLocation)arrowLocation + arrowLocation:(info_bubble::BubbleArrowLocation) + arrowLocation devMode:(BOOL)devMode; // Returns the controller used to display the popup being shown. If no popup is diff --git a/chrome/browser/cocoa/extensions/extension_popup_controller.mm b/chrome/browser/cocoa/extensions/extension_popup_controller.mm index 1dec941..90413b8 100644 --- a/chrome/browser/cocoa/extensions/extension_popup_controller.mm +++ b/chrome/browser/cocoa/extensions/extension_popup_controller.mm @@ -74,7 +74,7 @@ class DevtoolsNotificationBridge : public NotificationObserver { - (id)initWithHost:(ExtensionHost*)host parentWindow:(NSWindow*)parentWindow anchoredAt:(NSPoint)anchoredAt - arrowLocation:(BubbleArrowLocation)arrowLocation + arrowLocation:(info_bubble::BubbleArrowLocation)arrowLocation devMode:(BOOL)devMode; // Called when the extension's hosted NSView has been resized. @@ -86,7 +86,7 @@ class DevtoolsNotificationBridge : public NotificationObserver { - (id)initWithHost:(ExtensionHost*)host parentWindow:(NSWindow*)parentWindow anchoredAt:(NSPoint)anchoredAt - arrowLocation:(BubbleArrowLocation)arrowLocation + arrowLocation:(info_bubble::BubbleArrowLocation)arrowLocation devMode:(BOOL)devMode { parentWindow_ = parentWindow; @@ -97,7 +97,7 @@ class DevtoolsNotificationBridge : public NotificationObserver { if (!view.get()) return nil; [view setArrowLocation:arrowLocation]; - [view setBubbleType:kWhiteInfoBubble]; + [view setBubbleType:info_bubble::kWhiteInfoBubble]; host->view()->set_is_toolstrip(NO); @@ -198,7 +198,8 @@ class DevtoolsNotificationBridge : public NotificationObserver { + (ExtensionPopupController*)showURL:(GURL)url inBrowser:(Browser*)browser anchoredAt:(NSPoint)anchoredAt - arrowLocation:(BubbleArrowLocation)arrowLocation + arrowLocation:(info_bubble::BubbleArrowLocation) + arrowLocation devMode:(BOOL)devMode { DCHECK([NSThread isMainThread]); DCHECK(browser); @@ -258,18 +259,20 @@ class DevtoolsNotificationBridge : public NotificationObserver { // Pad the window by half of the rounded corner radius to prevent the // extension's view from bleeding out over the corners. - CGFloat inset = kBubbleCornerRadius / 2.0; + CGFloat inset = info_bubble::kBubbleCornerRadius / 2.0; [extensionView_ setFrameOrigin:NSMakePoint(inset, inset)]; NSRect frame = [extensionView_ frame]; - frame.size.height += kBubbleArrowHeight + kBubbleCornerRadius; - frame.size.width += kBubbleCornerRadius; + frame.size.height += info_bubble::kBubbleArrowHeight + + info_bubble::kBubbleCornerRadius; + frame.size.width += info_bubble::kBubbleCornerRadius; frame = [extensionView_ convertRectToBase:frame]; // Adjust the origin according to the height and width so that the arrow is // positioned correctly at the middle and slightly down from the button. NSPoint windowOrigin = anchor_; - NSSize offsets = NSMakeSize(kBubbleArrowXOffset + kBubbleArrowWidth / 2.0, - kBubbleArrowHeight / 2.0); + NSSize offsets = NSMakeSize(info_bubble::kBubbleArrowXOffset + + info_bubble::kBubbleArrowWidth / 2.0, + info_bubble::kBubbleArrowHeight / 2.0); offsets = [extensionView_ convertSize:offsets toView:nil]; windowOrigin.x -= NSWidth(frame) - offsets.width; windowOrigin.y -= NSHeight(frame) - offsets.height; diff --git a/chrome/browser/cocoa/extensions/extension_popup_controller_unittest.mm b/chrome/browser/cocoa/extensions/extension_popup_controller_unittest.mm index c6335dd..235d85b 100644 --- a/chrome/browser/cocoa/extensions/extension_popup_controller_unittest.mm +++ b/chrome/browser/cocoa/extensions/extension_popup_controller_unittest.mm @@ -66,7 +66,7 @@ class ExtensionPopupControllerTest : public CocoaTest { [ExtensionPopupController showURL:GURL("http://google.com") inBrowser:browser_.get() anchoredAt:NSZeroPoint - arrowLocation:kTopRight + arrowLocation:info_bubble::kTopRight devMode:NO]; } virtual void TearDown() { diff --git a/chrome/browser/cocoa/info_bubble_view.h b/chrome/browser/cocoa/info_bubble_view.h index 91ffc907..2cd5119 100644 --- a/chrome/browser/cocoa/info_bubble_view.h +++ b/chrome/browser/cocoa/info_bubble_view.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,10 +7,13 @@ #import <Cocoa/Cocoa.h> -extern const CGFloat kBubbleArrowHeight; -extern const CGFloat kBubbleArrowWidth; -extern const CGFloat kBubbleArrowXOffset; -extern const CGFloat kBubbleCornerRadius; +namespace info_bubble { + +// TODO(andybons): confirm constants with UI dudes. +const CGFloat kBubbleArrowHeight = 8.0; +const CGFloat kBubbleArrowWidth = 15.0; +const CGFloat kBubbleArrowXOffset = 10.0; +const CGFloat kBubbleCornerRadius = 8.0; enum BubbleArrowLocation { kTopLeft, @@ -22,19 +25,21 @@ enum InfoBubbleType { kWhiteInfoBubble }; +} // namespace info_bubble + // Content view for a bubble with an arrow showing arbitrary content. // This is where nonrectangular drawing happens. @interface InfoBubbleView : NSView { @private - BubbleArrowLocation arrowLocation_; + info_bubble::BubbleArrowLocation arrowLocation_; // The type simply is used to determine what sort of background it should // draw. - InfoBubbleType bubbleType_; + info_bubble::InfoBubbleType bubbleType_; } -@property (assign, nonatomic) BubbleArrowLocation arrowLocation; -@property (assign, nonatomic) InfoBubbleType bubbleType; +@property (assign, nonatomic) info_bubble::BubbleArrowLocation arrowLocation; +@property (assign, nonatomic) info_bubble::InfoBubbleType bubbleType; // Returns the point location in view coordinates of the tip of the arrow. - (NSPoint)arrowTip; diff --git a/chrome/browser/cocoa/info_bubble_view.mm b/chrome/browser/cocoa/info_bubble_view.mm index 1ced0dd..7a90513 100644 --- a/chrome/browser/cocoa/info_bubble_view.mm +++ b/chrome/browser/cocoa/info_bubble_view.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,12 +8,6 @@ #include "base/scoped_nsobject.h" #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" -// TODO(andybons): confirm constants with UI dudes. -extern const CGFloat kBubbleArrowHeight = 8.0; -extern const CGFloat kBubbleArrowWidth = 15.0; -extern const CGFloat kBubbleArrowXOffset = 10.0; -extern const CGFloat kBubbleCornerRadius = 8.0; - @implementation InfoBubbleView @synthesize arrowLocation = arrowLocation_; @@ -21,8 +15,8 @@ extern const CGFloat kBubbleCornerRadius = 8.0; - (id)initWithFrame:(NSRect)frameRect { if ((self = [super initWithFrame:frameRect])) { - arrowLocation_ = kTopLeft; - bubbleType_ = kGradientInfoBubble; + arrowLocation_ = info_bubble::kTopLeft; + bubbleType_ = info_bubble::kGradientInfoBubble; } return self; @@ -31,23 +25,24 @@ extern const CGFloat kBubbleCornerRadius = 8.0; - (void)drawRect:(NSRect)rect { // Make room for the border to be seen. NSRect bounds = [self bounds]; - bounds.size.height -= kBubbleArrowHeight; + bounds.size.height -= info_bubble::kBubbleArrowHeight; NSBezierPath* bezier = [NSBezierPath bezierPath]; - rect.size.height -= kBubbleArrowHeight; + rect.size.height -= info_bubble::kBubbleArrowHeight; // Start with a rounded rectangle. [bezier appendBezierPathWithRoundedRect:bounds - xRadius:kBubbleCornerRadius - yRadius:kBubbleCornerRadius]; + xRadius:info_bubble::kBubbleCornerRadius + yRadius:info_bubble::kBubbleCornerRadius]; // Add the bubble arrow. CGFloat dX = 0; switch (arrowLocation_) { - case kTopLeft: - dX = kBubbleArrowXOffset; + case info_bubble::kTopLeft: + dX = info_bubble::kBubbleArrowXOffset; break; - case kTopRight: - dX = NSWidth(bounds) - kBubbleArrowXOffset - kBubbleArrowWidth; + case info_bubble::kTopRight: + dX = NSWidth(bounds) - info_bubble::kBubbleArrowXOffset - + info_bubble::kBubbleArrowWidth; break; default: NOTREACHED(); @@ -56,14 +51,16 @@ extern const CGFloat kBubbleCornerRadius = 8.0; NSPoint arrowStart = NSMakePoint(NSMinX(bounds), NSMaxY(bounds)); arrowStart.x += dX; [bezier moveToPoint:NSMakePoint(arrowStart.x, arrowStart.y)]; - [bezier lineToPoint:NSMakePoint(arrowStart.x + kBubbleArrowWidth/2.0, - arrowStart.y + kBubbleArrowHeight)]; - [bezier lineToPoint:NSMakePoint(arrowStart.x + kBubbleArrowWidth, + [bezier lineToPoint:NSMakePoint(arrowStart.x + + info_bubble::kBubbleArrowWidth / 2.0, + arrowStart.y + + info_bubble::kBubbleArrowHeight)]; + [bezier lineToPoint:NSMakePoint(arrowStart.x + info_bubble::kBubbleArrowWidth, arrowStart.y)]; [bezier closePath]; // Then fill the inside depending on the type of bubble. - if (bubbleType_ == kGradientInfoBubble) { + if (bubbleType_ == info_bubble::kGradientInfoBubble) { NSColor* base_color = [NSColor colorWithCalibratedWhite:0.5 alpha:1.0]; NSColor* startColor = [base_color gtm_colorAdjustedFor:GTMColorationLightHighlight @@ -86,7 +83,7 @@ extern const CGFloat kBubbleCornerRadius = 8.0; nil]); [gradient.get() drawInBezierPath:bezier angle:0.0]; - } else if (bubbleType_ == kWhiteInfoBubble) { + } else if (bubbleType_ == info_bubble::kWhiteInfoBubble) { [[NSColor whiteColor] set]; [bezier fill]; } @@ -94,9 +91,11 @@ extern const CGFloat kBubbleCornerRadius = 8.0; - (NSPoint)arrowTip { NSRect bounds = [self bounds]; - CGFloat tipXOffset = kBubbleArrowXOffset + kBubbleArrowWidth / 2.0; - CGFloat xOffset = arrowLocation_ == kTopRight ? NSMaxX(bounds) - tipXOffset : - NSMinX(bounds) + tipXOffset; + CGFloat tipXOffset = + info_bubble::kBubbleArrowXOffset + info_bubble::kBubbleArrowWidth / 2.0; + CGFloat xOffset = + (arrowLocation_ == info_bubble::kTopRight) ? NSMaxX(bounds) - tipXOffset : + NSMinX(bounds) + tipXOffset; NSPoint arrowTip = NSMakePoint(xOffset, NSMaxY(bounds)); return arrowTip; } diff --git a/chrome/browser/cocoa/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar_view_mac.mm index ae1680a..26a7fc9 100644 --- a/chrome/browser/cocoa/location_bar_view_mac.mm +++ b/chrome/browser/cocoa/location_bar_view_mac.mm @@ -728,7 +728,7 @@ void LocationBarViewMac::PageActionImageView::OnMousePressed(NSRect bounds) { [ExtensionPopupController showURL:page_action_->GetPopupUrl(current_tab_id_) inBrowser:BrowserList::GetLastActive() anchoredAt:arrowPoint - arrowLocation:kTopRight + arrowLocation:info_bubble::kTopRight devMode:NO]; } else { ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted( |