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
3// found in the LICENSE file.
4
5#import <Cocoa/Cocoa.h>
6
7#include "base/mac/scoped_nsobject.h"
8
9// A view class that looks like a "bubble" with rounded corners and displays
10// text inside. Can be themed. To put flush against the sides of a window, the
11// corner flags can be adjusted.
12
13// Constants that define where the bubble will have a rounded corner. If
14// not set, the corner will be square.
15enum {
16  kRoundedTopLeftCorner = 1,
17  kRoundedTopRightCorner = 1 << 1,
18  kRoundedBottomLeftCorner = 1 << 2,
19  kRoundedBottomRightCorner = 1 << 3,
20  kRoundedAllCorners = kRoundedTopLeftCorner |
21                       kRoundedTopRightCorner |
22                       kRoundedBottomLeftCorner |
23                       kRoundedBottomRightCorner
24};
25
26// Constants that affect where the text is positioned within the view. They
27// are exposed in case anyone needs to use the padding to set the content string
28// length appropriately based on available space (such as eliding a URL).
29enum {
30  kBubbleViewTextPositionX = 4,
31  kBubbleViewTextPositionY = 2
32};
33
34@interface BubbleView : NSView {
35 @private
36  base::scoped_nsobject<NSString> content_;
37  unsigned long cornerFlags_;
38  // The window from which we get the theme used to draw. In some cases,
39  // it might not be the window we're in. As a result, this may or may not
40  // directly own us, so it needs to be weak to prevent a cycle.
41  NSWindow* themeProvider_;
42}
43
44// Designated initializer. |provider| is the window from which we get the
45// current theme to draw text and backgrounds. If nil, the current window will
46// be checked. The caller needs to ensure |provider| can't go away as it will
47// not be retained. Defaults to all corners being rounded.
48- (id)initWithFrame:(NSRect)frame themeProvider:(NSWindow*)provider;
49
50// Sets the string displayed in the bubble. A copy of the string is made.
51- (void)setContent:(NSString*)content;
52
53// Sets which corners will be rounded.
54- (void)setCornerFlags:(unsigned long)flags;
55
56// Sets the window whose theme is used to draw.
57- (void)setThemeProvider:(NSWindow*)provider;
58
59// The font used to display the content string.
60- (NSFont*)font;
61
62@end
63
64// APIs exposed only for testing.
65@interface BubbleView(TestingOnly)
66- (NSString*)content;
67- (unsigned long)cornerFlags;
68@end
69