summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/bubble_view.mm
diff options
context:
space:
mode:
authorpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-08 21:09:29 +0000
committerpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-08 21:09:29 +0000
commit1a3e0967c5a0cbfb6bee4a63b49955acbb6b387e (patch)
tree1c90b017ca427ecc4a66e1a41cd2d44682f9f223 /chrome/browser/cocoa/bubble_view.mm
parent63d23bb1410837f9fdc300b4b5c0a3470724c8d6 (diff)
downloadchromium_src-1a3e0967c5a0cbfb6bee4a63b49955acbb6b387e.zip
chromium_src-1a3e0967c5a0cbfb6bee4a63b49955acbb6b387e.tar.gz
chromium_src-1a3e0967c5a0cbfb6bee4a63b49955acbb6b387e.tar.bz2
Pretty-up the blocked popup view by sharing code from the status bubble. Blocked Popup view is now themed as well.
BUG=20815 TEST=popup blocking and status bubble still work. Review URL: http://codereview.chromium.org/196043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25662 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/bubble_view.mm')
-rw-r--r--chrome/browser/cocoa/bubble_view.mm123
1 files changed, 123 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/bubble_view.mm b/chrome/browser/cocoa/bubble_view.mm
new file mode 100644
index 0000000..1a536c9
--- /dev/null
+++ b/chrome/browser/cocoa/bubble_view.mm
@@ -0,0 +1,123 @@
+// Copyright (c) 2009 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.
+
+#import "chrome/browser/cocoa/bubble_view.h"
+
+#import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h"
+#import "third_party/GTM/AppKit/GTMNSColor+Luminance.h"
+#import "third_party/GTM/AppKit/GTMTheme.h"
+
+// The roundedness of the edges of our bubble.
+const int kBubbleCornerRadius = 4.0f;
+const float kWindowEdge = 0.7f;
+
+@implementation BubbleView
+
+// Designated initializer. |provider| is the window from which we get the
+// current theme to draw text and backgrounds. If nil, the current window will
+// be checked. Defaults to all corners being rounded. The caller needs to
+// ensure |provider| can't go away as it will not be retained.
+- (id)initWithFrame:(NSRect)frame themeProvider:(NSWindow*)provider {
+ if ((self = [super initWithFrame:frame])) {
+ cornerFlags_ = kRoundedAllCorners;
+ themeProvider_ = provider;
+ }
+ return self;
+}
+
+// Sets the string displayed in the bubble. A copy of the string is made.
+- (void)setContent:(NSString*)content {
+ content_.reset([content copy]);
+ [self setNeedsDisplay:YES];
+}
+
+// Sets which corners will be rounded.
+- (void)setCornerFlags:(unsigned long)flags {
+ cornerFlags_ = flags;
+ [self setNeedsDisplay:YES];
+}
+
+- (NSString*)content {
+ return content_.get();
+}
+
+- (unsigned long)cornerFlags {
+ return cornerFlags_;
+}
+
+// The font used to display the content string.
+- (NSFont*)font {
+ return [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
+}
+
+// Asks the given theme provider for its theme. If there isn't one specified,
+// check the window we are in. May still return nil if the window doesn't
+// support themeing.
+- (GTMTheme*)gtm_theme {
+ GTMTheme* theme = [themeProvider_ gtm_theme];
+ if (!theme)
+ theme = [[self window] gtm_theme];
+ return theme;
+}
+
+// Draws the themed background and the text. Will draw a gray bg if no theme.
+- (void)drawRect:(NSRect)rect {
+ float topLeftRadius =
+ cornerFlags_ & kRoundedTopLeftCorner ? kBubbleCornerRadius : 0;
+ float topRightRadius =
+ cornerFlags_ & kRoundedTopRightCorner ? kBubbleCornerRadius : 0;
+ float bottomLeftRadius =
+ cornerFlags_ & kRoundedBottomLeftCorner ? kBubbleCornerRadius : 0;
+ float bottomRightRadius =
+ cornerFlags_ & kRoundedBottomRightCorner ? kBubbleCornerRadius : 0;
+
+ GTMTheme* theme = [self gtm_theme];
+
+ // Background / Edge
+
+ NSRect bounds = [self bounds];
+ bounds = NSInsetRect(bounds, 0.5, 0.5);
+ NSBezierPath* border =
+ [NSBezierPath gtm_bezierPathWithRoundRect:bounds
+ topLeftCornerRadius:topLeftRadius
+ topRightCornerRadius:topRightRadius
+ bottomLeftCornerRadius:bottomLeftRadius
+ bottomRightCornerRadius:bottomRightRadius];
+
+ NSColor* color =
+ [theme backgroundColorForStyle:GTMThemeStyleToolBar
+ state:GTMThemeStateActiveWindow];
+
+ // workaround for default theme
+ // TODO(alcor) next GTM update return nil for background color if not set;
+ if ([color isEqual:[NSColor colorWithCalibratedWhite:0.5 alpha:1.0]])
+ color = nil;
+ if (!color)
+ color = [NSColor colorWithCalibratedWhite:0.9 alpha:1.0];
+ [color set];
+ [border fill];
+
+ [[NSColor colorWithDeviceWhite:kWindowEdge alpha:1.0f] set];
+ [border stroke];
+
+ // Text
+ NSColor* textColor = [theme textColorForStyle:GTMThemeStyleToolBar
+ state:GTMThemeStateActiveWindow];
+ NSFont* textFont = [self font];
+ scoped_nsobject<NSShadow> textShadow([[NSShadow alloc] init]);
+ [textShadow setShadowBlurRadius:0.0f];
+ [textShadow setShadowColor:[textColor gtm_legibleTextColor]];
+ [textShadow setShadowOffset:NSMakeSize(0.0f, -1.0f)];
+
+ NSDictionary* textDict = [NSDictionary dictionaryWithObjectsAndKeys:
+ textColor, NSForegroundColorAttributeName,
+ textFont, NSFontAttributeName,
+ textShadow.get(), NSShadowAttributeName,
+ nil];
+ [content_ drawAtPoint:NSMakePoint(kBubbleViewTextPositionX,
+ kBubbleViewTextPositionY)
+ withAttributes:textDict];
+}
+
+@end