Skip to content

Commit

Permalink
Implemented CSSStyleDeclaration.setPropertyPriority
Browse files Browse the repository at this point in the history
Implemented CSSStyleDeclaration.setPropertyPriority, resolves #4433
  • Loading branch information
thomas-daniels committed Dec 23, 2014
1 parent 0109cc3 commit 07d37af
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
37 changes: 37 additions & 0 deletions components/script/dom/cssstyledeclaration.rs
Expand Up @@ -200,6 +200,43 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> {
Ok(())
}

// http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-setpropertypriority
fn SetPropertyPriority(self, property: DOMString, priority: DOMString) -> ErrorResult {
//TODO: disallow modifications if readonly flag is set

// Step 2
let property = property.as_slice().to_ascii_lower();

// Step 3
if !is_supported_property(property.as_slice()) {
return Ok(());
}

// Step 4
let priority = priority.as_slice().to_ascii_lower();
if priority.as_slice() != "important" && !priority.is_empty() {
return Ok(());
}

let owner = self.owner.root();
let window = window_from_node(*owner).root();
let page = window.page();
let decl_block = parse_style_attribute(property.as_slice(),
&page.get_url());
let element: JSRef<Element> = ElementCast::from_ref(*owner);

// Step 5
for decl in decl_block.normal.iter() {
// Step 6
element.update_inline_style(decl.clone(), !priority.is_empty());
}

let document = document_from_node(element).root();
let node: JSRef<Node> = NodeCast::from_ref(element);
document.content_changed(node, NodeDamage::NodeStyleDamaged);
Ok(())
}

// http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-setpropertyvalue
fn SetPropertyValue(self, property: DOMString, value: DOMString) -> ErrorResult {
self.SetProperty(property, value, "".to_string())
Expand Down
6 changes: 4 additions & 2 deletions components/script/dom/webidls/CSSStyleDeclaration.webidl
Expand Up @@ -20,8 +20,10 @@ interface CSSStyleDeclaration {
[TreatNullAs=EmptyString] optional DOMString priority = "");
[Throws]
void setPropertyValue(DOMString property, [TreatNullAs=EmptyString] DOMString value);
//[Throws]
//void setPropertyPriority(DOMString property, [TreatNullAs=EmptyString] DOMString priority);

[Throws]
void setPropertyPriority(DOMString property, [TreatNullAs=EmptyString] DOMString priority);

DOMString removeProperty(DOMString property);
//readonly attribute CSSRule? parentRule;
[SetterThrows]
Expand Down

5 comments on commit 07d37af

@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 thomas-daniels@07d37af

@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 ProgramFOX/servo/issue-4433 = 07d37af 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.

ProgramFOX/servo/issue-4433 = 07d37af merged ok, testing candidate = 49f2c69

@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 = 49f2c69

Please sign in to comment.