mirror of
https://github.com/servo/servo.git
synced 2025-06-20 15:18:58 +01:00
Add support for clearTimeout.
This commit is contained in:
parent
5be084a3b6
commit
29a75daa66
3 changed files with 22 additions and 5 deletions
|
@ -63,8 +63,8 @@ interface WindowTimers {
|
||||||
//long setTimeout(Function handler, optional long timeout, any... arguments);
|
//long setTimeout(Function handler, optional long timeout, any... arguments);
|
||||||
//XXXjdm No support for Function or variadic arguments yet
|
//XXXjdm No support for Function or variadic arguments yet
|
||||||
long setTimeout(any handler, optional long timeout/*, any... arguments*/);
|
long setTimeout(any handler, optional long timeout/*, any... arguments*/);
|
||||||
/*long setTimeout(DOMString handler, optional long timeout, any... arguments);
|
|
||||||
void clearTimeout(long handle);
|
void clearTimeout(long handle);
|
||||||
|
/*long setTimeout(DOMString handler, optional long timeout, any... arguments);
|
||||||
long setInterval(Function handler, optional long timeout, any... arguments);
|
long setInterval(Function handler, optional long timeout, any... arguments);
|
||||||
long setInterval(DOMString handler, optional long timeout, any... arguments);
|
long setInterval(DOMString handler, optional long timeout, any... arguments);
|
||||||
void clearInterval(long handle);*/
|
void clearInterval(long handle);*/
|
||||||
|
|
|
@ -23,6 +23,7 @@ use std::cast;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::comm;
|
use std::comm;
|
||||||
use std::comm::SharedChan;
|
use std::comm::SharedChan;
|
||||||
|
use std::hashmap::HashSet;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::int;
|
use std::int;
|
||||||
|
@ -45,6 +46,8 @@ pub struct Window {
|
||||||
timer_chan: SharedChan<TimerControlMsg>,
|
timer_chan: SharedChan<TimerControlMsg>,
|
||||||
navigator: Option<@mut Navigator>,
|
navigator: Option<@mut Navigator>,
|
||||||
image_cache_task: ImageCacheTask,
|
image_cache_task: ImageCacheTask,
|
||||||
|
active_timers: ~HashSet<i32>,
|
||||||
|
next_timer_handle: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe_destructor]
|
#[unsafe_destructor]
|
||||||
|
@ -58,6 +61,7 @@ impl Drop for Window {
|
||||||
// (ie. function value to invoke and all arguments to pass
|
// (ie. function value to invoke and all arguments to pass
|
||||||
// to the function when calling it)
|
// to the function when calling it)
|
||||||
pub struct TimerData {
|
pub struct TimerData {
|
||||||
|
handle: i32,
|
||||||
funval: JSVal,
|
funval: JSVal,
|
||||||
args: ~[JSVal],
|
args: ~[JSVal],
|
||||||
}
|
}
|
||||||
|
@ -148,8 +152,10 @@ impl BindingObject for Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn SetTimeout(&self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32 {
|
pub fn SetTimeout(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32 {
|
||||||
let timeout = int::max(0, timeout) as u64;
|
let timeout = int::max(0, timeout) as u64;
|
||||||
|
let handle = self.next_timer_handle;
|
||||||
|
self.next_timer_handle += 1;
|
||||||
|
|
||||||
// Post a delayed message to the per-window timer task; it will dispatch it
|
// Post a delayed message to the per-window timer task; it will dispatch it
|
||||||
// to the relevant script handler that will deal with it.
|
// to the relevant script handler that will deal with it.
|
||||||
|
@ -159,11 +165,17 @@ impl Window {
|
||||||
let mut tm = tm.take();
|
let mut tm = tm.take();
|
||||||
tm.sleep(timeout);
|
tm.sleep(timeout);
|
||||||
chan.send(TimerMessage_Fire(~TimerData {
|
chan.send(TimerMessage_Fire(~TimerData {
|
||||||
|
handle: handle,
|
||||||
funval: callback,
|
funval: callback,
|
||||||
args: ~[]
|
args: ~[]
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
return 0; //TODO return handle into list of active timers
|
self.active_timers.insert(handle);
|
||||||
|
handle
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ClearTimeout(&mut self, handle: i32) {
|
||||||
|
self.active_timers.remove(&handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn content_changed(&self) {
|
pub fn content_changed(&self) {
|
||||||
|
@ -208,6 +220,8 @@ impl Window {
|
||||||
},
|
},
|
||||||
navigator: None,
|
navigator: None,
|
||||||
image_cache_task: image_cache_task,
|
image_cache_task: image_cache_task,
|
||||||
|
active_timers: ~HashSet::new(),
|
||||||
|
next_timer_handle: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -251,4 +265,3 @@ impl Traceable for Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -254,7 +254,7 @@ impl Page {
|
||||||
///
|
///
|
||||||
/// This function fails if there is no root frame.
|
/// This function fails if there is no root frame.
|
||||||
fn reflow(&mut self, goal: ReflowGoal, script_chan: ScriptChan, compositor: @ScriptListener) {
|
fn reflow(&mut self, goal: ReflowGoal, script_chan: ScriptChan, compositor: @ScriptListener) {
|
||||||
|
|
||||||
debug!("script: performing reflow for goal %?", goal);
|
debug!("script: performing reflow for goal %?", goal);
|
||||||
|
|
||||||
// Now, join the layout so that they will see the latest changes we have made.
|
// Now, join the layout so that they will see the latest changes we have made.
|
||||||
|
@ -561,6 +561,10 @@ impl ScriptTask {
|
||||||
fn handle_fire_timer_msg(&mut self, id: PipelineId, timer_data: ~TimerData) {
|
fn handle_fire_timer_msg(&mut self, id: PipelineId, timer_data: ~TimerData) {
|
||||||
let page = self.page_tree.find(id).expect("ScriptTask: received fire timer msg for a
|
let page = self.page_tree.find(id).expect("ScriptTask: received fire timer msg for a
|
||||||
pipeline ID not associated with this script task. This is a bug.").page;
|
pipeline ID not associated with this script task. This is a bug.").page;
|
||||||
|
let window = page.frame.expect("ScriptTask: Expect a timeout to have a document").window;
|
||||||
|
if !window.active_timers.contains(&timer_data.handle) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
let this_value = if timer_data.args.len() > 0 {
|
let this_value = if timer_data.args.len() > 0 {
|
||||||
RUST_JSVAL_TO_OBJECT(timer_data.args[0])
|
RUST_JSVAL_TO_OBJECT(timer_data.args[0])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue