2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2011-08-03 18:12:08 +00:00
|
|
|
/* 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/. */
|
|
|
|
|
2012-02-16 00:47:13 +00:00
|
|
|
#include "Gamepad.h"
|
2015-01-07 19:17:04 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
2011-08-03 18:12:08 +00:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsVariant.h"
|
2013-04-09 12:43:25 +00:00
|
|
|
#include "mozilla/dom/GamepadBinding.h"
|
2011-08-03 18:12:08 +00:00
|
|
|
|
2012-02-16 00:47:13 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2011-08-03 18:12:08 +00:00
|
|
|
|
2012-02-16 00:47:13 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(Gamepad)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(Gamepad)
|
2011-08-03 18:12:08 +00:00
|
|
|
|
2012-02-16 00:47:13 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Gamepad)
|
2013-04-09 12:43:25 +00:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2011-08-03 18:12:08 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2014-04-29 08:57:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Gamepad, mParent, mButtons)
|
2013-04-09 12:43:25 +00:00
|
|
|
|
2015-01-07 19:17:04 +00:00
|
|
|
void
|
|
|
|
Gamepad::UpdateTimestamp()
|
|
|
|
{
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> newWindow(do_QueryInterface(mParent));
|
2015-01-07 19:17:04 +00:00
|
|
|
if(newWindow) {
|
2016-06-09 17:04:42 +00:00
|
|
|
Performance* perf = newWindow->GetPerformance();
|
2015-01-07 19:17:04 +00:00
|
|
|
if (perf) {
|
2015-07-30 05:41:00 +00:00
|
|
|
mTimestamp = perf->Now();
|
2015-01-07 19:17:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 00:47:13 +00:00
|
|
|
Gamepad::Gamepad(nsISupports* aParent,
|
|
|
|
const nsAString& aID, uint32_t aIndex,
|
2013-04-09 12:43:25 +00:00
|
|
|
GamepadMappingType aMapping,
|
2012-02-16 00:47:13 +00:00
|
|
|
uint32_t aNumButtons, uint32_t aNumAxes)
|
2013-04-09 12:43:25 +00:00
|
|
|
: mParent(aParent),
|
|
|
|
mID(aID),
|
2011-08-03 18:12:08 +00:00
|
|
|
mIndex(aIndex),
|
2013-04-09 12:43:25 +00:00
|
|
|
mMapping(aMapping),
|
2013-10-17 19:07:19 +00:00
|
|
|
mConnected(true),
|
|
|
|
mButtons(aNumButtons),
|
2016-01-12 18:16:59 +00:00
|
|
|
mAxes(aNumAxes),
|
|
|
|
mTimestamp(0)
|
2011-08-03 18:12:08 +00:00
|
|
|
{
|
2013-10-17 19:07:19 +00:00
|
|
|
for (unsigned i = 0; i < aNumButtons; i++) {
|
|
|
|
mButtons.InsertElementAt(i, new GamepadButton(mParent));
|
|
|
|
}
|
2011-08-03 18:12:08 +00:00
|
|
|
mAxes.InsertElementsAt(0, aNumAxes, 0.0f);
|
2015-01-07 19:17:04 +00:00
|
|
|
UpdateTimestamp();
|
2011-08-03 18:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-16 00:47:13 +00:00
|
|
|
Gamepad::SetIndex(uint32_t aIndex)
|
2011-08-03 18:12:08 +00:00
|
|
|
{
|
|
|
|
mIndex = aIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-16 00:47:13 +00:00
|
|
|
Gamepad::SetConnected(bool aConnected)
|
2011-08-03 18:12:08 +00:00
|
|
|
{
|
|
|
|
mConnected = aConnected;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-04-09 12:43:25 +00:00
|
|
|
Gamepad::SetButton(uint32_t aButton, bool aPressed, double aValue)
|
2011-08-03 18:12:08 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aButton < mButtons.Length());
|
2013-10-17 19:07:19 +00:00
|
|
|
mButtons[aButton]->SetPressed(aPressed);
|
|
|
|
mButtons[aButton]->SetValue(aValue);
|
2015-01-07 19:17:04 +00:00
|
|
|
UpdateTimestamp();
|
2011-08-03 18:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-16 00:47:13 +00:00
|
|
|
Gamepad::SetAxis(uint32_t aAxis, double aValue)
|
2011-08-03 18:12:08 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aAxis < mAxes.Length());
|
2013-12-06 16:41:13 +00:00
|
|
|
if (mAxes[aAxis] != aValue) {
|
|
|
|
mAxes[aAxis] = aValue;
|
|
|
|
GamepadBinding::ClearCachedAxesValue(this);
|
2011-08-03 18:12:08 +00:00
|
|
|
}
|
2015-01-07 19:17:04 +00:00
|
|
|
UpdateTimestamp();
|
2011-08-03 18:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-16 00:47:13 +00:00
|
|
|
Gamepad::SyncState(Gamepad* aOther)
|
2011-08-03 18:12:08 +00:00
|
|
|
{
|
|
|
|
if (mButtons.Length() != aOther->mButtons.Length() ||
|
|
|
|
mAxes.Length() != aOther->mAxes.Length()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mConnected = aOther->mConnected;
|
|
|
|
for (uint32_t i = 0; i < mButtons.Length(); ++i) {
|
2013-10-17 19:07:19 +00:00
|
|
|
mButtons[i]->SetPressed(aOther->mButtons[i]->Pressed());
|
|
|
|
mButtons[i]->SetValue(aOther->mButtons[i]->Value());
|
2011-08-03 18:12:08 +00:00
|
|
|
}
|
2013-12-06 16:41:13 +00:00
|
|
|
bool changed = false;
|
2011-08-03 18:12:08 +00:00
|
|
|
for (uint32_t i = 0; i < mAxes.Length(); ++i) {
|
2013-12-06 16:41:13 +00:00
|
|
|
changed = changed || (mAxes[i] != aOther->mAxes[i]);
|
2011-08-03 18:12:08 +00:00
|
|
|
mAxes[i] = aOther->mAxes[i];
|
|
|
|
}
|
2013-12-06 16:41:13 +00:00
|
|
|
if (changed) {
|
|
|
|
GamepadBinding::ClearCachedAxesValue(this);
|
|
|
|
}
|
2015-01-07 19:17:04 +00:00
|
|
|
UpdateTimestamp();
|
2011-08-03 18:12:08 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 00:47:13 +00:00
|
|
|
already_AddRefed<Gamepad>
|
|
|
|
Gamepad::Clone(nsISupports* aParent)
|
2011-08-03 18:12:08 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Gamepad> out =
|
2013-04-09 12:43:25 +00:00
|
|
|
new Gamepad(aParent, mID, mIndex, mMapping,
|
|
|
|
mButtons.Length(), mAxes.Length());
|
2011-08-03 18:12:08 +00:00
|
|
|
out->SyncState(this);
|
|
|
|
return out.forget();
|
|
|
|
}
|
2013-04-09 12:43:25 +00:00
|
|
|
|
|
|
|
/* virtual */ JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
Gamepad::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-04-09 12:43:25 +00:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
return GamepadBinding::Wrap(aCx, this, aGivenProto);
|
2013-04-09 12:43:25 +00:00
|
|
|
}
|
2012-02-16 00:47:13 +00:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|