| 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 #include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h" | 5 #include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/views/layout_constants.h" | 8 #include "chrome/browser/ui/views/layout_constants.h" |
| 9 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" |
| 9 #include "ui/base/resource/material_design/material_design_controller.h" | 10 #include "ui/base/resource/material_design/material_design_controller.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
| 11 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
| 12 #include "ui/gfx/color_utils.h" | 13 #include "ui/gfx/color_utils.h" |
| 13 #include "ui/views/controls/image_view.h" | 14 #include "ui/views/controls/image_view.h" |
| 14 #include "ui/views/painter.h" | 15 #include "ui/views/painter.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 SkColor CalculateImageColor(gfx::ImageSkia* image) { | 19 SkColor CalculateImageColor(gfx::ImageSkia* image) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 background_painter_.reset( | 63 background_painter_.reset( |
| 63 views::Painter::CreateImageGridPainter(background_images)); | 64 views::Painter::CreateImageGridPainter(background_images)); |
| 64 // Use the middle image of the background to represent the color of the entire | 65 // Use the middle image of the background to represent the color of the entire |
| 65 // background. | 66 // background. |
| 66 gfx::ImageSkia* background_image = | 67 gfx::ImageSkia* background_image = |
| 67 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 68 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 68 background_images[4]); | 69 background_images[4]); |
| 69 SetLabelBackgroundColor(CalculateImageColor(background_image)); | 70 SetLabelBackgroundColor(CalculateImageColor(background_image)); |
| 70 } | 71 } |
| 71 | 72 |
| 72 void IconLabelBubbleView::SetBackgroundImageWithInsets(int background_image_id, | |
| 73 gfx::Insets& insets) { | |
| 74 gfx::ImageSkia* background_image = | |
| 75 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 76 background_image_id); | |
| 77 background_painter_.reset( | |
| 78 views::Painter::CreateImagePainter(*background_image, insets)); | |
| 79 SetLabelBackgroundColor(CalculateImageColor(background_image)); | |
| 80 } | |
| 81 | |
| 82 void IconLabelBubbleView::SetLabel(const base::string16& label) { | 73 void IconLabelBubbleView::SetLabel(const base::string16& label) { |
| 83 label_->SetText(label); | 74 label_->SetText(label); |
| 84 } | 75 } |
| 85 | 76 |
| 86 void IconLabelBubbleView::SetImage(const gfx::ImageSkia& image_skia) { | 77 void IconLabelBubbleView::SetImage(const gfx::ImageSkia& image_skia) { |
| 87 image_->SetImage(image_skia); | 78 image_->SetImage(image_skia); |
| 88 } | 79 } |
| 89 | 80 |
| 90 bool IconLabelBubbleView::ShouldShowBackground() const { | 81 bool IconLabelBubbleView::ShouldShowBackground() const { |
| 91 return true; | 82 return true; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 112 0, image_->GetPreferredSize().width(), height()); | 103 0, image_->GetPreferredSize().width(), height()); |
| 113 | 104 |
| 114 const int padding = GetLayoutConstant(ICON_LABEL_VIEW_INTERNAL_PADDING); | 105 const int padding = GetLayoutConstant(ICON_LABEL_VIEW_INTERNAL_PADDING); |
| 115 int pre_label_width = | 106 int pre_label_width = |
| 116 GetBubbleOuterPadding(true) + (image_width ? (image_width + padding) : 0); | 107 GetBubbleOuterPadding(true) + (image_width ? (image_width + padding) : 0); |
| 117 label_->SetBounds(pre_label_width, 0, | 108 label_->SetBounds(pre_label_width, 0, |
| 118 width() - pre_label_width - GetBubbleOuterPadding(false), | 109 width() - pre_label_width - GetBubbleOuterPadding(false), |
| 119 height()); | 110 height()); |
| 120 } | 111 } |
| 121 | 112 |
| 113 void IconLabelBubbleView::OnNativeThemeChanged( |
| 114 const ui::NativeTheme* native_theme) { |
| 115 if (!ui::MaterialDesignController::IsModeMaterial()) |
| 116 return; |
| 117 |
| 118 label_->SetEnabledColor(GetTextColor()); |
| 119 SkColor border_color = GetBorderColor(); |
| 120 SkColor background_color = SkColorSetA(border_color, 0x13); |
| 121 set_background( |
| 122 new BackgroundWith1PxBorder(background_color, border_color, false)); |
| 123 SetLabelBackgroundColor(background_color); |
| 124 } |
| 125 |
| 122 gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int width) const { | 126 gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int width) const { |
| 123 gfx::Size size(image_->GetPreferredSize()); | 127 gfx::Size size(image_->GetPreferredSize()); |
| 124 if (ShouldShowBackground()) { | 128 if (ShouldShowBackground()) { |
| 125 const int image_width = image_->GetPreferredSize().width(); | 129 const int image_width = image_->GetPreferredSize().width(); |
| 126 const int padding = GetLayoutConstant(ICON_LABEL_VIEW_INTERNAL_PADDING); | 130 const int padding = GetLayoutConstant(ICON_LABEL_VIEW_INTERNAL_PADDING); |
| 127 const int non_label_width = | 131 const int non_label_width = |
| 128 GetBubbleOuterPadding(true) + | 132 GetBubbleOuterPadding(true) + |
| 129 (image_width ? (image_width + padding) : 0) + | 133 (image_width ? (image_width + padding) : 0) + |
| 130 GetBubbleOuterPadding(false); | 134 GetBubbleOuterPadding(false); |
| 131 size = gfx::Size(WidthMultiplier() * (width + non_label_width), 0); | 135 size = gfx::Size(WidthMultiplier() * (width + non_label_width), 0); |
| 132 size.SetToMax(background_painter_->GetMinimumSize()); | 136 if (!ui::MaterialDesignController::IsModeMaterial()) |
| 137 size.SetToMax(background_painter_->GetMinimumSize()); |
| 133 } | 138 } |
| 134 | 139 |
| 135 return size; | 140 return size; |
| 136 } | 141 } |
| 137 | 142 |
| 138 int IconLabelBubbleView::GetBubbleOuterPadding(bool by_icon) const { | 143 int IconLabelBubbleView::GetBubbleOuterPadding(bool by_icon) const { |
| 139 return GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) - | 144 return GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) - |
| 140 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) + | 145 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) + |
| 141 (by_icon ? 0 : GetLayoutConstant(ICON_LABEL_VIEW_TRAILING_PADDING)); | 146 (by_icon ? 0 : GetLayoutConstant(ICON_LABEL_VIEW_TRAILING_PADDING)); |
| 142 } | 147 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 157 | 162 |
| 158 const char* IconLabelBubbleView::GetClassName() const { | 163 const char* IconLabelBubbleView::GetClassName() const { |
| 159 return "IconLabelBubbleView"; | 164 return "IconLabelBubbleView"; |
| 160 } | 165 } |
| 161 | 166 |
| 162 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { | 167 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { |
| 163 if (!ShouldShowBackground()) | 168 if (!ShouldShowBackground()) |
| 164 return; | 169 return; |
| 165 if (background_painter_) | 170 if (background_painter_) |
| 166 background_painter_->Paint(canvas, size()); | 171 background_painter_->Paint(canvas, size()); |
| 172 if (background()) |
| 173 background()->Paint(canvas, this); |
| 167 } | 174 } |
| OLD | NEW |