Add "inherited" markers on longhand properties.

This commit is contained in:
Simon Sapin 2013-08-23 15:25:57 +01:00
parent 622bc5705c
commit a931c8d4a0

View file

@ -35,18 +35,21 @@ class Shorthand(object):
self.ident = to_rust_ident(name) self.ident = to_rust_ident(name)
self.sub_properties = [Longhand(s) for s in sub_properties] self.sub_properties = [Longhand(s) for s in sub_properties]
longhands = [] LONGHANDS = []
shorthands = [] SHORTHANDS = []
INHERITED = set()
%> %>
pub mod longhands { pub mod longhands {
pub use super::*; pub use super::*;
<%def name="longhand(name)"> <%def name="longhand(name, inherited=False)">
<% <%
property = Longhand(name) property = Longhand(name)
longhands.append(property) LONGHANDS.append(property)
if inherited:
INHERITED.add(name)
%> %>
pub mod ${property.ident} { pub mod ${property.ident} {
use super::*; use super::*;
@ -54,8 +57,8 @@ pub mod longhands {
} }
</%def> </%def>
<%def name="single_component_value(name)"> <%def name="single_component_value(name, inherited=False)">
<%self:longhand name="${name}"> <%self:longhand name="${name}" inherited="${inherited}">
${caller.body()} ${caller.body()}
pub fn parse(input: &[ComponentValue]) -> Option<SpecifiedValue> { pub fn parse(input: &[ComponentValue]) -> Option<SpecifiedValue> {
one_component_value(input).chain(from_component_value) one_component_value(input).chain(from_component_value)
@ -63,8 +66,8 @@ pub mod longhands {
</%self:longhand> </%self:longhand>
</%def> </%def>
<%def name="single_keyword(name, values)"> <%def name="single_keyword(name, values, inherited=False)">
<%self:single_component_value name="${name}"> <%self:single_component_value name="${name}" inherited="${inherited}">
pub enum SpecifiedValue { pub enum SpecifiedValue {
% for value in values.split(): % for value in values.split():
${to_rust_ident(value)}, ${to_rust_ident(value)},
@ -83,8 +86,8 @@ pub mod longhands {
</%self:single_component_value> </%self:single_component_value>
</%def> </%def>
<%def name="predefined_function(name, result_type, function)"> <%def name="predefined_function(name, result_type, function, inherited=False)">
<%self:longhand name="${name}"> <%self:longhand name="${name}" inherited="${inherited}">
pub type SpecifiedValue = ${result_type}; pub type SpecifiedValue = ${result_type};
pub fn parse(input: &[ComponentValue]) -> Option<SpecifiedValue> { pub fn parse(input: &[ComponentValue]) -> Option<SpecifiedValue> {
one_component_value(input).chain(${function}) one_component_value(input).chain(${function})
@ -92,8 +95,8 @@ pub mod longhands {
</%self:longhand> </%self:longhand>
</%def> </%def>
<%def name="predefined_type(name, type)"> <%def name="predefined_type(name, type, inherited=False)">
${predefined_function(name, type, type + "::parse")} ${predefined_function(name, type, type + "::parse", inherited)}
</%def> </%def>
@ -226,11 +229,11 @@ pub mod longhands {
// CSS 2.1, Section 14 - Colors and Backgrounds // CSS 2.1, Section 14 - Colors and Backgrounds
${predefined_type("background-color", "CSSColor")} ${predefined_type("background-color", "CSSColor")}
${predefined_type("color", "CSSColor")} ${predefined_type("color", "CSSColor", inherited=True)}
// CSS 2.1, Section 15 - Fonts // CSS 2.1, Section 15 - Fonts
<%self:longhand name="font-family"> <%self:longhand name="font-family" inherited="True">
enum FontFamily { enum FontFamily {
FamilyName(~str), FamilyName(~str),
// Generic // Generic
@ -300,10 +303,10 @@ pub mod longhands {
</%self:longhand> </%self:longhand>
${single_keyword("font-style", "normal italic oblique")} ${single_keyword("font-style", "normal italic oblique", inherited=True)}
${single_keyword("font-variant", "normal")} // Add small-caps when supported ${single_keyword("font-variant", "normal", inherited=True)} // Add small-caps when supported
<%self:single_component_value name="font-weight"> <%self:single_component_value name="font-weight" inherited="True">
pub enum SpecifiedValue { pub enum SpecifiedValue {
Bolder, Bolder,
Lighther, Lighther,
@ -344,7 +347,7 @@ pub mod longhands {
} }
</%self:single_component_value> </%self:single_component_value>
<%self:single_component_value name="font-size"> <%self:single_component_value name="font-size" inherited="True">
pub type SpecifiedValue = specified::Length; // Percentages are the same as em. pub type SpecifiedValue = specified::Length; // Percentages are the same as em.
/// <length> | <percentage> /// <length> | <percentage>
/// TODO: support <absolute-size> and <relative-size> /// TODO: support <absolute-size> and <relative-size>
@ -360,7 +363,7 @@ pub mod longhands {
// CSS 2.1, Section 16 - Text // CSS 2.1, Section 16 - Text
${single_keyword("text-align", "left right center justify")} ${single_keyword("text-align", "left right center justify", inherited=True)}
<%self:longhand name="text-decoration"> <%self:longhand name="text-decoration">
pub struct SpecifiedValue { pub struct SpecifiedValue {
@ -411,7 +414,7 @@ pub mod shorthands {
<%def name="shorthand(name, sub_properties)"> <%def name="shorthand(name, sub_properties)">
<% <%
shorthand = Shorthand(name, sub_properties.split()) shorthand = Shorthand(name, sub_properties.split())
shorthands.append(shorthand) SHORTHANDS.append(shorthand)
%> %>
pub mod ${shorthand.ident} { pub mod ${shorthand.ident} {
use super::*; use super::*;
@ -588,7 +591,7 @@ pub enum DeclaredValue<T> {
} }
pub enum PropertyDeclaration { pub enum PropertyDeclaration {
% for property in longhands: % for property in LONGHANDS:
${property.ident}_declaration(DeclaredValue<longhands::${property.ident}::SpecifiedValue>), ${property.ident}_declaration(DeclaredValue<longhands::${property.ident}::SpecifiedValue>),
% endfor % endfor
} }
@ -597,7 +600,7 @@ impl PropertyDeclaration {
pub fn parse(name: &str, value: &[ComponentValue], pub fn parse(name: &str, value: &[ComponentValue],
result_list: &mut ~[PropertyDeclaration]) -> bool { result_list: &mut ~[PropertyDeclaration]) -> bool {
match name.to_ascii_lower().as_slice() { match name.to_ascii_lower().as_slice() {
% for property in longhands: % for property in LONGHANDS:
"${property.name}" => result_list.push(${property.ident}_declaration( "${property.name}" => result_list.push(${property.ident}_declaration(
match CSSWideKeyword::parse(value) { match CSSWideKeyword::parse(value) {
Some(keyword) => CSSWideKeyword(keyword), Some(keyword) => CSSWideKeyword(keyword),
@ -608,7 +611,7 @@ impl PropertyDeclaration {
} }
)), )),
% endfor % endfor
% for shorthand in shorthands: % for shorthand in SHORTHANDS:
"${shorthand.name}" => match CSSWideKeyword::parse(value) { "${shorthand.name}" => match CSSWideKeyword::parse(value) {
Some(keyword) => { Some(keyword) => {
% for sub_property in shorthand.sub_properties: % for sub_property in shorthand.sub_properties: