Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1927)

Unified Diff: content/common/gamepad_connection_event_message_params.cc

Issue 200873002: Gamepad API: add support for connection events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/common/gamepad_connection_event_message_params.h ('k') | content/common/gamepad_messages.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/gamepad_connection_event_message_params.cc
diff --git a/content/common/gamepad_connection_event_message_params.cc b/content/common/gamepad_connection_event_message_params.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7ca11c750449d9f355038bf0b0590c269a5eda31
--- /dev/null
+++ b/content/common/gamepad_connection_event_message_params.cc
@@ -0,0 +1,65 @@
+#include "content/common/gamepad_connection_event_message_params.h"
+
+#include "base/logging.h"
+
+namespace content {
+
+namespace {
+ template <size_t N>
+ size_t StringLengthInBytes(const blink::WebUChar web_string[N]) {
+ size_t i = 0;
+ while (web_string[i] != 0) ++i;
+ DCHECK(i < N);
+ size_t num_characters = i > 0 ? (i - 1) : 0;
+ return num_characters * sizeof(blink::WebUChar);
+ }
+}
+
+GamepadConnectionEventMessageParams::GamepadConnectionEventMessageParams()
+ : index(-1) {
+}
+
+GamepadConnectionEventMessageParams::~GamepadConnectionEventMessageParams() {
+}
+
+GamepadConnectionEventMessageParams::GamepadConnectionEventMessageParams(
+ int index, const blink::WebGamepad& gamepad)
+ : index(index),
+ timestamp(gamepad.timestamp),
+ axes_length(gamepad.axesLength),
+ buttons_length(gamepad.buttonsLength),
+ connected(gamepad.connected) {
+ size_t num_bytes =
+ StringLengthInBytes<blink::WebGamepad::idLengthCap>(gamepad.id);
+ const blink::WebUChar* characters = &gamepad.id[0];
+ id_characters = std::vector<blink::WebUChar>(characters,
+ characters + num_bytes);
+
+ num_bytes =
+ StringLengthInBytes<blink::WebGamepad::mappingLengthCap>(gamepad.mapping);
+ characters = &gamepad.mapping[0];
+ mapping_characters = std::vector<blink::WebUChar>(characters,
+ characters + num_bytes);
+}
+
+void GamepadConnectionEventMessageParams::GetWebGamepad(
+ blink::WebGamepad* gamepad) const {
+ DCHECK(index >= 0);
+ DCHECK(id_characters.size() < (blink::WebGamepad::idLengthCap - 1));
+
+ size_t num_bytes = id_characters.size() * sizeof(blink::WebUChar);
+ memcpy(&gamepad->id[0], &id_characters[0], num_bytes);
+ gamepad->id[id_characters.size()] = 0;
+
+ DCHECK(mapping_characters.size() < (blink::WebGamepad::mappingLengthCap - 1));
+ num_bytes = mapping_characters.size() * sizeof(blink::WebUChar);
+ memcpy(&gamepad->mapping[0], &mapping_characters[0], num_bytes);
+ gamepad->mapping[mapping_characters.size()] = 0;
+
+ gamepad->timestamp = timestamp;
+ gamepad->axesLength = axes_length;
+ gamepad->buttonsLength = buttons_length;
+ gamepad->connected = connected;
+}
+
+}
« no previous file with comments | « content/common/gamepad_connection_event_message_params.h ('k') | content/common/gamepad_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698