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) {
}
void ContentSettingImageView::UpdateImage() {
SetImage(content_setting_image_model_
->GetIcon(icon_color_ ? icon_color_.value()
: color_utils::DeriveDefaultIconColor(
GetForegroundColor()))
.AsImageSkia());
gfx::Image icon = content_setting_image_model_->GetIcon(icon_color_.value_or(
color_utils::DeriveDefaultIconColor(GetForegroundColor())));
if (!icon.IsEmpty())
SetImage(icon.AsImageSkia());
}
void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) {
......
......@@ -395,6 +395,7 @@ void IconLabelBubbleView::OnTouchUiChanged() {
}
void IconLabelBubbleView::SetImage(const gfx::ImageSkia& image_skia) {
DCHECK(!image_skia.isNull());
LabelButton::SetImage(STATE_NORMAL, image_skia);
}
......
......@@ -428,7 +428,8 @@ gfx::Size LocationBarView::CalculatePreferredSize() const {
}
void LocationBarView::OnKeywordFaviconFetched(const gfx::Image& icon) {
selected_keyword_view_->SetCustomImage(icon.AsImageSkia());
DCHECK(!icon.IsEmpty());
selected_keyword_view_->SetCustomImage(icon);
}
void LocationBarView::Layout() {
......@@ -501,15 +502,14 @@ void LocationBarView::Layout() {
const TemplateURL* template_url =
TemplateURLServiceFactory::GetForProfile(profile_)
->GetTemplateURLForKeyword(keyword);
gfx::Image image;
if (template_url &&
(template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION)) {
gfx::Image image =
extensions::OmniboxAPI::Get(profile_)->GetOmniboxIcon(
template_url->GetExtensionId());
selected_keyword_view_->SetCustomImage(image.AsImageSkia());
image = extensions::OmniboxAPI::Get(profile_)->GetOmniboxIcon(
template_url->GetExtensionId());
} else if (template_url && template_url->type() == TemplateURL::NORMAL &&
OmniboxFieldTrial::IsExperimentalKeywordModeEnabled()) {
gfx::Image image =
image =
omnibox_view()
->model()
->client()
......@@ -517,13 +517,8 @@ void LocationBarView::Layout() {
template_url,
base::BindOnce(&LocationBarView::OnKeywordFaviconFetched,
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()) {
leading_decorations.AddDecoration(vertical_padding, location_height, false,
......
......@@ -202,11 +202,12 @@ void LocationIconView::UpdateIcon() {
gfx::ImageSkia icon = delegate_->GetLocationIcon(
base::BindOnce(&LocationIconView::OnIconFetched,
icon_fetch_weak_ptr_factory_.GetWeakPtr()));
SetImage(icon);
if (!icon.isNull())
SetImage(icon);
}
void LocationIconView::OnIconFetched(const gfx::Image& image) {
DCHECK(!image.IsEmpty());
SetImage(image.AsImageSkia());
}
......
......@@ -34,16 +34,15 @@ SelectedKeywordView::SelectedKeywordView(LocationBarView* location_bar,
SelectedKeywordView::~SelectedKeywordView() {}
void SelectedKeywordView::SetCustomImage(const gfx::ImageSkia& image) {
IconLabelBubbleView::SetImage(image);
using_custom_image_ = true;
}
void SelectedKeywordView::ResetImage() {
IconLabelBubbleView::SetImage(gfx::CreateVectorIcon(
vector_icons::kSearchIcon, GetLayoutConstant(LOCATION_BAR_ICON_SIZE),
GetForegroundColor()));
using_custom_image_ = false;
void SelectedKeywordView::SetCustomImage(const gfx::Image& image) {
using_custom_image_ = !image.IsEmpty();
if (using_custom_image_) {
IconLabelBubbleView::SetImage(image.AsImageSkia());
} else {
IconLabelBubbleView::SetImage(gfx::CreateVectorIcon(
vector_icons::kSearchIcon, GetLayoutConstant(LOCATION_BAR_ICON_SIZE),
GetForegroundColor()));
}
}
void SelectedKeywordView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
......@@ -67,7 +66,7 @@ gfx::Size SelectedKeywordView::GetMinimumSize() const {
void SelectedKeywordView::OnThemeChanged() {
IconLabelBubbleView::OnThemeChanged();
if (!using_custom_image_)
ResetImage();
SetCustomImage(gfx::Image());
}
void SelectedKeywordView::SetKeyword(const base::string16& keyword) {
......
......@@ -29,11 +29,9 @@ class SelectedKeywordView : public IconLabelBubbleView {
Profile* profile);
~SelectedKeywordView() override;
// Sets the icon for this chip to |image|.
void SetCustomImage(const gfx::ImageSkia& image);
// Resets the icon for this chip to its default.
void ResetImage();
// Sets the icon for this chip to |image|. If there is no custom image (i.e.
// |image| is empty), resets the icon for this chip to its default.
void SetCustomImage(const gfx::Image& image);
// IconLabelBubbleView:
gfx::Size CalculatePreferredSize() const override;
......
......@@ -219,8 +219,10 @@ void PageActionIconView::UpdateIconImage() {
? theme->GetSystemColor(
ui::NativeTheme::kColorId_ProminentButtonColor)
: icon_color_;
SetImage(gfx::CreateVectorIconWithBadge(GetVectorIcon(), icon_size_,
icon_color, GetVectorIconBadge()));
gfx::ImageSkia image = gfx::CreateVectorIconWithBadge(
GetVectorIcon(), icon_size_, icon_color, GetVectorIconBadge());
if (!image.isNull())
SetImage(image);
}
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