| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_COCOA_LOCATION_BAR_BUBBLE_DECORATION_H_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_LOCATION_BAR_BUBBLE_DECORATION_H_ |
| 6 #define CHROME_BROWSER_UI_COCOA_LOCATION_BAR_BUBBLE_DECORATION_H_ | 6 #define CHROME_BROWSER_UI_COCOA_LOCATION_BAR_BUBBLE_DECORATION_H_ |
| 7 | 7 |
| 8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
| 9 | 9 |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| 11 #include "base/mac/scoped_nsobject.h" | 11 #include "base/mac/scoped_nsobject.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" | 13 #include "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" |
| 14 #import "ui/base/cocoa/appkit_utils.h" | 14 #import "ui/base/cocoa/appkit_utils.h" |
| 15 | 15 |
| 16 // Draws an outlined rounded rect, with an optional image to the left | 16 // Draws an outlined rounded rect, with an optional image to the left |
| 17 // and an optional text label to the right. | 17 // and an optional text label to the right. |
| 18 | 18 |
| 19 class BubbleDecoration : public LocationBarDecoration { | 19 class BubbleDecoration : public LocationBarDecoration { |
| 20 public: | 20 public: |
| 21 BubbleDecoration(); | 21 BubbleDecoration(); |
| 22 ~BubbleDecoration() override; | 22 ~BubbleDecoration() override; |
| 23 | 23 |
| 24 // Setup the drawing parameters. | 24 // Setup the drawing parameters. |
| 25 NSImage* GetImage(); | 25 NSImage* GetImage(); |
| 26 virtual NSColor* GetBackgroundBorderColor() = 0; | 26 virtual NSColor* GetBackgroundBorderColor() = 0; |
| 27 void SetImage(NSImage* image); | 27 void SetImage(NSImage* image); |
| 28 void SetLabel(NSString* label); | 28 void SetLabel(NSString* label); |
| 29 void SetTextColor(NSColor* text_color); | 29 void SetTextColor(NSColor* text_color); |
| 30 void SetFont(NSFont* font); |
| 31 void SetBaselineOffset(CGFloat offset); |
| 30 virtual ui::NinePartImageIds GetBubbleImageIds() = 0; | 32 virtual ui::NinePartImageIds GetBubbleImageIds() = 0; |
| 31 | 33 |
| 32 // Implement |LocationBarDecoration|. | 34 // Implement |LocationBarDecoration|. |
| 35 CGFloat GetWidthForSpace(CGFloat width) override; |
| 33 void DrawInFrame(NSRect frame, NSView* control_view) override; | 36 void DrawInFrame(NSRect frame, NSView* control_view) override; |
| 34 void DrawWithBackgroundInFrame(NSRect background_frame, | 37 void DrawWithBackgroundInFrame(NSRect background_frame, |
| 35 NSRect frame, | 38 NSRect frame, |
| 36 NSView* control_view) override; | 39 NSView* control_view) override; |
| 37 CGFloat GetWidthForSpace(CGFloat width) override; | 40 NSFont* GetFont() const override; |
| 38 | 41 |
| 39 protected: | 42 protected: |
| 40 // Helper returning bubble width for the given |image| and |label| | 43 // Helper returning bubble width for the given |image| and |label| |
| 41 // assuming |font_| (for sizing text). Arguments can be nil. | 44 // assuming |font_| (for sizing text). Arguments can be nil. |
| 42 CGFloat GetWidthForImageAndLabel(NSImage* image, NSString* label); | 45 CGFloat GetWidthForImageAndLabel(NSImage* image, NSString* label); |
| 43 | 46 |
| 44 // Helper to return where the image is drawn, for subclasses to drag | 47 // Helper to return where the image is drawn, for subclasses to drag |
| 45 // from. |frame| is the decoration's frame in the containing cell. | 48 // from. |frame| is the decoration's frame in the containing cell. |
| 46 NSRect GetImageRectInFrame(NSRect frame); | 49 NSRect GetImageRectInFrame(NSRect frame); |
| 47 | 50 |
| 48 private: | 51 private: |
| 49 friend class SelectedKeywordDecorationTest; | 52 friend class SelectedKeywordDecorationTest; |
| 50 FRIEND_TEST_ALL_PREFIXES(SelectedKeywordDecorationTest, | 53 FRIEND_TEST_ALL_PREFIXES(SelectedKeywordDecorationTest, |
| 51 UsesPartialKeywordIfNarrow); | 54 UsesPartialKeywordIfNarrow); |
| 52 | 55 |
| 53 // Image drawn in the left side of the bubble. | 56 // Image drawn in the left side of the bubble. |
| 54 base::scoped_nsobject<NSImage> image_; | 57 base::scoped_nsobject<NSImage> image_; |
| 55 | 58 |
| 56 // Label to draw to right of image. Can be |nil|. | 59 // Label to draw to right of image. Can be |nil|. |
| 57 base::scoped_nsobject<NSString> label_; | 60 base::scoped_nsobject<NSString> label_; |
| 58 | 61 |
| 59 // Contains attribute for drawing |label_|. | 62 // Contains attribute for drawing |label_|. |
| 60 base::scoped_nsobject<NSMutableDictionary> attributes_; | 63 base::scoped_nsobject<NSMutableDictionary> attributes_; |
| 61 | 64 |
| 65 // Contains any baseline adjustment for the text. |
| 66 CGFloat baseline_offset_; |
| 67 |
| 62 DISALLOW_COPY_AND_ASSIGN(BubbleDecoration); | 68 DISALLOW_COPY_AND_ASSIGN(BubbleDecoration); |
| 63 }; | 69 }; |
| 64 | 70 |
| 65 #endif // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_BUBBLE_DECORATION_H_ | 71 #endif // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_BUBBLE_DECORATION_H_ |
| OLD | NEW |