Skip to content

Commit

Permalink
script: insert the restyle attribute restyle hint when a style attrib…
Browse files Browse the repository at this point in the history
…ute is modified.
  • Loading branch information
emilio committed Jan 30, 2017
1 parent d37e6f8 commit cb304fd
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions components/script/dom/document.rs
Expand Up @@ -129,7 +129,7 @@ use std::sync::Arc;
use std::time::{Duration, Instant};
use style::attr::AttrValue;
use style::context::{QuirksMode, ReflowGoal};
use style::restyle_hints::RestyleHint;
use style::restyle_hints::{RestyleHint, RESTYLE_STYLE_ATTRIBUTE};
use style::selector_parser::{RestyleDamage, Snapshot};
use style::str::{split_html_space_chars, str_join};
use style::stylesheets::Stylesheet;
Expand Down Expand Up @@ -2142,23 +2142,32 @@ impl Document {
RefMut::map(map, |m| m.entry(JS::from_ref(el)).or_insert_with(PendingRestyle::new))
}

pub fn ensure_snapshot(&self, el: &Element) -> RefMut<Snapshot> {
pub fn element_state_will_change(&self, el: &Element) {
let mut entry = self.ensure_pending_restyle(el);
if entry.snapshot.is_none() {
entry.snapshot = Some(Snapshot::new(el.html_element_in_html_document()));
}
RefMut::map(entry, |e| e.snapshot.as_mut().unwrap())
}

pub fn element_state_will_change(&self, el: &Element) {
let mut snapshot = self.ensure_snapshot(el);
let mut snapshot = entry.snapshot.as_mut().unwrap();
if snapshot.state.is_none() {
snapshot.state = Some(el.state());
}
}

pub fn element_attr_will_change(&self, el: &Element, _attr: &Attr) {
let mut snapshot = self.ensure_snapshot(el);
pub fn element_attr_will_change(&self, el: &Element, attr: &Attr) {
// FIXME(emilio): Kind of a shame we have to duplicate this.
//
// I'm getting rid of the whole hashtable soon anyway, since all it does
// right now is populate the element restyle data in layout, and we
// could in theory do it in the DOM I think.
let mut entry = self.ensure_pending_restyle(el);
if entry.snapshot.is_none() {
entry.snapshot = Some(Snapshot::new(el.html_element_in_html_document()));
}
if attr.local_name() == &local_name!("style") {
entry.hint |= RESTYLE_STYLE_ATTRIBUTE;
}

let mut snapshot = entry.snapshot.as_mut().unwrap();
if snapshot.attrs.is_none() {
let attrs = el.attrs()
.iter()
Expand Down

0 comments on commit cb304fd

Please sign in to comment.