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

Unified Diff: ui/aura/event.cc

Issue 8567021: Port views::KeyEvent functions to aura::KeyEvent. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/aura/event.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/event.cc
diff --git a/ui/aura/event.cc b/ui/aura/event.cc
index 309858df6cdffab6e944476de904a9087d71894d..92465fbff61b4c1779f15da51d3ecea534af8474 100644
--- a/ui/aura/event.cc
+++ b/ui/aura/event.cc
@@ -4,10 +4,19 @@
#include "ui/aura/event.h"
+#if defined(USE_X11)
+#include <X11/Xlib.h>
+#endif
+
#include "ui/aura/window.h"
+#include "ui/base/keycodes/keyboard_code_conversion.h"
#include "ui/gfx/point3.h"
#include "ui/gfx/transform.h"
+#if defined(USE_X11)
+#include "ui/base/keycodes/keyboard_code_conversion_x.h"
+#endif
+
namespace aura {
Event::Event(ui::EventType type, int flags)
@@ -130,7 +139,9 @@ KeyEvent::KeyEvent(const base::NativeEvent& native_event, bool is_char)
ui::EventTypeFromNative(native_event),
ui::EventFlagsFromNative(native_event)),
key_code_(ui::KeyboardCodeFromNative(native_event)),
- is_char_(is_char) {
+ is_char_(is_char),
+ character_(0),
+ unmodified_character_(0) {
}
KeyEvent::KeyEvent(ui::EventType type,
@@ -138,7 +149,65 @@ KeyEvent::KeyEvent(ui::EventType type,
int flags)
: Event(type, flags),
key_code_(key_code),
- is_char_(false) {
+ is_char_(false),
+ character_(ui::GetCharacterFromKeyCode(key_code, flags)),
+ unmodified_character_(0) {
+}
+
+uint16 KeyEvent::GetCharacter() const {
+ if (character_)
+ return character_;
+
+#if defined(OS_WIN)
+ return (native_event().message == WM_CHAR) ? key_code_ :
+ ui::GetCharacterFromKeyCode(key_code_, flags());
+#elif defined(USE_X11)
+ if (!native_event()) {
James Su 2011/11/15 11:51:10 nit: no { } for single line if statement.
Yusuke Sato 2011/11/15 12:20:59 Done.
+ return ui::GetCharacterFromKeyCode(key_code_, flags());
+ }
+
+ DCHECK(native_event()->type == KeyPress ||
+ native_event()->type == KeyRelease);
+
+ uint16 ch = ui::DefaultSymbolFromXEvent(native_event());
+ return ch ? ch : ui::GetCharacterFromKeyCode(key_code_, flags());
+#else
+ NOTIMPLEMENTED();
+ return 0;
+#endif
+}
+
+uint16 KeyEvent::GetUnmodifiedCharacter() const {
+ if (unmodified_character_)
+ return unmodified_character_;
+
+#if defined(OS_WIN)
+ // Looks like there is no way to get unmodified character on Windows.
+ return (native_event().message == WM_CHAR) ? key_code_ :
+ ui::GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN);
+#elif defined(USE_X11)
+ if (!native_event()) {
+ return ui::GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN);
James Su 2011/11/15 11:51:10 ditto.
Yusuke Sato 2011/11/15 12:20:59 Done.
+ }
+
+ DCHECK(native_event()->type == KeyPress ||
+ native_event()->type == KeyRelease);
+
+ XKeyEvent *key = &native_event()->xkey;
+
+ static const unsigned int kIgnoredModifiers = ControlMask | LockMask |
+ Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask;
+
+ // We can't use things like (key.state & ShiftMask), as it may mask out bits
+ // used by X11 internally.
+ key->state &= ~kIgnoredModifiers;
+ uint16 ch = ui::DefaultSymbolFromXEvent(native_event());
+ return ch ? ch :
+ ui::GetCharacterFromKeyCode(key_code_, flags() & ui::EF_SHIFT_DOWN);
+#else
+ NOTIMPLEMENTED();
+ return 0;
+#endif
}
} // namespace aura
« no previous file with comments | « ui/aura/event.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698