blob: 4db4ab854ecbfafd5b96e496528fe20f47b82805 (
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
// 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"
// 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_;
@synthesize bubbleType = bubbleType_;
- (id)initWithFrame:(NSRect)frameRect {
if ((self = [super initWithFrame:frameRect])) {
arrowLocation_ = kTopLeft;
bubbleType_ = kGradientInfoBubble;
}
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 = 0;
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 depending on the type of bubble.
if (bubbleType_ == kGradientInfoBubble) {
GTMTheme *theme = [GTMTheme defaultTheme];
NSGradient *gradient = [theme gradientForStyle:GTMThemeStyleToolBar
state:NO];
[gradient drawInBezierPath:bezier angle:0.0];
} else if (bubbleType_ == kWhiteInfoBubble) {
[[NSColor whiteColor] set];
[bezier fill];
}
}
@end
|