mirror of
https://github.com/servo/servo.git
synced 2025-06-25 09:34:32 +01:00
Add style structs.
This commit is contained in:
parent
dd8b178860
commit
cb340df79c
1 changed files with 66 additions and 0 deletions
|
@ -34,10 +34,19 @@ 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_PER_STYLE_STRUCT = []
|
||||||
|
THIS_STYLE_STRUCT_LONGHANDS = None
|
||||||
LONGHANDS = []
|
LONGHANDS = []
|
||||||
SHORTHANDS = []
|
SHORTHANDS = []
|
||||||
INHERITED = set()
|
INHERITED = set()
|
||||||
|
|
||||||
|
def new_style_struct(name):
|
||||||
|
longhands = []
|
||||||
|
LONGHANDS_PER_STYLE_STRUCT.append((name, longhands))
|
||||||
|
global THIS_STYLE_STRUCT_LONGHANDS
|
||||||
|
THIS_STYLE_STRUCT_LONGHANDS = longhands
|
||||||
|
return ""
|
||||||
|
|
||||||
%>
|
%>
|
||||||
|
|
||||||
pub mod longhands {
|
pub mod longhands {
|
||||||
|
@ -47,6 +56,7 @@ pub mod longhands {
|
||||||
<%def name="longhand(name, inherited=False, no_super=False)">
|
<%def name="longhand(name, inherited=False, no_super=False)">
|
||||||
<%
|
<%
|
||||||
property = Longhand(name)
|
property = Longhand(name)
|
||||||
|
THIS_STYLE_STRUCT_LONGHANDS.append(property)
|
||||||
LONGHANDS.append(property)
|
LONGHANDS.append(property)
|
||||||
if inherited:
|
if inherited:
|
||||||
INHERITED.add(name)
|
INHERITED.add(name)
|
||||||
|
@ -109,11 +119,15 @@ pub mod longhands {
|
||||||
|
|
||||||
// CSS 2.1, Section 8 - Box model
|
// CSS 2.1, Section 8 - Box model
|
||||||
|
|
||||||
|
${new_style_struct("Margin")}
|
||||||
|
|
||||||
% for side in ["top", "right", "bottom", "left"]:
|
% for side in ["top", "right", "bottom", "left"]:
|
||||||
${predefined_type("margin-" + side, "LengthOrPercentageOrAuto",
|
${predefined_type("margin-" + side, "LengthOrPercentageOrAuto",
|
||||||
"computed::LPA_Length(computed::Length(0))")}
|
"computed::LPA_Length(computed::Length(0))")}
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
|
${new_style_struct("Padding")}
|
||||||
|
|
||||||
% for side in ["top", "right", "bottom", "left"]:
|
% for side in ["top", "right", "bottom", "left"]:
|
||||||
${predefined_type("padding-" + side, "LengthOrPercentage",
|
${predefined_type("padding-" + side, "LengthOrPercentage",
|
||||||
"computed::LP_Length(computed::Length(0))",
|
"computed::LP_Length(computed::Length(0))",
|
||||||
|
@ -124,6 +138,8 @@ pub mod longhands {
|
||||||
${predefined_type("border-%s-color" % side, "CSSColor", "CurrentColor")}
|
${predefined_type("border-%s-color" % side, "CSSColor", "CurrentColor")}
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
|
${new_style_struct("Border")}
|
||||||
|
|
||||||
// dotted dashed double groove ridge insed outset hidden
|
// dotted dashed double groove ridge insed outset hidden
|
||||||
${single_keyword("border-top-style", "none solid")}
|
${single_keyword("border-top-style", "none solid")}
|
||||||
% for side in ["right", "bottom", "left"]:
|
% for side in ["right", "bottom", "left"]:
|
||||||
|
@ -165,6 +181,8 @@ pub mod longhands {
|
||||||
|
|
||||||
// CSS 2.1, Section 9 - Visual formatting model
|
// CSS 2.1, Section 9 - Visual formatting model
|
||||||
|
|
||||||
|
${new_style_struct("Box")}
|
||||||
|
|
||||||
// TODO: don't parse values we don't support
|
// TODO: don't parse values we don't support
|
||||||
${single_keyword("display",
|
${single_keyword("display",
|
||||||
"inline block list-item inline-block none "
|
"inline block list-item inline-block none "
|
||||||
|
@ -231,14 +249,22 @@ pub mod longhands {
|
||||||
|
|
||||||
// CSS 2.1, Section 14 - Colors and Backgrounds
|
// CSS 2.1, Section 14 - Colors and Backgrounds
|
||||||
|
|
||||||
|
${new_style_struct("Background")}
|
||||||
|
|
||||||
${predefined_type("background-color", "CSSColor",
|
${predefined_type("background-color", "CSSColor",
|
||||||
"RGBA(RGBA { red: 0., green: 0., blue: 0., alpha: 0. }) /* transparent */")}
|
"RGBA(RGBA { red: 0., green: 0., blue: 0., alpha: 0. }) /* transparent */")}
|
||||||
|
|
||||||
|
|
||||||
|
${new_style_struct("Color")}
|
||||||
|
|
||||||
${predefined_type("color", "CSSColor",
|
${predefined_type("color", "CSSColor",
|
||||||
"RGBA(RGBA { red: 0., green: 0., blue: 0., alpha: 1. }) /* black */",
|
"RGBA(RGBA { red: 0., green: 0., blue: 0., alpha: 1. }) /* black */",
|
||||||
inherited=True)}
|
inherited=True)}
|
||||||
|
|
||||||
// CSS 2.1, Section 15 - Fonts
|
// CSS 2.1, Section 15 - Fonts
|
||||||
|
|
||||||
|
${new_style_struct("Font")}
|
||||||
|
|
||||||
<%self:longhand name="font-family" inherited="True">
|
<%self:longhand name="font-family" inherited="True">
|
||||||
pub use to_computed_value = std::util::id;
|
pub use to_computed_value = std::util::id;
|
||||||
enum FontFamily {
|
enum FontFamily {
|
||||||
|
@ -407,6 +433,8 @@ pub mod longhands {
|
||||||
|
|
||||||
// CSS 2.1, Section 16 - Text
|
// CSS 2.1, Section 16 - Text
|
||||||
|
|
||||||
|
${new_style_struct("Text")}
|
||||||
|
|
||||||
// TODO: initial value should be 'start' (CSS Text Level 3, direction-dependent.)
|
// TODO: initial value should be 'start' (CSS Text Level 3, direction-dependent.)
|
||||||
${single_keyword("text-align", "left right center justify", inherited=True)}
|
${single_keyword("text-align", "left right center justify", inherited=True)}
|
||||||
|
|
||||||
|
@ -685,3 +713,41 @@ impl PropertyDeclaration {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod style_structs {
|
||||||
|
use super::longhands;
|
||||||
|
% for name, longhands in LONGHANDS_PER_STYLE_STRUCT:
|
||||||
|
pub struct ${name} {
|
||||||
|
% for longhand in longhands:
|
||||||
|
${longhand.ident}: longhands::${longhand.ident}::ComputedValue,
|
||||||
|
% endfor
|
||||||
|
}
|
||||||
|
% endfor
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ComputedValues {
|
||||||
|
% for name, longhands in LONGHANDS_PER_STYLE_STRUCT:
|
||||||
|
${name}: style_structs::${name},
|
||||||
|
% endfor
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_initial_values() -> ComputedValues {
|
||||||
|
ComputedValues {
|
||||||
|
% for name, longhands in LONGHANDS_PER_STYLE_STRUCT:
|
||||||
|
${name}: style_structs::${name} {
|
||||||
|
% for longhand in longhands:
|
||||||
|
${longhand.ident}: longhands::${longhand.ident}::get_initial_value(),
|
||||||
|
% endfor
|
||||||
|
},
|
||||||
|
% endfor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn cascade(applicable_declarations: &[PropertyDeclaration], parent_style: &ComputedValues)
|
||||||
|
-> ComputedValues {
|
||||||
|
// TODO
|
||||||
|
let _ = applicable_declarations;
|
||||||
|
let _ = parent_style;
|
||||||
|
get_initial_values()
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue