| 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 11 matching lines...) Expand all Loading... |
| 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
| 23 * DAMAGE. | 23 * DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "modules/gamepad/NavigatorGamepad.h" | 26 #include "modules/gamepad/NavigatorGamepad.h" |
| 27 | 27 |
| 28 #include "core/dom/Document.h" | 28 #include "core/dom/Document.h" |
| 29 #include "core/frame/LocalFrame.h" | 29 #include "core/frame/LocalFrame.h" |
| 30 #include "core/frame/Navigator.h" | 30 #include "core/frame/Navigator.h" |
| 31 #include "core/page/Page.h" | 31 #include "core/page/Page.h" |
| 32 #include "device/gamepad/public/cpp/gamepad.h" |
| 32 #include "modules/gamepad/GamepadDispatcher.h" | 33 #include "modules/gamepad/GamepadDispatcher.h" |
| 33 #include "modules/gamepad/GamepadEvent.h" | 34 #include "modules/gamepad/GamepadEvent.h" |
| 34 #include "modules/gamepad/GamepadList.h" | 35 #include "modules/gamepad/GamepadList.h" |
| 35 | 36 |
| 36 namespace blink { | 37 namespace blink { |
| 37 | 38 |
| 38 template <typename T> | 39 template <typename T> |
| 39 static void SampleGamepad(unsigned index, | 40 static void SampleGamepad(unsigned index, |
| 40 T& gamepad, | 41 T& gamepad, |
| 41 const WebGamepad& web_gamepad) { | 42 const device::Gamepad& device_gamepad) { |
| 42 gamepad.SetId(web_gamepad.id); | 43 gamepad.SetId(device_gamepad.id); |
| 43 gamepad.SetIndex(index); | 44 gamepad.SetIndex(index); |
| 44 gamepad.SetConnected(web_gamepad.connected); | 45 gamepad.SetConnected(device_gamepad.connected); |
| 45 gamepad.SetTimestamp(web_gamepad.timestamp); | 46 gamepad.SetTimestamp(device_gamepad.timestamp); |
| 46 gamepad.SetMapping(web_gamepad.mapping); | 47 gamepad.SetMapping(device_gamepad.mapping); |
| 47 gamepad.SetAxes(web_gamepad.axes_length, web_gamepad.axes); | 48 gamepad.SetAxes(device_gamepad.axes_length, device_gamepad.axes); |
| 48 gamepad.SetButtons(web_gamepad.buttons_length, web_gamepad.buttons); | 49 gamepad.SetButtons(device_gamepad.buttons_length, device_gamepad.buttons); |
| 49 gamepad.SetPose(web_gamepad.pose); | 50 gamepad.SetPose(device_gamepad.pose); |
| 50 gamepad.SetHand(web_gamepad.hand); | 51 gamepad.SetHand(device_gamepad.hand); |
| 51 gamepad.SetDisplayId(web_gamepad.display_id); | 52 gamepad.SetDisplayId(device_gamepad.display_id); |
| 52 } | 53 } |
| 53 | 54 |
| 54 template <typename GamepadType, typename ListType> | 55 template <typename GamepadType, typename ListType> |
| 55 static void SampleGamepads(ListType* into) { | 56 static void SampleGamepads(ListType* into) { |
| 56 WebGamepads gamepads; | 57 device::Gamepads gamepads; |
| 57 | 58 |
| 58 GamepadDispatcher::Instance().SampleGamepads(gamepads); | 59 GamepadDispatcher::Instance().SampleGamepads(gamepads); |
| 59 | 60 |
| 60 for (unsigned i = 0; i < WebGamepads::kItemsLengthCap; ++i) { | 61 for (unsigned i = 0; i < device::Gamepads::kItemsLengthCap; ++i) { |
| 61 WebGamepad& web_gamepad = gamepads.items[i]; | 62 device::Gamepad& web_gamepad = gamepads.items[i]; |
| 62 if (web_gamepad.connected) { | 63 if (web_gamepad.connected) { |
| 63 GamepadType* gamepad = into->item(i); | 64 GamepadType* gamepad = into->item(i); |
| 64 if (!gamepad) | 65 if (!gamepad) |
| 65 gamepad = GamepadType::Create(); | 66 gamepad = GamepadType::Create(); |
| 66 SampleGamepad(i, *gamepad, web_gamepad); | 67 SampleGamepad(i, *gamepad, web_gamepad); |
| 67 into->Set(i, gamepad); | 68 into->Set(i, gamepad); |
| 68 } else { | 69 } else { |
| 69 into->Set(i, 0); | 70 into->Set(i, 0); |
| 70 } | 71 } |
| 71 } | 72 } |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 if (!visible || !has_event_listener_) | 248 if (!visible || !has_event_listener_) |
| 248 return; | 249 return; |
| 249 | 250 |
| 250 // Tell the page what has changed. m_gamepads contains the state before we | 251 // Tell the page what has changed. m_gamepads contains the state before we |
| 251 // became hidden. We create a new snapshot and compare them. | 252 // became hidden. We create a new snapshot and compare them. |
| 252 GamepadList* old_gamepads = gamepads_.Release(); | 253 GamepadList* old_gamepads = gamepads_.Release(); |
| 253 Gamepads(); | 254 Gamepads(); |
| 254 GamepadList* new_gamepads = gamepads_.Get(); | 255 GamepadList* new_gamepads = gamepads_.Get(); |
| 255 DCHECK(new_gamepads); | 256 DCHECK(new_gamepads); |
| 256 | 257 |
| 257 for (unsigned i = 0; i < WebGamepads::kItemsLengthCap; ++i) { | 258 for (unsigned i = 0; i < device::Gamepads::kItemsLengthCap; ++i) { |
| 258 Gamepad* old_gamepad = old_gamepads ? old_gamepads->item(i) : 0; | 259 Gamepad* old_gamepad = old_gamepads ? old_gamepads->item(i) : 0; |
| 259 Gamepad* new_gamepad = new_gamepads->item(i); | 260 Gamepad* new_gamepad = new_gamepads->item(i); |
| 260 bool old_was_connected = old_gamepad && old_gamepad->connected(); | 261 bool old_was_connected = old_gamepad && old_gamepad->connected(); |
| 261 bool new_is_connected = new_gamepad && new_gamepad->connected(); | 262 bool new_is_connected = new_gamepad && new_gamepad->connected(); |
| 262 bool connected_gamepad_changed = old_was_connected && new_is_connected && | 263 bool connected_gamepad_changed = old_was_connected && new_is_connected && |
| 263 old_gamepad->id() != new_gamepad->id(); | 264 old_gamepad->id() != new_gamepad->id(); |
| 264 if (connected_gamepad_changed || (old_was_connected && !new_is_connected)) { | 265 if (connected_gamepad_changed || (old_was_connected && !new_is_connected)) { |
| 265 old_gamepad->SetConnected(false); | 266 old_gamepad->SetConnected(false); |
| 266 pending_events_.push_back(old_gamepad); | 267 pending_events_.push_back(old_gamepad); |
| 267 } | 268 } |
| 268 if (connected_gamepad_changed || (!old_was_connected && new_is_connected)) { | 269 if (connected_gamepad_changed || (!old_was_connected && new_is_connected)) { |
| 269 pending_events_.push_back(new_gamepad); | 270 pending_events_.push_back(new_gamepad); |
| 270 } | 271 } |
| 271 } | 272 } |
| 272 | 273 |
| 273 if (!pending_events_.IsEmpty()) | 274 if (!pending_events_.IsEmpty()) |
| 274 dispatch_one_event_runner_->RunAsync(); | 275 dispatch_one_event_runner_->RunAsync(); |
| 275 } | 276 } |
| 276 | 277 |
| 277 } // namespace blink | 278 } // namespace blink |
| OLD | NEW |