Bug 856373 - WebIDL-ify Gamepad events r=smaug

This commit is contained in:
David Zbarsky 2013-09-11 18:35:51 -04:00
parent 84f303b8c3
commit 5e12eb5de7
11 changed files with 79 additions and 156 deletions

View File

@ -10743,12 +10743,15 @@ class CGEventMethod(CGNativeMember):
self.args = list(self.originalArgs)
members = ""
holdJS = ""
for m in self.descriptorProvider.interface.members:
if m.isAttr():
name = CGDictionary.makeMemberName(m.identifier.name)
members += "e->%s = %s.%s;\n" % (name, self.args[1].name, name)
if m.type.isAny() or m.type.isObject() or m.type.isSpiderMonkeyInterface():
holdJS = "mozilla::HoldJSObjects(e.get());\n"
iface = self.descriptorProvider.interface
while iface.identifier.name != "Event":
for m in self.descriptorProvider.getDescriptor(iface.identifier.name).interface.members:
if m.isAttr():
name = CGDictionary.makeMemberName(m.identifier.name)
members += "e->%s = %s.%s;\n" % (name, self.args[1].name, name)
if m.type.isAny() or m.type.isObject() or m.type.isSpiderMonkeyInterface():
holdJS = "mozilla::HoldJSObjects(e.get());\n"
iface = iface.parent
self.body = (
"nsRefPtr<${nativeType}> e = new ${nativeType}(aOwner);\n"
@ -10824,21 +10827,24 @@ class CGEventClass(CGBindingImplClass):
visibility="private",
body="body"))
parent = self.descriptor.interface.parent
self.parentType = self.descriptor.getDescriptor(parent.identifier.name).nativeType.split('::')[-1]
baseDeclarations=(
"public:\n"
" NS_DECL_ISUPPORTS_INHERITED\n"
" NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(${nativeType}, nsDOMEvent)\n"
" NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(${nativeType}, ${parentType})\n"
" virtual ~${nativeType}();\n"
"protected:\n"
" ${nativeType}(mozilla::dom::EventTarget* aOwner);\n\n")
baseDeclarations = string.Template(baseDeclarations).substitute(
{
"nativeType": self.descriptor.nativeType.split('::')[-1]
"nativeType": self.descriptor.nativeType.split('::')[-1],
"parentType": self.parentType
})
CGClass.__init__(self, descriptor.nativeType.split('::')[-1],
bases=[ClassBase("nsDOMEvent")],
bases=[ClassBase(self.parentType)],
methods=self.methodDecls,
members=members,
extradeclarations=baseDeclarations)
@ -10891,26 +10897,29 @@ class CGEventClass(CGBindingImplClass):
if dropJS != "":
dropJS += " mozilla::DropJSObjects(this);\n"
# Just override CGClass and do our own thing
nativeType = self.descriptor.nativeType.split('::')[-1]
ctorParams = ("aOwner, nullptr, nullptr" if self.parentType == "nsDOMEvent"
else "aOwner")
classImpl = """
NS_IMPL_CYCLE_COLLECTION_CLASS(${nativeType})
NS_IMPL_ADDREF_INHERITED(${nativeType}, nsDOMEvent)
NS_IMPL_RELEASE_INHERITED(${nativeType}, nsDOMEvent)
NS_IMPL_ADDREF_INHERITED(${nativeType}, ${parentType})
NS_IMPL_RELEASE_INHERITED(${nativeType}, ${parentType})
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(${nativeType}, nsDOMEvent)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(${nativeType}, ${parentType})
${traverse}NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(${nativeType}, nsDOMEvent)
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(${nativeType}, ${parentType})
${trace}NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(${nativeType}, nsDOMEvent)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(${nativeType}, ${parentType})
${unlink}NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(${nativeType})
NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
NS_INTERFACE_MAP_END_INHERITING(${parentType})
${nativeType}::${nativeType}(mozilla::dom::EventTarget* aOwner)
: nsDOMEvent(aOwner, nullptr, nullptr)
: ${parentType}(${ctorParams})
{
}
@ -10921,7 +10930,9 @@ ${dropJS}}
"""
return string.Template(classImpl).substitute(
{ "ifaceName": self.descriptor.name,
"nativeType": self.descriptor.nativeType.split('::')[-1],
"nativeType": nativeType,
"ctorParams": ctorParams,
"parentType": self.parentType,
"traverse": self.implTraverse(),
"unlink": self.implUnlink(),
"trace": self.implTrace(),
@ -10942,9 +10953,11 @@ class CGEventRoot(CGThing):
self.root = CGList([CGClassForwardDeclare("JSContext", isStruct=True),
self.root], "\n")
parent = descriptor.interface.parent.identifier.name
# Throw in our #includes
self.root = CGHeaders([descriptor], [], [], [],
[ "nsDOMEvent.h",
[ config.getDescriptor(parent, False).headerFile,
"mozilla/Attributes.h",
"mozilla/ErrorResult.h" ,
"mozilla/dom/%sBinding.h" % interfaceName,

View File

@ -12,9 +12,6 @@
#include "nsAutoPtr.h"
#include "nsIDOMEvent.h"
#include "nsIDOMDocument.h"
#include "nsIDOMGamepadButtonEvent.h"
#include "nsIDOMGamepadAxisMoveEvent.h"
#include "nsIDOMGamepadEvent.h"
#include "GeneratedEvents.h"
#include "nsIDOMWindow.h"
#include "nsIObserver.h"
@ -24,6 +21,10 @@
#include "nsThreadUtils.h"
#include "mozilla/Services.h"
#include "mozilla/dom/GamepadAxisMoveEvent.h"
#include "mozilla/dom/GamepadButtonEvent.h"
#include "mozilla/dom/GamepadEvent.h"
#include <cstddef>
namespace mozilla {
@ -241,18 +242,19 @@ GamepadService::FireButtonEvent(EventTarget* aTarget,
uint32_t aButton,
double aValue)
{
nsCOMPtr<nsIDOMEvent> event;
bool defaultActionEnabled = true;
NS_NewDOMGamepadButtonEvent(getter_AddRefs(event), aTarget, nullptr, nullptr);
nsCOMPtr<nsIDOMGamepadButtonEvent> je = do_QueryInterface(event);
MOZ_ASSERT(je, "QI should not fail");
nsString name = aValue == 1.0L ? NS_LITERAL_STRING("gamepadbuttondown") :
NS_LITERAL_STRING("gamepadbuttonup");
je->InitGamepadButtonEvent(name, false, false, aGamepad, aButton);
je->SetTrusted(true);
GamepadButtonEventInitInitializer init;
init.mBubbles = false;
init.mCancelable = false;
init.mGamepad = aGamepad;
init.mButton = aButton;
nsRefPtr<GamepadButtonEvent> event =
GamepadButtonEvent::Constructor(aTarget, name, init);
event->SetTrusted(true);
bool defaultActionEnabled = true;
aTarget->DispatchEvent(event, &defaultActionEnabled);
}
@ -305,17 +307,20 @@ GamepadService::FireAxisMoveEvent(EventTarget* aTarget,
uint32_t aAxis,
double aValue)
{
nsCOMPtr<nsIDOMEvent> event;
GamepadAxisMoveEventInitInitializer init;
init.mBubbles = false;
init.mCancelable = false;
init.mGamepad = aGamepad;
init.mAxis = aAxis;
init.mValue = aValue;
nsRefPtr<GamepadAxisMoveEvent> event =
GamepadAxisMoveEvent::Constructor(aTarget,
NS_LITERAL_STRING("gamepadaxismove"),
init);
event->SetTrusted(true);
bool defaultActionEnabled = true;
NS_NewDOMGamepadAxisMoveEvent(getter_AddRefs(event), aTarget, nullptr,
nullptr);
nsCOMPtr<nsIDOMGamepadAxisMoveEvent> je = do_QueryInterface(event);
MOZ_ASSERT(je, "QI should not fail");
je->InitGamepadAxisMoveEvent(NS_LITERAL_STRING("gamepadaxismove"),
false, false, aGamepad, aAxis, aValue);
je->SetTrusted(true);
aTarget->DispatchEvent(event, &defaultActionEnabled);
}
@ -381,17 +386,18 @@ GamepadService::FireConnectionEvent(EventTarget* aTarget,
Gamepad* aGamepad,
bool aConnected)
{
nsCOMPtr<nsIDOMEvent> event;
bool defaultActionEnabled = true;
NS_NewDOMGamepadEvent(getter_AddRefs(event), aTarget, nullptr, nullptr);
nsCOMPtr<nsIDOMGamepadEvent> je = do_QueryInterface(event);
MOZ_ASSERT(je, "QI should not fail");
nsString name = aConnected ? NS_LITERAL_STRING("gamepadconnected") :
NS_LITERAL_STRING("gamepaddisconnected");
je->InitGamepadEvent(name, false, false, aGamepad);
je->SetTrusted(true);
GamepadEventInitInitializer init;
init.mBubbles = false;
init.mCancelable = false;
init.mGamepad = aGamepad;
nsRefPtr<GamepadEvent> event =
GamepadEvent::Constructor(aTarget, name, init);
event->SetTrusted(true);
bool defaultActionEnabled = true;
aTarget->DispatchEvent(event, &defaultActionEnabled);
}

View File

@ -24,9 +24,6 @@ XPIDL_SOURCES += [
'nsIDOMEventListener.idl',
'nsIDOMEventTarget.idl',
'nsIDOMFocusEvent.idl',
'nsIDOMGamepadAxisMoveEvent.idl',
'nsIDOMGamepadButtonEvent.idl',
'nsIDOMGamepadEvent.idl',
'nsIDOMHashChangeEvent.idl',
'nsIDOMKeyEvent.idl',
'nsIDOMMessageEvent.idl',

View File

@ -1,33 +0,0 @@
/* 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/. */
#include "nsIDOMGamepadEvent.idl"
[builtinclass, scriptable, uuid(bd09eef8-8e07-4baf-8d39-4f92003dbca8)]
interface nsIDOMGamepadAxisMoveEvent : nsIDOMGamepadEvent
{
/**
* Index in gamepad.axes of the axis that was moved.
*/
readonly attribute unsigned long axis;
/**
* Position of the axis in the range -1.0...1.0.
*/
readonly attribute double value;
[noscript]
void initGamepadAxisMoveEvent(in DOMString typeArg,
in boolean canBubbleArg,
in boolean cancelableArg,
in nsIDOMGamepad gamepad,
in unsigned long axis,
in double value);
};
dictionary GamepadAxisMoveEventInit : GamepadEventInit
{
unsigned long axis;
double value;
};

View File

@ -1,26 +0,0 @@
/* 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/. */
#include "nsIDOMGamepadEvent.idl"
[builtinclass, scriptable, uuid(d75d4d2b-e7b4-4b93-ac35-2e70b57d9b28)]
interface nsIDOMGamepadButtonEvent : nsIDOMGamepadEvent
{
/**
* Index in gamepad.buttons of the button that was pressed or released.
*/
readonly attribute unsigned long button;
[noscript]
void initGamepadButtonEvent(in DOMString typeArg,
in boolean canBubbleArg,
in boolean cancelableArg,
in nsIDOMGamepad gamepad,
in unsigned long button);
};
dictionary GamepadButtonEventInit : GamepadEventInit
{
unsigned long button;
};

View File

@ -1,27 +0,0 @@
/* 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/. */
#include "nsIDOMEvent.idl"
interface nsIDOMGamepad;
[builtinclass, scriptable, uuid(93b048d6-2aef-46a9-b0f4-06d7f00d8ef2)]
interface nsIDOMGamepadEvent : nsIDOMEvent
{
/**
* The device that generated this event.
*/
readonly attribute nsIDOMGamepad gamepad;
[noscript]
void initGamepadEvent(in DOMString typeArg,
in boolean canBubbleArg,
in boolean cancelableArg,
in nsIDOMGamepad gamepad);
};
dictionary GamepadEventInit : EventInit
{
nsIDOMGamepad gamepad;
};

View File

@ -5,8 +5,7 @@
*/
[Pref="dom.gamepad.non_standard_events.enabled",
Constructor(DOMString type, optional GamepadAxisMoveEventInit eventInitDict),
HeaderFile="GeneratedEventClasses.h"]
Constructor(DOMString type, optional GamepadAxisMoveEventInit eventInitDict)]
interface GamepadAxisMoveEvent : GamepadEvent
{
readonly attribute unsigned long axis;

View File

@ -5,8 +5,7 @@
*/
[Pref="dom.gamepad.non_standard_events.enabled",
Constructor(DOMString type, optional GamepadButtonEventInit eventInitDict),
HeaderFile="GeneratedEventClasses.h"]
Constructor(DOMString type, optional GamepadButtonEventInit eventInitDict)]
interface GamepadButtonEvent : GamepadEvent
{
readonly attribute unsigned long button;

View File

@ -5,8 +5,7 @@
*/
[Pref="dom.gamepad.enabled",
Constructor(DOMString type, optional GamepadEventInit eventInitDict),
HeaderFile="GeneratedEventClasses.h"]
Constructor(DOMString type, optional GamepadEventInit eventInitDict)]
interface GamepadEvent : Event
{
readonly attribute Gamepad? gamepad;

View File

@ -506,13 +506,6 @@ if CONFIG['MOZ_B2G_RIL']:
'USSDReceivedEvent.webidl',
]
if CONFIG['MOZ_GAMEPAD']:
WEBIDL_FILES += [
'GamepadAxisMoveEvent.webidl',
'GamepadButtonEvent.webidl',
'GamepadEvent.webidl',
]
if CONFIG['MOZ_WEBSPEECH']:
WEBIDL_FILES += [
'SpeechRecognitionError.webidl',
@ -543,3 +536,12 @@ GENERATED_EVENTS_WEBIDL_FILES = [
'BlobEvent.webidl',
'DeviceProximityEvent.webidl',
]
if CONFIG['MOZ_GAMEPAD']:
GENERATED_EVENTS_WEBIDL_FILES += [
'GamepadAxisMoveEvent.webidl',
'GamepadButtonEvent.webidl',
'GamepadEvent.webidl',
]

View File

@ -51,11 +51,6 @@ simple_events = [
'DeviceStorageChangeEvent',
'PopupBlockedEvent',
'RecordErrorEvent',
#ifdef MOZ_GAMEPAD
'GamepadEvent',
'GamepadButtonEvent',
'GamepadAxisMoveEvent',
#endif
#ifdef MOZ_WEBSPEECH
'SpeechRecognitionEvent',
#endif
@ -81,6 +76,5 @@ xpidl_to_native = [
['nsIDOMDocument', 'nsIDocument', 'nsIDocument'],
['nsIDOMElement', 'mozilla::dom::Element', 'mozilla::dom::Element'],
['nsIDOMCSSStyleSheet', 'nsCSSStyleSheet', 'nsIStyleSheet'],
['nsIDOMGamepad', 'Gamepad', 'nsIDOMGamepad']
]