| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, Google Inc. All rights reserved. | 2 * Copyright (C) 2011, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are met: | 5 * modification, are permitted provided that the following conditions are met: |
| 6 * | 6 * |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "core/page/Page.h" | 33 #include "core/page/Page.h" |
| 34 #include "modules/gamepad/GamepadDispatcher.h" | 34 #include "modules/gamepad/GamepadDispatcher.h" |
| 35 #include "modules/gamepad/GamepadEvent.h" | 35 #include "modules/gamepad/GamepadEvent.h" |
| 36 #include "modules/gamepad/GamepadList.h" | 36 #include "modules/gamepad/GamepadList.h" |
| 37 #include "modules/gamepad/WebKitGamepadList.h" | 37 #include "modules/gamepad/WebKitGamepadList.h" |
| 38 #include "platform/RuntimeEnabledFeatures.h" | 38 #include "platform/RuntimeEnabledFeatures.h" |
| 39 | 39 |
| 40 namespace blink { | 40 namespace blink { |
| 41 | 41 |
| 42 template<typename T> | 42 template<typename T> |
| 43 static void sampleGamepad(unsigned index, T& gamepad, const blink::WebGamepad& w
ebGamepad) | 43 static void sampleGamepad(unsigned index, T& gamepad, const WebGamepad& webGamep
ad) |
| 44 { | 44 { |
| 45 gamepad.setId(webGamepad.id); | 45 gamepad.setId(webGamepad.id); |
| 46 gamepad.setIndex(index); | 46 gamepad.setIndex(index); |
| 47 gamepad.setConnected(webGamepad.connected); | 47 gamepad.setConnected(webGamepad.connected); |
| 48 gamepad.setTimestamp(webGamepad.timestamp); | 48 gamepad.setTimestamp(webGamepad.timestamp); |
| 49 gamepad.setMapping(webGamepad.mapping); | 49 gamepad.setMapping(webGamepad.mapping); |
| 50 gamepad.setAxes(webGamepad.axesLength, webGamepad.axes); | 50 gamepad.setAxes(webGamepad.axesLength, webGamepad.axes); |
| 51 gamepad.setButtons(webGamepad.buttonsLength, webGamepad.buttons); | 51 gamepad.setButtons(webGamepad.buttonsLength, webGamepad.buttons); |
| 52 } | 52 } |
| 53 | 53 |
| 54 template<typename GamepadType, typename ListType> | 54 template<typename GamepadType, typename ListType> |
| 55 static void sampleGamepads(ListType* into) | 55 static void sampleGamepads(ListType* into) |
| 56 { | 56 { |
| 57 blink::WebGamepads gamepads; | 57 WebGamepads gamepads; |
| 58 | 58 |
| 59 GamepadDispatcher::instance().sampleGamepads(gamepads); | 59 GamepadDispatcher::instance().sampleGamepads(gamepads); |
| 60 | 60 |
| 61 for (unsigned i = 0; i < blink::WebGamepads::itemsLengthCap; ++i) { | 61 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { |
| 62 blink::WebGamepad& webGamepad = gamepads.items[i]; | 62 WebGamepad& webGamepad = gamepads.items[i]; |
| 63 if (i < gamepads.length && webGamepad.connected) { | 63 if (i < gamepads.length && webGamepad.connected) { |
| 64 GamepadType* gamepad = into->item(i); | 64 GamepadType* gamepad = into->item(i); |
| 65 if (!gamepad) | 65 if (!gamepad) |
| 66 gamepad = GamepadType::create(); | 66 gamepad = GamepadType::create(); |
| 67 sampleGamepad(i, *gamepad, webGamepad); | 67 sampleGamepad(i, *gamepad, webGamepad); |
| 68 into->set(i, gamepad); | 68 into->set(i, gamepad); |
| 69 } else { | 69 } else { |
| 70 into->set(i, 0); | 70 into->set(i, 0); |
| 71 } | 71 } |
| 72 } | 72 } |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 if (!visible || !m_hasEventListener) | 264 if (!visible || !m_hasEventListener) |
| 265 return; | 265 return; |
| 266 | 266 |
| 267 // Tell the page what has changed. m_gamepads contains the state before we b
ecame hidden. | 267 // Tell the page what has changed. m_gamepads contains the state before we b
ecame hidden. |
| 268 // We create a new snapshot and compare them. | 268 // We create a new snapshot and compare them. |
| 269 GamepadList* oldGamepads = m_gamepads.release(); | 269 GamepadList* oldGamepads = m_gamepads.release(); |
| 270 gamepads(); | 270 gamepads(); |
| 271 GamepadList* newGamepads = m_gamepads.get(); | 271 GamepadList* newGamepads = m_gamepads.get(); |
| 272 ASSERT(newGamepads); | 272 ASSERT(newGamepads); |
| 273 | 273 |
| 274 for (unsigned i = 0; i < blink::WebGamepads::itemsLengthCap; ++i) { | 274 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { |
| 275 Gamepad* oldGamepad = oldGamepads ? oldGamepads->item(i) : 0; | 275 Gamepad* oldGamepad = oldGamepads ? oldGamepads->item(i) : 0; |
| 276 Gamepad* newGamepad = newGamepads->item(i); | 276 Gamepad* newGamepad = newGamepads->item(i); |
| 277 bool oldWasConnected = oldGamepad && oldGamepad->connected(); | 277 bool oldWasConnected = oldGamepad && oldGamepad->connected(); |
| 278 bool newIsConnected = newGamepad && newGamepad->connected(); | 278 bool newIsConnected = newGamepad && newGamepad->connected(); |
| 279 bool connectedGamepadChanged = oldWasConnected && newIsConnected && oldG
amepad->id() != newGamepad->id(); | 279 bool connectedGamepadChanged = oldWasConnected && newIsConnected && oldG
amepad->id() != newGamepad->id(); |
| 280 if (connectedGamepadChanged || (oldWasConnected && !newIsConnected)) { | 280 if (connectedGamepadChanged || (oldWasConnected && !newIsConnected)) { |
| 281 oldGamepad->setConnected(false); | 281 oldGamepad->setConnected(false); |
| 282 m_pendingEvents.append(oldGamepad); | 282 m_pendingEvents.append(oldGamepad); |
| 283 } | 283 } |
| 284 if (connectedGamepadChanged || (!oldWasConnected && newIsConnected)) { | 284 if (connectedGamepadChanged || (!oldWasConnected && newIsConnected)) { |
| 285 m_pendingEvents.append(newGamepad); | 285 m_pendingEvents.append(newGamepad); |
| 286 } | 286 } |
| 287 } | 287 } |
| 288 | 288 |
| 289 if (!m_pendingEvents.isEmpty()) | 289 if (!m_pendingEvents.isEmpty()) |
| 290 m_dispatchOneEventRunner.runAsync(); | 290 m_dispatchOneEventRunner.runAsync(); |
| 291 } | 291 } |
| 292 | 292 |
| 293 } // namespace blink | 293 } // namespace blink |
| OLD | NEW |