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

Side by Side Diff: components/exo/gamepad.cc

Issue 2572323002: Delete WebGamepads::length. (Closed)
Patch Set: Rebase Created 3 years, 11 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
« no previous file with comments | « no previous file | components/exo/gamepad_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/exo/gamepad.h" 5 #include "components/exo/gamepad.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 has_poll_scheduled_ = false; 116 has_poll_scheduled_ = false;
117 if (!is_enabled_) 117 if (!is_enabled_)
118 return; 118 return;
119 119
120 DCHECK(fetcher_); 120 DCHECK(fetcher_);
121 121
122 blink::WebGamepads new_state = state_; 122 blink::WebGamepads new_state = state_;
123 fetcher_->GetGamepadData( 123 fetcher_->GetGamepadData(
124 false /* No hardware changed notification from the system */); 124 false /* No hardware changed notification from the system */);
125 125
126 new_state.length = 0;
127 device::PadState& pad_state = pad_states_.get()[0]; 126 device::PadState& pad_state = pad_states_.get()[0];
128 127
129 // After querying the gamepad clear the state if it did not have it's active 128 // After querying the gamepad clear the state if it did not have it's active
130 // state updated but is still listed as being associated with a specific 129 // state updated but is still listed as being associated with a specific
131 // source. This indicates the gamepad is disconnected. 130 // source. This indicates the gamepad is disconnected.
132 if (!pad_state.active_state && 131 if (!pad_state.active_state &&
133 pad_state.source != device::GAMEPAD_SOURCE_NONE) { 132 pad_state.source != device::GAMEPAD_SOURCE_NONE) {
134 ClearPadState(pad_state); 133 ClearPadState(pad_state);
135 } 134 }
136 135
137 MapAndSanitizeGamepadData(&pad_state, &new_state.items[0], 136 MapAndSanitizeGamepadData(&pad_state, &new_state.items[0],
138 false /* Don't sanitize gamepad data */); 137 false /* Don't sanitize gamepad data */);
139 138
140 // If the gamepad was active then increment the length of the WebGamepads 139 // If the gamepad is still actively reporting the next call to
141 // struct to indicate it's valid, then set the pad state to inactive. If the 140 // GetGamepadData will set the active state to active again.
142 // gamepad is still actively reporting the next call to GetGamepadData will 141 if (pad_state.active_state)
143 // set the active state to active again.
144 if (pad_state.active_state) {
145 new_state.length++;
146 pad_state.active_state = device::GAMEPAD_INACTIVE; 142 pad_state.active_state = device::GAMEPAD_INACTIVE;
147 }
148 143
149 if (std::max(new_state.length, state_.length) > 0) { 144 if (new_state.items[0].connected != state_.items[0].connected ||
150 if (new_state.items[0].connected != state_.items[0].connected || 145 new_state.items[0].timestamp > state_.items[0].timestamp) {
151 new_state.items[0].timestamp > state_.items[0].timestamp) { 146 origin_task_runner_->PostTask(
152 origin_task_runner_->PostTask( 147 FROM_HERE, base::Bind(process_gamepad_changes_, new_state.items[0]));
153 FROM_HERE,
154 base::Bind(process_gamepad_changes_, new_state.items[0]));
155 }
156 } 148 }
157 149
158 state_ = new_state; 150 state_ = new_state;
159 SchedulePollOnPollingThread(); 151 SchedulePollOnPollingThread();
160 } 152 }
161 153
162 // Callback to ProcessGamepadChanges using weak reference to Gamepad. 154 // Callback to ProcessGamepadChanges using weak reference to Gamepad.
163 ProcessGamepadChangesCallback process_gamepad_changes_; 155 ProcessGamepadChangesCallback process_gamepad_changes_;
164 156
165 // Callback method to create a gamepad data fetcher. 157 // Callback method to create a gamepad data fetcher.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 delegate_->OnButton(button_id, new_button.pressed, new_button.value); 271 delegate_->OnButton(button_id, new_button.pressed, new_button.value);
280 } 272 }
281 } 273 }
282 if (send_frame) 274 if (send_frame)
283 delegate_->OnFrame(); 275 delegate_->OnFrame();
284 276
285 pad_state_ = new_pad; 277 pad_state_ = new_pad;
286 } 278 }
287 279
288 } // namespace exo 280 } // namespace exo
OLDNEW
« no previous file with comments | « no previous file | components/exo/gamepad_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698