mirror of
				https://bitbucket.org/chromiumembedded/cef
				synced 2025-06-05 21:39:12 +02:00 
			
		
		
		
	views: Support themes for Alloy BrowserView in Chrome Window (see #3681)
To test:
- Run `cefclient --enable-chrome-runtime --use-alloy-style
                 --use-chrome-style-window [--background-color=green]`
- OS and Chrome theme changes behave as expected.
			
			
This commit is contained in:
		@@ -16,23 +16,6 @@
 | 
			
		||||
#include "ui/linux/linux_ui.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
namespace {
 | 
			
		||||
 | 
			
		||||
ui::ColorProviderKey::SchemeVariant GetSchemeVariant(
 | 
			
		||||
    ui::mojom::BrowserColorVariant color_variant) {
 | 
			
		||||
  using BCV = ui::mojom::BrowserColorVariant;
 | 
			
		||||
  using SV = ui::ColorProviderKey::SchemeVariant;
 | 
			
		||||
  static constexpr auto kSchemeVariantMap = base::MakeFixedFlatMap<BCV, SV>({
 | 
			
		||||
      {BCV::kTonalSpot, SV::kTonalSpot},
 | 
			
		||||
      {BCV::kNeutral, SV::kNeutral},
 | 
			
		||||
      {BCV::kVibrant, SV::kVibrant},
 | 
			
		||||
      {BCV::kExpressive, SV::kExpressive},
 | 
			
		||||
  });
 | 
			
		||||
  return kSchemeVariantMap.at(color_variant);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}  // namespace
 | 
			
		||||
 | 
			
		||||
CefWidgetImpl::CefWidgetImpl(CefWindowView* window_view)
 | 
			
		||||
    : window_view_(window_view) {}
 | 
			
		||||
 | 
			
		||||
@@ -157,62 +140,11 @@ void CefWidgetImpl::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ui::ColorProviderKey CefWidgetImpl::GetColorProviderKey() const {
 | 
			
		||||
  auto* profile = GetThemeProfile();
 | 
			
		||||
  if (!profile) {
 | 
			
		||||
    return Widget::GetColorProviderKey();
 | 
			
		||||
  const auto& widget_key = Widget::GetColorProviderKey();
 | 
			
		||||
  if (auto* profile = GetThemeProfile()) {
 | 
			
		||||
    return CefWidget::GetColorProviderKey(widget_key, profile);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Based on BrowserFrame::GetColorProviderKey.
 | 
			
		||||
  auto key = Widget::GetColorProviderKey();
 | 
			
		||||
 | 
			
		||||
  const auto* theme_service = ThemeServiceFactory::GetForProfile(profile);
 | 
			
		||||
  CHECK(theme_service);
 | 
			
		||||
 | 
			
		||||
  // color_mode.
 | 
			
		||||
  [&key, theme_service]() {
 | 
			
		||||
    const auto browser_color_scheme = theme_service->GetBrowserColorScheme();
 | 
			
		||||
    if (browser_color_scheme != ThemeService::BrowserColorScheme::kSystem) {
 | 
			
		||||
      key.color_mode =
 | 
			
		||||
          browser_color_scheme == ThemeService::BrowserColorScheme::kLight
 | 
			
		||||
              ? ui::ColorProviderKey::ColorMode::kLight
 | 
			
		||||
              : ui::ColorProviderKey::ColorMode::kDark;
 | 
			
		||||
    }
 | 
			
		||||
  }();
 | 
			
		||||
 | 
			
		||||
  // user_color.
 | 
			
		||||
  // Device theme retains the user_color from `Widget`.
 | 
			
		||||
  if (!theme_service->UsingDeviceTheme()) {
 | 
			
		||||
    if (theme_service->UsingAutogeneratedTheme()) {
 | 
			
		||||
      key.user_color = theme_service->GetAutogeneratedThemeColor();
 | 
			
		||||
    } else if (auto user_color = theme_service->GetUserColor()) {
 | 
			
		||||
      key.user_color = user_color;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // user_color_source.
 | 
			
		||||
  if (theme_service->UsingDeviceTheme()) {
 | 
			
		||||
    key.user_color_source = ui::ColorProviderKey::UserColorSource::kAccent;
 | 
			
		||||
  } else if (theme_service->GetIsGrayscale()) {
 | 
			
		||||
    key.user_color_source = ui::ColorProviderKey::UserColorSource::kGrayscale;
 | 
			
		||||
  } else if (theme_service->GetIsBaseline()) {
 | 
			
		||||
    key.user_color_source = ui::ColorProviderKey::UserColorSource::kBaseline;
 | 
			
		||||
  } else {
 | 
			
		||||
    CHECK(key.user_color.has_value());
 | 
			
		||||
    key.user_color_source = ui::ColorProviderKey::UserColorSource::kAccent;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // scheme_variant.
 | 
			
		||||
  ui::mojom::BrowserColorVariant color_variant =
 | 
			
		||||
      theme_service->GetBrowserColorVariant();
 | 
			
		||||
  if (!theme_service->UsingDeviceTheme() &&
 | 
			
		||||
      color_variant != ui::mojom::BrowserColorVariant::kSystem) {
 | 
			
		||||
    key.scheme_variant = GetSchemeVariant(color_variant);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // frame_type.
 | 
			
		||||
  key.frame_type = ui::ColorProviderKey::FrameType::kNative;
 | 
			
		||||
 | 
			
		||||
  return key;
 | 
			
		||||
  return widget_key;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CefWidgetImpl::OnThemeChanged() {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user