Remove forwarding shift key events and fix keycode conversion.
authorKarol Furmaniak <k.furmaniak@samsung.com>
Fri, 30 Jan 2015 13:48:28 +0000 (14:48 +0100)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
[Requirement] WCS TC 90

There was unnecessary shift key event forwarding what causes
wrong events dispatching.

Now after press "A" letter, events are:

keydown
keydown
keypress
composition-end
input
keyup
keyup

but it should be:

keydown
keypress
composition-end
input
keyup

This patch fix this.

Added conversion of keycode.

Bug: http://web.sec.samsung.net/bugzilla/show_bug.cgi?id=10687
Reviewed by: Antonio Gomes, Piotr Grad

Change-Id: I892c065edc7490ee66425787d59a6596a4adc0d4
Signed-off-by: Karol Furmaniak <k.furmaniak@samsung.com>
tizen_src/impl/browser/renderer_host/render_widget_host_view_efl.cc
tizen_src/impl/browser/renderer_host/render_widget_host_view_efl.h
tizen_src/impl/browser/renderer_host/web_event_factory_efl.cc

index 47b4e3a..5a589ca 100644 (file)
@@ -116,7 +116,6 @@ RenderWidgetHostViewEfl::RenderWidgetHostViewEfl(RenderWidgetHost* widget, EWebV
     next_pixmap_id_(0),
     surface_id_(0),
     is_hw_accelerated_(true),
-    is_modifier_key_(false),
     should_restore_selection_menu_(false),
     selection_acked_on_tap_(false),
     was_scrolled_(false),
@@ -1202,6 +1201,12 @@ void RenderWidgetHostViewEfl::HandleEvasEvent(const Evas_Event_Key_Down* event)
     im_context_->HandleKeyDownEvent(event, &wasFiltered);
     NativeWebKeyboardEvent n_event = WebEventFactoryEfl::toWebKeyboardEvent(evas_, event);
 
+    // When upper case letter is entered there are two events
+    // Shift + letter key
+    // Do not forward shift key to prevent shift keydown event.
+    if (!strcmp(event->key, "Shift_L"))
+      return;
+
     if (wasFiltered)
       n_event.isSystemKey = true;
 
@@ -1266,21 +1271,6 @@ void RenderWidgetHostViewEfl::OnDidHandleKeyEvent(const blink::WebInputEvent* in
     return;
 
   if (input_event->type == blink::WebInputEvent::KeyDown) {
-    // Handling KeyDown event of modifier key(Shift for example)
-    if (input_event->modifiers && !is_modifier_key_) {
-      is_modifier_key_ = true;
-      return;
-    }
-
-    // Handling KeyDown event of key+modifier (Shift+a=A for example)
-    if (is_modifier_key_) {
-      HandleCommitQueue(processed);
-      HandlePreeditQueue(processed);
-      HandleKeyUpQueue();
-      HandleKeyDownQueue();
-      is_modifier_key_ = false;
-    }
-
     HandleCommitQueue(processed);
     HandlePreeditQueue(processed);
     HandleKeyUpQueue();
index d18f448..b5235c0 100644 (file)
@@ -341,7 +341,6 @@ class RenderWidgetHostViewEfl
   GLuint texture_id_;
   int surface_id_;
   bool is_hw_accelerated_;
-  bool is_modifier_key_;
   GLuint vertex_buffer_obj_;
   GLuint vertex_buffer_obj_270_;
   GLuint vertex_buffer_obj_90_;
index ab53625..76d23ab 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "base/time/time.h"
 #include "base/strings/utf_string_conversions.h"
+#include "platform/WindowsKeyboardCodes.h"
 #include "third_party/WebKit/public/web/WebInputEvent.h"
 #include "ui/events/keycodes/keyboard_codes.h"
 #include "ui/events/keycodes/keyboard_code_conversion_x.h"
@@ -35,10 +36,142 @@ static void TranslateEvasCoordToWebKitCoord(Evas_Object *web_view, int& x, int&
 
 namespace content {
 
+typedef base::hash_map<std::string, int> WindowsKeyMap;
 static const float cDefaultScrollStep = 20;
 
-static ui::KeyboardCode KeyboardCodeFromEflKey(const char* key) {
-  return ui::KeyboardCodeFromXKeysym(XStringToKeysym(key));
+static WindowsKeyMap& WinKeyMap() {
+  CR_DEFINE_STATIC_LOCAL(WindowsKeyMap, windowsKeyMap, ());
+  return windowsKeyMap;
+}
+
+static inline void AddCharactersToWinKeyMap(const char from, const char to, const int baseCode) {
+  int i = 0;
+  for (char c = from; c <= to; c++, i++) {
+    WinKeyMap()[std::string(&c, 1)] = baseCode + i;
+  }
+}
+
+static void PopulateWindowsKeyMap() {
+  WinKeyMap()["Return"] = VK_RETURN;
+  WinKeyMap()["KP_Return"] = VK_RETURN;
+  WinKeyMap()["Alt_L"] = VK_LMENU;
+  WinKeyMap()["Alt_R"] = VK_RMENU;
+  WinKeyMap()["ISO_Level3_Shift"] = VK_MENU;
+  WinKeyMap()["Menu"] = VK_MENU;
+  WinKeyMap()["Shift_L"] = VK_LSHIFT;
+  WinKeyMap()["Shift_R"] = VK_RSHIFT;
+  WinKeyMap()["Control_L"] = VK_LCONTROL;
+  WinKeyMap()["Control_R"] = VK_RCONTROL;
+  WinKeyMap()["Pause"] = VK_PAUSE;
+  WinKeyMap()["Break"] = VK_PAUSE;
+  WinKeyMap()["Caps_Lock"] = VK_CAPITAL;
+  WinKeyMap()["Scroll_Lock"] = VK_SCROLL;
+  WinKeyMap()["Num_Lock"] = VK_NUMLOCK;
+  WinKeyMap()["Escape"] = VK_ESCAPE;
+  WinKeyMap()["Tab"] = VK_TAB;
+  WinKeyMap()["ISO_Left_Tab"] = VK_TAB;
+  WinKeyMap()["BackSpace"] = VK_BACK;
+  WinKeyMap()["space"] = VK_SPACE;
+  WinKeyMap()["Next"] = VK_NEXT;
+  WinKeyMap()["Prior"] = VK_PRIOR;
+  WinKeyMap()["Home"] = VK_HOME;
+  WinKeyMap()["End"] = VK_END;
+  WinKeyMap()["Right"] = VK_RIGHT;
+  WinKeyMap()["Left"] = VK_LEFT;
+  WinKeyMap()["Up"] = VK_UP;
+  WinKeyMap()["Down"] = VK_DOWN;
+  WinKeyMap()["Print"] = VK_SNAPSHOT;
+  WinKeyMap()["Insert"] = VK_INSERT;
+  WinKeyMap()["Delete"] = VK_DELETE;
+
+  WinKeyMap()["comma"] = VK_OEM_COMMA;
+  WinKeyMap()["less"] = VK_OEM_COMMA;
+  WinKeyMap()["period"] = VK_OEM_PERIOD;
+  WinKeyMap()["greater"] = VK_OEM_PERIOD;
+  WinKeyMap()["semicolon"] = VK_OEM_1;
+  WinKeyMap()["colon"] = VK_OEM_1;
+  WinKeyMap()["slash"] = VK_OEM_2;
+  WinKeyMap()["question"] = VK_OEM_2;
+  WinKeyMap()["grave"] = VK_OEM_3;
+  WinKeyMap()["asciitilde"] = VK_OEM_3;
+  WinKeyMap()["bracketleft"] = VK_OEM_4;
+  WinKeyMap()["braceleft"] = VK_OEM_4;
+  WinKeyMap()["backslash"] = VK_OEM_5;
+  WinKeyMap()["bar"] = VK_OEM_5;
+  WinKeyMap()["bracketright"] = VK_OEM_6;
+  WinKeyMap()["braceright"] = VK_OEM_6;
+  WinKeyMap()["apostrophe"] = VK_OEM_7;
+  WinKeyMap()["quotedbl"] = VK_OEM_7;
+  // Keypad location
+  WinKeyMap()["KP_Left"] = VK_LEFT;
+  WinKeyMap()["KP_Right"] = VK_RIGHT;
+  WinKeyMap()["KP_Up"] = VK_UP;
+  WinKeyMap()["KP_Down"] = VK_DOWN;
+  WinKeyMap()["KP_Prior"] = VK_PRIOR;
+  WinKeyMap()["KP_Next"] = VK_NEXT;
+  WinKeyMap()["KP_Home"] = VK_HOME;
+  WinKeyMap()["KP_End"] = VK_END;
+  WinKeyMap()["KP_Insert"] = VK_INSERT;
+  WinKeyMap()["KP_Delete"] = VK_DELETE;
+
+  // Set alphabet to the windowsKeyMap.
+  AddCharactersToWinKeyMap('a', 'z', VK_A);
+  AddCharactersToWinKeyMap('A', 'Z', VK_A);
+
+  // Set digits to the windowsKeyMap.
+  AddCharactersToWinKeyMap('0', '9', VK_0);
+
+  // Set shifted digits to the windowsKeyMap.
+  WinKeyMap()["exclam"] = VK_1;
+  WinKeyMap()["at"] = VK_2;
+  WinKeyMap()["numbersign"] = VK_3;
+  WinKeyMap()["dollar"] = VK_4;
+  WinKeyMap()["percent"] = VK_5;
+  WinKeyMap()["asciicircum"] = VK_6;
+  WinKeyMap()["ampersand"] = VK_7;
+  WinKeyMap()["asterisk"] = VK_8;
+  WinKeyMap()["parenleft"] = VK_9;
+  WinKeyMap()["parenright"] = VK_0;
+  WinKeyMap()["minus"] = VK_OEM_MINUS;
+  WinKeyMap()["underscore"] = VK_OEM_MINUS;
+  WinKeyMap()["equal"] = VK_OEM_PLUS;
+  WinKeyMap()["plus"] = VK_OEM_PLUS;
+
+  // Set F_XX keys to the windowsKeyMap.
+  for (unsigned i = 1; i < 25; i++) {
+    std::string key = "F" + std::to_string(i);
+    WinKeyMap()[key] = VK_F1 + i - 1;
+  }
+
+  WinKeyMap()["KP_Enter"] = VK_RETURN;
+  WinKeyMap()["Hangul"] = VK_HANGUL;
+  WinKeyMap()["Hangul_Hanja"] = VK_HANJA;
+  WinKeyMap()["KP_Multiply"] = VK_MULTIPLY;
+  WinKeyMap()["KP_Add"] = VK_ADD;
+  WinKeyMap()["KP_Subtract"] = VK_SUBTRACT;
+  WinKeyMap()["KP_Decimal"] = VK_DECIMAL;
+  WinKeyMap()["KP_Divide"] = VK_DIVIDE;
+  WinKeyMap()["dead_grave"] = VK_OEM_3;
+  WinKeyMap()["ISO_Level3_Shift"] = 0xE1;
+
+  for (unsigned i = 0; i < 10; i++) {
+    std::string key = "KP_" + std::to_string(i);
+    WinKeyMap()[key] = VK_NUMPAD0 + i;
+  }
+}
+
+static int KeyboardCodeFromEflKey(const char* key) {
+
+  if (WinKeyMap().empty())
+    PopulateWindowsKeyMap();
+
+  std::string keyName(key);
+  WindowsKeyMap::iterator it = WinKeyMap().find(keyName);
+
+  if (it != WinKeyMap().end())
+    return it->second;
+
+  return 0;
 }
 
 static int WindowsKeyCodeFromEflKey(const char* key) {