| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/common/gamepad_param_traits.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 | |
| 9 #include "base/macros.h" | |
| 10 #include "base/pickle.h" | |
| 11 #include "base/strings/string16.h" | |
| 12 #include "base/strings/utf_string_conversions.h" | |
| 13 #include "ipc/ipc_message_utils.h" | |
| 14 #include "third_party/WebKit/public/platform/WebGamepad.h" | |
| 15 | |
| 16 using blink::WebGamepad; | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 void LogWebUCharString( | |
| 21 const blink::WebUChar web_string[], | |
| 22 const size_t array_size, | |
| 23 std::string* log) { | |
| 24 base::string16 utf16; | |
| 25 utf16.reserve(array_size); | |
| 26 for (size_t i = 0; i < array_size && web_string[i]; ++i) { | |
| 27 utf16[i] = web_string[i]; | |
| 28 } | |
| 29 log->append(base::UTF16ToUTF8(utf16)); | |
| 30 } | |
| 31 | |
| 32 } | |
| 33 | |
| 34 namespace IPC { | |
| 35 | |
| 36 void ParamTraits<WebGamepad>::Write(base::Pickle* m, const WebGamepad& p) { | |
| 37 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(WebGamepad)); | |
| 38 } | |
| 39 | |
| 40 bool ParamTraits<WebGamepad>::Read(const base::Pickle* m, | |
| 41 base::PickleIterator* iter, | |
| 42 WebGamepad* p) { | |
| 43 int length; | |
| 44 const char* data; | |
| 45 if (!iter->ReadData(&data, &length) || length != sizeof(WebGamepad)) | |
| 46 return false; | |
| 47 memcpy(p, data, sizeof(WebGamepad)); | |
| 48 | |
| 49 return true; | |
| 50 } | |
| 51 | |
| 52 void ParamTraits<WebGamepad>::Log( | |
| 53 const WebGamepad& p, | |
| 54 std::string* l) { | |
| 55 l->append("WebGamepad("); | |
| 56 LogParam(p.connected, l); | |
| 57 LogWebUCharString(p.id, WebGamepad::idLengthCap, l); | |
| 58 l->append(","); | |
| 59 LogWebUCharString(p.mapping, WebGamepad::mappingLengthCap, l); | |
| 60 l->append(","); | |
| 61 LogParam(p.timestamp, l); | |
| 62 l->append(","); | |
| 63 LogParam(p.axesLength, l); | |
| 64 l->append(", ["); | |
| 65 for (size_t i = 0; i < arraysize(p.axes); ++i) { | |
| 66 l->append(base::StringPrintf("%f%s", p.axes[i], | |
| 67 i < (arraysize(p.axes) - 1) ? ", " : "], ")); | |
| 68 } | |
| 69 LogParam(p.buttonsLength, l); | |
| 70 l->append(", ["); | |
| 71 for (size_t i = 0; i < arraysize(p.buttons); ++i) { | |
| 72 l->append(base::StringPrintf("(%u, %f)%s", | |
| 73 p.buttons[i].pressed, p.buttons[i].value, | |
| 74 i < (arraysize(p.buttons) - 1) ? ", " : "], ")); | |
| 75 } | |
| 76 l->append(")"); | |
| 77 } | |
| 78 | |
| 79 } // namespace IPC | |
| OLD | NEW |