diff --git a/src/components/servo/dom/document.rs b/src/components/servo/dom/document.rs index 393f5b0fdeb..8933ba9095b 100644 --- a/src/components/servo/dom/document.rs +++ b/src/components/servo/dom/document.rs @@ -4,11 +4,10 @@ use dom::bindings::document; use dom::bindings::utils::{DOMString, WrapperCache}; -use dom::event::ReflowEvent; use dom::htmlcollection::HTMLCollection; use dom::node::AbstractNode; use dom::window::Window; -use scripting::script_task::{SendEventMsg, global_script_context}; +use scripting::script_task::global_script_context; use js::jsapi::bindgen::{JS_AddObjectRoot, JS_RemoveObjectRoot}; use servo_util::tree::{TreeNodeRef, TreeUtils}; @@ -65,7 +64,7 @@ pub impl Document { fn content_changed(&self) { for self.window.each |window| { - window.script_chan.send(SendEventMsg(ReflowEvent)) + window.content_changed() } } } diff --git a/src/components/servo/dom/window.rs b/src/components/servo/dom/window.rs index 3c0e7b52477..c7eaacd7f31 100644 --- a/src/components/servo/dom/window.rs +++ b/src/components/servo/dom/window.rs @@ -5,7 +5,7 @@ use dom::bindings::utils::WrapperCache; use dom::bindings::window; use scripting::script_task::{ExitMsg, FireTimerMsg, ScriptMsg, ScriptContext}; -use scripting::script_task::{global_script_context}; +use layout::layout_task::MatchSelectorsDamage; use util::task::spawn_listener; use core::comm::{Port, Chan, SharedChan}; @@ -82,6 +82,12 @@ pub impl Window { TimerMessage_Fire(~TimerData(argc, argv))); } + fn content_changed(&self) { + unsafe { + (*self.script_context).trigger_relayout(MatchSelectorsDamage); + } + } + pub fn new(script_chan: SharedChan, script_context: *mut ScriptContext) -> @mut Window { let script_chan_copy = script_chan.clone(); @@ -102,8 +108,10 @@ pub impl Window { script_context: script_context, }; - let compartment = global_script_context().js_compartment; - window::create(compartment, win); + unsafe { + let compartment = (*script_context).js_compartment; + window::create(compartment, win); + } win } } diff --git a/src/components/servo/scripting/script_task.rs b/src/components/servo/scripting/script_task.rs index 035873e76f4..456e9985787 100644 --- a/src/components/servo/scripting/script_task.rs +++ b/src/components/servo/scripting/script_task.rs @@ -375,6 +375,12 @@ impl ScriptContext { } } + /// Initiate an asynchronous relayout operation + pub fn trigger_relayout(&mut self, damage: Damage) { + self.damage.add(damage); + self.relayout(); + } + /// This method will wait until the layout task has completed its current action, join the /// layout task, and then request a new layout run. It won't wait for the new layout /// computation to finish. @@ -412,7 +418,6 @@ impl ScriptContext { /// Sends the given query to layout. pub fn query_layout(&mut self, query: LayoutQuery) -> LayoutQueryResponse { - //self.relayout(); self.join_layout(); let (response_port, response_chan) = comm::stream(); diff --git a/src/test/test_hammer_layout.js b/src/test/test_hammer_layout.js index 9b28847e9aa..e5c1d51b92d 100644 --- a/src/test/test_hammer_layout.js +++ b/src/test/test_hammer_layout.js @@ -6,7 +6,6 @@ var start = new Date(); for (var i = 0; i < count; i++) { div.setAttribute('id', 'styled'); div.getBoundingClientRect(); - window.alert(i); } var stop = new Date(); window.alert((stop - start) / count * 1e6);