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

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

Issue 808643005: Sync Navigator.getGamepads() with the spec Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement)); 87 provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement));
88 } 88 }
89 return *supplement; 89 return *supplement;
90 } 90 }
91 91
92 WebKitGamepadList* NavigatorGamepad::webkitGetGamepads(Navigator& navigator) 92 WebKitGamepadList* NavigatorGamepad::webkitGetGamepads(Navigator& navigator)
93 { 93 {
94 return NavigatorGamepad::from(navigator).webkitGamepads(); 94 return NavigatorGamepad::from(navigator).webkitGamepads();
95 } 95 }
96 96
97 GamepadList* NavigatorGamepad::getGamepads(Navigator& navigator) 97 HeapVector<Member<Gamepad>> NavigatorGamepad::getGamepads(Navigator& navigator)
98 { 98 {
99 return NavigatorGamepad::from(navigator).gamepads(); 99 GamepadList* gamepadList = NavigatorGamepad::from(navigator).gamepads();
100 unsigned length = gamepadList->length();
101 HeapVector<Member<Gamepad>> gamepads(length);
102 unsigned actualLength = 0;
103 for (unsigned i = 0; i < length; ++i) {
104 Gamepad* gamepad = gamepadList->item(i);
105 if (gamepad) {
106 ASSERT(gamepad->index() == i);
107 gamepads[i] = gamepad;
kbalazs 2014/12/17 21:53:41 This should be gamepads[actualLength], no? It see
philipj_slow 2014/12/17 22:45:38 This started out as a loop simply copying gamepads
kbalazs 2014/12/18 00:34:39 I see this in Vector::shrink: TypeOperations::des
philipj_slow 2014/12/18 08:29:03 gamepad-polling-access.html tries exactly this, an
108 actualLength = i + 1;
109 }
110 }
111 gamepads.shrink(actualLength);
kbalazs 2014/12/17 21:53:41 In the common case this would allocate, deallocate
philipj_slow 2014/12/17 22:45:38 shrink() only modifies the size, it doesn't reallo
kbalazs 2014/12/18 00:34:39 Correct, it doesn't deallocate but it destroys ele
philipj_slow 2014/12/18 08:29:03 It's Member<Gamepad> being destroyed, so that seem
112 return gamepads;
100 } 113 }
101 114
102 WebKitGamepadList* NavigatorGamepad::webkitGamepads() 115 WebKitGamepadList* NavigatorGamepad::webkitGamepads()
103 { 116 {
104 if (!m_webkitGamepads) 117 if (!m_webkitGamepads)
105 m_webkitGamepads = WebKitGamepadList::create(); 118 m_webkitGamepads = WebKitGamepadList::create();
106 if (window()) { 119 if (window()) {
107 startUpdating(); 120 startUpdating();
108 sampleGamepads<WebKitGamepad>(m_webkitGamepads.get()); 121 sampleGamepads<WebKitGamepad>(m_webkitGamepads.get());
109 } 122 }
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 if (connectedGamepadChanged || (!oldWasConnected && newIsConnected)) { 298 if (connectedGamepadChanged || (!oldWasConnected && newIsConnected)) {
286 m_pendingEvents.append(newGamepad); 299 m_pendingEvents.append(newGamepad);
287 } 300 }
288 } 301 }
289 302
290 if (!m_pendingEvents.isEmpty()) 303 if (!m_pendingEvents.isEmpty())
291 m_dispatchOneEventRunner.runAsync(); 304 m_dispatchOneEventRunner.runAsync();
292 } 305 }
293 306
294 } // namespace blink 307 } // namespace blink
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