diff --git a/accessible/base/TextAttrs.cpp b/accessible/base/TextAttrs.cpp index d7fb1081eb76..01e583bb2af1 100644 --- a/accessible/base/TextAttrs.cpp +++ b/accessible/base/TextAttrs.cpp @@ -348,11 +348,11 @@ bool TextAttrsMgr::BGColorTextAttr::GetColor(nsIFrame* aFrame, TextAttrsMgr::ColorTextAttr::ColorTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame) : TTextAttr(!aFrame) { - mRootNativeValue = aRootFrame->StyleColor()->mColor; + mRootNativeValue = aRootFrame->StyleColor()->mColor.ToColor(); mIsRootDefined = true; if (aFrame) { - mNativeValue = aFrame->StyleColor()->mColor; + mNativeValue = aFrame->StyleColor()->mColor.ToColor(); mIsDefined = true; } } @@ -361,9 +361,8 @@ bool TextAttrsMgr::ColorTextAttr::GetValueFor(Accessible* aAccessible, nscolor* aValue) { nsIContent* elm = nsCoreUtils::GetDOMElementFor(aAccessible->GetContent()); if (elm) { - nsIFrame* frame = elm->GetPrimaryFrame(); - if (frame) { - *aValue = frame->StyleColor()->mColor; + if (nsIFrame* frame = elm->GetPrimaryFrame()) { + *aValue = frame->StyleColor()->mColor.ToColor(); return true; } } diff --git a/accessible/windows/ia2/ia2AccessibleComponent.cpp b/accessible/windows/ia2/ia2AccessibleComponent.cpp index d516a443e9db..2fe360be2289 100644 --- a/accessible/windows/ia2/ia2AccessibleComponent.cpp +++ b/accessible/windows/ia2/ia2AccessibleComponent.cpp @@ -79,7 +79,7 @@ ia2AccessibleComponent::get_foreground(IA2Color* aForeground) { if (acc->IsDefunct()) return CO_E_OBJNOTCONNECTED; nsIFrame* frame = acc->GetFrame(); - if (frame) *aForeground = frame->StyleColor()->mColor; + if (frame) *aForeground = frame->StyleColor()->mColor.ToColor(); return S_OK; } diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index e42cf80fe8a8..232a5e518b68 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -1002,7 +1002,7 @@ bool CanvasRenderingContext2D::ParseColor(const nsAString& aString, RefPtr canvasStyle = nsComputedDOMStyle::GetComputedStyle(mCanvasElement, nullptr); if (canvasStyle) { - *aColor = canvasStyle->StyleColor()->mColor; + *aColor = canvasStyle->StyleColor()->mColor.ToColor(); } // Beware that the presShell could be gone here. } diff --git a/editor/libeditor/HTMLAbsPositionEditor.cpp b/editor/libeditor/HTMLAbsPositionEditor.cpp index 73489746c358..dfbf44a5f879 100644 --- a/editor/libeditor/HTMLAbsPositionEditor.cpp +++ b/editor/libeditor/HTMLAbsPositionEditor.cpp @@ -623,10 +623,10 @@ nsresult HTMLEditor::GetTemporaryStyleForFocusedPositionedElement( const uint8_t kBlackBgTrigger = 0xd0; - nscolor color = style->StyleColor()->mColor; - if (NS_GET_R(color) >= kBlackBgTrigger && - NS_GET_G(color) >= kBlackBgTrigger && - NS_GET_B(color) >= kBlackBgTrigger) { + const auto& color = style->StyleColor()->mColor; + if (color.red >= kBlackBgTrigger && + color.green >= kBlackBgTrigger && + color.blue >= kBlackBgTrigger) { aReturn.AssignLiteral("black"); } else { aReturn.AssignLiteral("white"); diff --git a/gfx/src/nsFont.cpp b/gfx/src/nsFont.cpp index f6af9078d00b..d618b9df7a31 100644 --- a/gfx/src/nsFont.cpp +++ b/gfx/src/nsFont.cpp @@ -256,7 +256,7 @@ void nsFont::AddFontFeaturesToStyle(gfxFontStyle* aStyle, aStyle->useGrayscaleAntialiasing = true; } - aStyle->fontSmoothingBackgroundColor = fontSmoothingBackgroundColor; + aStyle->fontSmoothingBackgroundColor = fontSmoothingBackgroundColor.ToColor(); } void nsFont::AddFontVariationsToStyle(gfxFontStyle* aStyle) const { diff --git a/gfx/src/nsFont.h b/gfx/src/nsFont.h index 6a6ca9759a36..52fd875d2196 100644 --- a/gfx/src/nsFont.h +++ b/gfx/src/nsFont.h @@ -15,7 +15,7 @@ #include "gfxFontVariations.h" #include "mozilla/FontPropertyTypes.h" #include "mozilla/RefPtr.h" // for RefPtr -#include "nsColor.h" // for nsColor and NS_RGBA +#include "mozilla/StyleColorInlines.h" // for StyleRGBA #include "nsCoord.h" // for nscoord #include "nsTArray.h" // for nsTArray @@ -51,7 +51,8 @@ struct nsFont { // The estimated background color behind the text. Enables a special // rendering mode when NS_GET_A(.) > 0. Only used for text in the chrome. - nscolor fontSmoothingBackgroundColor = NS_RGBA(0, 0, 0, 0); + mozilla::StyleRGBA fontSmoothingBackgroundColor = + mozilla::StyleRGBA::Transparent(); // Language system tag, to override document language; // this is an OpenType "language system" tag represented as a 32-bit integer diff --git a/gfx/thebes/gfxUtils.cpp b/gfx/thebes/gfxUtils.cpp index 89a91dd4fb8b..2e52124e729c 100644 --- a/gfx/thebes/gfxUtils.cpp +++ b/gfx/thebes/gfxUtils.cpp @@ -1565,5 +1565,9 @@ Color ToDeviceColor(nscolor aColor) { return ToDeviceColor(Color::FromABGR(aColor)); } +Color ToDeviceColor(const StyleRGBA& aColor) { + return ToDeviceColor(aColor.ToColor()); +} + } // namespace gfx } // namespace mozilla diff --git a/gfx/thebes/gfxUtils.h b/gfx/thebes/gfxUtils.h index 46e5d497df03..54ad7afc9937 100644 --- a/gfx/thebes/gfxUtils.h +++ b/gfx/thebes/gfxUtils.h @@ -327,6 +327,9 @@ class gfxUtils { }; namespace mozilla { + +struct StyleRGBA; + namespace gfx { /** @@ -337,6 +340,7 @@ namespace gfx { * applicable). */ Color ToDeviceColor(Color aColor); +Color ToDeviceColor(const StyleRGBA& aColor); Color ToDeviceColor(nscolor aColor); /** diff --git a/layout/generic/nsCanvasFrame.cpp b/layout/generic/nsCanvasFrame.cpp index d087c7e88ba8..96d34dd4e57b 100644 --- a/layout/generic/nsCanvasFrame.cpp +++ b/layout/generic/nsCanvasFrame.cpp @@ -635,13 +635,8 @@ void nsCanvasFrame::PaintFocus(DrawTarget* aDrawTarget, nsPoint aPt) { // for HTML documents? nsIFrame* root = mFrames.FirstChild(); const nsStyleColor* color = root ? root->StyleColor() : StyleColor(); - if (!color) { - NS_ERROR("current color cannot be found"); - return; - } - nsCSSRendering::PaintFocus(PresContext(), aDrawTarget, focusRect, - color->mColor); + color->mColor.ToColor()); } /* virtual */ diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index 70f7d42c1fa7..b44c8fa162e9 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -1156,7 +1156,7 @@ void nsImageFrame::DisplayAltText(nsPresContext* aPresContext, const nsString& aAltText, const nsRect& aRect) { // Set font and color - aRenderingContext.SetColor(Color::FromABGR(StyleColor()->mColor)); + aRenderingContext.SetColor(Color::FromABGR(StyleColor()->mColor.ToColor())); RefPtr fm = nsLayoutUtils::GetInflatedFontMetricsForFrame(this); diff --git a/layout/painting/nsDisplayList.cpp b/layout/painting/nsDisplayList.cpp index 1e290fa0516c..4ebcd4a161e6 100644 --- a/layout/painting/nsDisplayList.cpp +++ b/layout/painting/nsDisplayList.cpp @@ -461,17 +461,8 @@ static void SetAnimatable(nsCSSPropertyID aProperty, case eCSSProperty_background_color: { // We don't support color animation on the compositor yet so that we can // resolve currentColor at this moment. - nscolor foreground; - if (aFrame->Style()->RelevantLinkVisited()) { - if (ComputedStyle* styleIfVisited = - aFrame->Style()->GetStyleIfVisited()) { - foreground = styleIfVisited->StyleColor()->mColor; - } else { - foreground = aFrame->Style()->StyleColor()->mColor; - } - } else { - foreground = aFrame->Style()->StyleColor()->mColor; - } + nscolor foreground = + aFrame->Style()->GetVisitedDependentColor(&nsStyleColor::mColor); aAnimatable = aAnimationValue.GetColor(foreground); break; } diff --git a/layout/style/ComputedStyle.cpp b/layout/style/ComputedStyle.cpp index d7a8e1153570..da3a3284c96f 100644 --- a/layout/style/ComputedStyle.cpp +++ b/layout/style/ComputedStyle.cpp @@ -278,8 +278,8 @@ static nscolor GetVisitedDependentColorInternal(ComputedStyle* aSc, } static nscolor ExtractColor(const ComputedStyle& aStyle, - const nscolor& aColor) { - return aColor; + const StyleRGBA& aColor) { + return aColor.ToColor(); } static nscolor ExtractColor(const ComputedStyle& aStyle, diff --git a/layout/style/StyleColor.cpp b/layout/style/StyleColor.cpp index fff232a1091d..06ee03e15285 100644 --- a/layout/style/StyleColor.cpp +++ b/layout/style/StyleColor.cpp @@ -15,21 +15,21 @@ namespace mozilla { // Blend one RGBA color with another based on a given ratios. // It is a linear combination of each channel with alpha premultipled. -static nscolor LinearBlendColors(nscolor aBg, float aBgRatio, nscolor aFg, - float aFgRatio) { +static nscolor LinearBlendColors(const StyleRGBA& aBg, float aBgRatio, + const StyleRGBA& aFg, float aFgRatio) { constexpr float kFactor = 1.0f / 255.0f; float p1 = aBgRatio; - float a1 = kFactor * NS_GET_A(aBg); - float r1 = a1 * NS_GET_R(aBg); - float g1 = a1 * NS_GET_G(aBg); - float b1 = a1 * NS_GET_B(aBg); + float a1 = kFactor * aBg.alpha; + float r1 = a1 * aBg.red; + float g1 = a1 * aBg.green; + float b1 = a1 * aBg.blue; float p2 = aFgRatio; - float a2 = kFactor * NS_GET_A(aFg); - float r2 = a2 * NS_GET_R(aFg); - float g2 = a2 * NS_GET_G(aFg); - float b2 = a2 * NS_GET_B(aFg); + float a2 = kFactor * aFg.alpha; + float r2 = a2 * aFg.red; + float g2 = a2 * aFg.green; + float b2 = a2 * aFg.blue; float a = p1 * a1 + p2 * a2; if (a <= 0.f) { @@ -55,21 +55,22 @@ bool StyleColor::MaybeTransparent() const { return !IsNumeric() || AsNumeric().alpha != 255; } -static nscolor RGBAToNSColor(const StyleRGBA& aRGBA) { - return NS_RGBA(aRGBA.red, aRGBA.green, aRGBA.blue, aRGBA.alpha); +template <> +nscolor StyleColor::CalcColor(nscolor aColor) const { + return CalcColor(StyleRGBA::FromColor(aColor)); } template <> -nscolor StyleColor::CalcColor(nscolor aForegroundColor) const { +nscolor StyleColor::CalcColor(const StyleRGBA& aForegroundColor) const { if (IsNumeric()) { - return RGBAToNSColor(AsNumeric()); + return AsNumeric().ToColor(); } if (IsCurrentColor()) { - return aForegroundColor; + return aForegroundColor.ToColor(); } MOZ_ASSERT(IsComplex()); const auto& complex = AsComplex(); - return LinearBlendColors(RGBAToNSColor(complex.color), complex.ratios.bg, + return LinearBlendColors(complex.color, complex.ratios.bg, aForegroundColor, complex.ratios.fg); } @@ -79,11 +80,9 @@ nscolor StyleColor::CalcColor(const ComputedStyle& aStyle) const { // can skip resolving StyleColor(). // TODO(djg): Is this optimization worth it? if (IsNumeric()) { - return RGBAToNSColor(AsNumeric()); + return AsNumeric().ToColor(); } - - auto fgColor = aStyle.StyleColor()->mColor; - return CalcColor(fgColor); + return CalcColor(aStyle.StyleColor()->mColor); } template <> diff --git a/layout/style/StyleColorInlines.h b/layout/style/StyleColorInlines.h index 70841575b482..51633f118a85 100644 --- a/layout/style/StyleColorInlines.h +++ b/layout/style/StyleColorInlines.h @@ -14,10 +14,20 @@ namespace mozilla { +inline StyleRGBA StyleRGBA::FromColor(nscolor aColor) { + return {NS_GET_R(aColor), NS_GET_G(aColor), NS_GET_B(aColor), + NS_GET_A(aColor)}; +} + +inline nscolor StyleRGBA::ToColor() const { + return NS_RGBA(red, green, blue, alpha); +} + +inline StyleRGBA StyleRGBA::Transparent() { return {0, 0, 0, 0}; } + template <> inline StyleColor StyleColor::FromColor(nscolor aColor) { - return StyleColor::Numeric( - {NS_GET_R(aColor), NS_GET_G(aColor), NS_GET_B(aColor), NS_GET_A(aColor)}); + return StyleColor::Numeric(StyleRGBA::FromColor(aColor)); } template <> @@ -36,7 +46,10 @@ inline StyleColor StyleColor::Transparent() { } template <> -nscolor StyleColor::CalcColor(nscolor aForegroundColor) const; +nscolor StyleColor::CalcColor(const StyleRGBA&) const; + +template <> +nscolor StyleColor::CalcColor(nscolor) const; template <> nscolor StyleColor::CalcColor(const ComputedStyle&) const; diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index b6e3192f87b5..c58f49bccf31 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -1047,7 +1047,7 @@ void nsComputedDOMStyle::SetValueFromComplexColor( already_AddRefed nsComputedDOMStyle::DoGetColor() { RefPtr val = new nsROCSSPrimitiveValue; - SetToRGBAColor(val, StyleColor()->mColor); + SetToRGBAColor(val, StyleColor()->mColor.ToColor()); return val.forget(); } @@ -2142,7 +2142,7 @@ static_assert(NS_STYLE_UNICODE_BIDI_NORMAL == 0, already_AddRefed nsComputedDOMStyle::DoGetCaretColor() { RefPtr val = new nsROCSSPrimitiveValue; if (StyleUI()->mCaretColor.IsAuto()) { - SetToRGBAColor(val, StyleColor()->mColor); + SetToRGBAColor(val, StyleColor()->mColor.ToColor()); } else { SetValueFromComplexColor(val, StyleUI()->mCaretColor.AsColor()); } diff --git a/layout/style/nsStyleStruct.cpp b/layout/style/nsStyleStruct.cpp index f2a294a73288..eac5a4fd1944 100644 --- a/layout/style/nsStyleStruct.cpp +++ b/layout/style/nsStyleStruct.cpp @@ -1672,8 +1672,9 @@ nsChangeHint nsStyleTableBorder::CalcDifference( // nsStyleColor // -static nscolor DefaultColor(const Document& aDocument) { - return PreferenceSheet::PrefsFor(aDocument).mDefaultColor; +static StyleRGBA DefaultColor(const Document& aDocument) { + return + StyleRGBA::FromColor(PreferenceSheet::PrefsFor(aDocument).mDefaultColor); } nsStyleColor::nsStyleColor(const Document& aDocument) diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h index 1ea1cb5bbb00..e0378504d128 100644 --- a/layout/style/nsStyleStruct.h +++ b/layout/style/nsStyleStruct.h @@ -466,7 +466,9 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleColor { // Don't add ANY members to this struct! We can achieve caching in the rule // tree (rather than the style tree) by letting color stay by itself! -dwh - nscolor mColor; + // + // FIXME(emilio): Not sure having color in its own struct is worth it anymore. + mozilla::StyleRGBA mColor; }; struct nsStyleImageLayers { diff --git a/layout/svg/nsFilterInstance.cpp b/layout/svg/nsFilterInstance.cpp index f04926738411..eb89a8a58bc0 100644 --- a/layout/svg/nsFilterInstance.cpp +++ b/layout/svg/nsFilterInstance.cpp @@ -601,7 +601,8 @@ nsresult nsFilterInstance::BuildPrimitivesForFilter( // If we don't have a frame, use opaque black for shadows with unspecified // shadow colors. nscolor shadowFallbackColor = - mTargetFrame ? mTargetFrame->StyleColor()->mColor : NS_RGB(0, 0, 0); + mTargetFrame ? mTargetFrame->StyleColor()->mColor.ToColor() + : NS_RGB(0, 0, 0); nsCSSFilterInstance cssFilterInstance( aFilter, shadowFallbackColor, mTargetBounds, @@ -704,8 +705,7 @@ void nsFilterInstance::BuildSourceImage(DrawTarget* aDest, SurfaceFormat format = SurfaceFormat::B8G8R8A8; if (aDest->CanCreateSimilarDrawTarget(neededRect.Size(), format)) { offscreenDT = aDest->CreateSimilarDrawTargetForFilter( - neededRect.Size(), format, aFilter, aSource, aSourceRect, - Point(0, 0)); + neededRect.Size(), format, aFilter, aSource, aSourceRect, Point(0, 0)); } if (!offscreenDT || !offscreenDT->IsValid()) { return; diff --git a/layout/xul/nsTextBoxFrame.cpp b/layout/xul/nsTextBoxFrame.cpp index 574259a71d3b..739acb9c8a22 100644 --- a/layout/xul/nsTextBoxFrame.cpp +++ b/layout/xul/nsTextBoxFrame.cpp @@ -284,7 +284,7 @@ void nsDisplayXULTextBox::Paint(nsDisplayListBuilder* aBuilder, nsRect drawRect = static_cast(mFrame)->mTextDrawRect + ToReferenceFrame(); nsLayoutUtils::PaintTextShadow(mFrame, aCtx, drawRect, GetPaintRect(), - mFrame->StyleColor()->mColor, + mFrame->StyleColor()->mColor.ToColor(), PaintTextShadowCallback, (void*)this); PaintTextToContext(aCtx, nsPoint(0, 0), nullptr); @@ -489,7 +489,7 @@ void nsTextBoxFrame::DrawText(gfxContext& aRenderingContext, CalculateUnderline(refDrawTarget, *fontMet); - nscolor c = aOverrideColor ? *aOverrideColor : StyleColor()->mColor; + nscolor c = aOverrideColor ? *aOverrideColor : StyleColor()->mColor.ToColor(); ColorPattern color(ToDeviceColor(c)); aRenderingContext.SetColor(Color::FromABGR(c)); diff --git a/layout/xul/tree/nsTreeBodyFrame.cpp b/layout/xul/tree/nsTreeBodyFrame.cpp index 9df05868bcc2..59101afd6a00 100644 --- a/layout/xul/tree/nsTreeBodyFrame.cpp +++ b/layout/xul/tree/nsTreeBodyFrame.cpp @@ -3485,7 +3485,7 @@ ImgDrawResult nsTreeBodyFrame::PaintText( } aRenderingContext.SetColor( - Color::FromABGR(textContext->StyleColor()->mColor)); + Color::FromABGR(textContext->StyleColor()->mColor.ToColor())); nsLayoutUtils::DrawString( this, *fontMet, &aRenderingContext, text.get(), text.Length(), textRect.TopLeft() + nsPoint(0, baseline), cellContext); diff --git a/servo/components/style/properties/gecko.mako.rs b/servo/components/style/properties/gecko.mako.rs index 44b76f28b5a3..837a295fb604 100644 --- a/servo/components/style/properties/gecko.mako.rs +++ b/servo/components/style/properties/gecko.mako.rs @@ -40,8 +40,6 @@ use crate::gecko_bindings::structs::nsCSSPropertyID; use crate::gecko_bindings::structs::mozilla::PseudoStyleType; use crate::gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordDataMut}; use crate::gecko_bindings::sugar::refptr::RefPtr; -use crate::gecko::values::convert_nscolor_to_rgba; -use crate::gecko::values::convert_rgba_to_nscolor; use crate::gecko::values::GeckoStyleCoordConvertible; use crate::gecko::values::round_border_to_device_pixels; use crate::logical_geometry::WritingMode; @@ -421,18 +419,6 @@ def set_gecko_property(ffi_name, expr): } -<%def name="impl_rgba_color(ident, gecko_ffi_name)"> - #[allow(non_snake_case)] - pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) { - ${set_gecko_property(gecko_ffi_name, "convert_rgba_to_nscolor(&v)")} - } - <%call expr="impl_simple_copy(ident, gecko_ffi_name)"> - #[allow(non_snake_case)] - pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { - convert_nscolor_to_rgba(${get_gecko_property(gecko_ffi_name)}) - } - - <%def name="impl_svg_length(ident, gecko_ffi_name)"> // When context-value is used on an SVG length, the corresponding flag is // set on mContextFlags, and the length field is set to the initial value. @@ -1206,7 +1192,6 @@ impl Clone for ${style_struct.gecko_struct_name} { predefined_types = { "length::NonNegativeLengthPercentageOrNormal": impl_style_coord, "MozScriptMinSize": impl_absolute_length, - "RGBAColor": impl_rgba_color, "SVGLength": impl_svg_length, "SVGOpacity": impl_svg_opacity, "SVGPaint": impl_svg_paint, @@ -4343,8 +4328,7 @@ clip-path } -<%self:impl_trait style_struct_name="Color" skip_longhands="color"> - ${impl_rgba_color("color", "mColor")} +<%self:impl_trait style_struct_name="Color"> <%self:impl_trait style_struct_name="InheritedUI" skip_longhands="cursor"> diff --git a/servo/components/style/properties/longhands/background.mako.rs b/servo/components/style/properties/longhands/background.mako.rs index c6a25be53c19..42344a18cb9c 100644 --- a/servo/components/style/properties/longhands/background.mako.rs +++ b/servo/components/style/properties/longhands/background.mako.rs @@ -9,7 +9,7 @@ ${helpers.predefined_type( "background-color", "Color", - "computed_value::T::transparent()", + "computed::Color::transparent()", initial_specified_value="SpecifiedValue::transparent()", spec="https://drafts.csswg.org/css-backgrounds/#background-color", animation_value_type="AnimatedColor", diff --git a/servo/components/style/properties/longhands/font.mako.rs b/servo/components/style/properties/longhands/font.mako.rs index b253fde0b8dd..7f7b66c35727 100644 --- a/servo/components/style/properties/longhands/font.mako.rs +++ b/servo/components/style/properties/longhands/font.mako.rs @@ -521,9 +521,9 @@ ${helpers.single_keyword( ${helpers.predefined_type( "-moz-font-smoothing-background-color", - "RGBAColor", - "RGBA::transparent()", - animation_value_type="AnimatedRGBA", + "color::MozFontSmoothingBackgroundColor", + "computed::color::MozFontSmoothingBackgroundColor::transparent()", + animation_value_type="none", products="gecko", gecko_ffi_name="mFont.fontSmoothingBackgroundColor", enabled_in="chrome", diff --git a/servo/components/style/properties/properties.mako.rs b/servo/components/style/properties/properties.mako.rs index 5390c8e8270e..99a91179150c 100644 --- a/servo/components/style/properties/properties.mako.rs +++ b/servo/components/style/properties/properties.mako.rs @@ -1287,32 +1287,6 @@ impl LonghandId { LonghandId::Direction ) } - - /// Whether computed values of this property lossily convert any complex - /// colors into RGBA colors. - /// - /// In Gecko, there are some properties still that compute currentcolor - /// down to an RGBA color at computed value time, instead of as - /// `StyleColor`s. For these properties, we must return `false`, - /// so that we correctly avoid caching style data in the rule tree. - pub fn stores_complex_colors_lossily(&self) -> bool { - % if product == "gecko": - matches!(*self, - % for property in data.longhands: - % if property.predefined_type == "RGBAColor": - LonghandId::${property.camel_case} | - % endif - % endfor - LonghandId::BackgroundImage | - LonghandId::BorderImageSource | - LonghandId::BoxShadow | - LonghandId::MaskImage | - LonghandId::TextShadow - ) - % else: - false - % endif - } } /// An iterator over all the property ids that are enabled for a given diff --git a/servo/components/style/values/computed/color.rs b/servo/components/style/values/computed/color.rs index ade384a99ad5..6098ea4590ea 100644 --- a/servo/components/style/values/computed/color.rs +++ b/servo/components/style/values/computed/color.rs @@ -11,14 +11,14 @@ use cssparser::{Color as CSSParserColor, RGBA}; use std::fmt; use style_traits::{CssWriter, ToCss}; -/// Computed value type for the specified RGBAColor. -pub type RGBAColor = RGBA; - /// The computed value of the `color` property. pub type ColorPropertyValue = RGBA; +/// The computed value of `-moz-font-smoothing-background-color`. +pub type MozFontSmoothingBackgroundColor = RGBA; + /// A computed value for ``. -pub type Color = GenericColor; +pub type Color = GenericColor; impl Color { /// Returns a complex color value representing transparent. diff --git a/servo/components/style/values/computed/mod.rs b/servo/components/style/values/computed/mod.rs index 4c92218e69bb..95a9806f3592 100644 --- a/servo/components/style/values/computed/mod.rs +++ b/servo/components/style/values/computed/mod.rs @@ -43,7 +43,7 @@ pub use self::box_::{Appearance, BreakBetween, BreakWithin, Clear, Float}; pub use self::box_::{Display, Overflow, OverflowAnchor, TransitionProperty}; pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize}; pub use self::box_::{ScrollSnapAlign, ScrollSnapType, TouchAction, VerticalAlign, WillChange}; -pub use self::color::{Color, ColorOrAuto, ColorPropertyValue, RGBAColor}; +pub use self::color::{Color, ColorOrAuto, ColorPropertyValue}; pub use self::column::ColumnCount; pub use self::counters::{Content, ContentItem, CounterIncrement, CounterSetOrReset}; pub use self::easing::TimingFunction; diff --git a/servo/components/style/values/specified/color.rs b/servo/components/style/values/specified/color.rs index 00a2033ef2a0..25e7af6b98bd 100644 --- a/servo/components/style/values/specified/color.rs +++ b/servo/components/style/values/specified/color.rs @@ -373,15 +373,7 @@ impl ToComputedValue for Color { type ComputedValue = ComputedColor; fn to_computed_value(&self, context: &Context) -> ComputedColor { - let result = self.to_computed_color(Some(context)).unwrap(); - if !result.is_numeric() { - if let Some(longhand) = context.for_non_inherited_property { - if longhand.stores_complex_colors_lossily() { - context.rule_cache_conditions.borrow_mut().set_uncacheable(); - } - } - } - result + self.to_computed_color(Some(context)).unwrap() } fn from_computed_value(computed: &ComputedColor) -> Self { @@ -393,37 +385,33 @@ impl ToComputedValue for Color { } } -/// Specified color value, but resolved to just RGBA for computed value -/// with value from color property at the same context. +/// Specified color value for `-moz-font-smoothing-background-color`. +/// +/// This property does not support `currentcolor`. We could drop it at +/// parse-time, but it's not exposed to the web so it doesn't really matter. +/// +/// We resolve it to `transparent` instead. #[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)] -pub struct RGBAColor(pub Color); +pub struct MozFontSmoothingBackgroundColor(pub Color); -impl Parse for RGBAColor { +impl Parse for MozFontSmoothingBackgroundColor { fn parse<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - Color::parse(context, input).map(RGBAColor) + Color::parse(context, input).map(MozFontSmoothingBackgroundColor) } } -impl ToComputedValue for RGBAColor { +impl ToComputedValue for MozFontSmoothingBackgroundColor { type ComputedValue = RGBA; fn to_computed_value(&self, context: &Context) -> RGBA { - self.0 - .to_computed_value(context) - .to_rgba(context.style().get_color().clone_color()) + self.0.to_computed_value(context).to_rgba(RGBA::transparent()) } fn from_computed_value(computed: &RGBA) -> Self { - RGBAColor(Color::rgba(*computed)) - } -} - -impl From for RGBAColor { - fn from(color: Color) -> RGBAColor { - RGBAColor(color) + MozFontSmoothingBackgroundColor(Color::rgba(*computed)) } } diff --git a/servo/components/style/values/specified/mod.rs b/servo/components/style/values/specified/mod.rs index 30f80fd44c2b..93f9eca23b60 100644 --- a/servo/components/style/values/specified/mod.rs +++ b/servo/components/style/values/specified/mod.rs @@ -42,7 +42,7 @@ pub use self::box_::{Clear, Float, Overflow, OverflowAnchor}; pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize}; pub use self::box_::{ScrollSnapAlign, ScrollSnapType}; pub use self::box_::{TouchAction, TransitionProperty, VerticalAlign, WillChange}; -pub use self::color::{Color, ColorOrAuto, ColorPropertyValue, RGBAColor}; +pub use self::color::{Color, ColorOrAuto, ColorPropertyValue}; pub use self::column::ColumnCount; pub use self::counters::{Content, ContentItem, CounterIncrement, CounterSetOrReset}; pub use self::easing::TimingFunction; diff --git a/servo/ports/geckolib/cbindgen.toml b/servo/ports/geckolib/cbindgen.toml index 673d1dbd0ee5..2ef7975a50ff 100644 --- a/servo/ports/geckolib/cbindgen.toml +++ b/servo/ports/geckolib/cbindgen.toml @@ -310,4 +310,12 @@ renaming_overrides_prefixing = true * Compute the final color, making the argument the foreground color. */ nscolor CalcColor(nscolor) const; + nscolor CalcColor(const StyleRGBA&) const; +""" + +"RGBA" = """ + static inline StyleRGBA Transparent(); + static inline StyleRGBA FromColor(nscolor); + + inline nscolor ToColor() const; """