#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "ui/native_theme/native_theme_base.h"
#include <algorithm>
#include <limits>
#include <memory>
#include "base/check.h"
#include "base/command_line.h"
#include "base/containers/fixed_flat_set.h"
#include "base/notreached.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "cc/paint/paint_flags.h"
#include "cc/paint/paint_shader.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkRRect.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/resource/resource_scale_factor.h"
#include "ui/base/ui_base_features.h"
#include "ui/base/ui_base_switches.h"
#include "ui/color/color_provider.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/skia_conversions.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/native_theme/common_theme.h"
#include "ui/native_theme/native_theme.h"
namespace {
const int kCheckboxAndRadioWidth = …;
const int kCheckboxAndRadioHeight = …;
constexpr SkColor kThumbActiveColor[2] = …;
constexpr SkColor kThumbInactiveColor[2] = …;
constexpr SkColor kTrackColor[2] = …;
constexpr SkColor kMenuPopupBackgroundColor[2] = …;
constexpr SkColor kArrowDisabledColor[2] = …;
const SkScalar kIndeterminateInsetWidthRatio = …;
const SkScalar kIndeterminateInsetHeightRatio = …;
const SkScalar kBorderWidth = …;
const SkScalar kSliderTrackHeight = …;
const SkScalar kSliderThumbBorderWidth = …;
const SkScalar kSliderThumbBorderHoveredWidth = …;
const SkScalar kTrackBlockRatio = …;
const SkScalar kMenuListArrowStrokeWidth = …;
const int kSliderThumbSize = …;
const double kAccentLuminanceAdjust = …;
SkColor GetColor(const SkColor colors[2],
ui::NativeTheme::ColorScheme color_scheme) { … }
SkColor AdjustLuminance(const SkColor& color, double luminance) { … }
SkColor CustomAccentColorForState(
const SkColor& accent_color,
ui::NativeTheme::State state,
const ui::NativeTheme::ColorScheme& color_scheme) { … }
}
namespace ui {
gfx::Size NativeThemeBase::GetPartSize(Part part,
State state,
const ExtraParams& extra) const { … }
float NativeThemeBase::GetBorderRadiusForPart(Part part,
float width,
float height) const { … }
void NativeThemeBase::Paint(cc::PaintCanvas* canvas,
const ui::ColorProvider* color_provider,
Part part,
State state,
const gfx::Rect& rect,
const ExtraParams& extra,
ColorScheme color_scheme,
bool in_forced_colors,
const std::optional<SkColor>& accent_color) const { … }
bool NativeThemeBase::SupportsNinePatch(Part part) const { … }
gfx::Size NativeThemeBase::GetNinePatchCanvasSize(Part part) const { … }
gfx::Rect NativeThemeBase::GetNinePatchAperture(Part part) const { … }
NativeThemeBase::NativeThemeBase() : … { … }
NativeThemeBase::NativeThemeBase(bool should_only_use_dark_colors,
ui::SystemTheme system_theme)
: … { … }
NativeThemeBase::~NativeThemeBase() = default;
void NativeThemeBase::PaintArrowButton(
cc::PaintCanvas* canvas,
const ColorProvider* color_provider,
const gfx::Rect& rect,
Part direction,
State state,
ColorScheme color_scheme,
bool in_forced_colors,
const ScrollbarArrowExtraParams& extra_params) const { … }
void NativeThemeBase::PaintArrow(cc::PaintCanvas* gc,
const gfx::Rect& rect,
Part direction,
SkColor color) const { … }
SkPath NativeThemeBase::PathForArrow(const gfx::Rect& bounding_rect,
Part direction) const { … }
gfx::Rect NativeThemeBase::BoundingRectForArrow(const gfx::Rect& rect) const { … }
void NativeThemeBase::PaintScrollbarTrack(
cc::PaintCanvas* canvas,
const ColorProvider* color_provider,
Part part,
State state,
const ScrollbarTrackExtraParams& extra_params,
const gfx::Rect& rect,
ColorScheme color_scheme,
bool in_forced_colors) const { … }
void NativeThemeBase::PaintScrollbarThumb(
cc::PaintCanvas* canvas,
const ColorProvider* color_provider,
Part part,
State state,
const gfx::Rect& rect,
const ScrollbarThumbExtraParams& extra_params,
ColorScheme color_scheme) const { … }
void NativeThemeBase::PaintScrollbarCorner(
cc::PaintCanvas* canvas,
const ColorProvider* color_provider,
State state,
const gfx::Rect& rect,
const ScrollbarTrackExtraParams& extra_params,
ColorScheme color_scheme) const { … }
void NativeThemeBase::PaintCheckbox(
cc::PaintCanvas* canvas,
const ColorProvider* color_provider,
State state,
const gfx::Rect& rect,
const ButtonExtraParams& button,
ColorScheme color_scheme,
const std::optional<SkColor>& accent_color) const { … }
SkRect NativeThemeBase::PaintCheckboxRadioCommon(
cc::PaintCanvas* canvas,
const ColorProvider* color_provider,
State state,
const gfx::Rect& rect,
const ButtonExtraParams& button,
bool is_checkbox,
const SkScalar border_radius,
ColorScheme color_scheme,
const std::optional<SkColor>& accent_color) const { … }
void NativeThemeBase::PaintRadio(
cc::PaintCanvas* canvas,
const ColorProvider* color_provider,
State state,
const gfx::Rect& rect,
const ButtonExtraParams& button,
ColorScheme color_scheme,
const std::optional<SkColor>& accent_color) const { … }
void NativeThemeBase::PaintButton(cc::PaintCanvas* canvas,
const ColorProvider* color_provider,
State state,
const gfx::Rect& rect,
const ButtonExtraParams& button,
ColorScheme color_scheme) const { … }
void NativeThemeBase::PaintTextField(cc::PaintCanvas* canvas,
const ColorProvider* color_provider,
State state,
const gfx::Rect& rect,
const TextFieldExtraParams& text,
ColorScheme color_scheme) const { … }
void NativeThemeBase::PaintMenuList(cc::PaintCanvas* canvas,
const ColorProvider* color_provider,
State state,
const gfx::Rect& rect,
const MenuListExtraParams& menu_list,
ColorScheme color_scheme) const { … }
void NativeThemeBase::PaintMenuPopupBackground(
cc::PaintCanvas* canvas,
const ColorProvider* color_provider,
const gfx::Size& size,
const MenuBackgroundExtraParams& menu_background,
ColorScheme color_scheme) const { … }
void NativeThemeBase::PaintMenuItemBackground(
cc::PaintCanvas* canvas,
const ColorProvider* color_provider,
State state,
const gfx::Rect& rect,
const MenuItemExtraParams& menu_item,
ColorScheme color_scheme) const { … }
void NativeThemeBase::PaintMenuSeparator(
cc::PaintCanvas* canvas,
const ui::ColorProvider* color_provider,
State state,
const gfx::Rect& rect,
const MenuSeparatorExtraParams& menu_separator) const { … }
void NativeThemeBase::PaintSliderTrack(
cc::PaintCanvas* canvas,
const ColorProvider* color_provider,
State state,
const gfx::Rect& rect,
const SliderExtraParams& slider,
ColorScheme color_scheme,
const std::optional<SkColor>& accent_color) const { … }
void NativeThemeBase::PaintSliderThumb(
cc::PaintCanvas* canvas,
const ColorProvider* color_provider,
State state,
const gfx::Rect& rect,
const SliderExtraParams& slider,
ColorScheme color_scheme,
const std::optional<SkColor>& accent_color) const { … }
void NativeThemeBase::PaintInnerSpinButton(
cc::PaintCanvas* canvas,
const ColorProvider* color_provider,
State state,
const gfx::Rect& rect,
const InnerSpinButtonExtraParams& spin_button,
ColorScheme color_scheme,
bool in_forced_colors) const { … }
void NativeThemeBase::PaintProgressBar(
cc::PaintCanvas* canvas,
const ColorProvider* color_provider,
State state,
const gfx::Rect& rect,
const ProgressBarExtraParams& progress_bar,
ColorScheme color_scheme,
const std::optional<SkColor>& accent_color) const { … }
void NativeThemeBase::PaintFrameTopArea(
cc::PaintCanvas* canvas,
State state,
const gfx::Rect& rect,
const FrameTopAreaExtraParams& frame_top_area,
ColorScheme color_scheme) const { … }
void NativeThemeBase::AdjustCheckboxRadioRectForPadding(SkRect* rect) const { … }
SkColor NativeThemeBase::SaturateAndBrighten(SkScalar* hsv,
SkScalar saturate_amount,
SkScalar brighten_amount) const { … }
SkColor NativeThemeBase::GetArrowColor(
State state,
ColorScheme color_scheme,
const ColorProvider* color_provider) const { … }
void NativeThemeBase::DrawVertLine(cc::PaintCanvas* canvas,
int x,
int y1,
int y2,
const cc::PaintFlags& flags) const { … }
void NativeThemeBase::DrawHorizLine(cc::PaintCanvas* canvas,
int x1,
int x2,
int y,
const cc::PaintFlags& flags) const { … }
void NativeThemeBase::DrawBox(cc::PaintCanvas* canvas,
const gfx::Rect& rect,
const cc::PaintFlags& flags) const { … }
SkColor NativeThemeBase::OutlineColor(SkScalar* hsv1, SkScalar* hsv2) const { … }
SkColor NativeThemeBase::ControlsAccentColorForState(
State state,
ColorScheme color_scheme,
const ColorProvider* color_provider) const { … }
SkColor NativeThemeBase::ControlsSliderColorForState(
State state,
ColorScheme color_scheme,
const ColorProvider* color_provider) const { … }
SkColor NativeThemeBase::ControlsBorderColorForState(
State state,
ColorScheme color_scheme,
const ColorProvider* color_provider) const { … }
SkColor NativeThemeBase::ButtonBorderColorForState(
State state,
ColorScheme color_scheme,
const ColorProvider* color_provider) const { … }
SkColor NativeThemeBase::ControlsFillColorForState(
State state,
ColorScheme color_scheme,
const ColorProvider* color_provider) const { … }
SkColor NativeThemeBase::ButtonFillColorForState(
State state,
ColorScheme color_scheme,
const ColorProvider* color_provider) const { … }
SkColor NativeThemeBase::ControlsBackgroundColorForState(
State state,
ColorScheme color_scheme,
const ColorProvider* color_provider) const { … }
SkColor NativeThemeBase::GetControlColor(
ControlColorId color_id,
ColorScheme color_scheme,
const ColorProvider* color_provider) const { … }
SkColor NativeThemeBase::GetDarkModeControlColor(
ControlColorId color_id) const { … }
SkColor NativeThemeBase::GetControlColorFromColorProvider(
ControlColorId color_id,
const ColorProvider* color_provider) const { … }
void NativeThemeBase::PaintLightenLayer(cc::PaintCanvas* canvas,
const ColorProvider* color_provider,
SkRect skrect,
State state,
SkScalar border_radius,
ColorScheme color_scheme) const { … }
SkRect NativeThemeBase::AlignSliderTrack(
const gfx::Rect& slider_rect,
const NativeTheme::SliderExtraParams& slider,
bool is_value,
float track_block_thickness) const { … }
bool NativeThemeBase::IsColorPipelineSupportedForControlColorId(
const ColorProvider* color_provider,
ControlColorId color_id) const { … }
}