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 #ifndef CHROME_BROWSER_UI_COCOA_LOCATION_BAR_BUBBLE_DECORATION_H_ 6 #define CHROME_BROWSER_UI_COCOA_LOCATION_BAR_BUBBLE_DECORATION_H_ 7 8 #import <Cocoa/Cocoa.h> 9 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" 14 15 // Draws an outlined rounded rect, with an optional image to the left 16 // and an optional text label to the right. 17 18 class BubbleDecoration : public LocationBarDecoration { 19 public: 20 BubbleDecoration(); 21 virtual ~BubbleDecoration(); 22 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; 29 30 // Implement |LocationBarDecoration|. 31 virtual void DrawInFrame(NSRect frame, NSView* control_view) OVERRIDE; 32 virtual void DrawWithBackgroundInFrame(NSRect background_frame, 33 NSRect frame, 34 NSView* control_view) OVERRIDE; 35 virtual CGFloat GetWidthForSpace(CGFloat width) OVERRIDE; 36 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); 41 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); 45 46 private: 47 friend class SelectedKeywordDecorationTest; 48 FRIEND_TEST_ALL_PREFIXES(SelectedKeywordDecorationTest, 49 UsesPartialKeywordIfNarrow); 50 51 // Image drawn in the left side of the bubble. 52 base::scoped_nsobject<NSImage> image_; 53 54 // Label to draw to right of image. Can be |nil|. 55 base::scoped_nsobject<NSString> label_; 56 57 // Contains attribute for drawing |label_|. 58 base::scoped_nsobject<NSMutableDictionary> attributes_; 59 60 DISALLOW_COPY_AND_ASSIGN(BubbleDecoration); 61 }; 62 63 #endif // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_BUBBLE_DECORATION_H_ 64