| 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 20 matching lines...) Expand all Loading... |
| 31 private: | 31 private: |
| 32 explicit GamepadControllerBindings( | 32 explicit GamepadControllerBindings( |
| 33 base::WeakPtr<GamepadController> controller); | 33 base::WeakPtr<GamepadController> controller); |
| 34 virtual ~GamepadControllerBindings(); | 34 virtual ~GamepadControllerBindings(); |
| 35 | 35 |
| 36 // gin::Wrappable. | 36 // gin::Wrappable. |
| 37 virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder( | 37 virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder( |
| 38 v8::Isolate* isolate) OVERRIDE; | 38 v8::Isolate* isolate) OVERRIDE; |
| 39 | 39 |
| 40 void Connect(int index); | 40 void Connect(int index); |
| 41 void DispatchConnected(int index); |
| 41 void Disconnect(int index); | 42 void Disconnect(int index); |
| 42 void SetId(int index, const std::string& src); | 43 void SetId(int index, const std::string& src); |
| 43 void SetButtonCount(int index, int buttons); | 44 void SetButtonCount(int index, int buttons); |
| 44 void SetButtonData(int index, int button, double data); | 45 void SetButtonData(int index, int button, double data); |
| 45 void SetAxisCount(int index, int axes); | 46 void SetAxisCount(int index, int axes); |
| 46 void SetAxisData(int index, int axis, double data); | 47 void SetAxisData(int index, int axis, double data); |
| 47 | 48 |
| 48 base::WeakPtr<GamepadController> controller_; | 49 base::WeakPtr<GamepadController> controller_; |
| 49 | 50 |
| 50 DISALLOW_COPY_AND_ASSIGN(GamepadControllerBindings); | 51 DISALLOW_COPY_AND_ASSIGN(GamepadControllerBindings); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 75 base::WeakPtr<GamepadController> controller) | 76 base::WeakPtr<GamepadController> controller) |
| 76 : controller_(controller) {} | 77 : controller_(controller) {} |
| 77 | 78 |
| 78 GamepadControllerBindings::~GamepadControllerBindings() {} | 79 GamepadControllerBindings::~GamepadControllerBindings() {} |
| 79 | 80 |
| 80 gin::ObjectTemplateBuilder GamepadControllerBindings::GetObjectTemplateBuilder( | 81 gin::ObjectTemplateBuilder GamepadControllerBindings::GetObjectTemplateBuilder( |
| 81 v8::Isolate* isolate) { | 82 v8::Isolate* isolate) { |
| 82 return gin::Wrappable<GamepadControllerBindings>::GetObjectTemplateBuilder( | 83 return gin::Wrappable<GamepadControllerBindings>::GetObjectTemplateBuilder( |
| 83 isolate) | 84 isolate) |
| 84 .SetMethod("connect", &GamepadControllerBindings::Connect) | 85 .SetMethod("connect", &GamepadControllerBindings::Connect) |
| 86 .SetMethod("dispatchConnected", &GamepadControllerBindings::DispatchConnec
ted) |
| 85 .SetMethod("disconnect", &GamepadControllerBindings::Disconnect) | 87 .SetMethod("disconnect", &GamepadControllerBindings::Disconnect) |
| 86 .SetMethod("setId", &GamepadControllerBindings::SetId) | 88 .SetMethod("setId", &GamepadControllerBindings::SetId) |
| 87 .SetMethod("setButtonCount", &GamepadControllerBindings::SetButtonCount) | 89 .SetMethod("setButtonCount", &GamepadControllerBindings::SetButtonCount) |
| 88 .SetMethod("setButtonData", &GamepadControllerBindings::SetButtonData) | 90 .SetMethod("setButtonData", &GamepadControllerBindings::SetButtonData) |
| 89 .SetMethod("setAxisCount", &GamepadControllerBindings::SetAxisCount) | 91 .SetMethod("setAxisCount", &GamepadControllerBindings::SetAxisCount) |
| 90 .SetMethod("setAxisData", &GamepadControllerBindings::SetAxisData); | 92 .SetMethod("setAxisData", &GamepadControllerBindings::SetAxisData); |
| 91 } | 93 } |
| 92 | 94 |
| 93 void GamepadControllerBindings::Connect(int index) { | 95 void GamepadControllerBindings::Connect(int index) { |
| 94 if (controller_) | 96 if (controller_) |
| 95 controller_->Connect(index); | 97 controller_->Connect(index); |
| 96 } | 98 } |
| 97 | 99 |
| 100 void GamepadControllerBindings::DispatchConnected(int index) { |
| 101 if (controller_) |
| 102 controller_->DispatchConnected(index); |
| 103 } |
| 104 |
| 98 void GamepadControllerBindings::Disconnect(int index) { | 105 void GamepadControllerBindings::Disconnect(int index) { |
| 99 if (controller_) | 106 if (controller_) |
| 100 controller_->Disconnect(index); | 107 controller_->Disconnect(index); |
| 101 } | 108 } |
| 102 | 109 |
| 103 void GamepadControllerBindings::SetId(int index, const std::string& src) { | 110 void GamepadControllerBindings::SetId(int index, const std::string& src) { |
| 104 if (controller_) | 111 if (controller_) |
| 105 controller_->SetId(index, src); | 112 controller_->SetId(index, src); |
| 106 } | 113 } |
| 107 | 114 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 gamepads_.items[index].connected = true; | 158 gamepads_.items[index].connected = true; |
| 152 gamepads_.length = 0; | 159 gamepads_.length = 0; |
| 153 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { | 160 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { |
| 154 if (gamepads_.items[i].connected) | 161 if (gamepads_.items[i].connected) |
| 155 gamepads_.length = i + 1; | 162 gamepads_.length = i + 1; |
| 156 } | 163 } |
| 157 if (delegate_) | 164 if (delegate_) |
| 158 delegate_->setGamepadData(gamepads_); | 165 delegate_->setGamepadData(gamepads_); |
| 159 } | 166 } |
| 160 | 167 |
| 168 void GamepadController::DispatchConnected(int index) { |
| 169 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) |
| 170 return; |
| 171 const WebGamepad& pad = gamepads_.items[index]; |
| 172 if (pad.connected && delegate_) |
| 173 delegate_->didConnectGamepad(index, pad); |
| 174 } |
| 175 |
| 161 void GamepadController::Disconnect(int index) { | 176 void GamepadController::Disconnect(int index) { |
| 162 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) | 177 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) |
| 163 return; | 178 return; |
| 164 gamepads_.items[index].connected = false; | 179 WebGamepad& pad = gamepads_.items[index]; |
| 180 pad.connected = false; |
| 165 gamepads_.length = 0; | 181 gamepads_.length = 0; |
| 166 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { | 182 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { |
| 167 if (gamepads_.items[i].connected) | 183 if (gamepads_.items[i].connected) |
| 168 gamepads_.length = i + 1; | 184 gamepads_.length = i + 1; |
| 169 } | 185 } |
| 170 if (delegate_) | 186 if (delegate_) { |
| 171 delegate_->setGamepadData(gamepads_); | 187 delegate_->setGamepadData(gamepads_); |
| 188 delegate_->didDisconnectGamepad(index, pad); |
| 189 } |
| 172 } | 190 } |
| 173 | 191 |
| 174 void GamepadController::SetId(int index, const std::string& src) { | 192 void GamepadController::SetId(int index, const std::string& src) { |
| 175 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) | 193 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) |
| 176 return; | 194 return; |
| 177 const char* p = src.c_str(); | 195 const char* p = src.c_str(); |
| 178 memset(gamepads_.items[index].id, 0, sizeof(gamepads_.items[index].id)); | 196 memset(gamepads_.items[index].id, 0, sizeof(gamepads_.items[index].id)); |
| 179 for (unsigned i = 0; *p && i < WebGamepad::idLengthCap - 1; ++i) | 197 for (unsigned i = 0; *p && i < WebGamepad::idLengthCap - 1; ++i) |
| 180 gamepads_.items[index].id[i] = *p++; | 198 gamepads_.items[index].id[i] = *p++; |
| 181 if (delegate_) | 199 if (delegate_) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) | 235 if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) |
| 218 return; | 236 return; |
| 219 if (axis < 0 || axis >= static_cast<int>(WebGamepad::axesLengthCap)) | 237 if (axis < 0 || axis >= static_cast<int>(WebGamepad::axesLengthCap)) |
| 220 return; | 238 return; |
| 221 gamepads_.items[index].axes[axis] = data; | 239 gamepads_.items[index].axes[axis] = data; |
| 222 if (delegate_) | 240 if (delegate_) |
| 223 delegate_->setGamepadData(gamepads_); | 241 delegate_->setGamepadData(gamepads_); |
| 224 } | 242 } |
| 225 | 243 |
| 226 } // namespace content | 244 } // namespace content |
| OLD | NEW |