auto merge of #4477 : thiagopnts/servo/descriptive-enum, r=jdm

refs #4472
This commit is contained in:
bors-servo 2014-12-24 10:45:45 -07:00
commit c35a18e81f
2 changed files with 15 additions and 7 deletions

View file

@ -9,7 +9,7 @@ use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, JSRef, OptionalRootedRootable, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::document::DocumentHelpers;
use dom::element::{Element, ElementHelpers};
use dom::element::{Element, ElementHelpers, StylePriority};
use dom::htmlelement::HTMLElement;
use dom::node::{window_from_node, document_from_node, NodeDamage, Node};
use dom::window::Window;
@ -222,7 +222,8 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> {
// Step 8
for decl in decl_block.normal.iter() {
// Step 9
element.update_inline_style(decl.clone(), !priority.is_empty());
let style_priority = if priority.is_empty() { StylePriority::Normal } else { StylePriority::Important };
element.update_inline_style(decl.clone(), style_priority);
}
let document = document_from_node(element).root();
@ -259,7 +260,8 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> {
// Step 5
for decl in decl_block.normal.iter() {
// Step 6
element.update_inline_style(decl.clone(), !priority.is_empty());
let style_priority = if priority.is_empty() { StylePriority::Normal } else { StylePriority::Important };
element.update_inline_style(decl.clone(), style_priority);
}
let document = document_from_node(element).root();

View file

@ -456,6 +456,12 @@ impl LayoutElementHelpers for JS<Element> {
}
}
#[deriving(PartialEq)]
pub enum StylePriority {
Important,
Normal,
}
pub trait ElementHelpers<'a> {
fn html_element_in_html_document(self) -> bool;
fn local_name(self) -> &'a Atom;
@ -467,7 +473,7 @@ pub trait ElementHelpers<'a> {
fn summarize(self) -> Vec<AttrInfo>;
fn is_void(self) -> bool;
fn remove_inline_style_property(self, property: DOMString);
fn update_inline_style(self, property_decl: style::PropertyDeclaration, important: bool);
fn update_inline_style(self, property_decl: style::PropertyDeclaration, style_priority: StylePriority);
fn get_inline_style_declaration(self, property: &Atom) -> Option<style::PropertyDeclaration>;
fn get_important_inline_style_declaration(self, property: &Atom) -> Option<style::PropertyDeclaration>;
}
@ -555,10 +561,10 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
});
}
fn update_inline_style(self, property_decl: style::PropertyDeclaration, important: bool) {
fn update_inline_style(self, property_decl: style::PropertyDeclaration, style_priority: StylePriority) {
let mut inline_declarations = self.style_attribute().borrow_mut();
if let Some(ref mut declarations) = *inline_declarations.deref_mut() {
let existing_declarations = if important {
let existing_declarations = if style_priority == StylePriority::Important {
declarations.important.make_unique()
} else {
declarations.normal.make_unique()
@ -574,7 +580,7 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
return;
}
let (important, normal) = if important {
let (important, normal) = if style_priority == StylePriority::Important {
(vec!(property_decl), vec!())
} else {
(vec!(), vec!(property_decl))