stylo: Generate eCSSPropertyID_all as a const rather than an enum value.
draft
stylo: Generate eCSSPropertyID_all as a const rather than an enum value.
MozReview-Commit-ID: DfI7y5wWUj9
--- a/servo/components/style/build_gecko.rs
+++ b/servo/components/style/build_gecko.rs
@@ -26,16 +26,17 @@ mod common {
BuildType::Release => STRUCTS_RELEASE_FILE
}
}
}
#[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;
use std::env;
use std::fs::{self, File};
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use std::sync::Mutex;
@@ -253,16 +254,33 @@ mod bindings {
let re = Regex::new(r#"^SERVO_ARC_TYPE\(\w+,\s*(\w+)\)$"#).unwrap();
content.lines().map(|line| line.trim()).filter(|line| !line.is_empty())
.map(|line| re.captures(&line)
.expect(&format!("Unrecognized line in ServoArcTypeList.h: '{}'", line))
.get(1).unwrap().as_str().to_string())
.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()
.with_codegen_config(CodegenConfig {
types: true,
vars: true,
..CodegenConfig::nothing()
})
@@ -291,17 +309,18 @@ mod bindings {
.raw_line("pub use self::root::mozilla::*;")
.raw_line("pub use self::root::mozilla::css::*;")
.raw_line("pub use self::root::mozilla::dom::*;")
.raw_line("use atomic_refcell::AtomicRefCell;")
.raw_line("use data::ElementData;")
.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_.*",
"NS_FONT_.*",
"NS_STYLE_.*",
"NS_MATHML_.*",
"NS_RADIUS_.*",
"BORDER_COLOR_.*",
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -1890,28 +1890,28 @@ fn static_assert() {
computed_value::T(Some(result))
}
${impl_transition_time_value('delay', 'Delay')}
${impl_transition_time_value('duration', 'Duration')}
${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()) };
self.gecko.mTransitionPropertyCount = v.0.len() as u32;
for (servo, gecko) in v.0.into_iter().zip(self.gecko.mTransitions.iter_mut()) {
gecko.mProperty = servo.into();
}
} 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;
}
}
/// Returns whether there are any transitions specified.
pub fn specifies_transitions(&self) -> bool {
use gecko_bindings::structs::nsCSSPropertyID::eCSSPropertyExtra_all_properties;
if self.gecko.mTransitionPropertyCount == 1 &&
self.gecko.mTransitions[0].mProperty == eCSSPropertyExtra_all_properties &&
--- a/servo/components/style/properties/helpers.mako.rs
+++ b/servo/components/style/properties/helpers.mako.rs
@@ -730,18 +730,16 @@
</%def>
</%self:logical_setter_helper>
}
% endif
</%def>
<%def name="alias_to_nscsspropertyid(alias)">
<%
- if alias == "word-wrap":
- return "nsCSSPropertyID_eCSSPropertyAlias_WordWrap"
return "nsCSSPropertyID::eCSSPropertyAlias_%s" % to_camel_case(alias)
%>
</%def>
<%def name="to_nscsspropertyid(ident)">
<%
if ident == "float":
ident = "float_"