mirror of
https://github.com/servo/servo.git
synced 2025-06-17 04:44:28 +00:00
Generate bindings for HTMLSelectElement.
This commit is contained in:
parent
e26a541eb2
commit
65c993e7e6
9 changed files with 228 additions and 22 deletions
|
@ -597,6 +597,7 @@ addHTMLElement('HTMLParamElement')
|
|||
addHTMLElement('HTMLProgressElement')
|
||||
addHTMLElement('HTMLQuoteElement')
|
||||
addHTMLElement('HTMLScriptElement')
|
||||
addHTMLElement('HTMLSelectElement')
|
||||
addHTMLElement('HTMLSourceElement')
|
||||
addHTMLElement('HTMLSpanElement')
|
||||
addHTMLElement('HTMLStyleElement')
|
||||
|
|
|
@ -92,7 +92,7 @@ class CastableObjectUnwrapper():
|
|||
|
||||
codeOnFailure is the code to run if unwrapping fails.
|
||||
"""
|
||||
def __init__(self, descriptor, source, target, codeOnFailure):
|
||||
def __init__(self, descriptor, source, target, codeOnFailure, isOptional=False):
|
||||
assert descriptor.castable
|
||||
|
||||
self.substitution = { "type" : descriptor.nativeType,
|
||||
|
@ -101,7 +101,8 @@ class CastableObjectUnwrapper():
|
|||
"protoID" : "PrototypeList::id::" + descriptor.name + " as uint",
|
||||
"source" : source,
|
||||
"target" : target,
|
||||
"codeOnFailure" : CGIndenter(CGGeneric(codeOnFailure), 4).define() }
|
||||
"codeOnFailure" : CGIndenter(CGGeneric(codeOnFailure), 4).define(),
|
||||
"unwrapped_val" : "Some(val)" if isOptional else "val" }
|
||||
if descriptor.hasXPConnectImpls:
|
||||
# We don't use xpc_qsUnwrapThis because it will always throw on
|
||||
# unwrap failure, whereas we want to control whether we throw or
|
||||
|
@ -123,7 +124,7 @@ class CastableObjectUnwrapper():
|
|||
def __str__(self):
|
||||
return string.Template(
|
||||
"""match unwrap_object(${source}, ${prototype}, ${depth}) {
|
||||
Ok(val) => ${target} = val,
|
||||
Ok(val) => ${target} = ${unwrapped_val},
|
||||
Err(()) => {
|
||||
${codeOnFailure}
|
||||
}
|
||||
|
@ -141,10 +142,11 @@ class FailureFatalCastableObjectUnwrapper(CastableObjectUnwrapper):
|
|||
"""
|
||||
As CastableObjectUnwrapper, but defaulting to throwing if unwrapping fails
|
||||
"""
|
||||
def __init__(self, descriptor, source, target):
|
||||
def __init__(self, descriptor, source, target, isOptional):
|
||||
CastableObjectUnwrapper.__init__(self, descriptor, source, target,
|
||||
"return 0; //XXXjdm return Throw<%s>(cx, rv);" %
|
||||
toStringBool(not descriptor.workers))
|
||||
toStringBool(not descriptor.workers),
|
||||
isOptional)
|
||||
|
||||
class CGThing():
|
||||
"""
|
||||
|
@ -229,9 +231,10 @@ class CGMethodCall(CGThing):
|
|||
argCountCases.append(
|
||||
CGCase(str(argCount), None, True))
|
||||
else:
|
||||
pass
|
||||
sigIndex = signatures.index(signature)
|
||||
argCountCases.append(
|
||||
CGCase(str(argCount), getPerSignatureCall(signature)))
|
||||
CGCase(str(argCount), getPerSignatureCall(signature,
|
||||
signatureIndex=sigIndex)))
|
||||
continue
|
||||
|
||||
distinguishingIndex = method.distinguishingIndexForArgCount(argCount)
|
||||
|
@ -302,7 +305,7 @@ class CGMethodCall(CGThing):
|
|||
# above.
|
||||
caseBody.append(CGGeneric("if JSVAL_IS_OBJECT(%s) {" %
|
||||
(distinguishingArg)))
|
||||
for sig in interfacesSigs:
|
||||
for idx, sig in enumerate(interfacesSigs):
|
||||
caseBody.append(CGIndenter(CGGeneric("loop {")));
|
||||
type = sig[1][distinguishingIndex].type
|
||||
|
||||
|
@ -326,7 +329,7 @@ class CGMethodCall(CGThing):
|
|||
# distinguishingIndex + 1, since we already converted
|
||||
# distinguishingIndex.
|
||||
caseBody.append(CGIndenter(
|
||||
getPerSignatureCall(sig, distinguishingIndex + 1), 4))
|
||||
getPerSignatureCall(sig, distinguishingIndex + 1, idx), 4))
|
||||
caseBody.append(CGIndenter(CGGeneric("}")))
|
||||
|
||||
caseBody.append(CGGeneric("}"))
|
||||
|
@ -926,12 +929,14 @@ for (uint32_t i = 0; i < length; ++i) {
|
|||
descriptor,
|
||||
"JSVAL_TO_OBJECT(${val})",
|
||||
"${declName}",
|
||||
failureCode))
|
||||
failureCode,
|
||||
isOptional or argIsPointer or type.nullable()))
|
||||
else:
|
||||
templateBody += str(FailureFatalCastableObjectUnwrapper(
|
||||
descriptor,
|
||||
"JSVAL_TO_OBJECT(${val})",
|
||||
"${declName}"))
|
||||
"${declName}",
|
||||
isOptional or argIsPointer or type.nullable()))
|
||||
elif descriptor.interface.isCallback() and False:
|
||||
#XXXjdm unfinished
|
||||
templateBody += str(CallbackObjectUnwrapper(
|
||||
|
@ -3532,8 +3537,8 @@ class CGProxySpecialOperation(CGPerSignatureCall):
|
|||
templateValues = {
|
||||
"declName": argument.identifier.name,
|
||||
"holderName": argument.identifier.name + "_holder",
|
||||
"val": "desc->value",
|
||||
"valPtr": "&desc->value"
|
||||
"val": "(*desc).value",
|
||||
"valPtr": "&(*desc).value"
|
||||
}
|
||||
self.cgRoot.prepend(instantiateJSToNativeConversionTemplate(template, templateValues))
|
||||
elif operation.isGetter():
|
||||
|
@ -3636,7 +3641,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
|
|||
if not 'IndexedCreator' in self.descriptor.operations:
|
||||
# FIXME need to check that this is a 'supported property index'
|
||||
assert False
|
||||
setOrIndexedGet += (" FillPropertyDescriptor(&mut *desc, proxy, JSVAL_VOID, false);\n" +
|
||||
setOrIndexedGet += (" FillPropertyDescriptor(&mut *desc, proxy, false);\n" +
|
||||
" return 1;\n" +
|
||||
" }\n")
|
||||
if self.descriptor.operations['NamedSetter']:
|
||||
|
@ -3644,7 +3649,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
|
|||
if not 'NamedCreator' in self.descriptor.operations:
|
||||
# FIXME need to check that this is a 'supported property name'
|
||||
assert False
|
||||
setOrIndexedGet += (" FillPropertyDescriptor(&mut *desc, proxy, JSVAL_VOID, false);\n" +
|
||||
setOrIndexedGet += (" FillPropertyDescriptor(&mut *desc, proxy, false);\n" +
|
||||
" return 1;\n" +
|
||||
" }\n")
|
||||
setOrIndexedGet += "}"
|
||||
|
@ -3710,7 +3715,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
|
|||
args = [Argument('*JSContext', 'cx'), Argument('*JSObject', 'proxy'),
|
||||
Argument('jsid', 'id'),
|
||||
Argument('*JSPropertyDescriptor', 'desc')]
|
||||
CGAbstractExternMethod.__init__(self, descriptor, "defineProperty", "bool", args)
|
||||
CGAbstractExternMethod.__init__(self, descriptor, "defineProperty", "JSBool", args)
|
||||
self.descriptor = descriptor
|
||||
def getBody(self):
|
||||
set = ""
|
||||
|
@ -3722,10 +3727,10 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
|
|||
set += ("let index = GetArrayIndexFromId(cx, id);\n" +
|
||||
"if index.is_some() {\n" +
|
||||
" let index = index.unwrap();\n" +
|
||||
" let this: *%s = UnwrapProxy(proxy);\n" +
|
||||
" let this: *mut %s = UnwrapProxy(proxy) as *mut %s;\n" +
|
||||
CGIndenter(CGProxyIndexedSetter(self.descriptor)).define() +
|
||||
" return 1;\n" +
|
||||
"}\n") % (self.descriptor.concreteType)
|
||||
"}\n") % (self.descriptor.concreteType, self.descriptor.concreteType)
|
||||
elif self.descriptor.operations['IndexedGetter']:
|
||||
set += ("if GetArrayIndexFromId(cx, id).is_some() {\n" +
|
||||
" return 0;\n" +
|
||||
|
@ -3771,7 +3776,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
|
|||
" }\n" +
|
||||
" return 1;\n"
|
||||
"}\n") % (self.descriptor.concreteType, self.descriptor.name)
|
||||
return set + """return proxyhandler::defineProperty(%s);""" % ", ".join(a.name for a in self.args)
|
||||
return set + """return proxyhandler::defineProperty_(%s);""" % ", ".join(a.name for a in self.args)
|
||||
|
||||
def definition_body(self):
|
||||
return self.getBody()
|
||||
|
@ -4618,6 +4623,7 @@ class CGBindingRoot(CGThing):
|
|||
'dom::bindings::codegen::*', #XXXjdm
|
||||
'script_task::{JSPageInfo, page_from_context}',
|
||||
'dom::bindings::utils::EnumEntry',
|
||||
'dom::bindings::proxyhandler',
|
||||
'dom::bindings::proxyhandler::*',
|
||||
'dom::document::AbstractDocument',
|
||||
'dom::node::{AbstractNode, ScriptView}',
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* The origin of this IDL file is
|
||||
* http://www.whatwg.org/html/#the-select-element
|
||||
*/
|
||||
|
||||
interface HTMLSelectElement : HTMLElement {
|
||||
[SetterThrows, Pure]
|
||||
attribute boolean autofocus;
|
||||
[SetterThrows, Pure]
|
||||
attribute boolean disabled;
|
||||
[Pure]
|
||||
readonly attribute HTMLFormElement? form;
|
||||
[SetterThrows, Pure]
|
||||
attribute boolean multiple;
|
||||
[SetterThrows, Pure]
|
||||
attribute DOMString name;
|
||||
[SetterThrows, Pure]
|
||||
attribute boolean required;
|
||||
[SetterThrows, Pure]
|
||||
attribute unsigned long size;
|
||||
|
||||
[Pure]
|
||||
readonly attribute DOMString type;
|
||||
|
||||
/*[Constant]
|
||||
readonly attribute HTMLOptionsCollection options;*/
|
||||
[SetterThrows, Pure]
|
||||
attribute unsigned long length;
|
||||
getter Element? item(unsigned long index);
|
||||
HTMLOptionElement? namedItem(DOMString name);
|
||||
/*[Throws]
|
||||
void add((HTMLOptionElement or HTMLOptGroupElement) element, optional (HTMLElement or long)? before = null);*/
|
||||
void remove(long index);
|
||||
[Throws]
|
||||
setter creator void (unsigned long index, HTMLOptionElement? option);
|
||||
|
||||
// NYI: readonly attribute HTMLCollection selectedOptions;
|
||||
[SetterThrows, Pure]
|
||||
attribute long selectedIndex;
|
||||
[Pure]
|
||||
attribute DOMString value;
|
||||
|
||||
readonly attribute boolean willValidate;
|
||||
readonly attribute ValidityState validity;
|
||||
readonly attribute DOMString validationMessage;
|
||||
boolean checkValidity();
|
||||
void setCustomValidity(DOMString error);
|
||||
|
||||
// NYI: readonly attribute NodeList labels;
|
||||
|
||||
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=20720
|
||||
void remove();
|
||||
};
|
|
@ -417,6 +417,8 @@ generate_cacheable_wrapper!(HTMLQuoteElement, HTMLQuoteElementBinding::Wrap)
|
|||
generate_binding_object!(HTMLQuoteElement)
|
||||
generate_cacheable_wrapper!(HTMLScriptElement, HTMLScriptElementBinding::Wrap)
|
||||
generate_binding_object!(HTMLScriptElement)
|
||||
generate_cacheable_wrapper!(HTMLSelectElement, HTMLSelectElementBinding::Wrap)
|
||||
generate_binding_object!(HTMLSelectElement)
|
||||
generate_cacheable_wrapper!(HTMLSourceElement, HTMLSourceElementBinding::Wrap)
|
||||
generate_binding_object!(HTMLSourceElement)
|
||||
generate_cacheable_wrapper!(HTMLSpanElement, HTMLSpanElementBinding::Wrap)
|
||||
|
|
|
@ -114,6 +114,7 @@ pub fn create(cx: *JSContext, node: &mut AbstractNode<ScriptView>) -> *JSObject
|
|||
ElementNodeTypeId(HTMLProgressElementTypeId) => generate_element!(HTMLProgressElement),
|
||||
ElementNodeTypeId(HTMLQuoteElementTypeId) => generate_element!(HTMLQuoteElement),
|
||||
ElementNodeTypeId(HTMLScriptElementTypeId) => generate_element!(HTMLScriptElement),
|
||||
ElementNodeTypeId(HTMLSelectElementTypeId) => generate_element!(HTMLSelectElement),
|
||||
ElementNodeTypeId(HTMLSourceElementTypeId) => generate_element!(HTMLSourceElement),
|
||||
ElementNodeTypeId(HTMLSpanElementTypeId) => generate_element!(HTMLSpanElement),
|
||||
ElementNodeTypeId(HTMLStyleElementTypeId) => generate_element!(HTMLStyleElement),
|
||||
|
|
|
@ -44,7 +44,7 @@ pub extern fn getPropertyDescriptor(cx: *JSContext, proxy: *JSObject, id: jsid,
|
|||
}
|
||||
}
|
||||
|
||||
pub extern fn defineProperty(cx: *JSContext, proxy: *JSObject, id: jsid,
|
||||
pub fn defineProperty_(cx: *JSContext, proxy: *JSObject, id: jsid,
|
||||
desc: *JSPropertyDescriptor) -> JSBool {
|
||||
unsafe {
|
||||
if ((*desc).attrs & JSPROP_GETTER) != 0 && (*desc).setter == JS_StrictPropertyStub {
|
||||
|
@ -66,6 +66,11 @@ pub extern fn defineProperty(cx: *JSContext, proxy: *JSObject, id: jsid,
|
|||
}
|
||||
}
|
||||
|
||||
pub extern fn defineProperty(cx: *JSContext, proxy: *JSObject, id: jsid,
|
||||
desc: *JSPropertyDescriptor) -> JSBool {
|
||||
defineProperty_(cx, proxy, id, desc)
|
||||
}
|
||||
|
||||
pub fn _obj_toString(cx: *JSContext, className: *libc::c_char) -> *JSString {
|
||||
unsafe {
|
||||
let name = str::raw::from_c_str(className);
|
||||
|
|
|
@ -112,7 +112,6 @@ pub enum ElementTypeId {
|
|||
// Regular old elements
|
||||
//
|
||||
|
||||
pub struct HTMLSelectElement { parent: HTMLElement }
|
||||
pub struct HTMLSmallElement { parent: HTMLElement }
|
||||
pub struct UnknownElement { parent: HTMLElement }
|
||||
|
||||
|
|
134
src/components/script/dom/htmlselectelement.rs
Normal file
134
src/components/script/dom/htmlselectelement.rs
Normal file
|
@ -0,0 +1,134 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::bindings::utils::{DOMString, ErrorResult, null_string};
|
||||
use dom::htmlelement::HTMLElement;
|
||||
use dom::node::{AbstractNode, ScriptView};
|
||||
use dom::validitystate::ValidityState;
|
||||
|
||||
pub struct HTMLSelectElement {
|
||||
parent: HTMLElement
|
||||
}
|
||||
|
||||
impl HTMLSelectElement {
|
||||
pub fn Autofocus(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
pub fn SetAutofocus(&mut self, _autofocus: bool, _rv: &mut ErrorResult) {
|
||||
}
|
||||
|
||||
pub fn Disabled(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
pub fn SetDisabled(&mut self, _disabled: bool, _rv: &mut ErrorResult) {
|
||||
}
|
||||
|
||||
pub fn GetForm(&self) -> Option<AbstractNode<ScriptView>> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn Multiple(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
pub fn SetMultiple(&mut self, _multiple: bool, _rv: &mut ErrorResult) {
|
||||
}
|
||||
|
||||
pub fn Name(&self) -> DOMString {
|
||||
null_string
|
||||
}
|
||||
|
||||
pub fn SetName(&mut self, _name: &DOMString, _rv: &mut ErrorResult) {
|
||||
}
|
||||
|
||||
pub fn Required(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
pub fn SetRequired(&mut self, _multiple: bool, _rv: &mut ErrorResult) {
|
||||
}
|
||||
|
||||
pub fn Size(&self) -> u32 {
|
||||
0
|
||||
}
|
||||
|
||||
pub fn SetSize(&mut self, _size: u32, _rv: &mut ErrorResult) {
|
||||
}
|
||||
|
||||
pub fn Type(&self) -> DOMString {
|
||||
null_string
|
||||
}
|
||||
|
||||
pub fn Length(&self) -> u32 {
|
||||
0
|
||||
}
|
||||
|
||||
pub fn SetLength(&mut self, _length: u32, _rv: &mut ErrorResult) {
|
||||
}
|
||||
|
||||
pub fn Item(&self, _index: u32) -> Option<AbstractNode<ScriptView>> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn NamedItem(&self, _name: &DOMString) -> Option<AbstractNode<ScriptView>> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Option<AbstractNode<ScriptView>> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn IndexedSetter(&mut self, _index: u32, _option: Option<AbstractNode<ScriptView>>, _rv: &mut ErrorResult) {
|
||||
}
|
||||
|
||||
pub fn Remove_(&self) {
|
||||
}
|
||||
|
||||
pub fn Remove(&self, _index: i32) {
|
||||
}
|
||||
|
||||
pub fn SelectedIndex(&self) -> i32 {
|
||||
0
|
||||
}
|
||||
|
||||
pub fn SetSelectedIndex(&mut self, _index: i32, _rv: &mut ErrorResult) {
|
||||
}
|
||||
|
||||
pub fn Value(&self) -> DOMString {
|
||||
null_string
|
||||
}
|
||||
|
||||
pub fn SetValue(&mut self, _value: &DOMString) {
|
||||
}
|
||||
|
||||
pub fn WillValidate(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
pub fn SetWillValidate(&mut self, _will_validate: bool) {
|
||||
}
|
||||
|
||||
pub fn Validity(&self) -> @mut ValidityState {
|
||||
@mut ValidityState::valid()
|
||||
}
|
||||
|
||||
pub fn SetValidity(&mut self, _validity: @mut ValidityState) {
|
||||
}
|
||||
|
||||
pub fn ValidationMessage(&self) -> DOMString {
|
||||
null_string
|
||||
}
|
||||
|
||||
pub fn SetValidationMessage(&mut self, _message: &DOMString, _rv: &mut ErrorResult) {
|
||||
}
|
||||
|
||||
pub fn CheckValidity(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
pub fn SetCustomValidity(&mut self, _error: &DOMString) {
|
||||
}
|
||||
}
|
|
@ -99,6 +99,7 @@ pub mod dom {
|
|||
pub mod htmlprogresselement;
|
||||
pub mod htmlquoteelement;
|
||||
pub mod htmlscriptelement;
|
||||
pub mod htmlselectelement;
|
||||
pub mod htmlspanelement;
|
||||
pub mod htmlsourceelement;
|
||||
pub mod htmlstyleelement;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue