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

Side by Side Diff: Source/modules/gamepad/NavigatorGamepad.cpp

Issue 183313003: Added non-prefixed navigator.getGamepads() with updated API (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « Source/modules/gamepad/NavigatorGamepad.h ('k') | Source/modules/gamepad/NavigatorGamepad.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10 matching lines...) Expand all
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
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 "config.h" 26 #include "config.h"
27 #include "modules/gamepad/NavigatorGamepad.h" 27 #include "modules/gamepad/NavigatorGamepad.h"
28 28
29 #include "core/frame/Navigator.h" 29 #include "core/frame/Navigator.h"
30 #include "modules/gamepad/GamepadList.h" 30 #include "modules/gamepad/GamepadList.h"
31 #include "modules/gamepad/WebKitGamepadList.h"
31 #include "public/platform/Platform.h" 32 #include "public/platform/Platform.h"
32 #include "wtf/PassOwnPtr.h" 33 #include "wtf/PassOwnPtr.h"
33 34
34 namespace WebCore { 35 namespace WebCore {
35 36
36 static void sampleGamepads(GamepadList* into) 37 template<typename T>
38 static void sampleGamepad(unsigned index, T& gamepad, const blink::WebGamepad& w ebGamepad)
39 {
40 gamepad.setId(webGamepad.id);
41 gamepad.setIndex(index);
42 gamepad.setConnected(webGamepad.connected);
43 gamepad.setTimestamp(webGamepad.timestamp);
44 gamepad.setMapping(webGamepad.mapping);
45 gamepad.setAxes(webGamepad.axesLength, webGamepad.axes);
46 gamepad.setButtons(webGamepad.buttonsLength, webGamepad.buttons);
47 }
48
49 template<typename GamepadType, typename ListType>
50 static void sampleGamepads(ListType* into)
37 { 51 {
38 blink::WebGamepads gamepads; 52 blink::WebGamepads gamepads;
39 53
40 blink::Platform::current()->sampleGamepads(gamepads); 54 blink::Platform::current()->sampleGamepads(gamepads);
41 55
42 for (unsigned i = 0; i < blink::WebGamepads::itemsLengthCap; ++i) { 56 for (unsigned i = 0; i < blink::WebGamepads::itemsLengthCap; ++i) {
43 blink::WebGamepad& webGamepad = gamepads.items[i]; 57 blink::WebGamepad& webGamepad = gamepads.items[i];
44 if (i < gamepads.length && webGamepad.connected) { 58 if (i < gamepads.length && webGamepad.connected) {
45 RefPtrWillBeRawPtr<Gamepad> gamepad = into->item(i); 59 RefPtrWillBeRawPtr<GamepadType> gamepad = into->item(i);
46 if (!gamepad) 60 if (!gamepad)
47 gamepad = Gamepad::create(); 61 gamepad = GamepadType::create();
48 gamepad->id(webGamepad.id); 62 sampleGamepad(i, *gamepad, webGamepad);
49 gamepad->index(i);
50 gamepad->connected(webGamepad.connected);
51 gamepad->timestamp(webGamepad.timestamp);
52 #if defined(ENABLE_NEW_GAMEPAD_API)
53 gamepad->mapping(webGamepad.mapping);
54 #endif
55 gamepad->axes(webGamepad.axesLength, webGamepad.axes);
56 gamepad->buttons(webGamepad.buttonsLength, webGamepad.buttons);
57 into->set(i, gamepad); 63 into->set(i, gamepad);
58 } else { 64 } else {
59 into->set(i, nullptr); 65 into->set(i, nullptr);
60 } 66 }
61 } 67 }
62 } 68 }
63 69
64 NavigatorGamepad::NavigatorGamepad() 70 NavigatorGamepad::NavigatorGamepad()
65 { 71 {
66 } 72 }
(...skipping 10 matching lines...) Expand all
77 NavigatorGamepad& NavigatorGamepad::from(Navigator& navigator) 83 NavigatorGamepad& NavigatorGamepad::from(Navigator& navigator)
78 { 84 {
79 NavigatorGamepad* supplement = static_cast<NavigatorGamepad*>(Supplement<Nav igator>::from(navigator, supplementName())); 85 NavigatorGamepad* supplement = static_cast<NavigatorGamepad*>(Supplement<Nav igator>::from(navigator, supplementName()));
80 if (!supplement) { 86 if (!supplement) {
81 supplement = new NavigatorGamepad(); 87 supplement = new NavigatorGamepad();
82 provideTo(navigator, supplementName(), adoptPtr(supplement)); 88 provideTo(navigator, supplementName(), adoptPtr(supplement));
83 } 89 }
84 return *supplement; 90 return *supplement;
85 } 91 }
86 92
87 GamepadList* NavigatorGamepad::webkitGetGamepads(Navigator& navigator) 93 WebKitGamepadList* NavigatorGamepad::webkitGetGamepads(Navigator& navigator)
94 {
95 return NavigatorGamepad::from(navigator).webkitGamepads();
96 }
97
98 GamepadList* NavigatorGamepad::getGamepads(Navigator& navigator)
88 { 99 {
89 return NavigatorGamepad::from(navigator).gamepads(); 100 return NavigatorGamepad::from(navigator).gamepads();
90 } 101 }
91 102
103 WebKitGamepadList* NavigatorGamepad::webkitGamepads()
104 {
105 if (!m_webkitGamepads)
106 m_webkitGamepads = WebKitGamepadList::create();
107 sampleGamepads<WebKitGamepad>(m_webkitGamepads.get());
108 return m_webkitGamepads.get();
109 }
110
92 GamepadList* NavigatorGamepad::gamepads() 111 GamepadList* NavigatorGamepad::gamepads()
93 { 112 {
94 if (!m_gamepads) 113 if (!m_gamepads)
95 m_gamepads = GamepadList::create(); 114 m_gamepads = GamepadList::create();
96 sampleGamepads(m_gamepads.get()); 115 sampleGamepads<Gamepad>(m_gamepads.get());
97 return m_gamepads.get(); 116 return m_gamepads.get();
98 } 117 }
99 118
100 } // namespace WebCore 119 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/gamepad/NavigatorGamepad.h ('k') | Source/modules/gamepad/NavigatorGamepad.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698