Commit 90d00474 authored by Owen Min's avatar Owen Min Committed by Commit Bot

Revert "Add new class ColorTrackingIconView to deduplicate subclasses."

This reverts commit 85ae69b0.

Reason for revert: crbug.com/1126038

Compile error on Linux Chrome:
https://ci.chromium.org/p/chrome/builders/ci/linux-chrome/15196

Original change's description:
> Add new class ColorTrackingIconView to deduplicate subclasses.
>
> Upon investigating the associated bug, I noticed that there are a few
> subclasses of ImageView that exist solely to override OnThemeChanged.
> Since I also needed a subclass like this to fix the bug, I decided to
> make a utility class to eliminate this ad-hoc subclassing, in the style
> of ColorTrackingVectorImageButton (in image_button_factory.cc).
>
> Bug: 1125510
> Change-Id: I975a9b6a4676bb6b2a454172f211f406934d7869
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2397737
> Commit-Queue: Bret Sepulveda <bsep@chromium.org>
> Reviewed-by: Trent Apted <tapted@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#804901}

TBR=tapted@chromium.org,bsep@chromium.org

Change-Id: I958b5f7c04434b680f58fb0d0e0e46a8529a6abb
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1125510, 1126038
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2398778Reviewed-by: default avatarOwen Min <zmin@chromium.org>
Commit-Queue: Owen Min <zmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804910}
parent 3157d77b
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/views/animation/ink_drop_impl.h" #include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/controls/color_tracking_icon_view.h"
#include "ui/views/controls/styled_label.h" #include "ui/views/controls/styled_label.h"
#include "ui/views/controls/throbber.h" #include "ui/views/controls/throbber.h"
#include "ui/views/layout/fill_layout.h" #include "ui/views/layout/fill_layout.h"
...@@ -37,6 +36,25 @@ namespace media_router { ...@@ -37,6 +36,25 @@ namespace media_router {
namespace { namespace {
// A view that represents the primary icon for a sink issue. This class is used
// to ensure its color is kept in sync with current theme.
class SinkIssueIconView : public views::ImageView {
public:
SinkIssueIconView() {
SetBorder(views::CreateEmptyBorder(kPrimaryIconBorder));
}
~SinkIssueIconView() override = default;
// views::ImageView:
void OnThemeChanged() override {
views::ImageView::OnThemeChanged();
const SkColor icon_color = GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_DefaultIconColor);
SetImage(gfx::CreateVectorIcon(::vector_icons::kInfoOutlineIcon,
kPrimaryIconSize, icon_color));
}
};
gfx::ImageSkia CreateSinkIcon(SinkIconType icon_type, bool enabled = true) { gfx::ImageSkia CreateSinkIcon(SinkIconType icon_type, bool enabled = true) {
const gfx::VectorIcon* vector_icon; const gfx::VectorIcon* vector_icon;
switch (icon_type) { switch (icon_type) {
...@@ -94,10 +112,7 @@ std::unique_ptr<views::View> CreatePrimaryIconForSink( ...@@ -94,10 +112,7 @@ std::unique_ptr<views::View> CreatePrimaryIconForSink(
return CreatePrimaryIconView(gfx::CreateVectorIcon( return CreatePrimaryIconView(gfx::CreateVectorIcon(
kGenericStopIcon, kPrimaryIconSize, gfx::kGoogleBlue500)); kGenericStopIcon, kPrimaryIconSize, gfx::kGoogleBlue500));
} else if (sink.issue) { } else if (sink.issue) {
auto icon = std::make_unique<views::ColorTrackingIconView>( return std::make_unique<SinkIssueIconView>();
vector_icons::kInfoOutlineIcon, kPrimaryIconSize);
icon->SetBorder(views::CreateEmptyBorder(kPrimaryIconBorder));
return icon;
} else if (sink.state == UIMediaSinkState::CONNECTING || } else if (sink.state == UIMediaSinkState::CONNECTING ||
sink.state == UIMediaSinkState::DISCONNECTING) { sink.state == UIMediaSinkState::DISCONNECTING) {
return CreateThrobber(); return CreateThrobber();
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/image_button_factory.h" #include "ui/views/controls/button/image_button_factory.h"
#include "ui/views/controls/button/md_text_button.h" #include "ui/views/controls/button/md_text_button.h"
#include "ui/views/controls/color_tracking_icon_view.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/controls/link.h" #include "ui/views/controls/link.h"
...@@ -62,6 +61,23 @@ enum PasswordItemsViewColumnSetType { ...@@ -62,6 +61,23 @@ enum PasswordItemsViewColumnSetType {
UNDO_COLUMN_SET UNDO_COLUMN_SET
}; };
// And ImageView that holds a kGlobeIcon of gfx::kFaviconSize and adapts to
// changes in theme color. Used as a fallback option when the page has no
// favicon.
class GlobeIconImageView : public views::ImageView {
public:
GlobeIconImageView() = default;
~GlobeIconImageView() override = default;
// views::View:
void OnThemeChanged() override {
views::ImageView::OnThemeChanged();
const SkColor icon_color = GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_DefaultIconColor);
SetImage(gfx::CreateVectorIcon(kGlobeIcon, gfx::kFaviconSize, icon_color));
}
};
PasswordItemsViewColumnSetType InferColumnSetTypeFromCredentials( PasswordItemsViewColumnSetType InferColumnSetTypeFromCredentials(
const std::vector<autofill::PasswordForm>& credentials) { const std::vector<autofill::PasswordForm>& credentials) {
if (std::any_of(credentials.begin(), credentials.end(), if (std::any_of(credentials.begin(), credentials.end(),
...@@ -294,8 +310,7 @@ void PasswordItemsView::PasswordRow::AddPasswordRow( ...@@ -294,8 +310,7 @@ void PasswordItemsView::PasswordRow::AddPasswordRow(
// Use a globe fallback until the actual favicon is loaded. // Use a globe fallback until the actual favicon is loaded.
if (parent_->favicon_.IsEmpty()) { if (parent_->favicon_.IsEmpty()) {
layout->AddView(std::make_unique<views::ColorTrackingIconView>( layout->AddView(std::make_unique<GlobeIconImageView>());
kGlobeIcon, gfx::kFaviconSize));
} else { } else {
auto favicon_view = std::make_unique<views::ImageView>(); auto favicon_view = std::make_unique<views::ImageView>();
favicon_view->SetImage(parent_->favicon_.AsImageSkia()); favicon_view->SetImage(parent_->favicon_.AsImageSkia());
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/app/vector_icons/vector_icons.h" #include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/ui/views/hover_button.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/send_tab_to_self/target_device_info.h" #include "components/send_tab_to_self/target_device_info.h"
#include "components/sync/protocol/sync.pb.h" #include "components/sync/protocol/sync.pb.h"
...@@ -18,24 +17,37 @@ ...@@ -18,24 +17,37 @@
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/native_theme/native_theme.h" #include "ui/native_theme/native_theme.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/color_tracking_icon_view.h"
namespace send_tab_to_self { namespace send_tab_to_self {
namespace { namespace {
std::unique_ptr<views::ColorTrackingIconView> CreateIcon( // IconView wraps the vector icon to track the color of the current Widget's
const sync_pb::SyncEnums::DeviceType device_type) { // NativeTheme.
class IconView : public views::ImageView {
public:
explicit IconView(const sync_pb::SyncEnums::DeviceType device_type)
: vector_icon_{device_type == sync_pb::SyncEnums::TYPE_PHONE
? &kHardwareSmartphoneIcon
: &kHardwareComputerIcon} {
constexpr auto kPrimaryIconBorder = gfx::Insets(6);
SetBorder(views::CreateEmptyBorder(kPrimaryIconBorder));
}
~IconView() override = default;
// views::View:
void OnThemeChanged() override {
views::ImageView::OnThemeChanged();
const SkColor icon_color = GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_DefaultIconColor);
SetImage(
gfx::CreateVectorIcon(*vector_icon_, kPrimaryIconSize, icon_color));
}
private:
static constexpr int kPrimaryIconSize = 20; static constexpr int kPrimaryIconSize = 20;
auto icon = std::make_unique<views::ColorTrackingIconView>( const gfx::VectorIcon* vector_icon_;
device_type == sync_pb::SyncEnums::TYPE_PHONE ? kHardwareSmartphoneIcon };
: kHardwareComputerIcon,
kPrimaryIconSize);
constexpr auto kPrimaryIconBorder = gfx::Insets(6);
icon->SetBorder(views::CreateEmptyBorder(kPrimaryIconBorder));
return icon;
}
base::string16 GetLastUpdatedTime(const TargetDeviceInfo& device_info) { base::string16 GetLastUpdatedTime(const TargetDeviceInfo& device_info) {
int time_in_days = int time_in_days =
...@@ -60,7 +72,7 @@ SendTabToSelfBubbleDeviceButton::SendTabToSelfBubbleDeviceButton( ...@@ -60,7 +72,7 @@ SendTabToSelfBubbleDeviceButton::SendTabToSelfBubbleDeviceButton(
const TargetDeviceInfo& device_info, const TargetDeviceInfo& device_info,
int button_tag) int button_tag)
: HoverButton(button_listener, : HoverButton(button_listener,
CreateIcon(device_info.device_type), std::make_unique<IconView>(device_info.device_type),
base::UTF8ToUTF16(device_info.device_name), base::UTF8ToUTF16(device_info.device_name),
GetLastUpdatedTime(device_info)) { GetLastUpdatedTime(device_info)) {
device_name_ = device_info.device_name; device_name_ = device_info.device_name;
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "ui/strings/grit/ui_strings.h" #include "ui/strings/grit/ui_strings.h"
#include "ui/views/border.h" #include "ui/views/border.h"
#include "ui/views/bubble/bubble_frame_view.h" #include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/controls/color_tracking_icon_view.h"
#include "ui/views/controls/scroll_view.h" #include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/styled_label.h" #include "ui/views/controls/styled_label.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
...@@ -40,6 +39,23 @@ ...@@ -40,6 +39,23 @@
namespace { namespace {
class VectorIconView : public views::ImageView {
public:
explicit VectorIconView(const gfx::VectorIcon& icon) : icon_(icon) {}
// views::ImageView
void OnThemeChanged() override {
ImageView::OnThemeChanged();
constexpr int kPrimaryIconSize = 20;
const SkColor color = GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_DefaultIconColor);
SetImage(gfx::CreateVectorIcon(icon_, kPrimaryIconSize, color));
}
private:
const gfx::VectorIcon& icon_;
};
class HeaderImageView : public NonAccessibleImageView { class HeaderImageView : public NonAccessibleImageView {
public: public:
explicit HeaderImageView(const views::BubbleFrameView* frame_view, explicit HeaderImageView(const views::BubbleFrameView* frame_view,
...@@ -267,7 +283,6 @@ void SharingDialogView::Init() { ...@@ -267,7 +283,6 @@ void SharingDialogView::Init() {
} }
void SharingDialogView::InitListView() { void SharingDialogView::InitListView() {
constexpr int kPrimaryIconSize = 20;
int tag = 0; int tag = 0;
const gfx::Insets device_border = const gfx::Insets device_border =
gfx::Insets(kSharingDialogSpacing, kSharingDialogSpacing * 2, gfx::Insets(kSharingDialogSpacing, kSharingDialogSpacing * 2,
...@@ -282,11 +297,10 @@ void SharingDialogView::InitListView() { ...@@ -282,11 +297,10 @@ void SharingDialogView::InitListView() {
// Devices: // Devices:
LogSharingDevicesToShow(data_.prefix, kSharingUiDialog, data_.devices.size()); LogSharingDevicesToShow(data_.prefix, kSharingUiDialog, data_.devices.size());
for (const auto& device : data_.devices) { for (const auto& device : data_.devices) {
auto icon = std::make_unique<views::ColorTrackingIconView>( auto icon = std::make_unique<VectorIconView>(
device->device_type() == sync_pb::SyncEnums::TYPE_TABLET device->device_type() == sync_pb::SyncEnums::TYPE_TABLET
? kTabletIcon ? kTabletIcon
: kHardwareSmartphoneIcon, : kHardwareSmartphoneIcon);
kPrimaryIconSize);
auto dialog_button = std::make_unique<HoverButton>( auto dialog_button = std::make_unique<HoverButton>(
this, std::move(icon), base::UTF8ToUTF16(device->client_name()), this, std::move(icon), base::UTF8ToUTF16(device->client_name()),
...@@ -303,8 +317,7 @@ void SharingDialogView::InitListView() { ...@@ -303,8 +317,7 @@ void SharingDialogView::InitListView() {
for (const auto& app : data_.apps) { for (const auto& app : data_.apps) {
std::unique_ptr<views::ImageView> icon; std::unique_ptr<views::ImageView> icon;
if (app.vector_icon) { if (app.vector_icon) {
icon = std::make_unique<views::ColorTrackingIconView>(*app.vector_icon, icon = std::make_unique<VectorIconView>(*app.vector_icon);
kPrimaryIconSize);
} else { } else {
icon = std::make_unique<views::ImageView>(); icon = std::make_unique<views::ImageView>();
icon->SetImage(app.image.AsImageSkia()); icon->SetImage(app.image.AsImageSkia());
......
...@@ -120,7 +120,6 @@ component("views") { ...@@ -120,7 +120,6 @@ component("views") {
"controls/button/menu_button_controller.h", "controls/button/menu_button_controller.h",
"controls/button/radio_button.h", "controls/button/radio_button.h",
"controls/button/toggle_button.h", "controls/button/toggle_button.h",
"controls/color_tracking_icon_view.h",
"controls/combobox/combobox.h", "controls/combobox/combobox.h",
"controls/combobox/combobox_listener.h", "controls/combobox/combobox_listener.h",
"controls/combobox/combobox_util.h", "controls/combobox/combobox_util.h",
...@@ -333,7 +332,6 @@ component("views") { ...@@ -333,7 +332,6 @@ component("views") {
"controls/button/menu_button_controller.cc", "controls/button/menu_button_controller.cc",
"controls/button/radio_button.cc", "controls/button/radio_button.cc",
"controls/button/toggle_button.cc", "controls/button/toggle_button.cc",
"controls/color_tracking_icon_view.cc",
"controls/combobox/combobox.cc", "controls/combobox/combobox.cc",
"controls/combobox/combobox_util.cc", "controls/combobox/combobox_util.cc",
"controls/combobox/empty_combobox_model.cc", "controls/combobox/empty_combobox_model.cc",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/views/controls/color_tracking_icon_view.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/native_theme/native_theme.h"
namespace views {
ColorTrackingIconView::ColorTrackingIconView(const gfx::VectorIcon& icon,
int icon_size)
: icon_(icon), icon_size_(icon_size) {}
void ColorTrackingIconView::OnThemeChanged() {
ImageView::OnThemeChanged();
const SkColor color = GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_DefaultIconColor);
SetImage(gfx::CreateVectorIcon(icon_, icon_size_, color));
}
} // namespace views
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_VIEWS_CONTROLS_COLOR_TRACKING_ICON_VIEW_H_
#define UI_VIEWS_CONTROLS_COLOR_TRACKING_ICON_VIEW_H_
#include "ui/views/controls/image_view.h"
namespace gfx {
struct VectorIcon;
}
namespace views {
// An ImageView that displays |icon| at |icon_size|. Tracks theme changes so the
// icon is always the correct color.
class VIEWS_EXPORT ColorTrackingIconView : public ImageView {
public:
ColorTrackingIconView(const gfx::VectorIcon& icon, int icon_size);
// ImageView:
void OnThemeChanged() override;
private:
const gfx::VectorIcon& icon_;
const int icon_size_;
};
} // namespace views
#endif // UI_VIEWS_CONTROLS_COLOR_TRACKING_ICON_VIEW_H_
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