Skip to content

Commit d834dfb

Browse files
committed
Bug 1336002 - Part 2: Support button touched in GamepadManager; r=Lenzak
MozReview-Commit-ID: DcX988Obthp --HG-- extra : rebase_source : 590704bc0e5edc0ed446da19267ad16a8f728ee6
1 parent 66e6df1 commit d834dfb

8 files changed

+39
-16
lines changed

dom/gamepad/GamepadManager.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ GamepadManager::RemoveGamepad(uint32_t aIndex, GamepadServiceType aServiceType)
269269

270270
void
271271
GamepadManager::NewButtonEvent(uint32_t aIndex, GamepadServiceType aServiceType,
272-
uint32_t aButton, bool aPressed, double aValue)
272+
uint32_t aButton, bool aPressed, bool aTouched,
273+
double aValue)
273274
{
274275
if (mShuttingDown) {
275276
return;
@@ -282,7 +283,7 @@ GamepadManager::NewButtonEvent(uint32_t aIndex, GamepadServiceType aServiceType,
282283
return;
283284
}
284285

285-
gamepad->SetButton(aButton, aPressed, aValue);
286+
gamepad->SetButton(aButton, aPressed, aTouched, aValue);
286287

287288
// Hold on to listeners in a separate array because firing events
288289
// can mutate the mListeners array.
@@ -303,7 +304,7 @@ GamepadManager::NewButtonEvent(uint32_t aIndex, GamepadServiceType aServiceType,
303304

304305
RefPtr<Gamepad> listenerGamepad = listeners[i]->GetGamepad(newIndex);
305306
if (listenerGamepad) {
306-
listenerGamepad->SetButton(aButton, aPressed, aValue);
307+
listenerGamepad->SetButton(aButton, aPressed, aTouched, aValue);
307308
if (firstTime) {
308309
FireConnectionEvent(listeners[i], listenerGamepad, true);
309310
}
@@ -650,7 +651,7 @@ GamepadManager::Update(const GamepadChangeEvent& aEvent)
650651
if (aEvent.type() == GamepadChangeEvent::TGamepadButtonInformation) {
651652
const GamepadButtonInformation& a = aEvent.get_GamepadButtonInformation();
652653
NewButtonEvent(a.index(), a.service_type(), a.button(),
653-
a.pressed(), a.value());
654+
a.pressed(), a.touched(), a.value());
654655
return;
655656
}
656657
if (aEvent.type() == GamepadChangeEvent::TGamepadAxisInformation) {

dom/gamepad/GamepadManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class GamepadManager final : public nsIObserver,
6262
// a gamepadbutton{up,down} event at them as well.
6363
// aPressed is used for digital buttons, aValue is for analog buttons.
6464
void NewButtonEvent(uint32_t aIndex, GamepadServiceType aServiceType, uint32_t aButton,
65-
bool aPressed, double aValue);
65+
bool aPressed, bool aTouched, double aValue);
6666

6767
// Update the state of |aAxis| for the gamepad at |aIndex| for all
6868
// windows that are listening and visible, and fire a gamepadaxismove

dom/gamepad/GamepadPlatformService.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,30 @@ GamepadPlatformService::RemoveGamepad(uint32_t aIndex)
117117

118118
void
119119
GamepadPlatformService::NewButtonEvent(uint32_t aIndex, uint32_t aButton,
120-
bool aPressed, double aValue)
120+
bool aPressed, bool aTouched,
121+
double aValue)
121122
{
122123
// This method is called by monitor thread populated in
123124
// platform-dependent backends
124125
MOZ_ASSERT(XRE_IsParentProcess());
125126
MOZ_ASSERT(!NS_IsMainThread());
126127
GamepadButtonInformation a(aIndex, GamepadServiceType::Standard,
127-
aButton, aPressed, aValue);
128+
aButton, aValue, aPressed, aTouched);
128129
NotifyGamepadChange<GamepadButtonInformation>(a);
129130
}
130131

132+
void
133+
GamepadPlatformService::NewButtonEvent(uint32_t aIndex, uint32_t aButton,
134+
bool aPressed, bool aTouched)
135+
{
136+
// This method is called by monitor thread populated in
137+
// platform-dependent backends
138+
MOZ_ASSERT(XRE_IsParentProcess());
139+
MOZ_ASSERT(!NS_IsMainThread());
140+
// When only a digital button is available the value will be synthesized.
141+
NewButtonEvent(aIndex, aButton, aPressed, aTouched, aPressed ? 1.0L : 0.0L);
142+
}
143+
131144
void
132145
GamepadPlatformService::NewButtonEvent(uint32_t aIndex, uint32_t aButton,
133146
bool aPressed)
@@ -137,7 +150,7 @@ GamepadPlatformService::NewButtonEvent(uint32_t aIndex, uint32_t aButton,
137150
MOZ_ASSERT(XRE_IsParentProcess());
138151
MOZ_ASSERT(!NS_IsMainThread());
139152
// When only a digital button is available the value will be synthesized.
140-
NewButtonEvent(aIndex, aButton, aPressed, aPressed ? 1.0L : 0.0L);
153+
NewButtonEvent(aIndex, aButton, aPressed, aPressed, aPressed ? 1.0L : 0.0L);
141154
}
142155

143156
void

dom/gamepad/GamepadPlatformService.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,15 @@ class GamepadPlatformService final
4646
// Update the state of |aButton| for the gamepad at |aIndex| for all
4747
// windows that are listening and visible, and fire one of
4848
// a gamepadbutton{up,down} event at them as well.
49-
// aPressed is used for digital buttons, aValue is for analog buttons.
49+
// aPressed is used for digital buttons, aTouched is for detecting touched
50+
// events, aValue is for analog buttons.
5051
void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed,
51-
double aValue);
52+
bool aTouched, double aValue);
5253
// When only a digital button is available the value will be synthesized.
5354
void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed);
55+
// When only a digital button are available the value will be synthesized.
56+
void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed,
57+
bool aTouched);
5458

5559
// Update the state of |aAxis| for the gamepad at |aIndex| for all
5660
// windows that are listening and visible, and fire a gamepadaxismove

dom/gamepad/GamepadServiceTest.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,15 @@ GamepadServiceTest::RemoveGamepad(uint32_t aIndex)
168168
void
169169
GamepadServiceTest::NewButtonEvent(uint32_t aIndex,
170170
uint32_t aButton,
171+
bool aTouched,
171172
bool aPressed)
172173
{
173174
if (mShuttingDown) {
174175
return;
175176
}
176177

177178
GamepadButtonInformation a(aIndex, GamepadServiceType::Standard,
178-
aButton, aPressed, aPressed ? 1.0 : 0);
179+
aButton, aPressed ? 1.0 : 0, aPressed, aTouched);
179180
GamepadChangeEvent e(a);
180181

181182
uint32_t id = ++mEventNumber;
@@ -191,14 +192,15 @@ void
191192
GamepadServiceTest::NewButtonValueEvent(uint32_t aIndex,
192193
uint32_t aButton,
193194
bool aPressed,
195+
bool aTouched,
194196
double aValue)
195197
{
196198
if (mShuttingDown) {
197199
return;
198200
}
199201

200202
GamepadButtonInformation a(aIndex, GamepadServiceType::Standard,
201-
aButton, aPressed, aValue);
203+
aButton, aValue, aPressed, aTouched);
202204
GamepadChangeEvent e(a);
203205

204206
uint32_t id = ++mEventNumber;

dom/gamepad/GamepadServiceTest.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ class GamepadServiceTest final : public DOMEventTargetHelper,
4343
uint32_t aNumHaptics,
4444
ErrorResult& aRv);
4545
void RemoveGamepad(uint32_t aIndex);
46-
void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed);
47-
void NewButtonValueEvent(uint32_t aIndex, uint32_t aButton, bool aPressed, double aValue);
46+
void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed, bool aTouched);
47+
void NewButtonValueEvent(uint32_t aIndex, uint32_t aButton, bool aPressed, bool aTouched,
48+
double aValue);
4849
void NewAxisMoveEvent(uint32_t aIndex, uint32_t aAxis, double aValue);
4950
void NewPoseMove(uint32_t aIndex,
5051
const Nullable<Float32Array>& aOrient,

dom/gamepad/ipc/GamepadEventTypes.ipdlh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ struct GamepadButtonInformation {
3838
uint32_t index;
3939
GamepadServiceType service_type;
4040
uint32_t button;
41-
bool pressed;
4241
double value;
42+
bool pressed;
43+
bool touched;
4344
};
4445

4546
struct GamepadPoseInformation {

dom/gamepad/ipc/GamepadTestChannelParent.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ GamepadTestChannelParent::RecvGamepadTestEvent(const uint32_t& aID,
4040
}
4141
if (aEvent.type() == GamepadChangeEvent::TGamepadButtonInformation) {
4242
const GamepadButtonInformation& a = aEvent.get_GamepadButtonInformation();
43-
service->NewButtonEvent(a.index(), a.button(), a.pressed(), a.value());
43+
service->NewButtonEvent(a.index(), a.button(), a.pressed(), a.touched(),
44+
a.value());
4445
return IPC_OK();
4546
}
4647
if (aEvent.type() == GamepadChangeEvent::TGamepadAxisInformation) {

0 commit comments

Comments
 (0)