Commit 13341aa7 authored by Matt Reynolds's avatar Matt Reynolds Committed by Commit Bot

Add GamepadButtonEvent and GamepadAxisEvent

This CL defines the GamepadButtonEvent and GamepadAxisEvent types that
will be used to return button and axis events to event listeners.

BUG=856290

Change-Id: I52d4eb91f9e40fe86e45d498e8aa97ec341341d6
Reviewed-on: https://chromium-review.googlesource.com/c/1167976Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarBrandon Jones <bajones@chromium.org>
Commit-Queue: Matt Reynolds <mattreynolds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605863}
parent f76bcfed
......@@ -2226,12 +2226,22 @@ interface Gamepad
getter timestamp
getter vibrationActuator
method constructor
interface GamepadAxisEvent : GamepadEvent
attribute @@toStringTag
getter axis
getter value
method constructor
interface GamepadButton
attribute @@toStringTag
getter pressed
getter touched
getter value
method constructor
interface GamepadButtonEvent : GamepadEvent
attribute @@toStringTag
getter button
getter value
method constructor
interface GamepadEvent : Event
attribute @@toStringTag
getter gamepad
......
......@@ -28,6 +28,8 @@ generate_event_interfaces("modules_bindings_generated_event_interfaces") {
"//third_party/blink/renderer/modules/device_orientation/device_orientation_event.idl",
"//third_party/blink/renderer/modules/encryptedmedia/media_encrypted_event.idl",
"//third_party/blink/renderer/modules/encryptedmedia/media_key_message_event.idl",
"//third_party/blink/renderer/modules/gamepad/gamepad_axis_event.idl",
"//third_party/blink/renderer/modules/gamepad/gamepad_button_event.idl",
"//third_party/blink/renderer/modules/gamepad/gamepad_event.idl",
"//third_party/blink/renderer/modules/indexeddb/idb_version_change_event.idl",
"//third_party/blink/renderer/modules/mediarecorder/blob_event.idl",
......
......@@ -8,8 +8,12 @@ blink_modules_sources("gamepad") {
sources = [
"gamepad.cc",
"gamepad.h",
"gamepad_axis_event.cc",
"gamepad_axis_event.h",
"gamepad_button.cc",
"gamepad_button.h",
"gamepad_button_event.cc",
"gamepad_button_event.h",
"gamepad_dispatcher.cc",
"gamepad_dispatcher.h",
"gamepad_event.cc",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/gamepad/gamepad_axis_event.h"
namespace blink {
GamepadAxisEvent::GamepadAxisEvent(const AtomicString& type,
Bubbles bubbles,
Cancelable cancelable,
Gamepad* gamepad,
uint32_t axis,
double value)
: GamepadEvent(type, bubbles, cancelable, gamepad),
axis_(axis),
value_(value) {}
GamepadAxisEvent::GamepadAxisEvent(const AtomicString& type,
const GamepadAxisEventInit* initializer)
: GamepadEvent(type, initializer) {
if (initializer->hasAxis())
axis_ = initializer->axis();
if (initializer->hasValue())
value_ = initializer->value();
}
GamepadAxisEvent::~GamepadAxisEvent() = default;
const AtomicString& GamepadAxisEvent::InterfaceName() const {
return event_interface_names::kGamepadAxisEvent;
}
} // namespace blink
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_GAMEPAD_GAMEPAD_AXIS_EVENT_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_GAMEPAD_GAMEPAD_AXIS_EVENT_H_
#include "third_party/blink/renderer/modules/gamepad/gamepad.h"
#include "third_party/blink/renderer/modules/gamepad/gamepad_axis_event_init.h"
#include "third_party/blink/renderer/modules/gamepad/gamepad_event.h"
namespace blink {
class GamepadAxisEvent final : public GamepadEvent {
DEFINE_WRAPPERTYPEINFO();
public:
static GamepadAxisEvent* Create(const AtomicString& type,
Bubbles bubbles,
Cancelable cancelable,
Gamepad* gamepad,
uint32_t axis,
double value) {
return new GamepadAxisEvent(type, bubbles, cancelable, gamepad, axis,
value);
}
static GamepadAxisEvent* Create(const AtomicString& type,
const GamepadAxisEventInit* initializer) {
return new GamepadAxisEvent(type, initializer);
}
~GamepadAxisEvent() override;
uint32_t getAxis() const { return axis_; }
double getValue() const { return value_; }
const AtomicString& InterfaceName() const override;
private:
GamepadAxisEvent(const AtomicString& type,
Bubbles,
Cancelable,
Gamepad*,
uint32_t axis,
double value);
GamepadAxisEvent(const AtomicString&, const GamepadAxisEventInit*);
uint32_t axis_ = 0;
double value_ = 0.0;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_GAMEPAD_GAMEPAD_AXIS_EVENT_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Non-standard gamepad axis event.
// https://docs.google.com/document/d/1rnQ1gU0iwPXbO7OvKS6KO9gyfpSdSQvKhK9_OkzUuKE
[
RuntimeEnabled=GamepadButtonAxisEvents,
Constructor(DOMString type, optional GamepadAxisEventInit eventInitDict)
] interface GamepadAxisEvent : GamepadEvent {
[ImplementedAs=getAxis] readonly attribute unsigned long axis;
[ImplementedAs=getValue] readonly attribute double value;
};
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Initialization dictionary type for GamepadAxisEvent.
// https://docs.google.com/document/d/1rnQ1gU0iwPXbO7OvKS6KO9gyfpSdSQvKhK9_OkzUuKE
dictionary GamepadAxisEventInit : GamepadEventInit {
unsigned long axis;
double value;
};
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/gamepad/gamepad_button_event.h"
namespace blink {
GamepadButtonEvent::GamepadButtonEvent(const AtomicString& type,
Bubbles bubbles,
Cancelable cancelable,
Gamepad* gamepad,
uint32_t button,
double value)
: GamepadEvent(type, bubbles, cancelable, gamepad),
button_(button),
value_(value) {}
GamepadButtonEvent::GamepadButtonEvent(
const AtomicString& type,
const GamepadButtonEventInit* initializer)
: GamepadEvent(type, initializer) {
if (initializer->hasButton())
button_ = initializer->button();
if (initializer->hasValue())
value_ = initializer->value();
}
GamepadButtonEvent::~GamepadButtonEvent() = default;
const AtomicString& GamepadButtonEvent::InterfaceName() const {
return event_interface_names::kGamepadButtonEvent;
}
} // namespace blink
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_GAMEPAD_GAMEPAD_BUTTON_EVENT_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_GAMEPAD_GAMEPAD_BUTTON_EVENT_H_
#include "third_party/blink/renderer/modules/gamepad/gamepad.h"
#include "third_party/blink/renderer/modules/gamepad/gamepad_button.h"
#include "third_party/blink/renderer/modules/gamepad/gamepad_button_event_init.h"
#include "third_party/blink/renderer/modules/gamepad/gamepad_event.h"
namespace blink {
class GamepadButtonEvent final : public GamepadEvent {
DEFINE_WRAPPERTYPEINFO();
public:
static GamepadButtonEvent* Create(const AtomicString& type,
Bubbles bubbles,
Cancelable cancelable,
Gamepad* gamepad,
uint32_t button,
double value) {
return new GamepadButtonEvent(type, bubbles, cancelable, gamepad, button,
value);
}
static GamepadButtonEvent* Create(const AtomicString& type,
const GamepadButtonEventInit* initializer) {
return new GamepadButtonEvent(type, initializer);
}
~GamepadButtonEvent() override;
uint32_t getButton() const { return button_; }
double getValue() const { return value_; }
const AtomicString& InterfaceName() const override;
private:
GamepadButtonEvent(const AtomicString& type,
Bubbles,
Cancelable,
Gamepad*,
uint32_t button,
double value);
GamepadButtonEvent(const AtomicString&, const GamepadButtonEventInit*);
uint32_t button_ = 0;
double value_ = 0.0;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_GAMEPAD_GAMEPAD_BUTTON_EVENT_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Non-standard gamepad button event.
// https://docs.google.com/document/d/1rnQ1gU0iwPXbO7OvKS6KO9gyfpSdSQvKhK9_OkzUuKE
[
RuntimeEnabled=GamepadButtonAxisEvents,
Constructor(DOMString type, optional GamepadButtonEventInit eventInitDict)
] interface GamepadButtonEvent : GamepadEvent {
[ImplementedAs=getButton] readonly attribute unsigned long button;
[ImplementedAs=getValue] readonly attribute double value;
};
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Initialization dictionary type for GamepadButtonEvent.
// https://docs.google.com/document/d/1rnQ1gU0iwPXbO7OvKS6KO9gyfpSdSQvKhK9_OkzUuKE
dictionary GamepadButtonEventInit : GamepadEventInit {
unsigned long button;
double value;
};
......@@ -11,7 +11,7 @@
namespace blink {
class GamepadEvent final : public Event {
class GamepadEvent : public Event {
DEFINE_WRAPPERTYPEINFO();
public:
......@@ -33,10 +33,11 @@ class GamepadEvent final : public Event {
void Trace(blink::Visitor*) override;
private:
protected:
GamepadEvent(const AtomicString& type, Bubbles, Cancelable, Gamepad*);
GamepadEvent(const AtomicString&, const GamepadEventInit*);
private:
Member<Gamepad> gamepad_;
};
......
......@@ -151,7 +151,9 @@ modules_idl_files =
"filesystem/metadata.idl",
"filesystem/metadata_callback.idl",
"gamepad/gamepad.idl",
"gamepad/gamepad_axis_event.idl",
"gamepad/gamepad_button.idl",
"gamepad/gamepad_button_event.idl",
"gamepad/gamepad_event.idl",
"gamepad/gamepad_haptic_actuator.idl",
"gamepad/gamepad_list.idl",
......@@ -535,6 +537,8 @@ modules_dictionary_idl_files =
"filesystem/file_system_get_directory_options.idl",
"filesystem/file_system_get_file_options.idl",
"filesystem/get_system_directory_options.idl",
"gamepad/gamepad_axis_event_init.idl",
"gamepad/gamepad_button_event_init.idl",
"gamepad/gamepad_effect_parameters.idl",
"gamepad/gamepad_event_init.idl",
"geolocation/position_options.idl",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment