| OLD | NEW |
| 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_; } |
| 48 const views::ImageView* image() const { return image_; } |
| 60 views::Label* label() { return label_; } | 49 views::Label* label() { return label_; } |
| 61 const views::Label* label() const { return label_; } | 50 const views::Label* label() const { return label_; } |
| 62 | 51 |
| 63 // Gets the color for displaying text. | 52 // Gets the color for displaying text. |
| 64 virtual SkColor GetTextColor() const = 0; | 53 virtual SkColor GetTextColor() const = 0; |
| 65 | 54 |
| 66 // Gets the color for the border (a more transparent version of which is used | 55 // Returns true when the label should be visible. |
| 67 // for the background). | 56 virtual bool ShouldShowLabel() const; |
| 68 virtual SkColor GetBorderColor() const = 0; | |
| 69 | |
| 70 // Returns true when the background should be rendered. | |
| 71 virtual bool ShouldShowBackground() const; | |
| 72 | 57 |
| 73 // Returns a multiplier used to calculate the actual width of the view based | 58 // 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 | 59 // 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. | 60 // full-width view and can be used to animate the width of the view. |
| 76 virtual double WidthMultiplier() const; | 61 virtual double WidthMultiplier() const; |
| 77 | 62 |
| 78 // Returns true when animation is in progress and is shrinking. | 63 // Returns true when animation is in progress and is shrinking. |
| 79 virtual bool IsShrinking() const; | 64 virtual bool IsShrinking() const; |
| 80 | 65 |
| 81 // The view has been activated by a user gesture such as spacebar. Returns | 66 // The view has been activated by a user gesture such as spacebar. Returns |
| (...skipping 11 matching lines...) Expand all Loading... |
| 93 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() | 78 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() |
| 94 const override; | 79 const override; |
| 95 SkColor GetInkDropBaseColor() const override; | 80 SkColor GetInkDropBaseColor() const override; |
| 96 | 81 |
| 97 const gfx::FontList& font_list() const { return label_->font_list(); } | 82 const gfx::FontList& font_list() const { return label_->font_list(); } |
| 98 | 83 |
| 99 SkColor GetParentBackgroundColor() const; | 84 SkColor GetParentBackgroundColor() const; |
| 100 | 85 |
| 101 gfx::Size GetSizeForLabelWidth(int label_width) const; | 86 gfx::Size GetSizeForLabelWidth(int label_width) const; |
| 102 | 87 |
| 103 // Returns the minimum width the view can be to show the complete image when | |
| 104 // the background is showing. | |
| 105 int MinimumWidthForImageWithBackgroundShown() const; | |
| 106 | |
| 107 private: | 88 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 | 89 // 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 | 90 // 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. | 91 // is invisible) to the trailing edge of the view. |
| 115 int GetOuterPadding(bool leading) const; | 92 int GetOuterPadding() const; |
| 116 | |
| 117 // Horizontal position of the image trailing edge (i.e. just after the image). | |
| 118 int GetImageTrailingEdge() const; | |
| 119 | 93 |
| 120 // Spacing between the image and the label. | 94 // Spacing between the image and the label. |
| 121 int GetInternalSpacing() const; | 95 int GetInternalSpacing() const; |
| 122 | 96 |
| 123 // Padding after the separator. | 97 // Padding after the separator. |
| 124 int GetPostSeparatorPadding() const; | 98 int GetPostSeparatorPadding() const; |
| 125 | 99 |
| 126 // views::View: | 100 // views::View: |
| 127 const char* GetClassName() const override; | 101 const char* GetClassName() const override; |
| 128 void OnPaint(gfx::Canvas* canvas) override; | 102 void OnPaint(gfx::Canvas* canvas) override; |
| 129 | 103 |
| 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. | 104 // The contents of the bubble. |
| 134 views::ImageView* image_; | 105 views::ImageView* image_; |
| 135 views::Label* label_; | 106 views::Label* label_; |
| 136 | 107 |
| 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); | 108 DISALLOW_COPY_AND_ASSIGN(IconLabelBubbleView); |
| 147 }; | 109 }; |
| 148 | 110 |
| 149 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ICON_LABEL_BUBBLE_VIEW_H_ | 111 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ICON_LABEL_BUBBLE_VIEW_H_ |
| OLD | NEW |