summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/bookmark_bubble_view.mm
blob: 18f589c8f90e6269c7ef26863ba16cf8d0367f83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// 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/bookmark_bubble_view.h"
#import "third_party/GTM/AppKit/GTMTheme.h"

namespace {
// TODO(jrg): 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 BookmarkBubbleView

- (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 (pointed at the star).
  NSPoint arrowStart = NSMakePoint(NSMinX(bounds), NSMaxY(bounds));
  arrowStart.x += kBubbleArrowXOffset;
  [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