Skip to content

Commit

Permalink
Auto merge of #16413 - heycam:all, r=emilio
Browse files Browse the repository at this point in the history
implement the all shorthand

From https://bugzilla.mozilla.org/show_bug.cgi?id=1356125.

<!-- 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/16413)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Apr 13, 2017
2 parents 54e691b + e983eab commit e2023a4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
21 changes: 20 additions & 1 deletion components/style/build_gecko.rs
Expand Up @@ -31,6 +31,7 @@ mod common {
#[cfg(feature = "bindgen")]
mod bindings {
use bindgen::{Builder, CodegenConfig};
use bindgen::chooser::{EnumVariantCustomBehavior, EnumVariantValue, TypeChooser};
use regex::Regex;
use std::cmp;
use std::collections::HashSet;
Expand Down Expand Up @@ -258,6 +259,23 @@ mod bindings {
.collect()
}

#[derive(Debug)]
struct Callbacks;
impl TypeChooser for Callbacks {
fn enum_variant_behavior(&self,
enum_name: Option<&str>,
variant_name: &str,
_variant_value: EnumVariantValue)
-> Option<EnumVariantCustomBehavior> {
if enum_name.map_or(false, |n| n == "nsCSSPropertyID") &&
variant_name.starts_with("eCSSProperty_COUNT") {
Some(EnumVariantCustomBehavior::Constify)
} else {
None
}
}
}

pub fn generate_structs(build_type: BuildType) {
let mut builder = Builder::get_initial_builder(build_type)
.enable_cxx_namespaces()
Expand Down Expand Up @@ -296,7 +314,8 @@ mod bindings {
.hide_type("nsString")
.bitfield_enum("nsChangeHint")
.bitfield_enum("nsRestyleHint")
.constified_enum("UpdateAnimationsTasks");
.constified_enum("UpdateAnimationsTasks")
.type_chooser(Box::new(Callbacks));
let whitelist_vars = [
"NS_THEME_.*",
"NODE_.*",
Expand Down
4 changes: 2 additions & 2 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -1896,7 +1896,7 @@ fn static_assert() {
${impl_transition_timing_function()}

pub fn set_transition_property(&mut self, v: longhands::transition_property::computed_value::T) {
use gecko_bindings::structs::nsCSSPropertyID_eCSSPropertyExtra_no_properties;
use gecko_bindings::structs::nsCSSPropertyID::eCSSPropertyExtra_no_properties;

if !v.0.is_empty() {
unsafe { self.gecko.mTransitions.ensure_len(v.0.len()) };
Expand All @@ -1907,7 +1907,7 @@ fn static_assert() {
} else {
// In gecko |none| is represented by eCSSPropertyExtra_no_properties.
self.gecko.mTransitionPropertyCount = 1;
self.gecko.mTransitions[0].mProperty = nsCSSPropertyID_eCSSPropertyExtra_no_properties;
self.gecko.mTransitions[0].mProperty = eCSSPropertyExtra_no_properties;
}
}

Expand Down
2 changes: 0 additions & 2 deletions components/style/properties/helpers.mako.rs
Expand Up @@ -735,8 +735,6 @@

<%def name="alias_to_nscsspropertyid(alias)">
<%
if alias == "word-wrap":
return "nsCSSPropertyID_eCSSPropertyAlias_WordWrap"
return "nsCSSPropertyID::eCSSPropertyAlias_%s" % to_camel_case(alias)
%>
</%def>
Expand Down
23 changes: 23 additions & 0 deletions components/style/properties/properties.mako.rs
Expand Up @@ -165,6 +165,29 @@ pub mod shorthands {
<%include file="/shorthand/position.mako.rs" />
<%include file="/shorthand/inherited_svg.mako.rs" />
<%include file="/shorthand/text.mako.rs" />

// FIXME(heycam): It might be worth trying to handle this more efficiently
// as part of the cascade function, rather than expanding this all
// shorthand out to hundreds of specified values.
<% components_of_all_shorthand = [p.name for p in data.longhands if p.name not in ['direction', 'unicode-bidi']] %>
<%helpers:shorthand name="all"
sub_properties="${' '.join(components_of_all_shorthand)}"
spec="https://drafts.csswg.org/css-cascade-3/#all-shorthand">

pub fn parse_value(_context: &ParserContext, _input: &mut Parser) -> Result<Longhands, ()> {
// cascade_property handles parsing the CSS-wide keywords, so we
// don't need to handle any other values here.
Err(())
}

impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, _dest: &mut W) -> fmt::Result where W: fmt::Write {
// get_shorthand_appendable_value handles this for us.
debug_assert!(false, "we shouldn't need to be called");
Ok(())
}
}
</%helpers:shorthand>
}

/// A module with all the code related to animated properties.
Expand Down

0 comments on commit e2023a4

Please sign in to comment.