Bug 1014162 - Make Gamepad.mapping into an enum. r=smaug

This commit is contained in:
Ted Mielczarek 2014-05-23 07:39:13 -04:00
parent fc83829a6e
commit 539dcae325
6 changed files with 14 additions and 18 deletions

View File

@ -6,6 +6,7 @@
#define mozilla_dom_gamepad_Gamepad_h
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/GamepadBinding.h"
#include "mozilla/dom/GamepadButton.h"
#include <stdint.h>
#include "nsCOMPtr.h"
@ -16,12 +17,6 @@
namespace mozilla {
namespace dom {
enum GamepadMappingType
{
NoMapping = 0,
StandardMapping = 1
};
// Per spec:
// https://dvcs.w3.org/hg/gamepad/raw-file/default/gamepad.html#remapping
const int kStandardGamepadButtons = 17;
@ -70,13 +65,9 @@ public:
aID = mID;
}
void GetMapping(nsAString& aMapping) const
GamepadMappingType Mapping()
{
if (mMapping == StandardMapping) {
aMapping = NS_LITERAL_STRING("standard");
} else {
aMapping = NS_LITERAL_STRING("");
}
return mMapping;
}
bool Connected() const

View File

@ -9,6 +9,11 @@ interface GamepadButton {
readonly attribute double value;
};
enum GamepadMappingType {
"",
"standard"
};
[Pref="dom.gamepad.enabled"]
interface Gamepad {
/**
@ -26,7 +31,7 @@ interface Gamepad {
* The mapping in use for this device. The empty string
* indicates that no mapping is in use.
*/
readonly attribute DOMString mapping;
readonly attribute GamepadMappingType mapping;
/**
* true if this gamepad is currently connected to the system.

View File

@ -171,7 +171,7 @@ DarwinGamepadService::DeviceAdded(IOHIDDeviceRef device)
sprintf(buffer, "%x-%x-%s", vendorId, productId, product_name);
nsRefPtr<GamepadService> service(GamepadService::GetService());
mGamepads[slot].mSuperIndex = service->AddGamepad(buffer,
mozilla::dom::NoMapping,
mozilla::dom::GamepadMappingType::_empty,
(int)mGamepads[slot].numButtons(),
(int)mGamepads[slot].numAxes());
}

View File

@ -140,7 +140,7 @@ LinuxGamepadService::AddDevice(struct udev_device* dev)
nsRefPtr<GamepadService> service(GamepadService::GetService());
gamepad.index = service->AddGamepad(gamepad.idstring,
mozilla::dom::NoMapping,
mozilla::dom::GamepadMappingType::_empty,
gamepad.numButtons,
gamepad.numAxes);

View File

@ -479,7 +479,7 @@ WindowsGamepadService::ScanForXInputDevices()
gamepad.numButtons = kStandardGamepadButtons;
gamepad.numAxes = kStandardGamepadAxes;
gamepad.id = gamepadsvc->AddGamepad("xinput",
StandardMapping,
GamepadMappingType::Standard,
kStandardGamepadButtons,
kStandardGamepadAxes);
mGamepads.AppendElement(gamepad);
@ -762,7 +762,7 @@ WindowsGamepadService::GetRawGamepad(HANDLE handle)
}
gamepad.id = gamepadsvc->AddGamepad(gamepad_id,
NoMapping,
GamepadMappingType::_empty,
gamepad.numButtons,
gamepad.numAxes);
mGamepads.AppendElement(gamepad);

View File

@ -601,7 +601,7 @@ nsAppShell::ProcessNextNativeEvent(bool mayWait)
if (svc) {
if (curEvent->Action() == AndroidGeckoEvent::ACTION_GAMEPAD_ADDED) {
int svc_id = svc->AddGamepad("android",
mozilla::dom::StandardMapping,
mozilla::dom::GamepadMappingType::Standard,
mozilla::dom::kStandardGamepadButtons,
mozilla::dom::kStandardGamepadAxes);
mozilla::widget::android::GeckoAppShell::GamepadAdded(curEvent->ID(),