style: Only expose longhands to rust via iterators.

The key here is that we only filter longhands if the shorthand is accessible to
content and vice-versa. This prevents the bug that prevented me to land this
patch before, which was us not expanding properly chrome-only shorthands.

Again, this is incomplete, and I need to teach LonghandsToSerialize to get a
potentially incomplete list of properties, and all that.
This commit is contained in:
Emilio Cobos Álvarez 2018-02-20 12:00:31 +01:00
parent 6fbf2c1e3c
commit 8c4b401dd3
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
8 changed files with 95 additions and 59 deletions

View file

@ -21,7 +21,6 @@ use properties::longhands;
use properties::longhands::font_weight::computed_value::T as FontWeight;
use properties::longhands::font_stretch::computed_value::T as FontStretch;
use properties::longhands::visibility::computed_value::T as Visibility;
#[cfg(feature = "gecko")]
use properties::PropertyId;
use properties::{LonghandId, ShorthandId};
use servo_arc::Arc;
@ -114,10 +113,10 @@ impl TransitionProperty {
}
/// Iterates over each longhand property.
pub fn each<F: FnMut(&LonghandId) -> ()>(mut cb: F) {
pub fn each<F: FnMut(LonghandId) -> ()>(mut cb: F) {
% for prop in data.longhands:
% if prop.transitionable:
cb(&LonghandId::${prop.camel_case});
cb(LonghandId::${prop.camel_case});
% endif
% endfor
}
@ -300,11 +299,11 @@ impl AnimatedProperty {
/// Get an animatable value from a transition-property, an old style, and a
/// new style.
pub fn from_longhand(
property: &LonghandId,
property: LonghandId,
old_style: &ComputedValues,
new_style: &ComputedValues,
) -> Option<AnimatedProperty> {
Some(match *property {
Some(match property {
% for prop in data.longhands:
% if prop.animatable:
LonghandId::${prop.camel_case} => {
@ -646,10 +645,10 @@ impl AnimationValue {
/// Get an AnimationValue for an AnimatableLonghand from a given computed values.
pub fn from_computed_values(
property: &LonghandId,
property: LonghandId,
computed_values: &ComputedValues
) -> Option<Self> {
Some(match *property {
Some(match property {
% for prop in data.longhands:
% if prop.animatable:
LonghandId::${prop.camel_case} => {
@ -3088,15 +3087,17 @@ impl ComputeSquaredDistance for AnimatedFilterList {
/// border-top-color, border-color, border-top, border
///
/// [property-order] https://drafts.csswg.org/web-animations/#calculating-computed-keyframes
#[cfg(feature = "gecko")]
pub fn compare_property_priority(a: &PropertyId, b: &PropertyId) -> cmp::Ordering {
match (a.as_shorthand(), b.as_shorthand()) {
// Within shorthands, sort by the number of subproperties, then by IDL name.
(Ok(a), Ok(b)) => {
let subprop_count_a = a.longhands().len();
let subprop_count_b = b.longhands().len();
subprop_count_a.cmp(&subprop_count_b).then_with(
|| get_idl_name_sort_order(&a).cmp(&get_idl_name_sort_order(&b)))
let subprop_count_a = a.longhands().count();
let subprop_count_b = b.longhands().count();
subprop_count_a
.cmp(&subprop_count_b)
.then_with(|| {
get_idl_name_sort_order(a).cmp(&get_idl_name_sort_order(b))
})
},
// Longhands go before shorthands.
@ -3109,8 +3110,7 @@ pub fn compare_property_priority(a: &PropertyId, b: &PropertyId) -> cmp::Orderin
}
}
#[cfg(feature = "gecko")]
fn get_idl_name_sort_order(shorthand: &ShorthandId) -> u32 {
fn get_idl_name_sort_order(shorthand: ShorthandId) -> u32 {
<%
# Sort by IDL name.
sorted_shorthands = sorted(data.shorthands, key=lambda p: to_idl_name(p.ident))
@ -3118,7 +3118,7 @@ sorted_shorthands = sorted(data.shorthands, key=lambda p: to_idl_name(p.ident))
# Annotate with sorted position
sorted_shorthands = [(p, position) for position, p in enumerate(sorted_shorthands)]
%>
match *shorthand {
match shorthand {
% for property, position in sorted_shorthands:
ShorthandId::${property.camel_case} => ${position},
% endfor