mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Move Window method implementations into actual impl to better reflect proposed bindings.
This commit is contained in:
parent
8729ea5791
commit
006f5be58f
4 changed files with 49 additions and 36 deletions
|
@ -51,7 +51,7 @@ use ptr::null;
|
||||||
enum ControlMsg {
|
enum ControlMsg {
|
||||||
ParseMsg(Url),
|
ParseMsg(Url),
|
||||||
ExecuteMsg(Url),
|
ExecuteMsg(Url),
|
||||||
Timer(~dom::bindings::window::TimerData),
|
Timer(~dom::base::TimerData),
|
||||||
ExitMsg
|
ExitMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,49 +23,23 @@ extern fn alert(cx: *JSContext, argc: c_uint, vp: *jsval) -> JSBool {
|
||||||
assert (argc == 1);
|
assert (argc == 1);
|
||||||
// Abstract this pattern and use it in debug, too?
|
// Abstract this pattern and use it in debug, too?
|
||||||
let jsstr = JS_ValueToString(cx, *ptr::offset(argv, 0));
|
let jsstr = JS_ValueToString(cx, *ptr::offset(argv, 0));
|
||||||
// Right now, just print to the console
|
|
||||||
io::println(#fmt("ALERT: %s", jsval_to_rust_str(cx, jsstr)));
|
(*unwrap(JS_THIS_OBJECT(cx, vp))).payload.alert(jsval_to_rust_str(cx, jsstr));
|
||||||
|
|
||||||
JS_SET_RVAL(cx, vp, JSVAL_NULL);
|
JS_SET_RVAL(cx, vp, JSVAL_NULL);
|
||||||
}
|
}
|
||||||
1_i32
|
1_i32
|
||||||
}
|
}
|
||||||
|
|
||||||
// Holder for the various JS values associated with setTimeout
|
|
||||||
// (ie. function value to invoke and all arguments to pass
|
|
||||||
// to the function when calling it)
|
|
||||||
struct TimerData {
|
|
||||||
funval: jsval,
|
|
||||||
args: DVec<jsval>,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn TimerData(argc: c_uint, argv: *jsval) -> TimerData unsafe {
|
|
||||||
let data = TimerData {
|
|
||||||
funval : *argv,
|
|
||||||
args : DVec(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut i = 2;
|
|
||||||
while i < argc as uint {
|
|
||||||
data.args.push(*ptr::offset(argv, i));
|
|
||||||
i += 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
data
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
extern fn setTimeout(cx: *JSContext, argc: c_uint, vp: *jsval) -> JSBool unsafe {
|
extern fn setTimeout(cx: *JSContext, argc: c_uint, vp: *jsval) -> JSBool unsafe {
|
||||||
let argv = JS_ARGV(cx, vp);
|
let argv = JS_ARGV(cx, vp);
|
||||||
assert (argc >= 2);
|
assert (argc >= 2);
|
||||||
|
|
||||||
//TODO: don't crash when passed a non-integer value for the timeout
|
//TODO: don't crash when passed a non-integer value for the timeout
|
||||||
|
|
||||||
// Post a delayed message to the per-window timer task; it will dispatch it
|
(*unwrap(JS_THIS_OBJECT(cx, vp))).payload.setTimeout(
|
||||||
// to the relevant content handler that will deal with it.
|
RUST_JSVAL_TO_INT(*ptr::offset(argv, 1)) as int,
|
||||||
std::timer::delayed_send(std::uv_global_loop::get(),
|
argc, argv);
|
||||||
RUST_JSVAL_TO_INT(*ptr::offset(argv, 1)) as uint,
|
|
||||||
(*unwrap(JS_THIS_OBJECT(cx, vp))).payload.timer_chan,
|
|
||||||
TimerMessage_Fire(~TimerData(argc, argv)));
|
|
||||||
|
|
||||||
JS_SET_RVAL(cx, vp, JSVAL_NULL);
|
JS_SET_RVAL(cx, vp, JSVAL_NULL);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -23,7 +23,6 @@ enum NodeData = {
|
||||||
kind: ~NodeKind,
|
kind: ~NodeKind,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* The tree holding Nodes (read-only) */
|
/* The tree holding Nodes (read-only) */
|
||||||
enum NodeTree { NodeTree }
|
enum NodeTree { NodeTree }
|
||||||
|
|
||||||
|
@ -176,4 +175,4 @@ impl NodeScope : tree::WriteMethods<Node> {
|
||||||
fn with_tree_fields<R>(node: Node, f: fn(tree::Tree<Node>) -> R) -> R {
|
fn with_tree_fields<R>(node: Node, f: fn(tree::Tree<Node>) -> R) -> R {
|
||||||
self.write(node, |n| f(n.tree))
|
self.write(node, |n| f(n.tree))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use comm::{Port, Chan};
|
||||||
use content::content_task::{ControlMsg, Timer};
|
use content::content_task::{ControlMsg, Timer};
|
||||||
|
|
||||||
enum TimerControlMsg {
|
enum TimerControlMsg {
|
||||||
TimerMessage_Fire(~dom::bindings::window::TimerData),
|
TimerMessage_Fire(~TimerData),
|
||||||
TimerMessage_Close
|
TimerMessage_Close
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,46 @@ struct Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Holder for the various JS values associated with setTimeout
|
||||||
|
// (ie. function value to invoke and all arguments to pass
|
||||||
|
// to the function when calling it)
|
||||||
|
struct TimerData {
|
||||||
|
funval: jsval,
|
||||||
|
args: DVec<jsval>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn TimerData(argc: libc::c_uint, argv: *jsval) -> TimerData unsafe {
|
||||||
|
let data = TimerData {
|
||||||
|
funval : *argv,
|
||||||
|
args : DVec(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut i = 2;
|
||||||
|
while i < argc as uint {
|
||||||
|
data.args.push(*ptr::offset(argv, i));
|
||||||
|
i += 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
data
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Window {
|
||||||
|
fn alert(s: &str) {
|
||||||
|
// Right now, just print to the console
|
||||||
|
io::println(#fmt("ALERT: %s", s));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setTimeout(&self, timeout: int, argc: libc::c_uint, argv: *jsval) {
|
||||||
|
let timeout = int::max(0, timeout) as uint;
|
||||||
|
|
||||||
|
// Post a delayed message to the per-window timer task; it will dispatch it
|
||||||
|
// to the relevant content handler that will deal with it.
|
||||||
|
std::timer::delayed_send(std::uv_global_loop::get(),
|
||||||
|
timeout, self.timer_chan,
|
||||||
|
TimerMessage_Fire(~TimerData(argc, argv)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn Window(content_port: Port<ControlMsg>) -> Window {
|
fn Window(content_port: Port<ControlMsg>) -> Window {
|
||||||
let content_chan = Chan(content_port);
|
let content_chan = Chan(content_port);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue