[GTK] Should support key and code properties on keyboard events
authorgns@gnome.org <gns@gnome.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Jan 2017 14:14:57 +0000 (14:14 +0000)
committergns@gnome.org <gns@gnome.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Jan 2017 14:14:57 +0000 (14:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=166759

Reviewed by Carlos Garcia Campos.

Source/WebCore:

This change fixes a bunch of tests which are currently failing, such as:
- fast/events/arrow-keys-on-body.html
- fast/events/constructors/keyboard-event-constructor.html
- fast/events/key-events-in-input-button.html
- fast/events/key-events-in-input-text.html
- fast/events/keyboardevent-code.html
- fast/events/keyboardevent-key.html

* platform/PlatformKeyboardEvent.h:
* platform/gtk/PlatformKeyboardEventGtk.cpp:
(WebCore::PlatformKeyboardEvent::keyValueForGdkKeyCode): match web key value
to GDK key symbol.
(WebCore::PlatformKeyboardEvent::keyCodeForHardwareKeyCode): match web key code
to hardware code as reported by GDK.
(WebCore::PlatformKeyboardEvent::PlatformKeyboardEvent): add web key value and
code to the keyboard event upon creation.

Source/WebKit2:

* Shared/WebEvent.h:
* Shared/WebKeyboardEvent.cpp:
(WebKit::WebKeyboardEvent::WebKeyboardEvent): accept web key value and code on construction.
* Shared/gtk/WebEventFactory.cpp:
(WebKit::WebEventFactory::createWebKeyboardEvent): pass web key value and code on construction.

Source/WTF:

* wtf/FeatureDefines.h: enable key and code properties support for GTK.

Tools:

* WebKitTestRunner/gtk/EventSenderProxyGtk.cpp:
(WTR::getGDKKeySymForKeyRef): add missing modifier keys which were being reported as 'l' and 'r' only
on tests.

LayoutTests:

* platform/gtk/fast/events/keyboardevent-code-expected.txt: Added. Hardware
codes are different for Mac and Linux for a couple of keys, so we need
platform-specific results.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@210504 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/gtk/fast/events/keyboardevent-code-expected.txt [new file with mode: 0644]
Source/WTF/ChangeLog
Source/WTF/wtf/FeatureDefines.h
Source/WebCore/ChangeLog
Source/WebCore/platform/PlatformKeyboardEvent.h
Source/WebCore/platform/gtk/PlatformKeyboardEventGtk.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebEvent.h
Source/WebKit2/Shared/WebKeyboardEvent.cpp
Source/WebKit2/Shared/gtk/WebEventFactory.cpp
Tools/ChangeLog
Tools/WebKitTestRunner/gtk/EventSenderProxyGtk.cpp

index e92b99a..a2bdc7a 100644 (file)
@@ -1,3 +1,14 @@
+2017-01-06  Gustavo Noronha Silva  <gustavo.noronha@collabora.co.uk>
+
+        [GTK] Should support key and code properties on keyboard events
+        https://bugs.webkit.org/show_bug.cgi?id=166759
+
+        Reviewed by Carlos Garcia Campos.
+
+        * platform/gtk/fast/events/keyboardevent-code-expected.txt: Added. Hardware
+        codes are different for Mac and Linux for a couple of keys, so we need
+        platform-specific results.
+
 2017-01-09  Alejandro G. Castro  <alex@igalia.com>
 
         [OWR] Unskip fast/mediastream/MediaStream-video-element-track-stop.html
diff --git a/LayoutTests/platform/gtk/fast/events/keyboardevent-code-expected.txt b/LayoutTests/platform/gtk/fast/events/keyboardevent-code-expected.txt
new file mode 100644 (file)
index 0000000..15fd291
--- /dev/null
@@ -0,0 +1,190 @@
+Test the code attribute on KeyboardEvent.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+* keydown
+PASS keyboardEvent.code is "Space"
+* keyup
+PASS keyboardEvent.code is "Space"
+
+* keydown
+PASS keyboardEvent.code is "KeyA"
+* keyup
+PASS keyboardEvent.code is "KeyA"
+
+* keydown
+PASS keyboardEvent.code is "Backspace"
+* keyup
+PASS keyboardEvent.code is "Backspace"
+
+* keydown
+FAIL keyboardEvent.code should be Minus. Was Escape.
+* keyup
+FAIL keyboardEvent.code should be Minus. Was Escape.
+
+* keydown
+PASS keyboardEvent.code is "ArrowLeft"
+* keyup
+PASS keyboardEvent.code is "ArrowLeft"
+
+* keydown
+PASS keyboardEvent.code is "ArrowRight"
+* keyup
+PASS keyboardEvent.code is "ArrowRight"
+
+* keydown
+PASS keyboardEvent.code is "ArrowUp"
+* keyup
+PASS keyboardEvent.code is "ArrowUp"
+
+* keydown
+PASS keyboardEvent.code is "ArrowDown"
+* keyup
+PASS keyboardEvent.code is "ArrowDown"
+
+* keydown
+PASS keyboardEvent.code is "PageUp"
+* keyup
+PASS keyboardEvent.code is "PageUp"
+
+* keydown
+PASS keyboardEvent.code is "PageDown"
+* keyup
+PASS keyboardEvent.code is "PageDown"
+
+* keydown
+PASS keyboardEvent.code is "Home"
+* keyup
+PASS keyboardEvent.code is "Home"
+
+* keydown
+PASS keyboardEvent.code is "End"
+* keyup
+PASS keyboardEvent.code is "End"
+
+* keydown
+PASS keyboardEvent.code is "Delete"
+* keyup
+PASS keyboardEvent.code is "Delete"
+
+* keydown
+PASS keyboardEvent.code is "ControlLeft"
+* keyup
+PASS keyboardEvent.code is "ControlLeft"
+
+* keydown
+PASS keyboardEvent.code is "ShiftLeft"
+* keyup
+PASS keyboardEvent.code is "ShiftLeft"
+
+* keydown
+PASS keyboardEvent.code is "AltLeft"
+* keyup
+PASS keyboardEvent.code is "AltLeft"
+
+* keydown
+PASS keyboardEvent.code is "ControlRight"
+* keyup
+PASS keyboardEvent.code is "ControlRight"
+
+* keydown
+PASS keyboardEvent.code is "ShiftRight"
+* keyup
+PASS keyboardEvent.code is "ShiftRight"
+
+* keydown
+PASS keyboardEvent.code is "AltRight"
+* keyup
+PASS keyboardEvent.code is "AltRight"
+
+* keydown
+PASS keyboardEvent.code is "F1"
+* keyup
+PASS keyboardEvent.code is "F1"
+
+* keydown
+PASS keyboardEvent.code is "F2"
+* keyup
+PASS keyboardEvent.code is "F2"
+
+* keydown
+PASS keyboardEvent.code is "F3"
+* keyup
+PASS keyboardEvent.code is "F3"
+
+* keydown
+PASS keyboardEvent.code is "F4"
+* keyup
+PASS keyboardEvent.code is "F4"
+
+* keydown
+PASS keyboardEvent.code is "F5"
+* keyup
+PASS keyboardEvent.code is "F5"
+
+* keydown
+PASS keyboardEvent.code is "F6"
+* keyup
+PASS keyboardEvent.code is "F6"
+
+* keydown
+PASS keyboardEvent.code is "F7"
+* keyup
+PASS keyboardEvent.code is "F7"
+
+* keydown
+PASS keyboardEvent.code is "F8"
+* keyup
+PASS keyboardEvent.code is "F8"
+
+* keydown
+PASS keyboardEvent.code is "F9"
+* keyup
+PASS keyboardEvent.code is "F9"
+
+* keydown
+PASS keyboardEvent.code is "F10"
+* keyup
+PASS keyboardEvent.code is "F10"
+
+* keydown
+PASS keyboardEvent.code is "F11"
+* keyup
+PASS keyboardEvent.code is "F11"
+
+* keydown
+PASS keyboardEvent.code is "F12"
+* keyup
+PASS keyboardEvent.code is "F12"
+
+* keydown
+FAIL keyboardEvent.code should be NumpadEnter. Was Enter.
+* keyup
+FAIL keyboardEvent.code should be NumpadEnter. Was Enter.
+
+* keydown
+PASS keyboardEvent.code is "KeyA"
+* keyup
+PASS keyboardEvent.code is "KeyA"
+
+* keydown
+PASS keyboardEvent.code is "KeyA"
+* keyup
+PASS keyboardEvent.code is "KeyA"
+
+* keydown
+PASS keyboardEvent.code is "KeyA"
+* keyup
+PASS keyboardEvent.code is "KeyA"
+
+* keydown
+PASS keyboardEvent.code is "Digit1"
+* keyup
+PASS keyboardEvent.code is "Digit1"
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
index b988a32..02656cd 100644 (file)
@@ -1,3 +1,12 @@
+2017-01-06  Gustavo Noronha Silva  <gustavo.noronha@collabora.co.uk>
+
+        [GTK] Should support key and code properties on keyboard events
+        https://bugs.webkit.org/show_bug.cgi?id=166759
+
+        Reviewed by Carlos Garcia Campos.
+
+        * wtf/FeatureDefines.h: enable key and code properties support for GTK.
+
 2017-01-08  Antti Koivisto  <antti@apple.com>
 
         Move cache coders to WTF
index 2942ef1..f56af24 100644 (file)
@@ -324,6 +324,13 @@ the public iOS SDK. We will also need to update the FeatureDefines.xcconfig file
 
 /* --------- Gtk port (Unix, Windows, Mac) --------- */
 #if PLATFORM(GTK)
+#if !defined(ENABLE_KEYBOARD_KEY_ATTRIBUTE)
+#define ENABLE_KEYBOARD_KEY_ATTRIBUTE 1
+#endif
+
+#if !defined(ENABLE_KEYBOARD_CODE_ATTRIBUTE)
+#define ENABLE_KEYBOARD_CODE_ATTRIBUTE 1
+#endif
 #endif /* PLATFORM(GTK) */
 
 /* ENABLE macro defaults for WebCore */
index d31eb7a..100d950 100644 (file)
@@ -1,3 +1,27 @@
+2017-01-06  Gustavo Noronha Silva  <gustavo.noronha@collabora.co.uk>
+
+        [GTK] Should support key and code properties on keyboard events
+        https://bugs.webkit.org/show_bug.cgi?id=166759
+
+        Reviewed by Carlos Garcia Campos.
+
+        This change fixes a bunch of tests which are currently failing, such as:
+        - fast/events/arrow-keys-on-body.html
+        - fast/events/constructors/keyboard-event-constructor.html
+        - fast/events/key-events-in-input-button.html
+        - fast/events/key-events-in-input-text.html
+        - fast/events/keyboardevent-code.html
+        - fast/events/keyboardevent-key.html
+
+        * platform/PlatformKeyboardEvent.h:
+        * platform/gtk/PlatformKeyboardEventGtk.cpp:
+        (WebCore::PlatformKeyboardEvent::keyValueForGdkKeyCode): match web key value
+        to GDK key symbol.
+        (WebCore::PlatformKeyboardEvent::keyCodeForHardwareKeyCode): match web key code
+        to hardware code as reported by GDK.
+        (WebCore::PlatformKeyboardEvent::PlatformKeyboardEvent): add web key value and
+        code to the keyboard event upon creation.
+
 2017-01-09  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] WebProcess from WebKitGtk+ 2.15.2 SIGSEGVs in std::unique_ptr<SoupBuffer, WTF::GPtrDeleter<SoupBuffer> >::get() const () at /usr/include/c++/6/bits/unique_ptr.h:305
index 7f40d69..679a4e4 100644 (file)
@@ -161,6 +161,8 @@ namespace WebCore {
         const CompositionResults& compositionResults() const { return m_compositionResults; }
 
         // Used by WebKit2
+        static String keyValueForGdkKeyCode(unsigned);
+        static String keyCodeForHardwareKeyCode(unsigned);
         static String keyIdentifierForGdkKeyCode(unsigned);
         static int windowsKeyCodeForGdkKeyCode(unsigned);
         static String singleCharacterString(unsigned);
index 8bdd48f..176e690 100644 (file)
 #include "NotImplemented.h"
 #include "TextEncoding.h"
 #include "WindowsKeyboardCodes.h"
-
 #include <gdk/gdk.h>
 #include <gdk/gdkkeysyms.h>
 #include <wtf/CurrentTime.h>
+#include <wtf/glib/GUniquePtr.h>
 
 namespace WebCore {
 
 // FIXME: This is incomplete.  We should change this to mirror
 // more like what Firefox does, and generate these switch statements
 // at build time.
+// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values
+String PlatformKeyboardEvent::keyValueForGdkKeyCode(unsigned keyCode)
+{
+    switch (keyCode) {
+    // Modifier keys.
+    case GDK_KEY_Alt_L:
+    case GDK_KEY_Alt_R:
+        return ASCIILiteral("Alt");
+    // Firefox uses GDK_KEY_Mode_switch for AltGraph as well.
+    case GDK_KEY_ISO_Level3_Shift:
+    case GDK_KEY_ISO_Level3_Latch:
+    case GDK_KEY_ISO_Level3_Lock:
+    case GDK_KEY_ISO_Level5_Shift:
+    case GDK_KEY_ISO_Level5_Latch:
+    case GDK_KEY_ISO_Level5_Lock:
+        return ASCIILiteral("AltGraph");
+    case GDK_KEY_Caps_Lock:
+        return ASCIILiteral("CapsLock");
+    case GDK_KEY_Control_L:
+    case GDK_KEY_Control_R:
+        return ASCIILiteral("Control");
+    // Fn: This is typically a hardware key that does not generate a separate code.
+    // FnLock.
+    case GDK_KEY_Hyper_L:
+    case GDK_KEY_Hyper_R:
+        return ASCIILiteral("Hyper");
+    case GDK_KEY_Meta_L:
+    case GDK_KEY_Meta_R:
+        return ASCIILiteral("Meta");
+    case GDK_KEY_Num_Lock:
+        return ASCIILiteral("NumLock");
+    case GDK_KEY_Scroll_Lock:
+        return ASCIILiteral("ScrollLock");
+    case GDK_KEY_Shift_L:
+    case GDK_KEY_Shift_R:
+        return ASCIILiteral("Shift");
+    case GDK_KEY_Super_L:
+    case GDK_KEY_Super_R:
+        return ASCIILiteral("Super");
+    // Symbol.
+    // SymbolLock.
+
+    // Whitespace keys.
+    case GDK_KEY_Return:
+    case GDK_KEY_KP_Enter:
+    case GDK_KEY_ISO_Enter:
+    case GDK_KEY_3270_Enter:
+        return ASCIILiteral("Enter");
+    case GDK_KEY_Tab:
+    case GDK_KEY_KP_Tab:
+        return ASCIILiteral("Tab");
+
+    // Navigation keys.
+    case GDK_KEY_Down:
+    case GDK_KEY_KP_Down:
+        return ASCIILiteral("ArrowDown");
+    case GDK_KEY_Left:
+    case GDK_KEY_KP_Left:
+        return ASCIILiteral("ArrowLeft");
+    case GDK_KEY_Right:
+    case GDK_KEY_KP_Right:
+        return ASCIILiteral("ArrowRight");
+    case GDK_KEY_Up:
+    case GDK_KEY_KP_Up:
+        return ASCIILiteral("ArrowUp");
+    case GDK_KEY_End:
+    case GDK_KEY_KP_End:
+        return ASCIILiteral("End");
+    case GDK_KEY_Home:
+    case GDK_KEY_KP_Home:
+        return ASCIILiteral("Home");
+    case GDK_KEY_Page_Down:
+    case GDK_KEY_KP_Page_Down:
+        return ASCIILiteral("PageDown");
+    case GDK_KEY_Page_Up:
+    case GDK_KEY_KP_Page_Up:
+        return ASCIILiteral("PageUp");
+
+    // Editing keys.
+    case GDK_KEY_BackSpace:
+        return ASCIILiteral("Backspace");
+    case GDK_KEY_Clear:
+        return ASCIILiteral("Clear");
+    case GDK_KEY_Copy:
+        return ASCIILiteral("Copy");
+    case GDK_KEY_3270_CursorSelect:
+        return ASCIILiteral("CrSel");
+    case GDK_KEY_Cut:
+        return ASCIILiteral("Cut");
+    case GDK_KEY_Delete:
+    case GDK_KEY_KP_Delete:
+        return ASCIILiteral("Delete");
+    case GDK_KEY_3270_EraseEOF:
+        return ASCIILiteral("EraseEof");
+    case GDK_KEY_3270_ExSelect:
+        return ASCIILiteral("ExSel");
+    case GDK_KEY_Insert:
+    case GDK_KEY_KP_Insert:
+        return ASCIILiteral("Insert");
+    case GDK_KEY_Paste:
+        return ASCIILiteral("Paste");
+    case GDK_KEY_Redo:
+        return ASCIILiteral("Redo");
+    case GDK_KEY_Undo:
+        return ASCIILiteral("Undo");
+
+    // UI keys.
+    // Accept.
+    // Again.
+    case GDK_KEY_3270_Attn:
+        return ASCIILiteral("Attn");
+    case GDK_KEY_Cancel:
+        return ASCIILiteral("Cancel");
+    case GDK_KEY_Menu:
+        return ASCIILiteral("ContextMenu");
+    case GDK_KEY_Escape:
+        return ASCIILiteral("Escape");
+    case GDK_KEY_Execute:
+        return ASCIILiteral("Execute");
+    case GDK_KEY_Find:
+        return ASCIILiteral("Find");
+    case GDK_KEY_Help:
+        return ASCIILiteral("Help");
+    case GDK_KEY_Pause:
+    case GDK_KEY_Break:
+        return ASCIILiteral("Pause");
+    case GDK_KEY_3270_Play:
+        return ASCIILiteral("Play");
+    // Props.
+    case GDK_KEY_Select:
+        return ASCIILiteral("Select");
+    case GDK_KEY_ZoomIn:
+        return ASCIILiteral("ZoomIn");
+    case GDK_KEY_ZoomOut:
+        return ASCIILiteral("ZoomOut");
+
+    // Device keys.
+    case GDK_KEY_MonBrightnessDown:
+        return ASCIILiteral("BrightnessDown");
+    case GDK_KEY_MonBrightnessUp:
+        return ASCIILiteral("BrightnessUp");
+    case GDK_KEY_Eject:
+        return ASCIILiteral("Eject");
+    case GDK_KEY_LogOff:
+        return ASCIILiteral("LogOff");
+    // Power.
+    case GDK_KEY_PowerDown:
+    case GDK_KEY_PowerOff:
+        return ASCIILiteral("PowerOff");
+    case GDK_KEY_3270_PrintScreen:
+    case GDK_KEY_Print:
+    case GDK_KEY_Sys_Req:
+        return ASCIILiteral("PrintScreen");
+    case GDK_KEY_Hibernate:
+        return ASCIILiteral("Hibernate");
+    case GDK_KEY_Standby:
+    case GDK_KEY_Suspend:
+    case GDK_KEY_Sleep:
+        return ASCIILiteral("Standby");
+    case GDK_KEY_WakeUp:
+        return ASCIILiteral("WakeUp");
+
+    // IME keys.
+    case GDK_KEY_MultipleCandidate:
+        return ASCIILiteral("AllCandidates");
+    case GDK_KEY_Eisu_Shift:
+    case GDK_KEY_Eisu_toggle:
+        return ASCIILiteral("Alphanumeric");
+    case GDK_KEY_Codeinput:
+        return ASCIILiteral("CodeInput");
+    case GDK_KEY_Multi_key:
+        return ASCIILiteral("Compose");
+    case GDK_KEY_Henkan:
+        return ASCIILiteral("Convert");
+    case GDK_KEY_dead_grave:
+    case GDK_KEY_dead_acute:
+    case GDK_KEY_dead_circumflex:
+    case GDK_KEY_dead_tilde:
+    case GDK_KEY_dead_macron:
+    case GDK_KEY_dead_breve:
+    case GDK_KEY_dead_abovedot:
+    case GDK_KEY_dead_diaeresis:
+    case GDK_KEY_dead_abovering:
+    case GDK_KEY_dead_doubleacute:
+    case GDK_KEY_dead_caron:
+    case GDK_KEY_dead_cedilla:
+    case GDK_KEY_dead_ogonek:
+    case GDK_KEY_dead_iota:
+    case GDK_KEY_dead_voiced_sound:
+    case GDK_KEY_dead_semivoiced_sound:
+    case GDK_KEY_dead_belowdot:
+    case GDK_KEY_dead_hook:
+    case GDK_KEY_dead_horn:
+    case GDK_KEY_dead_stroke:
+    case GDK_KEY_dead_abovecomma:
+    case GDK_KEY_dead_abovereversedcomma:
+    case GDK_KEY_dead_doublegrave:
+    case GDK_KEY_dead_belowring:
+    case GDK_KEY_dead_belowmacron:
+    case GDK_KEY_dead_belowcircumflex:
+    case GDK_KEY_dead_belowtilde:
+    case GDK_KEY_dead_belowbreve:
+    case GDK_KEY_dead_belowdiaeresis:
+    case GDK_KEY_dead_invertedbreve:
+    case GDK_KEY_dead_belowcomma:
+    case GDK_KEY_dead_currency:
+    case GDK_KEY_dead_a:
+    case GDK_KEY_dead_A:
+    case GDK_KEY_dead_e:
+    case GDK_KEY_dead_E:
+    case GDK_KEY_dead_i:
+    case GDK_KEY_dead_I:
+    case GDK_KEY_dead_o:
+    case GDK_KEY_dead_O:
+    case GDK_KEY_dead_u:
+    case GDK_KEY_dead_U:
+    case GDK_KEY_dead_small_schwa:
+    case GDK_KEY_dead_capital_schwa:
+        return ASCIILiteral("Dead");
+    // FinalMode
+    case GDK_KEY_ISO_First_Group:
+        return ASCIILiteral("GroupFirst");
+    case GDK_KEY_ISO_Last_Group:
+        return ASCIILiteral("GroupLast");
+    case GDK_KEY_ISO_Next_Group:
+        return ASCIILiteral("GroupNext");
+    case GDK_KEY_ISO_Prev_Group:
+        return ASCIILiteral("GroupPrevious");
+    case GDK_KEY_Mode_switch:
+        return ASCIILiteral("ModeChange");
+    // NextCandidate.
+    case GDK_KEY_Muhenkan:
+        return ASCIILiteral("NonConvert");
+    case GDK_KEY_PreviousCandidate:
+        return ASCIILiteral("PreviousCandidate");
+    // Process.
+    case GDK_KEY_SingleCandidate:
+        return ASCIILiteral("SingleCandidate");
+
+    // Korean and Japanese keys.
+    case GDK_KEY_Hangul:
+        return ASCIILiteral("HangulMode");
+    case GDK_KEY_Hangul_Hanja:
+        return ASCIILiteral("HanjaMode");
+    case GDK_KEY_Hangul_Jeonja:
+        return ASCIILiteral("JunjaMode");
+    case GDK_KEY_Hankaku:
+        return ASCIILiteral("Hankaku");
+    case GDK_KEY_Hiragana:
+        return ASCIILiteral("Hiragana");
+    case GDK_KEY_Hiragana_Katakana:
+        return ASCIILiteral("HiraganaKatakana");
+    case GDK_KEY_Kana_Lock:
+    case GDK_KEY_Kana_Shift:
+        return ASCIILiteral("KanaMode");
+    case GDK_KEY_Kanji:
+        return ASCIILiteral("KanjiMode");
+    case GDK_KEY_Katakana:
+        return ASCIILiteral("Katakana");
+    case GDK_KEY_Romaji:
+        return ASCIILiteral("Romaji");
+    case GDK_KEY_Zenkaku:
+        return ASCIILiteral("Zenkaku");
+    case GDK_KEY_Zenkaku_Hankaku:
+        return ASCIILiteral("ZenkakuHanaku");
+
+    // Multimedia keys.
+    // ChannelDown.
+    // ChannelUp.
+    case GDK_KEY_Close:
+        return ASCIILiteral("Close");
+    case GDK_KEY_MailForward:
+        return ASCIILiteral("MailForward");
+    case GDK_KEY_Reply:
+        return ASCIILiteral("MailReply");
+    case GDK_KEY_Send:
+        return ASCIILiteral("MailSend");
+    case GDK_KEY_AudioForward:
+        return ASCIILiteral("MediaFastForward");
+    case GDK_KEY_AudioPause:
+        return ASCIILiteral("MediaPause");
+    case GDK_KEY_AudioPlay:
+        return ASCIILiteral("MediaPlay");
+    // MediaPlayPause
+    case GDK_KEY_AudioRecord:
+        return ASCIILiteral("MediaRecord");
+    case GDK_KEY_AudioRewind:
+        return ASCIILiteral("MediaRewind");
+    case GDK_KEY_AudioStop:
+        return ASCIILiteral("MediaStop");
+    case GDK_KEY_AudioNext:
+        return ASCIILiteral("MediaTrackNext");
+    case GDK_KEY_AudioPrev:
+        return ASCIILiteral("MediaTrackPrevious");
+    case GDK_KEY_New:
+        return ASCIILiteral("New");
+    case GDK_KEY_Open:
+        return ASCIILiteral("Open");
+    // Print.
+    case GDK_KEY_Save:
+        return ASCIILiteral("Save");
+    case GDK_KEY_Spell:
+        return ASCIILiteral("SpellCheck");
+
+    // Function keys.
+    case GDK_KEY_F1:
+        return ASCIILiteral("F1");
+    case GDK_KEY_F2:
+        return ASCIILiteral("F2");
+    case GDK_KEY_F3:
+        return ASCIILiteral("F3");
+    case GDK_KEY_F4:
+        return ASCIILiteral("F4");
+    case GDK_KEY_F5:
+        return ASCIILiteral("F5");
+    case GDK_KEY_F6:
+        return ASCIILiteral("F6");
+    case GDK_KEY_F7:
+        return ASCIILiteral("F7");
+    case GDK_KEY_F8:
+        return ASCIILiteral("F8");
+    case GDK_KEY_F9:
+        return ASCIILiteral("F9");
+    case GDK_KEY_F10:
+        return ASCIILiteral("F10");
+    case GDK_KEY_F11:
+        return ASCIILiteral("F11");
+    case GDK_KEY_F12:
+        return ASCIILiteral("F12");
+    case GDK_KEY_F13:
+        return ASCIILiteral("F13");
+    case GDK_KEY_F14:
+        return ASCIILiteral("F14");
+    case GDK_KEY_F15:
+        return ASCIILiteral("F15");
+    case GDK_KEY_F16:
+        return ASCIILiteral("F16");
+    case GDK_KEY_F17:
+        return ASCIILiteral("F17");
+    case GDK_KEY_F18:
+        return ASCIILiteral("F18");
+    case GDK_KEY_F19:
+        return ASCIILiteral("F19");
+    case GDK_KEY_F20:
+        return ASCIILiteral("F20");
+
+    default: {
+        guint32 unicodeCharacter = gdk_keyval_to_unicode(keyCode);
+        if (unicodeCharacter) {
+            // UTF-8 will use up to 6 bytes.
+            char utf8[7] = { 0 };
+            g_unichar_to_utf8(unicodeCharacter, utf8);
+            return String::fromUTF8(utf8);
+        }
+        return ASCIILiteral("Unidentified");
+    }
+    }
+}
+
+// FIXME: This is incomplete. We should change this to mirror
+// more like what Firefox does, and generate these switch statements
+// at build time.
+// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code
+String PlatformKeyboardEvent::keyCodeForHardwareKeyCode(unsigned keyCode)
+{
+    switch (keyCode) {
+    case 0x0009:
+        return ASCIILiteral("Escape");
+    case 0x000A:
+        return ASCIILiteral("Digit1");
+    case 0x000B:
+        return ASCIILiteral("Digit2");
+    case 0x000C:
+        return ASCIILiteral("Digit3");
+    case 0x000D:
+        return ASCIILiteral("Digit4");
+    case 0x000E:
+        return ASCIILiteral("Digit5");
+    case 0x000F:
+        return ASCIILiteral("Digit6");
+    case 0x0010:
+        return ASCIILiteral("Digit7");
+    case 0x0011:
+        return ASCIILiteral("Digit8");
+    case 0x0012:
+        return ASCIILiteral("Digit9");
+    case 0x0013:
+        return ASCIILiteral("Digit0");
+    case 0x0014:
+        return ASCIILiteral("Minus");
+    case 0x0015:
+        return ASCIILiteral("Equal");
+    case 0x0016:
+        return ASCIILiteral("Backspace");
+    case 0x0017:
+        return ASCIILiteral("Tab");
+    case 0x0018:
+        return ASCIILiteral("KeyQ");
+    case 0x0019:
+        return ASCIILiteral("KeyW");
+    case 0x001A:
+        return ASCIILiteral("KeyE");
+    case 0x001B:
+        return ASCIILiteral("KeyR");
+    case 0x001C:
+        return ASCIILiteral("KeyT");
+    case 0x001D:
+        return ASCIILiteral("KeyY");
+    case 0x001E:
+        return ASCIILiteral("KeyU");
+    case 0x001F:
+        return ASCIILiteral("KeyI");
+    case 0x0020:
+        return ASCIILiteral("KeyO");
+    case 0x0021:
+        return ASCIILiteral("KeyP");
+    case 0x0022:
+        return ASCIILiteral("BracketLeft");
+    case 0x0023:
+        return ASCIILiteral("BracketRight");
+    case 0x0024:
+        return ASCIILiteral("Enter");
+    case 0x0025:
+        return ASCIILiteral("ControlLeft");
+    case 0x0026:
+        return ASCIILiteral("KeyA");
+    case 0x0027:
+        return ASCIILiteral("KeyS");
+    case 0x0028:
+        return ASCIILiteral("KeyD");
+    case 0x0029:
+        return ASCIILiteral("KeyF");
+    case 0x002A:
+        return ASCIILiteral("KeyG");
+    case 0x002B:
+        return ASCIILiteral("KeyH");
+    case 0x002C:
+        return ASCIILiteral("KeyJ");
+    case 0x002D:
+        return ASCIILiteral("KeyK");
+    case 0x002E:
+        return ASCIILiteral("KeyL");
+    case 0x002F:
+        return ASCIILiteral("Semicolon");
+    case 0x0030:
+        return ASCIILiteral("Quote");
+    case 0x0031:
+        return ASCIILiteral("Backquote");
+    case 0x0032:
+        return ASCIILiteral("ShiftLeft");
+    case 0x0033:
+        return ASCIILiteral("Backslash");
+    case 0x0034:
+        return ASCIILiteral("KeyZ");
+    case 0x0035:
+        return ASCIILiteral("KeyX");
+    case 0x0036:
+        return ASCIILiteral("KeyC");
+    case 0x0037:
+        return ASCIILiteral("KeyV");
+    case 0x0038:
+        return ASCIILiteral("KeyB");
+    case 0x0039:
+        return ASCIILiteral("KeyN");
+    case 0x003A:
+        return ASCIILiteral("KeyM");
+    case 0x003B:
+        return ASCIILiteral("Comma");
+    case 0x003C:
+        return ASCIILiteral("Period");
+    case 0x003D:
+        return ASCIILiteral("Slash");
+    case 0x003E:
+        return ASCIILiteral("ShiftRight");
+    case 0x003F:
+        return ASCIILiteral("NumpadMultiply");
+    case 0x0040:
+        return ASCIILiteral("AltLeft");
+    case 0x0041:
+        return ASCIILiteral("Space");
+    case 0x0042:
+        return ASCIILiteral("CapsLock");
+    case 0x0043:
+        return ASCIILiteral("F1");
+    case 0x0044:
+        return ASCIILiteral("F2");
+    case 0x0045:
+        return ASCIILiteral("F3");
+    case 0x0046:
+        return ASCIILiteral("F4");
+    case 0x0047:
+        return ASCIILiteral("F5");
+    case 0x0048:
+        return ASCIILiteral("F6");
+    case 0x0049:
+        return ASCIILiteral("F7");
+    case 0x004A:
+        return ASCIILiteral("F8");
+    case 0x004B:
+        return ASCIILiteral("F9");
+    case 0x004C:
+        return ASCIILiteral("F10");
+    case 0x004D:
+        return ASCIILiteral("NumLock");
+    case 0x004E:
+        return ASCIILiteral("ScrollLock");
+    case 0x004F:
+        return ASCIILiteral("Numpad7");
+    case 0x0050:
+        return ASCIILiteral("Numpad8");
+    case 0x0051:
+        return ASCIILiteral("Numpad9");
+    case 0x0052:
+        return ASCIILiteral("NumpadSubtract");
+    case 0x0053:
+        return ASCIILiteral("Numpad4");
+    case 0x0054:
+        return ASCIILiteral("Numpad5");
+    case 0x0055:
+        return ASCIILiteral("Numpad6");
+    case 0x0056:
+        return ASCIILiteral("NumpadAdd");
+    case 0x0057:
+        return ASCIILiteral("Numpad1");
+    case 0x0058:
+        return ASCIILiteral("Numpad2");
+    case 0x0059:
+        return ASCIILiteral("Numpad3");
+    case 0x005A:
+        return ASCIILiteral("Numpad0");
+    case 0x005B:
+        return ASCIILiteral("NumpadDecimal");
+    case 0x005E:
+        return ASCIILiteral("IntlBackslash");
+    case 0x005F:
+        return ASCIILiteral("F11");
+    case 0x0060:
+        return ASCIILiteral("F12");
+    case 0x0061:
+        return ASCIILiteral("IntlRo");
+    case 0x0064:
+        return ASCIILiteral("Convert");
+    case 0x0065:
+        return ASCIILiteral("KanaMode");
+    case 0x0066:
+        return ASCIILiteral("NonConvert");
+    case 0x0068:
+        return ASCIILiteral("NumpadEnter");
+    case 0x0069:
+        return ASCIILiteral("ControlRight");
+    case 0x006A:
+        return ASCIILiteral("NumpadDivide");
+    case 0x006B:
+        return ASCIILiteral("PrintScreen");
+    case 0x006C:
+        return ASCIILiteral("AltRight");
+    case 0x006E:
+        return ASCIILiteral("Home");
+    case 0x006F:
+        return ASCIILiteral("ArrowUp");
+    case 0x0070:
+        return ASCIILiteral("PageUp");
+    case 0x0071:
+        return ASCIILiteral("ArrowLeft");
+    case 0x0072:
+        return ASCIILiteral("ArrowRight");
+    case 0x0073:
+        return ASCIILiteral("End");
+    case 0x0074:
+        return ASCIILiteral("ArrowDown");
+    case 0x0075:
+        return ASCIILiteral("PageDown");
+    case 0x0076:
+        return ASCIILiteral("Insert");
+    case 0x0077:
+        return ASCIILiteral("Delete");
+    case 0x0079:
+        return ASCIILiteral("AudioVolumeMute");
+    case 0x007A:
+        return ASCIILiteral("AudioVolumeDown");
+    case 0x007B:
+        return ASCIILiteral("AudioVolumeUp");
+    case 0x007D:
+        return ASCIILiteral("NumpadEqual");
+    case 0x007F:
+        return ASCIILiteral("Pause");
+    case 0x0081:
+        return ASCIILiteral("NumpadComma");
+    case 0x0082:
+        return ASCIILiteral("Lang1");
+    case 0x0083:
+        return ASCIILiteral("Lang2");
+    case 0x0084:
+        return ASCIILiteral("IntlYen");
+    case 0x0085:
+        return ASCIILiteral("OSLeft");
+    case 0x0086:
+        return ASCIILiteral("OSRight");
+    case 0x0087:
+        return ASCIILiteral("ContextMenu");
+    case 0x0088:
+        return ASCIILiteral("BrowserStop");
+    case 0x0089:
+        return ASCIILiteral("Again");
+    case 0x008A:
+        return ASCIILiteral("Props");
+    case 0x008B:
+        return ASCIILiteral("Undo");
+    case 0x008C:
+        return ASCIILiteral("Select");
+    case 0x008D:
+        return ASCIILiteral("Copy");
+    case 0x008E:
+        return ASCIILiteral("Open");
+    case 0x008F:
+        return ASCIILiteral("Paste");
+    case 0x0090:
+        return ASCIILiteral("Find");
+    case 0x0091:
+        return ASCIILiteral("Cut");
+    case 0x0092:
+        return ASCIILiteral("Help");
+    case 0x0094:
+        return ASCIILiteral("LaunchApp2");
+    case 0x0097:
+        return ASCIILiteral("WakeUp");
+    case 0x0098:
+        return ASCIILiteral("LaunchApp1");
+    case 0x00A3:
+        return ASCIILiteral("LaunchMail");
+    case 0x00A4:
+        return ASCIILiteral("BrowserFavorites");
+    case 0x00A6:
+        return ASCIILiteral("BrowserBack");
+    case 0x00A7:
+        return ASCIILiteral("BrowserForward");
+    case 0x00A9:
+        return ASCIILiteral("Eject");
+    case 0x00AB:
+        return ASCIILiteral("MediaTrackNext");
+    case 0x00AC:
+        return ASCIILiteral("MediaPlayPause");
+    case 0x00AD:
+        return ASCIILiteral("MediaTrackPrevious");
+    case 0x00AE:
+        return ASCIILiteral("MediaStop");
+    case 0x00B3:
+        return ASCIILiteral("LaunchMediaPlayer");
+    case 0x00B4:
+        return ASCIILiteral("BrowserHome");
+    case 0x00B5:
+        return ASCIILiteral("BrowserRefresh");
+    case 0x00BF:
+        return ASCIILiteral("F13");
+    case 0x00C0:
+        return ASCIILiteral("F14");
+    case 0x00C1:
+        return ASCIILiteral("F15");
+    case 0x00C2:
+        return ASCIILiteral("F16");
+    case 0x00C3:
+        return ASCIILiteral("F17");
+    case 0x00C4:
+        return ASCIILiteral("F18");
+    case 0x00C5:
+        return ASCIILiteral("F19");
+    case 0x00C6:
+        return ASCIILiteral("F20");
+    case 0x00C7:
+        return ASCIILiteral("F21");
+    case 0x00C8:
+        return ASCIILiteral("F22");
+    case 0x00C9:
+        return ASCIILiteral("F23");
+    case 0x00CA:
+        return ASCIILiteral("F24");
+    case 0x00E1:
+        return ASCIILiteral("BrowserSearch");
+    default:
+        return ASCIILiteral("Unidentified");
+    }
+}
+
+// FIXME: This is incomplete. We should change this to mirror
+// more like what Firefox does, and generate these switch statements
+// at build time.
 String PlatformKeyboardEvent::keyIdentifierForGdkKeyCode(unsigned keyCode)
 {
     switch (keyCode) {
@@ -574,6 +1260,8 @@ PlatformKeyboardEvent::PlatformKeyboardEvent(GdkEventKey* event, const Compositi
     : PlatformEvent(eventTypeForGdkKeyEvent(event), modifiersForGdkKeyEvent(event), currentTime())
     , m_text(compositionResults.simpleString.length() ? compositionResults.simpleString : singleCharacterString(event->keyval))
     , m_unmodifiedText(m_text)
+    , m_key(keyValueForGdkKeyCode(event->keyval))
+    , m_code(keyCodeForHardwareKeyCode(event->hardware_keycode))
     , m_keyIdentifier(keyIdentifierForGdkKeyCode(event->keyval))
     , m_windowsVirtualKeyCode(windowsKeyCodeForGdkKeyCode(event->keyval))
     , m_autoRepeat(false)
index 7d830a6..a81cc10 100644 (file)
@@ -1,3 +1,16 @@
+2017-01-06  Gustavo Noronha Silva  <gustavo.noronha@collabora.co.uk>
+
+        [GTK] Should support key and code properties on keyboard events
+        https://bugs.webkit.org/show_bug.cgi?id=166759
+
+        Reviewed by Carlos Garcia Campos.
+
+        * Shared/WebEvent.h:
+        * Shared/WebKeyboardEvent.cpp:
+        (WebKit::WebKeyboardEvent::WebKeyboardEvent): accept web key value and code on construction.
+        * Shared/gtk/WebEventFactory.cpp:
+        (WebKit::WebEventFactory::createWebKeyboardEvent): pass web key value and code on construction.
+
 2017-01-08  Antti Koivisto  <antti@apple.com>
 
         Move cache coders to WTF
index 762a671..85dec2f 100644 (file)
@@ -246,7 +246,7 @@ public:
 #if USE(APPKIT)
     WebKeyboardEvent(Type, const String& text, const String& unmodifiedText, const String& key, const String& code, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, int macCharCode, bool handledByInputMethod, const Vector<WebCore::KeypressCommand>&, bool isAutoRepeat, bool isKeypad, bool isSystemKey, Modifiers, double timestamp);
 #elif PLATFORM(GTK)
-    WebKeyboardEvent(Type, const String& text, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, bool handledByInputMethod, Vector<String>&& commands, bool isKeypad, Modifiers, double timestamp);
+    WebKeyboardEvent(Type, const String& text, const String& key, const String& code, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, bool handledByInputMethod, Vector<String>&& commands, bool isKeypad, Modifiers, double timestamp);
 #else
     WebKeyboardEvent(Type, const String& text, const String& unmodifiedText, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, int macCharCode, bool isAutoRepeat, bool isKeypad, bool isSystemKey, Modifiers, double timestamp);
 #endif
index 817d2f0..a6cbcab 100644 (file)
@@ -58,10 +58,12 @@ WebKeyboardEvent::WebKeyboardEvent(Type type, const String& text, const String&
 
 #elif PLATFORM(GTK)
 
-WebKeyboardEvent::WebKeyboardEvent(Type type, const String& text, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, bool handledByInputMethod, Vector<String>&& commands, bool isKeypad, Modifiers modifiers, double timestamp)
+WebKeyboardEvent::WebKeyboardEvent(Type type, const String& text, const String& key, const String& code, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, bool handledByInputMethod, Vector<String>&& commands, bool isKeypad, Modifiers modifiers, double timestamp)
     : WebEvent(type, modifiers, timestamp)
     , m_text(text)
     , m_unmodifiedText(text)
+    , m_key(key)
+    , m_code(code)
     , m_keyIdentifier(keyIdentifier)
     , m_windowsVirtualKeyCode(windowsVirtualKeyCode)
     , m_nativeVirtualKeyCode(nativeVirtualKeyCode)
index 2d66393..8ef0fdb 100644 (file)
@@ -193,6 +193,8 @@ WebKeyboardEvent WebEventFactory::createWebKeyboardEvent(const GdkEvent* event,
     return WebKeyboardEvent(
         event->type == GDK_KEY_RELEASE ? WebEvent::KeyUp : WebEvent::KeyDown,
         compositionResults.simpleString.length() ? compositionResults.simpleString : PlatformKeyboardEvent::singleCharacterString(event->key.keyval),
+        PlatformKeyboardEvent::keyValueForGdkKeyCode(event->key.keyval),
+        PlatformKeyboardEvent::keyCodeForHardwareKeyCode(event->key.hardware_keycode),
         PlatformKeyboardEvent::keyIdentifierForGdkKeyCode(event->key.keyval),
         PlatformKeyboardEvent::windowsKeyCodeForGdkKeyCode(event->key.keyval),
         static_cast<int>(event->key.keyval),
index 48d22b9..0a99f58 100644 (file)
@@ -1,3 +1,14 @@
+2017-01-06  Gustavo Noronha Silva  <gustavo.noronha@collabora.co.uk>
+
+        [GTK] Should support key and code properties on keyboard events
+        https://bugs.webkit.org/show_bug.cgi?id=166759
+
+        Reviewed by Carlos Garcia Campos.
+
+        * WebKitTestRunner/gtk/EventSenderProxyGtk.cpp:
+        (WTR::getGDKKeySymForKeyRef): add missing modifier keys which were being reported as 'l' and 'r' only
+        on tests.
+
 2017-01-06  Per Arne Vollan  <pvollan@apple.com>
 
         [Win] Some tests are flaky because certain DLLs are writing to stdout.
index 023edc8..5ab21cf 100644 (file)
@@ -226,6 +226,18 @@ int getGDKKeySymForKeyRef(WKStringRef keyRef, unsigned location, guint* modifier
         return GDK_KEY_VoidSymbol;
     }
 
+    if (WKStringIsEqualToUTF8CString(keyRef, "leftControl"))
+        return GDK_KEY_Control_L;
+    if (WKStringIsEqualToUTF8CString(keyRef, "rightControl"))
+        return GDK_KEY_Control_R;
+    if (WKStringIsEqualToUTF8CString(keyRef, "leftShift"))
+        return GDK_KEY_Shift_L;
+    if (WKStringIsEqualToUTF8CString(keyRef, "rightShift"))
+        return GDK_KEY_Shift_R;
+    if (WKStringIsEqualToUTF8CString(keyRef, "leftAlt"))
+        return GDK_KEY_Alt_L;
+    if (WKStringIsEqualToUTF8CString(keyRef, "rightAlt"))
+        return GDK_KEY_Alt_R;
     if (WKStringIsEqualToUTF8CString(keyRef, "leftArrow"))
         return GDK_KEY_Left;
     if (WKStringIsEqualToUTF8CString(keyRef, "rightArrow"))