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

Side by Side Diff: content/browser/renderer_host/web_input_event_aurax11.cc

Issue 10541139: Improve MakeWebKeyboardEventFromAuraEvent() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix linux_chromeos_clang shared build Created 8 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Portions based heavily on: 5 // Portions based heavily on:
6 // third_party/WebKit/Source/WebKit/chromium/public/gtk/WebInputEventFactory.cpp 6 // third_party/WebKit/Source/WebKit/chromium/public/gtk/WebInputEventFactory.cpp
7 // 7 //
8 /* 8 /*
9 * Copyright (C) 2006-2011 Google Inc. All rights reserved. 9 * Copyright (C) 2006-2011 Google Inc. All rights reserved.
10 * 10 *
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 namespace content { 50 namespace content {
51 51
52 // chromium WebKit does not provide a WebInputEventFactory for X11, so we have 52 // chromium WebKit does not provide a WebInputEventFactory for X11, so we have
53 // to do the work here ourselves. 53 // to do the work here ourselves.
54 54
55 namespace { 55 namespace {
56 56
57 // This matches Firefox behavior. 57 // This matches Firefox behavior.
58 const int kPixelsPerTick = 53; 58 const int kPixelsPerTick = 53;
59 59
60 // Normalizes event.flags() to make it Windows/Mac compatible. Since the way
61 // of setting modifier mask on X is very different than Windows/Mac as shown
62 // in http://crbug.com/127142#c8, the normalization is necessary.
63 int NormalizeEventFlags(const aura::KeyEvent& event) {
64 int mask = 0;
65 switch (event.key_code()) {
66 case ui::VKEY_CONTROL:
67 mask = ui::EF_CONTROL_DOWN;
68 break;
69 case ui::VKEY_SHIFT:
70 mask = ui::EF_SHIFT_DOWN;
71 break;
72 case ui::VKEY_MENU:
73 mask = ui::EF_ALT_DOWN;
74 break;
75 case ui::VKEY_CAPITAL:
76 mask = ui::EF_CAPS_LOCK_DOWN;
77 break;
78 default:
79 return event.flags();
80 }
81 if (event.type() == ui::ET_KEY_PRESSED)
82 return event.flags() | mask;
83 return event.flags() & ~mask;
84 }
85
60 int EventFlagsToWebEventModifiers(int flags) { 86 int EventFlagsToWebEventModifiers(int flags) {
61 int modifiers = 0; 87 int modifiers = 0;
62 if (flags & ui::EF_SHIFT_DOWN) 88 if (flags & ui::EF_SHIFT_DOWN)
63 modifiers |= WebKit::WebInputEvent::ShiftKey; 89 modifiers |= WebKit::WebInputEvent::ShiftKey;
64 if (flags & ui::EF_CONTROL_DOWN) 90 if (flags & ui::EF_CONTROL_DOWN)
65 modifiers |= WebKit::WebInputEvent::ControlKey; 91 modifiers |= WebKit::WebInputEvent::ControlKey;
66 if (flags & ui::EF_ALT_DOWN) 92 if (flags & ui::EF_ALT_DOWN)
67 modifiers |= WebKit::WebInputEvent::AltKey; 93 modifiers |= WebKit::WebInputEvent::AltKey;
68 // TODO(beng): MetaKey/META_MASK 94 // TODO(beng): MetaKey/META_MASK
69 if (flags & ui::EF_LEFT_MOUSE_BUTTON) 95 if (flags & ui::EF_LEFT_MOUSE_BUTTON)
70 modifiers |= WebKit::WebInputEvent::LeftButtonDown; 96 modifiers |= WebKit::WebInputEvent::LeftButtonDown;
71 if (flags & ui::EF_MIDDLE_MOUSE_BUTTON) 97 if (flags & ui::EF_MIDDLE_MOUSE_BUTTON)
72 modifiers |= WebKit::WebInputEvent::MiddleButtonDown; 98 modifiers |= WebKit::WebInputEvent::MiddleButtonDown;
73 if (flags & ui::EF_RIGHT_MOUSE_BUTTON) 99 if (flags & ui::EF_RIGHT_MOUSE_BUTTON)
74 modifiers |= WebKit::WebInputEvent::RightButtonDown; 100 modifiers |= WebKit::WebInputEvent::RightButtonDown;
75 if (flags & ui::EF_CAPS_LOCK_DOWN) 101 if (flags & ui::EF_CAPS_LOCK_DOWN)
76 modifiers |= WebKit::WebInputEvent::CapsLockOn; 102 modifiers |= WebKit::WebInputEvent::CapsLockOn;
77 return modifiers; 103 return modifiers;
78 } 104 }
79 105
80 int XStateToWebEventModifiers(unsigned int state) {
81 int modifiers = 0;
82 if (state & ShiftMask)
83 modifiers |= WebKit::WebInputEvent::ShiftKey;
84 if (state & ControlMask)
85 modifiers |= WebKit::WebInputEvent::ControlKey;
86 if (state & Mod1Mask)
87 modifiers |= WebKit::WebInputEvent::AltKey;
88 // TODO(beng): MetaKey/META_MASK
89 if (state & Button1Mask)
90 modifiers |= WebKit::WebInputEvent::LeftButtonDown;
91 if (state & Button2Mask)
92 modifiers |= WebKit::WebInputEvent::MiddleButtonDown;
93 if (state & Button3Mask)
94 modifiers |= WebKit::WebInputEvent::RightButtonDown;
95 if (state & LockMask)
96 modifiers |= WebKit::WebInputEvent::CapsLockOn;
97 if (state & Mod2Mask)
98 modifiers |= WebKit::WebInputEvent::NumLockOn;
99 return modifiers;
100 }
101
102 int XKeyEventToWindowsKeyCode(XKeyEvent* event) { 106 int XKeyEventToWindowsKeyCode(XKeyEvent* event) {
103 return ui::KeyboardCodeFromXKeyEvent((XEvent*)event); 107 return ui::KeyboardCodeFromXKeyEvent((XEvent*)event);
104 } 108 }
105 109
106 // From 110 // From
107 // third_party/WebKit/Source/WebKit/chromium/src/gtk/WebInputEventFactory.cpp: 111 // third_party/WebKit/Source/WebKit/chromium/src/gtk/WebInputEventFactory.cpp:
108 WebKit::WebUChar GetControlCharacter(int windows_key_code, bool shift) { 112 WebKit::WebUChar GetControlCharacter(int windows_key_code, bool shift) {
109 if (windows_key_code >= ui::VKEY_A && 113 if (windows_key_code >= ui::VKEY_A &&
110 windows_key_code <= ui::VKEY_Z) { 114 windows_key_code <= ui::VKEY_Z) {
111 // ctrl-A ~ ctrl-Z map to \x01 ~ \x1A 115 // ctrl-A ~ ctrl-Z map to \x01 ~ \x1A
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 return webkit_event; 280 return webkit_event;
277 } 281 }
278 282
279 WebKit::WebKeyboardEvent MakeWebKeyboardEventFromAuraEvent( 283 WebKit::WebKeyboardEvent MakeWebKeyboardEventFromAuraEvent(
280 aura::KeyEvent* event) { 284 aura::KeyEvent* event) {
281 base::NativeEvent native_event = event->native_event(); 285 base::NativeEvent native_event = event->native_event();
282 WebKit::WebKeyboardEvent webkit_event; 286 WebKit::WebKeyboardEvent webkit_event;
283 XKeyEvent* native_key_event = &native_event->xkey; 287 XKeyEvent* native_key_event = &native_event->xkey;
284 288
285 webkit_event.timeStampSeconds = event->time_stamp().InSecondsF(); 289 webkit_event.timeStampSeconds = event->time_stamp().InSecondsF();
286 webkit_event.modifiers = XStateToWebEventModifiers(native_key_event->state); 290 webkit_event.modifiers =
291 EventFlagsToWebEventModifiers(NormalizeEventFlags(*event));
287 292
288 switch (native_event->type) { 293 switch (native_event->type) {
289 case KeyPress: 294 case KeyPress:
290 webkit_event.type = event->is_char() ? WebKit::WebInputEvent::Char : 295 webkit_event.type = event->is_char() ? WebKit::WebInputEvent::Char :
291 WebKit::WebInputEvent::RawKeyDown; 296 WebKit::WebInputEvent::RawKeyDown;
292 break; 297 break;
293 case KeyRelease: 298 case KeyRelease:
294 webkit_event.type = WebKit::WebInputEvent::KeyUp; 299 webkit_event.type = WebKit::WebInputEvent::KeyUp;
295 break; 300 break;
296 default: 301 default:
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 453
449 // Update the type of the touch event. 454 // Update the type of the touch event.
450 web_event->type = TouchEventTypeFromEvent(event); 455 web_event->type = TouchEventTypeFromEvent(event);
451 web_event->timeStampSeconds = event->time_stamp().InSecondsF(); 456 web_event->timeStampSeconds = event->time_stamp().InSecondsF();
452 web_event->modifiers = EventFlagsToWebEventModifiers(event->flags()); 457 web_event->modifiers = EventFlagsToWebEventModifiers(event->flags());
453 458
454 return point; 459 return point;
455 } 460 }
456 461
457 } // namespace content 462 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/web_input_event_aura_unittest.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698