mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Auto merge of #6741 - servo:fix-setpropertypriority, r=pcwalton
Fix CSSStyleDeclaration::setPropertyPriority and some refactoring r? @Ms2ger <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6741) <!-- Reviewable:end -->
This commit is contained in:
commit
c6b043582b
8 changed files with 197 additions and 116 deletions
|
@ -5,12 +5,12 @@
|
|||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::process::{Command, Stdio};
|
||||
use std::process::{Command, Stdio, exit};
|
||||
use std::path::Path;
|
||||
|
||||
|
||||
fn main() {
|
||||
let python = if Command::new("python2.7").arg("--version").status().unwrap().success() {
|
||||
let python = if Command::new("python2.7").arg("--version").output().unwrap().status.success() {
|
||||
"python2.7"
|
||||
} else {
|
||||
"python"
|
||||
|
@ -22,14 +22,23 @@ fn main() {
|
|||
.env("PYTHONPATH", &mako)
|
||||
.env("TEMPLATE", &template)
|
||||
.arg("-c")
|
||||
.arg("from os import environ; from mako.template import Template; \
|
||||
from mako import exceptions; \n\
|
||||
try:\n print(Template(filename=environ['TEMPLATE']).render());\n\
|
||||
except:\n print exceptions.html_error_template().render()")
|
||||
.arg(r#"
|
||||
import os
|
||||
import sys
|
||||
from mako.template import Template
|
||||
from mako import exceptions
|
||||
try:
|
||||
print(Template(filename=os.environ['TEMPLATE'], input_encoding='utf8').render().encode('utf8'))
|
||||
except:
|
||||
sys.stderr.write(exceptions.text_error_template().render().encode('utf8'))
|
||||
sys.exit(1)
|
||||
"#)
|
||||
.stderr(Stdio::inherit())
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(result.status.success());
|
||||
if !result.status.success() {
|
||||
exit(1)
|
||||
}
|
||||
let out = env::var("OUT_DIR").unwrap();
|
||||
File::create(&Path::new(&out).join("properties.rs")).unwrap().write_all(&result.stdout).unwrap();
|
||||
}
|
||||
|
|
|
@ -5534,6 +5534,15 @@ pub fn parse_style_attribute(input: &str, base_url: &Url) -> PropertyDeclaration
|
|||
parse_property_declaration_list(&context, &mut Parser::new(input))
|
||||
}
|
||||
|
||||
pub fn parse_one_declaration(name: &str, input: &str, base_url: &Url)
|
||||
-> Result<Vec<PropertyDeclaration>, ()> {
|
||||
let context = ParserContext::new(Origin::Author, base_url);
|
||||
let mut results = vec![];
|
||||
match PropertyDeclaration::parse(name, &context, &mut Parser::new(input), &mut results) {
|
||||
PropertyDeclarationParseResult::ValidOrIgnoredDeclaration => Ok(results),
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
|
||||
struct PropertyDeclarationParser<'a, 'b: 'a> {
|
||||
context: &'a ParserContext<'b>,
|
||||
|
@ -5574,9 +5583,9 @@ pub fn parse_property_declaration_list(context: &ParserContext, input: &mut Pars
|
|||
match declaration {
|
||||
Ok((results, important)) => {
|
||||
if important {
|
||||
important_declarations.push_all(&results);
|
||||
important_declarations.extend(results);
|
||||
} else {
|
||||
normal_declarations.push_all(&results);
|
||||
normal_declarations.extend(results);
|
||||
}
|
||||
}
|
||||
Err(range) => {
|
||||
|
@ -5660,7 +5669,7 @@ impl<T: ToCss> DeclaredValue<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
#[derive(PartialEq)]
|
||||
pub enum PropertyDeclaration {
|
||||
% for property in LONGHANDS:
|
||||
${property.camel_case}(DeclaredValue<longhands::${property.ident}::SpecifiedValue>),
|
||||
|
@ -6543,11 +6552,12 @@ pub fn modify_style_for_inline_sides(style: &mut Arc<ComputedValues>,
|
|||
}
|
||||
|
||||
pub fn is_supported_property(property: &str) -> bool {
|
||||
match property {
|
||||
% for property in SHORTHANDS + LONGHANDS:
|
||||
match_ignore_ascii_case! { property,
|
||||
% for property in SHORTHANDS + LONGHANDS[:-1]:
|
||||
"${property.name}" => true,
|
||||
% endfor
|
||||
_ => false,
|
||||
"${LONGHANDS[-1].name}" => true
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6579,16 +6589,24 @@ macro_rules! longhand_properties_idents {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn longhands_from_shorthand(shorthand: &str) -> Option<Vec<String>> {
|
||||
match shorthand {
|
||||
% for property in SHORTHANDS:
|
||||
"${property.name}" => Some(vec!(
|
||||
// Extra space here because < seems to be removed by Mako when immediately followed by &.
|
||||
// ↓
|
||||
pub fn longhands_from_shorthand(shorthand: &str) -> Option< &'static [&'static str]> {
|
||||
% for property in SHORTHANDS:
|
||||
static ${property.ident.upper()}: &'static [&'static str] = &[
|
||||
% for sub in property.sub_properties:
|
||||
"${sub.name}".to_owned(),
|
||||
"${sub.name}",
|
||||
% endfor
|
||||
)),
|
||||
];
|
||||
% endfor
|
||||
match_ignore_ascii_case!{ shorthand,
|
||||
% for property in SHORTHANDS[:-1]:
|
||||
"${property.name}" => Some(${property.ident.upper()}),
|
||||
% endfor
|
||||
_ => None,
|
||||
% for property in SHORTHANDS[-1:]:
|
||||
"${property.name}" => Some(${property.ident.upper()})
|
||||
% endfor
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue