2015-05-03 22:32:37 +03: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 22:12:08 +04: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 04:47:13 +04:00
|
|
|
#include "Gamepad.h"
|
2013-04-09 16:43:25 +04:00
|
|
|
#include "nsAutoPtr.h"
|
2015-01-07 22:17:04 +03:00
|
|
|
#include "nsPIDOMWindow.h"
|
2011-08-03 22:12:08 +04:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsVariant.h"
|
2013-04-09 16:43:25 +04:00
|
|
|
#include "mozilla/dom/GamepadBinding.h"
|
2011-08-03 22:12:08 +04:00
|
|
|
|
2012-02-16 04:47:13 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2011-08-03 22:12:08 +04:00
|
|
|
|
2012-02-16 04:47:13 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(Gamepad)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(Gamepad)
|
2011-08-03 22:12:08 +04:00
|
|
|
|
2012-02-16 04:47:13 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Gamepad)
|
2013-04-09 16:43:25 +04:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2011-08-03 22:12:08 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2014-04-29 12:57:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Gamepad, mParent, mButtons)
|
2013-04-09 16:43:25 +04:00
|
|
|
|
2015-01-07 22:17:04 +03:00
|
|
|
void
|
|
|
|
Gamepad::UpdateTimestamp()
|
|
|
|
{
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> newWindow(do_QueryInterface(mParent));
|
2015-01-07 22:17:04 +03:00
|
|
|
if(newWindow) {
|
|
|
|
nsPerformance* perf = newWindow->GetPerformance();
|
|
|
|
if (perf) {
|
2015-07-30 08:41:00 +03:00
|
|
|
mTimestamp = perf->Now();
|
2015-01-07 22:17:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:47:13 +04:00
|
|
|
Gamepad::Gamepad(nsISupports* aParent,
|
|
|
|
const nsAString& aID, uint32_t aIndex,
|
2013-04-09 16:43:25 +04:00
|
|
|
GamepadMappingType aMapping,
|
2012-02-16 04:47:13 +04:00
|
|
|
uint32_t aNumButtons, uint32_t aNumAxes)
|
2013-04-09 16:43:25 +04:00
|
|
|
: mParent(aParent),
|
|
|
|
mID(aID),
|
2011-08-03 22:12:08 +04:00
|
|
|
mIndex(aIndex),
|
2013-04-09 16:43:25 +04:00
|
|
|
mMapping(aMapping),
|
2013-10-17 23:07:19 +04:00
|
|
|
mConnected(true),
|
|
|
|
mButtons(aNumButtons),
|
2016-01-12 21:16:59 +03:00
|
|
|
mAxes(aNumAxes),
|
|
|
|
mTimestamp(0)
|
2011-08-03 22:12:08 +04:00
|
|
|
{
|
2013-10-17 23:07:19 +04:00
|
|
|
for (unsigned i = 0; i < aNumButtons; i++) {
|
|
|
|
mButtons.InsertElementAt(i, new GamepadButton(mParent));
|
|
|
|
}
|
2011-08-03 22:12:08 +04:00
|
|
|
mAxes.InsertElementsAt(0, aNumAxes, 0.0f);
|
2015-01-07 22:17:04 +03:00
|
|
|
UpdateTimestamp();
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-16 04:47:13 +04:00
|
|
|
Gamepad::SetIndex(uint32_t aIndex)
|
2011-08-03 22:12:08 +04:00
|
|
|
{
|
|
|
|
mIndex = aIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-16 04:47:13 +04:00
|
|
|
Gamepad::SetConnected(bool aConnected)
|
2011-08-03 22:12:08 +04:00
|
|
|
{
|
|
|
|
mConnected = aConnected;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-04-09 16:43:25 +04:00
|
|
|
Gamepad::SetButton(uint32_t aButton, bool aPressed, double aValue)
|
2011-08-03 22:12:08 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aButton < mButtons.Length());
|
2013-10-17 23:07:19 +04:00
|
|
|
mButtons[aButton]->SetPressed(aPressed);
|
|
|
|
mButtons[aButton]->SetValue(aValue);
|
2015-01-07 22:17:04 +03:00
|
|
|
UpdateTimestamp();
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-16 04:47:13 +04:00
|
|
|
Gamepad::SetAxis(uint32_t aAxis, double aValue)
|
2011-08-03 22:12:08 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aAxis < mAxes.Length());
|
2013-12-06 20:41:13 +04:00
|
|
|
if (mAxes[aAxis] != aValue) {
|
|
|
|
mAxes[aAxis] = aValue;
|
|
|
|
GamepadBinding::ClearCachedAxesValue(this);
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
2015-01-07 22:17:04 +03:00
|
|
|
UpdateTimestamp();
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-16 04:47:13 +04:00
|
|
|
Gamepad::SyncState(Gamepad* aOther)
|
2011-08-03 22:12:08 +04: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 23:07:19 +04:00
|
|
|
mButtons[i]->SetPressed(aOther->mButtons[i]->Pressed());
|
|
|
|
mButtons[i]->SetValue(aOther->mButtons[i]->Value());
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
2013-12-06 20:41:13 +04:00
|
|
|
bool changed = false;
|
2011-08-03 22:12:08 +04:00
|
|
|
for (uint32_t i = 0; i < mAxes.Length(); ++i) {
|
2013-12-06 20:41:13 +04:00
|
|
|
changed = changed || (mAxes[i] != aOther->mAxes[i]);
|
2011-08-03 22:12:08 +04:00
|
|
|
mAxes[i] = aOther->mAxes[i];
|
|
|
|
}
|
2013-12-06 20:41:13 +04:00
|
|
|
if (changed) {
|
|
|
|
GamepadBinding::ClearCachedAxesValue(this);
|
|
|
|
}
|
2015-01-07 22:17:04 +03:00
|
|
|
UpdateTimestamp();
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:47:13 +04:00
|
|
|
already_AddRefed<Gamepad>
|
|
|
|
Gamepad::Clone(nsISupports* aParent)
|
2011-08-03 22:12:08 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Gamepad> out =
|
2013-04-09 16:43:25 +04:00
|
|
|
new Gamepad(aParent, mID, mIndex, mMapping,
|
|
|
|
mButtons.Length(), mAxes.Length());
|
2011-08-03 22:12:08 +04:00
|
|
|
out->SyncState(this);
|
|
|
|
return out.forget();
|
|
|
|
}
|
2013-04-09 16:43:25 +04: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 17:13:33 +03:00
|
|
|
Gamepad::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-04-09 16:43:25 +04: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 17:13:33 +03:00
|
|
|
return GamepadBinding::Wrap(aCx, this, aGivenProto);
|
2013-04-09 16:43:25 +04:00
|
|
|
}
|
2012-02-16 04:47:13 +04:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|