Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / views / location_bar / icon_label_bubble_view.h
blob11b6672645b04c9209cd15fc3412a6dbbbac7a03
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.
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_
8 #include <string>
10 #include "base/strings/string16.h"
11 #include "ui/gfx/geometry/insets.h"
12 #include "ui/gfx/geometry/size.h"
13 #include "ui/views/controls/label.h"
14 #include "ui/views/view.h"
16 namespace gfx {
17 class Canvas;
18 class FontList;
19 class ImageSkia;
22 namespace views {
23 class ImageView;
24 class Label;
25 class Painter;
28 // View used to draw a bubble, containing an icon and a label. We use this as a
29 // base for the classes that handle the EV bubble, tab-to-search UI, and
30 // content settings.
31 class IconLabelBubbleView : public views::View {
32 public:
33 IconLabelBubbleView(int contained_image,
34 const gfx::FontList& font_list,
35 SkColor text_color,
36 SkColor parent_background_color,
37 bool elide_in_middle);
38 ~IconLabelBubbleView() override;
40 // Sets a background that paints |background_images| in a scalable grid.
41 // Subclasses are required to call this or SetBackgroundImageWithInsets during
42 // construction.
43 void SetBackgroundImageGrid(const int background_images[]);
45 // Divides the image designated by |background_image_id| into nine regions.
46 // The four corners are specified by |insets|, the remainder are stretched to
47 // fill the background. Subclasses are required to call this or
48 // SetBackgroundImageGrid during construction.
49 void SetBackgroundImageWithInsets(int background_image_id,
50 gfx::Insets& insets);
52 void SetLabel(const base::string16& label);
53 void SetImage(const gfx::ImageSkia& image);
54 void set_is_extension_icon(bool is_extension_icon) {
55 is_extension_icon_ = is_extension_icon;
58 protected:
59 views::ImageView* image() { return image_; }
60 views::Label* label() { return label_; }
62 // Returns true when the background should be rendered.
63 virtual bool ShouldShowBackground() const;
65 // Returns a multiplier used to calculate the actual width of the view based
66 // on its desired width. This ranges from 0 for a zero-width view to 1 for a
67 // full-width view and can be used to animate the width of the view.
68 virtual double WidthMultiplier() const;
70 // views::View:
71 gfx::Size GetPreferredSize() const override;
72 void Layout() override;
74 const gfx::FontList& font_list() const { return label_->font_list(); }
76 gfx::Size GetSizeForLabelWidth(int width) const;
78 private:
79 // Amount of padding at the edges of the bubble. If |by_icon| is true, this
80 // is the padding next to the icon; otherwise it's the padding next to the
81 // label. (We increase padding next to the label by the amount of padding
82 // "built in" to the icon in order to make the bubble appear to have
83 // symmetrical padding.)
84 int GetBubbleOuterPadding(bool by_icon) const;
86 // Sets a background color on |label_| based on |background_image_color| and
87 // |parent_background_color_|.
88 void SetLabelBackgroundColor(SkColor background_image_color);
90 // views::View:
91 const char* GetClassName() const override;
92 void OnPaint(gfx::Canvas* canvas) override;
94 // For painting the background.
95 scoped_ptr<views::Painter> background_painter_;
97 // The contents of the bubble.
98 views::ImageView* image_;
99 views::Label* label_;
101 bool is_extension_icon_;
103 SkColor parent_background_color_;
105 DISALLOW_COPY_AND_ASSIGN(IconLabelBubbleView);
108 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ICON_LABEL_BUBBLE_VIEW_H_