Bug 1467621 - P1: nsCSSShadowItem - Change nscolor to StyleComplexColor. r=xidorn

MozReview-Commit-ID: moE2CI7fT8

--HG--
extra : rebase_source : 7b64beccbd4c499d93567d62b913257dfa53c9fe
This commit is contained in:
Dan Glastonbury 2018-06-19 14:18:33 +10:00
Родитель 0308aa001d
Коммит 334258d77f
16 изменённых файлов: 69 добавлений и 99 удалений

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

@ -6121,11 +6121,7 @@ nsLayoutUtils::PaintTextShadow(const nsIFrame* aFrame,
nsPresContext* presCtx = aFrame->PresContext();
nsContextBoxBlur contextBoxBlur;
nscolor shadowColor;
if (shadowDetails->mHasColor)
shadowColor = shadowDetails->mColor;
else
shadowColor = aForegroundColor;
nscolor shadowColor = shadowDetails->mColor.CalcColor(aForegroundColor);
// Webrender just needs the shadow details
if (auto* textDrawer = aContext->GetTextDrawer()) {

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

@ -6246,8 +6246,8 @@ nsTextFrame::PaintOneShadow(const PaintShadowParams& aParams,
gfx::Point shadowOffset(aShadowDetails->mXOffset, aShadowDetails->mYOffset);
nscoord blurRadius = std::max(aShadowDetails->mRadius, 0);
nscolor shadowColor = aShadowDetails->mHasColor ? aShadowDetails->mColor
: aParams.foregroundColor;
nscolor shadowColor =
aShadowDetails->mColor.CalcColor(aParams.foregroundColor);
if (auto* textDrawer = aParams.context->GetTextDrawer()) {
wr::Shadow wrShadow;

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

@ -1520,12 +1520,7 @@ nsCSSRendering::GetShadowColor(nsCSSShadowItem* aShadow,
float aOpacity)
{
// Get the shadow color; if not specified, use the foreground color
nscolor shadowColor;
if (aShadow->mHasColor)
shadowColor = aShadow->mColor;
else
shadowColor = aFrame->StyleColor()->mColor;
nscolor shadowColor = aShadow->mColor.CalcColor(aFrame);
Color color = Color::FromABGR(shadowColor);
color.a *= aOpacity;
return color;

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

@ -9844,10 +9844,7 @@ nsDisplayFilter::CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuild
}
nsCSSShadowItem* shadow = shadows->ShadowAt(0);
nscolor color = shadow->mColor;
if (!shadow->mHasColor) {
color = mFrame->StyleColor()->mColor;
}
nscolor color = shadow->mColor.CalcColor(mFrame);
mozilla::wr::WrFilterOp filterOp = {
wr::ToWrFilterOpType(filter.GetType()),

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

@ -56,23 +56,34 @@ StyleComplexColor::MaybeTransparent() const {
return mTag != eNumeric || NS_GET_A(mColor) != 255;
}
nscolor
StyleComplexColor::CalcColor(nscolor aForegroundColor) const {
switch (mTag) {
case eNumeric:
return mColor;
case eForeground:
case eAuto:
return aForegroundColor;
case eComplex:
return LinearBlendColors(mColor, mBgRatio, aForegroundColor, mFgRatio);
default:
MOZ_ASSERT_UNREACHABLE("StyleComplexColor has invalid mTag");
return mColor;
}
}
nscolor
StyleComplexColor::CalcColor(mozilla::ComputedStyle* aStyle) const {
// Common case that is numeric color, which is pure background, we
// can skip resolving StyleColor().
// TODO(djg): Is this optimization worth it?
if (mTag == eNumeric) {
return mColor;
}
MOZ_ASSERT(aStyle);
auto fgColor = aStyle->StyleColor()->mColor;
if (mTag == eComplex) {
return LinearBlendColors(mColor, mBgRatio, fgColor, mFgRatio);
}
// eForeground and eAuto return the currentcolor.
return fgColor;
return CalcColor(fgColor);
}
nscolor

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

@ -72,6 +72,12 @@ public:
*/
bool MaybeTransparent() const;
/**
* Compute the color for this StyleComplexColor, taking into account
* the foreground color, aForegroundColor.
*/
nscolor CalcColor(nscolor aForegroundColor) const;
/**
* Compute the color for this StyleComplexColor, taking into account
* the foreground color from aStyle.

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

@ -3903,7 +3903,6 @@ nsComputedDOMStyle::GetEllipseRadii(const nsStyleCorners& aRadius,
already_AddRefed<CSSValue>
nsComputedDOMStyle::GetCSSShadowArray(nsCSSShadowArray* aArray,
const nscolor& aDefaultColor,
bool aIsBoxShadow)
{
if (!aArray) {
@ -3944,13 +3943,7 @@ nsComputedDOMStyle::GetCSSShadowArray(nsCSSShadowArray* aArray,
// Color is either the specified shadow color or the foreground color
RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
nscolor shadowColor;
if (item->mHasColor) {
shadowColor = item->mColor;
} else {
shadowColor = aDefaultColor;
}
SetToRGBAColor(val, shadowColor);
SetValueFromComplexColor(val, item->mColor);
itemList->AppendCSSValue(val.forget());
// Set the offsets, blur radius, and spread if available
@ -3988,9 +3981,7 @@ nsComputedDOMStyle::DoGetBoxDecorationBreak()
already_AddRefed<CSSValue>
nsComputedDOMStyle::DoGetBoxShadow()
{
return GetCSSShadowArray(StyleEffects()->mBoxShadow,
StyleColor()->mColor,
true);
return GetCSSShadowArray(StyleEffects()->mBoxShadow, true);
}
already_AddRefed<CSSValue>
@ -4381,9 +4372,7 @@ nsComputedDOMStyle::DoGetTextOverflow()
already_AddRefed<CSSValue>
nsComputedDOMStyle::DoGetTextShadow()
{
return GetCSSShadowArray(StyleText()->mTextShadow,
StyleColor()->mColor,
false);
return GetCSSShadowArray(StyleText()->mTextShadow, false);
}
already_AddRefed<CSSValue>
@ -6671,9 +6660,7 @@ nsComputedDOMStyle::CreatePrimitiveValueForStyleFilter(
if (aStyleFilter.GetType() == NS_STYLE_FILTER_DROP_SHADOW) {
// Handle drop-shadow()
RefPtr<CSSValue> shadowValue =
GetCSSShadowArray(aStyleFilter.GetDropShadow(),
StyleColor()->mColor,
false);
GetCSSShadowArray(aStyleFilter.GetDropShadow(), false);
ErrorResult dummy;
shadowValue->GetCssText(argumentString, dummy);
} else {

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

@ -225,7 +225,6 @@ private:
bool GetLineHeightCoord(nscoord& aCoord);
already_AddRefed<CSSValue> GetCSSShadowArray(nsCSSShadowArray* aArray,
const nscolor& aDefaultColor,
bool aIsBoxShadow);
void GetCSSGradientString(const nsStyleGradient* aGradient,

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

@ -868,8 +868,7 @@ struct nsCSSShadowItem
nscoord mRadius;
nscoord mSpread;
nscolor mColor;
bool mHasColor; // Whether mColor should be used
mozilla::StyleComplexColor mColor;
bool mInset;
nsCSSShadowItem()
@ -877,8 +876,7 @@ struct nsCSSShadowItem
, mYOffset(0)
, mRadius(0)
, mSpread(0)
, mColor(NS_RGB(0, 0, 0))
, mHasColor(false)
, mColor(mozilla::StyleComplexColor::CurrentColor())
, mInset(false)
{
MOZ_COUNT_CTOR(nsCSSShadowItem);
@ -891,10 +889,9 @@ struct nsCSSShadowItem
return (mXOffset == aOther.mXOffset &&
mYOffset == aOther.mYOffset &&
mRadius == aOther.mRadius &&
mHasColor == aOther.mHasColor &&
mSpread == aOther.mSpread &&
mInset == aOther.mInset &&
(!mHasColor || mColor == aOther.mColor));
mColor == aOther.mColor);
}
bool operator!=(const nsCSSShadowItem& aOther) const {
return !(*this == aOther);

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

@ -934,10 +934,10 @@ var filterTests = [
expected: ["drop-shadow", "rgb(66, 96, 0) 5px 5px 2px"] },
{ start: "blur(25px) drop-shadow(8px 8px)",
end: "blur(75px)",
expected: ["blur", 37.5, "drop-shadow", "rgb(0, 0, 0) 6px 6px 0px"] },
expected: ["blur", 37.5, "drop-shadow", "rgba(0, 0, 0, 0.75) 6px 6px 0px"] },
{ start: "blur(75px)",
end: "blur(25px) drop-shadow(8px 8px)",
expected: ["blur", 62.5, "drop-shadow", "rgb(0, 0, 0) 2px 2px 0px"] },
expected: ["blur", 62.5, "drop-shadow", "rgba(0, 0, 0, 0.25) 2px 2px 0px"] },
{ start: "drop-shadow(2px 2px blue)",
end: "none",
expected: ["drop-shadow", "rgba(0, 0, 255, 0.75) 1.5px 1.5px 0px"] },
@ -1716,12 +1716,9 @@ function test_shadow_transition(prop) {
"shadow-valued property " + prop + ": computed value before transition");
div.style.setProperty("transition-property", prop, "");
div.style.setProperty(prop, "8px 8px 8px red", "");
// Bug 726550 for gecko (can't transition), bug 1390697 for servo (doesn't
// work currentColor animation for {text,box}-shadow).
todo_is(cs.getPropertyValue(prop),
"rgb(66, 0, 0) 3.5px 3.5px 3.5px" + spreadStr,
"shadow-valued property " + prop +
": interpolation values with/without color");
is(cs.getPropertyValue(prop), "rgb(66, 0, 0) 3.5px 3.5px 3.5px" + spreadStr,
"shadow-valued property " + prop +
": interpolation values with/without color");
// Transition beween values without color.
var defaultColor = cs.getPropertyValue("color") + " ";

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

@ -224,7 +224,7 @@ nsCSSFilterInstance::SetAttributesForDropShadow(FilterPrimitiveDescription& aDes
aDescr.Attributes().Set(eDropShadowOffset, offsetInFilterSpace);
// Set color. If unspecified, use the CSS color property.
nscolor shadowColor = shadow->mHasColor ? shadow->mColor : mShadowFallbackColor;
nscolor shadowColor = shadow->mColor.CalcColor(mShadowFallbackColor);
aDescr.Attributes().Set(eDropShadowColor, ToAttributeColor(shadowColor));
return NS_OK;

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

@ -5,9 +5,7 @@
//! Rust helpers for Gecko's `nsCSSShadowItem`.
use app_units::Au;
use gecko::values::{convert_nscolor_to_rgba, convert_rgba_to_nscolor};
use gecko_bindings::structs::nsCSSShadowItem;
use values::computed::RGBAColor;
use values::computed::effects::{BoxShadow, SimpleShadow};
impl nsCSSShadowItem {
@ -37,31 +35,14 @@ impl nsCSSShadowItem {
self.mRadius = shadow.blur.0.to_i32_au();
self.mSpread = 0;
self.mInset = false;
if let Some(color) = shadow.color {
self.mHasColor = true;
self.mColor = convert_rgba_to_nscolor(&color);
} else {
// TODO handle currentColor
// https://bugzilla.mozilla.org/show_bug.cgi?id=760345
self.mHasColor = false;
self.mColor = 0;
}
}
#[inline]
fn extract_color(&self) -> Option<RGBAColor> {
if self.mHasColor {
Some(convert_nscolor_to_rgba(self.mColor))
} else {
None
}
self.mColor = shadow.color.into();
}
/// Gets a simple shadow from this item.
#[inline]
fn extract_simple_shadow(&self) -> SimpleShadow {
SimpleShadow {
color: self.extract_color(),
color: self.mColor.into(),
horizontal: Au(self.mXOffset).into(),
vertical: Au(self.mYOffset).into(),
blur: Au(self.mRadius).into(),

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

@ -186,7 +186,7 @@ impl ComputeSquaredDistance for Color {
(Foreground, Foreground) => SquaredDistance::from_sqrt(0.),
(Numeric(c1), Numeric(c2)) => c1.compute_squared_distance(&c2)?,
(Foreground, Numeric(color)) | (Numeric(color), Foreground) => {
// `computed_squared_distance` is symmetic.
// `computed_squared_distance` is symmetric.
color.compute_squared_distance(&RGBA::transparent())?
+ SquaredDistance::from_sqrt(1.)
}
@ -207,7 +207,6 @@ impl ComputeSquaredDistance for Color {
impl ToAnimatedZero for Color {
#[inline]
fn to_animated_zero(&self) -> Result<Self, ()> {
// FIXME(nox): This does not look correct to me.
Err(())
Ok(RGBA::transparent().into())
}
}

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

@ -6,7 +6,7 @@
#[cfg(not(feature = "gecko"))]
use values::Impossible;
use values::animated::color::RGBA;
use values::animated::color::Color;
use values::computed::{Angle, Number};
use values::computed::length::Length;
#[cfg(feature = "gecko")]
@ -17,7 +17,7 @@ use values::generics::effects::Filter as GenericFilter;
use values::generics::effects::SimpleShadow as GenericSimpleShadow;
/// An animated value for a single `box-shadow`.
pub type BoxShadow = GenericBoxShadow<Option<RGBA>, Length, Length, Length>;
pub type BoxShadow = GenericBoxShadow<Color, Length, Length, Length>;
/// An animated value for a single `filter`.
#[cfg(feature = "gecko")]
@ -28,7 +28,7 @@ pub type Filter = GenericFilter<Angle, Number, Length, SimpleShadow, ComputedUrl
pub type Filter = GenericFilter<Angle, Number, Length, Impossible, Impossible>;
/// An animated value for the `drop-shadow()` filter.
pub type SimpleShadow = GenericSimpleShadow<Option<RGBA>, Length, Length>;
pub type SimpleShadow = GenericSimpleShadow<Color, Length, Length>;
impl ComputeSquaredDistance for BoxShadow {
#[inline]

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

@ -7,7 +7,7 @@
#[cfg(not(feature = "gecko"))]
use values::Impossible;
use values::computed::{Angle, NonNegativeNumber};
use values::computed::color::RGBAColor;
use values::computed::color::Color;
use values::computed::length::{Length, NonNegativeLength};
#[cfg(feature = "gecko")]
use values::computed::url::ComputedUrl;
@ -16,7 +16,7 @@ use values::generics::effects::Filter as GenericFilter;
use values::generics::effects::SimpleShadow as GenericSimpleShadow;
/// A computed value for a single shadow of the `box-shadow` property.
pub type BoxShadow = GenericBoxShadow<Option<RGBAColor>, Length, NonNegativeLength, Length>;
pub type BoxShadow = GenericBoxShadow<Color, Length, NonNegativeLength, Length>;
/// A computed value for a single `filter`.
#[cfg(feature = "gecko")]
@ -27,4 +27,4 @@ pub type Filter = GenericFilter<Angle, NonNegativeNumber, NonNegativeLength, Sim
pub type Filter = GenericFilter<Angle, NonNegativeNumber, NonNegativeLength, Impossible, Impossible>;
/// A computed value for the `drop-shadow()` filter.
pub type SimpleShadow = GenericSimpleShadow<Option<RGBAColor>, Length, NonNegativeLength>;
pub type SimpleShadow = GenericSimpleShadow<Color, Length, NonNegativeLength>;

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

@ -17,14 +17,14 @@ use values::generics::effects::BoxShadow as GenericBoxShadow;
use values::generics::effects::Filter as GenericFilter;
use values::generics::effects::SimpleShadow as GenericSimpleShadow;
use values::specified::{Angle, NumberOrPercentage};
use values::specified::color::RGBAColor;
use values::specified::color::Color;
use values::specified::length::{Length, NonNegativeLength};
#[cfg(feature = "gecko")]
use values::specified::url::SpecifiedUrl;
/// A specified value for a single shadow of the `box-shadow` property.
pub type BoxShadow =
GenericBoxShadow<Option<RGBAColor>, Length, Option<NonNegativeLength>, Option<Length>>;
GenericBoxShadow<Option<Color>, Length, Option<NonNegativeLength>, Option<Length>>;
/// A specified value for a single `filter`.
#[cfg(feature = "gecko")]
@ -93,7 +93,7 @@ impl ToComputedValue for Factor {
}
/// A specified value for the `drop-shadow()` filter.
pub type SimpleShadow = GenericSimpleShadow<Option<RGBAColor>, Length, Option<NonNegativeLength>>;
pub type SimpleShadow = GenericSimpleShadow<Option<Color>, Length, Option<NonNegativeLength>>;
impl Parse for BoxShadow {
fn parse<'i, 't>(
@ -135,7 +135,7 @@ impl Parse for BoxShadow {
}
}
if color.is_none() {
if let Ok(value) = input.try(|i| RGBAColor::parse(context, i)) {
if let Ok(value) = input.try(|i| Color::parse(context, i)) {
color = Some(value);
continue;
}
@ -249,16 +249,18 @@ impl Parse for SimpleShadow {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
let color = input.try(|i| RGBAColor::parse(context, i)).ok();
let color = input.try(|i| Color::parse(context, i)).ok();
let horizontal = Length::parse(context, input)?;
let vertical = Length::parse(context, input)?;
let blur = input.try(|i| Length::parse_non_negative(context, i)).ok();
let color = color.or_else(|| input.try(|i| RGBAColor::parse(context, i)).ok());
let blur = blur.map(NonNegative::<Length>);
let color = color.or_else(|| input.try(|i| Color::parse(context, i)).ok());
Ok(SimpleShadow {
color: color,
horizontal: horizontal,
vertical: vertical,
blur: blur.map(NonNegative::<Length>),
color,
horizontal,
vertical,
blur,
})
}
}
@ -269,7 +271,10 @@ impl ToComputedValue for SimpleShadow {
#[inline]
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
ComputedSimpleShadow {
color: self.color.to_computed_value(context),
color: self.color
.as_ref()
.unwrap_or(&Color::currentcolor())
.to_computed_value(context),
horizontal: self.horizontal.to_computed_value(context),
vertical: self.vertical.to_computed_value(context),
blur: self.blur
@ -282,7 +287,7 @@ impl ToComputedValue for SimpleShadow {
#[inline]
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
SimpleShadow {
color: ToComputedValue::from_computed_value(&computed.color),
color: Some(ToComputedValue::from_computed_value(&computed.color)),
horizontal: ToComputedValue::from_computed_value(&computed.horizontal),
vertical: ToComputedValue::from_computed_value(&computed.vertical),
blur: Some(ToComputedValue::from_computed_value(&computed.blur)),