mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Applied a bunch of suggestions from Simon.
This commit is contained in:
parent
d0489f1160
commit
4643737a1b
11 changed files with 384 additions and 389 deletions
|
@ -44,14 +44,7 @@ def abort(message):
|
||||||
|
|
||||||
def render(filename, **context):
|
def render(filename, **context):
|
||||||
try:
|
try:
|
||||||
# Workaround the fact that we can have a different working directory when called, and Mako includes will fail
|
lookup = TemplateLookup(directories=[BASE])
|
||||||
# miserably if we don't give it proper instructions in the TemplateLookup.
|
|
||||||
if os.getcwd().endswith("components/style"):
|
|
||||||
properties_path = "properties"
|
|
||||||
else:
|
|
||||||
properties_path = "components/style/properties"
|
|
||||||
|
|
||||||
lookup = TemplateLookup(directories=[properties_path])
|
|
||||||
template = Template(open(filename, "rb").read(),
|
template = Template(open(filename, "rb").read(),
|
||||||
filename=filename,
|
filename=filename,
|
||||||
input_encoding="utf8",
|
input_encoding="utf8",
|
||||||
|
|
|
@ -134,9 +134,6 @@ class PropertiesData(object):
|
||||||
return
|
return
|
||||||
raise Exception("Failed to find the struct named " + name)
|
raise Exception("Failed to find the struct named " + name)
|
||||||
|
|
||||||
def new_method(self, name, return_type):
|
|
||||||
return Method(name, return_type)
|
|
||||||
|
|
||||||
def declare_longhand(self, name, products="gecko servo", **kwargs):
|
def declare_longhand(self, name, products="gecko servo", **kwargs):
|
||||||
products = products.split()
|
products = products.split()
|
||||||
if self.product not in products:
|
if self.product not in products:
|
||||||
|
@ -157,7 +154,3 @@ class PropertiesData(object):
|
||||||
shorthand = Shorthand(name, sub_properties, *args, **kwargs)
|
shorthand = Shorthand(name, sub_properties, *args, **kwargs)
|
||||||
self.shorthands.append(shorthand)
|
self.shorthands.append(shorthand)
|
||||||
return shorthand
|
return shorthand
|
||||||
|
|
||||||
# Wrapper for the module-level method, since some scopes can only access the stuff in the PropertiesData class.
|
|
||||||
def to_rust_ident(self, name):
|
|
||||||
return to_rust_ident(name)
|
|
||||||
|
|
191
components/style/properties/helpers.mako.rs
Normal file
191
components/style/properties/helpers.mako.rs
Normal file
|
@ -0,0 +1,191 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
<%! from data import Keyword, to_rust_ident %>
|
||||||
|
|
||||||
|
<%def name="longhand(name, **kwargs)">
|
||||||
|
<%call expr="raw_longhand(name, **kwargs)">
|
||||||
|
${caller.body()}
|
||||||
|
% if not data.longhands_by_name[name].derived_from:
|
||||||
|
pub fn parse_specified(context: &ParserContext, input: &mut Parser)
|
||||||
|
-> Result<DeclaredValue<SpecifiedValue>, ()> {
|
||||||
|
parse(context, input).map(DeclaredValue::Value)
|
||||||
|
}
|
||||||
|
% endif
|
||||||
|
</%call>
|
||||||
|
</%def>
|
||||||
|
|
||||||
|
<%def name="predefined_type(name, type, initial_value, parse_method='parse', products='gecko servo')">
|
||||||
|
<%self:longhand name="${name}" products="${products}">
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
use app_units::Au;
|
||||||
|
pub type SpecifiedValue = specified::${type};
|
||||||
|
pub mod computed_value {
|
||||||
|
pub use values::computed::${type} as T;
|
||||||
|
}
|
||||||
|
#[inline] pub fn get_initial_value() -> computed_value::T { ${initial_value} }
|
||||||
|
#[inline] pub fn parse(_context: &ParserContext, input: &mut Parser)
|
||||||
|
-> Result<SpecifiedValue, ()> {
|
||||||
|
specified::${type}::${parse_method}(input)
|
||||||
|
}
|
||||||
|
</%self:longhand>
|
||||||
|
</%def>
|
||||||
|
|
||||||
|
<%def name="raw_longhand(*args, **kwargs)">
|
||||||
|
<%
|
||||||
|
property = data.declare_longhand(*args, **kwargs)
|
||||||
|
if property is None:
|
||||||
|
return ""
|
||||||
|
%>
|
||||||
|
pub mod ${property.ident} {
|
||||||
|
#![allow(unused_imports)]
|
||||||
|
% if not property.derived_from:
|
||||||
|
use cssparser::Parser;
|
||||||
|
use parser::ParserContext;
|
||||||
|
use properties::{CSSWideKeyword, DeclaredValue, Shorthand};
|
||||||
|
% endif
|
||||||
|
use error_reporting::ParseErrorReporter;
|
||||||
|
use properties::longhands;
|
||||||
|
use properties::property_bit_field::PropertyBitField;
|
||||||
|
use properties::{ComputedValues, ServoComputedValues, PropertyDeclaration};
|
||||||
|
use properties::style_struct_traits::${data.current_style_struct.trait_name};
|
||||||
|
use properties::style_structs;
|
||||||
|
use std::boxed::Box as StdBox;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use values::computed::{TContext, ToComputedValue};
|
||||||
|
use values::{computed, specified};
|
||||||
|
use string_cache::Atom;
|
||||||
|
${caller.body()}
|
||||||
|
#[allow(unused_variables)]
|
||||||
|
pub fn cascade_property<C: ComputedValues>(
|
||||||
|
declaration: &PropertyDeclaration,
|
||||||
|
inherited_style: &C,
|
||||||
|
context: &mut computed::Context<C>,
|
||||||
|
seen: &mut PropertyBitField,
|
||||||
|
cacheable: &mut bool,
|
||||||
|
error_reporter: &mut StdBox<ParseErrorReporter + Send>) {
|
||||||
|
let declared_value = match *declaration {
|
||||||
|
PropertyDeclaration::${property.camel_case}(ref declared_value) => {
|
||||||
|
declared_value
|
||||||
|
}
|
||||||
|
_ => panic!("entered the wrong cascade_property() implementation"),
|
||||||
|
};
|
||||||
|
% if not property.derived_from:
|
||||||
|
if seen.get_${property.ident}() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
seen.set_${property.ident}();
|
||||||
|
{
|
||||||
|
let custom_props = context.style().custom_properties();
|
||||||
|
::properties::substitute_variables_${property.ident}(
|
||||||
|
declared_value, &custom_props, |value| match *value {
|
||||||
|
DeclaredValue::Value(ref specified_value) => {
|
||||||
|
let computed = specified_value.to_computed_value(context);
|
||||||
|
context.mutate_style().mutate_${data.current_style_struct.trait_name_lower}()
|
||||||
|
.set_${property.ident}(computed);
|
||||||
|
}
|
||||||
|
DeclaredValue::WithVariables { .. } => unreachable!(),
|
||||||
|
DeclaredValue::Initial => {
|
||||||
|
// We assume that it's faster to use copy_*_from rather than
|
||||||
|
// set_*(get_initial_value());
|
||||||
|
let initial_struct = C::initial_values()
|
||||||
|
.get_${data.current_style_struct.trait_name_lower}();
|
||||||
|
context.mutate_style().mutate_${data.current_style_struct.trait_name_lower}()
|
||||||
|
.copy_${property.ident}_from(initial_struct);
|
||||||
|
},
|
||||||
|
DeclaredValue::Inherit => {
|
||||||
|
// This is a bit slow, but this is rare so it shouldn't
|
||||||
|
// matter.
|
||||||
|
//
|
||||||
|
// FIXME: is it still?
|
||||||
|
*cacheable = false;
|
||||||
|
let inherited_struct =
|
||||||
|
inherited_style.get_${data.current_style_struct.trait_name_lower}();
|
||||||
|
context.mutate_style().mutate_${data.current_style_struct.trait_name_lower}()
|
||||||
|
.copy_${property.ident}_from(inherited_struct);
|
||||||
|
}
|
||||||
|
}, error_reporter
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
% if property.custom_cascade:
|
||||||
|
cascade_property_custom(declaration,
|
||||||
|
inherited_style,
|
||||||
|
context,
|
||||||
|
seen,
|
||||||
|
cacheable,
|
||||||
|
error_reporter);
|
||||||
|
% endif
|
||||||
|
% else:
|
||||||
|
// Do not allow stylesheets to set derived properties.
|
||||||
|
% endif
|
||||||
|
}
|
||||||
|
% if not property.derived_from:
|
||||||
|
pub fn parse_declared(context: &ParserContext, input: &mut Parser)
|
||||||
|
-> Result<DeclaredValue<SpecifiedValue>, ()> {
|
||||||
|
match input.try(CSSWideKeyword::parse) {
|
||||||
|
Ok(CSSWideKeyword::InheritKeyword) => Ok(DeclaredValue::Inherit),
|
||||||
|
Ok(CSSWideKeyword::InitialKeyword) => Ok(DeclaredValue::Initial),
|
||||||
|
Ok(CSSWideKeyword::UnsetKeyword) => Ok(DeclaredValue::${
|
||||||
|
"Inherit" if data.current_style_struct.inherited else "Initial"}),
|
||||||
|
Err(()) => {
|
||||||
|
input.look_for_var_functions();
|
||||||
|
let start = input.position();
|
||||||
|
let specified = parse_specified(context, input);
|
||||||
|
if specified.is_err() {
|
||||||
|
while let Ok(_) = input.next() {} // Look for var() after the error.
|
||||||
|
}
|
||||||
|
let var = input.seen_var_functions();
|
||||||
|
if specified.is_err() && var {
|
||||||
|
input.reset(start);
|
||||||
|
let (first_token_type, css) = try!(
|
||||||
|
::custom_properties::parse_non_custom_with_var(input));
|
||||||
|
return Ok(DeclaredValue::WithVariables {
|
||||||
|
css: css.into_owned(),
|
||||||
|
first_token_type: first_token_type,
|
||||||
|
base_url: context.base_url.clone(),
|
||||||
|
from_shorthand: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
specified
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
% endif
|
||||||
|
}
|
||||||
|
</%def>
|
||||||
|
|
||||||
|
<%def name="single_keyword(name, values, **kwargs)">
|
||||||
|
<%call expr="single_keyword_computed(name, values, **kwargs)">
|
||||||
|
use values::computed::ComputedValueAsSpecified;
|
||||||
|
impl ComputedValueAsSpecified for SpecifiedValue {}
|
||||||
|
</%call>
|
||||||
|
</%def>
|
||||||
|
|
||||||
|
<%def name="single_keyword_computed(name, values, **kwargs)">
|
||||||
|
<%
|
||||||
|
keyword_kwargs = {a: kwargs.pop(a, None) for a in [
|
||||||
|
'gecko_constant_prefix', 'extra_gecko_values', 'extra_servo_values'
|
||||||
|
]}
|
||||||
|
%>
|
||||||
|
<%call expr="longhand(name, keyword=Keyword(name, values.split(), **keyword_kwargs), **kwargs)">
|
||||||
|
pub use self::computed_value::T as SpecifiedValue;
|
||||||
|
${caller.body()}
|
||||||
|
pub mod computed_value {
|
||||||
|
define_css_keyword_enum! { T:
|
||||||
|
% for value in data.longhands_by_name[name].keyword.values_for(product):
|
||||||
|
"${value}" => ${to_rust_ident(value)},
|
||||||
|
% endfor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[inline] pub fn get_initial_value() -> computed_value::T {
|
||||||
|
computed_value::T::${to_rust_ident(values.split()[0])}
|
||||||
|
}
|
||||||
|
pub fn parse(_context: &ParserContext, input: &mut Parser)
|
||||||
|
-> Result<SpecifiedValue, ()> {
|
||||||
|
computed_value::T::parse(input)
|
||||||
|
}
|
||||||
|
</%call>
|
||||||
|
</%def>
|
|
@ -2,11 +2,13 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
<%page args="data, helpers" />
|
<%namespace name="helpers" file="/helpers.mako.rs" />
|
||||||
|
|
||||||
|
<% from data import Method %>
|
||||||
|
|
||||||
<% data.new_style_struct("Border", inherited=False, gecko_ffi_name="nsStyleBorder",
|
<% data.new_style_struct("Border", inherited=False, gecko_ffi_name="nsStyleBorder",
|
||||||
additional_methods=[data.new_method("border_" + side + "_is_none_or_hidden_and_has_nonzero_width",
|
additional_methods=[Method("border_" + side + "_is_none_or_hidden_and_has_nonzero_width",
|
||||||
"bool") for side in ["top", "right", "bottom", "left"]]) %>
|
"bool") for side in ["top", "right", "bottom", "left"]]) %>
|
||||||
|
|
||||||
% for side in ["top", "right", "bottom", "left"]:
|
% for side in ["top", "right", "bottom", "left"]:
|
||||||
${helpers.predefined_type("border-%s-color" % side, "CSSColor", "::cssparser::Color::CurrentColor")}
|
${helpers.predefined_type("border-%s-color" % side, "CSSColor", "::cssparser::Color::CurrentColor")}
|
||||||
|
|
|
@ -2,17 +2,19 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
<%page args="data, helpers" />
|
<%namespace name="helpers" file="/helpers.mako.rs" />
|
||||||
|
|
||||||
<% data.new_style_struct("Box", inherited=False, gecko_ffi_name="nsStyleDisplay",
|
<% from data import Method, to_rust_ident %>
|
||||||
additional_methods=[data.new_method("clone_display",
|
|
||||||
"longhands::display::computed_value::T"),
|
<% data.new_style_struct("Box",
|
||||||
data.new_method("clone_position",
|
inherited=False,
|
||||||
"longhands::position::computed_value::T"),
|
gecko_ffi_name="nsStyleDisplay",
|
||||||
data.new_method("is_floated", "bool"),
|
additional_methods=[Method("clone_display", "longhands::display::computed_value::T"),
|
||||||
data.new_method("overflow_x_is_visible", "bool"),
|
Method("clone_position", "longhands::position::computed_value::T"),
|
||||||
data.new_method("overflow_y_is_visible", "bool"),
|
Method("is_floated", "bool"),
|
||||||
data.new_method("transition_count", "usize")]) %>
|
Method("overflow_x_is_visible", "bool"),
|
||||||
|
Method("overflow_y_is_visible", "bool"),
|
||||||
|
Method("transition_count", "usize")]) %>
|
||||||
|
|
||||||
// TODO(SimonSapin): don't parse `inline-table`, since we don't support it
|
// TODO(SimonSapin): don't parse `inline-table`, since we don't support it
|
||||||
<%helpers:longhand name="display" custom_cascade="${product == 'servo'}">
|
<%helpers:longhand name="display" custom_cascade="${product == 'servo'}">
|
||||||
|
@ -34,7 +36,7 @@
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
pub enum T {
|
pub enum T {
|
||||||
% for value in values:
|
% for value in values:
|
||||||
${data.to_rust_ident(value)},
|
${to_rust_ident(value)},
|
||||||
% endfor
|
% endfor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,14 +45,14 @@
|
||||||
where W: ::std::fmt::Write {
|
where W: ::std::fmt::Write {
|
||||||
match *self {
|
match *self {
|
||||||
% for value in values:
|
% for value in values:
|
||||||
T::${data.to_rust_ident(value)} => dest.write_str("${value}"),
|
T::${to_rust_ident(value)} => dest.write_str("${value}"),
|
||||||
% endfor
|
% endfor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline] pub fn get_initial_value() -> computed_value::T {
|
#[inline] pub fn get_initial_value() -> computed_value::T {
|
||||||
computed_value::T::${data.to_rust_ident(values[0])}
|
computed_value::T::${to_rust_ident(values[0])}
|
||||||
}
|
}
|
||||||
pub fn parse(_context: &ParserContext, input: &mut Parser)
|
pub fn parse(_context: &ParserContext, input: &mut Parser)
|
||||||
-> Result<SpecifiedValue, ()> {
|
-> Result<SpecifiedValue, ()> {
|
||||||
|
@ -63,7 +65,7 @@
|
||||||
return Err(())
|
return Err(())
|
||||||
}
|
}
|
||||||
% endif
|
% endif
|
||||||
Ok(computed_value::T::${data.to_rust_ident(value)})
|
Ok(computed_value::T::${to_rust_ident(value)})
|
||||||
},
|
},
|
||||||
% endfor
|
% endfor
|
||||||
_ => Err(())
|
_ => Err(())
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
<%page args="data, helpers" />
|
<%namespace name="helpers" file="/helpers.mako.rs" />
|
||||||
|
|
||||||
<% data.new_style_struct("Margin", inherited=False, gecko_ffi_name="nsStyleMargin") %>
|
<% data.new_style_struct("Margin", inherited=False, gecko_ffi_name="nsStyleMargin") %>
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,14 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
<%page args="data, helpers" />
|
<%namespace name="helpers" file="/helpers.mako.rs" />
|
||||||
|
|
||||||
<% data.new_style_struct("Outline", inherited=False, gecko_ffi_name="nsStyleOutline",
|
<% from data import Method %>
|
||||||
additional_methods=[data.new_method("outline_is_none_or_hidden_and_has_nonzero_width", "bool")]) %>
|
|
||||||
|
<% data.new_style_struct("Outline",
|
||||||
|
inherited=False,
|
||||||
|
gecko_ffi_name="nsStyleOutline",
|
||||||
|
additional_methods=[Method("outline_is_none_or_hidden_and_has_nonzero_width", "bool")]) %>
|
||||||
|
|
||||||
// TODO(pcwalton): `invert`
|
// TODO(pcwalton): `invert`
|
||||||
${helpers.predefined_type("outline-color", "CSSColor", "::cssparser::Color::CurrentColor")}
|
${helpers.predefined_type("outline-color", "CSSColor", "::cssparser::Color::CurrentColor")}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
<%page args="data, helpers" />
|
<%namespace name="helpers" file="/helpers.mako.rs" />
|
||||||
|
|
||||||
<% data.new_style_struct("Padding", inherited=False, gecko_ffi_name="nsStylePadding") %>
|
<% data.new_style_struct("Padding", inherited=False, gecko_ffi_name="nsStylePadding") %>
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
<%page args="data, helpers" />
|
<%namespace name="helpers" file="/helpers.mako.rs" />
|
||||||
|
|
||||||
<% data.new_style_struct("Position", inherited=False, gecko_ffi_name="nsStylePosition") %>
|
<% data.new_style_struct("Position", inherited=False, gecko_ffi_name="nsStylePosition") %>
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -277,9 +277,7 @@ def check_toml(file_name, lines):
|
||||||
|
|
||||||
def check_rust(file_name, lines):
|
def check_rust(file_name, lines):
|
||||||
if not file_name.endswith(".rs") or \
|
if not file_name.endswith(".rs") or \
|
||||||
file_name.endswith("properties.mako.rs") or \
|
file_name.endswith(".mako.rs") or \
|
||||||
file_name.find("properties/longhand") or \
|
|
||||||
file_name.find("properties/shorthand") or \
|
|
||||||
file_name.endswith(os.path.join("style", "build.rs")) or \
|
file_name.endswith(os.path.join("style", "build.rs")) or \
|
||||||
file_name.endswith(os.path.join("geckolib", "build.rs")) or \
|
file_name.endswith(os.path.join("geckolib", "build.rs")) or \
|
||||||
file_name.endswith(os.path.join("unit", "style", "stylesheets.rs")):
|
file_name.endswith(os.path.join("unit", "style", "stylesheets.rs")):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue