Migrate views::Background class to ui::ColorVariant
This migration allows us to merge theme aware and SkColor based background implementations. This CL also renames `SetNativeControlColor()` to `SetColor()` and `get_color()` to `color()`. This CL also bans setting color for a Painter based background. Bug: b:400775304 Change-Id: Ied07375c9f5629f04c9f1f1b7505f05f35aacb37 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6331510 Reviewed-by: Avi Drissman <avi@chromium.org> Reviewed-by: Xiyuan Xia <xiyuan@chromium.org> Reviewed-by: Elly FJ <ellyjones@chromium.org> Commit-Queue: Zoraiz Naeem <zoraiznaeem@chromium.org> Cr-Commit-Position: refs/heads/main@{#1431684}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
2546414068
commit
2e8003b739
ash
app_list
assistant
ui
capture_mode
hud_display
login
quick_insert
search_box
shelf
style
system
holding_space
time
wm
chrome/browser
enterprise
connectors
analysis
picture_in_picture
ui
ash
quick_answers
views
autofill
location_bar
omnibox
omnibox_popup_view_views_interactive_uitest.ccomnibox_popup_view_webui_interactive_uitest.ccomnibox_result_view.cc
page_action
payments
permissions
chromeos/ash/experiences/arc
ui/views
@ -196,10 +196,13 @@ class PromiseIconBackground : public views::Background {
|
||||
PromiseIconBackground(ui::ColorId color_id,
|
||||
const gfx::Rect& icon_bounds,
|
||||
const gfx::Insets& insets)
|
||||
: color_id_(color_id), icon_bounds_(icon_bounds), insets_(insets) {}
|
||||
: icon_bounds_(icon_bounds), insets_(insets) {
|
||||
SetColor(color_id);
|
||||
}
|
||||
|
||||
PromiseIconBackground(const PromiseIconBackground&) = delete;
|
||||
PromiseIconBackground& operator=(const PromiseIconBackground&) = delete;
|
||||
|
||||
~PromiseIconBackground() override = default;
|
||||
|
||||
// views::Background:
|
||||
@ -212,18 +215,16 @@ class PromiseIconBackground : public views::Background {
|
||||
|
||||
cc::PaintFlags flags;
|
||||
flags.setAntiAlias(true);
|
||||
flags.setColor(get_color());
|
||||
flags.setColor(color().ConvertToSkColor(view->GetColorProvider()));
|
||||
|
||||
canvas->DrawCircle(bounds.CenterPoint(), radius, flags);
|
||||
}
|
||||
|
||||
void OnViewThemeChanged(views::View* view) override {
|
||||
SetNativeControlColor(view->GetColorProvider()->GetColor(color_id_));
|
||||
view->SchedulePaint();
|
||||
}
|
||||
|
||||
private:
|
||||
const ui::ColorId color_id_;
|
||||
const gfx::Rect icon_bounds_;
|
||||
const gfx::Insets insets_;
|
||||
};
|
||||
|
@ -246,7 +246,7 @@ class FolderHeaderView::FolderNameView : public views::Textfield,
|
||||
|
||||
private:
|
||||
void UpdateBackgroundColor(bool is_active) {
|
||||
background()->SetNativeControlColor(GetFolderBackgroundColor(is_active));
|
||||
background()->SetColor(GetFolderBackgroundColor(is_active));
|
||||
SchedulePaint();
|
||||
}
|
||||
|
||||
|
@ -156,11 +156,8 @@ void AssistantOnboardingSuggestionView::RemoveLayerFromRegions(
|
||||
void AssistantOnboardingSuggestionView::OnThemeChanged() {
|
||||
views::View::OnThemeChanged();
|
||||
|
||||
GetBackground()->SetNativeControlColor(GetBackgroundColor(index_));
|
||||
|
||||
// SetNativeControlColor does not trigger a repaint.
|
||||
GetBackground()->SetColor(GetBackgroundColor(index_));
|
||||
SchedulePaint();
|
||||
|
||||
label_->SetEnabledColor(GetForegroundColor(index_));
|
||||
|
||||
if (assistant::util::IsResourceLinkType(url_, ResourceLinkType::kIcon)) {
|
||||
|
@ -3,6 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "ash/assistant/ui/main_stage/assistant_onboarding_suggestion_view.h"
|
||||
|
||||
#include "ash/assistant/ui/assistant_view_ids.h"
|
||||
#include "ash/constants/ash_pref_names.h"
|
||||
#include "ash/session/session_controller_impl.h"
|
||||
@ -14,6 +15,7 @@
|
||||
#include "ui/gfx/color_palette.h"
|
||||
#include "ui/views/background.h"
|
||||
#include "ui/views/controls/label.h"
|
||||
#include "ui/views/view.h"
|
||||
#include "ui/views/widget/widget.h"
|
||||
|
||||
namespace ash {
|
||||
@ -57,32 +59,37 @@ TEST_F(AssistantOnboardingSuggestionViewTest, DarkAndLightTheme) {
|
||||
AssistantOnboardingSuggestionView* suggestion_view_5 =
|
||||
CreateSuggestionViewAt(5, widget.get());
|
||||
|
||||
auto get_background_color([](const views::View* view) {
|
||||
return view->GetBackground()->color().ConvertToSkColor(
|
||||
view->GetColorProvider());
|
||||
});
|
||||
|
||||
// 0x19 is for 10% alpha. 255*0.1=25.5. -> 25 in hex is 0x19.
|
||||
EXPECT_EQ(suggestion_view_0->GetBackground()->get_color(),
|
||||
EXPECT_EQ(get_background_color(suggestion_view_0),
|
||||
SkColorSetA(gfx::kGoogleBlue600, 0x19));
|
||||
EXPECT_EQ(GetLabel(suggestion_view_0)->GetEnabledColor(),
|
||||
gfx::kGoogleBlue800);
|
||||
|
||||
EXPECT_EQ(suggestion_view_1->GetBackground()->get_color(),
|
||||
EXPECT_EQ(get_background_color(suggestion_view_1),
|
||||
SkColorSetA(gfx::kGoogleRed600, 0x19));
|
||||
EXPECT_EQ(GetLabel(suggestion_view_1)->GetEnabledColor(), gfx::kGoogleRed800);
|
||||
|
||||
EXPECT_EQ(suggestion_view_2->GetBackground()->get_color(),
|
||||
EXPECT_EQ(get_background_color(suggestion_view_2),
|
||||
SkColorSetA(gfx::kGoogleYellow600, 0x19));
|
||||
EXPECT_EQ(GetLabel(suggestion_view_2)->GetEnabledColor(),
|
||||
SkColorSetRGB(0xBF, 0x50, 0x00));
|
||||
|
||||
EXPECT_EQ(suggestion_view_3->GetBackground()->get_color(),
|
||||
EXPECT_EQ(get_background_color(suggestion_view_3),
|
||||
SkColorSetA(gfx::kGoogleGreen600, 0x19));
|
||||
EXPECT_EQ(GetLabel(suggestion_view_3)->GetEnabledColor(),
|
||||
gfx::kGoogleGreen800);
|
||||
|
||||
EXPECT_EQ(suggestion_view_4->GetBackground()->get_color(),
|
||||
EXPECT_EQ(get_background_color(suggestion_view_4),
|
||||
SkColorSetARGB(0x19, 0xc6, 0x1a, 0xd9));
|
||||
EXPECT_EQ(GetLabel(suggestion_view_4)->GetEnabledColor(),
|
||||
SkColorSetRGB(0xaa, 0x00, 0xb8));
|
||||
|
||||
EXPECT_EQ(suggestion_view_5->GetBackground()->get_color(),
|
||||
EXPECT_EQ(get_background_color(suggestion_view_5),
|
||||
SkColorSetA(gfx::kGoogleBlue600, 0x19));
|
||||
EXPECT_EQ(GetLabel(suggestion_view_5)->GetEnabledColor(),
|
||||
gfx::kGoogleBlue800);
|
||||
@ -91,31 +98,31 @@ TEST_F(AssistantOnboardingSuggestionViewTest, DarkAndLightTheme) {
|
||||
ASSERT_TRUE(DarkLightModeControllerImpl::Get()->IsDarkModeEnabled());
|
||||
|
||||
// 0x4c is for 30% alpha. 255*0.3=76.5. 0x4c is 76 in hex.
|
||||
EXPECT_EQ(suggestion_view_0->GetBackground()->get_color(),
|
||||
EXPECT_EQ(get_background_color(suggestion_view_0),
|
||||
SkColorSetA(gfx::kGoogleBlue300, 0x4c));
|
||||
EXPECT_EQ(GetLabel(suggestion_view_0)->GetEnabledColor(),
|
||||
gfx::kGoogleBlue200);
|
||||
|
||||
EXPECT_EQ(suggestion_view_1->GetBackground()->get_color(),
|
||||
EXPECT_EQ(get_background_color(suggestion_view_1),
|
||||
SkColorSetA(gfx::kGoogleRed300, 0x4c));
|
||||
EXPECT_EQ(GetLabel(suggestion_view_1)->GetEnabledColor(), gfx::kGoogleRed200);
|
||||
|
||||
EXPECT_EQ(suggestion_view_2->GetBackground()->get_color(),
|
||||
EXPECT_EQ(get_background_color(suggestion_view_2),
|
||||
SkColorSetA(gfx::kGoogleYellow300, 0x4c));
|
||||
EXPECT_EQ(GetLabel(suggestion_view_2)->GetEnabledColor(),
|
||||
gfx::kGoogleYellow200);
|
||||
|
||||
EXPECT_EQ(suggestion_view_3->GetBackground()->get_color(),
|
||||
EXPECT_EQ(get_background_color(suggestion_view_3),
|
||||
SkColorSetA(gfx::kGoogleGreen300, 0x4c));
|
||||
EXPECT_EQ(GetLabel(suggestion_view_3)->GetEnabledColor(),
|
||||
gfx::kGoogleGreen200);
|
||||
|
||||
EXPECT_EQ(suggestion_view_4->GetBackground()->get_color(),
|
||||
EXPECT_EQ(get_background_color(suggestion_view_4),
|
||||
SkColorSetARGB(0x4c, 0xf8, 0x82, 0xff));
|
||||
EXPECT_EQ(GetLabel(suggestion_view_4)->GetEnabledColor(),
|
||||
SkColorSetRGB(0xf8, 0x82, 0xff));
|
||||
|
||||
EXPECT_EQ(suggestion_view_5->GetBackground()->get_color(),
|
||||
EXPECT_EQ(get_background_color(suggestion_view_5),
|
||||
SkColorSetA(gfx::kGoogleBlue300, 0x4c));
|
||||
EXPECT_EQ(GetLabel(suggestion_view_5)->GetEnabledColor(),
|
||||
gfx::kGoogleBlue200);
|
||||
|
@ -188,8 +188,7 @@ void UiElementContainerView::OnCommittedQueryChanged(
|
||||
|
||||
void UiElementContainerView::OnThemeChanged() {
|
||||
views::View::OnThemeChanged();
|
||||
|
||||
scroll_indicator_->background()->SetNativeControlColor(
|
||||
scroll_indicator_->background()->SetColor(
|
||||
GetOverflowIndicatorBackgroundColor());
|
||||
|
||||
// SetNativeControlColor doesn't trigger a repaint.
|
||||
|
@ -43,7 +43,12 @@ TEST_F(UiElementContainerViewTest, DarkAndLightTheme) {
|
||||
page_view()->GetViewByID(kUiElementContainer);
|
||||
views::View* indicator =
|
||||
ui_element_container_view->GetViewByID(kOverflowIndicator);
|
||||
EXPECT_EQ(indicator->GetBackground()->get_color(),
|
||||
auto get_background_color([](const views::View* view) {
|
||||
return view->GetBackground()->color().ConvertToSkColor(
|
||||
view->GetColorProvider());
|
||||
});
|
||||
|
||||
EXPECT_EQ(get_background_color(indicator),
|
||||
AshColorProvider::Get()->GetContentLayerColor(
|
||||
ColorProvider::ContentLayerType::kSeparatorColor));
|
||||
|
||||
@ -52,7 +57,7 @@ TEST_F(UiElementContainerViewTest, DarkAndLightTheme) {
|
||||
const bool dark_mode_status = dark_light_mode_controller->IsDarkModeEnabled();
|
||||
ASSERT_NE(initial_dark_mode_status, dark_mode_status);
|
||||
|
||||
EXPECT_EQ(indicator->GetBackground()->get_color(),
|
||||
EXPECT_EQ(get_background_color(indicator),
|
||||
AshColorProvider::Get()->GetContentLayerColor(
|
||||
ColorProvider::ContentLayerType::kSeparatorColor));
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ void KeyItemView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
|
||||
|
||||
void KeyItemView::OnThemeChanged() {
|
||||
views::View::OnThemeChanged();
|
||||
GetBackground()->SetNativeControlColor(GetColor());
|
||||
GetBackground()->SetColor(GetColor());
|
||||
SchedulePaint();
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ class BottomLeftOuterBackground : public views::Background {
|
||||
// Background will have left bottom rounded corner with |top_rounding_radius|.
|
||||
BottomLeftOuterBackground(SkColor color, SkScalar top_rounding_radius)
|
||||
: inner_radius_(top_rounding_radius) {
|
||||
SetNativeControlColor(color);
|
||||
SetColor(color);
|
||||
}
|
||||
|
||||
BottomLeftOuterBackground(const BottomLeftOuterBackground&) = delete;
|
||||
@ -59,7 +59,7 @@ class BottomLeftOuterBackground : public views::Background {
|
||||
flags.setAntiAlias(true);
|
||||
flags.setBlendMode(SkBlendMode::kSrc);
|
||||
flags.setStyle(cc::PaintFlags::kFill_Style);
|
||||
flags.setColor(get_color());
|
||||
flags.setColor(color().ConvertToSkColor(view->GetColorProvider()));
|
||||
canvas->DrawPath(path, flags);
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,8 @@ namespace {
|
||||
constexpr SkColor kHUDDisabledButtonColor =
|
||||
SkColorSetA(kHUDDefaultColor, 0xFF * 0.5);
|
||||
|
||||
constexpr float kActionButtonCornerRadius = 2;
|
||||
|
||||
// Thickness of border around settings.
|
||||
constexpr int kHUDSettingsBorderWidth = 1;
|
||||
|
||||
@ -362,7 +364,6 @@ void AnimationSpeedControl::Layout(PassKey) {
|
||||
|
||||
class HUDActionButton : public views::LabelButton {
|
||||
METADATA_HEADER(HUDActionButton, views::LabelButton)
|
||||
|
||||
public:
|
||||
HUDActionButton(views::Button::PressedCallback::Callback callback,
|
||||
const std::u16string& text)
|
||||
@ -370,9 +371,8 @@ class HUDActionButton : public views::LabelButton {
|
||||
SetHorizontalAlignment(gfx::ALIGN_CENTER);
|
||||
SetEnabledTextColors(kHUDBackground);
|
||||
SetProperty(kHUDClickHandler, HTCLIENT);
|
||||
constexpr float kActionButtonCournerRadius = 2;
|
||||
SetBackground(views::CreateRoundedRectBackground(
|
||||
kHUDDefaultColor, kActionButtonCournerRadius));
|
||||
kHUDDefaultColor, kActionButtonCornerRadius));
|
||||
SetFocusBehavior(views::View::FocusBehavior::ACCESSIBLE_ONLY);
|
||||
on_enabled_changed_subscription_ =
|
||||
AddEnabledChangedCallback(base::BindRepeating(
|
||||
@ -411,11 +411,9 @@ class HUDActionButton : public views::LabelButton {
|
||||
}
|
||||
|
||||
void UpdateBackgroundColor() override {
|
||||
if (GetVisualState() == STATE_DISABLED) {
|
||||
GetBackground()->SetNativeControlColor(kHUDDisabledButtonColor);
|
||||
} else {
|
||||
GetBackground()->SetNativeControlColor(kHUDDefaultColor);
|
||||
}
|
||||
GetBackground()->SetColor(GetVisualState() == STATE_DISABLED
|
||||
? kHUDDisabledButtonColor
|
||||
: kHUDDefaultColor);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -16,15 +16,17 @@ namespace hud_display {
|
||||
SolidSourceBackground::SolidSourceBackground(SkColor color,
|
||||
SkScalar top_rounding_radius)
|
||||
: top_rounding_radius_(top_rounding_radius) {
|
||||
SetNativeControlColor(color);
|
||||
SetColor(color);
|
||||
}
|
||||
|
||||
void SolidSourceBackground::Paint(gfx::Canvas* canvas,
|
||||
views::View* view) const {
|
||||
const SkColor resolved_color =
|
||||
color().ConvertToSkColor(view->GetColorProvider());
|
||||
if (top_rounding_radius_ == 0) {
|
||||
// Fill the background. Note that we don't constrain to the bounds as
|
||||
// canvas is already clipped for us.
|
||||
canvas->DrawColor(get_color(), SkBlendMode::kSrc);
|
||||
canvas->DrawColor(resolved_color, SkBlendMode::kSrc);
|
||||
} else {
|
||||
const SkScalar circle_size = top_rounding_radius_ * 2;
|
||||
const SkScalar right_edge = view->width();
|
||||
@ -42,7 +44,7 @@ void SolidSourceBackground::Paint(gfx::Canvas* canvas,
|
||||
flags.setAntiAlias(true);
|
||||
flags.setBlendMode(SkBlendMode::kSrc);
|
||||
flags.setStyle(cc::PaintFlags::kFill_Style);
|
||||
flags.setColor(get_color());
|
||||
flags.setColor(resolved_color);
|
||||
canvas->DrawPath(path, flags);
|
||||
}
|
||||
}
|
||||
|
@ -85,9 +85,8 @@ TEST_F(LoginBaseBubbleViewTest, BasicProperties) {
|
||||
EXPECT_TRUE(bubble_->GetVisible());
|
||||
|
||||
EXPECT_EQ(bubble_->width(), kBubbleTotalWidthDp);
|
||||
SkColor background_color = bubble_->GetColorProvider()->GetColor(
|
||||
cros_tokens::kCrosSysSystemBaseElevated);
|
||||
EXPECT_EQ(bubble_->background()->get_color(), background_color);
|
||||
EXPECT_EQ(bubble_->background()->color(),
|
||||
cros_tokens::kCrosSysSystemBaseElevated);
|
||||
|
||||
bubble_->Hide();
|
||||
EXPECT_FALSE(bubble_->GetVisible());
|
||||
|
@ -53,9 +53,8 @@ TEST_F(QuickInsertMainContainerViewTest, BackgroundColor) {
|
||||
auto* container =
|
||||
widget->SetContentsView(std::make_unique<QuickInsertMainContainerView>());
|
||||
|
||||
EXPECT_EQ(container->background()->get_color(),
|
||||
container->GetColorProvider()->GetColor(
|
||||
cros_tokens::kCrosSysSystemBaseElevatedOpaque));
|
||||
EXPECT_EQ(container->background()->color(),
|
||||
cros_tokens::kCrosSysSystemBaseElevatedOpaque);
|
||||
}
|
||||
|
||||
TEST_F(QuickInsertMainContainerViewTest, LayoutWithContentsBelowSearchField) {
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "base/functional/callback_forward.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/strings/strcat.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
#include "third_party/skia/include/core/SkPath.h"
|
||||
#include "ui/base/ime/text_input_flags.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
@ -111,8 +112,10 @@ void SetupLabelView(views::Label* label,
|
||||
// border.
|
||||
class SearchBoxBackground : public views::Background {
|
||||
public:
|
||||
explicit SearchBoxBackground(int corner_radius)
|
||||
: corner_radius_(corner_radius) {}
|
||||
SearchBoxBackground(SkColor color, int corner_radius)
|
||||
: corner_radius_(corner_radius) {
|
||||
SetColor(color);
|
||||
}
|
||||
|
||||
SearchBoxBackground(const SearchBoxBackground&) = delete;
|
||||
SearchBoxBackground& operator=(const SearchBoxBackground&) = delete;
|
||||
@ -128,7 +131,7 @@ class SearchBoxBackground : public views::Background {
|
||||
|
||||
cc::PaintFlags flags;
|
||||
flags.setAntiAlias(true);
|
||||
flags.setColor(get_color());
|
||||
flags.setColor(color().ConvertToSkColor(view->GetColorProvider()));
|
||||
canvas->DrawRoundRect(bounds, corner_radius_, flags);
|
||||
}
|
||||
|
||||
@ -465,8 +468,8 @@ void SearchBoxViewBase::Init(const InitParams& params) {
|
||||
layer()->SetFillsBoundsOpaquely(false);
|
||||
layer()->SetMasksToBounds(true);
|
||||
if (params.create_background) {
|
||||
SetBackground(
|
||||
std::make_unique<SearchBoxBackground>(kSearchBoxBorderCornerRadius));
|
||||
SetBackground(std::make_unique<SearchBoxBackground>(
|
||||
gfx::kPlaceholderColor, kSearchBoxBorderCornerRadius));
|
||||
}
|
||||
|
||||
if (params.increase_child_view_padding) {
|
||||
@ -935,7 +938,7 @@ void SearchBoxViewBase::HandleSearchBoxEvent(ui::LocatedEvent* located_event) {
|
||||
void SearchBoxViewBase::UpdateBackgroundColor(SkColor color) {
|
||||
auto* search_box_background = background();
|
||||
if (search_box_background)
|
||||
search_box_background->SetNativeControlColor(color);
|
||||
search_box_background->SetColor(color);
|
||||
if (close_button_)
|
||||
close_button_->UpdateInkDropColorAndOpacity(color);
|
||||
if (assistant_button_)
|
||||
|
@ -192,10 +192,13 @@ class PromiseIconBackground : public views::Background {
|
||||
PromiseIconBackground(ui::ColorId color_id,
|
||||
const gfx::Rect& icon_bounds,
|
||||
const gfx::Insets& insets)
|
||||
: color_id_(color_id), icon_bounds_(icon_bounds), insets_(insets) {}
|
||||
: icon_bounds_(icon_bounds), insets_(insets) {
|
||||
SetColor(color_id);
|
||||
}
|
||||
|
||||
PromiseIconBackground(const PromiseIconBackground&) = delete;
|
||||
PromiseIconBackground& operator=(const PromiseIconBackground&) = delete;
|
||||
|
||||
~PromiseIconBackground() override = default;
|
||||
|
||||
// views::Background:
|
||||
@ -208,18 +211,16 @@ class PromiseIconBackground : public views::Background {
|
||||
|
||||
cc::PaintFlags flags;
|
||||
flags.setAntiAlias(true);
|
||||
flags.setColor(get_color());
|
||||
flags.setColor(color().ConvertToSkColor(view->GetColorProvider()));
|
||||
|
||||
canvas->DrawCircle(bounds.CenterPoint(), radius, flags);
|
||||
}
|
||||
|
||||
void OnViewThemeChanged(views::View* view) override {
|
||||
SetNativeControlColor(view->GetColorProvider()->GetColor(color_id_));
|
||||
view->SchedulePaint();
|
||||
}
|
||||
|
||||
private:
|
||||
const ui::ColorId color_id_;
|
||||
const gfx::Rect icon_bounds_;
|
||||
const gfx::Insets insets_;
|
||||
};
|
||||
|
@ -683,11 +683,6 @@ void IconButton::OnEnabledStateChanged() {
|
||||
UpdateBackground();
|
||||
}
|
||||
|
||||
SkColor IconButton::GetBackgroundColor() const {
|
||||
DCHECK(background());
|
||||
return background()->get_color();
|
||||
}
|
||||
|
||||
bool IconButton::IsToggledOn() const {
|
||||
return toggled_ &&
|
||||
(GetEnabled() ||
|
||||
|
@ -204,9 +204,6 @@ class ASH_EXPORT IconButton : public views::ImageButton {
|
||||
|
||||
void OnEnabledStateChanged();
|
||||
|
||||
// Gets the background color of the icon button.
|
||||
SkColor GetBackgroundColor() const;
|
||||
|
||||
private:
|
||||
// For unit tests.
|
||||
friend class BluetoothFeaturePodControllerTest;
|
||||
|
@ -36,8 +36,9 @@ constexpr int kTooltipMaxLines = 3;
|
||||
// of the minimum dimension of its view's local bounds.
|
||||
class ThemedFullyRoundedRectBackground : public views::Background {
|
||||
public:
|
||||
explicit ThemedFullyRoundedRectBackground(ui::ColorId color_id)
|
||||
: color_id_(color_id) {}
|
||||
explicit ThemedFullyRoundedRectBackground(ui::ColorId color_id) {
|
||||
SetColor(color_id);
|
||||
}
|
||||
ThemedFullyRoundedRectBackground(const ThemedFullyRoundedRectBackground&) =
|
||||
delete;
|
||||
ThemedFullyRoundedRectBackground& operator=(
|
||||
@ -46,7 +47,6 @@ class ThemedFullyRoundedRectBackground : public views::Background {
|
||||
|
||||
// views::Background:
|
||||
void OnViewThemeChanged(views::View* view) override {
|
||||
SetNativeControlColor(view->GetColorProvider()->GetColor(color_id_));
|
||||
view->SchedulePaint();
|
||||
}
|
||||
|
||||
@ -55,11 +55,11 @@ class ThemedFullyRoundedRectBackground : public views::Background {
|
||||
cc::PaintFlags paint;
|
||||
paint.setAntiAlias(true);
|
||||
|
||||
SkColor color = get_color();
|
||||
SkColor resolved_color = color().ConvertToSkColor(view->GetColorProvider());
|
||||
if (!view->GetEnabled()) {
|
||||
color = ColorUtil::GetDisabledColor(color);
|
||||
resolved_color = ColorUtil::GetDisabledColor(resolved_color);
|
||||
}
|
||||
paint.setColor(color);
|
||||
paint.setColor(resolved_color);
|
||||
|
||||
const gfx::Rect bounds = view->GetLocalBounds();
|
||||
// Set the rounded corner radius to the half of the minimum dimension of
|
||||
@ -68,10 +68,6 @@ class ThemedFullyRoundedRectBackground : public views::Background {
|
||||
std::min(bounds.width(), bounds.height()) / 2;
|
||||
canvas->DrawRoundRect(bounds, rounded_corner_radius, paint);
|
||||
}
|
||||
|
||||
private:
|
||||
// Color Id of the background.
|
||||
const ui::ColorId color_id_;
|
||||
};
|
||||
|
||||
// A `HighlightPathGenerator` that uses caller-supplied rounded rect corners.
|
||||
|
@ -95,49 +95,34 @@ class SystemUIComponentsStyleViewerView::ComponentButton
|
||||
SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_CENTER);
|
||||
SetBorder(std::make_unique<views::HighlightBorder>(
|
||||
0, views::HighlightBorder::Type::kHighlightBorderNoShadow));
|
||||
SetBackground(
|
||||
views::CreateSolidBackground(kInactiveButtonBackgroundColorId));
|
||||
SetEnabledTextColors(kInactiveButtonTextColorId);
|
||||
|
||||
label()->SetSubpixelRenderingEnabled(false);
|
||||
label()->SetFontList(views::Label::GetDefaultFontList().Derive(
|
||||
1, gfx::Font::NORMAL, gfx::Font::Weight::MEDIUM));
|
||||
|
||||
SetFocusBehavior(views::View::FocusBehavior::NEVER);
|
||||
}
|
||||
|
||||
ComponentButton(const ComponentButton&) = delete;
|
||||
ComponentButton& operator=(const ComponentButton&) = delete;
|
||||
|
||||
~ComponentButton() override = default;
|
||||
|
||||
void SetActive(bool active) {
|
||||
background_color_id_ = active ? kActiveButtonBackgroundColorId
|
||||
: kInactiveButtonBackgroundColorId;
|
||||
text_color_id_ =
|
||||
active ? kActiveButtonTextColorId : kInactiveButtonTextColorId;
|
||||
OnThemeChanged();
|
||||
SetEnabledTextColors(active ? kActiveButtonTextColorId
|
||||
: kInactiveButtonTextColorId);
|
||||
background()->SetColor(active ? kActiveButtonBackgroundColorId
|
||||
: kInactiveButtonBackgroundColorId);
|
||||
}
|
||||
|
||||
// views::LabelButton:
|
||||
void AddedToWidget() override {
|
||||
SetBackground(views::CreateSolidBackground(
|
||||
GetColorProvider()->GetColor(background_color_id_)));
|
||||
}
|
||||
|
||||
gfx::Size CalculatePreferredSize(
|
||||
const views::SizeBounds& available_size) const override {
|
||||
return gfx::Size(kMenuWidth, kDefaultButtonHeight);
|
||||
}
|
||||
|
||||
void OnThemeChanged() override {
|
||||
views::LabelButton::OnThemeChanged();
|
||||
|
||||
if (!GetWidget())
|
||||
return;
|
||||
|
||||
ui::ColorProvider* color_provider = GetColorProvider();
|
||||
SetEnabledTextColors(color_provider->GetColor(text_color_id_));
|
||||
if (auto* bg = background())
|
||||
bg->SetNativeControlColor(color_provider->GetColor(background_color_id_));
|
||||
}
|
||||
|
||||
private:
|
||||
ui::ColorId background_color_id_ = kInactiveButtonBackgroundColorId;
|
||||
ui::ColorId text_color_id_ = kInactiveButtonTextColorId;
|
||||
};
|
||||
|
||||
BEGIN_METADATA(SystemUIComponentsStyleViewerView, ComponentButton)
|
||||
|
@ -92,9 +92,7 @@ TEST_F(HoldingSpaceTrayChildBubbleTest, HasExpectedBubbleTreatment) {
|
||||
// Background.
|
||||
auto* background = child_bubble()->GetBackground();
|
||||
ASSERT_TRUE(background);
|
||||
EXPECT_EQ(background->get_color(),
|
||||
child_bubble()->GetColorProvider()->GetColor(
|
||||
cros_tokens::kCrosSysSystemBaseElevated));
|
||||
EXPECT_EQ(background->color(), cros_tokens::kCrosSysSystemBaseElevated);
|
||||
EXPECT_EQ(layer->background_blur(), ColorProvider::kBackgroundBlurSigma);
|
||||
|
||||
// Border.
|
||||
|
@ -50,13 +50,18 @@ class CallbackPathGenerator : public views::HighlightPathGenerator {
|
||||
class CircleBackground : public views::Background {
|
||||
public:
|
||||
CircleBackground(ui::ColorId color_id, size_t fixed_size)
|
||||
: color_id_(color_id), fixed_size_(fixed_size) {}
|
||||
: fixed_size_(fixed_size) {
|
||||
SetColor(color_id);
|
||||
}
|
||||
|
||||
CircleBackground(ui::ColorId color_id, const gfx::InsetsF& insets)
|
||||
: color_id_(color_id), insets_(insets) {}
|
||||
: insets_(insets) {
|
||||
SetColor(color_id);
|
||||
}
|
||||
|
||||
CircleBackground(const CircleBackground&) = delete;
|
||||
CircleBackground& operator=(const CircleBackground&) = delete;
|
||||
|
||||
~CircleBackground() override = default;
|
||||
|
||||
// views::Background:
|
||||
@ -73,18 +78,16 @@ class CircleBackground : public views::Background {
|
||||
|
||||
cc::PaintFlags flags;
|
||||
flags.setAntiAlias(true);
|
||||
flags.setColor(get_color());
|
||||
flags.setColor(color().ConvertToSkColor(view->GetColorProvider()));
|
||||
|
||||
canvas->DrawCircle(bounds.CenterPoint(), radius, flags);
|
||||
}
|
||||
|
||||
void OnViewThemeChanged(views::View* view) override {
|
||||
SetNativeControlColor(view->GetColorProvider()->GetColor(color_id_));
|
||||
view->SchedulePaint();
|
||||
}
|
||||
|
||||
private:
|
||||
const ui::ColorId color_id_;
|
||||
const std::optional<size_t> fixed_size_;
|
||||
const std::optional<gfx::InsetsF> insets_;
|
||||
};
|
||||
|
@ -20,8 +20,10 @@ constexpr float kTopOffset = 12.f;
|
||||
|
||||
} // namespace
|
||||
|
||||
CalendarUpNextViewBackground::CalendarUpNextViewBackground(ui::ColorId color_id)
|
||||
: color_id_(color_id) {}
|
||||
CalendarUpNextViewBackground::CalendarUpNextViewBackground(
|
||||
ui::ColorId color_id) {
|
||||
SetColor(color_id);
|
||||
}
|
||||
|
||||
CalendarUpNextViewBackground::~CalendarUpNextViewBackground() = default;
|
||||
|
||||
@ -80,7 +82,7 @@ void CalendarUpNextViewBackground::Paint(gfx::Canvas* canvas,
|
||||
flags.setBlendMode(SkBlendMode::kSrcOver);
|
||||
flags.setAntiAlias(true);
|
||||
flags.setStyle(cc::PaintFlags::kFill_Style);
|
||||
flags.setColor(view->GetColorProvider()->GetColor(color_id_));
|
||||
flags.setColor(color().ConvertToSkColor(view->GetColorProvider()));
|
||||
|
||||
// Get the path to draw on the canvas.
|
||||
SkPath path = GetPath(view->GetLocalBounds().size());
|
||||
@ -90,7 +92,6 @@ void CalendarUpNextViewBackground::Paint(gfx::Canvas* canvas,
|
||||
}
|
||||
|
||||
void CalendarUpNextViewBackground::OnViewThemeChanged(views::View* view) {
|
||||
SetNativeControlColor(view->GetColorProvider()->GetColor(color_id_));
|
||||
view->SchedulePaint();
|
||||
}
|
||||
|
||||
|
@ -29,9 +29,6 @@ class CalendarUpNextViewBackground : public views::Background {
|
||||
// views::Background:
|
||||
void Paint(gfx::Canvas* canvas, views::View* view) const override;
|
||||
void OnViewThemeChanged(views::View* view) override;
|
||||
|
||||
private:
|
||||
ui::ColorId color_id_;
|
||||
};
|
||||
|
||||
} // namespace ash
|
||||
|
@ -120,7 +120,7 @@ void DeskIconButton::UpdateState(State state) {
|
||||
// the new `state_`.
|
||||
if (background()) {
|
||||
SetBackground(views::CreateRoundedRectBackground(
|
||||
background()->get_color(), GetCornerRadiusOnState(state_)));
|
||||
background()->color(), GetCornerRadiusOnState(state_)));
|
||||
}
|
||||
views::InstallRoundRectHighlightPathGenerator(
|
||||
this, gfx::Insets(kWindowMiniViewFocusRingHaloInset),
|
||||
|
@ -281,7 +281,7 @@ void AnimateDeskIconButtonScale(DeskIconButton* button,
|
||||
auto* layer = button->layer();
|
||||
layer->SetRoundedCornerRadius(initial_radius);
|
||||
button->SetBackground(
|
||||
views::CreateSolidBackground(button->background()->get_color()));
|
||||
views::CreateSolidBackground(button->background()->color()));
|
||||
|
||||
layer->SetTransform(scale_transform);
|
||||
|
||||
@ -297,7 +297,7 @@ void AnimateDeskIconButtonScale(DeskIconButton* button,
|
||||
if (overview_controller->InOverviewSession()) {
|
||||
button->layer()->SetRoundedCornerRadius(gfx::RoundedCornersF());
|
||||
button->SetBackground(views::CreateRoundedRectBackground(
|
||||
button->background()->get_color(),
|
||||
button->background()->color(),
|
||||
DeskIconButton::GetCornerRadiusOnState(button->state())));
|
||||
}
|
||||
},
|
||||
|
@ -510,10 +510,6 @@ class DesksTest : public AshTestBase,
|
||||
: state != DeskIconButton::State::kExpanded);
|
||||
}
|
||||
|
||||
SkColor GetNewDeskButtonBackgroundColor(const DeskBarViewBase* bar_view) {
|
||||
return bar_view->new_desk_button()->background()->get_color();
|
||||
}
|
||||
|
||||
void TryScrollOverviewDeskBar(DeskBarScrollDirection scroll_direction,
|
||||
bool do_left_click = true) {
|
||||
ScrollArrowButton* scroll_button = nullptr;
|
||||
@ -2437,14 +2433,21 @@ TEST_P(DesksTest, NewDeskButtonStateAndColor) {
|
||||
SkColor background_color =
|
||||
color_provider->GetColor(cros_tokens::kCrosSysPrimary);
|
||||
|
||||
auto get_background_color([](const views::View* view) {
|
||||
return view->GetBackground()->color().ConvertToSkColor(
|
||||
view->GetColorProvider());
|
||||
});
|
||||
|
||||
const SkColor disabled_background_color =
|
||||
ColorUtil::GetDisabledColor(background_color);
|
||||
EXPECT_TRUE(new_desk_button->GetEnabled());
|
||||
EXPECT_EQ(background_color, GetNewDeskButtonBackgroundColor(desks_bar_view));
|
||||
EXPECT_EQ(background_color,
|
||||
get_background_color(desks_bar_view->new_desk_button()));
|
||||
|
||||
LeftClickOn(new_desk_button);
|
||||
EXPECT_TRUE(new_desk_button->GetEnabled());
|
||||
EXPECT_EQ(background_color, GetNewDeskButtonBackgroundColor(desks_bar_view));
|
||||
EXPECT_EQ(background_color,
|
||||
get_background_color(desks_bar_view->new_desk_button()));
|
||||
|
||||
// Tests that adding desks until we reach the desks limit should change the
|
||||
// state and color of the new desk button.
|
||||
@ -2459,7 +2462,7 @@ TEST_P(DesksTest, NewDeskButtonStateAndColor) {
|
||||
}
|
||||
EXPECT_FALSE(new_desk_button->GetEnabled());
|
||||
EXPECT_EQ(disabled_background_color,
|
||||
GetNewDeskButtonBackgroundColor(desks_bar_view));
|
||||
get_background_color(desks_bar_view->new_desk_button()));
|
||||
}
|
||||
|
||||
// Tests that the fullscreen state in shell is updated when switching between
|
||||
@ -11176,30 +11179,25 @@ TEST_P(DeskButtonTest, UpdateShelfAlignmentDuringTest) {
|
||||
// Verify desk names and color changes.
|
||||
ASSERT_EQ(bottom_at_start ? u"school" : u"s",
|
||||
desk_button->desk_name_label()->GetText());
|
||||
auto* color_provider = desk_button->GetColorProvider();
|
||||
ASSERT_EQ(color_provider->GetColor(bottom_at_start
|
||||
? cros_tokens::kCrosSysSystemOnBase1
|
||||
: cros_tokens::kCrosSysSystemOnBase),
|
||||
desk_button->GetBackground()->get_color());
|
||||
ASSERT_EQ(bottom_at_start ? cros_tokens::kCrosSysSystemOnBase1
|
||||
: cros_tokens::kCrosSysSystemOnBase,
|
||||
desk_button->GetBackground()->color());
|
||||
|
||||
// Activate/Deactivate the desk button and verify color changes.
|
||||
ClickDeskButton();
|
||||
ASSERT_EQ(
|
||||
color_provider->GetColor(cros_tokens::kCrosSysSystemPrimaryContainer),
|
||||
desk_button->GetBackground()->get_color());
|
||||
ASSERT_EQ(cros_tokens::kCrosSysSystemPrimaryContainer,
|
||||
desk_button->GetBackground()->color());
|
||||
ClickDeskButton();
|
||||
ASSERT_EQ(color_provider->GetColor(bottom_at_start
|
||||
? cros_tokens::kCrosSysSystemOnBase1
|
||||
: cros_tokens::kCrosSysSystemOnBase),
|
||||
desk_button->GetBackground()->get_color());
|
||||
ASSERT_EQ(bottom_at_start ? cros_tokens::kCrosSysSystemOnBase1
|
||||
: cros_tokens::kCrosSysSystemOnBase,
|
||||
desk_button->GetBackground()->color());
|
||||
|
||||
// Update shelf alignment and verify desk names and color changes.
|
||||
GetPrimaryShelf()->SetAlignment(bottom_at_start ? ShelfAlignment::kLeft
|
||||
: ShelfAlignment::kBottom);
|
||||
ASSERT_EQ(color_provider->GetColor(bottom_at_start
|
||||
? cros_tokens::kCrosSysSystemOnBase
|
||||
: cros_tokens::kCrosSysSystemOnBase1),
|
||||
desk_button->GetBackground()->get_color());
|
||||
ASSERT_EQ(bottom_at_start ? cros_tokens::kCrosSysSystemOnBase
|
||||
: cros_tokens::kCrosSysSystemOnBase1,
|
||||
desk_button->GetBackground()->color());
|
||||
EXPECT_EQ(bottom_at_start ? u"s" : u"school",
|
||||
desk_button->desk_name_label()->GetText());
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "content/public/browser/browser_task_traits.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "ui/base/metadata/metadata_header_macros.h"
|
||||
#include "ui/base/metadata/metadata_impl_macros.h"
|
||||
@ -80,7 +81,7 @@ base::TimeDelta show_dialog_delay_ = base::Seconds(1);
|
||||
// TODO(pkasting): This is copy and pasted from ThemedSolidBackground. Merge.
|
||||
class CircleBackground : public views::Background {
|
||||
public:
|
||||
explicit CircleBackground(ui::ColorId color_id) : color_id_(color_id) {}
|
||||
explicit CircleBackground(ui::ColorId color) { SetColor(color); }
|
||||
|
||||
CircleBackground(const CircleBackground&) = delete;
|
||||
CircleBackground& operator=(const CircleBackground&) = delete;
|
||||
@ -94,17 +95,14 @@ class CircleBackground : public views::Background {
|
||||
cc::PaintFlags flags;
|
||||
flags.setAntiAlias(true);
|
||||
flags.setStyle(cc::PaintFlags::kFill_Style);
|
||||
flags.setColor(get_color());
|
||||
flags.setColor(color().ConvertToSkColor(view->GetColorProvider()));
|
||||
canvas->DrawCircle(center, radius, flags);
|
||||
}
|
||||
|
||||
void OnViewThemeChanged(views::View* view) override {
|
||||
SetNativeControlColor(view->GetColorProvider()->GetColor(color_id_));
|
||||
view->SchedulePaint();
|
||||
}
|
||||
|
||||
private:
|
||||
ui::ColorId color_id_;
|
||||
};
|
||||
|
||||
ContentAnalysisDialog::TestObserver* observer_for_testing = nullptr;
|
||||
@ -161,10 +159,8 @@ class DeepScanningSideIconImageView : public DeepScanningBaseView,
|
||||
dialog()->GetSideImageLogoColor(),
|
||||
kSideImageSize));
|
||||
if (dialog()->is_result()) {
|
||||
ui::ColorId color = dialog()->GetSideImageBackgroundColor();
|
||||
SetBackground(std::make_unique<CircleBackground>(color));
|
||||
GetBackground()->SetNativeControlColor(
|
||||
GetColorProvider()->GetColor(color));
|
||||
SetBackground(std::make_unique<CircleBackground>(
|
||||
dialog()->GetSideImageBackgroundColor()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,9 +120,7 @@ class AutoPipSettingOverlayViewTest : public views::ViewsTestBase {
|
||||
|
||||
TEST_F(AutoPipSettingOverlayViewTest, TestViewInitialization) {
|
||||
EXPECT_TRUE(widget()->IsVisible());
|
||||
EXPECT_EQ(
|
||||
background()->GetColorProvider()->GetColor(kColorPipWindowBackground),
|
||||
background()->GetBackground()->get_color());
|
||||
EXPECT_EQ(kColorPipWindowBackground, background()->GetBackground()->color());
|
||||
EXPECT_EQ(4.0f, blur_view()->layer()->background_blur());
|
||||
}
|
||||
|
||||
|
@ -14,19 +14,24 @@
|
||||
|
||||
namespace quick_answers {
|
||||
namespace {
|
||||
|
||||
constexpr gfx::Insets kHighlightInsets = gfx::Insets::VH(4, 0);
|
||||
|
||||
class HighlightBackground : public views::Background {
|
||||
public:
|
||||
HighlightBackground() { SetColor(ui::kColorMenuItemBackgroundHighlighted); }
|
||||
|
||||
HighlightBackground(const HighlightBackground&) = delete;
|
||||
HighlightBackground& operator=(const HighlightBackground&) = delete;
|
||||
|
||||
~HighlightBackground() override = default;
|
||||
|
||||
// `OnViewThemeChanged` is called when a background is added to a view.
|
||||
void OnViewThemeChanged(views::View* view) override {
|
||||
SetNativeControlColor(view->GetColorProvider()->GetColor(
|
||||
ui::kColorMenuItemBackgroundHighlighted));
|
||||
|
||||
// Use `SolidRoundRectPainter` to get a rectangle painter with insets.
|
||||
painter_ = views::Painter::CreateSolidRoundRectPainter(get_color(),
|
||||
/*radius=*/0,
|
||||
kHighlightInsets);
|
||||
painter_ = views::Painter::CreateSolidRoundRectPainter(
|
||||
color().ConvertToSkColor(view->GetColorProvider()),
|
||||
/*radius=*/0, kHighlightInsets);
|
||||
|
||||
view->SchedulePaint();
|
||||
}
|
||||
|
@ -80,8 +80,7 @@ TEST_F(PopupRowContentViewTest, SetSelectedUpdatesBackground) {
|
||||
view().UpdateStyle(true);
|
||||
background = view().GetBackground();
|
||||
ASSERT_TRUE(background);
|
||||
EXPECT_EQ(background->get_color(), view().GetColorProvider()->GetColor(
|
||||
ui::kColorDropdownBackgroundSelected));
|
||||
EXPECT_EQ(background->color(), ui::kColorDropdownBackgroundSelected);
|
||||
}
|
||||
|
||||
} // namespace autofill
|
||||
|
@ -176,24 +176,18 @@ class PopupRowViewTest : public ChromeViewsTestBase {
|
||||
TEST_F(PopupRowViewTest, BackgroundColorOnContentSelect) {
|
||||
ShowView(/*line_number=*/0, {Suggestion(u"Some entry")});
|
||||
ASSERT_EQ(row_view().GetSelectedCell(), std::nullopt);
|
||||
EXPECT_EQ(
|
||||
row_view().GetBackground()->get_color(),
|
||||
row_view().GetColorProvider()->GetColor(ui::kColorDropdownBackground));
|
||||
EXPECT_EQ(row_view().GetBackground()->color(), ui::kColorDropdownBackground);
|
||||
EXPECT_FALSE(row_view().GetContentView().GetBackground());
|
||||
|
||||
row_view().SetSelectedCell(CellType::kContent);
|
||||
// If only the content view is selected, then the background color of the row
|
||||
// view remains the same ...
|
||||
EXPECT_EQ(
|
||||
row_view().GetBackground()->get_color(),
|
||||
row_view().GetColorProvider()->GetColor(ui::kColorDropdownBackground));
|
||||
EXPECT_EQ(row_view().GetBackground()->color(), ui::kColorDropdownBackground);
|
||||
// ... but the background of the content view is set.
|
||||
views::Background* content_background =
|
||||
row_view().GetContentView().GetBackground();
|
||||
ASSERT_TRUE(content_background);
|
||||
EXPECT_EQ(content_background->get_color(),
|
||||
row_view().GetColorProvider()->GetColor(
|
||||
ui::kColorDropdownBackgroundSelected));
|
||||
EXPECT_EQ(content_background->color(), ui::kColorDropdownBackgroundSelected);
|
||||
}
|
||||
|
||||
// Tests that the background colors of both the `PopupRowView` and the
|
||||
@ -205,17 +199,13 @@ TEST_F(PopupRowViewTest,
|
||||
suggestion.highlight_on_select = false;
|
||||
ShowView(/*line_number=*/0, {suggestion});
|
||||
ASSERT_EQ(row_view().GetSelectedCell(), std::nullopt);
|
||||
EXPECT_EQ(
|
||||
row_view().GetBackground()->get_color(),
|
||||
row_view().GetColorProvider()->GetColor(ui::kColorDropdownBackground));
|
||||
EXPECT_EQ(row_view().GetBackground()->color(), ui::kColorDropdownBackground);
|
||||
EXPECT_FALSE(row_view().GetContentView().GetBackground());
|
||||
|
||||
// When `highlight_on_select` is false, then selecting a cell does not change
|
||||
// the background color.
|
||||
row_view().SetSelectedCell(CellType::kContent);
|
||||
EXPECT_EQ(
|
||||
row_view().GetBackground()->get_color(),
|
||||
row_view().GetColorProvider()->GetColor(ui::kColorDropdownBackground));
|
||||
EXPECT_EQ(row_view().GetBackground()->color(), ui::kColorDropdownBackground);
|
||||
EXPECT_FALSE(row_view().GetContentView().GetBackground());
|
||||
}
|
||||
|
||||
|
@ -511,7 +511,6 @@ std::unique_ptr<views::Background> LocationBarView::CreateRoundRectBackground(
|
||||
should_border_scale);
|
||||
std::unique_ptr<views::Background> background =
|
||||
CreateBackgroundFromPainter(std::move(painter));
|
||||
background->SetNativeControlColor(background_color);
|
||||
return background;
|
||||
}
|
||||
|
||||
@ -1260,19 +1259,19 @@ void LocationBarView::RefreshBackground() {
|
||||
SkColor hovered =
|
||||
color_provider->GetColor(kColorLocationBarBackgroundHovered);
|
||||
|
||||
SkColor background_color =
|
||||
gfx::Tween::ColorValueBetween(opacity, normal, hovered);
|
||||
background_color_ = gfx::Tween::ColorValueBetween(opacity, normal, hovered);
|
||||
if (is_caret_visible) {
|
||||
// Match the background color to the popup if the Omnibox is visibly
|
||||
// focused.
|
||||
background_color = color_provider->GetColor(kColorOmniboxResultsBackground);
|
||||
background_color_ =
|
||||
color_provider->GetColor(kColorOmniboxResultsBackground);
|
||||
} else if (input_in_progress && !high_contrast) {
|
||||
// Under CR23 guidelines, if the Omnibox is unfocused, but still contains
|
||||
// in-progress user input, the background color matches the popup (unless
|
||||
// high-contrast mode is enabled).
|
||||
normal = color_provider->GetColor(kColorOmniboxResultsBackground);
|
||||
hovered = color_provider->GetColor(kColorOmniboxResultsBackgroundHovered);
|
||||
background_color = gfx::Tween::ColorValueBetween(opacity, normal, hovered);
|
||||
background_color_ = gfx::Tween::ColorValueBetween(opacity, normal, hovered);
|
||||
}
|
||||
|
||||
SkColor border_color = SK_ColorTRANSPARENT;
|
||||
@ -1290,22 +1289,22 @@ void LocationBarView::RefreshBackground() {
|
||||
}
|
||||
|
||||
if (is_popup_mode_) {
|
||||
SetBackground(views::CreateSolidBackground(background_color));
|
||||
SetBackground(views::CreateSolidBackground(background_color_));
|
||||
} else {
|
||||
SetBackground(CreateRoundRectBackground(
|
||||
background_color, border_color, /*blend_mode=*/SkBlendMode::kSrcOver,
|
||||
background_color_, border_color, /*blend_mode=*/SkBlendMode::kSrcOver,
|
||||
/*antialias=*/true, /*should_border_scale=*/true));
|
||||
}
|
||||
|
||||
// Keep the views::Textfield in sync. It needs an opaque background to
|
||||
// correctly enable subpixel AA.
|
||||
omnibox_view_->SetBackgroundColor(background_color);
|
||||
omnibox_view_->SetBackgroundColor(background_color_);
|
||||
|
||||
// The divider between indicators and request chips should have the same color
|
||||
// as the omnibox.
|
||||
if (base::FeatureList::IsEnabled(
|
||||
content_settings::features::kLeftHandSideActivityIndicators)) {
|
||||
permission_dashboard_view_->SetDividerBackgroundColor(background_color);
|
||||
permission_dashboard_view_->SetDividerBackgroundColor(background_color_);
|
||||
}
|
||||
|
||||
SchedulePaint();
|
||||
@ -1763,9 +1762,13 @@ void LocationBarView::RecordPageInfoMetrics() {
|
||||
ui::ImageModel LocationBarView::GetLocationIcon(
|
||||
LocationIconView::Delegate::IconFetchedCallback on_icon_fetched) const {
|
||||
bool dark_mode = false;
|
||||
if (location_icon_view_ && location_icon_view_->GetBackground()) {
|
||||
dark_mode =
|
||||
color_utils::IsDark(location_icon_view_->GetBackground()->get_color());
|
||||
if (location_icon_view_) {
|
||||
auto* background = location_icon_view_->GetBackground();
|
||||
auto* color_provider = location_icon_view_->GetColorProvider();
|
||||
if (background && color_provider) {
|
||||
dark_mode = color_utils::IsDark(
|
||||
background->color().ConvertToSkColor(color_provider));
|
||||
}
|
||||
}
|
||||
|
||||
return omnibox_view_
|
||||
|
@ -30,10 +30,12 @@
|
||||
#include "components/permissions/permission_prompt.h"
|
||||
#include "components/security_state/core/security_state.h"
|
||||
#include "services/device/public/cpp/geolocation/buildflags.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
#include "ui/base/metadata/metadata_header_macros.h"
|
||||
#include "ui/base/mojom/menu_source_type.mojom-forward.h"
|
||||
#include "ui/base/pointer/touch_ui_controller.h"
|
||||
#include "ui/gfx/animation/slide_animation.h"
|
||||
#include "ui/gfx/color_palette.h"
|
||||
#include "ui/gfx/font.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
@ -300,6 +302,8 @@ class LocationBarView
|
||||
confirmation_chip_collapsed_time_ = time;
|
||||
}
|
||||
|
||||
SkColor GetBackgroundColorForTesting() const { return background_color_; }
|
||||
|
||||
private:
|
||||
FRIEND_TEST_ALL_PREFIXES(SecurityIndicatorTest, CheckIndicatorText);
|
||||
FRIEND_TEST_ALL_PREFIXES(TouchLocationBarViewBrowserTest,
|
||||
@ -528,7 +532,9 @@ class LocationBarView
|
||||
bool is_initialized_ = false;
|
||||
|
||||
// Used for metrics collection.
|
||||
base::TimeTicks confirmation_chip_collapsed_time_ = base::TimeTicks();
|
||||
base::TimeTicks confirmation_chip_collapsed_time_;
|
||||
|
||||
SkColor background_color_ = gfx::kPlaceholderColor;
|
||||
|
||||
// The focus manager associated with this view. The focus manager is expected
|
||||
// to outlive this view.
|
||||
|
@ -24,12 +24,14 @@ IN_PROC_BROWSER_TEST_F(OmniboxPopupViewViewsTest,
|
||||
|
||||
// Start with the Omnibox unfocused.
|
||||
omnibox_view()->GetFocusManager()->ClearFocus();
|
||||
const SkColor color_before_focus = location_bar()->background()->get_color();
|
||||
const SkColor color_before_focus =
|
||||
location_bar()->GetBackgroundColorForTesting();
|
||||
EXPECT_EQ(color_before_focus, omnibox_view()->GetBackgroundColor());
|
||||
|
||||
// Give the Omnibox focus and get its focused color.
|
||||
omnibox_view()->RequestFocus();
|
||||
const SkColor color_after_focus = location_bar()->background()->get_color();
|
||||
const SkColor color_after_focus =
|
||||
location_bar()->GetBackgroundColorForTesting();
|
||||
|
||||
// Sanity check that the colors are different, otherwise this test will not be
|
||||
// testing anything useful. It is possible that a particular theme could
|
||||
@ -41,13 +43,15 @@ IN_PROC_BROWSER_TEST_F(OmniboxPopupViewViewsTest,
|
||||
// The background is hosted in the view that contains the results area.
|
||||
CreatePopupForTestQuery();
|
||||
views::View* background_host = popup_view()->parent();
|
||||
EXPECT_EQ(color_after_focus, background_host->background()->get_color());
|
||||
EXPECT_EQ(color_after_focus,
|
||||
background_host->background()->color().ConvertToSkColor(
|
||||
background_host->GetColorProvider()));
|
||||
|
||||
omnibox_view()->GetFocusManager()->ClearFocus();
|
||||
|
||||
// Blurring the Omnibox w/ in-progress input (e.g. "foo") should result in
|
||||
// the on-focus colors.
|
||||
EXPECT_EQ(color_after_focus, location_bar()->background()->get_color());
|
||||
EXPECT_EQ(color_after_focus, location_bar()->GetBackgroundColorForTesting());
|
||||
EXPECT_EQ(color_after_focus, omnibox_view()->GetBackgroundColor());
|
||||
}
|
||||
|
||||
|
@ -29,12 +29,14 @@ IN_PROC_BROWSER_TEST_F(OmniboxPopupViewWebUITest,
|
||||
|
||||
// Start with the Omnibox unfocused.
|
||||
omnibox_view()->GetFocusManager()->ClearFocus();
|
||||
const SkColor color_before_focus = location_bar()->background()->get_color();
|
||||
const SkColor color_before_focus =
|
||||
location_bar()->GetBackgroundColorForTesting();
|
||||
EXPECT_EQ(color_before_focus, omnibox_view()->GetBackgroundColor());
|
||||
|
||||
// Give the Omnibox focus and get its focused color.
|
||||
omnibox_view()->RequestFocus();
|
||||
const SkColor color_after_focus = location_bar()->background()->get_color();
|
||||
const SkColor color_after_focus =
|
||||
location_bar()->GetBackgroundColorForTesting();
|
||||
|
||||
// Sanity check that the colors are different, otherwise this test will not be
|
||||
// testing anything useful. It is possible that a particular theme could
|
||||
@ -45,14 +47,14 @@ IN_PROC_BROWSER_TEST_F(OmniboxPopupViewWebUITest,
|
||||
|
||||
// The background is hosted in the view that contains the results area.
|
||||
CreatePopupForTestQuery();
|
||||
views::View* background_host = location_bar();
|
||||
EXPECT_EQ(color_after_focus, background_host->background()->get_color());
|
||||
LocationBarView* background_host = location_bar();
|
||||
EXPECT_EQ(color_after_focus, background_host->GetBackgroundColorForTesting());
|
||||
|
||||
omnibox_view()->GetFocusManager()->ClearFocus();
|
||||
|
||||
// Blurring the Omnibox w/ in-progress input (e.g. "foo") should result in
|
||||
// the on-focus colors.
|
||||
EXPECT_EQ(color_after_focus, location_bar()->background()->get_color());
|
||||
EXPECT_EQ(color_after_focus, location_bar()->GetBackgroundColorForTesting());
|
||||
EXPECT_EQ(color_after_focus, omnibox_view()->GetBackgroundColor());
|
||||
}
|
||||
|
||||
|
@ -338,7 +338,7 @@ std::unique_ptr<views::Background> OmniboxResultView::GetPopupCellBackground(
|
||||
const bool prefers_contrast =
|
||||
view->GetNativeTheme() &&
|
||||
view->GetNativeTheme()->UserHasContrastPreference();
|
||||
// TODO(tapted): Consider using background()->SetNativeControlColor() and
|
||||
// TODO(tapted): Consider using background()->SetColor() and
|
||||
// always have a background.
|
||||
if (part_state == OmniboxPartState::NORMAL && !prefers_contrast) {
|
||||
return nullptr;
|
||||
|
@ -271,7 +271,7 @@ TEST_F(PageActionViewWithMockModelTest,
|
||||
page_action_view()->OnPageActionModelChanged(*model());
|
||||
|
||||
ASSERT_NE(page_action_view()->GetBackground(), nullptr);
|
||||
EXPECT_EQ(page_action_view()->GetBackground()->get_color(),
|
||||
EXPECT_EQ(page_action_view()->GetBackground()->color(),
|
||||
page_action_view()->GetColorProvider()->GetColor(
|
||||
kColorOmniboxIconBackgroundTonal));
|
||||
|
||||
|
@ -343,9 +343,16 @@ void PaymentHandlerWebFlowViewController::PopulateSheetHeaderView(
|
||||
origin_label->SetElideBehavior(gfx::ELIDE_HEAD);
|
||||
origin_label->SetID(static_cast<int>(DialogViewID::SHEET_TITLE));
|
||||
origin_label->SetFocusBehavior(views::View::FocusBehavior::ACCESSIBLE_ONLY);
|
||||
// Turn off autoreadability because the computed foreground color takes
|
||||
|
||||
// Turn off auto-readability because the computed foreground color takes
|
||||
// contrast into account.
|
||||
SkColor background_color = container->background()->get_color();
|
||||
SkColor background_color = gfx::kPlaceholderColor;
|
||||
if (container->GetWidget()) {
|
||||
const auto* background = container->background();
|
||||
background_color =
|
||||
background->color().ConvertToSkColor(container->GetColorProvider());
|
||||
}
|
||||
|
||||
// Get the closest label color to kColorPrimaryForeground, with a minimum
|
||||
// readable contrast ratio.
|
||||
SkColor foreground = GetContrastingGoogleColor(
|
||||
@ -524,11 +531,10 @@ PaymentHandlerWebFlowViewController::GetHeaderBackground(
|
||||
auto default_header_background =
|
||||
views::CreateSolidBackground(ui::kColorDialogBackground);
|
||||
if (web_contents() && header_view->GetWidget()) {
|
||||
// Make sure the color is actually set before using it.
|
||||
default_header_background->OnViewThemeChanged(header_view);
|
||||
auto* color_provider = header_view->GetColorProvider();
|
||||
return views::CreateSolidBackground(color_utils::GetResultingPaintColor(
|
||||
web_contents()->GetThemeColor().value_or(SK_ColorTRANSPARENT),
|
||||
default_header_background->get_color()));
|
||||
color_provider->GetColor(ui::kColorDialogBackground)));
|
||||
}
|
||||
return default_header_background;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ class IndicatorDividerBackground : public views::Background {
|
||||
// Background will have right rounded side with |arc_radius|.
|
||||
IndicatorDividerBackground(SkColor color, SkScalar arc_radius)
|
||||
: arc_radius_(arc_radius) {
|
||||
SetNativeControlColor(color);
|
||||
SetColor(color);
|
||||
}
|
||||
|
||||
IndicatorDividerBackground(const IndicatorDividerBackground&) = delete;
|
||||
@ -77,7 +77,7 @@ class IndicatorDividerBackground : public views::Background {
|
||||
cc::PaintFlags flags;
|
||||
flags.setAntiAlias(true);
|
||||
flags.setStyle(cc::PaintFlags::kFill_Style);
|
||||
flags.setColor(get_color());
|
||||
flags.setColor(color().ConvertToSkColor(view->GetColorProvider()));
|
||||
canvas->DrawPath(path, flags);
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,9 @@ namespace arc {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr int kButtonRadius = 12;
|
||||
constexpr int kBorderThicknessDp = 1;
|
||||
|
||||
class RoundedCornerBubbleDialogDelegateView
|
||||
: public views::BubbleDialogDelegateView {
|
||||
METADATA_HEADER(RoundedCornerBubbleDialogDelegateView,
|
||||
@ -113,12 +116,10 @@ ResizeToggleMenu::MenuButtonView::MenuButtonView(PressedCallback callback,
|
||||
ash::TypographyProvider::Get()->StyleLabel(ash::TypographyToken::kCrosButton2,
|
||||
*label);
|
||||
|
||||
constexpr int kBorderThicknessDp = 1;
|
||||
const auto button_radius = 12;
|
||||
SetBorder(views::CreateRoundedRectBorder(kBorderThicknessDp, button_radius,
|
||||
SetBorder(views::CreateRoundedRectBorder(kBorderThicknessDp, kButtonRadius,
|
||||
gfx::kPlaceholderColor));
|
||||
SetBackground(views::CreateRoundedRectBackground(gfx::kPlaceholderColor,
|
||||
button_radius));
|
||||
kButtonRadius));
|
||||
|
||||
const int focus_ring_radius = 16;
|
||||
// With Jellyroll, the ring should have a 4dp gap from the view. Setting a
|
||||
@ -157,30 +158,17 @@ gfx::Size ResizeToggleMenu::MenuButtonView::CalculatePreferredSize(
|
||||
}
|
||||
|
||||
void ResizeToggleMenu::MenuButtonView::UpdateColors() {
|
||||
if (!GetWidget()) {
|
||||
return;
|
||||
}
|
||||
icon_view_->SetImage(ui::ImageModel::FromVectorIcon(
|
||||
*icon_, is_selected_ ? cros_tokens::kCrosSysOnPrimary
|
||||
: cros_tokens::kCrosSysOnSurface));
|
||||
|
||||
const auto* color_provider = GetColorProvider();
|
||||
title_->SetEnabledColor(is_selected_ ? cros_tokens::kCrosSysOnPrimary
|
||||
: cros_tokens::kCrosSysOnSurface);
|
||||
|
||||
const auto icon_color =
|
||||
is_selected_ ? color_provider->GetColor(cros_tokens::kCrosSysOnPrimary)
|
||||
: color_provider->GetColor(cros_tokens::kCrosSysOnSurface);
|
||||
icon_view_->SetImage(ui::ImageModel::FromVectorIcon(*icon_, icon_color));
|
||||
background()->SetColor(is_selected_ ? cros_tokens::kCrosSysPrimary
|
||||
: cros_tokens::kCrosSysSystemOnBase);
|
||||
|
||||
const auto text_color =
|
||||
is_selected_ ? color_provider->GetColor(cros_tokens::kCrosSysOnPrimary)
|
||||
: color_provider->GetColor(cros_tokens::kCrosSysOnSurface);
|
||||
title_->SetEnabledColor(text_color);
|
||||
|
||||
const auto background_color =
|
||||
is_selected_
|
||||
? color_provider->GetColor(cros_tokens::kCrosSysPrimary)
|
||||
: color_provider->GetColor(cros_tokens::kCrosSysSystemOnBase);
|
||||
background()->SetNativeControlColor(background_color);
|
||||
|
||||
const auto border_color = SK_ColorTRANSPARENT;
|
||||
GetBorder()->set_color(border_color);
|
||||
GetBorder()->set_color(SK_ColorTRANSPARENT);
|
||||
}
|
||||
|
||||
BEGIN_METADATA(ResizeToggleMenu, MenuButtonView)
|
||||
|
@ -439,15 +439,6 @@ bool ArcNotificationView::HandleAccessibleAction(
|
||||
return false;
|
||||
}
|
||||
|
||||
void ArcNotificationView::OnThemeChanged() {
|
||||
message_center::MessageView::OnThemeChanged();
|
||||
|
||||
if (content_view_->background()) {
|
||||
background()->SetNativeControlColor(
|
||||
GetColorProvider()->GetColor(cros_tokens::kCrosSysSystemBaseElevated));
|
||||
}
|
||||
}
|
||||
|
||||
void ArcNotificationView::OnItemDestroying() {
|
||||
DCHECK(item_);
|
||||
item_->RemoveObserver(this);
|
||||
|
@ -78,7 +78,6 @@ class ArcNotificationView : public message_center::MessageView,
|
||||
bool OnKeyPressed(const ui::KeyEvent& event) override;
|
||||
void ChildPreferredSizeChanged(View* child) override;
|
||||
bool HandleAccessibleAction(const ui::AXActionData& action) override;
|
||||
void OnThemeChanged() override;
|
||||
|
||||
// ArcNotificationItem::Observer
|
||||
void OnItemDestroying() override;
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include "base/check.h"
|
||||
#include "base/notreached.h"
|
||||
#include "build/build_config.h"
|
||||
#include "cc/paint/paint_flags.h"
|
||||
#include "ui/color/color_id.h"
|
||||
@ -30,7 +31,7 @@ namespace views {
|
||||
// background in a solid color.
|
||||
class SolidBackground : public Background {
|
||||
public:
|
||||
explicit SolidBackground(SkColor color) { SetNativeControlColor(color); }
|
||||
explicit SolidBackground(ui::ColorVariant color) { SetColor(color); }
|
||||
|
||||
SolidBackground(const SolidBackground&) = delete;
|
||||
SolidBackground& operator=(const SolidBackground&) = delete;
|
||||
@ -38,20 +39,28 @@ class SolidBackground : public Background {
|
||||
void Paint(gfx::Canvas* canvas, View* view) const override {
|
||||
// Fill the background. Note that we don't constrain to the bounds as
|
||||
// canvas is already clipped for us.
|
||||
canvas->DrawColor(get_color());
|
||||
canvas->DrawColor(color().ConvertToSkColor(view->GetColorProvider()));
|
||||
}
|
||||
|
||||
void OnViewThemeChanged(View* view) override {
|
||||
if (color().GetColorId()) {
|
||||
view->SchedulePaint();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Shared class for RoundedRectBackground and ThemedRoundedRectBackground.
|
||||
class BaseRoundedRectBackground : public Background {
|
||||
class RoundedRectBackground : public Background {
|
||||
public:
|
||||
BaseRoundedRectBackground(const gfx::RoundedCornersF& radii,
|
||||
int for_border_thickness)
|
||||
: radii_(radii), half_thickness_(for_border_thickness / 2.0f) {}
|
||||
RoundedRectBackground(ui::ColorVariant color,
|
||||
const gfx::RoundedCornersF& radii,
|
||||
int for_border_thickness)
|
||||
: radii_(radii), half_thickness_(for_border_thickness / 2.0f) {
|
||||
SetColor(color);
|
||||
}
|
||||
|
||||
BaseRoundedRectBackground(const BaseRoundedRectBackground&) = delete;
|
||||
BaseRoundedRectBackground& operator=(const BaseRoundedRectBackground&) =
|
||||
delete;
|
||||
RoundedRectBackground(const RoundedRectBackground&) = delete;
|
||||
RoundedRectBackground& operator=(const RoundedRectBackground&) = delete;
|
||||
|
||||
void Paint(gfx::Canvas* canvas, View* view) const override {
|
||||
gfx::Rect rect(view->GetLocalBounds());
|
||||
@ -66,7 +75,7 @@ class BaseRoundedRectBackground : public Background {
|
||||
cc::PaintFlags flags;
|
||||
flags.setAntiAlias(true);
|
||||
flags.setStyle(cc::PaintFlags::kFill_Style);
|
||||
flags.setColor(get_color());
|
||||
flags.setColor(color().ConvertToSkColor(view->GetColorProvider()));
|
||||
canvas->DrawPath(path, flags);
|
||||
}
|
||||
|
||||
@ -74,26 +83,17 @@ class BaseRoundedRectBackground : public Background {
|
||||
return radii_;
|
||||
}
|
||||
|
||||
void OnViewThemeChanged(View* view) override {
|
||||
if (color().GetColorId()) {
|
||||
view->SchedulePaint();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const gfx::RoundedCornersF radii_;
|
||||
const float half_thickness_;
|
||||
};
|
||||
|
||||
// RoundedRectBackground is a filled solid colored background that has
|
||||
// rounded corners.
|
||||
class RoundedRectBackground : public BaseRoundedRectBackground {
|
||||
public:
|
||||
RoundedRectBackground(SkColor color,
|
||||
const gfx::RoundedCornersF& radii,
|
||||
int for_border_thickness)
|
||||
: BaseRoundedRectBackground(radii, for_border_thickness) {
|
||||
SetNativeControlColor(color);
|
||||
}
|
||||
|
||||
RoundedRectBackground(const RoundedRectBackground&) = delete;
|
||||
RoundedRectBackground& operator=(const RoundedRectBackground&) = delete;
|
||||
};
|
||||
|
||||
// ThemedVectorIconBackground is an image drawn on the view's background using
|
||||
// ThemedVectorIcon to react to theme changes.
|
||||
class ThemedVectorIconBackground : public Background {
|
||||
@ -117,52 +117,6 @@ class ThemedVectorIconBackground : public Background {
|
||||
const ui::ThemedVectorIcon icon_;
|
||||
};
|
||||
|
||||
// ThemedSolidBackground is a solid background that stays in sync with a view's
|
||||
// ColorProvider.
|
||||
class ThemedSolidBackground : public SolidBackground {
|
||||
public:
|
||||
explicit ThemedSolidBackground(ui::ColorId color_id)
|
||||
: SolidBackground(gfx::kPlaceholderColor), color_id_(color_id) {}
|
||||
|
||||
ThemedSolidBackground(const ThemedSolidBackground&) = delete;
|
||||
ThemedSolidBackground& operator=(const ThemedSolidBackground&) = delete;
|
||||
|
||||
~ThemedSolidBackground() override = default;
|
||||
|
||||
void OnViewThemeChanged(View* view) override {
|
||||
SetNativeControlColor(view->GetColorProvider()->GetColor(color_id_));
|
||||
view->SchedulePaint();
|
||||
}
|
||||
|
||||
private:
|
||||
const ui::ColorId color_id_;
|
||||
};
|
||||
|
||||
// ThemedRoundedRectBackground is a solid rounded rect background that stays in
|
||||
// sync with a view's ColorProvider.
|
||||
class ThemedRoundedRectBackground : public BaseRoundedRectBackground {
|
||||
public:
|
||||
ThemedRoundedRectBackground(ui::ColorId color_id,
|
||||
const gfx::RoundedCornersF& radii,
|
||||
int for_border_thickness)
|
||||
: BaseRoundedRectBackground(radii, for_border_thickness),
|
||||
color_id_(color_id) {}
|
||||
|
||||
ThemedRoundedRectBackground(const ThemedRoundedRectBackground&) = delete;
|
||||
ThemedRoundedRectBackground& operator=(const ThemedRoundedRectBackground&) =
|
||||
delete;
|
||||
|
||||
~ThemedRoundedRectBackground() override = default;
|
||||
|
||||
void OnViewThemeChanged(View* view) override {
|
||||
SetNativeControlColor(view->GetColorProvider()->GetColor(color_id_));
|
||||
view->SchedulePaint();
|
||||
}
|
||||
|
||||
private:
|
||||
const ui::ColorId color_id_;
|
||||
};
|
||||
|
||||
class BackgroundPainter : public Background {
|
||||
public:
|
||||
explicit BackgroundPainter(std::unique_ptr<Painter> painter)
|
||||
@ -179,6 +133,11 @@ class BackgroundPainter : public Background {
|
||||
Painter::PaintPainterAt(canvas, painter_.get(), view->GetLocalBounds());
|
||||
}
|
||||
|
||||
void SetColor(ui::ColorVariant color) override {
|
||||
NOTREACHED() << "It does not make sense to `SetColor()` for a painter "
|
||||
"based background.";
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<Painter> painter_;
|
||||
};
|
||||
@ -187,7 +146,7 @@ Background::Background() = default;
|
||||
|
||||
Background::~Background() = default;
|
||||
|
||||
void Background::SetNativeControlColor(SkColor color) {
|
||||
void Background::SetColor(ui::ColorVariant color) {
|
||||
color_ = color;
|
||||
}
|
||||
|
||||
@ -202,11 +161,7 @@ std::optional<gfx::RoundedCornersF> Background::GetRoundedCornerRadii() const {
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::unique_ptr<Background> CreateSolidBackground(ui::ColorVariant color) {
|
||||
if (auto color_id = color.GetColorId()) {
|
||||
return std::make_unique<ThemedSolidBackground>(*color_id);
|
||||
}
|
||||
|
||||
return std::make_unique<SolidBackground>(*color.GetSkColor());
|
||||
return std::make_unique<SolidBackground>(color);
|
||||
}
|
||||
|
||||
std::unique_ptr<Background> CreateRoundedRectBackground(
|
||||
@ -239,12 +194,7 @@ std::unique_ptr<Background> CreateRoundedRectBackground(
|
||||
return CreateSolidBackground(color);
|
||||
}
|
||||
|
||||
if (auto color_id = color.GetColorId()) {
|
||||
return std::make_unique<ThemedRoundedRectBackground>(*color_id, radii,
|
||||
for_border_thickness);
|
||||
}
|
||||
|
||||
return std::make_unique<RoundedRectBackground>(*color.GetSkColor(), radii,
|
||||
return std::make_unique<RoundedRectBackground>(color, radii,
|
||||
for_border_thickness);
|
||||
}
|
||||
|
||||
|
@ -54,10 +54,6 @@ class VIEWS_EXPORT Background {
|
||||
// Render the background for the provided view
|
||||
virtual void Paint(gfx::Canvas* canvas, View* view) const = 0;
|
||||
|
||||
// Set a solid, opaque color to be used when drawing backgrounds of native
|
||||
// controls. Unfortunately alpha=0 is not an option.
|
||||
void SetNativeControlColor(SkColor color);
|
||||
|
||||
// This is called by the View on which it is attached. This is overridden for
|
||||
// subclasses that depend on theme colors.
|
||||
virtual void OnViewThemeChanged(View* view);
|
||||
@ -66,14 +62,17 @@ class VIEWS_EXPORT Background {
|
||||
// by default.
|
||||
virtual std::optional<gfx::RoundedCornersF> GetRoundedCornerRadii() const;
|
||||
|
||||
// Returns the "background color". This is equivalent to the color set in
|
||||
// SetNativeControlColor(). For solid backgrounds, this is the color; for
|
||||
// gradient backgrounds, it's the midpoint of the gradient; for painter
|
||||
// backgrounds, this is not useful (returns a default color).
|
||||
SkColor get_color() const { return color_; }
|
||||
// Returns the "background color". After resolution, this color is the color
|
||||
// for solid backgrounds; for gradient backgrounds, it's the midpoint of the
|
||||
// gradient; for painter backgrounds, this is not useful (returns a default
|
||||
// color).
|
||||
ui::ColorVariant color() const { return color_; }
|
||||
|
||||
// Set a solid color to be used when drawing backgrounds.
|
||||
virtual void SetColor(ui::ColorVariant color);
|
||||
|
||||
private:
|
||||
SkColor color_ = gfx::kPlaceholderColor;
|
||||
ui::ColorVariant color_;
|
||||
};
|
||||
|
||||
// Creates a background that fills the canvas in the specified color.
|
||||
|
@ -25,9 +25,8 @@ namespace {
|
||||
// A solid color background where the bottom two corners are rounded.
|
||||
class HalfRoundedRectBackground : public Background {
|
||||
public:
|
||||
explicit HalfRoundedRectBackground(SkColor color, float radius)
|
||||
: radius_(radius) {
|
||||
SetNativeControlColor(color);
|
||||
HalfRoundedRectBackground(SkColor color, float radius) : radius_(radius) {
|
||||
SetColor(color);
|
||||
}
|
||||
|
||||
HalfRoundedRectBackground() = delete;
|
||||
@ -42,7 +41,7 @@ class HalfRoundedRectBackground : public Background {
|
||||
cc::PaintFlags flags;
|
||||
flags.setAntiAlias(true);
|
||||
flags.setStyle(cc::PaintFlags::kFill_Style);
|
||||
flags.setColor(get_color());
|
||||
flags.setColor(color().ConvertToSkColor(view->GetColorProvider()));
|
||||
// Draw a rounded rect that spills outside of the clipping area, so that the
|
||||
// rounded corners only show in the bottom 2 corners.
|
||||
gfx::RectF spilling_rect(view->GetLocalBounds());
|
||||
|
@ -13,9 +13,11 @@
|
||||
|
||||
#include <tuple>
|
||||
|
||||
#include "base/check.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "ui/color/color_provider.h"
|
||||
#include "ui/events/test/event_generator.h"
|
||||
#include "ui/views/background.h"
|
||||
#include "ui/views/color_chooser/color_chooser_listener.h"
|
||||
@ -85,9 +87,11 @@ class ColorChooserTest : public views::ViewsTestBase {
|
||||
}
|
||||
|
||||
SkColor GetShownColor() const {
|
||||
CHECK(widget_);
|
||||
return chooser_->selected_color_patch_for_testing()
|
||||
->background()
|
||||
->get_color();
|
||||
->color()
|
||||
.ConvertToSkColor(widget_->GetColorProvider());
|
||||
}
|
||||
|
||||
SkColor GetTextualColor() const {
|
||||
|
@ -428,7 +428,7 @@ void SelectedColorPatchView::SetColor(SkColor color) {
|
||||
if (!background()) {
|
||||
SetBackground(CreateSolidBackground(color));
|
||||
} else {
|
||||
background()->SetNativeControlColor(color);
|
||||
background()->SetColor(color);
|
||||
}
|
||||
SchedulePaint();
|
||||
}
|
||||
|
@ -931,9 +931,12 @@ void Label::PaintText(gfx::Canvas* canvas) {
|
||||
// This is our approximation of being painted on an opaque region. If any
|
||||
// parent has an opaque background we assume that that background covers the
|
||||
// text bounds. This is not necessarily true as the background could be
|
||||
// inset from the parent bounds, and get_color() does not imply that all of
|
||||
// inset from the parent bounds, and color() does not imply that all of
|
||||
// the background is painted with the same opaque color.
|
||||
if (view->background() && IsOpaque(view->background()->get_color())) {
|
||||
const auto* background = view->background();
|
||||
auto* color_provider = view->GetColorProvider();
|
||||
if (background && color_provider &&
|
||||
IsOpaque(background->color().ConvertToSkColor(color_provider))) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@ -1314,8 +1315,9 @@ TEST_F(LabelTest, GetSubstringBounds) {
|
||||
#endif
|
||||
// Ensures DCHECK for subpixel rendering on transparent layer is working.
|
||||
TEST_F(LabelTest, MAYBE_ChecksSubpixelRenderingOntoOpaqueSurface) {
|
||||
View view;
|
||||
Label* label = view.AddChildView(std::make_unique<TestLabel>());
|
||||
View* view =
|
||||
widget()->GetContentsView()->AddChildView(std::make_unique<View>());
|
||||
Label* label = view->AddChildView(std::make_unique<TestLabel>());
|
||||
EXPECT_TRUE(label->GetSubpixelRenderingEnabled());
|
||||
|
||||
gfx::Canvas canvas;
|
||||
@ -1324,11 +1326,11 @@ TEST_F(LabelTest, MAYBE_ChecksSubpixelRenderingOntoOpaqueSurface) {
|
||||
label->OnPaint(&canvas);
|
||||
|
||||
// Painting to an opaque layer should also be fine.
|
||||
view.SetPaintToLayer();
|
||||
view->SetPaintToLayer();
|
||||
label->OnPaint(&canvas);
|
||||
|
||||
// Set up a transparent layer for the parent view.
|
||||
view.layer()->SetFillsBoundsOpaquely(false);
|
||||
view->layer()->SetFillsBoundsOpaquely(false);
|
||||
|
||||
// Painting on a transparent layer should DCHECK.
|
||||
EXPECT_DCHECK_DEATH(label->OnPaint(&canvas));
|
||||
@ -1340,7 +1342,7 @@ TEST_F(LabelTest, MAYBE_ChecksSubpixelRenderingOntoOpaqueSurface) {
|
||||
|
||||
// Painting onto a transparent layer should not DCHECK if there's an opaque
|
||||
// background in a parent of the Label.
|
||||
view.SetBackground(CreateSolidBackground(SK_ColorWHITE));
|
||||
view->SetBackground(CreateSolidBackground(SK_ColorWHITE));
|
||||
label->OnPaint(&canvas);
|
||||
}
|
||||
|
||||
|
@ -104,8 +104,10 @@ void TooltipViewAura::OnThemeChanged() {
|
||||
views::View::OnThemeChanged();
|
||||
// Force the text color to be readable when |background_color| is not
|
||||
// opaque.
|
||||
const SkColor background_color =
|
||||
background()->color().ConvertToSkColor(GetColorProvider());
|
||||
render_text_->set_subpixel_rendering_suppressed(
|
||||
SkColorGetA(background()->get_color()) != SK_AlphaOPAQUE);
|
||||
SkColorGetA(background_color) != SK_AlphaOPAQUE);
|
||||
render_text_->SetColor(
|
||||
GetColorProvider()->GetColor(ui::kColorTooltipForeground));
|
||||
}
|
||||
|
@ -13,8 +13,8 @@
|
||||
|
||||
std::u16string ui::metadata::TypeConverter<views::Background>::ToString(
|
||||
const views::Background& source_value) {
|
||||
return ui::metadata::TypeConverter<SkColor>::ToString(
|
||||
source_value.get_color());
|
||||
return ui::metadata::TypeConverter<ui::ColorVariant>::ToString(
|
||||
source_value.color());
|
||||
}
|
||||
|
||||
std::u16string ui::metadata::TypeConverter<views::Border>::ToString(
|
||||
|
Reference in New Issue
Block a user