Refactor CSSStyleDeclaration::setProperty to not synthesize a name: value string to parse.

This commit is contained in:
Simon Sapin 2015-07-25 00:21:12 +02:00
parent e2984349ed
commit d2bd070dc3
3 changed files with 23 additions and 20 deletions

View file

@ -16,7 +16,7 @@ use dom::window::{Window, WindowHelpers};
use util::str::DOMString;
use selectors::parser::PseudoElement;
use string_cache::Atom;
use style::properties::{is_supported_property, longhands_from_shorthand, parse_style_attribute};
use style::properties::{is_supported_property, longhands_from_shorthand, parse_one_declaration};
use style::properties::PropertyDeclaration;
use std::ascii::AsciiExt;
@ -228,37 +228,31 @@ impl<'a> CSSStyleDeclarationMethods for &'a CSSStyleDeclaration {
}
// Step 5
let priority = priority.to_ascii_lowercase();
if priority != "!important" && !priority.is_empty() {
return Ok(());
}
let priority = match &*priority {
"" => StylePriority::Normal,
p if p.eq_ignore_ascii_case("important") => StylePriority::Important,
_ => return Ok(()),
};
// Step 6
let mut synthesized_declaration = property;
synthesized_declaration.push_str(": ");
synthesized_declaration.push_str(&value);
let owner = self.owner.root();
let window = window_from_node(owner.r());
let decl_block = parse_style_attribute(&synthesized_declaration, &window.r().get_url());
let declarations = parse_one_declaration(&property, &value, &window.r().get_url());
// Step 7
if decl_block.normal.len() == 0 {
let declarations = if let Ok(declarations) = declarations {
declarations
} else {
return Ok(());
}
};
let owner = self.owner.root();
let element = ElementCast::from_ref(owner.r());
// Step 8
for decl in decl_block.normal.iter() {
for decl in declarations {
// Step 9
let style_priority = if priority.is_empty() {
StylePriority::Normal
} else {
StylePriority::Important
};
element.update_inline_style(decl.clone(), style_priority);
element.update_inline_style(decl, priority);
}
let document = document_from_node(element);

View file

@ -564,7 +564,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
}
}
#[derive(PartialEq)]
#[derive(PartialEq, Eq, Copy, Clone)]
pub enum StylePriority {
Important,
Normal,