OLD | NEW |
---|---|
(Empty) | |
1 #include "content/common/gamepad_connection_event_message_params.h" | |
jam
2014/03/17 19:01:00
nit: need license header
kbalazs
2014/03/20 20:42:50
Done.
| |
2 | |
3 #include "base/logging.h" | |
4 | |
5 namespace content { | |
6 | |
7 namespace { | |
8 template <size_t N> | |
9 size_t StringLengthInBytes(const blink::WebUChar web_string[N]) { | |
jam
2014/03/17 19:01:00
nit: no indentation in namespace
kbalazs
2014/03/20 20:42:50
Done.
| |
10 size_t i = 0; | |
11 while (web_string[i] != 0) ++i; | |
12 DCHECK(i < N); | |
13 size_t num_characters = i > 0 ? (i - 1) : 0; | |
14 return num_characters * sizeof(blink::WebUChar); | |
15 } | |
16 } | |
17 | |
18 GamepadConnectionEventMessageParams::GamepadConnectionEventMessageParams() | |
19 : index(-1) { | |
20 } | |
21 | |
22 GamepadConnectionEventMessageParams::~GamepadConnectionEventMessageParams() { | |
23 } | |
24 | |
25 GamepadConnectionEventMessageParams::GamepadConnectionEventMessageParams( | |
26 int index, const blink::WebGamepad& gamepad) | |
27 : index(index), | |
28 timestamp(gamepad.timestamp), | |
29 axes_length(gamepad.axesLength), | |
30 buttons_length(gamepad.buttonsLength), | |
31 connected(gamepad.connected) { | |
32 size_t num_bytes = | |
33 StringLengthInBytes<blink::WebGamepad::idLengthCap>(gamepad.id); | |
34 const blink::WebUChar* characters = &gamepad.id[0]; | |
35 id_characters = std::vector<blink::WebUChar>(characters, | |
36 characters + num_bytes); | |
37 | |
38 num_bytes = | |
39 StringLengthInBytes<blink::WebGamepad::mappingLengthCap>(gamepad.mapping); | |
40 characters = &gamepad.mapping[0]; | |
41 mapping_characters = std::vector<blink::WebUChar>(characters, | |
42 characters + num_bytes); | |
43 } | |
44 | |
45 void GamepadConnectionEventMessageParams::GetWebGamepad( | |
46 blink::WebGamepad* gamepad) const { | |
47 DCHECK(index >= 0); | |
48 DCHECK(id_characters.size() < (blink::WebGamepad::idLengthCap - 1)); | |
49 | |
50 size_t num_bytes = id_characters.size() * sizeof(blink::WebUChar); | |
51 memcpy(&gamepad->id[0], &id_characters[0], num_bytes); | |
52 gamepad->id[id_characters.size()] = 0; | |
53 | |
54 DCHECK(mapping_characters.size() < (blink::WebGamepad::mappingLengthCap - 1)); | |
55 num_bytes = mapping_characters.size() * sizeof(blink::WebUChar); | |
56 memcpy(&gamepad->mapping[0], &mapping_characters[0], num_bytes); | |
57 gamepad->mapping[mapping_characters.size()] = 0; | |
58 | |
59 gamepad->timestamp = timestamp; | |
60 gamepad->axesLength = axes_length; | |
61 gamepad->buttonsLength = buttons_length; | |
62 gamepad->connected = connected; | |
63 } | |
64 | |
65 } | |
OLD | NEW |