Skip to content

Commit

Permalink
Replace bool attribute in Element::update_inline_style with a descrip…
Browse files Browse the repository at this point in the history
…tive enum
  • Loading branch information
thiagopnts committed Dec 24, 2014
1 parent 194ce20 commit eacbe33
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
8 changes: 5 additions & 3 deletions components/script/dom/cssstyledeclaration.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 10 additions & 4 deletions components/script/dom/element.rs
Expand Up @@ -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;
Expand All @@ -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>;
}
Expand Down Expand Up @@ -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()
Expand All @@ -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))
Expand Down

9 comments on commit eacbe33

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from jdm
at thiagopnts@eacbe33

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging thiagopnts/servo/descriptive-enum = eacbe33 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thiagopnts/servo/descriptive-enum = eacbe33 merged ok, testing candidate = 209439f

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from jdm
at thiagopnts@eacbe33

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging thiagopnts/servo/descriptive-enum = eacbe33 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thiagopnts/servo/descriptive-enum = eacbe33 merged ok, testing candidate = c35a18e

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = c35a18e

Please sign in to comment.