Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: chrome/browser/ui/views/location_bar/icon_label_bubble_view.h

Issue 2348853004: Remove non-md code in location bar (Views). (Closed)
Patch Set: images Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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_VIEWS_LOCATION_BAR_ICON_LABEL_BUBBLE_VIEW_H_ 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_ 6 #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ICON_LABEL_BUBBLE_VIEW_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "ui/gfx/geometry/insets.h" 12 #include "ui/gfx/geometry/insets.h"
13 #include "ui/gfx/geometry/size.h" 13 #include "ui/gfx/geometry/size.h"
14 #include "ui/views/animation/ink_drop_host_view.h" 14 #include "ui/views/animation/ink_drop_host_view.h"
15 #include "ui/views/controls/label.h" 15 #include "ui/views/controls/label.h"
16 16
17 namespace gfx { 17 namespace gfx {
18 class Canvas; 18 class Canvas;
19 class FontList; 19 class FontList;
20 class ImageSkia; 20 class ImageSkia;
21 } 21 }
22 22
23 namespace views { 23 namespace views {
24 class ImageView; 24 class ImageView;
25 class Label; 25 class Label;
26 class Painter;
27 } 26 }
28 27
29 // View used to draw a bubble, containing an icon and a label. We use this as a 28 // View used to draw a bubble, containing an icon and a label. We use this as a
30 // base for the classes that handle the location icon (including the EV bubble), 29 // base for the classes that handle the location icon (including the EV bubble),
31 // tab-to-search UI, and content settings. 30 // tab-to-search UI, and content settings.
32 class IconLabelBubbleView : public views::InkDropHostView { 31 class IconLabelBubbleView : public views::InkDropHostView {
33 public: 32 public:
34 static constexpr int kTrailingPaddingPreMd = 2; 33 static constexpr int kTrailingPaddingPreMd = 2;
35 34
36 IconLabelBubbleView(int contained_image, 35 IconLabelBubbleView(const gfx::FontList& font_list, bool elide_in_middle);
37 const gfx::FontList& font_list,
38 SkColor parent_background_color,
39 bool elide_in_middle);
40 ~IconLabelBubbleView() override; 36 ~IconLabelBubbleView() override;
41 37
42 // Sets a background that paints |background_images| in a scalable grid.
43 // Subclasses must call this during construction.
44 void SetBackgroundImageGrid(const int background_images[]);
45 void UnsetBackgroundImageGrid();
46
47 void SetLabel(const base::string16& label); 38 void SetLabel(const base::string16& label);
48 void SetImage(const gfx::ImageSkia& image); 39 void SetImage(const gfx::ImageSkia& image);
49 void set_is_extension_icon(bool is_extension_icon) {
50 is_extension_icon_ = is_extension_icon;
51 }
52 40
53 const views::ImageView* GetImageView() const { return image_; } 41 const views::ImageView* GetImageView() const { return image_; }
54 views::ImageView* GetImageView() { return image_; } 42 views::ImageView* GetImageView() { return image_; }
55 43
56 protected: 44 protected:
57 static constexpr int kOpenTimeMS = 150; 45 static constexpr int kOpenTimeMS = 150;
58 46
59 views::ImageView* image() { return image_; } 47 views::ImageView* image() { return image_; }
60 views::Label* label() { return label_; } 48 views::Label* label() { return label_; }
61 const views::Label* label() const { return label_; } 49 const views::Label* label() const { return label_; }
62 50
63 // Gets the color for displaying text. 51 // Gets the color for displaying text.
64 virtual SkColor GetTextColor() const = 0; 52 virtual SkColor GetTextColor() const = 0;
65 53
66 // Gets the color for the border (a more transparent version of which is used 54 // Gets the color for the border (a more transparent version of which is used
67 // for the background). 55 // for the background).
68 virtual SkColor GetBorderColor() const = 0; 56 virtual SkColor GetBorderColor() const = 0;
69 57
70 // Returns true when the background should be rendered. 58 // Returns true when the label should be visible.
71 virtual bool ShouldShowBackground() const; 59 virtual bool ShouldShowLabel() const;
72 60
73 // Returns a multiplier used to calculate the actual width of the view based 61 // Returns a multiplier used to calculate the actual width of the view based
74 // on its desired width. This ranges from 0 for a zero-width view to 1 for a 62 // on its desired width. This ranges from 0 for a zero-width view to 1 for a
75 // full-width view and can be used to animate the width of the view. 63 // full-width view and can be used to animate the width of the view.
76 virtual double WidthMultiplier() const; 64 virtual double WidthMultiplier() const;
77 65
78 // Returns true when animation is in progress and is shrinking. 66 // Returns true when animation is in progress and is shrinking.
79 virtual bool IsShrinking() const; 67 virtual bool IsShrinking() const;
80 68
81 // The view has been activated by a user gesture such as spacebar. Returns 69 // The view has been activated by a user gesture such as spacebar. Returns
(...skipping 16 matching lines...) Expand all
98 86
99 SkColor GetParentBackgroundColor() const; 87 SkColor GetParentBackgroundColor() const;
100 88
101 gfx::Size GetSizeForLabelWidth(int label_width) const; 89 gfx::Size GetSizeForLabelWidth(int label_width) const;
102 90
103 // Returns the minimum width the view can be to show the complete image when 91 // Returns the minimum width the view can be to show the complete image when
104 // the background is showing. 92 // the background is showing.
105 int MinimumWidthForImageWithBackgroundShown() const; 93 int MinimumWidthForImageWithBackgroundShown() const;
106 94
107 private: 95 private:
108 // Sets a background color on |label_| based on |chip_background_color| and
109 // the parent's bg color.
110 void SetLabelBackgroundColor(SkColor chip_background_color);
111
112 // Amount of padding from the leading edge of the view to the leading edge of 96 // Amount of padding from the leading edge of the view to the leading edge of
113 // the image (if |leading| is true), or from the trailing edge of the label 97 // the image, and from the trailing edge of the label (or image, if the label
114 // (or image, if the label is invisible) to the trailing edge of the view. 98 // is invisible) to the trailing edge of the view.
115 int GetOuterPadding(bool leading) const; 99 int GetOuterPadding() const;
116 100
117 // Horizontal position of the image trailing edge (i.e. just after the image). 101 // Horizontal position of the image trailing edge (i.e. just after the image).
118 int GetImageTrailingEdge() const; 102 int GetImageTrailingEdge() const;
119 103
120 // Spacing between the image and the label. 104 // Spacing between the image and the label.
121 int GetInternalSpacing() const; 105 int GetInternalSpacing() const;
122 106
123 // Padding after the separator. 107 // Padding after the separator.
124 int GetPostSeparatorPadding() const; 108 int GetPostSeparatorPadding() const;
125 109
126 // views::View: 110 // views::View:
127 const char* GetClassName() const override; 111 const char* GetClassName() const override;
128 void OnPaint(gfx::Canvas* canvas) override; 112 void OnPaint(gfx::Canvas* canvas) override;
129 113
130 // For painting the background. TODO(estade): remove post MD launch.
131 std::unique_ptr<views::Painter> background_painter_;
132
133 // The contents of the bubble. 114 // The contents of the bubble.
134 views::ImageView* image_; 115 views::ImageView* image_;
135 views::Label* label_; 116 views::Label* label_;
136 117
137 bool is_extension_icon_;
138
139 // This is only used in pre-MD. In MD, the background color is derived from
140 // the native theme (so it responds to native theme updates). TODO(estade):
141 // remove when MD is default.
142 SkColor parent_background_color_;
143
144 bool should_show_background_;
145
146 DISALLOW_COPY_AND_ASSIGN(IconLabelBubbleView); 118 DISALLOW_COPY_AND_ASSIGN(IconLabelBubbleView);
147 }; 119 };
148 120
149 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ICON_LABEL_BUBBLE_VIEW_H_ 121 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ICON_LABEL_BUBBLE_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698