Skip to content

Commit

Permalink
Move ColorProviderManager::Key into its own header
Browse files Browse the repository at this point in the history
Many includes of color_provider_manager.h just need one of the types and
not the manager itself. Separate the Key types and declaration into its
own compilation units.

This allows targets to set ColorProviderKey values without depending
on the entirety of ui/color.

Bug: b:286952053
Change-Id: I8416bc3bd40b1352cc0b3d9cbab42648256c9c42
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4609702
Reviewed-by: Ricky Liang <jcliang@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Sean Kau <skau@chromium.org>
Reviewed-by: Alexander Timin <altimin@chromium.org>
Reviewed-by: Thomas Lukaszewicz <tluk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1158531}
  • Loading branch information
Sean Kau authored and Chromium LUCI CQ committed Jun 15, 2023
1 parent aef68ae commit fedf27f
Show file tree
Hide file tree
Showing 115 changed files with 639 additions and 623 deletions.
3 changes: 1 addition & 2 deletions ash/components/arc/system_ui/arc_system_ui_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ void ArcSystemUIBridge::OnColorPaletteChanging(
previous_seed_.emplace(seed);

if (!old_previous || seed.color_mode != old_previous->color_mode) {
bool dark_theme =
seed.color_mode == ui::ColorProviderManager::ColorMode::kDark;
bool dark_theme = seed.color_mode == ui::ColorProviderKey::ColorMode::kDark;
if (!SendDeviceDarkThemeState(dark_theme)) {
LOG(ERROR) << "Failed to send theme status of: " << dark_theme;
return;
Expand Down
8 changes: 4 additions & 4 deletions ash/components/arc/system_ui/arc_system_ui_bridge_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ TEST_F(ArcSystemUIBridgeTest, DestroyColorPaletteControllerFirst) {
TEST_F(ArcSystemUIBridgeTest, OnColorModeChanged) {
EXPECT_FALSE(system_ui_instance_.dark_theme_status());
ash::ColorPaletteSeed seed;
seed.color_mode = ui::ColorProviderManager::ColorMode::kDark;
seed.color_mode = ui::ColorProviderKey::ColorMode::kDark;
bridge_->OnColorPaletteChanging(seed);
EXPECT_TRUE(system_ui_instance_.dark_theme_status());
ArcServiceManager::Get()->arc_bridge_service()->system_ui()->CloseInstance(
&system_ui_instance_);
EXPECT_ERROR_LOG(testing::HasSubstr("Failed to send theme status"));
log_.StartCapturingLogs();
seed.color_mode = ui::ColorProviderManager::ColorMode::kLight;
seed.color_mode = ui::ColorProviderKey::ColorMode::kLight;
bridge_->OnColorPaletteChanging(seed);
}

Expand All @@ -149,7 +149,7 @@ TEST_F(ArcSystemUIBridgeTest, OnConnectionReady) {

EXPECT_FALSE(system_ui_instance_.dark_theme_status());
ash::ColorPaletteSeed seed;
seed.color_mode = ui::ColorProviderManager::ColorMode::kDark;
seed.color_mode = ui::ColorProviderKey::ColorMode::kDark;
seed.scheme = ash::ColorScheme::kVibrant;
seed.seed_color = SK_ColorMAGENTA;
test_palette_->SetSeed(seed);
Expand Down Expand Up @@ -193,7 +193,7 @@ TEST_F(ArcSystemUIBridgeTest, OnConnectionReady_NeutralToSpritzConversion) {

EXPECT_FALSE(system_ui_instance_.dark_theme_status());
ash::ColorPaletteSeed seed;
seed.color_mode = ui::ColorProviderManager::ColorMode::kLight;
seed.color_mode = ui::ColorProviderKey::ColorMode::kLight;
seed.scheme = ash::ColorScheme::kNeutral;
seed.seed_color = SK_ColorCYAN;
test_palette_->SetSeed(seed);
Expand Down
26 changes: 12 additions & 14 deletions ash/style/ash_color_mixer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "ui/color/color_id.h"
#include "ui/color/color_mixer.h"
#include "ui/color/color_provider.h"
#include "ui/color/color_provider_key.h"
#include "ui/color/color_recipe.h"
#include "ui/color/color_transform.h"
#include "ui/gfx/color_palette.h"
Expand All @@ -40,7 +41,7 @@ constexpr int kSecondToneOpacity = SK_AlphaOPAQUE * 0.3f;
constexpr int kDisabledColorOpacity = SK_AlphaOPAQUE * 0.38f;

void AddShieldAndBaseColors(ui::ColorMixer& mixer,
const ui::ColorProviderManager::Key& key) {
const ui::ColorProviderKey& key) {
if (chromeos::features::IsJellyEnabled()) {
// Generally, shield and base colors are cros.sys.sys-base-elevated. That
// is cros.sys.surface3 @ 90%. So, map all shield colors to surface3 and
Expand All @@ -64,7 +65,7 @@ void AddShieldAndBaseColors(ui::ColorMixer& mixer,
}

const bool use_dark_color =
key.color_mode == ui::ColorProviderManager::ColorMode::kDark;
key.color_mode == ui::ColorProviderKey::ColorMode::kDark;

// Colors of the Shield and Base layers.
const SkColor default_background_color =
Expand All @@ -90,10 +91,9 @@ void AddShieldAndBaseColors(ui::ColorMixer& mixer,
}

// Mappings of Controls Colors for Material 2.
void AddControlsColors(ui::ColorMixer& mixer,
const ui::ColorProviderManager::Key& key) {
void AddControlsColors(ui::ColorMixer& mixer, const ui::ColorProviderKey& key) {
const bool use_dark_color =
key.color_mode == ui::ColorProviderManager::ColorMode::kDark;
key.color_mode == ui::ColorProviderKey::ColorMode::kDark;

// ControlsLayer colors
mixer[kColorAshHairlineBorderColor] =
Expand All @@ -115,10 +115,9 @@ void AddControlsColors(ui::ColorMixer& mixer,
}

// Mappings the Content layer colors for Material 2.
void AddContentColors(ui::ColorMixer& mixer,
const ui::ColorProviderManager::Key& key) {
void AddContentColors(ui::ColorMixer& mixer, const ui::ColorProviderKey& key) {
const bool use_dark_color =
key.color_mode == ui::ColorProviderManager::ColorMode::kDark;
key.color_mode == ui::ColorProviderKey::ColorMode::kDark;

// ContentLayer colors.
mixer[kColorAshScrollBarColor] =
Expand Down Expand Up @@ -364,8 +363,7 @@ void RemapLegacySemanticColors(ui::ColorMixer& mixer) {

// Adds the dynamic color palette tokens based on user_color. This is the base
// palette so it is independent of ColorMode.
void AddRefPalette(ui::ColorMixer& mixer,
const ui::ColorProviderManager::Key& key) {
void AddRefPalette(ui::ColorMixer& mixer, const ui::ColorProviderKey& key) {
// TODO(skau): Currently these colors are mapped 1-1 with the ui ref color ids
// for compatibility with the older generated CrOS ids. Uses of these CrOS ids
// can eventually be migrated to use the equivalent ui ids.
Expand Down Expand Up @@ -574,9 +572,9 @@ void ReverseMapSysColors(ui::ColorMixer& mixer, bool dark_mode) {
} // namespace

void AddCrosStylesColorMixer(ui::ColorProvider* provider,
const ui::ColorProviderManager::Key& key) {
const ui::ColorProviderKey& key) {
ui::ColorMixer& mixer = provider->AddMixer();
bool dark_mode = key.color_mode == ui::ColorProviderManager::ColorMode::kDark;
bool dark_mode = key.color_mode == ui::ColorProviderKey::ColorMode::kDark;
if (chromeos::features::IsJellyEnabled()) {
AddRefPalette(mixer, key);
} else {
Expand All @@ -600,10 +598,10 @@ void AddCrosStylesColorMixer(ui::ColorProvider* provider,
}

void AddAshColorMixer(ui::ColorProvider* provider,
const ui::ColorProviderManager::Key& key) {
const ui::ColorProviderKey& key) {
ui::ColorMixer& mixer = provider->AddMixer();
const bool use_dark_color =
key.color_mode == ui::ColorProviderManager::ColorMode::kDark;
key.color_mode == ui::ColorProviderKey::ColorMode::kDark;

AddShieldAndBaseColors(mixer, key);
AddControlsColors(mixer, key);
Expand Down
9 changes: 4 additions & 5 deletions ash/style/ash_color_mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define ASH_STYLE_ASH_COLOR_MIXER_H_

#include "ash/ash_export.h"
#include "ui/color/color_provider_manager.h"
#include "ui/color/color_provider_key.h"

namespace ui {
class ColorProvider;
Expand All @@ -15,14 +15,13 @@ class ColorProvider;
namespace ash {

// Adds a color mixer with colors generated from ui/chromeos/styles/*.json5.
ASH_EXPORT void AddCrosStylesColorMixer(
ui::ColorProvider* provider,
const ui::ColorProviderManager::Key& key);
ASH_EXPORT void AddCrosStylesColorMixer(ui::ColorProvider* provider,
const ui::ColorProviderKey& key);

// Adds a color mixer to `provider` that supplies default values for various
// ash/ colors before taking into account any custom themes.
ASH_EXPORT void AddAshColorMixer(ui::ColorProvider* provider,
const ui::ColorProviderManager::Key& key);
const ui::ColorProviderKey& key);

} // namespace ash

Expand Down
8 changes: 4 additions & 4 deletions ash/style/ash_color_mixer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/chromeos/styles/cros_tokens_color_mappings.h"
#include "ui/color/color_provider.h"
#include "ui/color/color_provider_manager.h"
#include "ui/color/color_provider_key.h"
#include "ui/color/color_provider_utils.h"
#include "ui/gfx/color_palette.h"

Expand All @@ -22,10 +22,10 @@ struct ColorsTestCase {
};

// Returns a key with reasonable values.
ui::ColorProviderManager::Key MakeColorProviderKey(SkColor seed_color) {
ui::ColorProviderManager::Key key;
ui::ColorProviderKey MakeColorProviderKey(SkColor seed_color) {
ui::ColorProviderKey key;
key.user_color = seed_color;
key.color_mode = ui::ColorProviderManager::ColorMode::kLight;
key.color_mode = ui::ColorProviderKey::ColorMode::kLight;
return key;
}

Expand Down
4 changes: 2 additions & 2 deletions ash/style/ash_color_provider_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ash/style/ash_color_provider_source.h"

#include "ui/color/color_provider.h"
#include "ui/color/color_provider_manager.h"

namespace ash {

Expand All @@ -25,8 +26,7 @@ void AshColorProviderSource::OnNativeThemeUpdated(
NotifyColorProviderChanged();
}

ui::ColorProviderManager::Key AshColorProviderSource::GetColorProviderKey()
const {
ui::ColorProviderKey AshColorProviderSource::GetColorProviderKey() const {
return ui::NativeTheme::GetInstanceForNativeUi()->GetColorProviderKey(
nullptr);
}
Expand Down
5 changes: 3 additions & 2 deletions ash/style/ash_color_provider_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "ash/ash_export.h"
#include "base/scoped_observation.h"
#include "ui/color/color_provider_key.h"
#include "ui/color/color_provider_source.h"
#include "ui/native_theme/native_theme.h"
#include "ui/native_theme/native_theme_observer.h"
Expand All @@ -32,7 +33,7 @@ class ASH_EXPORT AshColorProviderSource : public ui::ColorProviderSource,

protected:
// ui::ColorProviderSource:
ui::ColorProviderManager::Key GetColorProviderKey() const override;
ui::ColorProviderKey GetColorProviderKey() const override;

private:
base::ScopedObservation<ui::NativeTheme, ui::NativeThemeObserver>
Expand All @@ -41,4 +42,4 @@ class ASH_EXPORT AshColorProviderSource : public ui::ColorProviderSource,

} // namespace ash

#endif // ASH_STYLE_ASH_COLOR_PROVIDER_SOURCE_H_
#endif // ASH_STYLE_ASH_COLOR_PROVIDER_SOURCE_H_
4 changes: 2 additions & 2 deletions ash/style/ash_color_provider_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
#include "base/test/task_environment.h"
#include "testing/gtest/include/gtest/gtest-param-test.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/color/color_provider_manager.h"
#include "ui/color/color_provider_key.h"

namespace ash {

namespace {

using ColorMode = ui::ColorProviderManager::ColorMode;
using ColorMode = ui::ColorProviderKey::ColorMode;

template <class LayerType>
struct ColorsTestCase {
Expand Down
14 changes: 7 additions & 7 deletions ash/style/color_palette_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "components/prefs/pref_service.h"
#include "components/user_manager/known_user.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/color/color_provider_manager.h"
#include "ui/color/color_provider_key.h"
#include "ui/color/dynamic_color/palette.h"
#include "ui/color/dynamic_color/palette_factory.h"
#include "ui/gfx/color_palette.h"
Expand All @@ -46,7 +46,7 @@ namespace {

class ColorPaletteControllerImpl;

using ColorMode = ui::ColorProviderManager::ColorMode;
using ColorMode = ui::ColorProviderKey::ColorMode;

const SkColor kDefaultWallpaperColor = gfx::kGoogleBlue400;

Expand Down Expand Up @@ -74,7 +74,7 @@ const AccountId& AccountFromSession(const UserSession* session) {
return session->user_info.account_id;
}

using SchemeVariant = ui::ColorProviderManager::SchemeVariant;
using SchemeVariant = ui::ColorProviderKey::SchemeVariant;

SchemeVariant ToVariant(ColorScheme scheme) {
switch (scheme) {
Expand Down Expand Up @@ -230,8 +230,8 @@ class ColorPaletteControllerImpl : public ColorPaletteController,
}

seed.color_mode = dark_light_mode_controller_->IsDarkModeEnabled()
? ui::ColorProviderManager::ColorMode::kDark
: ui::ColorProviderManager::ColorMode::kLight;
? ui::ColorProviderKey::ColorMode::kDark
: ui::ColorProviderKey::ColorMode::kLight;
seed.seed_color = *seed_color;
seed.scheme = GetColorScheme(account_id);

Expand Down Expand Up @@ -411,8 +411,8 @@ class ColorPaletteControllerImpl : public ColorPaletteController,
// the color computation is done and this will be called again.
return {};
}
seed.color_mode = dark ? ui::ColorProviderManager::ColorMode::kDark
: ui::ColorProviderManager::ColorMode::kLight;
seed.color_mode = dark ? ui::ColorProviderKey::ColorMode::kDark
: ui::ColorProviderKey::ColorMode::kLight;
seed.seed_color = *seed_color;
seed.scheme = ColorScheme::kTonalSpot;

Expand Down
6 changes: 3 additions & 3 deletions ash/style/color_palette_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "components/prefs/pref_service.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/color/color_provider_manager.h"
#include "ui/color/color_provider_key.h"
#include "ui/gfx/color_palette.h"

class PrefRegistrySimple;
Expand Down Expand Up @@ -50,8 +50,8 @@ struct ASH_EXPORT ColorPaletteSeed {
// The type of palette which is being generated.
ColorScheme scheme = ColorScheme::kStatic;
// Dark or light palette.
ui::ColorProviderManager::ColorMode color_mode =
ui::ColorProviderManager::ColorMode::kLight;
ui::ColorProviderKey::ColorMode color_mode =
ui::ColorProviderKey::ColorMode::kLight;

bool operator==(const ColorPaletteSeed& other) const {
return std::tie(seed_color, scheme, color_mode) ==
Expand Down
9 changes: 4 additions & 5 deletions ash/style/color_palette_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ TEST_F(ColorPaletteControllerTest, ColorModeTriggersObserver) {

EXPECT_CALL(observer, OnColorPaletteChanging(testing::Field(
&ColorPaletteSeed::color_mode,
ui::ColorProviderManager::ColorMode::kDark)))
ui::ColorProviderKey::ColorMode::kDark)))
.Times(1);
dark_light_controller()->SetDarkModeEnabledForTest(true);
}
Expand Down Expand Up @@ -263,7 +263,7 @@ TEST_F(ColorPaletteControllerTest, NativeTheme_DarkModeChanged_JellyDisabled) {
// Pre-Jelly, this should always be TonalSpot.
EXPECT_THAT(
observer.last_theme()->scheme_variant(),
testing::Optional(ui::ColorProviderManager::SchemeVariant::kTonalSpot));
testing::Optional(ui::ColorProviderKey::SchemeVariant::kTonalSpot));
}

TEST_F(ColorPaletteControllerTest, NativeTheme_DarkModeChanged_JellyEnabled) {
Expand Down Expand Up @@ -292,9 +292,8 @@ TEST_F(ColorPaletteControllerTest, NativeTheme_DarkModeChanged_JellyEnabled) {
EXPECT_EQ(ui::NativeTheme::ColorScheme::kLight,
observer.last_theme()->GetDefaultSystemColorScheme());
EXPECT_EQ(kCelebiColor, observer.last_theme()->user_color().value());
EXPECT_THAT(
observer.last_theme()->scheme_variant(),
testing::Optional(ui::ColorProviderManager::SchemeVariant::kVibrant));
EXPECT_THAT(observer.last_theme()->scheme_variant(),
testing::Optional(ui::ColorProviderKey::SchemeVariant::kVibrant));
}

// Emulates Dark mode changes on login screen that can result from pod
Expand Down
2 changes: 1 addition & 1 deletion ash/style/harmonized_colors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void InsertIntoMixer(ui::ColorMixer& mixer,
} // namespace

void AddHarmonizedColors(ui::ColorMixer& mixer,
const ui::ColorProviderManager::Key& key) {
const ui::ColorProviderKey& key) {
// Zip the arrays into a map indexed by the angle lower bound.
static const base::flat_map<int, HarmonizedSeeds> kSeedMap = MakeMap();

Expand Down
4 changes: 2 additions & 2 deletions ash/style/harmonized_colors.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
#define ASH_STYLE_HARMONIZED_COLORS_H_

#include "ui/color/color_mixer.h"
#include "ui/color/color_provider_manager.h"
#include "ui/color/color_provider_key.h"

namespace ash {

// Adds the harmonized reference colors to `mixer` based on the seed color in
// `key`. If a seed color is not specified, an arbitrary set of harmonized
// colors are used.
void AddHarmonizedColors(ui::ColorMixer& mixer,
const ui::ColorProviderManager::Key& key);
const ui::ColorProviderKey& key);

} // namespace ash

Expand Down
2 changes: 1 addition & 1 deletion ash/webui/camera_app_ui/camera_app_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ void CameraAppUI::BindInterface(
mojo::PendingReceiver<color_change_listener::mojom::PageHandler> receiver) {
views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window());
// Camera app is always dark.
widget->SetColorModeOverride(ui::ColorProviderManager::ColorMode::kDark);
widget->SetColorModeOverride(ui::ColorProviderKey::ColorMode::kDark);

color_provider_handler_ = std::make_unique<ui::ColorChangeHandler>(
web_ui()->GetWebContents(), std::move(receiver));
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/app_controller_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
#import "ui/base/cocoa/nsmenu_additions.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/color/color_provider.h"
#include "ui/color/color_provider_manager.h"
#include "ui/native_theme/native_theme_mac.h"
#include "ui/native_theme/native_theme_observer.h"
#include "url/gurl.h"
Expand Down

0 comments on commit fedf27f

Please sign in to comment.