icon_label_bubble_view.h revision 868fa2fe829687343ffae624259930155e16dbd8
1// Copyright (c) 2012 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_VIEWS_LOCATION_BAR_ICON_LABEL_BUBBLE_VIEW_H_ 6#define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ICON_LABEL_BUBBLE_VIEW_H_ 7 8#include <string> 9 10#include "base/strings/string16.h" 11#include "ui/gfx/size.h" 12#include "ui/views/view.h" 13 14namespace gfx { 15class Canvas; 16class Font; 17class ImageSkia; 18} 19 20namespace views { 21class ImageView; 22class Label; 23class Painter; 24} 25 26// View used to draw a bubble to the left of the address, containing an icon and 27// a label. We use this as a base for the classes that handle the EV bubble and 28// tab-to-search UI. 29class IconLabelBubbleView : public views::View { 30 public: 31 // The label will be positioned |font_y_offset| px. from the top of the view. 32 IconLabelBubbleView(const int background_images[], 33 int contained_image, 34 const gfx::Font& font, 35 int font_y_offset, 36 SkColor text_color, 37 SkColor parent_background_color, 38 bool elide_in_middle); 39 virtual ~IconLabelBubbleView(); 40 41 void SetLabel(const string16& label); 42 void SetImage(const gfx::ImageSkia& image); 43 void set_is_extension_icon(bool is_extension_icon) { 44 is_extension_icon_ = is_extension_icon; 45 } 46 47 protected: 48 // views::View: 49 virtual gfx::Size GetPreferredSize() OVERRIDE; 50 virtual void Layout() OVERRIDE; 51 52 gfx::Size GetSizeForLabelWidth(int width) const; 53 54 private: 55 // Amount of padding at the edges of the bubble. If |by_icon| is true, this 56 // is the padding next to the icon; otherwise it's the padding next to the 57 // label. (We increase padding next to the label by the amount of padding 58 // "built in" to the icon in order to make the bubble appear to have 59 // symmetrical padding.) 60 static int GetBubbleOuterPadding(bool by_icon); 61 62 // views::View: 63 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 64 65 int GetPreLabelWidth() const; 66 67 // For painting the background. 68 scoped_ptr<views::Painter> background_painter_; 69 70 // The contents of the bubble. 71 views::ImageView* image_; 72 views::Label* label_; 73 74 bool is_extension_icon_; 75 76 DISALLOW_COPY_AND_ASSIGN(IconLabelBubbleView); 77}; 78 79#endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ICON_LABEL_BUBBLE_VIEW_H_ 80