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

Side by Side Diff: chrome/browser/chromeos/events/event_rewriter.cc

Issue 192123002: chromeos: A little more cleanup for EventRewriter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/chromeos/events/event_rewriter.h" 5 #include "chrome/browser/chromeos/events/event_rewriter.h"
6 6
7 #include <X11/extensions/XInput2.h> 7 #include <X11/extensions/XInput2.h>
8 #include <X11/keysym.h> 8 #include <X11/keysym.h>
9 #include <X11/XF86keysym.h> 9 #include <X11/XF86keysym.h>
10 #include <X11/Xlib.h> 10 #include <X11/Xlib.h>
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 return kDeviceAppleKeyboard; 178 return kDeviceAppleKeyboard;
179 } 179 }
180 180
181 return kDeviceUnknown; 181 return kDeviceUnknown;
182 } 182 }
183 183
184 void EventRewriter::RewriteForTesting(XEvent* event) { 184 void EventRewriter::RewriteForTesting(XEvent* event) {
185 Rewrite(event); 185 Rewrite(event);
186 } 186 }
187 187
188 void EventRewriter::DeviceKeyPressedOrReleased(int device_id) {
189 std::map<int, DeviceType>::const_iterator iter =
190 device_id_to_type_.find(device_id);
191 if (iter == device_id_to_type_.end()) {
192 // |device_id| is unknown. This means the device was connected before
193 // booting the OS. Query the name of the device and add it to the map.
194 DeviceAdded(device_id);
195 }
196
197 last_device_id_ = device_id;
198 }
199
188 base::EventStatus EventRewriter::WillProcessEvent( 200 base::EventStatus EventRewriter::WillProcessEvent(
189 const base::NativeEvent& event) { 201 const base::NativeEvent& event) {
190 XEvent* xevent = event; 202 XEvent* xevent = event;
191 if (xevent->type == KeyPress || xevent->type == KeyRelease) { 203 if (xevent->type == KeyPress || xevent->type == KeyRelease) {
192 Rewrite(xevent); 204 Rewrite(xevent);
193 } else if (xevent->type == GenericEvent) { 205 } else if (xevent->type == GenericEvent) {
194 RewriteLocatedEvent(xevent); 206 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xevent->xcookie.data);
207 if (xievent->evtype == XI_KeyPress || xievent->evtype == XI_KeyRelease) {
208 if (xievent->deviceid == xievent->sourceid)
209 DeviceKeyPressedOrReleased(xievent->deviceid);
210 } else {
211 RewriteLocatedEvent(xevent);
212 }
195 } else if (xevent->type == MappingNotify) { 213 } else if (xevent->type == MappingNotify) {
196 if (xevent->xmapping.request == MappingModifier || 214 if (xevent->xmapping.request == MappingModifier ||
197 xevent->xmapping.request == MappingKeyboard) { 215 xevent->xmapping.request == MappingKeyboard) {
198 RefreshKeycodes(); 216 RefreshKeycodes();
199 } 217 }
200 } 218 }
201 return base::EVENT_CONTINUE; 219 return base::EVENT_CONTINUE;
202 } 220 }
203 221
204 void EventRewriter::DidProcessEvent(const base::NativeEvent& event) { 222 void EventRewriter::DidProcessEvent(const base::NativeEvent& event) {
205 } 223 }
206 224
225 void EventRewriter::DeviceHierarchyChanged() {}
226
207 void EventRewriter::DeviceAdded(int device_id) { 227 void EventRewriter::DeviceAdded(int device_id) {
208 DCHECK_NE(XIAllDevices, device_id); 228 DCHECK_NE(XIAllDevices, device_id);
209 DCHECK_NE(XIAllMasterDevices, device_id); 229 DCHECK_NE(XIAllMasterDevices, device_id);
210 if (device_id == XIAllDevices || device_id == XIAllMasterDevices) { 230 if (device_id == XIAllDevices || device_id == XIAllMasterDevices) {
211 LOG(ERROR) << "Unexpected device_id passed: " << device_id; 231 LOG(ERROR) << "Unexpected device_id passed: " << device_id;
212 return; 232 return;
213 } 233 }
214 234
215 int ndevices_return = 0; 235 int ndevices_return = 0;
216 XIDeviceInfo* device_info = XIQueryDevice(gfx::GetXDisplay(), 236 XIDeviceInfo* device_info = XIQueryDevice(gfx::GetXDisplay(),
(...skipping 14 matching lines...) Expand all
231 DeviceAddedInternal(device_info[i].deviceid, device_info[i].name); 251 DeviceAddedInternal(device_info[i].deviceid, device_info[i].name);
232 } 252 }
233 253
234 XIFreeDeviceInfo(device_info); 254 XIFreeDeviceInfo(device_info);
235 } 255 }
236 256
237 void EventRewriter::DeviceRemoved(int device_id) { 257 void EventRewriter::DeviceRemoved(int device_id) {
238 device_id_to_type_.erase(device_id); 258 device_id_to_type_.erase(device_id);
239 } 259 }
240 260
241 void EventRewriter::DeviceKeyPressedOrReleased(int device_id) {
242 std::map<int, DeviceType>::const_iterator iter =
243 device_id_to_type_.find(device_id);
244 if (iter == device_id_to_type_.end()) {
245 // |device_id| is unknown. This means the device was connected before
246 // booting the OS. Query the name of the device and add it to the map.
247 DeviceAdded(device_id);
248 }
249
250 last_device_id_ = device_id;
251 }
252
253 void EventRewriter::RefreshKeycodes() { 261 void EventRewriter::RefreshKeycodes() {
254 keysym_to_keycode_map_.clear(); 262 keysym_to_keycode_map_.clear();
255 } 263 }
256 264
257 KeyCode EventRewriter::NativeKeySymToNativeKeycode(KeySym keysym) { 265 KeyCode EventRewriter::NativeKeySymToNativeKeycode(KeySym keysym) {
258 if (keysym_to_keycode_map_.count(keysym)) 266 if (keysym_to_keycode_map_.count(keysym))
259 return keysym_to_keycode_map_[keysym]; 267 return keysym_to_keycode_map_[keysym];
260 268
261 XDisplay* display = gfx::GetXDisplay(); 269 XDisplay* display = gfx::GetXDisplay();
262 KeyCode keycode = XKeysymToKeycode(display, keysym); 270 KeyCode keycode = XKeysymToKeycode(display, keysym);
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 VLOG(1) << "Apple keyboard '" << device_name << "' connected: " 897 VLOG(1) << "Apple keyboard '" << device_name << "' connected: "
890 << "id=" << device_id; 898 << "id=" << device_id;
891 } 899 }
892 // Always overwrite the existing device_id since the X server may reuse a 900 // Always overwrite the existing device_id since the X server may reuse a
893 // device id for an unattached device. 901 // device id for an unattached device.
894 device_id_to_type_[device_id] = type; 902 device_id_to_type_[device_id] = type;
895 return type; 903 return type;
896 } 904 }
897 905
898 } // namespace chromeos 906 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698