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

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

Issue 2707183003: Move //components/test_runner back into //content/shell (Closed)
Patch Set: Trim DEPS Created 3 years, 10 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 "components/test_runner/gamepad_controller.h" 5 #include "content/shell/test_runner/gamepad_controller.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "components/test_runner/web_test_delegate.h" 10 #include "content/shell/test_runner/web_test_delegate.h"
11 #include "gin/arguments.h" 11 #include "gin/arguments.h"
12 #include "gin/handle.h" 12 #include "gin/handle.h"
13 #include "gin/object_template_builder.h" 13 #include "gin/object_template_builder.h"
14 #include "gin/wrappable.h" 14 #include "gin/wrappable.h"
15 #include "third_party/WebKit/public/platform/WebGamepadListener.h" 15 #include "third_party/WebKit/public/platform/WebGamepadListener.h"
16 #include "third_party/WebKit/public/web/WebFrame.h" 16 #include "third_party/WebKit/public/web/WebFrame.h"
17 #include "third_party/WebKit/public/web/WebKit.h" 17 #include "third_party/WebKit/public/web/WebKit.h"
18 #include "v8/include/v8.h" 18 #include "v8/include/v8.h"
19 19
20 using blink::WebFrame; 20 using blink::WebFrame;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 GamepadController* controller = new GamepadController(); 148 GamepadController* controller = new GamepadController();
149 delegate->SetGamepadProvider(controller); 149 delegate->SetGamepadProvider(controller);
150 return controller->weak_factory_.GetWeakPtr(); 150 return controller->weak_factory_.GetWeakPtr();
151 } 151 }
152 152
153 GamepadController::GamepadController() 153 GamepadController::GamepadController()
154 : listener_(nullptr), weak_factory_(this) { 154 : listener_(nullptr), weak_factory_(this) {
155 Reset(); 155 Reset();
156 } 156 }
157 157
158 GamepadController::~GamepadController() { 158 GamepadController::~GamepadController() {}
159 }
160 159
161 void GamepadController::Reset() { 160 void GamepadController::Reset() {
162 memset(&gamepads_, 0, sizeof(gamepads_)); 161 memset(&gamepads_, 0, sizeof(gamepads_));
163 } 162 }
164 163
165 void GamepadController::Install(WebFrame* frame) { 164 void GamepadController::Install(WebFrame* frame) {
166 GamepadControllerBindings::Install(weak_factory_.GetWeakPtr(), frame); 165 GamepadControllerBindings::Install(weak_factory_.GetWeakPtr(), frame);
167 } 166 }
168 167
169 void GamepadController::SampleGamepads(blink::WebGamepads& gamepads) { 168 void GamepadController::SampleGamepads(blink::WebGamepads& gamepads) {
170 memcpy(&gamepads, &gamepads_, sizeof(blink::WebGamepads)); 169 memcpy(&gamepads, &gamepads_, sizeof(blink::WebGamepads));
171 } 170 }
172 171
173 void GamepadController::SetListener(blink::WebGamepadListener* listener) { 172 void GamepadController::SetListener(blink::WebGamepadListener* listener) {
174 listener_ = listener; 173 listener_ = listener;
175 } 174 }
176 175
177 void GamepadController::Connect(int index) { 176 void GamepadController::Connect(int index) {
178 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) 177 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap))
179 return; 178 return;
180 gamepads_.items[index].connected = true; 179 gamepads_.items[index].connected = true;
181 } 180 }
182 181
183 void GamepadController::DispatchConnected(int index) { 182 void GamepadController::DispatchConnected(int index) {
184 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap) 183 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap) ||
185 || !gamepads_.items[index].connected) 184 !gamepads_.items[index].connected)
186 return; 185 return;
187 const WebGamepad& pad = gamepads_.items[index]; 186 const WebGamepad& pad = gamepads_.items[index];
188 if (listener_) 187 if (listener_)
189 listener_->didConnectGamepad(index, pad); 188 listener_->didConnectGamepad(index, pad);
190 } 189 }
191 190
192 void GamepadController::Disconnect(int index) { 191 void GamepadController::Disconnect(int index) {
193 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) 192 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap))
194 return; 193 return;
195 WebGamepad& pad = gamepads_.items[index]; 194 WebGamepad& pad = gamepads_.items[index];
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 233
235 void GamepadController::SetAxisData(int index, int axis, double data) { 234 void GamepadController::SetAxisData(int index, int axis, double data) {
236 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) 235 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap))
237 return; 236 return;
238 if (axis < 0 || axis >= static_cast<int>(WebGamepad::axesLengthCap)) 237 if (axis < 0 || axis >= static_cast<int>(WebGamepad::axesLengthCap))
239 return; 238 return;
240 gamepads_.items[index].axes[axis] = data; 239 gamepads_.items[index].axes[axis] = data;
241 } 240 }
242 241
243 } // namespace test_runner 242 } // namespace test_runner
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698