OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/shell/renderer/test_runner/gamepad_controller.h" | 5 #include "content/shell/renderer/test_runner/gamepad_controller.h" |
6 | 6 |
7 #include "content/shell/renderer/test_runner/TestInterfaces.h" | 7 #include "content/shell/renderer/test_runner/TestInterfaces.h" |
8 #include "content/shell/renderer/test_runner/WebTestDelegate.h" | 8 #include "content/shell/renderer/test_runner/WebTestDelegate.h" |
9 #include "gin/arguments.h" | 9 #include "gin/arguments.h" |
10 #include "gin/handle.h" | 10 #include "gin/handle.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 if (controller_) | 131 if (controller_) |
132 controller_->SetAxisCount(index, axes); | 132 controller_->SetAxisCount(index, axes); |
133 } | 133 } |
134 | 134 |
135 void GamepadControllerBindings::SetAxisData(int index, int axis, double data) { | 135 void GamepadControllerBindings::SetAxisData(int index, int axis, double data) { |
136 if (controller_) | 136 if (controller_) |
137 controller_->SetAxisData(index, axis, data); | 137 controller_->SetAxisData(index, axis, data); |
138 } | 138 } |
139 | 139 |
140 GamepadController::GamepadController() | 140 GamepadController::GamepadController() |
141 : listener_(NULL), | 141 : RendererGamepadProvider(0), |
142 weak_factory_(this) { | 142 weak_factory_(this) { |
143 Reset(); | 143 Reset(); |
144 } | 144 } |
145 | 145 |
146 GamepadController::~GamepadController() {} | 146 GamepadController::~GamepadController() {} |
147 | 147 |
148 void GamepadController::Reset() { | 148 void GamepadController::Reset() { |
149 memset(&gamepads_, 0, sizeof(gamepads_)); | 149 memset(&gamepads_, 0, sizeof(gamepads_)); |
150 } | 150 } |
151 | 151 |
152 void GamepadController::Install(WebFrame* frame) { | 152 void GamepadController::Install(WebFrame* frame) { |
153 GamepadControllerBindings::Install(weak_factory_.GetWeakPtr(), frame); | 153 GamepadControllerBindings::Install(weak_factory_.GetWeakPtr(), frame); |
154 } | 154 } |
155 | 155 |
156 void GamepadController::SetDelegate(WebTestDelegate* delegate) { | 156 void GamepadController::SetDelegate(WebTestDelegate* delegate) { |
157 if (!delegate) | 157 if (!delegate) |
158 return; | 158 return; |
159 delegate->setGamepadProvider(this); | 159 delegate->setGamepadProvider(this); |
160 } | 160 } |
161 | 161 |
162 void GamepadController::SampleGamepads(blink::WebGamepads& gamepads) { | 162 void GamepadController::SampleGamepads(blink::WebGamepads& gamepads) { |
163 memcpy(&gamepads, &gamepads_, sizeof(blink::WebGamepads)); | 163 memcpy(&gamepads, &gamepads_, sizeof(blink::WebGamepads)); |
164 } | 164 } |
165 | 165 |
166 void GamepadController::SetGamepadListener( | 166 bool GamepadController::OnControlMessageReceived(const IPC::Message& msg) { |
167 blink::WebGamepadListener* listener) { | 167 return false; |
168 listener_ = listener; | 168 } |
| 169 |
| 170 void GamepadController::SendStartMessage() { |
| 171 } |
| 172 |
| 173 void GamepadController::SendStopMessage() { |
169 } | 174 } |
170 | 175 |
171 void GamepadController::Connect(int index) { | 176 void GamepadController::Connect(int index) { |
172 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) | 177 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) |
173 return; | 178 return; |
174 gamepads_.items[index].connected = true; | 179 gamepads_.items[index].connected = true; |
175 gamepads_.length = 0; | 180 gamepads_.length = 0; |
176 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { | 181 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { |
177 if (gamepads_.items[i].connected) | 182 if (gamepads_.items[i].connected) |
178 gamepads_.length = i + 1; | 183 gamepads_.length = i + 1; |
179 } | 184 } |
180 } | 185 } |
181 | 186 |
182 void GamepadController::DispatchConnected(int index) { | 187 void GamepadController::DispatchConnected(int index) { |
183 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap) | 188 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap) |
184 || !gamepads_.items[index].connected) | 189 || !gamepads_.items[index].connected) |
185 return; | 190 return; |
186 const WebGamepad& pad = gamepads_.items[index]; | 191 const WebGamepad& pad = gamepads_.items[index]; |
187 if (listener_) | 192 if (listener()) |
188 listener_->didConnectGamepad(index, pad); | 193 listener()->didConnectGamepad(index, pad); |
189 } | 194 } |
190 | 195 |
191 void GamepadController::Disconnect(int index) { | 196 void GamepadController::Disconnect(int index) { |
192 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) | 197 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) |
193 return; | 198 return; |
194 WebGamepad& pad = gamepads_.items[index]; | 199 WebGamepad& pad = gamepads_.items[index]; |
195 pad.connected = false; | 200 pad.connected = false; |
196 gamepads_.length = 0; | 201 gamepads_.length = 0; |
197 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { | 202 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { |
198 if (gamepads_.items[i].connected) | 203 if (gamepads_.items[i].connected) |
199 gamepads_.length = i + 1; | 204 gamepads_.length = i + 1; |
200 } | 205 } |
201 if (listener_) | 206 if (listener()) |
202 listener_->didDisconnectGamepad(index, pad); | 207 listener()->didDisconnectGamepad(index, pad); |
203 } | 208 } |
204 | 209 |
205 void GamepadController::SetId(int index, const std::string& src) { | 210 void GamepadController::SetId(int index, const std::string& src) { |
206 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) | 211 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) |
207 return; | 212 return; |
208 const char* p = src.c_str(); | 213 const char* p = src.c_str(); |
209 memset(gamepads_.items[index].id, 0, sizeof(gamepads_.items[index].id)); | 214 memset(gamepads_.items[index].id, 0, sizeof(gamepads_.items[index].id)); |
210 for (unsigned i = 0; *p && i < WebGamepad::idLengthCap - 1; ++i) | 215 for (unsigned i = 0; *p && i < WebGamepad::idLengthCap - 1; ++i) |
211 gamepads_.items[index].id[i] = *p++; | 216 gamepads_.items[index].id[i] = *p++; |
212 } | 217 } |
(...skipping 25 matching lines...) Expand all Loading... |
238 | 243 |
239 void GamepadController::SetAxisData(int index, int axis, double data) { | 244 void GamepadController::SetAxisData(int index, int axis, double data) { |
240 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) | 245 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) |
241 return; | 246 return; |
242 if (axis < 0 || axis >= static_cast<int>(WebGamepad::axesLengthCap)) | 247 if (axis < 0 || axis >= static_cast<int>(WebGamepad::axesLengthCap)) |
243 return; | 248 return; |
244 gamepads_.items[index].axes[axis] = data; | 249 gamepads_.items[index].axes[axis] = data; |
245 } | 250 } |
246 | 251 |
247 } // namespace content | 252 } // namespace content |
OLD | NEW |