Files
palemoon27/dom/gamepad/Gamepad.cpp
T
roytam1 e5bf86fbc7 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1137151: Enable test for non-public ref-counted destructors on gcc 4.8 and later, r=nfroyd (f286340cea)
- Bug 1028132 - Remove mozilla::HasDangerousPublicDestructor<T>. r=mccr8 (f4922e45d7)
- Bug 1057224 - Disable MOZ_ASSERT_CLASSNAME on gcc < 4.7. r=ehsan (faf4d10f51)
- Bug 1137175 - tighten up public interface of MiscContainer; r=khuey (510bf01921)
- bit of Bug 1152551, part 2 (0f734e8824)
- Bug 1208371 - Implement operator!= for nsMainThreadPtrHandle. r=bholley (df2f2505f9)
- Bug 1228451 - Set short-lived cert lifetime to the max OCSP response lifetime. r=keeler (877f012cce)
- Bug 1231378 - part 5 - Fix uninitialized members of classes in dom/{workers,events,media,canvas}, r=smaug (442135f0ae)
- Bug 1193854 - Restoring userContextIds with the browser session - part 1 - store the userContextId in sessionStore, r=smaug, r=ttaubert (1f6fbe0653)
- Bug 1193854 - Restoring userContextIds with the browser session - part 2 - restore the UI, r=ttaubert (c5ebd875df)
- Bug 1213650 - Regression tests. r=Mossop (c09eb0f7b6)
- Bug 1225921 - Regression tests. r=billm (c3ce773354)
- Bug 1193854 - Restoring userContextIds with the browser session - part 3 - tests, r=ttaubert (de3a5f0558)
- Bug 1237081 - Remove the getter of userContextId from nsIDocShell. r=smaug (0e3a43361e)
- Bug 1232150 - Add atomics for ppc/ppc64. r=lth (0790116e87)
- Backed out changeset 1b5c66916877 (bug 1237081) for mochitest browser-chrome bustage (278ba3c0a7)
- Bug 1237081 - remove the getter of userContextId from nsIDocShell, r=smaug (51d2b9aafa)
- Bug 567365 - allow bfcache for no-cache/https r=jduell r=bz (c94d3a1c00)
- Bug 1239420 - UserContextId should be propagate to nested docShells, r=smaug (148726b883)
- Bug 1212299 part 1 - Forbid documents inside elements other than iframe from requesting fullscreen. r=smaug (6e4662c4d5)
- Bug 1212299 part 2 - Rewrite fullscreen-denied test to have a clearer structure. r=smaug (c0200a46cc)
- Bug 1212299 part 3 - Add test for requesting fullscreen from doc inside frame/object. rs=smaug (3e0c7dae0d)
- Bug 1212299 followup - Fix minor grammar issue in locale text. DONTBUILD (905b69ff0f)
- Bug 1172224 - Ensure that docshells return an appropriate value for APZ-enabled even if they don't have a presShell. r=dvander (a906aeac93)
- Bug 1244076 - Fix a crash in nsDocShell::IssueWarning by null-checking mContentViewer; r=bzbarsky (beb09e9da8)
- Bug 1210439, r=smaug (5d42d61f5c)
- Bug 1100154 - Ensure that targeted links in a private browsing window can't target non-private-browsing windows and vice versa. r=bz (ff6f7ca3ef)
- Bug 1247872. Just get our private browsing state directly off the docshells we already have instead of trying to indirect through their documents. r=smaug (48a4c98815)
2023-09-06 15:22:39 +08:00

133 lines
3.2 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 "Gamepad.h"
#include "nsAutoPtr.h"
#include "nsPIDOMWindow.h"
#include "nsTArray.h"
#include "nsVariant.h"
#include "mozilla/dom/GamepadBinding.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTING_ADDREF(Gamepad)
NS_IMPL_CYCLE_COLLECTING_RELEASE(Gamepad)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Gamepad)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Gamepad, mParent, mButtons)
void
Gamepad::UpdateTimestamp()
{
nsCOMPtr<nsPIDOMWindow> newWindow(do_QueryInterface(mParent));
if(newWindow) {
nsPerformance* perf = newWindow->GetPerformance();
if (perf) {
mTimestamp = perf->GetDOMTiming()->TimeStampToDOMHighRes(TimeStamp::Now());
}
}
}
Gamepad::Gamepad(nsISupports* aParent,
const nsAString& aID, uint32_t aIndex,
GamepadMappingType aMapping,
uint32_t aNumButtons, uint32_t aNumAxes)
: mParent(aParent),
mID(aID),
mIndex(aIndex),
mMapping(aMapping),
mConnected(true),
mButtons(aNumButtons),
mAxes(aNumAxes),
mTimestamp(0)
{
for (unsigned i = 0; i < aNumButtons; i++) {
mButtons.InsertElementAt(i, new GamepadButton(mParent));
}
mAxes.InsertElementsAt(0, aNumAxes, 0.0f);
UpdateTimestamp();
}
void
Gamepad::SetIndex(uint32_t aIndex)
{
mIndex = aIndex;
}
void
Gamepad::SetConnected(bool aConnected)
{
mConnected = aConnected;
}
void
Gamepad::SetButton(uint32_t aButton, bool aPressed, double aValue)
{
MOZ_ASSERT(aButton < mButtons.Length());
mButtons[aButton]->SetPressed(aPressed);
mButtons[aButton]->SetValue(aValue);
UpdateTimestamp();
}
void
Gamepad::SetAxis(uint32_t aAxis, double aValue)
{
MOZ_ASSERT(aAxis < mAxes.Length());
if (mAxes[aAxis] != aValue) {
mAxes[aAxis] = aValue;
GamepadBinding::ClearCachedAxesValue(this);
}
UpdateTimestamp();
}
void
Gamepad::SyncState(Gamepad* aOther)
{
if (mButtons.Length() != aOther->mButtons.Length() ||
mAxes.Length() != aOther->mAxes.Length()) {
return;
}
mConnected = aOther->mConnected;
for (uint32_t i = 0; i < mButtons.Length(); ++i) {
mButtons[i]->SetPressed(aOther->mButtons[i]->Pressed());
mButtons[i]->SetValue(aOther->mButtons[i]->Value());
}
bool changed = false;
for (uint32_t i = 0; i < mAxes.Length(); ++i) {
changed = changed || (mAxes[i] != aOther->mAxes[i]);
mAxes[i] = aOther->mAxes[i];
}
if (changed) {
GamepadBinding::ClearCachedAxesValue(this);
}
UpdateTimestamp();
}
already_AddRefed<Gamepad>
Gamepad::Clone(nsISupports* aParent)
{
RefPtr<Gamepad> out =
new Gamepad(aParent, mID, mIndex, mMapping,
mButtons.Length(), mAxes.Length());
out->SyncState(this);
return out.forget();
}
/* virtual */ JSObject*
Gamepad::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return GamepadBinding::Wrap(aCx, this, aGivenProto);
}
} // namespace dom
} // namespace mozilla