Bug 1846249 - Change color functions to constants r=dholbert

Differential Revision: https://phabricator.services.mozilla.com/D184929
This commit is contained in:
Tiaan Louw 2023-07-31 18:22:46 +00:00
Родитель e77f0449bb
Коммит 54b0405222
17 изменённых файлов: 73 добавлений и 86 удалений

Просмотреть файл

@ -45,7 +45,7 @@ struct nsFont final {
// rendering mode when the alpha component > 0. Only used for text in the
// chrome.
mozilla::StyleAbsoluteColor fontSmoothingBackgroundColor =
mozilla::StyleAbsoluteColor::Transparent();
mozilla::StyleAbsoluteColor::TRANSPARENT;
// Language system tag, to override document language;
// this is an OpenType "language system" tag represented as a 32-bit integer

Просмотреть файл

@ -1809,7 +1809,7 @@ void nsImageFrame::DisplayAltText(nsPresContext* aPresContext,
struct nsRecessedBorder : public nsStyleBorder {
explicit nsRecessedBorder(nscoord aBorderWidth) {
for (const auto side : AllPhysicalSides()) {
BorderColorFor(side) = StyleColor::Black();
BorderColorFor(side) = StyleColor::BLACK;
mBorder.Side(side) = aBorderWidth;
// Note: use SetBorderStyle here because we want to affect
// mComputedBorder

Просмотреть файл

@ -552,7 +552,7 @@ static StyleAbsoluteColor GetSpecifiedColor(
const StyleGenericGradientItem<StyleColor, T>& aItem,
const ComputedStyle& aStyle) {
if (aItem.IsInterpolationHint()) {
return StyleAbsoluteColor::Transparent();
return StyleAbsoluteColor::TRANSPARENT;
}
const StyleColor& c = aItem.IsSimpleColorStop()
? aItem.AsSimpleColorStop()
@ -1084,7 +1084,7 @@ void nsCSSGradientRenderer::Paint(gfxContext& aContext, const nsRect& aDest,
gfxRect dirtyFillRect = fillRect.Intersect(dirtyAreaToFill);
gfxRect fillRectRelativeToTile = dirtyFillRect - tileRect.TopLeft();
auto edgeColor = StyleAbsoluteColor::Transparent();
auto edgeColor = StyleAbsoluteColor::TRANSPARENT;
if (mGradient->IsLinear() && !isRepeat &&
RectIsBeyondLinearGradientEdge(fillRectRelativeToTile, matrix, mStops,
gradientStart, gradientEnd,

Просмотреть файл

@ -28,37 +28,25 @@ inline StyleAbsoluteColor StyleAbsoluteColor::Srgb(float red, float green,
StyleColorSpace::Srgb, StyleColorFlags{0}};
}
inline StyleAbsoluteColor StyleAbsoluteColor::Transparent() {
return StyleAbsoluteColor::Srgb(0.0f, 0.0f, 0.0f, 0.0f);
}
inline StyleAbsoluteColor StyleAbsoluteColor::Black() {
return StyleAbsoluteColor::Srgb(0.0f, 0.0f, 0.0f, 1.0f);
}
inline StyleAbsoluteColor StyleAbsoluteColor::White() {
return StyleAbsoluteColor::Srgb(1.0f, 1.0f, 1.0f, 1.0f);
}
template <>
inline StyleColor StyleColor::FromColor(nscolor aColor) {
return StyleColor::Absolute(StyleAbsoluteColor::FromColor(aColor));
}
// static
template <>
inline StyleColor StyleColor::Black() {
return FromColor(NS_RGB(0, 0, 0));
}
inline const StyleColor StyleColor::TRANSPARENT =
StyleColor::Absolute(StyleAbsoluteColor::TRANSPARENT);
// static
template <>
inline StyleColor StyleColor::White() {
return FromColor(NS_RGB(255, 255, 255));
}
inline const StyleColor StyleColor::BLACK =
StyleColor::Absolute(StyleAbsoluteColor::BLACK);
// static
template <>
inline StyleColor StyleColor::Transparent() {
return FromColor(NS_RGBA(0, 0, 0, 0));
}
inline const StyleColor StyleColor::WHITE =
StyleColor::Absolute(StyleAbsoluteColor::WHITE);
template <>
StyleAbsoluteColor StyleColor::ResolveColor(const StyleAbsoluteColor&) const;

Просмотреть файл

@ -752,7 +752,7 @@ using SVGPaintFallback = StyleGenericSVGPaintFallback<StyleColor>;
// nsStyleSVG
//
nsStyleSVG::nsStyleSVG()
: mFill{StyleSVGPaintKind::Color(StyleColor::Black()),
: mFill{StyleSVGPaintKind::Color(StyleColor::BLACK),
SVGPaintFallback::Unset()},
mStroke{StyleSVGPaintKind::None(), SVGPaintFallback::Unset()},
mMarkerEnd(StyleUrlOrNone::None()),
@ -899,9 +899,9 @@ nsStyleSVGReset::nsStyleSVGReset()
mR(NonNegativeLengthPercentage::Zero()),
mMask(nsStyleImageLayers::LayerType::Mask),
mClipPath(StyleClipPath::None()),
mStopColor(StyleColor::Black()),
mFloodColor(StyleColor::Black()),
mLightingColor(StyleColor::White()),
mStopColor(StyleColor::BLACK),
mFloodColor(StyleColor::BLACK),
mLightingColor(StyleColor::WHITE),
mStopOpacity(1.0f),
mFloodOpacity(1.0f),
mVectorEffect(StyleVectorEffect::None),
@ -2037,7 +2037,7 @@ nsChangeHint nsStyleImageLayers::Layer::CalcDifference(
nsStyleBackground::nsStyleBackground()
: mImage(nsStyleImageLayers::LayerType::Background),
mBackgroundColor(StyleColor::Transparent()) {
mBackgroundColor(StyleColor::TRANSPARENT) {
MOZ_COUNT_CTOR(nsStyleBackground);
}

Просмотреть файл

@ -185,6 +185,30 @@ macro_rules! color_components_as {
}
impl AbsoluteColor {
/// A fully transparent color in the legacy syntax.
pub const TRANSPARENT: Self = Self {
components: ColorComponents(0.0, 0.0, 0.0),
alpha: 0.0,
color_space: ColorSpace::Srgb,
flags: ColorFlags { bits: 0 }, // cbindgen does not like ColorFlags::empty().
};
/// An opaque black color in the legacy syntax.
pub const BLACK: Self = Self {
components: ColorComponents(0.0, 0.0, 0.0),
alpha: 1.0,
color_space: ColorSpace::Srgb,
flags: ColorFlags { bits: 0 }, // cbindgen does not like ColorFlags::empty().
};
/// An opaque white color in the legacy syntax.
pub const WHITE: Self = Self {
components: ColorComponents(1.0, 1.0, 1.0),
alpha: 1.0,
color_space: ColorSpace::Srgb,
flags: ColorFlags { bits: 0 }, // cbindgen does not like ColorFlags::empty().
};
/// Create a new [`AbsoluteColor`] with the given [`ColorSpace`] and
/// components.
pub fn new(color_space: ColorSpace, components: ColorComponents, alpha: f32) -> Self {
@ -223,21 +247,6 @@ impl AbsoluteColor {
Self::new(ColorSpace::Srgb, ColorComponents(red, green, blue), alpha)
}
/// Create a new transparent color.
pub fn transparent() -> Self {
Self::srgb(0.0, 0.0, 0.0, 0.0)
}
/// Create a new opaque black color.
pub fn black() -> Self {
Self::srgb(0.0, 0.0, 0.0, 1.0)
}
/// Create a new opaque white color.
pub fn white() -> Self {
Self::srgb(1.0, 1.0, 1.0, 1.0)
}
/// Return all the components of the color in an array. (Includes alpha)
#[inline]
pub fn raw_components(&self) -> &[f32; 4] {

Просмотреть файл

@ -445,7 +445,7 @@ fn tweak_when_ignoring_colors(
// We assume here currentColor is opaque.
color
.to_computed_value(context)
.resolve_to_absolute(&AbsoluteColor::black())
.resolve_to_absolute(&AbsoluteColor::BLACK)
.alpha
}

Просмотреть файл

@ -9,7 +9,7 @@
${helpers.predefined_type(
"background-color",
"Color",
"computed::Color::transparent()",
"computed::Color::TRANSPARENT",
engines="gecko servo-2013 servo-2020",
initial_specified_value="SpecifiedValue::transparent()",
spec="https://drafts.csswg.org/css-backgrounds/#background-color",

Просмотреть файл

@ -445,7 +445,7 @@ ${helpers.single_keyword(
${helpers.predefined_type(
"-moz-font-smoothing-background-color",
"color::MozFontSmoothingBackgroundColor",
"computed::color::MozFontSmoothingBackgroundColor::transparent()",
"computed::color::MozFontSmoothingBackgroundColor::TRANSPARENT",
engines="gecko",
animation_value_type="none",
gecko_ffi_name="mFont.fontSmoothingBackgroundColor",

Просмотреть файл

@ -51,7 +51,7 @@ ${helpers.single_keyword(
${helpers.predefined_type(
"fill",
"SVGPaint",
"crate::values::computed::SVGPaint::black()",
"crate::values::computed::SVGPaint::BLACK",
engines="gecko",
animation_value_type="IntermediateSVGPaint",
boxed=True,

Просмотреть файл

@ -9,7 +9,7 @@
${helpers.predefined_type(
"color",
"ColorPropertyValue",
"crate::color::AbsoluteColor::black()",
"crate::color::AbsoluteColor::BLACK",
engines="gecko servo-2013 servo-2020",
animation_value_type="AbsoluteColor",
ignored_when_colors_disabled="True",

Просмотреть файл

@ -20,7 +20,7 @@ ${helpers.single_keyword(
${helpers.predefined_type(
"stop-color",
"Color",
"computed::Color::black()",
"computed::Color::BLACK",
engines="gecko",
animation_value_type="AnimatedRGBA",
spec="https://www.w3.org/TR/SVGTiny12/painting.html#StopColorProperty",
@ -40,7 +40,7 @@ ${helpers.predefined_type(
${helpers.predefined_type(
"flood-color",
"Color",
"computed::Color::black()",
"computed::Color::BLACK",
engines="gecko",
animation_value_type="AnimatedColor",
spec="https://www.w3.org/TR/SVG/filters.html#FloodColorProperty",
@ -58,7 +58,7 @@ ${helpers.predefined_type(
${helpers.predefined_type(
"lighting-color",
"Color",
"computed::Color::white()",
"computed::Color::WHITE",
engines="gecko",
animation_value_type="AnimatedColor",
spec="https://www.w3.org/TR/SVG/filters.html#LightingColorProperty",

Просмотреть файл

@ -74,7 +74,7 @@ impl Animate for Color {
impl ComputeSquaredDistance for Color {
#[inline]
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
let current_color = AbsoluteColor::transparent();
let current_color = AbsoluteColor::TRANSPARENT;
self.resolve_to_absolute(&current_color)
.compute_squared_distance(&other.resolve_to_absolute(&current_color))
}
@ -83,6 +83,6 @@ impl ComputeSquaredDistance for Color {
impl ToAnimatedZero for Color {
#[inline]
fn to_animated_zero(&self) -> Result<Self, ()> {
Ok(Color::Absolute(AbsoluteColor::transparent()))
Ok(Color::Absolute(AbsoluteColor::TRANSPARENT))
}
}

Просмотреть файл

@ -42,6 +42,15 @@ impl ToCss for Color {
}
impl Color {
/// A fully transparent color.
pub const TRANSPARENT: Self = Self::Absolute(AbsoluteColor::TRANSPARENT);
/// An opaque black color.
pub const BLACK: Self = Self::Absolute(AbsoluteColor::BLACK);
/// An opaque white color.
pub const WHITE: Self = Self::Absolute(AbsoluteColor::WHITE);
/// Create a new computed [`Color`] from a given color-mix, simplifying it to an absolute color
/// if possible.
pub fn from_color_mix(color_mix: ColorMix) -> Self {
@ -52,21 +61,6 @@ impl Color {
}
}
/// Returns a complex color value representing transparent.
pub fn transparent() -> Color {
Color::Absolute(AbsoluteColor::transparent())
}
/// Returns opaque black.
pub fn black() -> Color {
Color::Absolute(AbsoluteColor::black())
}
/// Returns opaque white.
pub fn white() -> Color {
Color::Absolute(AbsoluteColor::white())
}
/// Combine this complex color with the given foreground color into an
/// absolute color.
pub fn resolve_to_absolute(&self, current_color: &AbsoluteColor) -> AbsoluteColor {
@ -93,7 +87,7 @@ impl Color {
impl ToAnimatedZero for AbsoluteColor {
fn to_animated_zero(&self) -> Result<Self, ()> {
Ok(Self::transparent())
Ok(Self::TRANSPARENT)
}
}

Просмотреть файл

@ -20,12 +20,10 @@ pub type SVGPaintKind = generic::GenericSVGPaintKind<Color, ComputedUrl>;
impl SVGPaint {
/// Opaque black color
pub fn black() -> Self {
SVGPaint {
kind: generic::SVGPaintKind::Color(Color::black()),
fallback: generic::SVGPaintFallback::Unset,
}
}
pub const BLACK: Self = Self {
kind: generic::SVGPaintKind::Color(Color::BLACK),
fallback: generic::SVGPaintFallback::Unset,
};
}
/// <length> | <percentage> | <number> | context-value

Просмотреть файл

@ -801,7 +801,7 @@ impl Color {
#[inline]
pub fn transparent() -> Self {
// We should probably set authored to "transparent", but maybe it doesn't matter.
Self::from_absolute_color(AbsoluteColor::transparent())
Self::from_absolute_color(AbsoluteColor::TRANSPARENT)
}
/// Create a color from an [`AbsoluteColor`].
@ -974,7 +974,7 @@ impl ToComputedValue for MozFontSmoothingBackgroundColor {
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
self.0
.to_computed_value(context)
.resolve_to_absolute(&AbsoluteColor::transparent())
.resolve_to_absolute(&AbsoluteColor::TRANSPARENT)
}
fn from_computed_value(computed: &Self::ComputedValue) -> Self {

Просмотреть файл

@ -545,10 +545,12 @@ renaming_overrides_prefixing = true
"""
"GenericColor" = """
static const StyleGenericColor TRANSPARENT;
static const StyleGenericColor BLACK;
static const StyleGenericColor WHITE;
static inline StyleGenericColor FromColor(nscolor);
static inline StyleGenericColor Black();
static inline StyleGenericColor White();
static inline StyleGenericColor Transparent();
bool MaybeTransparent() const;
/**
@ -579,10 +581,6 @@ renaming_overrides_prefixing = true
*/
static inline StyleAbsoluteColor Srgb(float red, float green, float blue, float alpha);
static inline StyleAbsoluteColor Transparent();
static inline StyleAbsoluteColor Black();
static inline StyleAbsoluteColor White();
static inline StyleAbsoluteColor FromColor(nscolor);
/**