tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

GamepadLightIndicator.cpp (2377B)


      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/. */
      6 
      7 #include "mozilla/dom/GamepadLightIndicator.h"
      8 
      9 #include "mozilla/HoldDropJSObjects.h"
     10 #include "mozilla/dom/GamepadManager.h"
     11 #include "mozilla/dom/Promise.h"
     12 
     13 namespace mozilla::dom {
     14 
     15 NS_IMPL_CYCLE_COLLECTING_ADDREF(GamepadLightIndicator)
     16 NS_IMPL_CYCLE_COLLECTING_RELEASE(GamepadLightIndicator)
     17 
     18 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GamepadLightIndicator)
     19  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
     20  NS_INTERFACE_MAP_ENTRY(nsISupports)
     21 NS_INTERFACE_MAP_END
     22 
     23 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(GamepadLightIndicator, mParent)
     24 
     25 GamepadLightIndicator::GamepadLightIndicator(nsISupports* aParent,
     26                                             GamepadHandle aGamepadHandle,
     27                                             uint32_t aIndex)
     28    : mParent(aParent),
     29      mType(DefaultType()),
     30      mGamepadHandle(aGamepadHandle),
     31      mIndex(aIndex) {}
     32 
     33 GamepadLightIndicator::~GamepadLightIndicator() {
     34  mozilla::DropJSObjects(this);
     35 }
     36 
     37 /* virtual */ JSObject* GamepadLightIndicator::WrapObject(
     38    JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
     39  return GamepadLightIndicator_Binding::Wrap(aCx, this, aGivenProto);
     40 }
     41 
     42 nsISupports* GamepadLightIndicator::GetParentObject() const { return mParent; }
     43 
     44 already_AddRefed<Promise> GamepadLightIndicator::SetColor(
     45    const GamepadLightColor& color, ErrorResult& aRv) {
     46  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
     47  MOZ_ASSERT(global);
     48 
     49  RefPtr<GamepadManager> gamepadManager(GamepadManager::GetService());
     50  MOZ_ASSERT(gamepadManager);
     51 
     52  RefPtr<Promise> promise = gamepadManager->SetLightIndicatorColor(
     53      mGamepadHandle, mIndex, color.mRed, color.mGreen, color.mBlue, global,
     54      aRv);
     55  if (!promise) {
     56    return nullptr;
     57  }
     58  return promise.forget();
     59 }
     60 
     61 GamepadLightIndicatorType GamepadLightIndicator::Type() const { return mType; }
     62 
     63 void GamepadLightIndicator::Set(const GamepadLightIndicator* aOther) {
     64  MOZ_ASSERT(aOther);
     65  mGamepadHandle = aOther->mGamepadHandle;
     66  mType = aOther->mType;
     67  mIndex = aOther->mIndex;
     68 }
     69 
     70 }  // namespace mozilla::dom