Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / gamepad / GamepadLightIndicator.cpp
blob0ddb1bffe6634520c171455a596e87f46fa9d627
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/GamepadLightIndicator.h"
8 #include "mozilla/dom/GamepadManager.h"
9 #include "mozilla/dom/Promise.h"
10 #include "mozilla/HoldDropJSObjects.h"
12 namespace mozilla::dom {
14 NS_IMPL_CYCLE_COLLECTING_ADDREF(GamepadLightIndicator)
15 NS_IMPL_CYCLE_COLLECTING_RELEASE(GamepadLightIndicator)
17 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GamepadLightIndicator)
18 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
19 NS_INTERFACE_MAP_ENTRY(nsISupports)
20 NS_INTERFACE_MAP_END
22 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(GamepadLightIndicator, mParent)
24 GamepadLightIndicator::GamepadLightIndicator(nsISupports* aParent,
25 GamepadHandle aGamepadHandle,
26 uint32_t aIndex)
27 : mParent(aParent),
28 mType(DefaultType()),
29 mGamepadHandle(aGamepadHandle),
30 mIndex(aIndex) {}
32 GamepadLightIndicator::~GamepadLightIndicator() {
33 mozilla::DropJSObjects(this);
36 /* virtual */ JSObject* GamepadLightIndicator::WrapObject(
37 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
38 return GamepadLightIndicator_Binding::Wrap(aCx, this, aGivenProto);
41 nsISupports* GamepadLightIndicator::GetParentObject() const { return mParent; }
43 already_AddRefed<Promise> GamepadLightIndicator::SetColor(
44 const GamepadLightColor& color, ErrorResult& aRv) {
45 nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
46 MOZ_ASSERT(global);
48 RefPtr<GamepadManager> gamepadManager(GamepadManager::GetService());
49 MOZ_ASSERT(gamepadManager);
51 RefPtr<Promise> promise = gamepadManager->SetLightIndicatorColor(
52 mGamepadHandle, mIndex, color.mRed, color.mGreen, color.mBlue, global,
53 aRv);
54 if (!promise) {
55 return nullptr;
57 return promise.forget();
60 GamepadLightIndicatorType GamepadLightIndicator::Type() const { return mType; }
62 void GamepadLightIndicator::Set(const GamepadLightIndicator* aOther) {
63 MOZ_ASSERT(aOther);
64 mGamepadHandle = aOther->mGamepadHandle;
65 mType = aOther->mType;
66 mIndex = aOther->mIndex;
69 } // namespace mozilla::dom