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.
5 #ifndef CHROME_BROWSER_UI_COCOA_LOCATION_BAR_BUBBLE_DECORATION_H_
6 #define CHROME_BROWSER_UI_COCOA_LOCATION_BAR_BUBBLE_DECORATION_H_
8 #import <Cocoa/Cocoa.h>
10 #include "base/gtest_prod_util.h"
11 #include "base/mac/scoped_nsobject.h"
12 #include "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h"
13 #import "ui/base/cocoa/appkit_utils.h"
15 // Draws an outlined rounded rect, with an optional image to the left
16 // and an optional text label to the right.
18 class BubbleDecoration
: public LocationBarDecoration
{
21 virtual ~BubbleDecoration();
23 // Setup the drawing parameters.
25 void SetImage(NSImage
* image
);
26 void SetLabel(NSString
* label
);
27 void SetTextColor(NSColor
* text_color
);
28 virtual ui::NinePartImageIds
GetBubbleImageIds() = 0;
30 // Implement |LocationBarDecoration|.
31 virtual void DrawInFrame(NSRect frame
, NSView
* control_view
) OVERRIDE
;
32 virtual void DrawWithBackgroundInFrame(NSRect background_frame
,
34 NSView
* control_view
) OVERRIDE
;
35 virtual CGFloat
GetWidthForSpace(CGFloat width
) OVERRIDE
;
38 // Helper returning bubble width for the given |image| and |label|
39 // assuming |font_| (for sizing text). Arguments can be nil.
40 CGFloat
GetWidthForImageAndLabel(NSImage
* image
, NSString
* label
);
42 // Helper to return where the image is drawn, for subclasses to drag
43 // from. |frame| is the decoration's frame in the containing cell.
44 NSRect
GetImageRectInFrame(NSRect frame
);
47 friend class SelectedKeywordDecorationTest
;
48 FRIEND_TEST_ALL_PREFIXES(SelectedKeywordDecorationTest
,
49 UsesPartialKeywordIfNarrow
);
51 // Image drawn in the left side of the bubble.
52 base::scoped_nsobject
<NSImage
> image_
;
54 // Label to draw to right of image. Can be |nil|.
55 base::scoped_nsobject
<NSString
> label_
;
57 // Contains attribute for drawing |label_|.
58 base::scoped_nsobject
<NSMutableDictionary
> attributes_
;
60 DISALLOW_COPY_AND_ASSIGN(BubbleDecoration
);
63 #endif // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_BUBBLE_DECORATION_H_