backed out dcf67f13c6bb – bug 851542 - for B2G bustage CLOSED TREE

This commit is contained in:
Ted Mielczarek 2013-04-11 09:25:12 -04:00
commit b6e9bb11be
10 changed files with 92 additions and 136 deletions

View File

@ -3,39 +3,49 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsDOMGamepad.h"
#include "nsAutoPtr.h"
#include "nsDOMClassInfoID.h"
#include "nsIClassInfo.h"
#include "nsIXPCScriptable.h"
#include "nsTArray.h"
#include "nsContentUtils.h"
#include "nsVariant.h"
#include "mozilla/dom/GamepadBinding.h"
using namespace mozilla;
using namespace mozilla::dom;
DOMCI_DATA(Gamepad, nsDOMGamepad)
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMGamepad)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMGamepad)
NS_IMPL_ADDREF(nsDOMGamepad)
NS_IMPL_RELEASE(nsDOMGamepad)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMGamepad)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_BEGIN(nsDOMGamepad)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY(nsIDOMGamepad)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Gamepad)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsDOMGamepad, mParent)
nsDOMGamepad::nsDOMGamepad(nsISupports* aParent,
const nsAString& aID, uint32_t aIndex,
nsDOMGamepad::nsDOMGamepad(const nsAString& aID, uint32_t aIndex,
uint32_t aNumButtons, uint32_t aNumAxes)
: mParent(aParent),
mID(aID),
: mID(aID),
mIndex(aIndex),
mConnected(true)
{
SetIsDOMBinding();
mButtons.InsertElementsAt(0, aNumButtons, 0);
mAxes.InsertElementsAt(0, aNumAxes, 0.0f);
}
/* readonly attribute DOMString id; */
NS_IMETHODIMP
nsDOMGamepad::GetId(nsAString& aID)
{
aID = mID;
return NS_OK;
}
NS_IMETHODIMP
nsDOMGamepad::GetIndex(uint32_t* aIndex)
{
*aIndex = mIndex;
return NS_OK;
}
void
nsDOMGamepad::SetIndex(uint32_t aIndex)
{
@ -62,7 +72,16 @@ nsDOMGamepad::SetAxis(uint32_t aAxis, double aValue)
mAxes[aAxis] = aValue;
}
nsresult
/* readonly attribute boolean connected; */
NS_IMETHODIMP
nsDOMGamepad::GetConnected(bool* aConnected)
{
*aConnected = mConnected;
return NS_OK;
}
/* readonly attribute nsIVariant buttons; */
NS_IMETHODIMP
nsDOMGamepad::GetButtons(nsIVariant** aButtons)
{
nsRefPtr<nsVariant> out = new nsVariant();
@ -93,7 +112,8 @@ nsDOMGamepad::GetButtons(nsIVariant** aButtons)
return NS_OK;
}
nsresult
/* readonly attribute nsIVariant axes; */
NS_IMETHODIMP
nsDOMGamepad::GetAxes(nsIVariant** aAxes)
{
nsRefPtr<nsVariant> out = new nsVariant();
@ -142,16 +162,10 @@ nsDOMGamepad::SyncState(nsDOMGamepad* aOther)
}
already_AddRefed<nsDOMGamepad>
nsDOMGamepad::Clone(nsISupports* aParent)
nsDOMGamepad::Clone()
{
nsRefPtr<nsDOMGamepad> out =
new nsDOMGamepad(aParent, mID, mIndex, mButtons.Length(), mAxes.Length());
new nsDOMGamepad(mID, mIndex, mButtons.Length(), mAxes.Length());
out->SyncState(this);
return out.forget();
}
/* virtual */ JSObject*
nsDOMGamepad::WrapObject(JSContext* aCx, JSObject* aScope)
{
return GamepadBinding::Wrap(aCx, aScope, this);
}

View File

@ -5,23 +5,19 @@
#ifndef nsDomGamepad_h
#define nsDomGamepad_h
#include "mozilla/ErrorResult.h"
#include "mozilla/StandardInteger.h"
#include "nsCOMPtr.h"
#include "nsIDOMGamepad.h"
#include "nsString.h"
#include "nsCOMPtr.h"
#include "nsTArray.h"
#include "nsWrapperCache.h"
class nsDOMGamepad : public nsIDOMGamepad
, public nsWrapperCache
{
public:
nsDOMGamepad(nsISupports* aParent,
const nsAString& aID, uint32_t aIndex,
nsDOMGamepad(const nsAString& aID, uint32_t aIndex,
uint32_t aNumButtons, uint32_t aNumAxes);
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMGamepad)
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMGAMEPAD
nsDOMGamepad();
void SetConnected(bool aConnected);
@ -32,55 +28,13 @@ public:
// Make the state of this gamepad equivalent to other.
void SyncState(nsDOMGamepad* other);
// Return a new nsDOMGamepad containing the same data as this object,
// parented to aParent.
already_AddRefed<nsDOMGamepad> Clone(nsISupports* aParent);
nsISupports* GetParentObject() const
{
return mParent;
}
virtual JSObject*
WrapObject(JSContext* aCx, JSObject* aScope) MOZ_OVERRIDE;
void GetId(nsAString& aID) const
{
aID = mID;
}
bool Connected() const
{
return mConnected;
}
uint32_t Index() const
{
return mIndex;
}
already_AddRefed<nsIVariant> GetButtons(mozilla::ErrorResult& aRv)
{
nsCOMPtr<nsIVariant> buttons;
aRv = GetButtons(getter_AddRefs(buttons));
return buttons.forget();
}
already_AddRefed<nsIVariant> GetAxes(mozilla::ErrorResult& aRv)
{
nsCOMPtr<nsIVariant> axes;
aRv = GetAxes(getter_AddRefs(axes));
return axes.forget();
}
// Return a new nsDOMGamepad containing the same data as this object.
already_AddRefed<nsDOMGamepad> Clone();
private:
virtual ~nsDOMGamepad() {}
nsresult GetButtons(nsIVariant** aButtons);
nsresult GetAxes(nsIVariant** aAxes);
protected:
nsCOMPtr<nsISupports> mParent;
nsString mID;
uint32_t mIndex;

View File

@ -218,6 +218,9 @@
#include "nsIControllers.h"
#include "nsISelection.h"
#include "nsIBoxObject.h"
#ifdef MOZ_GAMEPAD
#include "nsIDOMGamepad.h"
#endif
#ifdef MOZ_XUL
#include "nsITreeSelection.h"
#include "nsITreeContentView.h"
@ -970,6 +973,11 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(TouchEvent, nsEventSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
#ifdef MOZ_GAMEPAD
NS_DEFINE_CLASSINFO_DATA(Gamepad, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
#endif
NS_DEFINE_CLASSINFO_DATA(MozCSSKeyframeRule, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MozCSSKeyframesRule, nsDOMGenericSH,
@ -2466,6 +2474,12 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_UI_EVENT_MAP_ENTRIES
DOM_CLASSINFO_MAP_END
#ifdef MOZ_GAMEPAD
DOM_CLASSINFO_MAP_BEGIN(Gamepad, nsIDOMGamepad)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMGamepad)
DOM_CLASSINFO_MAP_END
#endif
DOM_CLASSINFO_MAP_BEGIN(MozCSSKeyframeRule, nsIDOMMozCSSKeyframeRule)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozCSSKeyframeRule)
DOM_CLASSINFO_MAP_END

View File

@ -238,6 +238,10 @@ DOMCI_CLASS(Touch)
DOMCI_CLASS(TouchList)
DOMCI_CLASS(TouchEvent)
#ifdef MOZ_GAMEPAD
DOMCI_CLASS(Gamepad)
#endif
DOMCI_CLASS(MozCSSKeyframeRule)
DOMCI_CLASS(MozCSSKeyframesRule)

View File

@ -1489,10 +1489,6 @@ nsGlobalWindow::FreeInnerObjects()
mAudioContexts[i]->Shutdown();
}
mAudioContexts.Clear();
#ifdef MOZ_GAMEPAD
mGamepads.Clear();
#endif
}
//*****************************************************************************
@ -1635,10 +1631,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindow)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPendingStorageEvents)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIdleObservers)
#ifdef MOZ_GAMEPAD
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGamepads)
#endif
// Traverse stuff from nsPIDOMWindow
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChromeEventHandler)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParentTarget)
@ -1682,10 +1674,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindow)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPendingStorageEvents)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mIdleObservers)
#ifdef MOZ_GAMEPAD
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGamepads)
#endif
// Unlink stuff from nsPIDOMWindow
NS_IMPL_CYCLE_COLLECTION_UNLINK(mChromeEventHandler)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mParentTarget)

View File

@ -367,10 +367,6 @@ DOMInterfaces = {
'wrapperCache': False
},
'Gamepad': {
'nativeType': 'nsDOMGamepad',
},
'HTMLAppletElement': {
'nativeType': 'mozilla::dom::HTMLSharedObjectElement'
},
@ -1462,7 +1458,6 @@ addExternalIface('nsIControllers', nativeType='nsIControllers')
addExternalIface('nsIStreamListener', nativeType='nsIStreamListener', notflattened=True)
addExternalIface('nsISupports', nativeType='nsISupports')
addExternalIface('nsIEditor', nativeType='nsIEditor', notflattened=True)
addExternalIface('nsIVariant', nativeType='nsIVariant', notflattened=True)
addExternalIface('OutputStream', nativeType='nsIOutputStream',
notflattened=True)
addExternalIface('Principal', nativeType='nsIPrincipal',

View File

@ -9,4 +9,31 @@ interface nsIVariant;
[builtinclass, scriptable, uuid(ff13acd9-11da-4817-8f2a-4a5700dfd13e)]
interface nsIDOMGamepad : nsISupports
{
/**
* An identifier, unique per type of device.
*/
readonly attribute DOMString id;
/**
* The game port index for the device. Unique per device
* attached to this system.
*/
readonly attribute unsigned long index;
/**
* true if this gamepad is currently connected to the system.
*/
readonly attribute boolean connected;
/**
* The current state of all buttons on the device, an
* array of doubles.
*/
readonly attribute nsIVariant buttons;
/**
* The current position of all axes on the device, an
* array of doubles.
*/
readonly attribute nsIVariant axes;
};

View File

@ -133,8 +133,7 @@ GamepadService::AddGamepad(const char* aId,
{
//TODO: bug 852258: get initial button/axis state
nsRefPtr<nsDOMGamepad> gamepad =
new nsDOMGamepad(nullptr,
NS_ConvertUTF8toUTF16(nsDependentCString(aId)),
new nsDOMGamepad(NS_ConvertUTF8toUTF16(nsDependentCString(aId)),
0,
aNumButtons,
aNumAxes);
@ -414,8 +413,7 @@ GamepadService::SetWindowHasSeenGamepad(nsGlobalWindow* aWindow,
if (aHasSeen) {
aWindow->SetHasSeenGamepadInput(true);
nsCOMPtr<nsISupports> window = nsGlobalWindow::ToSupports(aWindow);
nsRefPtr<nsDOMGamepad> gamepad = mGamepads[aIndex]->Clone(window);
nsRefPtr<nsDOMGamepad> gamepad = mGamepads[aIndex]->Clone();
aWindow->AddGamepad(aIndex, gamepad);
} else {
aWindow->RemoveGamepad(aIndex);

View File

@ -1,37 +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/. */
interface nsIVariant;
interface Gamepad {
/**
* An identifier, unique per type of device.
*/
readonly attribute DOMString id;
/**
* The game port index for the device. Unique per device
* attached to this system.
*/
readonly attribute unsigned long index;
/**
* true if this gamepad is currently connected to the system.
*/
readonly attribute boolean connected;
/**
* The current state of all buttons on the device, an
* array of doubles.
*/
[Throws]
readonly attribute nsIVariant buttons;
/**
* The current position of all axes on the device, an
* array of doubles.
*/
[Throws]
readonly attribute nsIVariant axes;
};

View File

@ -71,7 +71,6 @@ webidl_files = \
FormData.webidl \
Function.webidl \
GainNode.webidl \
Gamepad.webidl \
HTMLAnchorElement.webidl \
HTMLAppletElement.webidl \
HTMLAreaElement.webidl \