Allow setting id, class, style without a full reflow

Instead we do selector matching again, then diff the style structs to set the
"restyle damage" bits which are used to prune reflow traversals.

Also don't force a reflow when timers finish, because individual DOM methods
should already take care of that.
This commit is contained in:
Keegan McAllister 2013-12-10 15:15:43 -08:00
parent 93e10eaf20
commit 0238410b47
4 changed files with 16 additions and 9 deletions

View file

@ -23,6 +23,7 @@ use dom::htmltitleelement::HTMLTitleElement;
use html::hubbub_html_parser::build_element_from_tag; use html::hubbub_html_parser::build_element_from_tag;
use js::jsapi::{JSObject, JSContext, JSTracer}; use js::jsapi::{JSObject, JSContext, JSTracer};
use servo_util::tree::{TreeNodeRef, ElementLike}; use servo_util::tree::{TreeNodeRef, ElementLike};
use layout_interface::{DocumentDamageLevel, ContentChangedDocumentDamage};
use std::hashmap::HashMap; use std::hashmap::HashMap;
@ -319,7 +320,11 @@ impl Document {
} }
pub fn content_changed(&self) { pub fn content_changed(&self) {
self.window.content_changed(); self.damage_and_reflow(ContentChangedDocumentDamage);
}
pub fn damage_and_reflow(&self, damage: DocumentDamageLevel) {
self.window.damage_and_reflow(damage);
} }
pub fn wait_until_safe_to_modify_dom(&self) { pub fn wait_until_safe_to_modify_dom(&self) {

View file

@ -18,7 +18,8 @@ use dom::document;
use dom::namespace; use dom::namespace;
use dom::namespace::Namespace; use dom::namespace::Namespace;
use layout_interface::{ContentBoxQuery, ContentBoxResponse, ContentBoxesQuery}; use layout_interface::{ContentBoxQuery, ContentBoxResponse, ContentBoxesQuery};
use layout_interface::{ContentBoxesResponse}; use layout_interface::{ContentBoxesResponse, ContentChangedDocumentDamage};
use layout_interface::{MatchSelectorsDocumentDamage};
use style; use style;
use servo_util::tree::{TreeNodeRef, ElementLike}; use servo_util::tree::{TreeNodeRef, ElementLike};
@ -293,8 +294,12 @@ impl<'self> Element {
} }
if abstract_self.is_in_doc() { if abstract_self.is_in_doc() {
let damage = match local_name.as_slice() {
"style" | "id" | "class" => MatchSelectorsDocumentDamage,
_ => ContentChangedDocumentDamage
};
let document = self.node.owner_doc(); let document = self.node.owner_doc();
document.document().content_changed(); document.document().damage_and_reflow(damage);
} }
} }
} }

View file

@ -12,7 +12,7 @@ use dom::node::{AbstractNode, ScriptView};
use dom::location::Location; use dom::location::Location;
use dom::navigator::Navigator; use dom::navigator::Navigator;
use layout_interface::{ReflowForDisplay, ContentChangedDocumentDamage}; use layout_interface::{ReflowForDisplay, DocumentDamageLevel};
use script_task::{ExitWindowMsg, FireTimerMsg, Page, ScriptChan}; use script_task::{ExitWindowMsg, FireTimerMsg, Page, ScriptChan};
use servo_msg::compositor_msg::ScriptListener; use servo_msg::compositor_msg::ScriptListener;
use servo_net::image_cache_task::ImageCacheTask; use servo_net::image_cache_task::ImageCacheTask;
@ -185,11 +185,11 @@ impl Window {
self.active_timers.remove(&handle); self.active_timers.remove(&handle);
} }
pub fn content_changed(&self) { pub fn damage_and_reflow(&self, damage: DocumentDamageLevel) {
// FIXME This should probably be ReflowForQuery, not Display. All queries currently // FIXME This should probably be ReflowForQuery, not Display. All queries currently
// currently rely on the display list, which means we can't destroy it by // currently rely on the display list, which means we can't destroy it by
// doing a query reflow. // doing a query reflow.
self.page.damage(ContentChangedDocumentDamage); self.page.damage(damage);
self.page.reflow(ReflowForDisplay, self.script_chan.clone(), self.compositor); self.page.reflow(ReflowForDisplay, self.script_chan.clone(), self.compositor);
} }

View file

@ -588,9 +588,6 @@ impl ScriptTask {
&rval); &rval);
} }
// We don't know what the script changed, so for now we will do a total redisplay.
page.damage(ContentChangedDocumentDamage);
page.reflow(ReflowForDisplay, self.chan.clone(), self.compositor);
} }
/// Handles a notification that reflow completed. /// Handles a notification that reflow completed.