Commit 33eaef93 authored by chinsenj's avatar chinsenj Committed by Commit Bot

cros: Make folder and desk rename textfields handle light/dark mode.

This CL changes hardcoded values to use their respective color
providers, allowing them to handle light/dark mode.

Test: manual
Bug: 1127498
Change-Id: I81b7a877dc0aff37d2fe080e6ee15ff73c094704
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2444489
Commit-Queue: Jeremy Chinsen <chinsenj@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813291}
parent 8ddf74f6
...@@ -125,6 +125,19 @@ SkColor AppListColorProviderImpl::GetFolderNameBackgroundColor( ...@@ -125,6 +125,19 @@ SkColor AppListColorProviderImpl::GetFolderNameBackgroundColor(
ripple_attributes.inkdrop_opacity * 255); ripple_attributes.inkdrop_opacity * 255);
} }
SkColor AppListColorProviderImpl::GetFolderNameBorderColor(bool active) const {
if (!active)
return SK_ColorTRANSPARENT;
return ash_color_provider_->GetControlsLayerColor(
AshColorProvider::ControlsLayerType::kFocusRingColor);
}
SkColor AppListColorProviderImpl::GetFolderNameSelectionColor() const {
return ash_color_provider_->GetControlsLayerColor(
AshColorProvider::ControlsLayerType::kFocusAuraColor);
}
SkColor AppListColorProviderImpl::GetContentsBackgroundColor() const { SkColor AppListColorProviderImpl::GetContentsBackgroundColor() const {
return ash_color_provider_->GetControlsLayerColor( return ash_color_provider_->GetControlsLayerColor(
AshColorProvider::ControlsLayerType::kControlBackgroundColorInactive); AshColorProvider::ControlsLayerType::kControlBackgroundColorInactive);
......
...@@ -36,6 +36,8 @@ class AppListColorProviderImpl : public AppListColorProvider { ...@@ -36,6 +36,8 @@ class AppListColorProviderImpl : public AppListColorProvider {
SkColor GetFolderTitleTextColor() const override; SkColor GetFolderTitleTextColor() const override;
SkColor GetFolderHintTextColor() const override; SkColor GetFolderHintTextColor() const override;
SkColor GetFolderNameBackgroundColor(bool active) const override; SkColor GetFolderNameBackgroundColor(bool active) const override;
SkColor GetFolderNameBorderColor(bool active) const override;
SkColor GetFolderNameSelectionColor() const override;
SkColor GetContentsBackgroundColor() const override; SkColor GetContentsBackgroundColor() const override;
SkColor GetSeparatorColor() const override; SkColor GetSeparatorColor() const override;
SkColor GetSearchResultViewHighlightColor() const override; SkColor GetSearchResultViewHighlightColor() const override;
......
...@@ -92,6 +92,17 @@ SkColor TestAppListColorProvider::GetFolderNameBackgroundColor( ...@@ -92,6 +92,17 @@ SkColor TestAppListColorProvider::GetFolderNameBackgroundColor(
return SkColorSetA(SK_ColorBLACK, 0x0F); return SkColorSetA(SK_ColorBLACK, 0x0F);
} }
SkColor TestAppListColorProvider::GetFolderNameBorderColor(bool active) const {
if (!active)
return SK_ColorTRANSPARENT;
return SkColorSetA(SK_ColorBLACK, 0x0F);
}
SkColor TestAppListColorProvider::GetFolderNameSelectionColor() const {
return SkColorSetA(SK_ColorBLACK, 0x0F);
}
SkColor TestAppListColorProvider::GetContentsBackgroundColor() const { SkColor TestAppListColorProvider::GetContentsBackgroundColor() const {
return gfx::kGoogleGrey200; return gfx::kGoogleGrey200;
} }
......
...@@ -36,6 +36,8 @@ class TestAppListColorProvider : public AppListColorProvider { ...@@ -36,6 +36,8 @@ class TestAppListColorProvider : public AppListColorProvider {
SkColor GetFolderTitleTextColor() const override; SkColor GetFolderTitleTextColor() const override;
SkColor GetFolderHintTextColor() const override; SkColor GetFolderHintTextColor() const override;
SkColor GetFolderNameBackgroundColor(bool active) const override; SkColor GetFolderNameBackgroundColor(bool active) const override;
SkColor GetFolderNameBorderColor(bool active) const override;
SkColor GetFolderNameSelectionColor() const override;
SkColor GetContentsBackgroundColor() const override; SkColor GetContentsBackgroundColor() const override;
SkColor GetSeparatorColor() const override; SkColor GetSeparatorColor() const override;
SkColor GetSearchResultViewHighlightColor() const override; SkColor GetSearchResultViewHighlightColor() const override;
......
...@@ -40,10 +40,8 @@ class FolderHeaderView::FolderNameView : public views::Textfield, ...@@ -40,10 +40,8 @@ class FolderHeaderView::FolderNameView : public views::Textfield,
// Make folder name font size 14px. // Make folder name font size 14px.
SetFontList( SetFontList(
ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta(2)); ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta(2));
SetTextColor(AppListColorProvider::Get()->GetFolderTitleTextColor());
set_placeholder_text_color( set_placeholder_text_color(
AppListColorProvider::Get()->GetFolderHintTextColor()); AppListColorProvider::Get()->GetFolderHintTextColor());
SetNameViewBorderAndBackground(/*is_active=*/false);
SetEventTargeter(std::make_unique<views::ViewTargeter>(this)); SetEventTargeter(std::make_unique<views::ViewTargeter>(this));
} }
...@@ -54,18 +52,31 @@ class FolderHeaderView::FolderNameView : public views::Textfield, ...@@ -54,18 +52,31 @@ class FolderHeaderView::FolderNameView : public views::Textfield,
AppListConfig::instance().folder_header_height()); AppListConfig::instance().folder_header_height());
} }
void OnThemeChanged() override {
Textfield::OnThemeChanged();
const bool is_active = has_mouse_already_entered_ || HasFocus();
AppListColorProvider* color_provider = AppListColorProvider::Get();
SetBackground(views::CreateRoundedRectBackground(
color_provider->GetFolderNameBackgroundColor(is_active),
AppListConfig::instance().folder_name_border_radius()));
const SkColor text_color = color_provider->GetFolderTitleTextColor();
SetTextColor(text_color);
SetSelectionTextColor(text_color);
SetSelectionBackgroundColor(color_provider->GetFolderNameSelectionColor());
SetNameViewBorderAndBackground(is_active);
}
void SetNameViewBorderAndBackground(bool is_active) { void SetNameViewBorderAndBackground(bool is_active) {
int horizontal_padding = AppListConfig::instance().folder_name_padding(); int horizontal_padding = AppListConfig::instance().folder_name_padding();
SetBorder(views::CreatePaddedBorder( SetBorder(views::CreatePaddedBorder(
views::CreateRoundedRectBorder( views::CreateRoundedRectBorder(
AppListConfig::instance().folder_name_border_thickness(), AppListConfig::instance().folder_name_border_thickness(),
AppListConfig::instance().folder_name_border_radius(), AppListConfig::instance().folder_name_border_radius(),
is_active ? AppListConfig::instance().folder_name_border_color() AppListColorProvider::Get()->GetFolderNameBorderColor(is_active)),
: SK_ColorTRANSPARENT),
gfx::Insets(0, horizontal_padding))); gfx::Insets(0, horizontal_padding)));
UpdateBackgroundColor(is_active);
SetBackgroundColor(
AppListColorProvider::Get()->GetFolderNameBackgroundColor(is_active));
} }
void OnFocus() override { void OnFocus() override {
...@@ -126,11 +137,8 @@ class FolderHeaderView::FolderNameView : public views::Textfield, ...@@ -126,11 +137,8 @@ class FolderHeaderView::FolderNameView : public views::Textfield,
} }
void OnMouseExited(const ui::MouseEvent& event) override { void OnMouseExited(const ui::MouseEvent& event) override {
if (!HasFocus()) { if (!HasFocus())
SetBackgroundColor( UpdateBackgroundColor(/*is_active=*/false);
AppListColorProvider::Get()->GetFolderNameBackgroundColor(
/*is_active=*/false));
}
has_mouse_already_entered_ = false; has_mouse_already_entered_ = false;
} }
...@@ -139,18 +147,13 @@ class FolderHeaderView::FolderNameView : public views::Textfield, ...@@ -139,18 +147,13 @@ class FolderHeaderView::FolderNameView : public views::Textfield,
if (DoesMouseEventActuallyIntersect(event) && !has_mouse_already_entered_) { if (DoesMouseEventActuallyIntersect(event) && !has_mouse_already_entered_) {
// If this is reached, the mouse is entering the view. // If this is reached, the mouse is entering the view.
// Recreate border to have custom corner radius. // Recreate border to have custom corner radius.
SetBackground(views::CreateRoundedRectBackground( UpdateBackgroundColor(/*is_active=*/true);
AppListColorProvider::Get()->GetFolderNameBackgroundColor(
/*is_active=*/true),
AppListConfig::instance().folder_name_border_radius()));
has_mouse_already_entered_ = true; has_mouse_already_entered_ = true;
} else if (!DoesMouseEventActuallyIntersect(event) && } else if (!DoesMouseEventActuallyIntersect(event) &&
has_mouse_already_entered_ && !HasFocus()) { has_mouse_already_entered_ && !HasFocus()) {
// If this is reached, the mouse is exiting the view on its horizontal // If this is reached, the mouse is exiting the view on its horizontal
// edges. // edges.
SetBackgroundColor( UpdateBackgroundColor(/*is_active=*/false);
AppListColorProvider::Get()->GetFolderNameBackgroundColor(
/*is_active=*/false));
has_mouse_already_entered_ = false; has_mouse_already_entered_ = false;
} }
} }
...@@ -183,6 +186,12 @@ class FolderHeaderView::FolderNameView : public views::Textfield, ...@@ -183,6 +186,12 @@ class FolderHeaderView::FolderNameView : public views::Textfield,
} }
private: private:
void UpdateBackgroundColor(bool is_active) {
background()->SetNativeControlColor(
AppListColorProvider::Get()->GetFolderNameBackgroundColor(is_active));
SchedulePaint();
}
// The parent FolderHeaderView, owns this. // The parent FolderHeaderView, owns this.
FolderHeaderView* folder_header_view_; FolderHeaderView* folder_header_view_;
......
...@@ -35,6 +35,8 @@ class ASH_PUBLIC_EXPORT AppListColorProvider { ...@@ -35,6 +35,8 @@ class ASH_PUBLIC_EXPORT AppListColorProvider {
virtual SkColor GetFolderTitleTextColor() const = 0; virtual SkColor GetFolderTitleTextColor() const = 0;
virtual SkColor GetFolderHintTextColor() const = 0; virtual SkColor GetFolderHintTextColor() const = 0;
virtual SkColor GetFolderNameBackgroundColor(bool active) const = 0; virtual SkColor GetFolderNameBackgroundColor(bool active) const = 0;
virtual SkColor GetFolderNameBorderColor(bool active) const = 0;
virtual SkColor GetFolderNameSelectionColor() const = 0;
virtual SkColor GetContentsBackgroundColor() const = 0; virtual SkColor GetContentsBackgroundColor() const = 0;
virtual SkColor GetSeparatorColor() const = 0; virtual SkColor GetSeparatorColor() const = 0;
virtual SkColor GetSearchResultViewHighlightColor() const = 0; virtual SkColor GetSearchResultViewHighlightColor() const = 0;
......
...@@ -300,7 +300,6 @@ AppListConfig::AppListConfig(AppListConfigType type) ...@@ -300,7 +300,6 @@ AppListConfig::AppListConfig(AppListConfigType type)
folder_name_border_radius_(4), folder_name_border_radius_(4),
folder_name_border_thickness_(2), folder_name_border_thickness_(2),
folder_name_padding_(8), folder_name_padding_(8),
folder_name_border_color_(gfx::kGoogleBlue600),
folder_icon_dimension_(FolderClippedIconDimensionForType(type)), folder_icon_dimension_(FolderClippedIconDimensionForType(type)),
folder_unclipped_icon_dimension_( folder_unclipped_icon_dimension_(
FolderUnclippedIconDimensionForType(type)), FolderUnclippedIconDimensionForType(type)),
...@@ -431,7 +430,6 @@ AppListConfig::AppListConfig(const AppListConfig& base_config, ...@@ -431,7 +430,6 @@ AppListConfig::AppListConfig(const AppListConfig& base_config,
folder_name_border_radius_(base_config.folder_name_border_radius_), folder_name_border_radius_(base_config.folder_name_border_radius_),
folder_name_border_thickness_(base_config.folder_name_border_thickness_), folder_name_border_thickness_(base_config.folder_name_border_thickness_),
folder_name_padding_(base_config.folder_name_padding_), folder_name_padding_(base_config.folder_name_padding_),
folder_name_border_color_(base_config.folder_name_border_color_),
folder_icon_dimension_(MinScale(base_config.folder_icon_dimension_, folder_icon_dimension_(MinScale(base_config.folder_icon_dimension_,
scale_x, scale_x,
inner_tile_scale_y)), inner_tile_scale_y)),
......
...@@ -126,7 +126,6 @@ class ASH_PUBLIC_EXPORT AppListConfig { ...@@ -126,7 +126,6 @@ class ASH_PUBLIC_EXPORT AppListConfig {
return folder_name_border_thickness_; return folder_name_border_thickness_;
} }
int folder_name_padding() const { return folder_name_padding_; } int folder_name_padding() const { return folder_name_padding_; }
SkColor folder_name_border_color() const { return folder_name_border_color_; }
int folder_icon_dimension() const { return folder_icon_dimension_; } int folder_icon_dimension() const { return folder_icon_dimension_; }
int folder_unclipped_icon_dimension() const { int folder_unclipped_icon_dimension() const {
return folder_unclipped_icon_dimension_; return folder_unclipped_icon_dimension_;
...@@ -401,9 +400,6 @@ class ASH_PUBLIC_EXPORT AppListConfig { ...@@ -401,9 +400,6 @@ class ASH_PUBLIC_EXPORT AppListConfig {
// The inner padding for folder name. // The inner padding for folder name.
const int folder_name_padding_; const int folder_name_padding_;
// The color of the folder name border.
const SkColor folder_name_border_color_;
// The icon dimension of folder. // The icon dimension of folder.
const int folder_icon_dimension_; const int folder_icon_dimension_;
......
...@@ -148,6 +148,7 @@ SkColor AshColorProvider::GetControlsLayerColor(ControlsLayerType type) const { ...@@ -148,6 +148,7 @@ SkColor AshColorProvider::GetControlsLayerColor(ControlsLayerType type) const {
gfx::kGoogleRed600, gfx::kGoogleRed600,
gfx::kGoogleYellow600, gfx::kGoogleYellow600,
gfx::kGoogleGreen600, gfx::kGoogleGreen600,
SkColorSetA(gfx::kGoogleBlue600, 0x3D),
gfx::kGoogleBlue600}; gfx::kGoogleBlue600};
constexpr SkColor kDarkColors[] = {SkColorSetA(SK_ColorWHITE, 0x24), constexpr SkColor kDarkColors[] = {SkColorSetA(SK_ColorWHITE, 0x24),
gfx::kGoogleBlue300, gfx::kGoogleBlue300,
...@@ -155,6 +156,7 @@ SkColor AshColorProvider::GetControlsLayerColor(ControlsLayerType type) const { ...@@ -155,6 +156,7 @@ SkColor AshColorProvider::GetControlsLayerColor(ControlsLayerType type) const {
gfx::kGoogleRed300, gfx::kGoogleRed300,
gfx::kGoogleYellow300, gfx::kGoogleYellow300,
gfx::kGoogleGreen300, gfx::kGoogleGreen300,
SkColorSetA(gfx::kGoogleBlue300, 0x3D),
gfx::kGoogleBlue300}; gfx::kGoogleBlue300};
DCHECK(base::size(kLightColors) == base::size(kDarkColors)); DCHECK(base::size(kLightColors) == base::size(kDarkColors));
static_assert( static_assert(
......
...@@ -74,6 +74,7 @@ class ASH_EXPORT AshColorProvider : public SessionObserver { ...@@ -74,6 +74,7 @@ class ASH_EXPORT AshColorProvider : public SessionObserver {
kControlBackgroundColorAlert, kControlBackgroundColorAlert,
kControlBackgroundColorWarning, kControlBackgroundColorWarning,
kControlBackgroundColorPositive, kControlBackgroundColorPositive,
kFocusAuraColor,
kFocusRingColor, kFocusRingColor,
}; };
......
...@@ -52,16 +52,6 @@ DeskNameView::DeskNameView() { ...@@ -52,16 +52,6 @@ DeskNameView::DeskNameView() {
border_ptr_ = border.get(); border_ptr_ = border.get();
SetBorder(std::move(border)); SetBorder(std::move(border));
const SkColor text_color = AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kTextColorPrimary);
SetTextColor(text_color);
SetSelectionTextColor(text_color);
const SkColor selection_color =
AshColorProvider::Get()->GetControlsLayerColor(
AshColorProvider::ControlsLayerType::kFocusRingColor);
SetSelectionBackgroundColor(selection_color);
SetCursorEnabled(true); SetCursorEnabled(true);
SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_CENTER); SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_CENTER);
} }
...@@ -137,8 +127,19 @@ void DeskNameView::OnMouseExited(const ui::MouseEvent& event) { ...@@ -137,8 +127,19 @@ void DeskNameView::OnMouseExited(const ui::MouseEvent& event) {
void DeskNameView::OnThemeChanged() { void DeskNameView::OnThemeChanged() {
Textfield::OnThemeChanged(); Textfield::OnThemeChanged();
SetBackground(views::CreateRoundedRectBackground(GetBackgroundColor(), SetBackground(views::CreateRoundedRectBackground(GetBackgroundColor(),
kDeskNameViewBorderRadius)); kDeskNameViewBorderRadius));
AshColorProvider* color_provider = AshColorProvider::Get();
const SkColor text_color = color_provider->GetContentLayerColor(
AshColorProvider::ContentLayerType::kTextColorPrimary);
SetTextColor(text_color);
SetSelectionTextColor(text_color);
const SkColor selection_color = color_provider->GetControlsLayerColor(
AshColorProvider::ControlsLayerType::kFocusAuraColor);
SetSelectionBackgroundColor(selection_color);
} }
views::View* DeskNameView::GetView() { views::View* DeskNameView::GetView() {
......
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