mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Move timer firing implemention into Window #1992
This commit is contained in:
parent
e8996d5ce5
commit
0b5a1b2ad9
2 changed files with 28 additions and 24 deletions
|
@ -26,9 +26,12 @@ use servo_util::str::DOMString;
|
||||||
use servo_util::task::{spawn_named};
|
use servo_util::task::{spawn_named};
|
||||||
use servo_util::url::parse_url;
|
use servo_util::url::parse_url;
|
||||||
|
|
||||||
|
use js::jsapi::JS_CallFunctionValue;
|
||||||
use js::jsapi::JSContext;
|
use js::jsapi::JSContext;
|
||||||
use js::jsapi::{JS_GC, JS_GetRuntime};
|
use js::jsapi::{JS_GC, JS_GetRuntime};
|
||||||
use js::jsval::JSVal;
|
use js::jsval::JSVal;
|
||||||
|
use js::jsval::NullValue;
|
||||||
|
use js::rust::with_compartment;
|
||||||
|
|
||||||
use std::collections::hashmap::HashMap;
|
use std::collections::hashmap::HashMap;
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
|
@ -37,6 +40,7 @@ use std::comm::{channel, Sender};
|
||||||
use std::comm::Select;
|
use std::comm::Select;
|
||||||
use std::hash::{Hash, sip};
|
use std::hash::{Hash, sip};
|
||||||
use std::io::timer::Timer;
|
use std::io::timer::Timer;
|
||||||
|
use std::ptr;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use time;
|
use time;
|
||||||
|
@ -284,6 +288,7 @@ pub trait WindowHelpers {
|
||||||
fn wait_until_safe_to_modify_dom(&self);
|
fn wait_until_safe_to_modify_dom(&self);
|
||||||
fn init_browser_context(&self, doc: &JSRef<Document>);
|
fn init_browser_context(&self, doc: &JSRef<Document>);
|
||||||
fn load_url(&self, href: DOMString);
|
fn load_url(&self, href: DOMString);
|
||||||
|
fn handle_fire_timer(&self, timer_id: TimerId, cx: *mut JSContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
trait PrivateWindowHelpers {
|
trait PrivateWindowHelpers {
|
||||||
|
@ -321,6 +326,28 @@ impl<'a> WindowHelpers for JSRef<'a, Window> {
|
||||||
script_chan.send(TriggerLoadMsg(self.page.id, url));
|
script_chan.send(TriggerLoadMsg(self.page.id, url));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_fire_timer(&self, timer_id: TimerId, cx: *mut JSContext) {
|
||||||
|
let this_value = self.reflector().get_jsobject();
|
||||||
|
|
||||||
|
let data = match self.active_timers.deref().borrow().find(&timer_id) {
|
||||||
|
None => return,
|
||||||
|
Some(timer_handle) => timer_handle.data,
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: Support extra arguments. This requires passing a `*JSVal` array as `argv`.
|
||||||
|
with_compartment(cx, this_value, || {
|
||||||
|
let mut rval = NullValue();
|
||||||
|
unsafe {
|
||||||
|
JS_CallFunctionValue(cx, this_value, *data.funval,
|
||||||
|
0, ptr::mut_null(), &mut rval);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if !data.is_interval {
|
||||||
|
self.active_timers.deref().borrow_mut().remove(&timer_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> PrivateWindowHelpers for JSRef<'a, Window> {
|
impl<'a> PrivateWindowHelpers for JSRef<'a, Window> {
|
||||||
|
|
|
@ -32,10 +32,8 @@ use layout_interface;
|
||||||
use page::{Page, IterablePage, Frame};
|
use page::{Page, IterablePage, Frame};
|
||||||
|
|
||||||
use geom::point::Point2D;
|
use geom::point::Point2D;
|
||||||
use js::jsapi::JS_CallFunctionValue;
|
|
||||||
use js::jsapi::{JS_SetWrapObjectCallbacks, JS_SetGCZeal, JS_DEFAULT_ZEAL_FREQ, JS_GC};
|
use js::jsapi::{JS_SetWrapObjectCallbacks, JS_SetGCZeal, JS_DEFAULT_ZEAL_FREQ, JS_GC};
|
||||||
use js::jsapi::{JSContext, JSRuntime};
|
use js::jsapi::{JSContext, JSRuntime};
|
||||||
use js::jsval::NullValue;
|
|
||||||
use js::rust::{Cx, RtUtils};
|
use js::rust::{Cx, RtUtils};
|
||||||
use js::rust::with_compartment;
|
use js::rust::with_compartment;
|
||||||
use js;
|
use js;
|
||||||
|
@ -51,7 +49,6 @@ use servo_util::task::send_on_failure;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::comm::{channel, Sender, Receiver};
|
use std::comm::{channel, Sender, Receiver};
|
||||||
use std::mem::replace;
|
use std::mem::replace;
|
||||||
use std::ptr;
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::task::TaskBuilder;
|
use std::task::TaskBuilder;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -416,27 +413,7 @@ impl ScriptTask {
|
||||||
pipeline ID not associated with this script task. This is a bug.");
|
pipeline ID not associated with this script task. This is a bug.");
|
||||||
let frame = page.frame();
|
let frame = page.frame();
|
||||||
let window = frame.get_ref().window.root();
|
let window = frame.get_ref().window.root();
|
||||||
|
window.handle_fire_timer(timer_id, self.get_cx());
|
||||||
let this_value = window.deref().reflector().get_jsobject();
|
|
||||||
|
|
||||||
let data = match window.deref().active_timers.deref().borrow().find(&timer_id) {
|
|
||||||
None => return,
|
|
||||||
Some(timer_handle) => timer_handle.data,
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: Support extra arguments. This requires passing a `*JSVal` array as `argv`.
|
|
||||||
let cx = self.get_cx();
|
|
||||||
with_compartment(cx, this_value, || {
|
|
||||||
let mut rval = NullValue();
|
|
||||||
unsafe {
|
|
||||||
JS_CallFunctionValue(cx, this_value, *data.funval,
|
|
||||||
0, ptr::mut_null(), &mut rval);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if !data.is_interval {
|
|
||||||
window.deref().active_timers.deref().borrow_mut().remove(&timer_id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles a notification that reflow completed.
|
/// Handles a notification that reflow completed.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue