Home | History | Annotate | Download | only in location_bar
      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 #pragma once
      8 
      9 #import <Cocoa/Cocoa.h>
     10 
     11 #include "base/gtest_prod_util.h"
     12 #include "base/memory/scoped_nsobject.h"
     13 #include "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.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   // |font| will be used when drawing the label, and cannot be |nil|.
     21   BubbleDecoration(NSFont* font);
     22   virtual ~BubbleDecoration();
     23 
     24   // Setup the drawing parameters.
     25   NSImage* GetImage();
     26   void SetImage(NSImage* image);
     27   void SetLabel(NSString* label);
     28   void SetColors(NSColor* border_color,
     29                  NSColor* background_color,
     30                  NSColor* text_color);
     31 
     32   // Implement |LocationBarDecoration|.
     33   virtual void DrawInFrame(NSRect frame, NSView* control_view);
     34   virtual CGFloat GetWidthForSpace(CGFloat width);
     35 
     36  protected:
     37   // Helper returning bubble width for the given |image| and |label|
     38   // assuming |font_| (for sizing text).  Arguments can be nil.
     39   CGFloat GetWidthForImageAndLabel(NSImage* image, NSString* label);
     40 
     41   // Helper to return where the image is drawn, for subclasses to drag
     42   // from.  |frame| is the decoration's frame in the containing cell.
     43   NSRect GetImageRectInFrame(NSRect frame);
     44 
     45  private:
     46   friend class SelectedKeywordDecorationTest;
     47   FRIEND_TEST_ALL_PREFIXES(SelectedKeywordDecorationTest,
     48                            UsesPartialKeywordIfNarrow);
     49 
     50   // Contains font and color attribute for drawing |label_|.
     51   scoped_nsobject<NSDictionary> attributes_;
     52 
     53   // Image drawn in the left side of the bubble.
     54   scoped_nsobject<NSImage> image_;
     55 
     56   // Label to draw to right of image.  Can be |nil|.
     57   scoped_nsobject<NSString> label_;
     58 
     59   // Colors used to draw the bubble, should be set by the subclass
     60   // constructor.
     61   scoped_nsobject<NSColor> background_color_;
     62   scoped_nsobject<NSColor> border_color_;
     63 
     64   DISALLOW_COPY_AND_ASSIGN(BubbleDecoration);
     65 };
     66 
     67 #endif  // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_BUBBLE_DECORATION_H_
     68