Add further HMTL element prototype hierarchy. Add HTMLImageElement.width getter/setter that interacts with layout.

This commit is contained in:
Josh Matthews 2012-08-21 22:42:38 -07:00
parent bfec29d86f
commit 07c17fdef4
13 changed files with 250 additions and 211 deletions

View file

@ -6,11 +6,11 @@ import js::jsapi::bindgen::{JS_ValueToString, JS_GetStringCharsZAndLength, JS_Re
JS_GetReservedSlot, JS_SetReservedSlot, JS_NewStringCopyN,
JS_DefineFunctions, JS_DefineProperty, JS_GetContextPrivate,
JS_GetClass, JS_GetPrototype};
import js::crust::{JS_ConvertStub, JS_PropertyStub, JS_StrictPropertyStub,
JS_EnumerateStub, JS_ConvertStub, JS_ResolveStub};
import js::glue::bindgen::*;
import ptr::null;
import result::{result, ok, err};
import js::crust::{JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub,
JS_ResolveStub, JS_ConvertStub};
enum DOMString {
str(~str),
@ -95,8 +95,37 @@ extern fn has_instance(_cx: *JSContext, obj: *JSObject, v: *jsval, bp: *mut JSBo
return 1;
}
fn Document_class(compartment: bare_compartment, name: ~str,
finalize: *u8) -> JSClass {
fn prototype_jsclass(name: ~str) -> fn(bare_compartment) -> JSClass {
return fn@(compartment: bare_compartment) -> JSClass {
{name: compartment.add_name(name),
flags: 0,
addProperty: JS_PropertyStub,
delProperty: JS_PropertyStub,
getProperty: JS_PropertyStub,
setProperty: JS_StrictPropertyStub,
enumerate: JS_EnumerateStub,
resolve: JS_PropertyStub,
convert: JS_ConvertStub,
finalize: null(),
checkAccess: null(),
call: null(),
construct: null(),
hasInstance: has_instance,
trace: null(),
reserved: (null(), null(), null(), null(), null(), // 05
null(), null(), null(), null(), null(), // 10
null(), null(), null(), null(), null(), // 15
null(), null(), null(), null(), null(), // 20
null(), null(), null(), null(), null(), // 25
null(), null(), null(), null(), null(), // 30
null(), null(), null(), null(), null(), // 35
null(), null(), null(), null(), null())} // 40
};
}
fn instance_jsclass(name: ~str, finalize: *u8)
-> fn(bare_compartment) -> JSClass {
return fn@(compartment: bare_compartment) -> JSClass {
{name: compartment.add_name(name),
flags: JSCLASS_HAS_RESERVED_SLOTS(1),
addProperty: JS_PropertyStub,
@ -110,7 +139,7 @@ fn Document_class(compartment: bare_compartment, name: ~str,
checkAccess: null(),
call: null(),
construct: null(),
hasInstance: null(),
hasInstance: has_instance,
trace: null(),
reserved: (null(), null(), null(), null(), null(), // 05
null(), null(), null(), null(), null(), // 10
@ -120,4 +149,24 @@ fn Document_class(compartment: bare_compartment, name: ~str,
null(), null(), null(), null(), null(), // 30
null(), null(), null(), null(), null(), // 35
null(), null(), null(), null(), null())} // 40
};
}
fn define_empty_prototype(name: ~str, proto: option<~str>, compartment: bare_compartment)
-> js::rust::jsobj {
compartment.register_class(utils::prototype_jsclass(name));
//TODO error checking
let obj = result::unwrap(
match proto {
some(s) => compartment.new_object_with_proto(name, s,
compartment.global_obj.ptr),
none => compartment.new_object(name, null(), compartment.global_obj.ptr)
});
compartment.define_property(name, RUST_OBJECT_TO_JSVAL(obj.ptr),
JS_PropertyStub, JS_StrictPropertyStub,
JSPROP_ENUMERATE);
compartment.stash_global_proto(name, obj);
return obj;
}