dom/gamepad/Gamepad.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifndef mozilla_dom_gamepad_Gamepad_h
     6 #define mozilla_dom_gamepad_Gamepad_h
     8 #include "mozilla/ErrorResult.h"
     9 #include "mozilla/dom/GamepadButton.h"
    10 #include <stdint.h>
    11 #include "nsCOMPtr.h"
    12 #include "nsString.h"
    13 #include "nsTArray.h"
    14 #include "nsWrapperCache.h"
    16 namespace mozilla {
    17 namespace dom {
    19 enum GamepadMappingType
    20 {
    21   NoMapping = 0,
    22   StandardMapping = 1
    23 };
    25 class Gamepad : public nsISupports,
    26                 public nsWrapperCache
    27 {
    28 public:
    29   Gamepad(nsISupports* aParent,
    30           const nsAString& aID, uint32_t aIndex,
    31           GamepadMappingType aMapping,
    32           uint32_t aNumButtons, uint32_t aNumAxes);
    33   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    34   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Gamepad)
    36   void SetConnected(bool aConnected);
    37   void SetButton(uint32_t aButton, bool aPressed, double aValue);
    38   void SetAxis(uint32_t aAxis, double aValue);
    39   void SetIndex(uint32_t aIndex);
    41   // Make the state of this gamepad equivalent to other.
    42   void SyncState(Gamepad* aOther);
    44   // Return a new Gamepad containing the same data as this object,
    45   // parented to aParent.
    46   already_AddRefed<Gamepad> Clone(nsISupports* aParent);
    48   nsISupports* GetParentObject() const
    49   {
    50     return mParent;
    51   }
    53   virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
    55   void GetId(nsAString& aID) const
    56   {
    57     aID = mID;
    58   }
    60   void GetMapping(nsAString& aMapping) const
    61   {
    62     if (mMapping == StandardMapping) {
    63       aMapping = NS_LITERAL_STRING("standard");
    64     } else {
    65       aMapping = NS_LITERAL_STRING("");
    66     }
    67   }
    69   bool Connected() const
    70   {
    71     return mConnected;
    72   }
    74   uint32_t Index() const
    75   {
    76     return mIndex;
    77   }
    79   void GetButtons(nsTArray<nsRefPtr<GamepadButton>>& aButtons) const
    80   {
    81     aButtons = mButtons;
    82   }
    84   void GetAxes(nsTArray<double>& aAxes) const
    85   {
    86     aAxes = mAxes;
    87   }
    89 private:
    90   virtual ~Gamepad() {}
    92 protected:
    93   nsCOMPtr<nsISupports> mParent;
    94   nsString mID;
    95   uint32_t mIndex;
    97   // The mapping in use.
    98   GamepadMappingType mMapping;
   100   // true if this gamepad is currently connected.
   101   bool mConnected;
   103   // Current state of buttons, axes.
   104   nsTArray<nsRefPtr<GamepadButton>> mButtons;
   105   nsTArray<double> mAxes;
   106 };
   108 } // namespace dom
   109 } // namespace mozilla
   111 #endif // mozilla_dom_gamepad_Gamepad_h

mercurial