mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: Change nscolor to StyleComplexColor in nsCSSShadowItem.
Bug: 1467621 Reviewed-by: xidorn MozReview-Commit-ID: moE2CI7fT8
This commit is contained in:
parent
9c243a115e
commit
a055e8af89
5 changed files with 27 additions and 42 deletions
|
@ -5,9 +5,7 @@
|
||||||
//! Rust helpers for Gecko's `nsCSSShadowItem`.
|
//! Rust helpers for Gecko's `nsCSSShadowItem`.
|
||||||
|
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use gecko::values::{convert_nscolor_to_rgba, convert_rgba_to_nscolor};
|
|
||||||
use gecko_bindings::structs::nsCSSShadowItem;
|
use gecko_bindings::structs::nsCSSShadowItem;
|
||||||
use values::computed::RGBAColor;
|
|
||||||
use values::computed::effects::{BoxShadow, SimpleShadow};
|
use values::computed::effects::{BoxShadow, SimpleShadow};
|
||||||
|
|
||||||
impl nsCSSShadowItem {
|
impl nsCSSShadowItem {
|
||||||
|
@ -37,31 +35,14 @@ impl nsCSSShadowItem {
|
||||||
self.mRadius = shadow.blur.0.to_i32_au();
|
self.mRadius = shadow.blur.0.to_i32_au();
|
||||||
self.mSpread = 0;
|
self.mSpread = 0;
|
||||||
self.mInset = false;
|
self.mInset = false;
|
||||||
if let Some(color) = shadow.color {
|
self.mColor = shadow.color.into();
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets a simple shadow from this item.
|
/// Gets a simple shadow from this item.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn extract_simple_shadow(&self) -> SimpleShadow {
|
fn extract_simple_shadow(&self) -> SimpleShadow {
|
||||||
SimpleShadow {
|
SimpleShadow {
|
||||||
color: self.extract_color(),
|
color: self.mColor.into(),
|
||||||
horizontal: Au(self.mXOffset).into(),
|
horizontal: Au(self.mXOffset).into(),
|
||||||
vertical: Au(self.mYOffset).into(),
|
vertical: Au(self.mYOffset).into(),
|
||||||
blur: Au(self.mRadius).into(),
|
blur: Au(self.mRadius).into(),
|
||||||
|
|
|
@ -186,7 +186,7 @@ impl ComputeSquaredDistance for Color {
|
||||||
(Foreground, Foreground) => SquaredDistance::from_sqrt(0.),
|
(Foreground, Foreground) => SquaredDistance::from_sqrt(0.),
|
||||||
(Numeric(c1), Numeric(c2)) => c1.compute_squared_distance(&c2)?,
|
(Numeric(c1), Numeric(c2)) => c1.compute_squared_distance(&c2)?,
|
||||||
(Foreground, Numeric(color)) | (Numeric(color), Foreground) => {
|
(Foreground, Numeric(color)) | (Numeric(color), Foreground) => {
|
||||||
// `computed_squared_distance` is symmetic.
|
// `computed_squared_distance` is symmetric.
|
||||||
color.compute_squared_distance(&RGBA::transparent())?
|
color.compute_squared_distance(&RGBA::transparent())?
|
||||||
+ SquaredDistance::from_sqrt(1.)
|
+ SquaredDistance::from_sqrt(1.)
|
||||||
}
|
}
|
||||||
|
@ -207,7 +207,6 @@ impl ComputeSquaredDistance for Color {
|
||||||
impl ToAnimatedZero for Color {
|
impl ToAnimatedZero for Color {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||||
// FIXME(nox): This does not look correct to me.
|
Ok(RGBA::transparent().into())
|
||||||
Err(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#[cfg(not(feature = "gecko"))]
|
#[cfg(not(feature = "gecko"))]
|
||||||
use values::Impossible;
|
use values::Impossible;
|
||||||
use values::animated::color::RGBA;
|
use values::animated::color::Color;
|
||||||
use values::computed::{Angle, Number};
|
use values::computed::{Angle, Number};
|
||||||
use values::computed::length::Length;
|
use values::computed::length::Length;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
|
@ -17,7 +17,7 @@ use values::generics::effects::Filter as GenericFilter;
|
||||||
use values::generics::effects::SimpleShadow as GenericSimpleShadow;
|
use values::generics::effects::SimpleShadow as GenericSimpleShadow;
|
||||||
|
|
||||||
/// An animated value for a single `box-shadow`.
|
/// 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`.
|
/// An animated value for a single `filter`.
|
||||||
#[cfg(feature = "gecko")]
|
#[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>;
|
pub type Filter = GenericFilter<Angle, Number, Length, Impossible, Impossible>;
|
||||||
|
|
||||||
/// An animated value for the `drop-shadow()` filter.
|
/// 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 {
|
impl ComputeSquaredDistance for BoxShadow {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#[cfg(not(feature = "gecko"))]
|
#[cfg(not(feature = "gecko"))]
|
||||||
use values::Impossible;
|
use values::Impossible;
|
||||||
use values::computed::{Angle, NonNegativeNumber};
|
use values::computed::{Angle, NonNegativeNumber};
|
||||||
use values::computed::color::RGBAColor;
|
use values::computed::color::Color;
|
||||||
use values::computed::length::{Length, NonNegativeLength};
|
use values::computed::length::{Length, NonNegativeLength};
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use values::computed::url::ComputedUrl;
|
use values::computed::url::ComputedUrl;
|
||||||
|
@ -16,7 +16,7 @@ use values::generics::effects::Filter as GenericFilter;
|
||||||
use values::generics::effects::SimpleShadow as GenericSimpleShadow;
|
use values::generics::effects::SimpleShadow as GenericSimpleShadow;
|
||||||
|
|
||||||
/// A computed value for a single shadow of the `box-shadow` property.
|
/// 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`.
|
/// A computed value for a single `filter`.
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
|
@ -27,4 +27,4 @@ pub type Filter = GenericFilter<Angle, NonNegativeNumber, NonNegativeLength, Sim
|
||||||
pub type Filter = GenericFilter<Angle, NonNegativeNumber, NonNegativeLength, Impossible, Impossible>;
|
pub type Filter = GenericFilter<Angle, NonNegativeNumber, NonNegativeLength, Impossible, Impossible>;
|
||||||
|
|
||||||
/// A computed value for the `drop-shadow()` filter.
|
/// 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::Filter as GenericFilter;
|
||||||
use values::generics::effects::SimpleShadow as GenericSimpleShadow;
|
use values::generics::effects::SimpleShadow as GenericSimpleShadow;
|
||||||
use values::specified::{Angle, NumberOrPercentage};
|
use values::specified::{Angle, NumberOrPercentage};
|
||||||
use values::specified::color::RGBAColor;
|
use values::specified::color::Color;
|
||||||
use values::specified::length::{Length, NonNegativeLength};
|
use values::specified::length::{Length, NonNegativeLength};
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use values::specified::url::SpecifiedUrl;
|
use values::specified::url::SpecifiedUrl;
|
||||||
|
|
||||||
/// A specified value for a single shadow of the `box-shadow` property.
|
/// A specified value for a single shadow of the `box-shadow` property.
|
||||||
pub type BoxShadow =
|
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`.
|
/// A specified value for a single `filter`.
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
|
@ -93,7 +93,7 @@ impl ToComputedValue for Factor {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A specified value for the `drop-shadow()` filter.
|
/// 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 {
|
impl Parse for BoxShadow {
|
||||||
fn parse<'i, 't>(
|
fn parse<'i, 't>(
|
||||||
|
@ -135,7 +135,7 @@ impl Parse for BoxShadow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if color.is_none() {
|
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);
|
color = Some(value);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -249,16 +249,18 @@ impl Parse for SimpleShadow {
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<Self, ParseError<'i>> {
|
) -> 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 horizontal = Length::parse(context, input)?;
|
||||||
let vertical = Length::parse(context, input)?;
|
let vertical = Length::parse(context, input)?;
|
||||||
let blur = input.try(|i| Length::parse_non_negative(context, i)).ok();
|
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 {
|
Ok(SimpleShadow {
|
||||||
color: color,
|
color,
|
||||||
horizontal: horizontal,
|
horizontal,
|
||||||
vertical: vertical,
|
vertical,
|
||||||
blur: blur.map(NonNegative::<Length>),
|
blur,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -269,7 +271,10 @@ impl ToComputedValue for SimpleShadow {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||||
ComputedSimpleShadow {
|
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),
|
horizontal: self.horizontal.to_computed_value(context),
|
||||||
vertical: self.vertical.to_computed_value(context),
|
vertical: self.vertical.to_computed_value(context),
|
||||||
blur: self.blur
|
blur: self.blur
|
||||||
|
@ -282,7 +287,7 @@ impl ToComputedValue for SimpleShadow {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||||
SimpleShadow {
|
SimpleShadow {
|
||||||
color: ToComputedValue::from_computed_value(&computed.color),
|
color: Some(ToComputedValue::from_computed_value(&computed.color)),
|
||||||
horizontal: ToComputedValue::from_computed_value(&computed.horizontal),
|
horizontal: ToComputedValue::from_computed_value(&computed.horizontal),
|
||||||
vertical: ToComputedValue::from_computed_value(&computed.vertical),
|
vertical: ToComputedValue::from_computed_value(&computed.vertical),
|
||||||
blur: Some(ToComputedValue::from_computed_value(&computed.blur)),
|
blur: Some(ToComputedValue::from_computed_value(&computed.blur)),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue