OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 5 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_nsobject.h" | 8 #include "base/memory/scoped_nsobject.h" |
9 | 9 |
10 @implementation InfoBubbleView | 10 @implementation InfoBubbleView |
11 | 11 |
12 @synthesize arrowLocation = arrowLocation_; | 12 @synthesize arrowLocation = arrowLocation_; |
13 | 13 |
14 - (id)initWithFrame:(NSRect)frameRect { | 14 - (id)initWithFrame:(NSRect)frameRect { |
15 if ((self = [super initWithFrame:frameRect])) { | 15 if ((self = [super initWithFrame:frameRect])) { |
16 arrowLocation_ = info_bubble::kTopLeft; | 16 arrowLocation_ = info_bubble::kTopLeft; |
17 } | 17 } |
18 return self; | 18 return self; |
19 } | 19 } |
20 | 20 |
21 - (void)drawRect:(NSRect)rect { | 21 - (void)drawRect:(NSRect)rect { |
22 // Make room for the border to be seen. | 22 // Make room for the border to be seen. |
23 NSRect bounds = [self bounds]; | 23 NSRect bounds = [self bounds]; |
24 bounds.size.height -= info_bubble::kBubbleArrowHeight; | 24 if (arrowLocation_ != info_bubble::kNoArrow) { |
| 25 bounds.size.height -= info_bubble::kBubbleArrowHeight; |
| 26 } |
25 NSBezierPath* bezier = [NSBezierPath bezierPath]; | 27 NSBezierPath* bezier = [NSBezierPath bezierPath]; |
26 rect.size.height -= info_bubble::kBubbleArrowHeight; | 28 rect.size.height -= info_bubble::kBubbleArrowHeight; |
27 | 29 |
28 // Start with a rounded rectangle. | 30 // Start with a rounded rectangle. |
29 [bezier appendBezierPathWithRoundedRect:bounds | 31 [bezier appendBezierPathWithRoundedRect:bounds |
30 xRadius:info_bubble::kBubbleCornerRadius | 32 xRadius:info_bubble::kBubbleCornerRadius |
31 yRadius:info_bubble::kBubbleCornerRadius]; | 33 yRadius:info_bubble::kBubbleCornerRadius]; |
32 | 34 |
33 // Add the bubble arrow. | 35 // Add the bubble arrow. |
34 CGFloat dX = 0; | 36 CGFloat dX = 0; |
35 switch (arrowLocation_) { | 37 switch (arrowLocation_) { |
36 case info_bubble::kTopLeft: | 38 case info_bubble::kTopLeft: |
37 dX = info_bubble::kBubbleArrowXOffset; | 39 dX = info_bubble::kBubbleArrowXOffset; |
38 break; | 40 break; |
39 case info_bubble::kTopRight: | 41 case info_bubble::kTopRight: |
40 dX = NSWidth(bounds) - info_bubble::kBubbleArrowXOffset - | 42 dX = NSWidth(bounds) - info_bubble::kBubbleArrowXOffset - |
41 info_bubble::kBubbleArrowWidth; | 43 info_bubble::kBubbleArrowWidth; |
42 break; | 44 break; |
| 45 case info_bubble::kNoArrow: |
| 46 break; |
43 default: | 47 default: |
44 NOTREACHED(); | 48 NOTREACHED(); |
45 break; | 49 break; |
46 } | 50 } |
47 NSPoint arrowStart = NSMakePoint(NSMinX(bounds), NSMaxY(bounds)); | 51 NSPoint arrowStart = NSMakePoint(NSMinX(bounds), NSMaxY(bounds)); |
48 arrowStart.x += dX; | 52 arrowStart.x += dX; |
49 [bezier moveToPoint:NSMakePoint(arrowStart.x, arrowStart.y)]; | 53 [bezier moveToPoint:NSMakePoint(arrowStart.x, arrowStart.y)]; |
50 [bezier lineToPoint:NSMakePoint(arrowStart.x + | 54 if (arrowLocation_ != info_bubble::kNoArrow) { |
51 info_bubble::kBubbleArrowWidth / 2.0, | 55 [bezier lineToPoint:NSMakePoint(arrowStart.x + |
52 arrowStart.y + | 56 info_bubble::kBubbleArrowWidth / 2.0, |
53 info_bubble::kBubbleArrowHeight)]; | 57 arrowStart.y + |
| 58 info_bubble::kBubbleArrowHeight)]; |
| 59 } |
54 [bezier lineToPoint:NSMakePoint(arrowStart.x + info_bubble::kBubbleArrowWidth, | 60 [bezier lineToPoint:NSMakePoint(arrowStart.x + info_bubble::kBubbleArrowWidth, |
55 arrowStart.y)]; | 61 arrowStart.y)]; |
56 [bezier closePath]; | 62 [bezier closePath]; |
57 [[NSColor whiteColor] set]; | 63 [[NSColor whiteColor] set]; |
58 [bezier fill]; | 64 [bezier fill]; |
59 } | 65 } |
60 | 66 |
61 - (NSPoint)arrowTip { | 67 - (NSPoint)arrowTip { |
62 NSRect bounds = [self bounds]; | 68 NSRect bounds = [self bounds]; |
63 CGFloat tipXOffset = | 69 CGFloat tipXOffset = |
64 info_bubble::kBubbleArrowXOffset + info_bubble::kBubbleArrowWidth / 2.0; | 70 info_bubble::kBubbleArrowXOffset + info_bubble::kBubbleArrowWidth / 2.0; |
65 CGFloat xOffset = | 71 CGFloat xOffset = |
66 (arrowLocation_ == info_bubble::kTopRight) ? NSMaxX(bounds) - tipXOffset : | 72 (arrowLocation_ == info_bubble::kTopRight) ? NSMaxX(bounds) - tipXOffset : |
67 NSMinX(bounds) + tipXOffset; | 73 NSMinX(bounds) + tipXOffset; |
68 NSPoint arrowTip = NSMakePoint(xOffset, NSMaxY(bounds)); | 74 NSPoint arrowTip = NSMakePoint(xOffset, NSMaxY(bounds)); |
69 return arrowTip; | 75 return arrowTip; |
70 } | 76 } |
71 | 77 |
72 @end | 78 @end |
OLD | NEW |