Generate DOM bindings for UIEvent and MouseEvent.

This commit is contained in:
Josh Matthews 2013-07-10 16:41:08 -04:00
parent 8787c1ac1f
commit 65f9aefb78
12 changed files with 601 additions and 22 deletions

View file

@ -256,6 +256,9 @@ DOMInterfaces = {
'workers': True,
}],
'MouseEvent': {
},
'NodeList': [
{
'nativeType': 'nsINodeList',
@ -333,6 +336,9 @@ DOMInterfaces = {
'resultNotAddRefed': [ 'getItem' ]
}],
'UIEvent': {
},
'WebGLRenderingContext': {
'nativeType': 'mozilla::WebGLContext',
'headerFile': 'WebGLContext.h',
@ -499,7 +505,7 @@ def addExternalIface(iface, nativeType=None, headerFile=None, pointerType=None):
# If you add one of these, you need to make sure nsDOMQS.h has the relevant
# macros added for it
def addExternalHTMLElement(element):
nativeElement = 'ns' + element
nativeElement = element
addExternalIface(element, nativeType=nativeElement,
headerFile=nativeElement + '.h')
@ -520,7 +526,7 @@ addExternalIface('File')
addExternalIface('HitRegionOptions', nativeType='nsISupports')
addExternalIface('HTMLElement')
addExternalIface('ImageData', nativeType='mozilla::dom::ImageData')
addExternalIface('Node', nativeType='nsINode')
addExternalIface('Node', nativeType='AbstractNode<ScriptView>', pointerType='')
addExternalIface('PaintRequest')
addExternalIface('SVGLength')
addExternalIface('SVGMatrix')
@ -552,4 +558,5 @@ addExternalIface('WebGLShaderPrecisionFormat',
addExternalIface('WebGLTexture', nativeType='mozilla::WebGLTexture',
headerFile='WebGLContext.h')
addExternalIface('Window')
addExternalIface('WindowProxy', nativeType='WindowProxy')
addExternalIface('XULElement')

View file

@ -558,7 +558,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
CGIndenter(CGGeneric(templateBody)).define() + "\n")
if type.nullable():
templateBody += (
"} else if (${val}.isNullOrUndefined()) {\n"
"} else if RUST_JSVAL_IS_NULL(${val}) != 0 || RUST_JSVAL_IS_VOID(${val}) != 0 {\n"
" %s;\n" % codeToSetNull)
templateBody += (
"} else {\n" +
@ -893,7 +893,7 @@ for (uint32_t i = 0; i < length; ++i) {
not descriptor.workers) or isMember
typeName = descriptor.nativeType
typePtr = typeName + "*"
typePtr = descriptor.pointerType + typeName
# Compute a few things:
# - declType is the type we want to return as the first element of our
@ -904,15 +904,9 @@ for (uint32_t i = 0; i < length; ++i) {
# Set up some sensible defaults for these things insofar as we can.
holderType = None
if argIsPointer:
if forceOwningType:
declType = "nsRefPtr<" + typeName + ">"
else:
declType = typePtr
declType = "Option<" + typePtr + ">"
else:
if forceOwningType:
declType = "OwningNonNull<" + typeName + ">"
else:
declType = descriptor.pointerType + typeName
declType = typePtr
templateBody = ""
if descriptor.castable:
@ -1298,10 +1292,15 @@ def instantiateJSToNativeConversionTemplate(templateTuple, replacements,
(holderType.define(), originalHolderName))
mutableHolderType = CGWrapper(holderType, pre="Optional< ", post=" >")
holderType = CGWrapper(mutableHolderType, pre="const ")
result.append(
CGList([holderType, CGGeneric(" "),
CGGeneric(originalHolderName),
CGGeneric(";")]))
tmpresult = [CGGeneric("let "),
CGGeneric(originalHolderName),
CGGeneric(": "),
holderType]
if initialValue:
tmpresult += [CGGeneric(" = "),
initialValue]
tmpresult += [CGGeneric(";")]
result.append(CGList(tmpresult))
originalDeclName = replacements["declName"]
if declType is not None:
@ -4034,11 +4033,11 @@ class CGDictionary(CGThing):
def defaultValue(ty):
if ty is "bool":
return "false"
elif ty in ["i32", "u32"]:
elif ty in ["i32", "u32", "i16", "u16"]:
return "0"
elif ty is "nsString":
return "\"\""
elif ty.startswith("Optional"):
elif ty.startswith("Option"):
return "None"
else:
return "/* uh oh: %s */" % ty
@ -4283,6 +4282,10 @@ class CGBindingRoot(CGThing):
'dom::event::*', #XXXjdm
'dom::eventtarget::*', #XXXjdm
'dom::formdata::*', #XXXjdm
'dom::mouseevent::*', #XXXjdm
'dom::uievent::*', #XXXjdm
'dom::windowproxy::*', #XXXjdm
'dom::bindings::codegen::*', #XXXjdm
'script_task::task_from_context',
'dom::bindings::utils::EnumEntry',
'dom::node::ScriptView',

View file

@ -0,0 +1,76 @@
/* -*- 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/.
*
* For more information on this interface please see
* http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html
*
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
* liability, trademark and document use rules apply.
*/
interface MouseEvent : UIEvent {
readonly attribute long screenX;
readonly attribute long screenY;
readonly attribute long clientX;
readonly attribute long clientY;
readonly attribute boolean ctrlKey;
readonly attribute boolean shiftKey;
readonly attribute boolean altKey;
readonly attribute boolean metaKey;
readonly attribute unsigned short button;
readonly attribute unsigned short buttons;
readonly attribute EventTarget? relatedTarget;
// Deprecated in DOM Level 3:
[Throws]
void initMouseEvent(DOMString typeArg,
boolean canBubbleArg,
boolean cancelableArg,
WindowProxy? viewArg,
long detailArg,
long screenXArg,
long screenYArg,
long clientXArg,
long clientYArg,
boolean ctrlKeyArg,
boolean altKeyArg,
boolean shiftKeyArg,
boolean metaKeyArg,
unsigned short buttonArg,
EventTarget? relatedTargetArg);
// Introduced in DOM Level 3:
boolean getModifierState(DOMString keyArg);
};
// Event Constructor Syntax:
[Constructor(DOMString typeArg, optional MouseEventInit mouseEventInitDict)]
partial interface MouseEvent
{
};
// Suggested initMouseEvent replacement initializer:
dictionary MouseEventInit {
// Attributes from Event:
boolean bubbles = false;
boolean cancelable = false;
// Attributes from UIEvent:
WindowProxy? view = null;
long detail = 0;
// Attributes for MouseEvent:
long screenX = 0;
long screenY = 0;
long clientX = 0;
long clientY = 0;
boolean ctrlKey = false;
boolean shiftKey = false;
boolean altKey = false;
boolean metaKey = false;
unsigned short button = 0;
// Note: "buttons" was not previously initializable through initMouseEvent!
unsigned short buttons = 0;
EventTarget? relatedTarget = null;
};

View file

@ -0,0 +1,48 @@
/* -*- 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/.
*
* For more information on this interface please see
* http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html
*
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
* liability, trademark and document use rules apply.
*/
interface WindowProxy;
interface Node;
[Constructor(DOMString type, optional UIEventInit eventInitDict)]
interface UIEvent : Event
{
readonly attribute WindowProxy? view;
readonly attribute long detail;
void initUIEvent(DOMString aType,
boolean aCanBubble,
boolean aCancelable,
WindowProxy? aView,
long aDetail);
};
// Additional DOM0 properties.
partial interface UIEvent {
const long SCROLL_PAGE_UP = -32768;
const long SCROLL_PAGE_DOWN = 32768;
readonly attribute long layerX;
readonly attribute long layerY;
readonly attribute long pageX;
readonly attribute long pageY;
readonly attribute unsigned long which;
readonly attribute Node? rangeParent;
readonly attribute long rangeOffset;
attribute boolean cancelBubble;
readonly attribute boolean isChar;
};
dictionary UIEventInit : EventInit
{
WindowProxy? view = null;
long detail = 0;
};