blob: bf4feac8272ec552ce616123536509797f68949c [file] [log] [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.
// This file is generated from:
{%- for path in in_files %}
// {{path}}
{%- endfor %}
#include "{{header_file}}"
#include <optional>
#include "third_party/skia/include/core/SkColor.h"
namespace {{namespace_name}} {
bool g_dark_mode_enabled = false;
bool g_debug_colors_enabled = false;
bool DarkModeEnabled() {
return g_dark_mode_enabled;
}
bool DebugColorsEnabled() {
return g_debug_colors_enabled;
}
void SetDarkModeEnabled(bool enabled) {
g_dark_mode_enabled = enabled;
}
void SetDebugColorsEnabled(bool enabled) {
g_debug_colors_enabled = enabled;
}
{%- if opacities %}
SkAlpha GetOpacity(OpacityName opacity_name, bool is_dark_mode) {
switch (opacity_name) {
{%- for name, mode_values in opacities.items() %}
case OpacityName::{{name | to_const_name}}:
{%- if mode_values[Modes.DARK] %}
if (is_dark_mode) {
return {{mode_values[Modes.DARK] | cpp_opacity}};
} else {
return {{mode_values[Modes.LIGHT] | cpp_opacity}};
}
{%- else %}
return {{mode_values[Modes.LIGHT] | cpp_opacity}};
{%- endif %}
{%- endfor %}
}
}
{%- endif %}
std::optional<SkColor> GetDebugColor(ColorName color_name, bool is_dark_mode) {
switch (color_name) {
{%- for obj in colors %}
{%- if obj.mode_values[Modes.DEBUG] %}
case ColorName::{{obj.name | to_const_name}}:
return {{obj.mode_values[Modes.DEBUG] | cpp_color}};
{%- endif %}
{%- endfor %}
default:
return std::nullopt;
}
}
SkColor ResolveColor(ColorName color_name,
bool is_dark_mode,
bool use_debug_colors) {
if (use_debug_colors) {
auto debug_color = GetDebugColor(color_name, is_dark_mode);
if (debug_color) {
return *debug_color;
}
}
switch (color_name) {
{%- for obj in colors %}
case ColorName::{{obj.name | to_const_name}}:
{%- if obj.mode_values[Modes.DARK] %}
if (is_dark_mode)
return {{obj.mode_values[Modes.DARK] | cpp_color}};
{%- endif %}
return {{obj.mode_values[Modes.LIGHT] | cpp_color}};
{%- endfor %}
}
}
} // namespace {{namespace_name}}