diff options
author | andybons@chromium.org <andybons@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-12 05:18:50 +0000 |
---|---|---|
committer | andybons@chromium.org <andybons@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-12 05:18:50 +0000 |
commit | d64f2a0ea7adada3e5221782e4739a9b858c53fd (patch) | |
tree | 08ca665b6c99e92bc12217dad7db5ed016bfca51 /chrome/browser/cocoa/info_bubble_view.mm | |
parent | 87eacb992a5fcc517a29a7097937df217b6839ff (diff) | |
download | chromium_src-d64f2a0ea7adada3e5221782e4739a9b858c53fd.zip chromium_src-d64f2a0ea7adada3e5221782e4739a9b858c53fd.tar.gz chromium_src-d64f2a0ea7adada3e5221782e4739a9b858c53fd.tar.bz2 |
o Renames the bookmark bubble class to InfoBubble in a step to make it more reusable.
o Adds the ability to position the arrow of the bubble on the top right as well as the top left (default).
BUG=none
TEST=Nothing should change visually. This is prep for use by browser action popups and the first run UI.
Review URL: http://codereview.chromium.org/385060
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31764 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/info_bubble_view.mm')
-rw-r--r-- | chrome/browser/cocoa/info_bubble_view.mm | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/info_bubble_view.mm b/chrome/browser/cocoa/info_bubble_view.mm new file mode 100644 index 0000000..e8c288d --- /dev/null +++ b/chrome/browser/cocoa/info_bubble_view.mm @@ -0,0 +1,71 @@ +// 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/info_bubble_view.h" + +#include "base/logging.h" +#import "third_party/GTM/AppKit/GTMTheme.h" + +namespace { +// TODO(andybons): confirm constants with UI dudes +const CGFloat kBubbleCornerRadius = 8.0; +const CGFloat kBubbleArrowXOffset = 10.0; +const CGFloat kBubbleArrowWidth = 15.0; +const CGFloat kBubbleArrowHeight = 8.0; +} + +@implementation InfoBubbleView + +@synthesize arrowLocation = arrowLocation_; + +- (id)initWithFrame:(NSRect)frameRect { + if ((self = [super initWithFrame:frameRect])) { + arrowLocation_ = kTopLeft; + } + + return self; +} + +- (void)drawRect:(NSRect)rect { + // Make room for the border to be seen. + NSRect bounds = [self bounds]; + bounds.size.height -= kBubbleArrowHeight; + NSBezierPath* bezier = [NSBezierPath bezierPath]; + rect.size.height -= kBubbleArrowHeight; + + // Start with a rounded rectangle. + [bezier appendBezierPathWithRoundedRect:bounds + xRadius:kBubbleCornerRadius + yRadius:kBubbleCornerRadius]; + + // Add the bubble arrow. + CGFloat dX; + switch (arrowLocation_) { + case kTopLeft: + dX = kBubbleArrowXOffset; + break; + case kTopRight: + dX = NSWidth(bounds) - kBubbleArrowXOffset - kBubbleArrowWidth; + break; + default: + NOTREACHED(); + break; + } + 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, + arrowStart.y)]; + [bezier closePath]; + + // Then fill the inside. + GTMTheme *theme = [GTMTheme defaultTheme]; + NSGradient *gradient = [theme gradientForStyle:GTMThemeStyleToolBar + state:NO]; + [gradient drawInBezierPath:bezier angle:0.0]; +} + +@end |