Commit 8fc421ed authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Simplify SelectedKeywordView API.

This implements suggestions from
https://chromium-review.googlesource.com/c/chromium/src/+/1983539 .

Bug: none
Change-Id: Id621d2bfa806c48d7efaa74b34f17a959dec898e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1989703
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#729993}
parent bed6132d
...@@ -231,11 +231,10 @@ void ContentSettingImageView::OnWidgetDestroying(views::Widget* widget) { ...@@ -231,11 +231,10 @@ void ContentSettingImageView::OnWidgetDestroying(views::Widget* widget) {
} }
void ContentSettingImageView::UpdateImage() { void ContentSettingImageView::UpdateImage() {
SetImage(content_setting_image_model_ gfx::Image icon = content_setting_image_model_->GetIcon(icon_color_.value_or(
->GetIcon(icon_color_ ? icon_color_.value() color_utils::DeriveDefaultIconColor(GetForegroundColor())));
: color_utils::DeriveDefaultIconColor( if (!icon.IsEmpty())
GetForegroundColor())) SetImage(icon.AsImageSkia());
.AsImageSkia());
} }
void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) { void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) {
......
...@@ -395,6 +395,7 @@ void IconLabelBubbleView::OnTouchUiChanged() { ...@@ -395,6 +395,7 @@ void IconLabelBubbleView::OnTouchUiChanged() {
} }
void IconLabelBubbleView::SetImage(const gfx::ImageSkia& image_skia) { void IconLabelBubbleView::SetImage(const gfx::ImageSkia& image_skia) {
DCHECK(!image_skia.isNull());
LabelButton::SetImage(STATE_NORMAL, image_skia); LabelButton::SetImage(STATE_NORMAL, image_skia);
} }
......
...@@ -428,7 +428,8 @@ gfx::Size LocationBarView::CalculatePreferredSize() const { ...@@ -428,7 +428,8 @@ gfx::Size LocationBarView::CalculatePreferredSize() const {
} }
void LocationBarView::OnKeywordFaviconFetched(const gfx::Image& icon) { void LocationBarView::OnKeywordFaviconFetched(const gfx::Image& icon) {
selected_keyword_view_->SetCustomImage(icon.AsImageSkia()); DCHECK(!icon.IsEmpty());
selected_keyword_view_->SetCustomImage(icon);
} }
void LocationBarView::Layout() { void LocationBarView::Layout() {
...@@ -501,15 +502,14 @@ void LocationBarView::Layout() { ...@@ -501,15 +502,14 @@ void LocationBarView::Layout() {
const TemplateURL* template_url = const TemplateURL* template_url =
TemplateURLServiceFactory::GetForProfile(profile_) TemplateURLServiceFactory::GetForProfile(profile_)
->GetTemplateURLForKeyword(keyword); ->GetTemplateURLForKeyword(keyword);
gfx::Image image;
if (template_url && if (template_url &&
(template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION)) { (template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION)) {
gfx::Image image = image = extensions::OmniboxAPI::Get(profile_)->GetOmniboxIcon(
extensions::OmniboxAPI::Get(profile_)->GetOmniboxIcon(
template_url->GetExtensionId()); template_url->GetExtensionId());
selected_keyword_view_->SetCustomImage(image.AsImageSkia());
} else if (template_url && template_url->type() == TemplateURL::NORMAL && } else if (template_url && template_url->type() == TemplateURL::NORMAL &&
OmniboxFieldTrial::IsExperimentalKeywordModeEnabled()) { OmniboxFieldTrial::IsExperimentalKeywordModeEnabled()) {
gfx::Image image = image =
omnibox_view() omnibox_view()
->model() ->model()
->client() ->client()
...@@ -517,13 +517,8 @@ void LocationBarView::Layout() { ...@@ -517,13 +517,8 @@ void LocationBarView::Layout() {
template_url, template_url,
base::BindOnce(&LocationBarView::OnKeywordFaviconFetched, base::BindOnce(&LocationBarView::OnKeywordFaviconFetched,
base::Unretained(this))); base::Unretained(this)));
if (!image.IsEmpty())
selected_keyword_view_->SetCustomImage(image.AsImageSkia());
else
selected_keyword_view_->ResetImage();
} else {
selected_keyword_view_->ResetImage();
} }
selected_keyword_view_->SetCustomImage(image);
} }
} else if (location_icon_view_->ShouldShowText()) { } else if (location_icon_view_->ShouldShowText()) {
leading_decorations.AddDecoration(vertical_padding, location_height, false, leading_decorations.AddDecoration(vertical_padding, location_height, false,
......
...@@ -202,11 +202,12 @@ void LocationIconView::UpdateIcon() { ...@@ -202,11 +202,12 @@ void LocationIconView::UpdateIcon() {
gfx::ImageSkia icon = delegate_->GetLocationIcon( gfx::ImageSkia icon = delegate_->GetLocationIcon(
base::BindOnce(&LocationIconView::OnIconFetched, base::BindOnce(&LocationIconView::OnIconFetched,
icon_fetch_weak_ptr_factory_.GetWeakPtr())); icon_fetch_weak_ptr_factory_.GetWeakPtr()));
if (!icon.isNull())
SetImage(icon); SetImage(icon);
} }
void LocationIconView::OnIconFetched(const gfx::Image& image) { void LocationIconView::OnIconFetched(const gfx::Image& image) {
DCHECK(!image.IsEmpty());
SetImage(image.AsImageSkia()); SetImage(image.AsImageSkia());
} }
......
...@@ -34,16 +34,15 @@ SelectedKeywordView::SelectedKeywordView(LocationBarView* location_bar, ...@@ -34,16 +34,15 @@ SelectedKeywordView::SelectedKeywordView(LocationBarView* location_bar,
SelectedKeywordView::~SelectedKeywordView() {} SelectedKeywordView::~SelectedKeywordView() {}
void SelectedKeywordView::SetCustomImage(const gfx::ImageSkia& image) { void SelectedKeywordView::SetCustomImage(const gfx::Image& image) {
IconLabelBubbleView::SetImage(image); using_custom_image_ = !image.IsEmpty();
using_custom_image_ = true; if (using_custom_image_) {
} IconLabelBubbleView::SetImage(image.AsImageSkia());
} else {
void SelectedKeywordView::ResetImage() {
IconLabelBubbleView::SetImage(gfx::CreateVectorIcon( IconLabelBubbleView::SetImage(gfx::CreateVectorIcon(
vector_icons::kSearchIcon, GetLayoutConstant(LOCATION_BAR_ICON_SIZE), vector_icons::kSearchIcon, GetLayoutConstant(LOCATION_BAR_ICON_SIZE),
GetForegroundColor())); GetForegroundColor()));
using_custom_image_ = false; }
} }
void SelectedKeywordView::OnBoundsChanged(const gfx::Rect& previous_bounds) { void SelectedKeywordView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
...@@ -67,7 +66,7 @@ gfx::Size SelectedKeywordView::GetMinimumSize() const { ...@@ -67,7 +66,7 @@ gfx::Size SelectedKeywordView::GetMinimumSize() const {
void SelectedKeywordView::OnThemeChanged() { void SelectedKeywordView::OnThemeChanged() {
IconLabelBubbleView::OnThemeChanged(); IconLabelBubbleView::OnThemeChanged();
if (!using_custom_image_) if (!using_custom_image_)
ResetImage(); SetCustomImage(gfx::Image());
} }
void SelectedKeywordView::SetKeyword(const base::string16& keyword) { void SelectedKeywordView::SetKeyword(const base::string16& keyword) {
......
...@@ -29,11 +29,9 @@ class SelectedKeywordView : public IconLabelBubbleView { ...@@ -29,11 +29,9 @@ class SelectedKeywordView : public IconLabelBubbleView {
Profile* profile); Profile* profile);
~SelectedKeywordView() override; ~SelectedKeywordView() override;
// Sets the icon for this chip to |image|. // Sets the icon for this chip to |image|. If there is no custom image (i.e.
void SetCustomImage(const gfx::ImageSkia& image); // |image| is empty), resets the icon for this chip to its default.
void SetCustomImage(const gfx::Image& image);
// Resets the icon for this chip to its default.
void ResetImage();
// IconLabelBubbleView: // IconLabelBubbleView:
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
......
...@@ -219,8 +219,10 @@ void PageActionIconView::UpdateIconImage() { ...@@ -219,8 +219,10 @@ void PageActionIconView::UpdateIconImage() {
? theme->GetSystemColor( ? theme->GetSystemColor(
ui::NativeTheme::kColorId_ProminentButtonColor) ui::NativeTheme::kColorId_ProminentButtonColor)
: icon_color_; : icon_color_;
SetImage(gfx::CreateVectorIconWithBadge(GetVectorIcon(), icon_size_, gfx::ImageSkia image = gfx::CreateVectorIconWithBadge(
icon_color, GetVectorIconBadge())); GetVectorIcon(), icon_size_, icon_color, GetVectorIconBadge());
if (!image.isNull())
SetImage(image);
} }
void PageActionIconView::InstallLoadingIndicator() { void PageActionIconView::InstallLoadingIndicator() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment