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

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

Issue 1448433004: [MD] update EV bubble icon and location bar https icons (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update Created 5 years, 1 month 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 #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 "chrome/browser/ui/views/location_bar/background_with_1_px_border.h"
10 #include "ui/base/resource/material_design/material_design_controller.h" 10 #include "ui/base/resource/material_design/material_design_controller.h"
11 #include "ui/base/resource/resource_bundle.h" 11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/gfx/canvas.h" 12 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/color_utils.h" 13 #include "ui/gfx/color_utils.h"
14 #include "ui/native_theme/native_theme.h"
14 #include "ui/views/controls/image_view.h" 15 #include "ui/views/controls/image_view.h"
15 #include "ui/views/painter.h" 16 #include "ui/views/painter.h"
16 17
17 namespace { 18 namespace {
18 19
19 SkColor CalculateImageColor(gfx::ImageSkia* image) { 20 SkColor CalculateImageColor(gfx::ImageSkia* image) {
20 // We grab the color of the middle pixel of the image, which we treat as 21 // We grab the color of the middle pixel of the image, which we treat as
21 // the representative color of the entire image (reasonable, given the current 22 // the representative color of the entire image (reasonable, given the current
22 // appearance of these assets). 23 // appearance of these assets).
23 const SkBitmap& bitmap(image->GetRepresentation(1.0f).sk_bitmap()); 24 const SkBitmap& bitmap(image->GetRepresentation(1.0f).sk_bitmap());
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 height()); 116 height());
116 } 117 }
117 118
118 void IconLabelBubbleView::OnNativeThemeChanged( 119 void IconLabelBubbleView::OnNativeThemeChanged(
119 const ui::NativeTheme* native_theme) { 120 const ui::NativeTheme* native_theme) {
120 if (!ui::MaterialDesignController::IsModeMaterial()) 121 if (!ui::MaterialDesignController::IsModeMaterial())
121 return; 122 return;
122 123
123 label_->SetEnabledColor(GetTextColor()); 124 label_->SetEnabledColor(GetTextColor());
124 125
125 bool inverted = 126 bool inverted = IsInvertedColorScheme();
126 color_utils::GetLuminanceForColor(parent_background_color_) < 128;
127 SkColor border_color = inverted ? SK_ColorWHITE : GetBorderColor(); 127 SkColor border_color = inverted ? SK_ColorWHITE : GetBorderColor();
128 SkColor background_color = 128 SkColor background_color =
129 inverted ? SK_ColorWHITE : SkColorSetA(border_color, 0x13); 129 inverted ? SK_ColorWHITE : SkColorSetA(border_color, 0x13);
130 set_background( 130 set_background(
131 new BackgroundWith1PxBorder(background_color, border_color, false)); 131 new BackgroundWith1PxBorder(background_color, border_color, false));
132 SetLabelBackgroundColor(background_color); 132 SetLabelBackgroundColor(background_color);
133 } 133 }
134 134
135 bool IconLabelBubbleView::IsInvertedColorScheme() const {
136 return color_utils::IsDark(GetNativeTheme()->GetSystemColor(
137 ui::NativeTheme::kColorId_TextfieldDefaultBackground));
Peter Kasting 2015/11/17 21:27:03 The code to get this background color is repeated
Evan Stade 2015/11/17 22:57:21 Done.
138 }
139
135 gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int width) const { 140 gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int width) const {
136 gfx::Size size(image_->GetPreferredSize()); 141 gfx::Size size(image_->GetPreferredSize());
137 if (ShouldShowBackground()) { 142 if (ShouldShowBackground()) {
138 const int non_label_width = GetBubbleOuterPadding(true) + 143 const int non_label_width = GetBubbleOuterPadding(true) +
139 GetImageAndPaddingWidth() + 144 GetImageAndPaddingWidth() +
140 GetBubbleOuterPadding(false); 145 GetBubbleOuterPadding(false);
141 size = gfx::Size(WidthMultiplier() * (width + non_label_width), 0); 146 size = gfx::Size(WidthMultiplier() * (width + non_label_width), 0);
142 if (!ui::MaterialDesignController::IsModeMaterial()) 147 if (!ui::MaterialDesignController::IsModeMaterial())
143 size.SetToMax(background_painter_->GetMinimumSize()); 148 size.SetToMax(background_painter_->GetMinimumSize());
144 } 149 }
(...skipping 13 matching lines...) Expand all
158 int IconLabelBubbleView::GetBubbleOuterPaddingMd(bool leading) const { 163 int IconLabelBubbleView::GetBubbleOuterPaddingMd(bool leading) const {
159 // When the image is empty, leading and trailing padding are equal. 164 // When the image is empty, leading and trailing padding are equal.
160 if (image_->GetPreferredSize().IsEmpty() || !leading) 165 if (image_->GetPreferredSize().IsEmpty() || !leading)
161 return GetLayoutConstant(ICON_LABEL_VIEW_TRAILING_PADDING); 166 return GetLayoutConstant(ICON_LABEL_VIEW_TRAILING_PADDING);
162 167
163 // Leading padding is 2dp. 168 // Leading padding is 2dp.
164 return 2; 169 return 2;
165 } 170 }
166 171
167 void IconLabelBubbleView::SetLabelBackgroundColor( 172 void IconLabelBubbleView::SetLabelBackgroundColor(
168 SkColor background_image_color) { 173 SkColor chip_background_color) {
174 SkColor parent_background_color =
175 ui::MaterialDesignController::IsModeMaterial()
176 ? GetNativeTheme()->GetSystemColor(
177 ui::NativeTheme::kColorId_TextfieldDefaultBackground)
178 : parent_background_color_;
169 // The background images are painted atop |parent_background_color_|. 179 // The background images are painted atop |parent_background_color_|.
170 // Alpha-blend |background_image_color| with |parent_background_color_| to 180 // Alpha-blend |chip_background_color| with |parent_background_color_| to
171 // determine the actual color the label text will sit atop. 181 // determine the actual color the label text will sit atop.
172 // Tricky bit: We alpha blend an opaque version of |background_image_color| 182 // Tricky bit: We alpha blend an opaque version of |chip_background_color|
173 // against |parent_background_color_| using the original image grid color's 183 // against |parent_background_color_| using the original image grid color's
174 // alpha. This is because AlphaBlend(a, b, 255) always returns |a| unchanged 184 // alpha. This is because AlphaBlend(a, b, 255) always returns |a| unchanged
175 // even if |a| is a color with non-255 alpha. 185 // even if |a| is a color with non-255 alpha.
176 label_->SetBackgroundColor(color_utils::AlphaBlend( 186 label_->SetBackgroundColor(color_utils::AlphaBlend(
177 SkColorSetA(background_image_color, 255), parent_background_color_, 187 SkColorSetA(chip_background_color, 255), parent_background_color,
178 SkColorGetA(background_image_color))); 188 SkColorGetA(chip_background_color)));
179 } 189 }
180 190
181 const char* IconLabelBubbleView::GetClassName() const { 191 const char* IconLabelBubbleView::GetClassName() const {
182 return "IconLabelBubbleView"; 192 return "IconLabelBubbleView";
183 } 193 }
184 194
185 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { 195 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) {
186 if (!ShouldShowBackground()) 196 if (!ShouldShowBackground())
187 return; 197 return;
188 if (background_painter_) 198 if (background_painter_)
189 background_painter_->Paint(canvas, size()); 199 background_painter_->Paint(canvas, size());
190 if (background()) 200 if (background())
191 background()->Paint(canvas, this); 201 background()->Paint(canvas, this);
192 } 202 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698