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

Unified Diff: content/common/gamepad_param_traits.cc

Issue 195873019: Gamepad API: add support for connection events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: and a missing override Created 6 years, 7 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_param_traits.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/gamepad_param_traits.cc
diff --git a/content/common/gamepad_param_traits.cc b/content/common/gamepad_param_traits.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0abe51c5a3a351eb0d4361c4b7d8fcca460f4210
--- /dev/null
+++ b/content/common/gamepad_param_traits.cc
@@ -0,0 +1,79 @@
+// Copyright (c) 2014 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 "content/common/gamepad_param_traits.h"
+
+#include "base/pickle.h"
+#include "base/strings/string16.h"
+#include "base/strings/utf_string_conversions.h"
+#include "ipc/ipc_message_utils.h"
+#include "third_party/WebKit/public/platform/WebGamepad.h"
+
+using blink::WebGamepad;
+
+namespace {
+
+void LogWebUCharString(
+ const blink::WebUChar web_string[],
+ const size_t array_size,
+ std::string* log) {
+ base::string16 utf16;
+ utf16.reserve(array_size);
+ for (size_t i = 0; i < array_size && web_string[i]; ++i) {
+ utf16[i] = web_string[i];
+ }
+ log->append(base::UTF16ToUTF8(utf16));
+}
+
+}
+
+namespace IPC {
+
+void ParamTraits<WebGamepad>::Write(
+ Message* m,
+ const WebGamepad& p) {
+ m->WriteData(reinterpret_cast<const char*>(&p), sizeof(WebGamepad));
+}
+
+bool ParamTraits<WebGamepad>::Read(
+ const Message* m,
+ PickleIterator* iter,
+ WebGamepad* p) {
+ int length;
+ const char* data;
+ if (!m->ReadData(iter, &data, &length) || length != sizeof(WebGamepad))
+ return false;
+ memcpy(p, data, sizeof(WebGamepad));
+
+ return true;
+}
+
+void ParamTraits<WebGamepad>::Log(
+ const WebGamepad& p,
+ std::string* l) {
+ l->append("WebGamepad(");
+ LogParam(p.connected, l);
+ LogWebUCharString(p.id, WebGamepad::idLengthCap, l);
+ l->append(",");
+ LogWebUCharString(p.mapping, WebGamepad::mappingLengthCap, l);
+ l->append(",");
+ LogParam(p.timestamp, l);
+ l->append(",");
+ LogParam(p.axesLength, l);
+ l->append(", [");
+ for (size_t i = 0; i < arraysize(p.axes); ++i) {
+ l->append(base::StringPrintf("%f%s", p.axes[i],
+ i < (arraysize(p.axes) - 1) ? ", " : "], "));
+ }
+ LogParam(p.buttonsLength, l);
+ l->append(", [");
+ for (size_t i = 0; i < arraysize(p.buttons); ++i) {
+ l->append(base::StringPrintf("(%u, %f)%s",
+ p.buttons[i].pressed, p.buttons[i].value,
+ i < (arraysize(p.buttons) - 1) ? ", " : "], "));
+ }
+ l->append(")");
+}
+
+} // namespace IPC
« no previous file with comments | « content/common/gamepad_param_traits.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698