mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #17209 - servo:derive-all-the-things, r=emilio
Introduce more generics and more deriving <!-- 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/17209) <!-- Reviewable:end -->
This commit is contained in:
commit
738483742c
20 changed files with 153 additions and 323 deletions
|
@ -3894,18 +3894,18 @@ fn static_assert() {
|
|||
}
|
||||
|
||||
pub fn set_initial_letter(&mut self, v: longhands::initial_letter::computed_value::T) {
|
||||
use properties::longhands::initial_letter::computed_value::T;
|
||||
use values::generics::text::InitialLetter;
|
||||
match v {
|
||||
T::Normal => {
|
||||
InitialLetter::Normal => {
|
||||
self.gecko.mInitialLetterSize = 0.;
|
||||
self.gecko.mInitialLetterSink = 0;
|
||||
},
|
||||
T::Specified(size, sink) => {
|
||||
self.gecko.mInitialLetterSize = size.get();
|
||||
InitialLetter::Specified(size, sink) => {
|
||||
self.gecko.mInitialLetterSize = size;
|
||||
if let Some(sink) = sink {
|
||||
self.gecko.mInitialLetterSink = sink.value();
|
||||
self.gecko.mInitialLetterSink = sink;
|
||||
} else {
|
||||
self.gecko.mInitialLetterSink = size.get().floor() as i32;
|
||||
self.gecko.mInitialLetterSink = size.floor() as i32;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -545,8 +545,6 @@ ${helpers.predefined_type("animation-timing-function",
|
|||
extra_prefixes="moz webkit"
|
||||
spec="https://drafts.csswg.org/css-animations/#propdef-animation-iteration-count",
|
||||
allowed_in_keyframe_block="False">
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
|
||||
pub mod computed_value {
|
||||
|
@ -554,8 +552,8 @@ ${helpers.predefined_type("animation-timing-function",
|
|||
}
|
||||
|
||||
// https://drafts.csswg.org/css-animations/#animation-iteration-count
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Debug, Clone, PartialEq, ToCss)]
|
||||
pub enum SpecifiedValue {
|
||||
Number(f32),
|
||||
Infinite,
|
||||
|
@ -576,15 +574,6 @@ ${helpers.predefined_type("animation-timing-function",
|
|||
}
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
SpecifiedValue::Number(n) => write!(dest, "{}", n),
|
||||
SpecifiedValue::Infinite => dest.write_str("infinite"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
no_viewport_percentage!(SpecifiedValue);
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -1039,28 +1039,15 @@ ${helpers.single_keyword_system("font-variant-caps",
|
|||
|
||||
pub mod computed_value {
|
||||
use properties::animated_properties::Animatable;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::CSSFloat;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Copy, Clone, Debug, PartialEq, ToCss)]
|
||||
pub enum T {
|
||||
None,
|
||||
Number(CSSFloat),
|
||||
}
|
||||
|
||||
impl ToCss for T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write,
|
||||
{
|
||||
match *self {
|
||||
T::None => dest.write_str("none"),
|
||||
T::Number(number) => number.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl T {
|
||||
pub fn from_gecko_adjust(gecko: f32) -> Self {
|
||||
if gecko == -1.0 {
|
||||
|
@ -2214,9 +2201,7 @@ ${helpers.single_keyword("-moz-math-variant",
|
|||
use app_units::Au;
|
||||
use cssparser::Parser;
|
||||
use properties::longhands;
|
||||
use std::fmt;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use style_traits::ToCss;
|
||||
use values::computed::{ToComputedValue, Context};
|
||||
<%
|
||||
system_fonts = """caption icon menu message-box small-caption status-bar
|
||||
|
@ -2230,23 +2215,13 @@ ${helpers.single_keyword("-moz-math-variant",
|
|||
kw_cast = """font_style font_variant_caps font_stretch
|
||||
font_kerning font_variant_position""".split()
|
||||
%>
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, ToCss)]
|
||||
pub enum SystemFont {
|
||||
% for font in system_fonts:
|
||||
${to_camel_case(font)},
|
||||
% endfor
|
||||
}
|
||||
|
||||
impl ToCss for SystemFont {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
dest.write_str(match *self {
|
||||
% for font in system_fonts:
|
||||
SystemFont::${to_camel_case(font)} => "${font}",
|
||||
% endfor
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ComputedValues are compared at times
|
||||
// so we need these impls. We don't want to
|
||||
// add Eq to Number (which contains a float)
|
||||
|
|
|
@ -287,72 +287,11 @@ ${helpers.predefined_type(
|
|||
ignored_when_colors_disabled=True,
|
||||
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-decoration-color")}
|
||||
|
||||
<%helpers:longhand name="initial-letter"
|
||||
animation_value_type="none"
|
||||
products="gecko"
|
||||
spec="https://drafts.csswg.org/css-inline/#sizing-drop-initials">
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
use values::specified::{Number, Integer};
|
||||
|
||||
impl ComputedValueAsSpecified for SpecifiedValue {}
|
||||
no_viewport_percentage!(SpecifiedValue);
|
||||
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum SpecifiedValue {
|
||||
Normal,
|
||||
Specified(Number, Option<Integer>)
|
||||
}
|
||||
|
||||
pub mod computed_value {
|
||||
pub use super::SpecifiedValue as T;
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
SpecifiedValue::Normal => try!(dest.write_str("normal")),
|
||||
SpecifiedValue::Specified(size, sink) => {
|
||||
try!(size.to_css(dest));
|
||||
if let Some(sink) = sink {
|
||||
try!(dest.write_str(" "));
|
||||
try!(sink.to_css(dest));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T::Normal
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||
SpecifiedValue::Normal
|
||||
}
|
||||
|
||||
/// normal | <number> <integer>?
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
|
||||
return Ok(SpecifiedValue::Normal);
|
||||
}
|
||||
|
||||
let size = try!(Number::parse_at_least_one(context, input));
|
||||
|
||||
match input.try(|input| Integer::parse(context, input)) {
|
||||
Ok(number) => {
|
||||
if number.value() < 1 {
|
||||
return Err(());
|
||||
}
|
||||
Ok(SpecifiedValue::Specified(size, Some(number)))
|
||||
}
|
||||
Err(()) => Ok(SpecifiedValue::Specified(size, None)),
|
||||
}
|
||||
}
|
||||
</%helpers:longhand>
|
||||
${helpers.predefined_type(
|
||||
"initial-letter",
|
||||
"InitialLetter",
|
||||
"computed::InitialLetter::normal()",
|
||||
initial_specified_value="specified::InitialLetter::normal()",
|
||||
animation_value_type="none",
|
||||
products="gecko",
|
||||
spec="https://drafts.csswg.org/css-inline/#sizing-drop-initials")}
|
||||
|
|
|
@ -450,8 +450,8 @@ impl PropertyDeclarationIdSet {
|
|||
% endfor
|
||||
|
||||
/// An enum to represent a CSS Wide keyword.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, ToCss)]
|
||||
pub enum CSSWideKeyword {
|
||||
/// The `initial` keyword.
|
||||
Initial,
|
||||
|
@ -483,12 +483,6 @@ impl CSSWideKeyword {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToCss for CSSWideKeyword {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
dest.write_str(self.to_str())
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for CSSWideKeyword {
|
||||
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
let ident = input.expect_ident()?;
|
||||
|
@ -628,8 +622,8 @@ impl LonghandId {
|
|||
}
|
||||
|
||||
/// An identifier for a given shorthand property.
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToCss)]
|
||||
pub enum ShorthandId {
|
||||
% for property in data.shorthands:
|
||||
/// ${property.name}
|
||||
|
@ -637,14 +631,6 @@ pub enum ShorthandId {
|
|||
% endfor
|
||||
}
|
||||
|
||||
impl ToCss for ShorthandId {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write,
|
||||
{
|
||||
dest.write_str(self.name())
|
||||
}
|
||||
}
|
||||
|
||||
impl ShorthandId {
|
||||
/// Get the name for this shorthand property.
|
||||
pub fn name(&self) -> &'static str {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue