1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46

ash / style / ash_color_provider_source.cc [blame]

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/style/ash_color_provider_source.h"

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

namespace ash {

AshColorProviderSource::AshColorProviderSource() {
  native_theme_observation_.Observe(ui::NativeTheme::GetInstanceForNativeUi());
}

AshColorProviderSource::~AshColorProviderSource() = default;

const ui::ColorProvider* AshColorProviderSource::GetColorProvider() const {
  return ui::ColorProviderManager::Get().GetColorProviderFor(
      GetColorProviderKey());
}

ui::RendererColorMap AshColorProviderSource::GetRendererColorMap(
    ui::ColorProviderKey::ColorMode color_mode,
    ui::ColorProviderKey::ForcedColors forced_colors) const {
  auto key = GetColorProviderKey();
  key.color_mode = color_mode;
  key.forced_colors = forced_colors;
  ui::ColorProvider* color_provider =
      ui::ColorProviderManager::Get().GetColorProviderFor(key);
  CHECK(color_provider);
  return ui::CreateRendererColorMap(*color_provider);
}

void AshColorProviderSource::OnNativeThemeUpdated(
    ui::NativeTheme* observed_theme) {
  DCHECK(native_theme_observation_.IsObservingSource(observed_theme));
  NotifyColorProviderChanged();
}

ui::ColorProviderKey AshColorProviderSource::GetColorProviderKey() const {
  return ui::NativeTheme::GetInstanceForNativeUi()->GetColorProviderKey(
      nullptr);
}

}  // namespace ash