mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Address review comments.
This commit is contained in:
parent
46a33b4b38
commit
91278da9dd
83 changed files with 316 additions and 374 deletions
|
@ -58,9 +58,7 @@ DOMInterfaces = {
|
||||||
|
|
||||||
# FIXME: This should be renamed: https://github.com/mozilla/servo/issues/1625
|
# FIXME: This should be renamed: https://github.com/mozilla/servo/issues/1625
|
||||||
def addHTMLElement(element):
|
def addHTMLElement(element):
|
||||||
DOMInterfaces[element] = {
|
DOMInterfaces[element] = {}
|
||||||
'nativeType': 'JS<%s>' % element,
|
|
||||||
}
|
|
||||||
|
|
||||||
addHTMLElement('Comment')
|
addHTMLElement('Comment')
|
||||||
addHTMLElement('DocumentFragment')
|
addHTMLElement('DocumentFragment')
|
||||||
|
|
|
@ -281,7 +281,6 @@ class CGMethodCall(CGThing):
|
||||||
isDefinitelyObject=True),
|
isDefinitelyObject=True),
|
||||||
{
|
{
|
||||||
"declName" : "arg%d" % distinguishingIndex,
|
"declName" : "arg%d" % distinguishingIndex,
|
||||||
"simpleDeclName" : "arg%d" % distinguishingIndex,
|
|
||||||
"holderName" : ("arg%d" % distinguishingIndex) + "_holder",
|
"holderName" : ("arg%d" % distinguishingIndex) + "_holder",
|
||||||
"val" : distinguishingArg
|
"val" : distinguishingArg
|
||||||
})
|
})
|
||||||
|
@ -395,6 +394,9 @@ def typeIsSequenceOrHasSequenceMember(type):
|
||||||
type.flatMemberTypes)
|
type.flatMemberTypes)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def typeNeedsRooting(type, descriptorProvider):
|
||||||
|
return type.isGeckoInterface() and descriptorProvider.getDescriptor(type.name).needsRooting
|
||||||
|
|
||||||
def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
isDefinitelyObject=False,
|
isDefinitelyObject=False,
|
||||||
isMember=False,
|
isMember=False,
|
||||||
|
@ -482,6 +484,8 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
if exceptionCode is None:
|
if exceptionCode is None:
|
||||||
exceptionCode = "return 0;"
|
exceptionCode = "return 0;"
|
||||||
|
|
||||||
|
needsRooting = typeNeedsRooting(type, descriptorProvider)
|
||||||
|
|
||||||
def handleOptional(template, declType, isOptional):
|
def handleOptional(template, declType, isOptional):
|
||||||
if isOptional:
|
if isOptional:
|
||||||
template = "Some(%s)" % template
|
template = "Some(%s)" % template
|
||||||
|
@ -490,7 +494,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
else:
|
else:
|
||||||
initialValue = None
|
initialValue = None
|
||||||
|
|
||||||
return (template, declType, isOptional, initialValue)
|
return (template, declType, isOptional, initialValue, needsRooting)
|
||||||
|
|
||||||
# Unfortunately, .capitalize() on a string will lowercase things inside the
|
# Unfortunately, .capitalize() on a string will lowercase things inside the
|
||||||
# string, which we do not want.
|
# string, which we do not want.
|
||||||
|
@ -751,7 +755,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
"} else {\n"
|
"} else {\n"
|
||||||
" ${declName} = NULL;\n"
|
" ${declName} = NULL;\n"
|
||||||
"}" % haveCallable,
|
"}" % haveCallable,
|
||||||
CGGeneric("JSObject*"), isOptional, None)
|
CGGeneric("JSObject*"), isOptional, None, needsRooting)
|
||||||
|
|
||||||
if type.isAny():
|
if type.isAny():
|
||||||
assert not isEnforceRange and not isClamp
|
assert not isEnforceRange and not isClamp
|
||||||
|
@ -795,7 +799,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
assert not isOptional
|
assert not isOptional
|
||||||
# This one only happens for return values, and its easy: Just
|
# This one only happens for return values, and its easy: Just
|
||||||
# ignore the jsval.
|
# ignore the jsval.
|
||||||
return ("", None, False, None)
|
return ("", None, False, None, False)
|
||||||
|
|
||||||
if not type.isPrimitive():
|
if not type.isPrimitive():
|
||||||
raise TypeError("Need conversion for argument type '%s'" % str(type))
|
raise TypeError("Need conversion for argument type '%s'" % str(type))
|
||||||
|
@ -848,7 +852,7 @@ def instantiateJSToNativeConversionTemplate(templateTuple, replacements,
|
||||||
replace ${argc} and ${index}, where ${index} is the index of this
|
replace ${argc} and ${index}, where ${index} is the index of this
|
||||||
argument (0-based) and ${argc} is the total number of arguments.
|
argument (0-based) and ${argc} is the total number of arguments.
|
||||||
"""
|
"""
|
||||||
(templateBody, declType, dealWithOptional, initialValue) = templateTuple
|
(templateBody, declType, dealWithOptional, initialValue, needsRooting) = templateTuple
|
||||||
|
|
||||||
if dealWithOptional and argcAndIndex is None:
|
if dealWithOptional and argcAndIndex is None:
|
||||||
raise TypeError("Have to deal with optional things, but don't know how")
|
raise TypeError("Have to deal with optional things, but don't know how")
|
||||||
|
@ -895,9 +899,8 @@ def instantiateJSToNativeConversionTemplate(templateTuple, replacements,
|
||||||
# conversion.
|
# conversion.
|
||||||
result.append(CGGeneric(""))
|
result.append(CGGeneric(""))
|
||||||
|
|
||||||
type = declType.define() if declType else None
|
if needsRooting:
|
||||||
if type and 'JS<' in type:
|
rootBody = "let ${declName} = ${declName}.root();"
|
||||||
rootBody = "let ${simpleDeclName} = ${declName}.root();"
|
|
||||||
result.append(CGGeneric(string.Template(rootBody).substitute(replacements)))
|
result.append(CGGeneric(string.Template(rootBody).substitute(replacements)))
|
||||||
result.append(CGGeneric(""))
|
result.append(CGGeneric(""))
|
||||||
|
|
||||||
|
@ -942,7 +945,6 @@ class CGArgumentConverter(CGThing):
|
||||||
}
|
}
|
||||||
self.replacementVariables = {
|
self.replacementVariables = {
|
||||||
"declName" : "arg%d" % index,
|
"declName" : "arg%d" % index,
|
||||||
"simpleDeclName" : "arg%d" % index,
|
|
||||||
"holderName" : ("arg%d" % index) + "_holder"
|
"holderName" : ("arg%d" % index) + "_holder"
|
||||||
}
|
}
|
||||||
self.replacementVariables["val"] = string.Template(
|
self.replacementVariables["val"] = string.Template(
|
||||||
|
@ -1808,7 +1810,7 @@ def CreateBindingJSObject(descriptor, parent=None):
|
||||||
if descriptor.proxy:
|
if descriptor.proxy:
|
||||||
assert not descriptor.createGlobal
|
assert not descriptor.createGlobal
|
||||||
handler = """
|
handler = """
|
||||||
let js_info = aScope.get().page().js_info();
|
let js_info = aScope.deref().page().js_info();
|
||||||
let handler = js_info.get_ref().dom_static.proxy_handlers.deref().get(&(PrototypeList::id::%s as uint));
|
let handler = js_info.get_ref().dom_static.proxy_handlers.deref().get(&(PrototypeList::id::%s as uint));
|
||||||
""" % descriptor.name
|
""" % descriptor.name
|
||||||
create += handler + """ let obj = NewProxyObject(aCx, *handler,
|
create += handler + """ let obj = NewProxyObject(aCx, *handler,
|
||||||
|
@ -2480,13 +2482,9 @@ class CGSpecializedMethod(CGAbstractExternMethod):
|
||||||
|
|
||||||
def definition_body(self):
|
def definition_body(self):
|
||||||
name = self.method.identifier.name
|
name = self.method.identifier.name
|
||||||
nativeName = MakeNativeName(name)
|
return CGWrapper(CGMethodCall([], MakeNativeName(name), self.method.isStatic(),
|
||||||
extraPre = ''
|
|
||||||
argsPre = []
|
|
||||||
return CGWrapper(CGMethodCall(argsPre, nativeName, self.method.isStatic(),
|
|
||||||
self.descriptor, self.method),
|
self.descriptor, self.method),
|
||||||
pre=extraPre +
|
pre=" let this = JS::from_raw(this);\n" +
|
||||||
" let this = JS::from_raw(this);\n" +
|
|
||||||
" let mut this = this.root();\n").define()
|
" let mut this = this.root();\n").define()
|
||||||
|
|
||||||
class CGGenericGetter(CGAbstractBindingMethod):
|
class CGGenericGetter(CGAbstractBindingMethod):
|
||||||
|
@ -2530,17 +2528,14 @@ class CGSpecializedGetter(CGAbstractExternMethod):
|
||||||
def definition_body(self):
|
def definition_body(self):
|
||||||
name = self.attr.identifier.name
|
name = self.attr.identifier.name
|
||||||
nativeName = MakeNativeName(name)
|
nativeName = MakeNativeName(name)
|
||||||
extraPre = ''
|
|
||||||
argsPre = []
|
|
||||||
infallible = ('infallible' in
|
infallible = ('infallible' in
|
||||||
self.descriptor.getExtendedAttributes(self.attr,
|
self.descriptor.getExtendedAttributes(self.attr,
|
||||||
getter=True))
|
getter=True))
|
||||||
if self.attr.type.nullable() or not infallible:
|
if self.attr.type.nullable() or not infallible:
|
||||||
nativeName = "Get" + nativeName
|
nativeName = "Get" + nativeName
|
||||||
return CGWrapper(CGIndenter(CGGetterCall(argsPre, self.attr.type, nativeName,
|
return CGWrapper(CGIndenter(CGGetterCall([], self.attr.type, nativeName,
|
||||||
self.descriptor, self.attr)),
|
self.descriptor, self.attr)),
|
||||||
pre=extraPre +
|
pre=" let this = JS::from_raw(this);\n" +
|
||||||
" let this = JS::from_raw(this);\n" +
|
|
||||||
" let mut this = this.root();\n").define()
|
" let mut this = this.root();\n").define()
|
||||||
|
|
||||||
class CGGenericSetter(CGAbstractBindingMethod):
|
class CGGenericSetter(CGAbstractBindingMethod):
|
||||||
|
@ -2588,13 +2583,10 @@ class CGSpecializedSetter(CGAbstractExternMethod):
|
||||||
|
|
||||||
def definition_body(self):
|
def definition_body(self):
|
||||||
name = self.attr.identifier.name
|
name = self.attr.identifier.name
|
||||||
nativeName = "Set" + MakeNativeName(name)
|
return CGWrapper(CGIndenter(CGSetterCall([], self.attr.type,
|
||||||
argsPre = []
|
"Set" + MakeNativeName(name),
|
||||||
extraPre = ''
|
|
||||||
return CGWrapper(CGIndenter(CGSetterCall(argsPre, self.attr.type, nativeName,
|
|
||||||
self.descriptor, self.attr)),
|
self.descriptor, self.attr)),
|
||||||
pre=extraPre +
|
pre=" let this = JS::from_raw(this);\n" +
|
||||||
" let this = JS::from_raw(this);\n" +
|
|
||||||
" let mut this = this.root();\n").define()
|
" let mut this = this.root();\n").define()
|
||||||
|
|
||||||
|
|
||||||
|
@ -2763,7 +2755,7 @@ def getUnionTypeTemplateVars(type, descriptorProvider):
|
||||||
name = type.name
|
name = type.name
|
||||||
typeName = "/*" + type.name + "*/"
|
typeName = "/*" + type.name + "*/"
|
||||||
|
|
||||||
(template, _, _, _) = getJSToNativeConversionTemplate(
|
(template, _, _, _, _) = getJSToNativeConversionTemplate(
|
||||||
type, descriptorProvider, failureCode="return Ok(None);",
|
type, descriptorProvider, failureCode="return Ok(None);",
|
||||||
exceptionCode='return Err(());',
|
exceptionCode='return Err(());',
|
||||||
isDefinitelyObject=True, isOptional=False)
|
isDefinitelyObject=True, isOptional=False)
|
||||||
|
@ -3421,7 +3413,6 @@ class CGProxySpecialOperation(CGPerSignatureCall):
|
||||||
treatNullAs=argument.treatNullAs)
|
treatNullAs=argument.treatNullAs)
|
||||||
templateValues = {
|
templateValues = {
|
||||||
"declName": argument.identifier.name,
|
"declName": argument.identifier.name,
|
||||||
"simpleDeclName": argument.identifier.name,
|
|
||||||
"holderName": argument.identifier.name + "_holder",
|
"holderName": argument.identifier.name + "_holder",
|
||||||
"val": "(*desc).value",
|
"val": "(*desc).value",
|
||||||
"valPtr": "&(*desc).value"
|
"valPtr": "&(*desc).value"
|
||||||
|
@ -3868,9 +3859,8 @@ class CGClassConstructHook(CGAbstractExternMethod):
|
||||||
|
|
||||||
def generate_code(self):
|
def generate_code(self):
|
||||||
preamble = """
|
preamble = """
|
||||||
let global = global_object_for_js_object(JS_CALLEE(cx, &*vp).to_object());
|
let global = global_object_for_js_object(JS_CALLEE(cx, &*vp).to_object()).root();
|
||||||
let global = global.root();
|
let obj = global.deref().reflector().get_jsobject();
|
||||||
let obj = global.reflector().get_jsobject();
|
|
||||||
"""
|
"""
|
||||||
nativeName = MakeNativeName(self._ctor.identifier.name)
|
nativeName = MakeNativeName(self._ctor.identifier.name)
|
||||||
callGenerator = CGMethodCall(["&global.root_ref()"], nativeName, True,
|
callGenerator = CGMethodCall(["&global.root_ref()"], nativeName, True,
|
||||||
|
@ -4148,14 +4138,14 @@ class CGDictionary(CGThing):
|
||||||
|
|
||||||
def getMemberType(self, memberInfo):
|
def getMemberType(self, memberInfo):
|
||||||
(member, (templateBody, declType,
|
(member, (templateBody, declType,
|
||||||
dealWithOptional, initialValue)) = memberInfo
|
dealWithOptional, initialValue, _)) = memberInfo
|
||||||
if dealWithOptional:
|
if dealWithOptional:
|
||||||
declType = CGWrapper(declType, pre="Optional< ", post=" >")
|
declType = CGWrapper(declType, pre="Optional< ", post=" >")
|
||||||
return declType.define()
|
return declType.define()
|
||||||
|
|
||||||
def getMemberConversion(self, memberInfo):
|
def getMemberConversion(self, memberInfo):
|
||||||
(member, (templateBody, declType,
|
(member, (templateBody, declType,
|
||||||
dealWithOptional, initialValue)) = memberInfo
|
dealWithOptional, initialValue, _)) = memberInfo
|
||||||
replacements = { "val": "value.unwrap()" }
|
replacements = { "val": "value.unwrap()" }
|
||||||
if member.defaultValue:
|
if member.defaultValue:
|
||||||
replacements["haveValue"] = "value.is_some()"
|
replacements["haveValue"] = "value.is_some()"
|
||||||
|
@ -4310,7 +4300,9 @@ class CGBindingRoot(CGThing):
|
||||||
'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}',
|
'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}',
|
||||||
'dom::types::*',
|
'dom::types::*',
|
||||||
'dom::bindings',
|
'dom::bindings',
|
||||||
'dom::bindings::js::{JS, JSRef, Root, RootedReference, Temporary, OptionalRootable, OptionalRootedRootable, ResultRootable}',
|
'dom::bindings::js::{JS, JSRef, Root, RootedReference, Temporary}',
|
||||||
|
'dom::bindings::js::{OptionalRootable, OptionalRootedRootable, ResultRootable}',
|
||||||
|
'dom::bindings::js::{OptionalRootedReference, OptionalOptionalRootedRootable}',
|
||||||
'dom::bindings::utils::{CreateDOMGlobal, CreateInterfaceObjects2}',
|
'dom::bindings::utils::{CreateDOMGlobal, CreateInterfaceObjects2}',
|
||||||
'dom::bindings::utils::{ConstantSpec, cx_for_dom_object, Default}',
|
'dom::bindings::utils::{ConstantSpec, cx_for_dom_object, Default}',
|
||||||
'dom::bindings::utils::{dom_object_slot, DOM_OBJECT_SLOT, DOMClass}',
|
'dom::bindings::utils::{dom_object_slot, DOM_OBJECT_SLOT, DOMClass}',
|
||||||
|
@ -5311,7 +5303,7 @@ class GlobalGenRoots():
|
||||||
cast = [CGGeneric(string.Template('''pub trait ${castTraitName} {
|
cast = [CGGeneric(string.Template('''pub trait ${castTraitName} {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn to_ref<'a, 'b, T: ${toBound}+Reflectable>(base: &'a JSRef<'b, T>) -> Option<&'a JSRef<'b, Self>> {
|
fn to_ref<'a, 'b, T: ${toBound}+Reflectable>(base: &'a JSRef<'b, T>) -> Option<&'a JSRef<'b, Self>> {
|
||||||
match base.get().${checkFn}() {
|
match base.deref().${checkFn}() {
|
||||||
true => unsafe { Some(base.transmute()) },
|
true => unsafe { Some(base.transmute()) },
|
||||||
false => None
|
false => None
|
||||||
}
|
}
|
||||||
|
@ -5319,7 +5311,7 @@ class GlobalGenRoots():
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn to_mut_ref<'a, 'b, T: ${toBound}+Reflectable>(base: &'a mut JSRef<'b, T>) -> Option<&'a mut JSRef<'b, Self>> {
|
fn to_mut_ref<'a, 'b, T: ${toBound}+Reflectable>(base: &'a mut JSRef<'b, T>) -> Option<&'a mut JSRef<'b, Self>> {
|
||||||
match base.get().${checkFn}() {
|
match base.deref().${checkFn}() {
|
||||||
true => unsafe { Some(base.transmute_mut()) },
|
true => unsafe { Some(base.transmute_mut()) },
|
||||||
false => None
|
false => None
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,15 +128,18 @@ class Descriptor(DescriptorProvider):
|
||||||
|
|
||||||
# Read the desc, and fill in the relevant defaults.
|
# Read the desc, and fill in the relevant defaults.
|
||||||
ifaceName = self.interface.identifier.name
|
ifaceName = self.interface.identifier.name
|
||||||
|
|
||||||
|
# Callback types do not use JS smart pointers, so we should not use the
|
||||||
|
# built-in rooting mechanisms for them.
|
||||||
if self.interface.isCallback():
|
if self.interface.isCallback():
|
||||||
nativeTypeDefault = "nsIDOM" + ifaceName
|
self.needsRooting = False
|
||||||
else:
|
else:
|
||||||
nativeTypeDefault = 'JS<%s>' % ifaceName
|
self.needsRooting = True
|
||||||
|
|
||||||
self.returnType = "Temporary<%s>" % ifaceName
|
self.returnType = "Temporary<%s>" % ifaceName
|
||||||
self.argumentType = "JSRef<%s>" % ifaceName
|
self.argumentType = "JSRef<%s>" % ifaceName
|
||||||
self.memberType = "Root<'a, 'b, %s>" % ifaceName
|
self.memberType = "Root<'a, 'b, %s>" % ifaceName
|
||||||
self.nativeType = desc.get('nativeType', nativeTypeDefault)
|
self.nativeType = desc.get('nativeType', 'JS<%s>' % ifaceName)
|
||||||
self.concreteType = desc.get('concreteType', ifaceName)
|
self.concreteType = desc.get('concreteType', ifaceName)
|
||||||
self.createGlobal = desc.get('createGlobal', False)
|
self.createGlobal = desc.get('createGlobal', False)
|
||||||
self.register = desc.get('register', True)
|
self.register = desc.get('register', True)
|
||||||
|
|
|
@ -40,8 +40,8 @@
|
||||||
/// - RootedReference: makes obtaining an Option<JSRef<T>> from an Option<Root<T>> easy
|
/// - RootedReference: makes obtaining an Option<JSRef<T>> from an Option<Root<T>> easy
|
||||||
|
|
||||||
use dom::bindings::utils::{Reflector, Reflectable, cx_for_dom_object};
|
use dom::bindings::utils::{Reflector, Reflectable, cx_for_dom_object};
|
||||||
use dom::window::Window;
|
use dom::node::Node;
|
||||||
use js::jsapi::{JSObject, JSContext, JS_AddObjectRoot, JS_RemoveObjectRoot};
|
use js::jsapi::{JSObject, JS_AddObjectRoot, JS_RemoveObjectRoot};
|
||||||
use layout_interface::TrustedNodeAddress;
|
use layout_interface::TrustedNodeAddress;
|
||||||
use script_task::StackRoots;
|
use script_task::StackRoots;
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ impl<T: Reflectable> Temporary<T> {
|
||||||
Temporary::new(root.unrooted())
|
Temporary::new(root.unrooted())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Root this unrooted value.
|
/// Create a stack-bounded root for this value.
|
||||||
pub fn root<'a, 'b>(self) -> Root<'a, 'b, T> {
|
pub fn root<'a, 'b>(self) -> Root<'a, 'b, T> {
|
||||||
local_data::get(StackRoots, |opt| {
|
local_data::get(StackRoots, |opt| {
|
||||||
let collection = opt.unwrap();
|
let collection = opt.unwrap();
|
||||||
|
@ -130,15 +130,17 @@ impl <T> Clone for JS<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Reflectable> JS<T> {
|
impl JS<Node> {
|
||||||
/// Create a new JS-reflected DOM object; returns an Temporary type because the new value
|
/// Create a new JS-owned value wrapped from an address known to be a Node pointer.
|
||||||
/// is not safe to use until it is rooted.
|
pub unsafe fn from_trusted_node_address(inner: TrustedNodeAddress) -> JS<Node> {
|
||||||
pub fn new(obj: ~T,
|
let TrustedNodeAddress(addr) = inner;
|
||||||
window: &JSRef<Window>,
|
JS {
|
||||||
wrap_fn: extern "Rust" fn(*JSContext, &JSRef<Window>, ~T) -> JS<T>) -> Temporary<T> {
|
ptr: RefCell::new(addr as *mut Node)
|
||||||
Temporary::new(wrap_fn(window.get().get_cx(), window, obj))
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: Reflectable> JS<T> {
|
||||||
/// Create a new JS-owned value wrapped from a raw Rust pointer.
|
/// Create a new JS-owned value wrapped from a raw Rust pointer.
|
||||||
pub unsafe fn from_raw(raw: *mut T) -> JS<T> {
|
pub unsafe fn from_raw(raw: *mut T) -> JS<T> {
|
||||||
JS {
|
JS {
|
||||||
|
@ -147,14 +149,6 @@ impl<T: Reflectable> JS<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Create a new JS-owned value wrapped from an address known to be a Node pointer.
|
|
||||||
pub unsafe fn from_trusted_node_address(inner: TrustedNodeAddress) -> JS<T> {
|
|
||||||
let TrustedNodeAddress(addr) = inner;
|
|
||||||
JS {
|
|
||||||
ptr: RefCell::new(addr as *mut T)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Root this JS-owned value to prevent its collection as garbage.
|
/// Root this JS-owned value to prevent its collection as garbage.
|
||||||
pub fn root<'a, 'b>(&self) -> Root<'a, 'b, T> {
|
pub fn root<'a, 'b>(&self) -> Root<'a, 'b, T> {
|
||||||
local_data::get(StackRoots, |opt| {
|
local_data::get(StackRoots, |opt| {
|
||||||
|
@ -209,6 +203,8 @@ impl<From, To> JS<From> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Get an Option<JSRef<T>> out of an Option<Root<T>>
|
||||||
pub trait RootedReference<T> {
|
pub trait RootedReference<T> {
|
||||||
fn root_ref<'a>(&'a self) -> Option<JSRef<'a, T>>;
|
fn root_ref<'a>(&'a self) -> Option<JSRef<'a, T>>;
|
||||||
}
|
}
|
||||||
|
@ -219,6 +215,17 @@ impl<'a, 'b, T: Reflectable> RootedReference<T> for Option<Root<'a, 'b, T>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get an Option<Option<JSRef<T>>> out of an Option<Option<Root<T>>>
|
||||||
|
pub trait OptionalRootedReference<T> {
|
||||||
|
fn root_ref<'a>(&'a self) -> Option<Option<JSRef<'a, T>>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, 'b, T: Reflectable> OptionalRootedReference<T> for Option<Option<Root<'a, 'b, T>>> {
|
||||||
|
fn root_ref<'a>(&'a self) -> Option<Option<JSRef<'a, T>>> {
|
||||||
|
self.as_ref().map(|inner| inner.root_ref())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Trait that allows extracting a JS<T> value from a variety of rooting-related containers,
|
/// Trait that allows extracting a JS<T> value from a variety of rooting-related containers,
|
||||||
/// which in general is an unsafe operation since they can outlive the rooted lifetime of the
|
/// which in general is an unsafe operation since they can outlive the rooted lifetime of the
|
||||||
/// original value.
|
/// original value.
|
||||||
|
@ -244,6 +251,8 @@ impl<T: Reflectable> Assignable<T> for Temporary<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Assign an optional rootable value (either of JS<T> or Temporary<T>) to an optional
|
||||||
|
/// field of a DOM type (ie. Option<JS<T>>)
|
||||||
pub trait OptionalSettable<T> {
|
pub trait OptionalSettable<T> {
|
||||||
fn assign(&mut self, val: Option<T>);
|
fn assign(&mut self, val: Option<T>);
|
||||||
}
|
}
|
||||||
|
@ -254,6 +263,7 @@ impl<T: Assignable<U>, U: Reflectable> OptionalSettable<T> for Option<JS<U>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Root a rootable Option type (used for Option<Temporary<T>>)
|
||||||
pub trait OptionalRootable<T> {
|
pub trait OptionalRootable<T> {
|
||||||
fn root<'a, 'b>(self) -> Option<Root<'a, 'b, T>>;
|
fn root<'a, 'b>(self) -> Option<Root<'a, 'b, T>>;
|
||||||
}
|
}
|
||||||
|
@ -264,6 +274,18 @@ impl<T: Reflectable> OptionalRootable<T> for Option<Temporary<T>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return an unrooted type for storing in optional DOM fields
|
||||||
|
pub trait OptionalUnrootable<T> {
|
||||||
|
fn unrooted(&self) -> Option<JS<T>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, T: Reflectable> OptionalUnrootable<T> for Option<JSRef<'a, T>> {
|
||||||
|
fn unrooted(&self) -> Option<JS<T>> {
|
||||||
|
self.as_ref().map(|inner| inner.unrooted())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Root a rootable Option type (used for Option<JS<T>>)
|
||||||
pub trait OptionalRootedRootable<T> {
|
pub trait OptionalRootedRootable<T> {
|
||||||
fn root<'a, 'b>(&self) -> Option<Root<'a, 'b, T>>;
|
fn root<'a, 'b>(&self) -> Option<Root<'a, 'b, T>>;
|
||||||
}
|
}
|
||||||
|
@ -274,6 +296,19 @@ impl<T: Reflectable> OptionalRootedRootable<T> for Option<JS<T>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Root a rootable Option<Option> type (used for Option<Option<JS<T>>>)
|
||||||
|
pub trait OptionalOptionalRootedRootable<T> {
|
||||||
|
fn root<'a, 'b>(&self) -> Option<Option<Root<'a, 'b, T>>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Reflectable> OptionalOptionalRootedRootable<T> for Option<Option<JS<T>>> {
|
||||||
|
fn root<'a, 'b>(&self) -> Option<Option<Root<'a, 'b, T>>> {
|
||||||
|
self.as_ref().map(|inner| inner.root())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Root a rootable Result type (any of Temporary<T> or JS<T>)
|
||||||
pub trait ResultRootable<T,U> {
|
pub trait ResultRootable<T,U> {
|
||||||
fn root<'a, 'b>(self) -> Result<Root<'a, 'b, T>, U>;
|
fn root<'a, 'b>(self) -> Result<Root<'a, 'b, T>, U>;
|
||||||
}
|
}
|
||||||
|
@ -310,26 +345,30 @@ impl<T: Assignable<U>, U: Reflectable> TemporaryPushable<T> for Vec<JS<U>> {
|
||||||
|
|
||||||
/// An opaque, LIFO rooting mechanism.
|
/// An opaque, LIFO rooting mechanism.
|
||||||
pub struct RootCollection {
|
pub struct RootCollection {
|
||||||
roots: RefCell<~[*JSObject]>,
|
roots: RefCell<Vec<*JSObject>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RootCollection {
|
impl RootCollection {
|
||||||
|
/// Create an empty collection of roots
|
||||||
pub fn new() -> RootCollection {
|
pub fn new() -> RootCollection {
|
||||||
RootCollection {
|
RootCollection {
|
||||||
roots: RefCell::new(~[]),
|
roots: RefCell::new(vec!()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a new stack-bounded root that will not outlive this collection
|
||||||
fn new_root<'a, 'b, T: Reflectable>(&'a self, unrooted: &JS<T>) -> Root<'a, 'b, T> {
|
fn new_root<'a, 'b, T: Reflectable>(&'a self, unrooted: &JS<T>) -> Root<'a, 'b, T> {
|
||||||
Root::new(self, unrooted)
|
Root::new(self, unrooted)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Track a stack-based root to ensure LIFO root ordering
|
||||||
fn root<'a, 'b, T: Reflectable>(&self, untracked: &Root<'a, 'b, T>) {
|
fn root<'a, 'b, T: Reflectable>(&self, untracked: &Root<'a, 'b, T>) {
|
||||||
let mut roots = self.roots.borrow_mut();
|
let mut roots = self.roots.borrow_mut();
|
||||||
roots.push(untracked.js_ptr);
|
roots.push(untracked.js_ptr);
|
||||||
debug!(" rooting {:?}", untracked.js_ptr);
|
debug!(" rooting {:?}", untracked.js_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Stop tracking a stack-based root, asserting if LIFO root ordering has been violated
|
||||||
fn unroot<'a, 'b, T: Reflectable>(&self, rooted: &Root<'a, 'b, T>) {
|
fn unroot<'a, 'b, T: Reflectable>(&self, rooted: &Root<'a, 'b, T>) {
|
||||||
let mut roots = self.roots.borrow_mut();
|
let mut roots = self.roots.borrow_mut();
|
||||||
debug!("unrooting {:?} (expecting {:?}", roots.last().unwrap(), rooted.js_ptr);
|
debug!("unrooting {:?} (expecting {:?}", roots.last().unwrap(), rooted.js_ptr);
|
||||||
|
@ -355,6 +394,9 @@ pub struct Root<'a, 'b, T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b, T: Reflectable> Root<'a, 'b, T> {
|
impl<'a, 'b, T: Reflectable> Root<'a, 'b, T> {
|
||||||
|
/// Create a new stack-bounded root for the provided JS-owned value.
|
||||||
|
/// It cannot not outlive its associated RootCollection, and it contains a JSRef
|
||||||
|
/// which cannot outlive this new Root.
|
||||||
fn new(roots: &'a RootCollection, unrooted: &JS<T>) -> Root<'a, 'b, T> {
|
fn new(roots: &'a RootCollection, unrooted: &JS<T>) -> Root<'a, 'b, T> {
|
||||||
let root = Root {
|
let root = Root {
|
||||||
root_list: roots,
|
root_list: roots,
|
||||||
|
@ -369,20 +411,8 @@ impl<'a, 'b, T: Reflectable> Root<'a, 'b, T> {
|
||||||
root
|
root
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get<'a>(&'a self) -> &'a T {
|
/// Obtain a safe reference to the wrapped JS owned-value that cannot outlive
|
||||||
unsafe {
|
/// the lifetime of this root.
|
||||||
let borrow = self.ptr.borrow();
|
|
||||||
&**borrow
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_mut<'a>(&'a mut self) -> &'a mut T {
|
|
||||||
unsafe {
|
|
||||||
let mut borrow = self.ptr.borrow_mut();
|
|
||||||
&mut **borrow
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn root_ref<'b>(&'b self) -> JSRef<'b,T> {
|
pub fn root_ref<'b>(&'b self) -> JSRef<'b,T> {
|
||||||
self.jsref.clone()
|
self.jsref.clone()
|
||||||
}
|
}
|
||||||
|
@ -395,37 +425,33 @@ impl<'a, 'b, T: Reflectable> Drop for Root<'a, 'b, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b, T: Reflectable> Reflectable for Root<'a, 'b, T> {
|
|
||||||
fn reflector<'a>(&'a self) -> &'a Reflector {
|
|
||||||
self.get().reflector()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector {
|
|
||||||
self.get_mut().mut_reflector()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, 'b, T: Reflectable> Deref<JSRef<'b, T>> for Root<'a, 'b, T> {
|
impl<'a, 'b, T: Reflectable> Deref<JSRef<'b, T>> for Root<'a, 'b, T> {
|
||||||
fn deref<'c>(&'c self) -> &'c JSRef<'b, T> {
|
fn deref<'c>(&'c self) -> &'c JSRef<'b, T> {
|
||||||
&'a self.jsref
|
&self.jsref
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b, T: Reflectable> DerefMut<JSRef<'b, T>> for Root<'a, 'b, T> {
|
impl<'a, 'b, T: Reflectable> DerefMut<JSRef<'b, T>> for Root<'a, 'b, T> {
|
||||||
fn deref_mut<'c>(&'c mut self) -> &'c mut JSRef<'b, T> {
|
fn deref_mut<'c>(&'c mut self) -> &'c mut JSRef<'b, T> {
|
||||||
&'a mut self.jsref
|
&mut self.jsref
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: Reflectable> Deref<T> for JSRef<'a, T> {
|
impl<'a, T: Reflectable> Deref<T> for JSRef<'a, T> {
|
||||||
fn deref<'b>(&'b self) -> &'b T {
|
fn deref<'b>(&'b self) -> &'b T {
|
||||||
self.get()
|
let borrow = self.ptr.borrow();
|
||||||
|
unsafe {
|
||||||
|
&**borrow
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: Reflectable> DerefMut<T> for JSRef<'a, T> {
|
impl<'a, T: Reflectable> DerefMut<T> for JSRef<'a, T> {
|
||||||
fn deref_mut<'b>(&'b mut self) -> &'b mut T {
|
fn deref_mut<'b>(&'b mut self) -> &'b mut T {
|
||||||
self.get_mut()
|
let mut borrowed = self.ptr.borrow_mut();
|
||||||
|
unsafe {
|
||||||
|
&mut **borrowed
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,20 +477,6 @@ impl<'a, T> Eq for JSRef<'a, T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a,T> JSRef<'a,T> {
|
impl<'a,T> JSRef<'a,T> {
|
||||||
pub fn get<'a>(&'a self) -> &'a T {
|
|
||||||
unsafe {
|
|
||||||
let borrow = self.ptr.borrow();
|
|
||||||
&**borrow
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_mut<'a>(&'a mut self) -> &'a mut T {
|
|
||||||
let mut borrowed = self.ptr.borrow_mut();
|
|
||||||
unsafe {
|
|
||||||
&mut **borrowed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//XXXjdm It would be lovely if this could be private.
|
//XXXjdm It would be lovely if this could be private.
|
||||||
pub unsafe fn transmute<'b, To>(&'b self) -> &'b JSRef<'a, To> {
|
pub unsafe fn transmute<'b, To>(&'b self) -> &'b JSRef<'a, To> {
|
||||||
cast::transmute(self)
|
cast::transmute(self)
|
||||||
|
@ -484,10 +496,10 @@ impl<'a,T> JSRef<'a,T> {
|
||||||
|
|
||||||
impl<'a, T: Reflectable> Reflectable for JSRef<'a, T> {
|
impl<'a, T: Reflectable> Reflectable for JSRef<'a, T> {
|
||||||
fn reflector<'a>(&'a self) -> &'a Reflector {
|
fn reflector<'a>(&'a self) -> &'a Reflector {
|
||||||
self.get().reflector()
|
self.deref().reflector()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector {
|
fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector {
|
||||||
self.get_mut().mut_reflector()
|
self.deref_mut().mut_reflector()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -392,7 +392,7 @@ pub fn reflect_dom_object<T: Reflectable>
|
||||||
window: &JSRef<window::Window>,
|
window: &JSRef<window::Window>,
|
||||||
wrap_fn: extern "Rust" fn(*JSContext, &JSRef<window::Window>, ~T) -> JS<T>)
|
wrap_fn: extern "Rust" fn(*JSContext, &JSRef<window::Window>, ~T) -> JS<T>)
|
||||||
-> Temporary<T> {
|
-> Temporary<T> {
|
||||||
JS::new(obj, window, wrap_fn)
|
Temporary::new(wrap_fn(window.deref().get_cx(), window, obj))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Eq)]
|
#[deriving(Eq)]
|
||||||
|
@ -415,8 +415,8 @@ impl Reflector {
|
||||||
/// Return a pointer to the memory location at which the JS reflector object is stored.
|
/// Return a pointer to the memory location at which the JS reflector object is stored.
|
||||||
/// Used by Temporary values to root the reflector, as required by the JSAPI rooting
|
/// Used by Temporary values to root the reflector, as required by the JSAPI rooting
|
||||||
/// APIs.
|
/// APIs.
|
||||||
pub fn rootable(&self) -> **JSObject {
|
pub fn rootable<'a>(&'a self) -> &'a *JSObject {
|
||||||
&self.object as **JSObject
|
&self.object
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new() -> Reflector {
|
pub fn new() -> Reflector {
|
||||||
|
@ -634,7 +634,7 @@ pub fn global_object_for_js_object(obj: *JSObject) -> JS<window::Window> {
|
||||||
|
|
||||||
fn cx_for_dom_reflector(obj: *JSObject) -> *JSContext {
|
fn cx_for_dom_reflector(obj: *JSObject) -> *JSContext {
|
||||||
let win = global_object_for_js_object(obj).root();
|
let win = global_object_for_js_object(obj).root();
|
||||||
let js_info = win.get().page().js_info();
|
let js_info = win.deref().page().js_info();
|
||||||
match *js_info {
|
match *js_info {
|
||||||
Some(ref info) => info.js_context.deref().deref().ptr,
|
Some(ref info) => info.js_context.deref().deref().ptr,
|
||||||
None => fail!("no JS context for DOM global")
|
None => fail!("no JS context for DOM global")
|
||||||
|
|
|
@ -48,13 +48,13 @@ impl BrowserContext {
|
||||||
|
|
||||||
pub fn create_window_proxy(&self) -> *JSObject {
|
pub fn create_window_proxy(&self) -> *JSObject {
|
||||||
let win = self.active_window().root();
|
let win = self.active_window().root();
|
||||||
let page = win.get().page();
|
let page = win.deref().page();
|
||||||
let js_info = page.js_info();
|
let js_info = page.js_info();
|
||||||
|
|
||||||
let handler = js_info.get_ref().dom_static.windowproxy_handler;
|
let handler = js_info.get_ref().dom_static.windowproxy_handler;
|
||||||
assert!(handler.deref().is_not_null());
|
assert!(handler.deref().is_not_null());
|
||||||
|
|
||||||
let parent = win.get().reflector().get_jsobject();
|
let parent = win.deref().reflector().get_jsobject();
|
||||||
let cx = js_info.get_ref().js_context.deref().deref().ptr;
|
let cx = js_info.get_ref().js_context.deref().deref().ptr;
|
||||||
let wrapper = unsafe {
|
let wrapper = unsafe {
|
||||||
WrapperNew(cx, parent, *handler.deref())
|
WrapperNew(cx, parent, *handler.deref())
|
||||||
|
|
|
@ -256,20 +256,22 @@ impl<'a> PrivateDocumentHelpers for JSRef<'a, Document> {
|
||||||
fn createNodeList(&self, callback: |node: &JSRef<Node>| -> bool) -> Temporary<NodeList> {
|
fn createNodeList(&self, callback: |node: &JSRef<Node>| -> bool) -> Temporary<NodeList> {
|
||||||
let window = self.window.root();
|
let window = self.window.root();
|
||||||
|
|
||||||
let mut nodes = vec!();
|
|
||||||
match self.GetDocumentElement().root() {
|
match self.GetDocumentElement().root() {
|
||||||
None => {},
|
None => {
|
||||||
|
NodeList::new_simple_list(&*window, vec!())
|
||||||
|
},
|
||||||
Some(root) => {
|
Some(root) => {
|
||||||
|
let mut nodes = vec!();
|
||||||
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
|
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
|
||||||
for child in root.traverse_preorder() {
|
for child in root.traverse_preorder() {
|
||||||
if callback(&child) {
|
if callback(&child) {
|
||||||
nodes.push(child);
|
nodes.push(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
NodeList::new_simple_list(&*window, nodes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeList::new_simple_list(&*window, nodes)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_html_element(&self) -> Option<Temporary<HTMLHtmlElement>> {
|
fn get_html_element(&self) -> Option<Temporary<HTMLHtmlElement>> {
|
||||||
|
@ -551,7 +553,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
for child in title_elem.children() {
|
for child in title_elem.children() {
|
||||||
if child.is_text() {
|
if child.is_text() {
|
||||||
let text: &JSRef<Text> = TextCast::to_ref(&child).unwrap();
|
let text: &JSRef<Text> = TextCast::to_ref(&child).unwrap();
|
||||||
title.push_str(text.get().characterdata.data.as_slice());
|
title.push_str(text.deref().characterdata.data.as_slice());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -563,15 +565,14 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
|
|
||||||
// http://www.whatwg.org/specs/web-apps/current-work/#document.title
|
// http://www.whatwg.org/specs/web-apps/current-work/#document.title
|
||||||
fn SetTitle(&self, title: DOMString) -> ErrorResult {
|
fn SetTitle(&self, title: DOMString) -> ErrorResult {
|
||||||
|
|
||||||
self.GetDocumentElement().root().map(|root| {
|
self.GetDocumentElement().root().map(|root| {
|
||||||
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
|
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
|
||||||
let mut head_node = root.traverse_preorder().find(|child| {
|
let mut head_node = root.traverse_preorder().find(|child| {
|
||||||
child.get().type_id == ElementNodeTypeId(HTMLHeadElementTypeId)
|
child.type_id() == ElementNodeTypeId(HTMLHeadElementTypeId)
|
||||||
});
|
});
|
||||||
head_node.as_mut().map(|head| {
|
head_node.as_mut().map(|head| {
|
||||||
let mut title_node = head.children().find(|child| {
|
let mut title_node = head.children().find(|child| {
|
||||||
child.get().type_id == ElementNodeTypeId(HTMLTitleElementTypeId)
|
child.type_id() == ElementNodeTypeId(HTMLTitleElementTypeId)
|
||||||
});
|
});
|
||||||
|
|
||||||
match title_node {
|
match title_node {
|
||||||
|
@ -630,7 +631,6 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
|
|
||||||
// http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body
|
// http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body
|
||||||
fn SetBody(&self, new_body: Option<JSRef<HTMLElement>>) -> ErrorResult {
|
fn SetBody(&self, new_body: Option<JSRef<HTMLElement>>) -> ErrorResult {
|
||||||
|
|
||||||
// Step 1.
|
// Step 1.
|
||||||
match new_body {
|
match new_body {
|
||||||
Some(ref htmlelem) => {
|
Some(ref htmlelem) => {
|
||||||
|
@ -674,7 +674,6 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
|
|
||||||
// http://www.whatwg.org/specs/web-apps/current-work/#dom-document-getelementsbyname
|
// http://www.whatwg.org/specs/web-apps/current-work/#dom-document-getelementsbyname
|
||||||
fn GetElementsByName(&self, name: DOMString) -> Temporary<NodeList> {
|
fn GetElementsByName(&self, name: DOMString) -> Temporary<NodeList> {
|
||||||
|
|
||||||
self.createNodeList(|node| {
|
self.createNodeList(|node| {
|
||||||
if !node.is_element() {
|
if !node.is_element() {
|
||||||
return false;
|
return false;
|
||||||
|
@ -694,7 +693,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
struct ImagesFilter;
|
struct ImagesFilter;
|
||||||
impl CollectionFilter for ImagesFilter {
|
impl CollectionFilter for ImagesFilter {
|
||||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||||
elem.get().local_name == ~"img"
|
elem.deref().local_name == ~"img"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let filter = ~ImagesFilter;
|
let filter = ~ImagesFilter;
|
||||||
|
@ -708,7 +707,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
struct EmbedsFilter;
|
struct EmbedsFilter;
|
||||||
impl CollectionFilter for EmbedsFilter {
|
impl CollectionFilter for EmbedsFilter {
|
||||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||||
elem.get().local_name == ~"embed"
|
elem.deref().local_name == ~"embed"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let filter = ~EmbedsFilter;
|
let filter = ~EmbedsFilter;
|
||||||
|
@ -727,7 +726,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
struct LinksFilter;
|
struct LinksFilter;
|
||||||
impl CollectionFilter for LinksFilter {
|
impl CollectionFilter for LinksFilter {
|
||||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||||
(elem.get().local_name == ~"a" || elem.get().local_name == ~"area") &&
|
(elem.deref().local_name == ~"a" || elem.deref().local_name == ~"area") &&
|
||||||
elem.get_attribute(Null, "href").is_some()
|
elem.get_attribute(Null, "href").is_some()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -742,7 +741,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
struct FormsFilter;
|
struct FormsFilter;
|
||||||
impl CollectionFilter for FormsFilter {
|
impl CollectionFilter for FormsFilter {
|
||||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||||
elem.get().local_name == ~"form"
|
elem.deref().local_name == ~"form"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let filter = ~FormsFilter;
|
let filter = ~FormsFilter;
|
||||||
|
@ -756,7 +755,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
struct ScriptsFilter;
|
struct ScriptsFilter;
|
||||||
impl CollectionFilter for ScriptsFilter {
|
impl CollectionFilter for ScriptsFilter {
|
||||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||||
elem.get().local_name == ~"script"
|
elem.deref().local_name == ~"script"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let filter = ~ScriptsFilter;
|
let filter = ~ScriptsFilter;
|
||||||
|
@ -770,7 +769,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
struct AnchorsFilter;
|
struct AnchorsFilter;
|
||||||
impl CollectionFilter for AnchorsFilter {
|
impl CollectionFilter for AnchorsFilter {
|
||||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||||
elem.get().local_name == ~"a" && elem.get_attribute(Null, "name").is_some()
|
elem.deref().local_name == ~"a" && elem.get_attribute(Null, "name").is_some()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let filter = ~AnchorsFilter;
|
let filter = ~AnchorsFilter;
|
||||||
|
@ -784,7 +783,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
struct AppletsFilter;
|
struct AppletsFilter;
|
||||||
impl CollectionFilter for AppletsFilter {
|
impl CollectionFilter for AppletsFilter {
|
||||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||||
elem.get().local_name == ~"applet"
|
elem.deref().local_name == ~"applet"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let filter = ~AppletsFilter;
|
let filter = ~AppletsFilter;
|
||||||
|
|
|
@ -74,4 +74,3 @@ impl<'a> DocumentTypeMethods for JSRef<'a, DocumentType> {
|
||||||
self.system_id.clone()
|
self.system_id.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,8 @@ impl DOMParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait DOMParserMethods {
|
pub trait DOMParserMethods {
|
||||||
fn ParseFromString(&self, _s: DOMString, ty: DOMParserBinding::SupportedType) -> Fallible<Temporary<Document>>;
|
fn ParseFromString(&self, _s: DOMString, ty: DOMParserBinding::SupportedType)
|
||||||
|
-> Fallible<Temporary<Document>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DOMParserMethods for JSRef<'a, DOMParser> {
|
impl<'a> DOMParserMethods for JSRef<'a, DOMParser> {
|
||||||
|
|
|
@ -228,11 +228,11 @@ pub trait AttributeHandlers {
|
||||||
impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||||
fn get_attribute(&self, namespace: Namespace, name: &str) -> Option<Temporary<Attr>> {
|
fn get_attribute(&self, namespace: Namespace, name: &str) -> Option<Temporary<Attr>> {
|
||||||
if self.html_element_in_html_document() {
|
if self.html_element_in_html_document() {
|
||||||
self.get().attrs.iter().map(|attr| attr.root()).find(|attr| {
|
self.deref().attrs.iter().map(|attr| attr.root()).find(|attr| {
|
||||||
name.to_ascii_lower() == attr.local_name && attr.namespace == namespace
|
name.to_ascii_lower() == attr.local_name && attr.namespace == namespace
|
||||||
}).map(|x| Temporary::from_rooted(&*x))
|
}).map(|x| Temporary::from_rooted(&*x))
|
||||||
} else {
|
} else {
|
||||||
self.get().attrs.iter().map(|attr| attr.root()).find(|attr| {
|
self.deref().attrs.iter().map(|attr| attr.root()).find(|attr| {
|
||||||
name == attr.local_name && attr.namespace == namespace
|
name == attr.local_name && attr.namespace == namespace
|
||||||
}).map(|x| Temporary::from_rooted(&*x))
|
}).map(|x| Temporary::from_rooted(&*x))
|
||||||
}
|
}
|
||||||
|
@ -262,9 +262,9 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||||
|
|
||||||
let position: |&JSRef<Attr>| -> bool =
|
let position: |&JSRef<Attr>| -> bool =
|
||||||
if self.html_element_in_html_document() {
|
if self.html_element_in_html_document() {
|
||||||
|attr| attr.get().local_name.eq_ignore_ascii_case(local_name)
|
|attr| attr.deref().local_name.eq_ignore_ascii_case(local_name)
|
||||||
} else {
|
} else {
|
||||||
|attr| attr.get().local_name == local_name
|
|attr| attr.deref().local_name == local_name
|
||||||
};
|
};
|
||||||
self.do_set_attribute(name.clone(), value, name.clone(), namespace::Null, None, position);
|
self.do_set_attribute(name.clone(), value, name.clone(), namespace::Null, None, position);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -273,7 +273,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||||
fn do_set_attribute(&mut self, local_name: DOMString, value: DOMString,
|
fn do_set_attribute(&mut self, local_name: DOMString, value: DOMString,
|
||||||
name: DOMString, namespace: Namespace,
|
name: DOMString, namespace: Namespace,
|
||||||
prefix: Option<DOMString>, cb: |&JSRef<Attr>| -> bool) {
|
prefix: Option<DOMString>, cb: |&JSRef<Attr>| -> bool) {
|
||||||
let idx = self.get().attrs.iter()
|
let idx = self.deref().attrs.iter()
|
||||||
.map(|attr| attr.root())
|
.map(|attr| attr.root())
|
||||||
.position(|attr| cb(&*attr));
|
.position(|attr| cb(&*attr));
|
||||||
let (idx, set_type) = match idx {
|
let (idx, set_type) = match idx {
|
||||||
|
@ -282,18 +282,18 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||||
let window = window_from_node(self).root();
|
let window = window_from_node(self).root();
|
||||||
let attr = Attr::new(&*window, local_name.clone(), value.clone(),
|
let attr = Attr::new(&*window, local_name.clone(), value.clone(),
|
||||||
name, namespace.clone(), prefix, self);
|
name, namespace.clone(), prefix, self);
|
||||||
self.get_mut().attrs.push_unrooted(&attr);
|
self.deref_mut().attrs.push_unrooted(&attr);
|
||||||
(self.get().attrs.len() - 1, FirstSetAttr)
|
(self.deref().attrs.len() - 1, FirstSetAttr)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.get_mut().attrs.get(idx).root().set_value(set_type, value);
|
self.deref_mut().attrs.get(idx).root().set_value(set_type, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_attribute(&mut self, namespace: Namespace, name: DOMString) -> ErrorResult {
|
fn remove_attribute(&mut self, namespace: Namespace, name: DOMString) -> ErrorResult {
|
||||||
let (_, local_name) = get_attribute_parts(name.clone());
|
let (_, local_name) = get_attribute_parts(name.clone());
|
||||||
|
|
||||||
let idx = self.get().attrs.iter().map(|attr| attr.root()).position(|attr| {
|
let idx = self.deref().attrs.iter().map(|attr| attr.root()).position(|attr| {
|
||||||
attr.local_name == local_name
|
attr.local_name == local_name
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -306,12 +306,12 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if namespace == namespace::Null {
|
if namespace == namespace::Null {
|
||||||
let removed_raw_value = self.get().attrs.get(idx).root().Value();
|
let removed_raw_value = self.deref().attrs.get(idx).root().Value();
|
||||||
vtable_for(NodeCast::from_mut_ref(self))
|
vtable_for(NodeCast::from_mut_ref(self))
|
||||||
.before_remove_attr(local_name.clone(), removed_raw_value);
|
.before_remove_attr(local_name.clone(), removed_raw_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.get_mut().attrs.remove(idx);
|
self.deref_mut().attrs.remove(idx);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -516,7 +516,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
||||||
|
|
||||||
// Step 3-5.
|
// Step 3-5.
|
||||||
self.do_set_attribute(name.clone(), value, name.clone(), namespace::Null, None, |attr| {
|
self.do_set_attribute(name.clone(), value, name.clone(), namespace::Null, None, |attr| {
|
||||||
attr.get().name == name
|
attr.deref().name == name
|
||||||
});
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -577,8 +577,8 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
||||||
|
|
||||||
// Step 9.
|
// Step 9.
|
||||||
self.do_set_attribute(local_name.clone(), value, name, namespace.clone(), prefix, |attr| {
|
self.do_set_attribute(local_name.clone(), value, name, namespace.clone(), prefix, |attr| {
|
||||||
attr.get().local_name == local_name &&
|
attr.deref().local_name == local_name &&
|
||||||
attr.get().namespace == namespace
|
attr.deref().namespace == namespace
|
||||||
});
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -694,9 +694,9 @@ pub fn get_attribute_parts(name: DOMString) -> (Option<~str>, ~str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> VirtualMethods for JSRef<'a, Element> {
|
impl<'a> VirtualMethods for JSRef<'a, Element> {
|
||||||
fn super_type(&self) -> Option<~VirtualMethods:> {
|
fn super_type<'a>(&'a mut self) -> Option<&'a mut VirtualMethods:> {
|
||||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
let node: &mut JSRef<Node> = NodeCast::from_mut_ref(self);
|
||||||
Some(~node.clone() as ~VirtualMethods:)
|
Some(node as &mut VirtualMethods:)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn after_set_attr(&mut self, name: DOMString, value: DOMString) {
|
fn after_set_attr(&mut self, name: DOMString, value: DOMString) {
|
||||||
|
@ -709,7 +709,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
|
||||||
"style" => {
|
"style" => {
|
||||||
let doc = document_from_node(self).root();
|
let doc = document_from_node(self).root();
|
||||||
let base_url = doc.deref().url().clone();
|
let base_url = doc.deref().url().clone();
|
||||||
self.get_mut().style_attribute = Some(style::parse_style_attribute(value, &base_url))
|
self.deref_mut().style_attribute = Some(style::parse_style_attribute(value, &base_url))
|
||||||
}
|
}
|
||||||
"id" => {
|
"id" => {
|
||||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||||
|
@ -732,7 +732,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
|
||||||
|
|
||||||
match name.as_slice() {
|
match name.as_slice() {
|
||||||
"style" => {
|
"style" => {
|
||||||
self.get_mut().style_attribute = None
|
self.deref_mut().style_attribute = None
|
||||||
}
|
}
|
||||||
"id" => {
|
"id" => {
|
||||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||||
|
|
|
@ -13,21 +13,21 @@ use dom::node::{Node, NodeHelpers};
|
||||||
pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>,
|
pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>,
|
||||||
pseudo_target: Option<JSRef<'b, EventTarget>>,
|
pseudo_target: Option<JSRef<'b, EventTarget>>,
|
||||||
event: &mut JSRef<Event>) -> bool {
|
event: &mut JSRef<Event>) -> bool {
|
||||||
assert!(!event.get().dispatching);
|
assert!(!event.deref().dispatching);
|
||||||
|
|
||||||
{
|
{
|
||||||
let event = event.get_mut();
|
let event = event.deref_mut();
|
||||||
match pseudo_target {
|
event.target.assign(Some(match pseudo_target {
|
||||||
Some(pseudo_target) => event.target.assign(Some(pseudo_target)),
|
Some(pseudo_target) => pseudo_target,
|
||||||
None => event.target.assign(Some(target.clone())),
|
None => target.clone(),
|
||||||
}
|
}));
|
||||||
event.dispatching = true;
|
event.dispatching = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let type_ = event.get().type_.clone();
|
let type_ = event.deref().type_.clone();
|
||||||
|
|
||||||
//TODO: no chain if not participating in a tree
|
//TODO: no chain if not participating in a tree
|
||||||
let mut chain: Vec<Root<EventTarget>> = if target.get().is_node() {
|
let mut chain: Vec<Root<EventTarget>> = if target.deref().is_node() {
|
||||||
let target_node: &JSRef<Node> = NodeCast::to_ref(target).unwrap();
|
let target_node: &JSRef<Node> = NodeCast::to_ref(target).unwrap();
|
||||||
target_node.ancestors().map(|ancestor| {
|
target_node.ancestors().map(|ancestor| {
|
||||||
let ancestor_target: &JSRef<EventTarget> = EventTargetCast::from_ref(&ancestor);
|
let ancestor_target: &JSRef<EventTarget> = EventTargetCast::from_ref(&ancestor);
|
||||||
|
@ -37,7 +37,7 @@ pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>,
|
||||||
vec!()
|
vec!()
|
||||||
};
|
};
|
||||||
|
|
||||||
event.get_mut().phase = PhaseCapturing;
|
event.deref_mut().phase = PhaseCapturing;
|
||||||
|
|
||||||
//FIXME: The "callback this value" should be currentTarget
|
//FIXME: The "callback this value" should be currentTarget
|
||||||
|
|
||||||
|
@ -51,12 +51,12 @@ pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>,
|
||||||
// drop the exception on the floor
|
// drop the exception on the floor
|
||||||
assert!(listener.HandleEvent__(event, ReportExceptions).is_ok());
|
assert!(listener.HandleEvent__(event, ReportExceptions).is_ok());
|
||||||
|
|
||||||
if event.get().stop_immediate {
|
if event.deref().stop_immediate {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
event.get().stop_propagation
|
event.deref().stop_propagation
|
||||||
}
|
}
|
||||||
None => false
|
None => false
|
||||||
};
|
};
|
||||||
|
@ -67,20 +67,20 @@ pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* at target */
|
/* at target */
|
||||||
if !event.get().stop_propagation {
|
if !event.deref().stop_propagation {
|
||||||
{
|
{
|
||||||
let event = event.get_mut();
|
let event = event.deref_mut();
|
||||||
event.phase = PhaseAtTarget;
|
event.phase = PhaseAtTarget;
|
||||||
event.current_target.assign(Some(target.clone()));
|
event.current_target.assign(Some(target.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let opt_listeners = target.get().get_listeners(type_);
|
let opt_listeners = target.deref().get_listeners(type_);
|
||||||
for listeners in opt_listeners.iter() {
|
for listeners in opt_listeners.iter() {
|
||||||
for listener in listeners.iter() {
|
for listener in listeners.iter() {
|
||||||
//FIXME: this should have proper error handling, or explicitly drop the
|
//FIXME: this should have proper error handling, or explicitly drop the
|
||||||
// exception on the floor.
|
// exception on the floor.
|
||||||
assert!(listener.HandleEvent__(event, ReportExceptions).is_ok());
|
assert!(listener.HandleEvent__(event, ReportExceptions).is_ok());
|
||||||
if event.get().stop_immediate {
|
if event.deref().stop_immediate {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,24 +88,24 @@ pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* bubbling */
|
/* bubbling */
|
||||||
if event.get().bubbles && !event.get().stop_propagation {
|
if event.deref().bubbles && !event.deref().stop_propagation {
|
||||||
event.get_mut().phase = PhaseBubbling;
|
event.deref_mut().phase = PhaseBubbling;
|
||||||
|
|
||||||
for cur_target in chain.iter() {
|
for cur_target in chain.iter() {
|
||||||
let stopped = match cur_target.get().get_listeners_for(type_, Bubbling) {
|
let stopped = match cur_target.deref().get_listeners_for(type_, Bubbling) {
|
||||||
Some(listeners) => {
|
Some(listeners) => {
|
||||||
event.get_mut().current_target.assign(Some(cur_target.deref().clone()));
|
event.deref_mut().current_target.assign(Some(cur_target.deref().clone()));
|
||||||
for listener in listeners.iter() {
|
for listener in listeners.iter() {
|
||||||
//FIXME: this should have proper error handling or explicitly
|
//FIXME: this should have proper error handling or explicitly
|
||||||
// drop exceptions on the floor.
|
// drop exceptions on the floor.
|
||||||
assert!(listener.HandleEvent__(event, ReportExceptions).is_ok());
|
assert!(listener.HandleEvent__(event, ReportExceptions).is_ok());
|
||||||
|
|
||||||
if event.get().stop_immediate {
|
if event.deref().stop_immediate {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
event.get().stop_propagation
|
event.deref().stop_propagation
|
||||||
}
|
}
|
||||||
None => false
|
None => false
|
||||||
};
|
};
|
||||||
|
|
|
@ -76,7 +76,7 @@ impl<'a> EventTargetHelpers for JSRef<'a, EventTarget> {
|
||||||
fn dispatch_event_with_target<'b>(&self,
|
fn dispatch_event_with_target<'b>(&self,
|
||||||
target: Option<JSRef<'b, EventTarget>>,
|
target: Option<JSRef<'b, EventTarget>>,
|
||||||
event: &mut JSRef<Event>) -> Fallible<bool> {
|
event: &mut JSRef<Event>) -> Fallible<bool> {
|
||||||
if event.get().dispatching || !event.get().initialized {
|
if event.deref().dispatching || !event.deref().initialized {
|
||||||
return Err(InvalidState);
|
return Err(InvalidState);
|
||||||
}
|
}
|
||||||
Ok(dispatch_event(self, target, event))
|
Ok(dispatch_event(self, target, event))
|
||||||
|
@ -149,7 +149,7 @@ impl Reflectable for EventTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> VirtualMethods for JSRef<'a, EventTarget> {
|
impl<'a> VirtualMethods for JSRef<'a, EventTarget> {
|
||||||
fn super_type(&self) -> Option<~VirtualMethods:> {
|
fn super_type<'a>(&'a mut self) -> Option<&'a mut VirtualMethods:> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||||
use dom::bindings::error::{Fallible};
|
use dom::bindings::error::{Fallible};
|
||||||
use dom::bindings::codegen::BindingDeclarations::FormDataBinding;
|
use dom::bindings::codegen::BindingDeclarations::FormDataBinding;
|
||||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
use dom::bindings::js::{JS, JSRef, Temporary, OptionalUnrootable};
|
||||||
use dom::blob::Blob;
|
use dom::blob::Blob;
|
||||||
use dom::htmlformelement::HTMLFormElement;
|
use dom::htmlformelement::HTMLFormElement;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
|
@ -33,7 +33,7 @@ impl FormData {
|
||||||
data: HashMap::new(),
|
data: HashMap::new(),
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
window: window.unrooted(),
|
window: window.unrooted(),
|
||||||
form: form.map(|form| form.unrooted())
|
form: form.unrooted(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,4 +64,3 @@ impl<'a> HTMLBaseElementMethods for JSRef<'a, HTMLBaseElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,4 +104,3 @@ impl<'a> HTMLBodyElementMethods for JSRef<'a, HTMLBodyElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLBRElementMethods for JSRef<'a, HTMLBRElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -185,4 +185,3 @@ impl<'a> HTMLButtonElementMethods for JSRef<'a, HTMLButtonElement> {
|
||||||
fn SetCustomValidity(&mut self, _error: DOMString) {
|
fn SetCustomValidity(&mut self, _error: DOMString) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,4 +64,3 @@ impl<'a> HTMLCanvasElementMethods for JSRef<'a, HTMLCanvasElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ impl HTMLCollection {
|
||||||
}
|
}
|
||||||
impl CollectionFilter for TagNameFilter {
|
impl CollectionFilter for TagNameFilter {
|
||||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||||
elem.get().local_name == self.tag
|
elem.deref().local_name == self.tag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let filter = TagNameFilter {
|
let filter = TagNameFilter {
|
||||||
|
@ -81,7 +81,7 @@ impl HTMLCollection {
|
||||||
}
|
}
|
||||||
impl CollectionFilter for TagNameNSFilter {
|
impl CollectionFilter for TagNameNSFilter {
|
||||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||||
elem.get().namespace == self.namespace && elem.get().local_name == self.tag
|
elem.deref().namespace == self.namespace && elem.deref().local_name == self.tag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let filter = TagNameNSFilter {
|
let filter = TagNameNSFilter {
|
||||||
|
@ -155,7 +155,7 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> {
|
||||||
.filter_map(|node| {
|
.filter_map(|node| {
|
||||||
let elem: Option<&JSRef<Element>> = ElementCast::to_ref(&node);
|
let elem: Option<&JSRef<Element>> = ElementCast::to_ref(&node);
|
||||||
elem.filtered(|&elem| filter.filter(elem, &*root))
|
elem.filtered(|&elem| filter.filter(elem, &*root))
|
||||||
.and_then(|elem| Some(elem.clone()))
|
.map(|elem| elem.clone())
|
||||||
})
|
})
|
||||||
.nth(index as uint)
|
.nth(index as uint)
|
||||||
.clone()
|
.clone()
|
||||||
|
@ -166,7 +166,6 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> {
|
||||||
|
|
||||||
// http://dom.spec.whatwg.org/#dom-htmlcollection-nameditem
|
// http://dom.spec.whatwg.org/#dom-htmlcollection-nameditem
|
||||||
fn NamedItem(&self, key: DOMString) -> Option<Temporary<Element>> {
|
fn NamedItem(&self, key: DOMString) -> Option<Temporary<Element>> {
|
||||||
|
|
||||||
// Step 1.
|
// Step 1.
|
||||||
if key.is_empty() {
|
if key.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
|
@ -186,7 +185,7 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> {
|
||||||
.filter_map(|node| {
|
.filter_map(|node| {
|
||||||
let elem: Option<&JSRef<Element>> = ElementCast::to_ref(&node);
|
let elem: Option<&JSRef<Element>> = ElementCast::to_ref(&node);
|
||||||
elem.filtered(|&elem| filter.filter(elem, &*root))
|
elem.filtered(|&elem| filter.filter(elem, &*root))
|
||||||
.and_then(|elem| Some(elem.clone()))
|
.map(|elem| elem.clone())
|
||||||
})
|
})
|
||||||
.find(|elem| {
|
.find(|elem| {
|
||||||
elem.get_string_attribute("name") == key ||
|
elem.get_string_attribute("name") == key ||
|
||||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLDataElementMethods for JSRef<'a, HTMLDataElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ impl<'a> HTMLDataListElementMethods for JSRef<'a, HTMLDataListElement> {
|
||||||
struct HTMLDataListOptionsFilter;
|
struct HTMLDataListOptionsFilter;
|
||||||
impl CollectionFilter for HTMLDataListOptionsFilter {
|
impl CollectionFilter for HTMLDataListOptionsFilter {
|
||||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||||
elem.get().local_name == ~"option"
|
elem.deref().local_name == ~"option"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||||
|
@ -58,4 +58,3 @@ impl<'a> HTMLDataListElementMethods for JSRef<'a, HTMLDataListElement> {
|
||||||
HTMLCollection::create(&*window, node, filter)
|
HTMLCollection::create(&*window, node, filter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLDirectoryElementMethods for JSRef<'a, HTMLDirectoryElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLDivElementMethods for JSRef<'a, HTMLDivElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -198,8 +198,8 @@ impl<'a> HTMLElementMethods for JSRef<'a, HTMLElement> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> VirtualMethods for JSRef<'a, HTMLElement> {
|
impl<'a> VirtualMethods for JSRef<'a, HTMLElement> {
|
||||||
fn super_type(&self) -> Option<~VirtualMethods:> {
|
fn super_type<'a>(&'a mut self) -> Option<&'a mut VirtualMethods:> {
|
||||||
let element: &JSRef<Element> = ElementCast::from_ref(self);
|
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(self);
|
||||||
Some(~element.clone() as ~VirtualMethods:)
|
Some(element as &mut VirtualMethods:)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,4 +109,3 @@ impl<'a> HTMLEmbedElementMethods for JSRef<'a, HTMLEmbedElement> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ impl<'a> HTMLFieldSetElementMethods for JSRef<'a, HTMLFieldSetElement> {
|
||||||
static tag_names: StaticStringVec = &["button", "fieldset", "input",
|
static tag_names: StaticStringVec = &["button", "fieldset", "input",
|
||||||
"keygen", "object", "output", "select", "textarea"];
|
"keygen", "object", "output", "select", "textarea"];
|
||||||
let root: &JSRef<Element> = ElementCast::to_ref(root).unwrap();
|
let root: &JSRef<Element> = ElementCast::to_ref(root).unwrap();
|
||||||
elem != root && tag_names.iter().any(|&tag_name| tag_name == elem.get().local_name)
|
elem != root && tag_names.iter().any(|&tag_name| tag_name == elem.deref().local_name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||||
|
@ -120,4 +120,3 @@ impl<'a> HTMLFieldSetElementMethods for JSRef<'a, HTMLFieldSetElement> {
|
||||||
fn SetCustomValidity(&mut self, _error: DOMString) {
|
fn SetCustomValidity(&mut self, _error: DOMString) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,4 +74,3 @@ impl<'a> HTMLFontElementMethods for JSRef<'a, HTMLFontElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -166,4 +166,3 @@ impl<'a> HTMLFormElementMethods for JSRef<'a, HTMLFormElement> {
|
||||||
fail!("Not implemented.")
|
fail!("Not implemented.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,4 +135,3 @@ impl<'a> HTMLFrameElementMethods for JSRef<'a, HTMLFrameElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,4 +64,3 @@ impl<'a> HTMLFrameSetElementMethods for JSRef<'a, HTMLFrameSetElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,4 +64,3 @@ impl<'a> HTMLHeadingElementMethods for JSRef<'a, HTMLHeadingElement> {
|
||||||
fn SetAlign(&mut self, _align: DOMString) {
|
fn SetAlign(&mut self, _align: DOMString) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,4 +94,3 @@ impl<'a> HTMLHRElementMethods for JSRef<'a, HTMLHRElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLHtmlElementMethods for JSRef<'a, HTMLHtmlElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -238,9 +238,9 @@ impl<'a> HTMLIFrameElementMethods for JSRef<'a, HTMLIFrameElement> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> VirtualMethods for JSRef<'a, HTMLIFrameElement> {
|
impl<'a> VirtualMethods for JSRef<'a, HTMLIFrameElement> {
|
||||||
fn super_type(&self) -> Option<~VirtualMethods:> {
|
fn super_type<'a>(&'a mut self) -> Option<&'a mut VirtualMethods:> {
|
||||||
let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_ref(self);
|
let htmlelement: &mut JSRef<HTMLElement> = HTMLElementCast::from_mut_ref(self);
|
||||||
Some(~htmlelement.clone() as ~VirtualMethods:)
|
Some(htmlelement as &mut VirtualMethods:)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn after_set_attr(&mut self, name: DOMString, value: DOMString) {
|
fn after_set_attr(&mut self, name: DOMString, value: DOMString) {
|
||||||
|
@ -264,7 +264,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLIFrameElement> {
|
||||||
_ => AllowNothing
|
_ => AllowNothing
|
||||||
} as u8;
|
} as u8;
|
||||||
}
|
}
|
||||||
self.get_mut().sandbox = Some(modes);
|
self.deref_mut().sandbox = Some(modes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,7 +275,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLIFrameElement> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if "sandbox" == name {
|
if "sandbox" == name {
|
||||||
self.get_mut().sandbox = None;
|
self.deref_mut().sandbox = None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,7 +218,7 @@ impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> {
|
||||||
|
|
||||||
fn Align(&self) -> DOMString {
|
fn Align(&self) -> DOMString {
|
||||||
let element: &JSRef<Element> = ElementCast::from_ref(self);
|
let element: &JSRef<Element> = ElementCast::from_ref(self);
|
||||||
element.get_string_attribute("longdesc")
|
element.get_string_attribute("align")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn SetAlign(&mut self, align: DOMString) {
|
fn SetAlign(&mut self, align: DOMString) {
|
||||||
|
@ -268,9 +268,9 @@ impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> {
|
impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> {
|
||||||
fn super_type(&self) -> Option<~VirtualMethods:> {
|
fn super_type<'a>(&'a mut self) -> Option<&'a mut VirtualMethods:> {
|
||||||
let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_ref(self);
|
let htmlelement: &mut JSRef<HTMLElement> = HTMLElementCast::from_mut_ref(self);
|
||||||
Some(~htmlelement.clone() as ~VirtualMethods:)
|
Some(htmlelement as &mut VirtualMethods:)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn after_set_attr(&mut self, name: DOMString, value: DOMString) {
|
fn after_set_attr(&mut self, name: DOMString, value: DOMString) {
|
||||||
|
@ -281,7 +281,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> {
|
||||||
|
|
||||||
if "src" == name {
|
if "src" == name {
|
||||||
let window = window_from_node(self).root();
|
let window = window_from_node(self).root();
|
||||||
let url = Some(window.get().get_url());
|
let url = Some(window.deref().get_url());
|
||||||
self.update_image(Some(value), url);
|
self.update_image(Some(value), url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -428,4 +428,3 @@ impl<'a> HTMLInputElementMethods for JSRef<'a, HTMLInputElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,4 +52,3 @@ impl<'a> HTMLLabelElementMethods for JSRef<'a, HTMLLabelElement> {
|
||||||
fn SetHtmlFor(&mut self, _html_for: DOMString) {
|
fn SetHtmlFor(&mut self, _html_for: DOMString) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLLegendElementMethods for JSRef<'a, HTMLLegendElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,4 +64,3 @@ impl<'a> HTMLLIElementMethods for JSRef<'a, HTMLLIElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,4 +143,3 @@ impl<'a> HTMLLinkElementMethods for JSRef<'a, HTMLLinkElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -207,5 +207,3 @@ impl<'a> HTMLMediaElementMethods for JSRef<'a, HTMLMediaElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -84,4 +84,3 @@ impl<'a> HTMLMetaElementMethods for JSRef<'a, HTMLMetaElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,4 +64,3 @@ impl<'a> HTMLModElementMethods for JSRef<'a, HTMLModElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -290,9 +290,9 @@ impl<'a> HTMLObjectElementMethods for JSRef<'a, HTMLObjectElement> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> VirtualMethods for JSRef<'a, HTMLObjectElement> {
|
impl<'a> VirtualMethods for JSRef<'a, HTMLObjectElement> {
|
||||||
fn super_type(&self) -> Option<~VirtualMethods:> {
|
fn super_type<'a>(&'a mut self) -> Option<&'a mut VirtualMethods:> {
|
||||||
let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_ref(self);
|
let htmlelement: &mut JSRef<HTMLElement> = HTMLElementCast::from_mut_ref(self);
|
||||||
Some(~htmlelement.clone() as ~VirtualMethods:)
|
Some(htmlelement as &mut VirtualMethods:)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn after_set_attr(&mut self, name: DOMString, value: DOMString) {
|
fn after_set_attr(&mut self, name: DOMString, value: DOMString) {
|
||||||
|
@ -303,8 +303,8 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLObjectElement> {
|
||||||
|
|
||||||
if "data" == name {
|
if "data" == name {
|
||||||
let window = window_from_node(self).root();
|
let window = window_from_node(self).root();
|
||||||
let url = Some(window.get().get_url());
|
let url = Some(window.deref().get_url());
|
||||||
self.process_data_url(window.get().image_cache_task.clone(), url);
|
self.process_data_url(window.deref().image_cache_task.clone(), url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,4 +84,3 @@ impl<'a> HTMLOListElementMethods for JSRef<'a, HTMLOListElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,4 +64,3 @@ impl<'a> HTMLOptGroupElementMethods for JSRef<'a, HTMLOptGroupElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,4 +115,3 @@ impl<'a> HTMLOptionElementMethods for JSRef<'a, HTMLOptionElement> {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,4 +120,3 @@ impl<'a> HTMLOutputElementMethods for JSRef<'a, HTMLOutputElement> {
|
||||||
fn SetCustomValidity(&mut self, _error: DOMString) {
|
fn SetCustomValidity(&mut self, _error: DOMString) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLParagraphElementMethods for JSRef<'a, HTMLParagraphElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,4 +84,3 @@ impl<'a> HTMLParamElementMethods for JSRef<'a, HTMLParamElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLPreElementMethods for JSRef<'a, HTMLPreElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,4 +74,3 @@ impl<'a> HTMLProgressElementMethods for JSRef<'a, HTMLProgressElement> {
|
||||||
Ok(0f64)
|
Ok(0f64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLQuoteElementMethods for JSRef<'a, HTMLQuoteElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,4 +136,3 @@ impl<'a> HTMLScriptElementMethods for JSRef<'a, HTMLScriptElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -214,4 +214,3 @@ impl<'a> HTMLSelectElementMethods for JSRef<'a, HTMLSelectElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ pub fn serialize(iterator: &mut NodeIterator) -> ~str {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_comment(comment: &JSRef<Comment>) -> ~str {
|
fn serialize_comment(comment: &JSRef<Comment>) -> ~str {
|
||||||
~"<!--" + comment.get().characterdata.data + "-->"
|
~"<!--" + comment.deref().characterdata.data + "-->"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_text(text: &JSRef<Text>) -> ~str {
|
fn serialize_text(text: &JSRef<Text>) -> ~str {
|
||||||
|
@ -74,41 +74,41 @@ fn serialize_text(text: &JSRef<Text>) -> ~str {
|
||||||
match text_node.parent_node().map(|node| node.root()) {
|
match text_node.parent_node().map(|node| node.root()) {
|
||||||
Some(ref parent) if parent.is_element() => {
|
Some(ref parent) if parent.is_element() => {
|
||||||
let elem: &JSRef<Element> = ElementCast::to_ref(&**parent).unwrap();
|
let elem: &JSRef<Element> = ElementCast::to_ref(&**parent).unwrap();
|
||||||
match elem.get().local_name.as_slice() {
|
match elem.deref().local_name.as_slice() {
|
||||||
"style" | "script" | "xmp" | "iframe" |
|
"style" | "script" | "xmp" | "iframe" |
|
||||||
"noembed" | "noframes" | "plaintext" |
|
"noembed" | "noframes" | "plaintext" |
|
||||||
"noscript" if elem.get().namespace == namespace::HTML => {
|
"noscript" if elem.deref().namespace == namespace::HTML => {
|
||||||
text.get().characterdata.data.clone()
|
text.deref().characterdata.data.clone()
|
||||||
},
|
},
|
||||||
_ => escape(text.get().characterdata.data, false)
|
_ => escape(text.deref().characterdata.data, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => escape(text.get().characterdata.data, false)
|
_ => escape(text.deref().characterdata.data, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_processing_instruction(processing_instruction: &JSRef<ProcessingInstruction>) -> ~str {
|
fn serialize_processing_instruction(processing_instruction: &JSRef<ProcessingInstruction>) -> ~str {
|
||||||
~"<?" + processing_instruction.get().target + " " + processing_instruction.get().characterdata.data + "?>"
|
~"<?" + processing_instruction.deref().target + " " + processing_instruction.deref().characterdata.data + "?>"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_doctype(doctype: &JSRef<DocumentType>) -> ~str {
|
fn serialize_doctype(doctype: &JSRef<DocumentType>) -> ~str {
|
||||||
~"<!DOCTYPE" + doctype.get().name + ">"
|
~"<!DOCTYPE" + doctype.deref().name + ">"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_elem(elem: &JSRef<Element>, open_elements: &mut Vec<~str>) -> ~str {
|
fn serialize_elem(elem: &JSRef<Element>, open_elements: &mut Vec<~str>) -> ~str {
|
||||||
let mut rv = ~"<" + elem.get().local_name;
|
let mut rv = ~"<" + elem.deref().local_name;
|
||||||
for attr in elem.get().attrs.iter() {
|
for attr in elem.deref().attrs.iter() {
|
||||||
let attr = attr.root();
|
let attr = attr.root();
|
||||||
rv.push_str(serialize_attr(&*attr));
|
rv.push_str(serialize_attr(&*attr));
|
||||||
};
|
};
|
||||||
rv.push_str(">");
|
rv.push_str(">");
|
||||||
match elem.get().local_name.as_slice() {
|
match elem.deref().local_name.as_slice() {
|
||||||
"pre" | "listing" | "textarea" if elem.get().namespace == namespace::HTML => {
|
"pre" | "listing" | "textarea" if elem.deref().namespace == namespace::HTML => {
|
||||||
let node: &JSRef<Node> = NodeCast::from_ref(elem);
|
let node: &JSRef<Node> = NodeCast::from_ref(elem);
|
||||||
match node.first_child().map(|child| child.root()) {
|
match node.first_child().map(|child| child.root()) {
|
||||||
Some(ref child) if child.is_text() => {
|
Some(ref child) if child.is_text() => {
|
||||||
let text: &JSRef<CharacterData> = CharacterDataCast::to_ref(&**child).unwrap();
|
let text: &JSRef<CharacterData> = CharacterDataCast::to_ref(&**child).unwrap();
|
||||||
if text.get().data.len() > 0 && text.get().data[0] == 0x0A as u8 {
|
if text.deref().data.len() > 0 && text.deref().data[0] == 0x0A as u8 {
|
||||||
rv.push_str("\x0A");
|
rv.push_str("\x0A");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -117,26 +117,26 @@ fn serialize_elem(elem: &JSRef<Element>, open_elements: &mut Vec<~str>) -> ~str
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
if !elem.get().is_void() {
|
if !elem.deref().is_void() {
|
||||||
open_elements.push(elem.get().local_name.clone());
|
open_elements.push(elem.deref().local_name.clone());
|
||||||
}
|
}
|
||||||
rv
|
rv
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_attr(attr: &JSRef<Attr>) -> ~str {
|
fn serialize_attr(attr: &JSRef<Attr>) -> ~str {
|
||||||
let attr_name = if attr.get().namespace == namespace::XML {
|
let attr_name = if attr.deref().namespace == namespace::XML {
|
||||||
~"xml:" + attr.get().local_name.clone()
|
~"xml:" + attr.deref().local_name.clone()
|
||||||
} else if attr.get().namespace == namespace::XMLNS &&
|
} else if attr.deref().namespace == namespace::XMLNS &&
|
||||||
attr.get().local_name.as_slice() == "xmlns" {
|
attr.deref().local_name.as_slice() == "xmlns" {
|
||||||
~"xmlns"
|
~"xmlns"
|
||||||
} else if attr.get().namespace == namespace::XMLNS {
|
} else if attr.deref().namespace == namespace::XMLNS {
|
||||||
~"xmlns:" + attr.get().local_name.clone()
|
~"xmlns:" + attr.deref().local_name.clone()
|
||||||
} else if attr.get().namespace == namespace::XLink {
|
} else if attr.deref().namespace == namespace::XLink {
|
||||||
~"xlink:" + attr.get().local_name.clone()
|
~"xlink:" + attr.deref().local_name.clone()
|
||||||
} else {
|
} else {
|
||||||
attr.get().name.clone()
|
attr.deref().name.clone()
|
||||||
};
|
};
|
||||||
~" " + attr_name + "=\"" + escape(attr.get().value, true) + "\""
|
~" " + attr_name + "=\"" + escape(attr.deref().value, true) + "\""
|
||||||
}
|
}
|
||||||
|
|
||||||
fn escape(string: &str, attr_mode: bool) -> ~str {
|
fn escape(string: &str, attr_mode: bool) -> ~str {
|
||||||
|
|
|
@ -74,4 +74,3 @@ impl<'a> HTMLSourceElementMethods for JSRef<'a, HTMLSourceElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,19 +95,19 @@ impl<'a> StyleElementHelpers for JSRef<'a, HTMLStyleElement> {
|
||||||
fn parse_own_css(&self) {
|
fn parse_own_css(&self) {
|
||||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||||
let win = window_from_node(node).root();
|
let win = window_from_node(node).root();
|
||||||
let url = win.get().page().get_url();
|
let url = win.deref().page().get_url();
|
||||||
|
|
||||||
let data = node.GetTextContent().expect("Element.textContent must be a string");
|
let data = node.GetTextContent().expect("Element.textContent must be a string");
|
||||||
let sheet = parse_inline_css(url, data);
|
let sheet = parse_inline_css(url, data);
|
||||||
let LayoutChan(ref layout_chan) = *win.get().page().layout_chan;
|
let LayoutChan(ref layout_chan) = *win.deref().page().layout_chan;
|
||||||
layout_chan.send(AddStylesheetMsg(sheet));
|
layout_chan.send(AddStylesheetMsg(sheet));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> VirtualMethods for JSRef<'a, HTMLStyleElement> {
|
impl<'a> VirtualMethods for JSRef<'a, HTMLStyleElement> {
|
||||||
fn super_type(&self) -> Option<~VirtualMethods:> {
|
fn super_type<'a>(&'a mut self) -> Option<&'a mut VirtualMethods:> {
|
||||||
let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_ref(self);
|
let htmlelement: &mut JSRef<HTMLElement> = HTMLElementCast::from_mut_ref(self);
|
||||||
Some(~htmlelement.clone() as ~VirtualMethods:)
|
Some(htmlelement as &mut VirtualMethods:)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn child_inserted(&mut self, child: &JSRef<Node>) {
|
fn child_inserted(&mut self, child: &JSRef<Node>) {
|
||||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLTableCaptionElementMethods for JSRef<'a, HTMLTableCaptionElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -189,5 +189,3 @@ impl<'a> HTMLTableCellElementMethods for JSRef<'a, HTMLTableCellElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -104,4 +104,3 @@ impl<'a> HTMLTableColElementMethods for JSRef<'a, HTMLTableColElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,4 +164,3 @@ impl<'a> HTMLTableElementMethods for JSRef<'a, HTMLTableElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,4 +119,3 @@ impl<'a> HTMLTableRowElementMethods for JSRef<'a, HTMLTableRowElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,4 +89,3 @@ impl<'a> HTMLTableSectionElementMethods for JSRef<'a, HTMLTableSectionElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -244,4 +244,3 @@ impl<'a> HTMLTextAreaElementMethods for JSRef<'a, HTMLTextAreaElement> {
|
||||||
fn SetRangeText(&self, _replacement: DOMString) {
|
fn SetRangeText(&self, _replacement: DOMString) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLTimeElementMethods for JSRef<'a, HTMLTimeElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,4 +54,3 @@ impl<'a> HTMLTitleElementMethods for JSRef<'a, HTMLTitleElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,4 +99,3 @@ impl<'a> HTMLTrackElementMethods for JSRef<'a, HTMLTrackElement> {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,4 +64,3 @@ impl<'a> HTMLUListElementMethods for JSRef<'a, HTMLUListElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,4 +84,3 @@ impl<'a> HTMLVideoElementMethods for JSRef<'a, HTMLVideoElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -161,7 +161,6 @@ impl<'a> LocationMethods for JSRef<'a, Location> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Reflectable for Location {
|
impl Reflectable for Location {
|
||||||
fn reflector<'a>(&'a self) -> &'a Reflector {
|
fn reflector<'a>(&'a self) -> &'a Reflector {
|
||||||
&self.reflector_
|
&self.reflector_
|
||||||
|
|
|
@ -113,7 +113,6 @@ impl<'a> NavigatorMethods for JSRef<'a, Navigator> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Reflectable for Navigator {
|
impl Reflectable for Navigator {
|
||||||
fn reflector<'a>(&'a self) -> &'a Reflector {
|
fn reflector<'a>(&'a self) -> &'a Reflector {
|
||||||
&self.reflector_
|
&self.reflector_
|
||||||
|
|
|
@ -10,7 +10,7 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, TextCast, NodeCast, Elem
|
||||||
use dom::bindings::codegen::InheritTypes::{CharacterDataCast, NodeBase, NodeDerived};
|
use dom::bindings::codegen::InheritTypes::{CharacterDataCast, NodeBase, NodeDerived};
|
||||||
use dom::bindings::codegen::InheritTypes::{ProcessingInstructionCast, EventTargetCast};
|
use dom::bindings::codegen::InheritTypes::{ProcessingInstructionCast, EventTargetCast};
|
||||||
use dom::bindings::codegen::BindingDeclarations::NodeBinding::NodeConstants;
|
use dom::bindings::codegen::BindingDeclarations::NodeBinding::NodeConstants;
|
||||||
use dom::bindings::js::{JS, JSRef, RootedReference, Temporary, Root};
|
use dom::bindings::js::{JS, JSRef, RootedReference, Temporary, Root, OptionalUnrootable};
|
||||||
use dom::bindings::js::{OptionalSettable, TemporaryPushable, OptionalRootedRootable};
|
use dom::bindings::js::{OptionalSettable, TemporaryPushable, OptionalRootedRootable};
|
||||||
use dom::bindings::js::{ResultRootable, OptionalRootable};
|
use dom::bindings::js::{ResultRootable, OptionalRootable};
|
||||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||||
|
@ -255,7 +255,7 @@ impl<'a> PrivateNodeHelpers for JSRef<'a, Node> {
|
||||||
document.deref().content_changed();
|
document.deref().content_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://spec.whatwg.org/#node-is-removed
|
// http://dom.spec.whatwg.org/#node-is-removed
|
||||||
fn node_removed(&self) {
|
fn node_removed(&self) {
|
||||||
assert!(self.parent_node().is_none());
|
assert!(self.parent_node().is_none());
|
||||||
let document = document_from_node(self).root();
|
let document = document_from_node(self).root();
|
||||||
|
@ -417,9 +417,9 @@ pub trait NodeHelpers {
|
||||||
fn dump_indent(&self, indent: uint);
|
fn dump_indent(&self, indent: uint);
|
||||||
fn debug_str(&self) -> ~str;
|
fn debug_str(&self) -> ~str;
|
||||||
|
|
||||||
fn traverse_preorder<'a>(&self) -> TreeIterator<'a>;
|
fn traverse_preorder<'a>(&'a self) -> TreeIterator<'a>;
|
||||||
fn sequential_traverse_postorder<'a>(&self) -> TreeIterator<'a>;
|
fn sequential_traverse_postorder<'a>(&'a self) -> TreeIterator<'a>;
|
||||||
fn inclusively_following_siblings(&self) -> AbstractNodeChildrenIterator;
|
fn inclusively_following_siblings<'a>(&'a self) -> AbstractNodeChildrenIterator<'a>;
|
||||||
|
|
||||||
fn to_trusted_node_address(&self) -> TrustedNodeAddress;
|
fn to_trusted_node_address(&self) -> TrustedNodeAddress;
|
||||||
|
|
||||||
|
@ -455,34 +455,34 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_in_doc(&self) -> bool {
|
fn is_in_doc(&self) -> bool {
|
||||||
self.get().flags.is_in_doc()
|
self.deref().flags.is_in_doc()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the type ID of this node. Fails if this node is borrowed mutably.
|
/// Returns the type ID of this node. Fails if this node is borrowed mutably.
|
||||||
fn type_id(&self) -> NodeTypeId {
|
fn type_id(&self) -> NodeTypeId {
|
||||||
self.get().type_id
|
self.deref().type_id
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parent_node(&self) -> Option<Temporary<Node>> {
|
fn parent_node(&self) -> Option<Temporary<Node>> {
|
||||||
self.get().parent_node.clone().map(|node| Temporary::new(node))
|
self.deref().parent_node.clone().map(|node| Temporary::new(node))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn first_child(&self) -> Option<Temporary<Node>> {
|
fn first_child(&self) -> Option<Temporary<Node>> {
|
||||||
self.get().first_child.clone().map(|node| Temporary::new(node))
|
self.deref().first_child.clone().map(|node| Temporary::new(node))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn last_child(&self) -> Option<Temporary<Node>> {
|
fn last_child(&self) -> Option<Temporary<Node>> {
|
||||||
self.get().last_child.clone().map(|node| Temporary::new(node))
|
self.deref().last_child.clone().map(|node| Temporary::new(node))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the previous sibling of this node. Fails if this node is borrowed mutably.
|
/// Returns the previous sibling of this node. Fails if this node is borrowed mutably.
|
||||||
fn prev_sibling(&self) -> Option<Temporary<Node>> {
|
fn prev_sibling(&self) -> Option<Temporary<Node>> {
|
||||||
self.get().prev_sibling.clone().map(|node| Temporary::new(node))
|
self.deref().prev_sibling.clone().map(|node| Temporary::new(node))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the next sibling of this node. Fails if this node is borrowed mutably.
|
/// Returns the next sibling of this node. Fails if this node is borrowed mutably.
|
||||||
fn next_sibling(&self) -> Option<Temporary<Node>> {
|
fn next_sibling(&self) -> Option<Temporary<Node>> {
|
||||||
self.get().next_sibling.clone().map(|node| Temporary::new(node))
|
self.deref().next_sibling.clone().map(|node| Temporary::new(node))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -536,22 +536,22 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterates over this node and all its descendants, in preorder.
|
/// Iterates over this node and all its descendants, in preorder.
|
||||||
fn traverse_preorder<'a>(&self) -> TreeIterator<'a> {
|
fn traverse_preorder<'a>(&'a self) -> TreeIterator<'a> {
|
||||||
let mut nodes = vec!();
|
let mut nodes = vec!();
|
||||||
gather_abstract_nodes(self, &mut nodes, false);
|
gather_abstract_nodes(self, &mut nodes, false);
|
||||||
TreeIterator::new(nodes)
|
TreeIterator::new(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterates over this node and all its descendants, in postorder.
|
/// Iterates over this node and all its descendants, in postorder.
|
||||||
fn sequential_traverse_postorder<'a>(&self) -> TreeIterator<'a> {
|
fn sequential_traverse_postorder<'a>(&'a self) -> TreeIterator<'a> {
|
||||||
let mut nodes = vec!();
|
let mut nodes = vec!();
|
||||||
gather_abstract_nodes(self, &mut nodes, true);
|
gather_abstract_nodes(self, &mut nodes, true);
|
||||||
TreeIterator::new(nodes)
|
TreeIterator::new(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inclusively_following_siblings(&self) -> AbstractNodeChildrenIterator {
|
fn inclusively_following_siblings<'a>(&'a self) -> AbstractNodeChildrenIterator<'a> {
|
||||||
AbstractNodeChildrenIterator {
|
AbstractNodeChildrenIterator {
|
||||||
current_node: Some((*self.unrooted().root()).clone()),
|
current_node: Some(self.clone()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -561,7 +561,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
|
||||||
|
|
||||||
fn following_siblings(&self) -> AbstractNodeChildrenIterator {
|
fn following_siblings(&self) -> AbstractNodeChildrenIterator {
|
||||||
AbstractNodeChildrenIterator {
|
AbstractNodeChildrenIterator {
|
||||||
current_node: self.next_sibling().map(|node| (*node.root()).clone()),
|
current_node: self.next_sibling().root().map(|next| next.deref().clone()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -573,12 +573,12 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_trusted_node_address(&self) -> TrustedNodeAddress {
|
fn to_trusted_node_address(&self) -> TrustedNodeAddress {
|
||||||
TrustedNodeAddress(self.get() as *Node as *libc::c_void)
|
TrustedNodeAddress(self.deref() as *Node as *libc::c_void)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_bounding_content_box(&self) -> Rect<Au> {
|
fn get_bounding_content_box(&self) -> Rect<Au> {
|
||||||
let window = window_from_node(self).root();
|
let window = window_from_node(self).root();
|
||||||
let page = window.get().page();
|
let page = window.deref().page();
|
||||||
let (chan, port) = channel();
|
let (chan, port) = channel();
|
||||||
let addr = self.to_trusted_node_address();
|
let addr = self.to_trusted_node_address();
|
||||||
let ContentBoxResponse(rect) = page.query_layout(ContentBoxQuery(addr, chan), port);
|
let ContentBoxResponse(rect) = page.query_layout(ContentBoxQuery(addr, chan), port);
|
||||||
|
@ -587,7 +587,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
|
||||||
|
|
||||||
fn get_content_boxes(&self) -> Vec<Rect<Au>> {
|
fn get_content_boxes(&self) -> Vec<Rect<Au>> {
|
||||||
let window = window_from_node(self).root();
|
let window = window_from_node(self).root();
|
||||||
let page = window.get().page();
|
let page = window.deref().page();
|
||||||
let (chan, port) = channel();
|
let (chan, port) = channel();
|
||||||
let addr = self.to_trusted_node_address();
|
let addr = self.to_trusted_node_address();
|
||||||
let ContentBoxesResponse(rects) = page.query_layout(ContentBoxesQuery(addr, chan), port);
|
let ContentBoxesResponse(rects) = page.query_layout(ContentBoxesQuery(addr, chan), port);
|
||||||
|
@ -803,7 +803,7 @@ impl NodeIterator {
|
||||||
fn next_child<'b>(&self, node: &JSRef<'b, Node>) -> Option<JSRef<Node>> {
|
fn next_child<'b>(&self, node: &JSRef<'b, Node>) -> Option<JSRef<Node>> {
|
||||||
if !self.include_descendants_of_void && node.is_element() {
|
if !self.include_descendants_of_void && node.is_element() {
|
||||||
let elem: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
let elem: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
||||||
if elem.get().is_void() {
|
if elem.deref().is_void() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
node.first_child().map(|child| (*child.root()).clone())
|
node.first_child().map(|child| (*child.root()).clone())
|
||||||
|
@ -861,15 +861,15 @@ impl<'a> Iterator<JSRef<'a, Node>> for NodeIterator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gather_abstract_nodes<'a>(cur: &JSRef<Node>, refs: &mut Vec<JSRef<Node>>, postorder: bool) {
|
fn gather_abstract_nodes<'a>(cur: &JSRef<'a, Node>, refs: &mut Vec<JSRef<'a, Node>>, postorder: bool) {
|
||||||
if !postorder {
|
if !postorder {
|
||||||
refs.push((*cur.unrooted().root()).clone());
|
refs.push(cur.clone());
|
||||||
}
|
}
|
||||||
for kid in cur.children() {
|
for kid in cur.children() {
|
||||||
gather_abstract_nodes(&kid, refs, postorder)
|
gather_abstract_nodes(&kid, refs, postorder)
|
||||||
}
|
}
|
||||||
if postorder {
|
if postorder {
|
||||||
refs.push((*cur.unrooted().root()).clone());
|
refs.push(cur.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -889,9 +889,9 @@ impl Node {
|
||||||
wrap_fn: extern "Rust" fn(*JSContext, &JSRef<Window>, ~N) -> JS<N>)
|
wrap_fn: extern "Rust" fn(*JSContext, &JSRef<Window>, ~N) -> JS<N>)
|
||||||
-> Temporary<N> {
|
-> Temporary<N> {
|
||||||
assert!(node.reflector().get_jsobject().is_null());
|
assert!(node.reflector().get_jsobject().is_null());
|
||||||
let window = document.get().window.root();
|
let window = document.deref().window.root();
|
||||||
let node = reflect_dom_object(node, &window.root_ref(), wrap_fn).root();
|
let node = reflect_dom_object(node, &window.root_ref(), wrap_fn).root();
|
||||||
assert!(node.reflector().get_jsobject().is_not_null());
|
assert!(node.deref().reflector().get_jsobject().is_not_null());
|
||||||
Temporary::from_rooted(&*node)
|
Temporary::from_rooted(&*node)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -914,7 +914,7 @@ impl Node {
|
||||||
next_sibling: None,
|
next_sibling: None,
|
||||||
prev_sibling: None,
|
prev_sibling: None,
|
||||||
|
|
||||||
owner_doc: doc.map(|doc| doc.unrooted()),
|
owner_doc: doc.unrooted(),
|
||||||
child_list: None,
|
child_list: None,
|
||||||
|
|
||||||
flags: NodeFlags::new(type_id),
|
flags: NodeFlags::new(type_id),
|
||||||
|
@ -1110,7 +1110,7 @@ impl Node {
|
||||||
// Step 8.
|
// Step 8.
|
||||||
for node in nodes.mut_iter() {
|
for node in nodes.mut_iter() {
|
||||||
parent.add_child(node, child.clone());
|
parent.add_child(node, child.clone());
|
||||||
node.get_mut().flags.set_is_in_doc(parent.is_in_doc());
|
node.deref_mut().flags.set_is_in_doc(parent.is_in_doc());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 9.
|
// Step 9.
|
||||||
|
@ -1193,7 +1193,7 @@ impl Node {
|
||||||
// Step 6-7: mutation observers.
|
// Step 6-7: mutation observers.
|
||||||
// Step 8.
|
// Step 8.
|
||||||
parent.remove_child(node);
|
parent.remove_child(node);
|
||||||
node.get_mut().flags.set_is_in_doc(false);
|
node.deref_mut().flags.set_is_in_doc(false);
|
||||||
|
|
||||||
// Step 9.
|
// Step 9.
|
||||||
match suppress_observers {
|
match suppress_observers {
|
||||||
|
@ -1217,7 +1217,7 @@ impl Node {
|
||||||
let mut copy: Root<Node> = match node.type_id() {
|
let mut copy: Root<Node> = match node.type_id() {
|
||||||
DoctypeNodeTypeId => {
|
DoctypeNodeTypeId => {
|
||||||
let doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(node).unwrap();
|
let doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(node).unwrap();
|
||||||
let doctype = doctype.get();
|
let doctype = doctype.deref();
|
||||||
let doctype = DocumentType::new(doctype.name.clone(),
|
let doctype = DocumentType::new(doctype.name.clone(),
|
||||||
Some(doctype.public_id.clone()),
|
Some(doctype.public_id.clone()),
|
||||||
Some(doctype.system_id.clone()), &*document);
|
Some(doctype.system_id.clone()), &*document);
|
||||||
|
@ -1229,7 +1229,7 @@ impl Node {
|
||||||
},
|
},
|
||||||
CommentNodeTypeId => {
|
CommentNodeTypeId => {
|
||||||
let comment: &JSRef<Comment> = CommentCast::to_ref(node).unwrap();
|
let comment: &JSRef<Comment> = CommentCast::to_ref(node).unwrap();
|
||||||
let comment = comment.get();
|
let comment = comment.deref();
|
||||||
let comment = Comment::new(comment.characterdata.data.clone(), &*document);
|
let comment = Comment::new(comment.characterdata.data.clone(), &*document);
|
||||||
NodeCast::from_unrooted(comment)
|
NodeCast::from_unrooted(comment)
|
||||||
},
|
},
|
||||||
|
@ -1246,19 +1246,19 @@ impl Node {
|
||||||
},
|
},
|
||||||
ElementNodeTypeId(..) => {
|
ElementNodeTypeId(..) => {
|
||||||
let element: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
let element: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
||||||
let element = element.get();
|
let element = element.deref();
|
||||||
let element = build_element_from_tag(element.local_name.clone(), &*document);
|
let element = build_element_from_tag(element.local_name.clone(), &*document);
|
||||||
NodeCast::from_unrooted(element)
|
NodeCast::from_unrooted(element)
|
||||||
},
|
},
|
||||||
TextNodeTypeId => {
|
TextNodeTypeId => {
|
||||||
let text: &JSRef<Text> = TextCast::to_ref(node).unwrap();
|
let text: &JSRef<Text> = TextCast::to_ref(node).unwrap();
|
||||||
let text = text.get();
|
let text = text.deref();
|
||||||
let text = Text::new(text.characterdata.data.clone(), &*document);
|
let text = Text::new(text.characterdata.data.clone(), &*document);
|
||||||
NodeCast::from_unrooted(text)
|
NodeCast::from_unrooted(text)
|
||||||
},
|
},
|
||||||
ProcessingInstructionNodeTypeId => {
|
ProcessingInstructionNodeTypeId => {
|
||||||
let pi: &JSRef<ProcessingInstruction> = ProcessingInstructionCast::to_ref(node).unwrap();
|
let pi: &JSRef<ProcessingInstruction> = ProcessingInstructionCast::to_ref(node).unwrap();
|
||||||
let pi = pi.get();
|
let pi = pi.deref();
|
||||||
let pi = ProcessingInstruction::new(pi.target.clone(),
|
let pi = ProcessingInstruction::new(pi.target.clone(),
|
||||||
pi.characterdata.data.clone(), &*document);
|
pi.characterdata.data.clone(), &*document);
|
||||||
NodeCast::from_unrooted(pi)
|
NodeCast::from_unrooted(pi)
|
||||||
|
@ -1275,7 +1275,7 @@ impl Node {
|
||||||
assert!(&*copy.owner_doc().root() == &*document);
|
assert!(&*copy.owner_doc().root() == &*document);
|
||||||
|
|
||||||
// Step 4 (some data already copied in step 2).
|
// Step 4 (some data already copied in step 2).
|
||||||
match node.get().type_id {
|
match node.type_id() {
|
||||||
DocumentNodeTypeId => {
|
DocumentNodeTypeId => {
|
||||||
let node_doc: &JSRef<Document> = DocumentCast::to_ref(node).unwrap();
|
let node_doc: &JSRef<Document> = DocumentCast::to_ref(node).unwrap();
|
||||||
let copy_doc: &mut JSRef<Document> = DocumentCast::to_mut_ref(&mut *copy).unwrap();
|
let copy_doc: &mut JSRef<Document> = DocumentCast::to_mut_ref(&mut *copy).unwrap();
|
||||||
|
@ -1284,16 +1284,16 @@ impl Node {
|
||||||
},
|
},
|
||||||
ElementNodeTypeId(..) => {
|
ElementNodeTypeId(..) => {
|
||||||
let node_elem: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
let node_elem: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
||||||
let node_elem = node_elem.get();
|
let node_elem = node_elem.deref();
|
||||||
let copy_elem: &mut JSRef<Element> = ElementCast::to_mut_ref(&mut *copy).unwrap();
|
let copy_elem: &mut JSRef<Element> = ElementCast::to_mut_ref(&mut *copy).unwrap();
|
||||||
|
|
||||||
// XXX: to avoid double borrowing compile error. we might be able to fix this after #1854
|
// XXX: to avoid double borrowing compile error. we might be able to fix this after #1854
|
||||||
let copy_elem_alias = copy_elem.clone();
|
let copy_elem_alias = copy_elem.clone();
|
||||||
|
|
||||||
let copy_elem = copy_elem.get_mut();
|
let copy_elem = copy_elem.deref_mut();
|
||||||
// FIXME: https://github.com/mozilla/servo/issues/1737
|
// FIXME: https://github.com/mozilla/servo/issues/1737
|
||||||
copy_elem.namespace = node_elem.namespace.clone();
|
copy_elem.namespace = node_elem.namespace.clone();
|
||||||
let window = document.get().window.root();
|
let window = document.deref().window.root();
|
||||||
for attr in node_elem.attrs.iter().map(|attr| attr.root()) {
|
for attr in node_elem.attrs.iter().map(|attr| attr.root()) {
|
||||||
copy_elem.attrs.push_unrooted(
|
copy_elem.attrs.push_unrooted(
|
||||||
&Attr::new(&*window,
|
&Attr::new(&*window,
|
||||||
|
@ -1396,7 +1396,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
||||||
CommentNodeTypeId => ~"#comment",
|
CommentNodeTypeId => ~"#comment",
|
||||||
DoctypeNodeTypeId => {
|
DoctypeNodeTypeId => {
|
||||||
let doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(self).unwrap();
|
let doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(self).unwrap();
|
||||||
doctype.get().name.clone()
|
doctype.deref().name.clone()
|
||||||
},
|
},
|
||||||
DocumentFragmentNodeTypeId => ~"#document-fragment",
|
DocumentFragmentNodeTypeId => ~"#document-fragment",
|
||||||
DocumentNodeTypeId => ~"#document"
|
DocumentNodeTypeId => ~"#document"
|
||||||
|
@ -1514,7 +1514,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
||||||
for node in self.traverse_preorder() {
|
for node in self.traverse_preorder() {
|
||||||
if node.is_text() {
|
if node.is_text() {
|
||||||
let text: &JSRef<Text> = TextCast::to_ref(&node).unwrap();
|
let text: &JSRef<Text> = TextCast::to_ref(&node).unwrap();
|
||||||
content.push_str(text.get().characterdata.data.as_slice());
|
content.push_str(text.deref().characterdata.data.as_slice());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(content)
|
Some(content)
|
||||||
|
@ -1557,7 +1557,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
||||||
|
|
||||||
{
|
{
|
||||||
let characterdata: &mut JSRef<CharacterData> = CharacterDataCast::to_mut_ref(self).unwrap();
|
let characterdata: &mut JSRef<CharacterData> = CharacterDataCast::to_mut_ref(self).unwrap();
|
||||||
characterdata.get_mut().data = value.clone();
|
characterdata.deref_mut().data = value.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify the document that the content of this node is different
|
// Notify the document that the content of this node is different
|
||||||
|
@ -1755,35 +1755,35 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
||||||
fn is_equal_doctype(node: &JSRef<Node>, other: &JSRef<Node>) -> bool {
|
fn is_equal_doctype(node: &JSRef<Node>, other: &JSRef<Node>) -> bool {
|
||||||
let doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(node).unwrap();
|
let doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(node).unwrap();
|
||||||
let other_doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(other).unwrap();
|
let other_doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(other).unwrap();
|
||||||
(doctype.get().name == other_doctype.get().name) &&
|
(doctype.deref().name == other_doctype.deref().name) &&
|
||||||
(doctype.get().public_id == other_doctype.get().public_id) &&
|
(doctype.deref().public_id == other_doctype.deref().public_id) &&
|
||||||
(doctype.get().system_id == other_doctype.get().system_id)
|
(doctype.deref().system_id == other_doctype.deref().system_id)
|
||||||
}
|
}
|
||||||
fn is_equal_element(node: &JSRef<Node>, other: &JSRef<Node>) -> bool {
|
fn is_equal_element(node: &JSRef<Node>, other: &JSRef<Node>) -> bool {
|
||||||
let element: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
let element: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
||||||
let other_element: &JSRef<Element> = ElementCast::to_ref(other).unwrap();
|
let other_element: &JSRef<Element> = ElementCast::to_ref(other).unwrap();
|
||||||
// FIXME: namespace prefix
|
// FIXME: namespace prefix
|
||||||
(element.get().namespace == other_element.get().namespace) &&
|
(element.deref().namespace == other_element.deref().namespace) &&
|
||||||
(element.get().local_name == other_element.get().local_name) &&
|
(element.deref().local_name == other_element.deref().local_name) &&
|
||||||
(element.get().attrs.len() == other_element.get().attrs.len())
|
(element.deref().attrs.len() == other_element.deref().attrs.len())
|
||||||
}
|
}
|
||||||
fn is_equal_processinginstruction(node: &JSRef<Node>, other: &JSRef<Node>) -> bool {
|
fn is_equal_processinginstruction(node: &JSRef<Node>, other: &JSRef<Node>) -> bool {
|
||||||
let pi: &JSRef<ProcessingInstruction> = ProcessingInstructionCast::to_ref(node).unwrap();
|
let pi: &JSRef<ProcessingInstruction> = ProcessingInstructionCast::to_ref(node).unwrap();
|
||||||
let other_pi: &JSRef<ProcessingInstruction> = ProcessingInstructionCast::to_ref(other).unwrap();
|
let other_pi: &JSRef<ProcessingInstruction> = ProcessingInstructionCast::to_ref(other).unwrap();
|
||||||
(pi.get().target == other_pi.get().target) &&
|
(pi.deref().target == other_pi.deref().target) &&
|
||||||
(pi.get().characterdata.data == other_pi.get().characterdata.data)
|
(pi.deref().characterdata.data == other_pi.deref().characterdata.data)
|
||||||
}
|
}
|
||||||
fn is_equal_characterdata(node: &JSRef<Node>, other: &JSRef<Node>) -> bool {
|
fn is_equal_characterdata(node: &JSRef<Node>, other: &JSRef<Node>) -> bool {
|
||||||
let characterdata: &JSRef<CharacterData> = CharacterDataCast::to_ref(node).unwrap();
|
let characterdata: &JSRef<CharacterData> = CharacterDataCast::to_ref(node).unwrap();
|
||||||
let other_characterdata: &JSRef<CharacterData> = CharacterDataCast::to_ref(other).unwrap();
|
let other_characterdata: &JSRef<CharacterData> = CharacterDataCast::to_ref(other).unwrap();
|
||||||
characterdata.get().data == other_characterdata.get().data
|
characterdata.deref().data == other_characterdata.deref().data
|
||||||
}
|
}
|
||||||
fn is_equal_element_attrs(node: &JSRef<Node>, other: &JSRef<Node>) -> bool {
|
fn is_equal_element_attrs(node: &JSRef<Node>, other: &JSRef<Node>) -> bool {
|
||||||
let element: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
let element: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
||||||
let other_element: &JSRef<Element> = ElementCast::to_ref(other).unwrap();
|
let other_element: &JSRef<Element> = ElementCast::to_ref(other).unwrap();
|
||||||
assert!(element.get().attrs.len() == other_element.get().attrs.len());
|
assert!(element.deref().attrs.len() == other_element.deref().attrs.len());
|
||||||
element.get().attrs.iter().map(|attr| attr.root()).all(|attr| {
|
element.deref().attrs.iter().map(|attr| attr.root()).all(|attr| {
|
||||||
other_element.get().attrs.iter().map(|attr| attr.root()).any(|other_attr| {
|
other_element.deref().attrs.iter().map(|attr| attr.root()).any(|other_attr| {
|
||||||
(attr.namespace == other_attr.namespace) &&
|
(attr.namespace == other_attr.namespace) &&
|
||||||
(attr.local_name == other_attr.local_name) &&
|
(attr.local_name == other_attr.local_name) &&
|
||||||
(attr.value == other_attr.value)
|
(attr.value == other_attr.value)
|
||||||
|
@ -1929,8 +1929,8 @@ pub fn window_from_node<T: NodeBase>(derived: &JSRef<T>) -> Temporary<Window> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> VirtualMethods for JSRef<'a, Node> {
|
impl<'a> VirtualMethods for JSRef<'a, Node> {
|
||||||
fn super_type(&self) -> Option<~VirtualMethods:> {
|
fn super_type<'a>(&'a mut self) -> Option<&'a mut VirtualMethods:> {
|
||||||
let eventtarget: &JSRef<EventTarget> = EventTargetCast::from_ref(self);
|
let eventtarget: &mut JSRef<EventTarget> = EventTargetCast::from_mut_ref(self);
|
||||||
Some(~eventtarget.clone() as ~VirtualMethods:)
|
Some(eventtarget as &mut VirtualMethods:)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,4 +50,3 @@ impl<'a> ProcessingInstructionMethods for JSRef<'a, ProcessingInstruction> {
|
||||||
self.target.clone()
|
self.target.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,7 +154,7 @@ pub trait TestBindingMethods {
|
||||||
fn PassOptionalNullableString(&self, _: Option<Option<DOMString>>);
|
fn PassOptionalNullableString(&self, _: Option<Option<DOMString>>);
|
||||||
fn PassOptionalNullableByteString(&self, _: Option<Option<ByteString>>) {}
|
fn PassOptionalNullableByteString(&self, _: Option<Option<ByteString>>) {}
|
||||||
// fn PassOptionalNullableEnum(&self, _: Option<Option<TestEnum>>);
|
// fn PassOptionalNullableEnum(&self, _: Option<Option<TestEnum>>);
|
||||||
fn PassOptionalNullableInterface(&self, _: Option<Option<JS<Blob>>>);
|
fn PassOptionalNullableInterface(&self, _: Option<Option<JSRef<Blob>>>);
|
||||||
fn PassOptionalNullableUnion(&self, _: Option<Option<HTMLElementOrLong>>);
|
fn PassOptionalNullableUnion(&self, _: Option<Option<HTMLElementOrLong>>);
|
||||||
|
|
||||||
fn PassOptionalBooleanWithDefault(&self, _: bool);
|
fn PassOptionalBooleanWithDefault(&self, _: bool);
|
||||||
|
@ -268,7 +268,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
|
||||||
fn GetEnumAttributeNullable(&self) -> Option<TestEnum> { Some(_empty) }
|
fn GetEnumAttributeNullable(&self) -> Option<TestEnum> { Some(_empty) }
|
||||||
fn GetInterfaceAttributeNullable(&self) -> Option<Temporary<Blob>> {
|
fn GetInterfaceAttributeNullable(&self) -> Option<Temporary<Blob>> {
|
||||||
let window = self.window.root();
|
let window = self.window.root();
|
||||||
Some(Blob::new(&(*window)))
|
Some(Blob::new(&*window))
|
||||||
}
|
}
|
||||||
fn SetInterfaceAttributeNullable(&self, _: Option<JSRef<Blob>>) {}
|
fn SetInterfaceAttributeNullable(&self, _: Option<JSRef<Blob>>) {}
|
||||||
|
|
||||||
|
@ -340,7 +340,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
|
||||||
fn PassOptionalNullableString(&self, _: Option<Option<DOMString>>) {}
|
fn PassOptionalNullableString(&self, _: Option<Option<DOMString>>) {}
|
||||||
fn PassOptionalNullableByteString(&self, _: Option<Option<ByteString>>) {}
|
fn PassOptionalNullableByteString(&self, _: Option<Option<ByteString>>) {}
|
||||||
// fn PassOptionalNullableEnum(&self, _: Option<Option<TestEnum>>) {}
|
// fn PassOptionalNullableEnum(&self, _: Option<Option<TestEnum>>) {}
|
||||||
fn PassOptionalNullableInterface(&self, _: Option<Option<JS<Blob>>>) {}
|
fn PassOptionalNullableInterface(&self, _: Option<Option<JSRef<Blob>>>) {}
|
||||||
fn PassOptionalNullableUnion(&self, _: Option<Option<HTMLElementOrLong>>) {}
|
fn PassOptionalNullableUnion(&self, _: Option<Option<HTMLElementOrLong>>) {}
|
||||||
|
|
||||||
fn PassOptionalBooleanWithDefault(&self, _: bool) {}
|
fn PassOptionalBooleanWithDefault(&self, _: bool) {}
|
||||||
|
|
|
@ -60,4 +60,3 @@ impl<'a> TextMethods for JSRef<'a, Text> {
|
||||||
Ok(~"")
|
Ok(~"")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,6 @@ impl<'a> UIEventMethods for JSRef<'a, UIEvent> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Reflectable for UIEvent {
|
impl Reflectable for UIEvent {
|
||||||
fn reflector<'a>(&'a self) -> &'a Reflector {
|
fn reflector<'a>(&'a self) -> &'a Reflector {
|
||||||
self.event.reflector()
|
self.event.reflector()
|
||||||
|
|
|
@ -80,7 +80,6 @@ impl<'a> ValidityStateMethods for JSRef<'a, ValidityState> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Reflectable for ValidityState {
|
impl Reflectable for ValidityState {
|
||||||
fn reflector<'a>(&'a self) -> &'a Reflector {
|
fn reflector<'a>(&'a self) -> &'a Reflector {
|
||||||
&self.reflector_
|
&self.reflector_
|
||||||
|
|
|
@ -17,7 +17,7 @@ use dom::htmliframeelement::HTMLIFrameElement;
|
||||||
use dom::htmlimageelement::HTMLImageElement;
|
use dom::htmlimageelement::HTMLImageElement;
|
||||||
use dom::htmlobjectelement::HTMLObjectElement;
|
use dom::htmlobjectelement::HTMLObjectElement;
|
||||||
use dom::htmlstyleelement::HTMLStyleElement;
|
use dom::htmlstyleelement::HTMLStyleElement;
|
||||||
use dom::node::{Node, ElementNodeTypeId};
|
use dom::node::{Node, NodeHelpers, ElementNodeTypeId};
|
||||||
use servo_util::str::DOMString;
|
use servo_util::str::DOMString;
|
||||||
|
|
||||||
/// Trait to allow DOM nodes to opt-in to overriding (or adding to) common
|
/// Trait to allow DOM nodes to opt-in to overriding (or adding to) common
|
||||||
|
@ -25,7 +25,7 @@ use servo_util::str::DOMString;
|
||||||
pub trait VirtualMethods {
|
pub trait VirtualMethods {
|
||||||
/// Returns self as the superclass of the implementation for this trait,
|
/// Returns self as the superclass of the implementation for this trait,
|
||||||
/// if any.
|
/// if any.
|
||||||
fn super_type(&self) -> Option<~VirtualMethods:>;
|
fn super_type<'a>(&'a mut self) -> Option<&'a mut VirtualMethods:>;
|
||||||
|
|
||||||
/// Called when changing or adding attributes, after the attribute's value
|
/// Called when changing or adding attributes, after the attribute's value
|
||||||
/// has been updated.
|
/// has been updated.
|
||||||
|
@ -75,7 +75,7 @@ pub trait VirtualMethods {
|
||||||
/// concrete type, propagating up the parent hierarchy unless otherwise
|
/// concrete type, propagating up the parent hierarchy unless otherwise
|
||||||
/// interrupted.
|
/// interrupted.
|
||||||
pub fn vtable_for<'a>(node: &'a mut JSRef<Node>) -> &'a mut VirtualMethods: {
|
pub fn vtable_for<'a>(node: &'a mut JSRef<Node>) -> &'a mut VirtualMethods: {
|
||||||
match node.get().type_id {
|
match node.type_id() {
|
||||||
ElementNodeTypeId(HTMLImageElementTypeId) => {
|
ElementNodeTypeId(HTMLImageElementTypeId) => {
|
||||||
let element: &mut JSRef<HTMLImageElement> = HTMLImageElementCast::to_mut_ref(node).unwrap();
|
let element: &mut JSRef<HTMLImageElement> = HTMLImageElementCast::to_mut_ref(node).unwrap();
|
||||||
element as &mut VirtualMethods:
|
element as &mut VirtualMethods:
|
||||||
|
|
|
@ -156,7 +156,7 @@ interface TestBinding {
|
||||||
void passOptionalNullableString(optional DOMString? arg);
|
void passOptionalNullableString(optional DOMString? arg);
|
||||||
void passOptionalNullableByteString(optional ByteString? arg);
|
void passOptionalNullableByteString(optional ByteString? arg);
|
||||||
// void passOptionalNullableEnum(optional TestEnum? arg);
|
// void passOptionalNullableEnum(optional TestEnum? arg);
|
||||||
//void passOptionalNullableInterface(optional Blob? arg); //XXXjdm disabled until later commit
|
void passOptionalNullableInterface(optional Blob? arg);
|
||||||
void passOptionalNullableUnion(optional (HTMLElement or long)? arg);
|
void passOptionalNullableUnion(optional (HTMLElement or long)? arg);
|
||||||
|
|
||||||
void passOptionalBooleanWithDefault(optional boolean arg = false);
|
void passOptionalBooleanWithDefault(optional boolean arg = false);
|
||||||
|
|
|
@ -81,7 +81,7 @@ trait NodeWrapping<T> {
|
||||||
|
|
||||||
impl<'a, T: NodeBase+Reflectable> NodeWrapping<T> for JSRef<'a, T> {
|
impl<'a, T: NodeBase+Reflectable> NodeWrapping<T> for JSRef<'a, T> {
|
||||||
unsafe fn to_hubbub_node(&self) -> hubbub::NodeDataPtr {
|
unsafe fn to_hubbub_node(&self) -> hubbub::NodeDataPtr {
|
||||||
cast::transmute(self.get())
|
cast::transmute(self.deref())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,7 +293,6 @@ pub fn parse_html(page: &Page,
|
||||||
let mut parser = hubbub::Parser("UTF-8", false);
|
let mut parser = hubbub::Parser("UTF-8", false);
|
||||||
debug!("created parser");
|
debug!("created parser");
|
||||||
|
|
||||||
|
|
||||||
parser.set_document_node(unsafe { document.to_hubbub_node() });
|
parser.set_document_node(unsafe { document.to_hubbub_node() });
|
||||||
parser.enable_scripting(true);
|
parser.enable_scripting(true);
|
||||||
parser.enable_styling(true);
|
parser.enable_styling(true);
|
||||||
|
@ -393,7 +392,7 @@ pub fn parse_html(page: &Page,
|
||||||
let SubpageId(id_num) = subpage_id;
|
let SubpageId(id_num) = subpage_id;
|
||||||
*next_subpage_id.borrow_mut() = SubpageId(id_num + 1);
|
*next_subpage_id.borrow_mut() = SubpageId(id_num + 1);
|
||||||
|
|
||||||
iframe_element.get_mut().size = Some(IFrameSize {
|
iframe_element.deref_mut().size = Some(IFrameSize {
|
||||||
pipeline_id: pipeline_id,
|
pipeline_id: pipeline_id,
|
||||||
subpage_id: subpage_id,
|
subpage_id: subpage_id,
|
||||||
});
|
});
|
||||||
|
@ -477,7 +476,7 @@ pub fn parse_html(page: &Page,
|
||||||
match script.get_attribute(Null, "src").root() {
|
match script.get_attribute(Null, "src").root() {
|
||||||
Some(src) => {
|
Some(src) => {
|
||||||
debug!("found script: {:s}", src.deref().Value());
|
debug!("found script: {:s}", src.deref().Value());
|
||||||
let new_url = parse_url(src.get().value_ref(), Some(url3.clone()));
|
let new_url = parse_url(src.deref().value_ref(), Some(url3.clone()));
|
||||||
js_chan2.send(JSTaskNewFile(new_url));
|
js_chan2.send(JSTaskNewFile(new_url));
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
@ -487,7 +486,7 @@ pub fn parse_html(page: &Page,
|
||||||
for child in scriptnode.children() {
|
for child in scriptnode.children() {
|
||||||
debug!("child = {:?}", child);
|
debug!("child = {:?}", child);
|
||||||
let text: &JSRef<Text> = TextCast::to_ref(&child).unwrap();
|
let text: &JSRef<Text> = TextCast::to_ref(&child).unwrap();
|
||||||
data.push(text.get().characterdata.data.to_str()); // FIXME: Bad copy.
|
data.push(text.deref().characterdata.data.to_str()); // FIXME: Bad copy.
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("script data = {:?}", data);
|
debug!("script data = {:?}", data);
|
||||||
|
|
|
@ -419,7 +419,7 @@ impl Page {
|
||||||
anchors.find(|node| {
|
anchors.find(|node| {
|
||||||
let elem: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
let elem: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
||||||
elem.get_attribute(Null, "name").root().map_or(false, |attr| {
|
elem.get_attribute(Null, "name").root().map_or(false, |attr| {
|
||||||
attr.get().value_ref() == fragid
|
attr.deref().value_ref() == fragid
|
||||||
})
|
})
|
||||||
}).map(|node| Temporary::from_rooted(ElementCast::to_ref(&node).unwrap()))
|
}).map(|node| Temporary::from_rooted(ElementCast::to_ref(&node).unwrap()))
|
||||||
}
|
}
|
||||||
|
@ -758,19 +758,18 @@ impl ScriptTask {
|
||||||
|
|
||||||
/// Handles a timer that fired.
|
/// Handles a timer that fired.
|
||||||
fn handle_fire_timer_msg(&self, id: PipelineId, timer_id: TimerId) {
|
fn handle_fire_timer_msg(&self, id: PipelineId, timer_id: TimerId) {
|
||||||
|
|
||||||
let mut page_tree = self.page_tree.borrow_mut();
|
let mut page_tree = self.page_tree.borrow_mut();
|
||||||
let page = page_tree.find(id).expect("ScriptTask: received fire timer msg for a
|
let page = 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 frame = page.frame();
|
let frame = page.frame();
|
||||||
let mut window = frame.get_ref().window.root();
|
let mut window = frame.get_ref().window.root();
|
||||||
|
|
||||||
|
let this_value = window.deref().reflector().get_jsobject();
|
||||||
|
|
||||||
let is_interval;
|
let is_interval;
|
||||||
match window.get().active_timers.find(&timer_id) {
|
match window.deref().active_timers.find(&timer_id) {
|
||||||
None => return,
|
None => return,
|
||||||
Some(timer_handle) => {
|
Some(timer_handle) => {
|
||||||
let this_value = window.reflector().get_jsobject();
|
|
||||||
|
|
||||||
// TODO: Support extra arguments. This requires passing a `*JSVal` array as `argv`.
|
// TODO: Support extra arguments. This requires passing a `*JSVal` array as `argv`.
|
||||||
let rval = NullValue();
|
let rval = NullValue();
|
||||||
let js_info = page.js_info();
|
let js_info = page.js_info();
|
||||||
|
@ -785,7 +784,7 @@ impl ScriptTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !is_interval {
|
if !is_interval {
|
||||||
window.get_mut().active_timers.remove(&timer_id);
|
window.deref_mut().active_timers.remove(&timer_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -874,7 +873,6 @@ impl ScriptTask {
|
||||||
fn load(&self, pipeline_id: PipelineId, url: Url) {
|
fn load(&self, pipeline_id: PipelineId, url: Url) {
|
||||||
debug!("ScriptTask: loading {:?} on page {:?}", url, pipeline_id);
|
debug!("ScriptTask: loading {:?} on page {:?}", url, pipeline_id);
|
||||||
|
|
||||||
|
|
||||||
let mut page_tree = self.page_tree.borrow_mut();
|
let mut page_tree = self.page_tree.borrow_mut();
|
||||||
let page_tree = page_tree.find(pipeline_id).expect("ScriptTask: received a load
|
let page_tree = page_tree.find(pipeline_id).expect("ScriptTask: received a load
|
||||||
message for a layout channel that is not associated with this script task. This
|
message for a layout channel that is not associated with this script task. This
|
||||||
|
@ -903,7 +901,7 @@ impl ScriptTask {
|
||||||
self.image_cache_task.clone()).root();
|
self.image_cache_task.clone()).root();
|
||||||
page.initialize_js_info(cx.clone(), window.reflector().get_jsobject());
|
page.initialize_js_info(cx.clone(), window.reflector().get_jsobject());
|
||||||
let mut document = Document::new(&*window, Some(url.clone()), HTMLDocument, None).root();
|
let mut document = Document::new(&*window, Some(url.clone()), HTMLDocument, None).root();
|
||||||
window.get_mut().init_browser_context(&*document);
|
window.deref_mut().init_browser_context(&*document);
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut js_info = page.mut_js_info();
|
let mut js_info = page.mut_js_info();
|
||||||
|
@ -1118,7 +1116,7 @@ impl ScriptTask {
|
||||||
|
|
||||||
if node.deref().is_element() {
|
if node.deref().is_element() {
|
||||||
let element: &JSRef<Element> = ElementCast::to_ref(&*node).unwrap();
|
let element: &JSRef<Element> = ElementCast::to_ref(&*node).unwrap();
|
||||||
if "a" == element.get().local_name {
|
if "a" == element.deref().local_name {
|
||||||
self.load_url_from_element(page, element)
|
self.load_url_from_element(page, element)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1205,10 +1203,10 @@ impl ScriptTask {
|
||||||
let attr = element.get_attribute(Null, "href");
|
let attr = element.get_attribute(Null, "href");
|
||||||
for href in attr.root().iter() {
|
for href in attr.root().iter() {
|
||||||
debug!("ScriptTask: clicked on link to {:s}", href.Value());
|
debug!("ScriptTask: clicked on link to {:s}", href.Value());
|
||||||
let click_frag = href.get().value_ref().starts_with("#");
|
let click_frag = href.deref().value_ref().starts_with("#");
|
||||||
let base_url = Some(page.get_url());
|
let base_url = Some(page.get_url());
|
||||||
debug!("ScriptTask: current url is {:?}", base_url);
|
debug!("ScriptTask: current url is {:?}", base_url);
|
||||||
let url = parse_url(href.get().value_ref(), base_url);
|
let url = parse_url(href.deref().value_ref(), base_url);
|
||||||
|
|
||||||
if click_frag {
|
if click_frag {
|
||||||
match page.find_fragment_node(url.fragment.unwrap()).root() {
|
match page.find_fragment_node(url.fragment.unwrap()).root() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue