Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / location_bar / bubble_decoration.h
blob25b5bd8f70a32e6c3d6a886c5e6f8b8d8b94f712
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 {
19 public:
20 BubbleDecoration();
21 ~BubbleDecoration() override;
23 // Setup the drawing parameters.
24 NSImage* GetImage();
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 void DrawInFrame(NSRect frame, NSView* control_view) override;
32 void DrawWithBackgroundInFrame(NSRect background_frame,
33 NSRect frame,
34 NSView* control_view) override;
35 CGFloat GetWidthForSpace(CGFloat width) override;
37 protected:
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);
46 private:
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_