From 89840a9b91f412ac7c9aeb3148e530b65b0cd1cb Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Wed, 24 Apr 2013 12:49:46 +0900 Subject: [PATCH] Bug 842927 part.1 Implement D3E KeyboardEvent.key r=smaug, sr=smaug --- content/events/public/moz.build | 1 + content/events/public/nsDOMKeyNameList.h | 246 ++++++++++++++++++ content/events/src/nsDOMEvent.cpp | 1 + content/events/src/nsDOMKeyboardEvent.cpp | 9 + .../events/test/test_dom_keyboard_event.html | 3 + dom/interfaces/events/nsIDOMKeyEvent.idl | 4 +- dom/webidl/KeyEvent.webidl | 2 + widget/nsEvent.h | 12 + widget/nsGUIEvent.h | 25 +- widget/nsGUIEventIPC.h | 17 +- widget/shared/WidgetUtils.cpp | 71 +++++ widget/shared/WidgetUtils.h | 9 + 12 files changed, 393 insertions(+), 7 deletions(-) create mode 100644 content/events/public/nsDOMKeyNameList.h diff --git a/content/events/public/moz.build b/content/events/public/moz.build index 096c3930683..e5ba09124fc 100644 --- a/content/events/public/moz.build +++ b/content/events/public/moz.build @@ -14,6 +14,7 @@ MODULE = 'content' EXPORTS += [ 'nsAsyncDOMEvent.h', + 'nsDOMKeyNameList.h', 'nsEventDispatcher.h', 'nsEventNameList.h', 'nsEventStates.h', diff --git a/content/events/public/nsDOMKeyNameList.h b/content/events/public/nsDOMKeyNameList.h new file mode 100644 index 00000000000..ab5cff45fb1 --- /dev/null +++ b/content/events/public/nsDOMKeyNameList.h @@ -0,0 +1,246 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + * This header file defines all DOM key name which are used for DOM + * KeyboardEvent.key. + * You must define NS_DEFINE_KEYNAME macro before including this. + * + * It must have two arguments, (aCPPName, aDOMKeyName) + * aCPPName is usable name for a part of C++ constants. + * aDOMKeyName is the actual value. + */ + +#define DEFINE_KEYNAME_INTERNAL(aCPPName, aDOMKeyName) \ + NS_DEFINE_KEYNAME(aCPPName, aDOMKeyName) + +#define DEFINE_KEYNAME_WITH_SAME_NAME(aName) \ + DEFINE_KEYNAME_INTERNAL(aName, #aName) + +DEFINE_KEYNAME_WITH_SAME_NAME(Unidentified) +DEFINE_KEYNAME_INTERNAL(PrintableKey, "MozPrintableKey") + +DEFINE_KEYNAME_WITH_SAME_NAME(Attn) +DEFINE_KEYNAME_WITH_SAME_NAME(Apps) +DEFINE_KEYNAME_WITH_SAME_NAME(Crsel) +DEFINE_KEYNAME_WITH_SAME_NAME(Exsel) +DEFINE_KEYNAME_WITH_SAME_NAME(F1) +DEFINE_KEYNAME_WITH_SAME_NAME(F2) +DEFINE_KEYNAME_WITH_SAME_NAME(F3) +DEFINE_KEYNAME_WITH_SAME_NAME(F4) +DEFINE_KEYNAME_WITH_SAME_NAME(F5) +DEFINE_KEYNAME_WITH_SAME_NAME(F6) +DEFINE_KEYNAME_WITH_SAME_NAME(F7) +DEFINE_KEYNAME_WITH_SAME_NAME(F8) +DEFINE_KEYNAME_WITH_SAME_NAME(F9) +DEFINE_KEYNAME_WITH_SAME_NAME(F10) +DEFINE_KEYNAME_WITH_SAME_NAME(F11) +DEFINE_KEYNAME_WITH_SAME_NAME(F12) +DEFINE_KEYNAME_WITH_SAME_NAME(F13) +DEFINE_KEYNAME_WITH_SAME_NAME(F14) +DEFINE_KEYNAME_WITH_SAME_NAME(F15) +DEFINE_KEYNAME_WITH_SAME_NAME(F16) +DEFINE_KEYNAME_WITH_SAME_NAME(F17) +DEFINE_KEYNAME_WITH_SAME_NAME(F18) +DEFINE_KEYNAME_WITH_SAME_NAME(F19) +DEFINE_KEYNAME_WITH_SAME_NAME(F20) +DEFINE_KEYNAME_WITH_SAME_NAME(F21) +DEFINE_KEYNAME_WITH_SAME_NAME(F22) +DEFINE_KEYNAME_WITH_SAME_NAME(F23) +DEFINE_KEYNAME_WITH_SAME_NAME(F24) +DEFINE_KEYNAME_WITH_SAME_NAME(LaunchApplication1) +DEFINE_KEYNAME_WITH_SAME_NAME(LaunchApplication2) +DEFINE_KEYNAME_WITH_SAME_NAME(LaunchMail) +DEFINE_KEYNAME_WITH_SAME_NAME(List) +DEFINE_KEYNAME_WITH_SAME_NAME(Props) +DEFINE_KEYNAME_WITH_SAME_NAME(Soft1) +DEFINE_KEYNAME_WITH_SAME_NAME(Soft2) +DEFINE_KEYNAME_WITH_SAME_NAME(Soft3) +DEFINE_KEYNAME_WITH_SAME_NAME(Soft4) +DEFINE_KEYNAME_WITH_SAME_NAME(Accept) +DEFINE_KEYNAME_WITH_SAME_NAME(Again) +DEFINE_KEYNAME_WITH_SAME_NAME(Enter) +DEFINE_KEYNAME_WITH_SAME_NAME(Find) +DEFINE_KEYNAME_WITH_SAME_NAME(Help) +DEFINE_KEYNAME_WITH_SAME_NAME(Info) +DEFINE_KEYNAME_WITH_SAME_NAME(Menu) +DEFINE_KEYNAME_WITH_SAME_NAME(Pause) +DEFINE_KEYNAME_WITH_SAME_NAME(Play) +DEFINE_KEYNAME_WITH_SAME_NAME(ScrollLock) // IE9 users "Scroll" +DEFINE_KEYNAME_WITH_SAME_NAME(Execute) +DEFINE_KEYNAME_WITH_SAME_NAME(Cancel) +DEFINE_KEYNAME_WITH_SAME_NAME(Esc) +DEFINE_KEYNAME_WITH_SAME_NAME(Exit) +DEFINE_KEYNAME_WITH_SAME_NAME(Zoom) +DEFINE_KEYNAME_WITH_SAME_NAME(Separator) +DEFINE_KEYNAME_WITH_SAME_NAME(Spacebar) +DEFINE_KEYNAME_WITH_SAME_NAME(Add) +DEFINE_KEYNAME_WITH_SAME_NAME(Subtract) +DEFINE_KEYNAME_WITH_SAME_NAME(Multiply) +DEFINE_KEYNAME_WITH_SAME_NAME(Divide) +DEFINE_KEYNAME_WITH_SAME_NAME(Equals) +DEFINE_KEYNAME_WITH_SAME_NAME(Decimal) +DEFINE_KEYNAME_WITH_SAME_NAME(BrightnessDown) +DEFINE_KEYNAME_WITH_SAME_NAME(BrightnessUp) +DEFINE_KEYNAME_WITH_SAME_NAME(Camera) +DEFINE_KEYNAME_WITH_SAME_NAME(Eject) +DEFINE_KEYNAME_WITH_SAME_NAME(Power) +DEFINE_KEYNAME_WITH_SAME_NAME(PrintScreen) +DEFINE_KEYNAME_WITH_SAME_NAME(BrowserFavorites) +DEFINE_KEYNAME_WITH_SAME_NAME(BrowserHome) +DEFINE_KEYNAME_WITH_SAME_NAME(BrowserRefresh) +DEFINE_KEYNAME_WITH_SAME_NAME(BrowserSearch) +DEFINE_KEYNAME_WITH_SAME_NAME(BrowserStop) +DEFINE_KEYNAME_WITH_SAME_NAME(BrowserBack) +DEFINE_KEYNAME_WITH_SAME_NAME(BrowserForward) +DEFINE_KEYNAME_WITH_SAME_NAME(Left) +DEFINE_KEYNAME_WITH_SAME_NAME(PageDown) +DEFINE_KEYNAME_WITH_SAME_NAME(PageUp) +DEFINE_KEYNAME_WITH_SAME_NAME(Right) +DEFINE_KEYNAME_WITH_SAME_NAME(Up) +DEFINE_KEYNAME_WITH_SAME_NAME(UpLeft) +DEFINE_KEYNAME_WITH_SAME_NAME(UpRight) +DEFINE_KEYNAME_WITH_SAME_NAME(Down) +DEFINE_KEYNAME_WITH_SAME_NAME(DownLeft) +DEFINE_KEYNAME_WITH_SAME_NAME(DownRight) +DEFINE_KEYNAME_WITH_SAME_NAME(Home) +DEFINE_KEYNAME_WITH_SAME_NAME(End) +DEFINE_KEYNAME_WITH_SAME_NAME(Select) +DEFINE_KEYNAME_WITH_SAME_NAME(Tab) +DEFINE_KEYNAME_WITH_SAME_NAME(Backspace) +DEFINE_KEYNAME_WITH_SAME_NAME(Clear) +DEFINE_KEYNAME_WITH_SAME_NAME(Copy) +DEFINE_KEYNAME_WITH_SAME_NAME(Cut) +DEFINE_KEYNAME_WITH_SAME_NAME(Del) +DEFINE_KEYNAME_WITH_SAME_NAME(EraseEof) +DEFINE_KEYNAME_WITH_SAME_NAME(Insert) +DEFINE_KEYNAME_WITH_SAME_NAME(Paste) +DEFINE_KEYNAME_WITH_SAME_NAME(Undo) +DEFINE_KEYNAME_WITH_SAME_NAME(DeadGrave) +DEFINE_KEYNAME_WITH_SAME_NAME(DeadAcute) +DEFINE_KEYNAME_WITH_SAME_NAME(DeadCircumflex) +DEFINE_KEYNAME_WITH_SAME_NAME(DeadTilde) +DEFINE_KEYNAME_WITH_SAME_NAME(DeadMacron) +DEFINE_KEYNAME_WITH_SAME_NAME(DeadBreve) +DEFINE_KEYNAME_WITH_SAME_NAME(DeadAboveDot) +DEFINE_KEYNAME_WITH_SAME_NAME(DeadUmlaut) +DEFINE_KEYNAME_WITH_SAME_NAME(DeadAboveRing) +DEFINE_KEYNAME_WITH_SAME_NAME(DeadDoubleacute) +DEFINE_KEYNAME_WITH_SAME_NAME(DeadCaron) +DEFINE_KEYNAME_WITH_SAME_NAME(DeadCedilla) +DEFINE_KEYNAME_WITH_SAME_NAME(DeadOgonek) +DEFINE_KEYNAME_WITH_SAME_NAME(DeadIota) +DEFINE_KEYNAME_WITH_SAME_NAME(DeadVoicedSound) +DEFINE_KEYNAME_WITH_SAME_NAME(DeadSemivoicedSound) +DEFINE_KEYNAME_WITH_SAME_NAME(Alphanumeric) +DEFINE_KEYNAME_WITH_SAME_NAME(Alt) +DEFINE_KEYNAME_WITH_SAME_NAME(AltGraph) +DEFINE_KEYNAME_WITH_SAME_NAME(CapsLock) +DEFINE_KEYNAME_WITH_SAME_NAME(Control) +DEFINE_KEYNAME_WITH_SAME_NAME(Fn) +DEFINE_KEYNAME_WITH_SAME_NAME(FnLock) +DEFINE_KEYNAME_WITH_SAME_NAME(Meta) +DEFINE_KEYNAME_WITH_SAME_NAME(Process) +DEFINE_KEYNAME_WITH_SAME_NAME(NumLock) +DEFINE_KEYNAME_WITH_SAME_NAME(Shift) +DEFINE_KEYNAME_WITH_SAME_NAME(SymbolLock) +DEFINE_KEYNAME_WITH_SAME_NAME(OS) // IE9 uses "Win" +DEFINE_KEYNAME_WITH_SAME_NAME(Compose) +DEFINE_KEYNAME_WITH_SAME_NAME(AllCandidates) +DEFINE_KEYNAME_WITH_SAME_NAME(NextCandidate) +DEFINE_KEYNAME_WITH_SAME_NAME(PreviousCandidate) +DEFINE_KEYNAME_WITH_SAME_NAME(CodeInput) +DEFINE_KEYNAME_WITH_SAME_NAME(Convert) +DEFINE_KEYNAME_WITH_SAME_NAME(Nonconvert) +DEFINE_KEYNAME_WITH_SAME_NAME(FinalMode) +DEFINE_KEYNAME_WITH_SAME_NAME(FullWidth) +DEFINE_KEYNAME_WITH_SAME_NAME(HalfWidth) +DEFINE_KEYNAME_WITH_SAME_NAME(ModeChange) +DEFINE_KEYNAME_WITH_SAME_NAME(RomanCharacters) +DEFINE_KEYNAME_WITH_SAME_NAME(HangulMode) +DEFINE_KEYNAME_WITH_SAME_NAME(HanjaMode) +DEFINE_KEYNAME_WITH_SAME_NAME(JunjaMode) +DEFINE_KEYNAME_WITH_SAME_NAME(Hiragana) +DEFINE_KEYNAME_WITH_SAME_NAME(KanaMode) +DEFINE_KEYNAME_WITH_SAME_NAME(KanjiMode) +DEFINE_KEYNAME_WITH_SAME_NAME(Katakana) +DEFINE_KEYNAME_WITH_SAME_NAME(AudioFaderFront) +DEFINE_KEYNAME_WITH_SAME_NAME(AudioFaderRear) +DEFINE_KEYNAME_WITH_SAME_NAME(AudioBalanceLeft) +DEFINE_KEYNAME_WITH_SAME_NAME(AudioBalanceRight) +DEFINE_KEYNAME_WITH_SAME_NAME(AudioBassBoostDown) +DEFINE_KEYNAME_WITH_SAME_NAME(AudioBassBoostUp) +DEFINE_KEYNAME_WITH_SAME_NAME(VolumeMute) +DEFINE_KEYNAME_WITH_SAME_NAME(VolumeDown) +DEFINE_KEYNAME_WITH_SAME_NAME(VolumeUp) +DEFINE_KEYNAME_WITH_SAME_NAME(MediaPause) +DEFINE_KEYNAME_WITH_SAME_NAME(MediaPlay) +DEFINE_KEYNAME_WITH_SAME_NAME(MediaStop) +DEFINE_KEYNAME_WITH_SAME_NAME(MediaNextTrack) +DEFINE_KEYNAME_WITH_SAME_NAME(MediaPreviousTrack) +DEFINE_KEYNAME_WITH_SAME_NAME(MediaPlayPause) +DEFINE_KEYNAME_WITH_SAME_NAME(MediaTrackSkip) +DEFINE_KEYNAME_WITH_SAME_NAME(MediaTrackStart) +DEFINE_KEYNAME_WITH_SAME_NAME(MediaTrackEnd) +DEFINE_KEYNAME_WITH_SAME_NAME(SelectMedia) +DEFINE_KEYNAME_WITH_SAME_NAME(Blue) +DEFINE_KEYNAME_WITH_SAME_NAME(Brown) +DEFINE_KEYNAME_WITH_SAME_NAME(ChannelDown) +DEFINE_KEYNAME_WITH_SAME_NAME(ChannelUp) +DEFINE_KEYNAME_WITH_SAME_NAME(ClearFavorite0) +DEFINE_KEYNAME_WITH_SAME_NAME(ClearFavorite1) +DEFINE_KEYNAME_WITH_SAME_NAME(ClearFavorite2) +DEFINE_KEYNAME_WITH_SAME_NAME(ClearFavorite3) +DEFINE_KEYNAME_WITH_SAME_NAME(Dimmer) +DEFINE_KEYNAME_WITH_SAME_NAME(DisplaySwap) +DEFINE_KEYNAME_WITH_SAME_NAME(FastFwd) +DEFINE_KEYNAME_WITH_SAME_NAME(Green) +DEFINE_KEYNAME_WITH_SAME_NAME(Grey) +DEFINE_KEYNAME_WITH_SAME_NAME(Guide) +DEFINE_KEYNAME_WITH_SAME_NAME(InstantReplay) +DEFINE_KEYNAME_WITH_SAME_NAME(MediaLast) +DEFINE_KEYNAME_WITH_SAME_NAME(Link) +DEFINE_KEYNAME_WITH_SAME_NAME(Live) +DEFINE_KEYNAME_WITH_SAME_NAME(Lock) +DEFINE_KEYNAME_WITH_SAME_NAME(NextDay) +DEFINE_KEYNAME_WITH_SAME_NAME(NextFavoriteChannel) +DEFINE_KEYNAME_WITH_SAME_NAME(OnDemand) +DEFINE_KEYNAME_WITH_SAME_NAME(PinPDown) +DEFINE_KEYNAME_WITH_SAME_NAME(PinPMove) +DEFINE_KEYNAME_WITH_SAME_NAME(PinPToggle) +DEFINE_KEYNAME_WITH_SAME_NAME(PinPUp) +DEFINE_KEYNAME_WITH_SAME_NAME(PlaySpeedDown) +DEFINE_KEYNAME_WITH_SAME_NAME(PlaySpeedReset) +DEFINE_KEYNAME_WITH_SAME_NAME(PlaySpeedUp) +DEFINE_KEYNAME_WITH_SAME_NAME(PrevDay) +DEFINE_KEYNAME_WITH_SAME_NAME(RandomToggle) +DEFINE_KEYNAME_WITH_SAME_NAME(RecallFavorite0) +DEFINE_KEYNAME_WITH_SAME_NAME(RecallFavorite1) +DEFINE_KEYNAME_WITH_SAME_NAME(RecallFavorite2) +DEFINE_KEYNAME_WITH_SAME_NAME(RecallFavorite3) +DEFINE_KEYNAME_WITH_SAME_NAME(MediaRecord) +DEFINE_KEYNAME_WITH_SAME_NAME(RecordSpeedNext) +DEFINE_KEYNAME_WITH_SAME_NAME(Red) +DEFINE_KEYNAME_WITH_SAME_NAME(MediaRewind) +DEFINE_KEYNAME_WITH_SAME_NAME(RfBypass) +DEFINE_KEYNAME_WITH_SAME_NAME(ScanChannelsToggle) +DEFINE_KEYNAME_WITH_SAME_NAME(ScreenModeNext) +DEFINE_KEYNAME_WITH_SAME_NAME(Settings) +DEFINE_KEYNAME_WITH_SAME_NAME(SplitScreenToggle) +DEFINE_KEYNAME_WITH_SAME_NAME(StoreFavorite0) +DEFINE_KEYNAME_WITH_SAME_NAME(StoreFavorite1) +DEFINE_KEYNAME_WITH_SAME_NAME(StoreFavorite2) +DEFINE_KEYNAME_WITH_SAME_NAME(StoreFavorite3) +DEFINE_KEYNAME_WITH_SAME_NAME(Subtitle) +DEFINE_KEYNAME_WITH_SAME_NAME(AudioSurroundModeNext) +DEFINE_KEYNAME_WITH_SAME_NAME(Teletext) +DEFINE_KEYNAME_WITH_SAME_NAME(VideoModeNext) +DEFINE_KEYNAME_WITH_SAME_NAME(DisplayWide) +DEFINE_KEYNAME_WITH_SAME_NAME(Wink) +DEFINE_KEYNAME_WITH_SAME_NAME(Yellow) + +#undef DEFINE_KEYNAME_WITH_SAME_NAME +#undef DEFINE_KEYNAME_INTERNAL diff --git a/content/events/src/nsDOMEvent.cpp b/content/events/src/nsDOMEvent.cpp index 18058e53fa0..9833a62d452 100644 --- a/content/events/src/nsDOMEvent.cpp +++ b/content/events/src/nsDOMEvent.cpp @@ -620,6 +620,7 @@ nsDOMEvent::DuplicatePrivateData() keyEvent->charCode = oldKeyEvent->charCode; keyEvent->location = oldKeyEvent->location; keyEvent->isChar = oldKeyEvent->isChar; + keyEvent->mKeyNameIndex = oldKeyEvent->mKeyNameIndex; newEvent = keyEvent; break; } diff --git a/content/events/src/nsDOMKeyboardEvent.cpp b/content/events/src/nsDOMKeyboardEvent.cpp index 195f9e47304..61f4fe6c08e 100644 --- a/content/events/src/nsDOMKeyboardEvent.cpp +++ b/content/events/src/nsDOMKeyboardEvent.cpp @@ -84,6 +84,15 @@ nsDOMKeyboardEvent::GetModifierState(const nsAString& aKey, return NS_OK; } +NS_IMETHODIMP +nsDOMKeyboardEvent::GetKey(nsAString& aKeyName) +{ + if (!mEventIsInternal) { + static_cast(mEvent)->GetDOMKeyName(aKeyName); + } + return NS_OK; +} + NS_IMETHODIMP nsDOMKeyboardEvent::GetCharCode(uint32_t* aCharCode) { diff --git a/content/events/test/test_dom_keyboard_event.html b/content/events/test/test_dom_keyboard_event.html index 4c39ca87dce..80e5c349bb2 100644 --- a/content/events/test/test_dom_keyboard_event.html +++ b/content/events/test/test_dom_keyboard_event.html @@ -120,6 +120,9 @@ function testInitializingUntrustedEvent() } is(e.isTrusted, false, description + "isTrusted returns wrong value"); + // Currently, there is no way to initialize char and key attribute values. + ok(e.key === "", description + "key must return empty string - got " + e.key); + // getModifierState() tests is(e.getModifierState("Shift"), kTest.shiftKey, description + "getModifierState(\"Shift\") returns wrong value"); diff --git a/dom/interfaces/events/nsIDOMKeyEvent.idl b/dom/interfaces/events/nsIDOMKeyEvent.idl index bd1d6e99131..f17bceeca1f 100644 --- a/dom/interfaces/events/nsIDOMKeyEvent.idl +++ b/dom/interfaces/events/nsIDOMKeyEvent.idl @@ -5,7 +5,7 @@ #include "nsIDOMUIEvent.idl" -[scriptable, builtinclass, uuid(ffbe684c-ca90-4b58-aa8c-9727f997f86d)] +[scriptable, builtinclass, uuid(91a3d7f2-223b-4e09-a566-634e7ee0a31d)] interface nsIDOMKeyEvent : nsIDOMUIEvent { const unsigned long DOM_VK_CANCEL = 0x03; @@ -252,4 +252,6 @@ interface nsIDOMKeyEvent : nsIDOMUIEvent const unsigned long DOM_KEY_LOCATION_JOYSTICK = 0x05; readonly attribute unsigned long location; + + readonly attribute DOMString key; }; diff --git a/dom/webidl/KeyEvent.webidl b/dom/webidl/KeyEvent.webidl index 374d686f701..d7e17db664d 100644 --- a/dom/webidl/KeyEvent.webidl +++ b/dom/webidl/KeyEvent.webidl @@ -253,4 +253,6 @@ interface KeyEvent : UIEvent const unsigned long DOM_KEY_LOCATION_JOYSTICK = 0x05; readonly attribute unsigned long location; + + readonly attribute DOMString key; }; diff --git a/widget/nsEvent.h b/widget/nsEvent.h index 0bb600b9c49..2702a023e35 100644 --- a/widget/nsEvent.h +++ b/widget/nsEvent.h @@ -115,6 +115,18 @@ enum NotificationToIME { REQUEST_TO_CANCEL_COMPOSITION }; +#define NS_DEFINE_KEYNAME(aCPPName, aDOMKeyName) \ + KEY_NAME_INDEX_##aCPPName, + +enum KeyNameIndex { +#include "nsDOMKeyNameList.h" + // There shouldn't be "," at the end of enum definition, this dummy item + // avoids bustage on some platforms. + NUMBER_OF_KEY_NAME_INDEX +}; + +#undef NS_DEFINE_KEYNAME + } // namespace widget } // namespace mozilla diff --git a/widget/nsGUIEvent.h b/widget/nsGUIEvent.h index 76c64ced720..fb8330464eb 100644 --- a/widget/nsGUIEvent.h +++ b/widget/nsGUIEvent.h @@ -1065,7 +1065,8 @@ public: nsKeyEvent(bool isTrusted, uint32_t msg, nsIWidget *w) : nsInputEvent(isTrusted, msg, w, NS_KEY_EVENT), keyCode(0), charCode(0), - location(nsIDOMKeyEvent::DOM_KEY_LOCATION_STANDARD), isChar(0) + location(nsIDOMKeyEvent::DOM_KEY_LOCATION_STANDARD), isChar(0), + mKeyNameIndex(mozilla::widget::KEY_NAME_INDEX_Unidentified) { } @@ -1080,6 +1081,28 @@ public: nsTArray alternativeCharCodes; // indicates whether the event signifies a printable character bool isChar; + // DOM KeyboardEvent.key + mozilla::widget::KeyNameIndex mKeyNameIndex; + + void GetDOMKeyName(nsAString& aKeyName) + { + GetDOMKeyName(mKeyNameIndex, aKeyName); + } + + static void GetDOMKeyName(mozilla::widget::KeyNameIndex aKeyNameIndex, + nsAString& aKeyName) + { +#define NS_DEFINE_KEYNAME(aCPPName, aDOMKeyName) \ + case mozilla::widget::KEY_NAME_INDEX_##aCPPName: \ + aKeyName.Assign(NS_LITERAL_STRING(aDOMKeyName)); return; + switch (aKeyNameIndex) { +#include "nsDOMKeyNameList.h" + default: + aKeyName.Truncate(); + return; + } +#undef NS_DEFINE_KEYNAME + } }; /** diff --git a/widget/nsGUIEventIPC.h b/widget/nsGUIEventIPC.h index 8f01a4c9524..1bb77748978 100644 --- a/widget/nsGUIEventIPC.h +++ b/widget/nsGUIEventIPC.h @@ -253,6 +253,7 @@ struct ParamTraits static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, static_cast(aParam)); + WriteParam(aMsg, static_cast(aParam.mKeyNameIndex)); WriteParam(aMsg, aParam.keyCode); WriteParam(aMsg, aParam.charCode); WriteParam(aMsg, aParam.isChar); @@ -261,11 +262,17 @@ struct ParamTraits static bool Read(const Message* aMsg, void** aIter, paramType* aResult) { - return ReadParam(aMsg, aIter, static_cast(aResult)) && - ReadParam(aMsg, aIter, &aResult->keyCode) && - ReadParam(aMsg, aIter, &aResult->charCode) && - ReadParam(aMsg, aIter, &aResult->isChar) && - ReadParam(aMsg, aIter, &aResult->location); + bool rv; + uint32_t keyNameIndex; + rv = ReadParam(aMsg, aIter, static_cast(aResult)) && + ReadParam(aMsg, aIter, &keyNameIndex) && + ReadParam(aMsg, aIter, &aResult->keyCode) && + ReadParam(aMsg, aIter, &aResult->charCode) && + ReadParam(aMsg, aIter, &aResult->isChar) && + ReadParam(aMsg, aIter, &aResult->location); + aResult->mKeyNameIndex = + static_cast(keyNameIndex); + return rv; } }; diff --git a/widget/shared/WidgetUtils.cpp b/widget/shared/WidgetUtils.cpp index 182d9efbddf..fd4a2804815 100644 --- a/widget/shared/WidgetUtils.cpp +++ b/widget/shared/WidgetUtils.cpp @@ -166,5 +166,76 @@ WidgetUtils::GetLatinCharCodeForKeyCode(uint32_t aKeyCode, } } +// static +KeyNameIndex +WidgetUtils::GetDeadKeyNameIndex(PRUnichar aChar) +{ + switch (aChar) { + case '`': + case 0x02CB: // MODIFIER LETTER GRAVE ACCENT + case 0x0300: // COMBINING GRAVE ACCENT + return KEY_NAME_INDEX_DeadGrave; + case '\'': + case 0x00B4: // ACUTE ACCENT + case 0x02B9: // MODIFIER LETTER PRIME + case 0x02CA: // MODIFIER LETTER ACUTE ACCENT + case 0x0301: // COMBINING ACUTE ACCENT + case 0x0384: // GREEK TONOS + return KEY_NAME_INDEX_DeadAcute; + case '^': + case 0x02C6: // MODIFIER LETTER CIRCUMFLEX ACCENT + case 0x0302: // COMBINING CIRCUMFLEX ACCENT + return KEY_NAME_INDEX_DeadCircumflex; + case '~': + case 0x02DC: // SMALL TILDE + case 0x0303: // COMBINING TILDE + return KEY_NAME_INDEX_DeadTilde; + case 0x00AF: // MACRON + case 0x02C9: // MODIFIER LETTER MACRON + case 0x0304: // COMBINING MACRON + return KEY_NAME_INDEX_DeadMacron; + case 0x02D8: // BRAVE + case 0xA67C: // COMBINING CYRILLIC KAVYKA + case 0x0306: // COMBINING BRAVE + return KEY_NAME_INDEX_DeadBreve; + case 0x02D9: // DOT ABOVE + case 0x0307: // COMBINING DOT ABOVE + return KEY_NAME_INDEX_DeadAboveDot; + case 0x00A8: // DIAERESIS + case 0x0308: // COMBINING DIAERESIS + return KEY_NAME_INDEX_DeadUmlaut; + case 0x00B0: // DEGREE SIGN + case 0x02DA: // RING ABOVE + case 0x030A: // COMBINING RING ABOVE + return KEY_NAME_INDEX_DeadAboveRing; + case '"': + case 0x02BA: // MODIFIER LETTER DOUBLE PRIME + case 0x02DD: // DOUBLE ACUTE ACCENT + case 0x030B: // COMBINING DOUBLE ACUTE ACCENT + return KEY_NAME_INDEX_DeadDoubleacute; + case 0x02C7: // CARON + case 0x030C: // COMBINING CARON + return KEY_NAME_INDEX_DeadCaron; + case 0x00B8: // CEDILLA + case 0x0327: // COMBINING CEDILLA + return KEY_NAME_INDEX_DeadCedilla; + case 0x02DB: // OGONEK + case 0x0328: // COMBINING OGONEK + return KEY_NAME_INDEX_DeadOgonek; + case 0x0345: // COMBINING GREEK YPOGEGRAMMENI + case 0x037A: // GREEK YPOGEGRAMMENI + case 0x0399: // GREEK CAPITAL LETTER IOTA + return KEY_NAME_INDEX_DeadIota; + case 0x3099: // COMBINING KATAKANA-HIRAGANA VOICED SOUND MARK + case 0x309B: // KATAKANA-HIRAGANA VOICED SOUND MARK + return KEY_NAME_INDEX_DeadVoicedSound; + case 0x309A: // COMBINING KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK + case 0x309C: // KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK + return KEY_NAME_INDEX_DeadSemivoicedSound; + default: + return KEY_NAME_INDEX_Unidentified; + } +} + } // namespace widget } // namespace mozilla diff --git a/widget/shared/WidgetUtils.h b/widget/shared/WidgetUtils.h index 1a392bd4a90..5debf916acd 100644 --- a/widget/shared/WidgetUtils.h +++ b/widget/shared/WidgetUtils.h @@ -9,6 +9,7 @@ #include "nsCOMPtr.h" #include "nsIWidget.h" +#include "nsEvent.h" #include "nsPIDOMWindow.h" #include "nsIDOMWindow.h" @@ -50,6 +51,14 @@ public: bool aIsCapsLock, uint32_t* aUnshiftedCharCode, uint32_t* aShiftedCharCode); + + /** + * GetDeadKeyNameIndex() returns a key name index for dead key or + * "Unidentified". This method can return the index from non-combining + * unicode character, e.g., '`' returns KEY_NAME_INDEX_DeadGrave. + * So, you cannot use this method for checking if the char is a dead char. + */ + static KeyNameIndex GetDeadKeyNameIndex(PRUnichar aChar); }; } // namespace widget