Browse Source

Autocomplete enter selection working on OS X (WIP)

Josh Engebretson 10 years ago
parent
commit
ebb90f5f07
2 changed files with 55 additions and 3 deletions
  1. 53 1
      Source/AtomicWebView/WebClient.cpp
  2. 2 2
      Source/AtomicWebView/WebKeyboardMac.cpp

+ 53 - 1
Source/AtomicWebView/WebClient.cpp

@@ -31,7 +31,12 @@ namespace Atomic
 void* GetNSWindowContentView(void* window);
 void* GetNSWindowContentView(void* window);
 #endif
 #endif
 
 
-class WebClientPrivate : public CefClient, public CefLifeSpanHandler, public CefLoadHandler, public CefDisplayHandler, public CefRequestHandler
+class WebClientPrivate : public CefClient,
+        public CefLifeSpanHandler,
+        public CefLoadHandler,
+        public CefDisplayHandler,
+        public CefRequestHandler,
+        public CefKeyboardHandler
 {
 {
     friend class WebClient;
     friend class WebClient;
 
 
@@ -84,6 +89,41 @@ public:
         return this;
         return this;
     }
     }
 
 
+    CefRefPtr<CefKeyboardHandler> GetKeyboardHandler() OVERRIDE
+    {
+        return this;
+    }
+
+
+    // CefKeyboardHandler
+
+    virtual bool OnPreKeyEvent(CefRefPtr<CefBrowser> browser,
+                               const CefKeyEvent& event,
+                               CefEventHandle os_event,
+                               bool* is_keyboard_shortcut) OVERRIDE
+    {
+
+        /*
+#ifdef ATOMIC_PLATFORM_OSX
+
+        if (!event.native_key_code)
+            return false;
+
+        if (event.native_key_code == 36)
+        {
+            if (event.focus_on_editable_field && event.type != KEYEVENT_CHAR)
+                return true;
+
+            if (!event.focus_on_editable_field && event.type == KEYEVENT_CHAR)
+                return true;
+        }
+
+#endif */
+
+        return false;
+    }
+
+
 
 
     // CefRequestHandler methods
     // CefRequestHandler methods
     bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
     bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
@@ -488,6 +528,18 @@ void WebClient::SendKeyEvent(const StringHash eventType, VariantMap& eventData)
     // bad interaction with arrow keys (for example here, after
     // bad interaction with arrow keys (for example here, after
     // hitting arrow keys, return/text takes a couple presses to register
     // hitting arrow keys, return/text takes a couple presses to register
 
 
+    if (keyEvent.native_key_code == 36)
+    {
+        keyEvent.type = KEYEVENT_CHAR;
+        host->SendKeyEvent(keyEvent);
+    }
+
+    //if (keyEvent.native_key_code == 125)
+    //{
+    //    keyEvent.type = KEYEVENT_KEYUP;
+    //    host->SendKeyEvent(keyEvent);
+    //}
+
     memset((void*)&keyEvent, 0, sizeof(keyEvent));
     memset((void*)&keyEvent, 0, sizeof(keyEvent));
 
 
     if (eventType == "KeyDown")
     if (eventType == "KeyDown")

+ 2 - 2
Source/AtomicWebView/WebKeyboardMac.cpp

@@ -62,7 +62,7 @@ bool ConvertKeyEvent(Input* input, const StringHash eventType, VariantMap& event
             return false;
             return false;
 
 
         keyEvent.native_key_code = 36;
         keyEvent.native_key_code = 36;
-        keyEvent.type = KEYEVENT_CHAR;
+        keyEvent.type = KEYEVENT_RAWKEYDOWN;
         return true;
         return true;
     }
     }
 
 
@@ -85,7 +85,7 @@ bool ConvertKeyEvent(Input* input, const StringHash eventType, VariantMap& event
     if (SDLScanCodeToDarwinScanCode((SDL_Scancode) wk.scanCode, darwinScanCode))
     if (SDLScanCodeToDarwinScanCode((SDL_Scancode) wk.scanCode, darwinScanCode))
     {
     {
         keyEvent.native_key_code = darwinScanCode;
         keyEvent.native_key_code = darwinScanCode;
-        keyEvent.type = wk.keyDown ? KEYEVENT_KEYDOWN : KEYEVENT_KEYUP;
+        keyEvent.type = wk.keyDown ? KEYEVENT_RAWKEYDOWN : KEYEVENT_KEYUP;
         return true;
         return true;
     }
     }