Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding sync method to update atrr from inline style updates #9410

Closed
wants to merge 15 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Removed previously copied serialize_shorthand method as well as unnec…

…essary calls to document.content_changed
  • Loading branch information
craftytrickster committed May 19, 2016
commit d9c0c88f0ab82434e8174c4b6cfd96069684b400
@@ -12,13 +12,11 @@ use dom::element::{Element, StylePriority};
use dom::node::{Node, NodeDamage, window_from_node};
use dom::window::Window;
use std::ascii::AsciiExt;
use std::borrow::ToOwned;
use std::cell::Ref;
use string_cache::Atom;
use style::properties::{PropertyDeclaration, Shorthand};
use style::properties::{is_supported_property, parse_one_declaration};
use style::selector_impl::PseudoElement;
use util::str::{DOMString, str_join};
use util::str::DOMString;

// http://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface
#[dom_struct]
@@ -48,29 +46,6 @@ macro_rules! css_properties(
);
);

fn serialize_shorthand(shorthand: Shorthand, declarations: &[Ref<PropertyDeclaration>]) -> String {
// https://drafts.csswg.org/css-variables/#variables-in-shorthands
if let Some(css) = declarations[0].with_variables_from_shorthand(shorthand) {
if declarations[1..]
.iter()
.all(|d| d.with_variables_from_shorthand(shorthand) == Some(css)) {
css.to_owned()
} else {
String::new()
}
} else {
if declarations.iter().any(|d| d.with_variables()) {
String::new()
} else {
let str_iter = declarations.iter().map(|d| d.value());
// FIXME: this needs property-specific code, which probably should be in style/
// "as appropriate according to the grammar of shorthand "
// https://drafts.csswg.org/cssom/#serialize-a-css-value
str_join(str_iter, " ")
}
}
}

impl CSSStyleDeclaration {
pub fn new_inherited(owner: &Element,
pseudo: Option<PseudoElement>,
@@ -164,13 +139,14 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {

// Step 2.2.2 & 2.2.3
match declaration {
Some(declaration) => list.push(declaration),
Some(declaration) => list.push(declaration.clone()),
None => return DOMString::new(),
}
}

// Step 2.3
return DOMString::from(serialize_shorthand(shorthand, &list));
let list = list.iter().map(|x| &*x).collect::<Vec<_>>();
return DOMString::from(shorthand.serialize_shorthand(&list));
}

// Step 3 & 4
@@ -256,8 +232,6 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
element.update_inline_style(decl, priority);
}

let node = element.upcast::<Node>();
node.dirty(NodeDamage::NodeStyleDamaged);
Ok(())
}

@@ -290,8 +264,6 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
None => element.set_inline_style_property_priority(&[&*property], priority),
}

let node = element.upcast::<Node>();
node.dirty(NodeDamage::NodeStyleDamaged);
Ok(())
}

@@ -326,9 +298,6 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
None => elem.remove_inline_style_property(&property),
}

let node = elem.upcast::<Node>();
node.dirty(NodeDamage::NodeStyleDamaged);

// Step 6
Ok(value)
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.