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

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

Issue 446603002: Refactor code listening to platform events in content/renderer/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webkitplatform_impl_start_stop
Patch Set: rebase 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
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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 void GamepadControllerBindings::SetAxisCount(int index, int axes) { 129 void GamepadControllerBindings::SetAxisCount(int index, int axes) {
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 // static
140 base::WeakPtr<GamepadController> GamepadController::Create(WebTestDelegate* dele gate) {
141 CHECK(delegate);
142
143 GamepadController* controller = new GamepadController();
144 delegate->setGamepadProvider(scoped_ptr<RendererGamepadProvider>(controller));
145 return controller->weak_factory_.GetWeakPtr();
146 }
147
139 GamepadController::GamepadController() 148 GamepadController::GamepadController()
140 : listener_(NULL), 149 : RendererGamepadProvider(0),
141 weak_factory_(this) { 150 weak_factory_(this) {
142 Reset(); 151 Reset();
143 } 152 }
144 153
145 GamepadController::~GamepadController() {} 154 GamepadController::~GamepadController() {}
146 155
147 void GamepadController::Reset() { 156 void GamepadController::Reset() {
148 memset(&gamepads_, 0, sizeof(gamepads_)); 157 memset(&gamepads_, 0, sizeof(gamepads_));
149 } 158 }
150 159
151 void GamepadController::Install(WebFrame* frame) { 160 void GamepadController::Install(WebFrame* frame) {
152 GamepadControllerBindings::Install(weak_factory_.GetWeakPtr(), frame); 161 GamepadControllerBindings::Install(weak_factory_.GetWeakPtr(), frame);
153 } 162 }
154 163
155 void GamepadController::SetDelegate(WebTestDelegate* delegate) {
156 if (!delegate)
157 return;
158 delegate->setGamepadProvider(this);
159 }
160 164
161 void GamepadController::SampleGamepads(blink::WebGamepads& gamepads) { 165 void GamepadController::SampleGamepads(blink::WebGamepads& gamepads) {
162 memcpy(&gamepads, &gamepads_, sizeof(blink::WebGamepads)); 166 memcpy(&gamepads, &gamepads_, sizeof(blink::WebGamepads));
163 } 167 }
164 168
165 void GamepadController::SetGamepadListener( 169 bool GamepadController::OnControlMessageReceived(const IPC::Message& msg) {
166 blink::WebGamepadListener* listener) { 170 return false;
167 listener_ = listener; 171 }
172
173 void GamepadController::SendStartMessage() {
174 }
175
176 void GamepadController::SendStopMessage() {
168 } 177 }
169 178
170 void GamepadController::Connect(int index) { 179 void GamepadController::Connect(int index) {
171 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) 180 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap))
172 return; 181 return;
173 gamepads_.items[index].connected = true; 182 gamepads_.items[index].connected = true;
174 gamepads_.length = 0; 183 gamepads_.length = 0;
175 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { 184 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) {
176 if (gamepads_.items[i].connected) 185 if (gamepads_.items[i].connected)
177 gamepads_.length = i + 1; 186 gamepads_.length = i + 1;
178 } 187 }
179 } 188 }
180 189
181 void GamepadController::DispatchConnected(int index) { 190 void GamepadController::DispatchConnected(int index) {
182 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap) 191 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)
183 || !gamepads_.items[index].connected) 192 || !gamepads_.items[index].connected)
184 return; 193 return;
185 const WebGamepad& pad = gamepads_.items[index]; 194 const WebGamepad& pad = gamepads_.items[index];
186 if (listener_) 195 if (listener())
187 listener_->didConnectGamepad(index, pad); 196 listener()->didConnectGamepad(index, pad);
188 } 197 }
189 198
190 void GamepadController::Disconnect(int index) { 199 void GamepadController::Disconnect(int index) {
191 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) 200 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap))
192 return; 201 return;
193 WebGamepad& pad = gamepads_.items[index]; 202 WebGamepad& pad = gamepads_.items[index];
194 pad.connected = false; 203 pad.connected = false;
195 gamepads_.length = 0; 204 gamepads_.length = 0;
196 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { 205 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) {
197 if (gamepads_.items[i].connected) 206 if (gamepads_.items[i].connected)
198 gamepads_.length = i + 1; 207 gamepads_.length = i + 1;
199 } 208 }
200 if (listener_) 209 if (listener())
201 listener_->didDisconnectGamepad(index, pad); 210 listener()->didDisconnectGamepad(index, pad);
202 } 211 }
203 212
204 void GamepadController::SetId(int index, const std::string& src) { 213 void GamepadController::SetId(int index, const std::string& src) {
205 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) 214 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap))
206 return; 215 return;
207 const char* p = src.c_str(); 216 const char* p = src.c_str();
208 memset(gamepads_.items[index].id, 0, sizeof(gamepads_.items[index].id)); 217 memset(gamepads_.items[index].id, 0, sizeof(gamepads_.items[index].id));
209 for (unsigned i = 0; *p && i < WebGamepad::idLengthCap - 1; ++i) 218 for (unsigned i = 0; *p && i < WebGamepad::idLengthCap - 1; ++i)
210 gamepads_.items[index].id[i] = *p++; 219 gamepads_.items[index].id[i] = *p++;
211 } 220 }
(...skipping 25 matching lines...) Expand all
237 246
238 void GamepadController::SetAxisData(int index, int axis, double data) { 247 void GamepadController::SetAxisData(int index, int axis, double data) {
239 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) 248 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap))
240 return; 249 return;
241 if (axis < 0 || axis >= static_cast<int>(WebGamepad::axesLengthCap)) 250 if (axis < 0 || axis >= static_cast<int>(WebGamepad::axesLengthCap))
242 return; 251 return;
243 gamepads_.items[index].axes[axis] = data; 252 gamepads_.items[index].axes[axis] = data;
244 } 253 }
245 254
246 } // namespace content 255 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/renderer/test_runner/gamepad_controller.h ('k') | content/shell/renderer/test_runner/test_interfaces.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698