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