mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Whitelist Copy types when generating PropertyDeclaration
This commit is contained in:
parent
8b9b3617a2
commit
335cb4c9f4
5 changed files with 63 additions and 23 deletions
|
@ -206,11 +206,51 @@ pub mod animated_properties {
|
||||||
<%
|
<%
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
|
|
||||||
|
copyTypes = set([
|
||||||
|
"AlignContent",
|
||||||
|
"AlignItems",
|
||||||
|
"AlignSelf",
|
||||||
|
"BackgroundRepeat",
|
||||||
|
"BorderImageRepeat",
|
||||||
|
"BorderStyle",
|
||||||
|
"Contain",
|
||||||
|
"FontStyleAdjust",
|
||||||
|
"FontSynthesis",
|
||||||
|
"FontWeight",
|
||||||
|
"GridAutoFlow",
|
||||||
|
"ImageOrientation",
|
||||||
|
"InitialLetter",
|
||||||
|
"Integer",
|
||||||
|
"IntegerOrAuto",
|
||||||
|
"JustifyContent",
|
||||||
|
"JustifyItems",
|
||||||
|
"JustifySelf",
|
||||||
|
"MozForceBrokenImageIcon",
|
||||||
|
"MozScriptLevel",
|
||||||
|
"MozScriptMinSize",
|
||||||
|
"MozScriptSizeMultiplier",
|
||||||
|
"NonNegativeNumber",
|
||||||
|
"Opacity",
|
||||||
|
"OutlineStyle",
|
||||||
|
"OverscrollBehavior",
|
||||||
|
"Percentage",
|
||||||
|
"PositiveIntegerOrAuto",
|
||||||
|
"SVGPaintOrder",
|
||||||
|
"ScrollSnapType",
|
||||||
|
"TextDecorationLine",
|
||||||
|
"TouchAction",
|
||||||
|
"TransformStyle",
|
||||||
|
"XSpan",
|
||||||
|
"XTextZoom",
|
||||||
|
])
|
||||||
|
|
||||||
variants = []
|
variants = []
|
||||||
for property in data.longhands:
|
for property in data.longhands:
|
||||||
if property.predefined_type and not property.is_vector:
|
if property.predefined_type and not property.is_vector:
|
||||||
|
copy = property.predefined_type in copyTypes
|
||||||
ty = "::values::specified::{}".format(property.predefined_type)
|
ty = "::values::specified::{}".format(property.predefined_type)
|
||||||
else:
|
else:
|
||||||
|
copy = bool(property.keyword) and not property.is_vector
|
||||||
ty = "longhands::{}::SpecifiedValue".format(property.ident)
|
ty = "longhands::{}::SpecifiedValue".format(property.ident)
|
||||||
if property.boxed:
|
if property.boxed:
|
||||||
ty = "Box<{}>".format(ty)
|
ty = "Box<{}>".format(ty)
|
||||||
|
@ -218,7 +258,7 @@ pub mod animated_properties {
|
||||||
"name": property.camel_case,
|
"name": property.camel_case,
|
||||||
"type": ty,
|
"type": ty,
|
||||||
"doc": "`" + property.name + "`",
|
"doc": "`" + property.name + "`",
|
||||||
"keyword": bool(property.keyword) and not property.is_vector,
|
"copy": copy,
|
||||||
})
|
})
|
||||||
|
|
||||||
groups = {}
|
groups = {}
|
||||||
|
@ -229,9 +269,9 @@ pub mod animated_properties {
|
||||||
groups[ty] = group
|
groups[ty] = group
|
||||||
for v in group:
|
for v in group:
|
||||||
if len(group) == 1:
|
if len(group) == 1:
|
||||||
sortkeys[v["name"]] = (not v["keyword"], 1, v["name"], "")
|
sortkeys[v["name"]] = (not v["copy"], 1, v["name"], "")
|
||||||
else:
|
else:
|
||||||
sortkeys[v["name"]] = (not v["keyword"], len(group), ty, v["name"])
|
sortkeys[v["name"]] = (not v["copy"], len(group), ty, v["name"])
|
||||||
variants.sort(key=lambda x: sortkeys[x["name"]])
|
variants.sort(key=lambda x: sortkeys[x["name"]])
|
||||||
|
|
||||||
# It is extremely important to sort the `data.longhands` array here so
|
# It is extremely important to sort the `data.longhands` array here so
|
||||||
|
@ -251,19 +291,19 @@ pub mod animated_properties {
|
||||||
"name": "CSSWideKeyword",
|
"name": "CSSWideKeyword",
|
||||||
"type": "WideKeywordDeclaration",
|
"type": "WideKeywordDeclaration",
|
||||||
"doc": "A CSS-wide keyword.",
|
"doc": "A CSS-wide keyword.",
|
||||||
"keyword": False,
|
"copy": False,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "WithVariables",
|
"name": "WithVariables",
|
||||||
"type": "VariableDeclaration",
|
"type": "VariableDeclaration",
|
||||||
"doc": "An unparsed declaration.",
|
"doc": "An unparsed declaration.",
|
||||||
"keyword": False,
|
"copy": False,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Custom",
|
"name": "Custom",
|
||||||
"type": "CustomDeclaration",
|
"type": "CustomDeclaration",
|
||||||
"doc": "A custom property declaration.",
|
"doc": "A custom property declaration.",
|
||||||
"keyword": False,
|
"copy": False,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
for v in extra:
|
for v in extra:
|
||||||
|
@ -292,15 +332,15 @@ impl Clone for PropertyDeclaration {
|
||||||
use self::PropertyDeclaration::*;
|
use self::PropertyDeclaration::*;
|
||||||
|
|
||||||
<%
|
<%
|
||||||
[keywords, others] = [list(g) for _, g in groupby(variants, key=lambda x: not x["keyword"])]
|
[copy, others] = [list(g) for _, g in groupby(variants, key=lambda x: not x["copy"])]
|
||||||
%>
|
%>
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
${" | ".join("{}(..)".format(v["name"]) for v in keywords)} => {
|
${" |\n".join("{}(..)".format(v["name"]) for v in copy)} => {
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
#[repr(u16)]
|
#[repr(u16)]
|
||||||
enum Keywords {
|
enum CopyVariants {
|
||||||
% for v in keywords:
|
% for v in copy:
|
||||||
_${v["name"]}(${v["type"]}),
|
_${v["name"]}(${v["type"]}),
|
||||||
% endfor
|
% endfor
|
||||||
}
|
}
|
||||||
|
@ -308,8 +348,8 @@ impl Clone for PropertyDeclaration {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut out = mem::uninitialized();
|
let mut out = mem::uninitialized();
|
||||||
ptr::write(
|
ptr::write(
|
||||||
&mut out as *mut _ as *mut Keywords,
|
&mut out as *mut _ as *mut CopyVariants,
|
||||||
*(self as *const _ as *const Keywords),
|
*(self as *const _ as *const CopyVariants),
|
||||||
);
|
);
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
@ -323,7 +363,7 @@ impl Clone for PropertyDeclaration {
|
||||||
${vs[0]["name"]}(value.clone())
|
${vs[0]["name"]}(value.clone())
|
||||||
}
|
}
|
||||||
% else:
|
% else:
|
||||||
${" | ".join("{}(ref value)".format(v["name"]) for v in vs)} => {
|
${" |\n".join("{}(ref value)".format(v["name"]) for v in vs)} => {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut out = ManuallyDrop::new(mem::uninitialized());
|
let mut out = ManuallyDrop::new(mem::uninitialized());
|
||||||
ptr::write(
|
ptr::write(
|
||||||
|
@ -357,7 +397,7 @@ impl PartialEq for PropertyDeclaration {
|
||||||
}
|
}
|
||||||
match *self {
|
match *self {
|
||||||
% for ty, vs in groupby(variants, key=lambda x: x["type"]):
|
% for ty, vs in groupby(variants, key=lambda x: x["type"]):
|
||||||
${" | ".join("{}(ref this)".format(v["name"]) for v in vs)} => {
|
${" |\n".join("{}(ref this)".format(v["name"]) for v in vs)} => {
|
||||||
let other_repr =
|
let other_repr =
|
||||||
&*(other as *const _ as *const PropertyDeclarationVariantRepr<${ty}>);
|
&*(other as *const _ as *const PropertyDeclarationVariantRepr<${ty}>);
|
||||||
*this == other_repr.value
|
*this == other_repr.value
|
||||||
|
|
|
@ -675,8 +675,8 @@ pub fn get_normalized_vector_and_angle<T: Zero>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(ComputeSquaredDistance, ToAnimatedZero, ToComputedValue)]
|
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf, PartialEq)]
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
|
#[derive(ToAnimatedZero, ToComputedValue, ToCss)]
|
||||||
/// A value of the `Rotate` property
|
/// A value of the `Rotate` property
|
||||||
///
|
///
|
||||||
/// <https://drafts.csswg.org/css-transforms-2/#individual-transforms>
|
/// <https://drafts.csswg.org/css-transforms-2/#individual-transforms>
|
||||||
|
@ -689,8 +689,8 @@ pub enum Rotate<Number, Angle> {
|
||||||
Rotate3D(Number, Number, Number, Angle),
|
Rotate3D(Number, Number, Number, Angle),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(ComputeSquaredDistance, ToAnimatedZero, ToComputedValue)]
|
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf, PartialEq)]
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
|
#[derive(ToAnimatedZero, ToComputedValue, ToCss)]
|
||||||
/// A value of the `Scale` property
|
/// A value of the `Scale` property
|
||||||
///
|
///
|
||||||
/// <https://drafts.csswg.org/css-transforms-2/#individual-transforms>
|
/// <https://drafts.csswg.org/css-transforms-2/#individual-transforms>
|
||||||
|
|
|
@ -58,7 +58,7 @@ pub enum BackgroundRepeatKeyword {
|
||||||
/// The specified value for the `background-repeat` property.
|
/// The specified value for the `background-repeat` property.
|
||||||
///
|
///
|
||||||
/// https://drafts.csswg.org/css-backgrounds/#the-background-repeat
|
/// https://drafts.csswg.org/css-backgrounds/#the-background-repeat
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
|
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||||
pub enum BackgroundRepeat {
|
pub enum BackgroundRepeat {
|
||||||
/// `repeat-x`
|
/// `repeat-x`
|
||||||
RepeatX,
|
RepeatX,
|
||||||
|
|
|
@ -186,7 +186,7 @@ pub enum BorderImageRepeatKeyword {
|
||||||
/// The specified value for the `border-image-repeat` property.
|
/// The specified value for the `border-image-repeat` property.
|
||||||
///
|
///
|
||||||
/// https://drafts.csswg.org/css-backgrounds/#the-border-image-repeat
|
/// https://drafts.csswg.org/css-backgrounds/#the-border-image-repeat
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
|
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||||
pub struct BorderImageRepeat(pub BorderImageRepeatKeyword, pub Option<BorderImageRepeatKeyword>);
|
pub struct BorderImageRepeat(pub BorderImageRepeatKeyword, pub Option<BorderImageRepeatKeyword>);
|
||||||
|
|
||||||
impl BorderImageRepeat {
|
impl BorderImageRepeat {
|
||||||
|
|
|
@ -1776,7 +1776,7 @@ impl Parse for FontFeatureSettings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
|
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
|
||||||
/// Whether user agents are allowed to synthesize bold or oblique font faces
|
/// Whether user agents are allowed to synthesize bold or oblique font faces
|
||||||
/// when a font family lacks bold or italic faces
|
/// when a font family lacks bold or italic faces
|
||||||
pub struct FontSynthesis {
|
pub struct FontSynthesis {
|
||||||
|
@ -2054,7 +2054,7 @@ impl Parse for VariationValue<Number> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
|
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
|
||||||
/// text-zoom. Enable if true, disable if false
|
/// text-zoom. Enable if true, disable if false
|
||||||
pub struct XTextZoom(pub bool);
|
pub struct XTextZoom(pub bool);
|
||||||
|
|
||||||
|
@ -2106,7 +2106,7 @@ impl ToCss for XLang {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
||||||
#[derive(Clone, Debug, PartialEq, ToCss)]
|
#[derive(Clone, Copy, Debug, PartialEq, ToCss)]
|
||||||
/// Specifies the minimum font size allowed due to changes in scriptlevel.
|
/// Specifies the minimum font size allowed due to changes in scriptlevel.
|
||||||
/// Ref: https://wiki.mozilla.org/MathML:mstyle
|
/// Ref: https://wiki.mozilla.org/MathML:mstyle
|
||||||
pub struct MozScriptMinSize(pub NoCalcLength);
|
pub struct MozScriptMinSize(pub NoCalcLength);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue