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

Side by Side Diff: content/shell/renderer/test_runner/gamepad_controller.cc

Issue 470683002: Revert "Refactor code listening to platform events in content/renderer/." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/WebTestDelegate.h" 7 #include "content/shell/renderer/test_runner/WebTestDelegate.h"
8 #include "gin/arguments.h" 8 #include "gin/arguments.h"
9 #include "gin/handle.h" 9 #include "gin/handle.h"
10 #include "gin/object_template_builder.h" 10 #include "gin/object_template_builder.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 if (controller_) 130 if (controller_)
131 controller_->SetAxisCount(index, axes); 131 controller_->SetAxisCount(index, axes);
132 } 132 }
133 133
134 void GamepadControllerBindings::SetAxisData(int index, int axis, double data) { 134 void GamepadControllerBindings::SetAxisData(int index, int axis, double data) {
135 if (controller_) 135 if (controller_)
136 controller_->SetAxisData(index, axis, data); 136 controller_->SetAxisData(index, axis, data);
137 } 137 }
138 138
139 GamepadController::GamepadController() 139 GamepadController::GamepadController()
140 : RendererGamepadProvider(0), 140 : listener_(NULL),
141 weak_factory_(this) { 141 weak_factory_(this) {
142 Reset(); 142 Reset();
143 } 143 }
144 144
145 GamepadController::~GamepadController() {} 145 GamepadController::~GamepadController() {}
146 146
147 void GamepadController::Reset() { 147 void GamepadController::Reset() {
148 memset(&gamepads_, 0, sizeof(gamepads_)); 148 memset(&gamepads_, 0, sizeof(gamepads_));
149 } 149 }
150 150
151 void GamepadController::Install(WebFrame* frame) { 151 void GamepadController::Install(WebFrame* frame) {
152 GamepadControllerBindings::Install(weak_factory_.GetWeakPtr(), frame); 152 GamepadControllerBindings::Install(weak_factory_.GetWeakPtr(), frame);
153 } 153 }
154 154
155 void GamepadController::SetDelegate(WebTestDelegate* delegate) { 155 void GamepadController::SetDelegate(WebTestDelegate* delegate) {
156 if (!delegate) 156 if (!delegate)
157 return; 157 return;
158 delegate->setGamepadProvider(this); 158 delegate->setGamepadProvider(this);
159 } 159 }
160 160
161 void GamepadController::SampleGamepads(blink::WebGamepads& gamepads) { 161 void GamepadController::SampleGamepads(blink::WebGamepads& gamepads) {
162 memcpy(&gamepads, &gamepads_, sizeof(blink::WebGamepads)); 162 memcpy(&gamepads, &gamepads_, sizeof(blink::WebGamepads));
163 } 163 }
164 164
165 bool GamepadController::OnControlMessageReceived(const IPC::Message& msg) { 165 void GamepadController::SetGamepadListener(
166 return false; 166 blink::WebGamepadListener* listener) {
167 } 167 listener_ = listener;
168
169 void GamepadController::SendStartMessage() {
170 }
171
172 void GamepadController::SendStopMessage() {
173 } 168 }
174 169
175 void GamepadController::Connect(int index) { 170 void GamepadController::Connect(int index) {
176 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) 171 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap))
177 return; 172 return;
178 gamepads_.items[index].connected = true; 173 gamepads_.items[index].connected = true;
179 gamepads_.length = 0; 174 gamepads_.length = 0;
180 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { 175 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) {
181 if (gamepads_.items[i].connected) 176 if (gamepads_.items[i].connected)
182 gamepads_.length = i + 1; 177 gamepads_.length = i + 1;
183 } 178 }
184 } 179 }
185 180
186 void GamepadController::DispatchConnected(int index) { 181 void GamepadController::DispatchConnected(int index) {
187 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap) 182 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)
188 || !gamepads_.items[index].connected) 183 || !gamepads_.items[index].connected)
189 return; 184 return;
190 const WebGamepad& pad = gamepads_.items[index]; 185 const WebGamepad& pad = gamepads_.items[index];
191 if (listener()) 186 if (listener_)
192 listener()->didConnectGamepad(index, pad); 187 listener_->didConnectGamepad(index, pad);
193 } 188 }
194 189
195 void GamepadController::Disconnect(int index) { 190 void GamepadController::Disconnect(int index) {
196 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) 191 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap))
197 return; 192 return;
198 WebGamepad& pad = gamepads_.items[index]; 193 WebGamepad& pad = gamepads_.items[index];
199 pad.connected = false; 194 pad.connected = false;
200 gamepads_.length = 0; 195 gamepads_.length = 0;
201 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { 196 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) {
202 if (gamepads_.items[i].connected) 197 if (gamepads_.items[i].connected)
203 gamepads_.length = i + 1; 198 gamepads_.length = i + 1;
204 } 199 }
205 if (listener()) 200 if (listener_)
206 listener()->didDisconnectGamepad(index, pad); 201 listener_->didDisconnectGamepad(index, pad);
207 } 202 }
208 203
209 void GamepadController::SetId(int index, const std::string& src) { 204 void GamepadController::SetId(int index, const std::string& src) {
210 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) 205 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap))
211 return; 206 return;
212 const char* p = src.c_str(); 207 const char* p = src.c_str();
213 memset(gamepads_.items[index].id, 0, sizeof(gamepads_.items[index].id)); 208 memset(gamepads_.items[index].id, 0, sizeof(gamepads_.items[index].id));
214 for (unsigned i = 0; *p && i < WebGamepad::idLengthCap - 1; ++i) 209 for (unsigned i = 0; *p && i < WebGamepad::idLengthCap - 1; ++i)
215 gamepads_.items[index].id[i] = *p++; 210 gamepads_.items[index].id[i] = *p++;
216 } 211 }
(...skipping 25 matching lines...) Expand all
242 237
243 void GamepadController::SetAxisData(int index, int axis, double data) { 238 void GamepadController::SetAxisData(int index, int axis, double data) {
244 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) 239 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap))
245 return; 240 return;
246 if (axis < 0 || axis >= static_cast<int>(WebGamepad::axesLengthCap)) 241 if (axis < 0 || axis >= static_cast<int>(WebGamepad::axesLengthCap))
247 return; 242 return;
248 gamepads_.items[index].axes[axis] = data; 243 gamepads_.items[index].axes[axis] = data;
249 } 244 }
250 245
251 } // namespace content 246 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/renderer/test_runner/gamepad_controller.h ('k') | content/test/layouttest_support.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698