mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Auto merge of #16413 - heycam:all, r=emilio
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 -->
This commit is contained in:
commit
1bf10a915c
8 changed files with 2652 additions and 2542 deletions
|
@ -33,6 +33,8 @@ interface CSSStyleDeclaration {
|
|||
};
|
||||
|
||||
partial interface CSSStyleDeclaration {
|
||||
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString all;
|
||||
|
||||
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString background;
|
||||
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString backgroundColor;
|
||||
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString background-color;
|
||||
|
|
|
@ -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;
|
||||
|
@ -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()
|
||||
|
@ -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_.*",
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -280,3 +280,6 @@ class PropertiesData(object):
|
|||
self.add_prefixed_aliases(shorthand)
|
||||
self.shorthands.append(shorthand)
|
||||
return shorthand
|
||||
|
||||
def shorthands_except_all(self):
|
||||
return [s for s in self.shorthands if s.name != "all"]
|
||||
|
|
|
@ -1986,7 +1986,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()) };
|
||||
|
@ -1997,7 +1997,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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -165,6 +165,45 @@ pub mod shorthands {
|
|||
<%include file="/shorthand/position.mako.rs" />
|
||||
<%include file="/shorthand/inherited_svg.mako.rs" />
|
||||
<%include file="/shorthand/text.mako.rs" />
|
||||
|
||||
// We don't defined the 'all' shorthand using the regular helpers:shorthand
|
||||
// mechanism, since it causes some very large types to be generated.
|
||||
<% data.declare_shorthand("all",
|
||||
[p.name for p in data.longhands if p.name not in ['direction', 'unicode-bidi']],
|
||||
spec="https://drafts.csswg.org/css-cascade-3/#all-shorthand") %>
|
||||
pub mod all {
|
||||
use cssparser::Parser;
|
||||
use parser::ParserContext;
|
||||
use properties::{ParsedDeclaration, ShorthandId, UnparsedValue};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<ParsedDeclaration, ()> {
|
||||
// This function is like the parse() that is generated by
|
||||
// helpers:shorthand, but since the only values for the 'all'
|
||||
// shorthand when not just a single CSS-wide keyword is one
|
||||
// with variable references, we can make this function a
|
||||
// little simpler.
|
||||
//
|
||||
// FIXME(heycam) Try to share code with the helpers:shorthand
|
||||
// definition.
|
||||
input.look_for_var_functions();
|
||||
let start = input.position();
|
||||
while let Ok(_) = input.next() {} // Look for var()
|
||||
if input.seen_var_functions() {
|
||||
input.reset(start);
|
||||
let (first_token_type, css) = try!(
|
||||
::custom_properties::parse_non_custom_with_var(input));
|
||||
Ok(ParsedDeclaration::AllWithVariables(Arc::new(UnparsedValue {
|
||||
css: css.into_owned(),
|
||||
first_token_type: first_token_type,
|
||||
url_data: context.url_data.clone(),
|
||||
from_shorthand: Some(ShorthandId::All),
|
||||
})))
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A module with all the code related to animated properties.
|
||||
|
@ -337,7 +376,12 @@ impl PropertyDeclarationIdSet {
|
|||
longhands::${property.ident}
|
||||
::parse_specified(&context, input).map(DeclaredValueOwned::Value)
|
||||
}
|
||||
% for shorthand in data.shorthands:
|
||||
Some(ShorthandId::All) => {
|
||||
// No need to parse the 'all' shorthand as anything other than a CSS-wide
|
||||
// keyword, after variable substitution.
|
||||
Err(())
|
||||
}
|
||||
% for shorthand in data.shorthands_except_all():
|
||||
% if property in shorthand.sub_properties:
|
||||
Some(ShorthandId::${shorthand.camel_case}) => {
|
||||
shorthands::${shorthand.ident}::parse_value(&context, input)
|
||||
|
@ -543,7 +587,14 @@ impl ShorthandId {
|
|||
I: Iterator<Item=&'a PropertyDeclaration>,
|
||||
{
|
||||
match *self {
|
||||
% for property in data.shorthands:
|
||||
ShorthandId::All => {
|
||||
// No need to try to serialize the declarations as the 'all'
|
||||
// shorthand, since it only accepts CSS-wide keywords (and
|
||||
// variable references), which will be handled in
|
||||
// get_shorthand_appendable_value.
|
||||
Err(fmt::Error)
|
||||
}
|
||||
% for property in data.shorthands_except_all():
|
||||
ShorthandId::${property.camel_case} => {
|
||||
match shorthands::${property.ident}::LonghandsToSerialize::from_iter(declarations) {
|
||||
Ok(longhands) => longhands.to_css(dest),
|
||||
|
@ -868,8 +919,14 @@ impl PropertyId {
|
|||
/// Includes shorthands before expansion
|
||||
pub enum ParsedDeclaration {
|
||||
% for shorthand in data.shorthands:
|
||||
% if shorthand.name == "all":
|
||||
// No need for an All(shorthands::all::Longhands) case, since we can
|
||||
// never have any values for 'all' other than the CSS-wide keywords
|
||||
// and values with variable references.
|
||||
% else:
|
||||
/// ${shorthand.name}
|
||||
${shorthand.camel_case}(shorthands::${shorthand.ident}::Longhands),
|
||||
% endif
|
||||
|
||||
/// ${shorthand.name} with a CSS-wide keyword
|
||||
${shorthand.camel_case}CSSWideKeyword(CSSWideKeyword),
|
||||
|
@ -910,6 +967,7 @@ impl ParsedDeclaration {
|
|||
overwrite_more_important: bool) -> bool {
|
||||
match self {
|
||||
% for shorthand in data.shorthands:
|
||||
% if shorthand.name != "all":
|
||||
ParsedDeclaration::${shorthand.camel_case}(
|
||||
shorthands::${shorthand.ident}::Longhands {
|
||||
% for sub_property in shorthand.sub_properties:
|
||||
|
@ -933,6 +991,7 @@ impl ParsedDeclaration {
|
|||
% endfor
|
||||
changed
|
||||
},
|
||||
% endif
|
||||
ParsedDeclaration::${shorthand.camel_case}CSSWideKeyword(keyword) => {
|
||||
let mut changed = false;
|
||||
% for sub_property in shorthand.sub_properties:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue