mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Auto merge of #18459 - servo:kill-cvas, r=emilio
Kill ComputedValueAsSpecified 🔫 <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18459) <!-- Reviewable:end -->
This commit is contained in:
commit
b856f11388
8 changed files with 40 additions and 81 deletions
|
@ -316,7 +316,7 @@
|
|||
|
||||
% if not property.derived_from:
|
||||
match value {
|
||||
DeclaredValue::Value(ref specified_value) => {
|
||||
DeclaredValue::Value(specified_value) => {
|
||||
% if property.ident in SYSTEM_FONT_LONGHANDS and product == "gecko":
|
||||
if let Some(sf) = specified_value.get_system() {
|
||||
longhands::system_font::resolve_system_font(sf, context);
|
||||
|
@ -341,7 +341,11 @@
|
|||
}
|
||||
context.builder.put_${data.current_style_struct.name_lower}(s);
|
||||
% else:
|
||||
% if property.boxed:
|
||||
let computed = (**specified_value).to_computed_value(context);
|
||||
% else:
|
||||
let computed = specified_value.to_computed_value(context);
|
||||
% endif
|
||||
% if property.ident == "font_size":
|
||||
longhands::font_size::cascade_specified_font_size(
|
||||
context,
|
||||
|
|
|
@ -544,7 +544,11 @@ impl AnimationValue {
|
|||
longhands::system_font::resolve_system_font(sf, context);
|
||||
}
|
||||
% endif
|
||||
% if prop.boxed:
|
||||
let computed = (**val).to_computed_value(context);
|
||||
% else:
|
||||
let computed = val.to_computed_value(context);
|
||||
% endif
|
||||
Some(AnimationValue::${prop.camel_case}(
|
||||
% if prop.is_animatable_with_computed_value:
|
||||
computed
|
||||
|
|
|
@ -2014,15 +2014,10 @@ https://drafts.csswg.org/css-fonts-4/#low-level-font-variation-settings-control-
|
|||
animation_value_type="ComputedValue"
|
||||
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER"
|
||||
spec="${variation_spec}">
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
use values::generics::FontSettings;
|
||||
|
||||
impl ComputedValueAsSpecified for SpecifiedValue {}
|
||||
|
||||
pub type SpecifiedValue = computed_value::T;
|
||||
|
||||
|
||||
|
||||
pub mod computed_value {
|
||||
use values::generics::{FontSettings, FontSettingTagFloat};
|
||||
pub type T = FontSettings<FontSettingTagFloat>;
|
||||
|
|
|
@ -98,7 +98,6 @@ ${helpers.single_keyword("list-style-position", "outside inside", animation_valu
|
|||
<%helpers:longhand name="list-style-image" animation_value_type="discrete"
|
||||
boxed="${product == 'gecko'}"
|
||||
spec="https://drafts.csswg.org/css-lists/#propdef-list-style-image">
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
use values::specified::UrlOrNone;
|
||||
pub use self::computed_value::T as SpecifiedValue;
|
||||
|
||||
|
@ -108,11 +107,12 @@ ${helpers.single_keyword("list-style-position", "outside inside", animation_valu
|
|||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Debug, PartialEq, ToCss)]
|
||||
pub struct T(pub UrlOrNone);
|
||||
|
||||
// FIXME(nox): This is wrong, there are different types for specified
|
||||
// and computed URLs in Servo.
|
||||
trivial_to_computed_value!(T);
|
||||
}
|
||||
|
||||
|
||||
impl ComputedValueAsSpecified for SpecifiedValue {}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T(Either::Second(None_))
|
||||
|
|
|
@ -408,7 +408,7 @@ impl ToComputedValue for specified::LengthOrPercentage {
|
|||
LengthOrPercentage::Percentage(value)
|
||||
}
|
||||
specified::LengthOrPercentage::Calc(ref calc) => {
|
||||
LengthOrPercentage::Calc(calc.to_computed_value(context))
|
||||
LengthOrPercentage::Calc((**calc).to_computed_value(context))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -502,7 +502,7 @@ impl ToComputedValue for specified::LengthOrPercentageOrAuto {
|
|||
LengthOrPercentageOrAuto::Auto
|
||||
}
|
||||
specified::LengthOrPercentageOrAuto::Calc(ref calc) => {
|
||||
LengthOrPercentageOrAuto::Calc(calc.to_computed_value(context))
|
||||
LengthOrPercentageOrAuto::Calc((**calc).to_computed_value(context))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -591,7 +591,7 @@ impl ToComputedValue for specified::LengthOrPercentageOrNone {
|
|||
LengthOrPercentageOrNone::Percentage(value)
|
||||
}
|
||||
specified::LengthOrPercentageOrNone::Calc(ref calc) => {
|
||||
LengthOrPercentageOrNone::Calc(calc.to_computed_value(context))
|
||||
LengthOrPercentageOrNone::Calc((**calc).to_computed_value(context))
|
||||
}
|
||||
specified::LengthOrPercentageOrNone::None => {
|
||||
LengthOrPercentageOrNone::None
|
||||
|
|
|
@ -296,6 +296,22 @@ impl<T> ToComputedValue for Vec<T>
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> ToComputedValue for Box<T>
|
||||
where T: ToComputedValue
|
||||
{
|
||||
type ComputedValue = Box<<T as ToComputedValue>::ComputedValue>;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
Box::new(T::to_computed_value(self, context))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||
Box::new(T::from_computed_value(computed))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ToComputedValue for Box<[T]>
|
||||
where T: ToComputedValue
|
||||
{
|
||||
|
@ -312,32 +328,13 @@ impl<T> ToComputedValue for Box<[T]>
|
|||
}
|
||||
}
|
||||
|
||||
/// A marker trait to represent that the specified value is also the computed
|
||||
/// value.
|
||||
pub trait ComputedValueAsSpecified {}
|
||||
|
||||
impl<T> ToComputedValue for T
|
||||
where T: ComputedValueAsSpecified + Clone,
|
||||
{
|
||||
type ComputedValue = T;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, _context: &Context) -> T {
|
||||
self.clone()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &T) -> Self {
|
||||
computed.clone()
|
||||
}
|
||||
}
|
||||
|
||||
trivial_to_computed_value!(());
|
||||
trivial_to_computed_value!(bool);
|
||||
trivial_to_computed_value!(f32);
|
||||
trivial_to_computed_value!(i32);
|
||||
trivial_to_computed_value!(u8);
|
||||
trivial_to_computed_value!(u16);
|
||||
trivial_to_computed_value!(u32);
|
||||
trivial_to_computed_value!(Atom);
|
||||
trivial_to_computed_value!(BorderStyle);
|
||||
trivial_to_computed_value!(Cursor);
|
||||
|
|
|
@ -11,13 +11,12 @@ use cssparser::serialize_identifier;
|
|||
use custom_properties;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::computed::{Context, ToComputedValue};
|
||||
|
||||
/// An [image].
|
||||
///
|
||||
/// [image]: https://drafts.csswg.org/css-images/#image-values
|
||||
#[derive(Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, PartialEq, ToComputedValue)]
|
||||
pub enum Image<Gradient, MozImageRect, ImageUrl> {
|
||||
/// A `<url()>` image.
|
||||
Url(ImageUrl),
|
||||
|
@ -34,47 +33,6 @@ pub enum Image<Gradient, MozImageRect, ImageUrl> {
|
|||
PaintWorklet(PaintWorklet),
|
||||
}
|
||||
|
||||
// Can't just use derive(ToComputedValue) on Image, because when trying to do
|
||||
// "impl<T> ToComputedValue for Box<T>" the Rust compiler complains that
|
||||
// "impl<T> ToComputedValue for T where T: ComputedValueAsSpecified + Clone"
|
||||
// aleady implements ToComputedValue for std::boxed::Box<_> and hence we have
|
||||
// conflicting implementations.
|
||||
impl<Gradient: ToComputedValue,
|
||||
MozImageRect: ToComputedValue,
|
||||
ImageUrl: ToComputedValue> ToComputedValue for Image<Gradient, MozImageRect, ImageUrl> {
|
||||
type ComputedValue = Image<<Gradient as ToComputedValue>::ComputedValue,
|
||||
<MozImageRect as ToComputedValue>::ComputedValue,
|
||||
<ImageUrl as ToComputedValue>::ComputedValue>;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
match *self {
|
||||
Image::Url(ref url) => Image::Url(url.to_computed_value(context)),
|
||||
Image::Gradient(ref gradient) =>
|
||||
Image::Gradient(Box::new(gradient.to_computed_value(context))),
|
||||
Image::Rect(ref rect) => Image::Rect(Box::new(rect.to_computed_value(context))),
|
||||
Image::Element(ref atom) => Image::Element(atom.to_computed_value(context)),
|
||||
#[cfg(feature = "servo")]
|
||||
Image::PaintWorklet(ref worklet) => Image::PaintWorklet(worklet.to_computed_value(context)),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||
match *computed {
|
||||
Image::Url(ref url) => Image::Url(ImageUrl::from_computed_value(url)),
|
||||
Image::Gradient(ref boxed_gradient) =>
|
||||
Image::Gradient(Box::new(Gradient::from_computed_value(&*boxed_gradient))),
|
||||
Image::Rect(ref boxed_rect) =>
|
||||
Image::Rect(Box::new(MozImageRect::from_computed_value(&*boxed_rect))),
|
||||
Image::Element(ref atom) => Image::Element(Atom::from_computed_value(atom)),
|
||||
#[cfg(feature = "servo")]
|
||||
Image::PaintWorklet(ref worklet) =>
|
||||
Image::PaintWorklet(PaintWorklet::from_computed_value(worklet)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A CSS gradient.
|
||||
/// https://drafts.csswg.org/css-images/#gradients
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
|
|
|
@ -129,8 +129,8 @@ impl Parse for CounterStyleOrNone {
|
|||
///
|
||||
/// For font-feature-settings, this is a tag and an integer,
|
||||
/// for font-variation-settings this is a tag and a float
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, ToComputedValue)]
|
||||
pub struct FontSettingTag<T> {
|
||||
/// A four-character tag, packed into a u32 (one byte per character)
|
||||
pub tag: u32,
|
||||
|
@ -187,7 +187,7 @@ impl<T: Parse> Parse for FontSettingTag<T> {
|
|||
|
||||
/// A font settings value for font-variation-settings or font-feature-settings
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, ToCss)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, ToComputedValue, ToCss)]
|
||||
pub enum FontSettings<T> {
|
||||
/// No settings (default)
|
||||
Normal,
|
||||
|
@ -210,16 +210,17 @@ impl<T: Parse> Parse for FontSettings<T> {
|
|||
///
|
||||
/// Do not use this type anywhere except within FontSettings
|
||||
/// because it serializes with the preceding space
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToComputedValue)]
|
||||
pub struct FontSettingTagInt(pub u32);
|
||||
|
||||
/// A number value to be used for font-variation-settings
|
||||
///
|
||||
/// Do not use this type anywhere except within FontSettings
|
||||
/// because it serializes with the preceding space
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[cfg_attr(feature = "gecko", derive(Animate, ComputeSquaredDistance))]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Debug, PartialEq, ToComputedValue)]
|
||||
pub struct FontSettingTagFloat(pub f32);
|
||||
|
||||
impl ToCss for FontSettingTagInt {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue