From eb484d5051c48e3bd35a2f06915eb75cf5c8c1fc Mon Sep 17 00:00:00 2001
From: rider <rider@lindenlab.com>
Date: Thu, 3 Dec 2015 13:32:06 -0800
Subject: [PATCH] MAINT-5909: Enable unicode text input on mac and feed that
 directly into the viewer.  Windows fixes still required.

---
 indra/llwindow/llwindowmacosx.cpp            | 18 +++++++++++++++++-
 indra/media_plugins/cef/media_plugin_cef.cpp | 15 +++++++++++++--
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp
index 952c6751dbd..0d41884462a 100755
--- a/indra/llwindow/llwindowmacosx.cpp
+++ b/indra/llwindow/llwindowmacosx.cpp
@@ -221,7 +221,23 @@ void callResetKeys()
 
 bool callUnicodeCallback(wchar_t character, unsigned int mask)
 {
-	return gWindowImplementation->getCallbacks()->handleUnicodeChar(character, mask);
+    NativeKeyEventData eventData;
+    
+    memset(&eventData, 0, sizeof(NativeKeyEventData));
+    
+    eventData.mKeyEvent = NativeKeyEventData::KEYCHAR;
+    eventData.mEventType = 0;
+    eventData.mEventModifiers = mask;
+    eventData.mEventKeyCode = 0;
+    eventData.mEventChars = character;
+    eventData.mEventUnmodChars = character;
+    eventData.mEventRepeat = false;
+    
+    mRawKeyEvent = &eventData;
+    
+    bool result = gWindowImplementation->getCallbacks()->handleUnicodeChar(character, mask);
+    mRawKeyEvent = NULL;
+    return result;
 }
 
 void callFocus()
diff --git a/indra/media_plugins/cef/media_plugin_cef.cpp b/indra/media_plugins/cef/media_plugin_cef.cpp
index 77e6d35b117..919d83bc090 100644
--- a/indra/media_plugins/cef/media_plugin_cef.cpp
+++ b/indra/media_plugins/cef/media_plugin_cef.cpp
@@ -763,16 +763,17 @@ void MediaPluginCEF::keyEvent(LLCEFLib::EKeyEvent key_event, int key, LLCEFLib::
         return;
     
     uint32_t eventType = native_key_data["event_type"].asInteger();
+    if (!eventType)
+        return;
     uint32_t eventModifiers = native_key_data["event_modifiers"].asInteger();
     uint32_t eventKeycode = native_key_data["event_keycode"].asInteger();
     char eventChars = static_cast<char>(native_key_data["event_chars"].isUndefined() ? 0 : native_key_data["event_chars"].asInteger());
     char eventUChars = static_cast<char>(native_key_data["event_umodchars"].isUndefined() ? 0 : native_key_data["event_umodchars"].asInteger());
     bool eventIsRepeat = native_key_data["event_isrepeat"].asBoolean();
-
     
     mLLCEFLib->keyboardEventOSX(eventType, eventModifiers, (eventChars) ? &eventChars : NULL,
                                 (eventUChars) ? &eventUChars : NULL, eventIsRepeat, eventKeycode);
-        
+    
 #elif LL_WINDOWS
 	U32 msg = ll_U32_from_sd(native_key_data["msg"]);
 	U32 wparam = ll_U32_from_sd(native_key_data["w_param"]);
@@ -787,6 +788,16 @@ void MediaPluginCEF::unicodeInput(const std::string &utf8str, LLCEFLib::EKeyboar
 #if LL_DARWIN
 	//mLLCEFLib->keyPress(utf8str[0], true);
 	//mLLCEFLib->keyboardEvent(LLCEFLib::KE_KEY_DOWN, (uint32_t)(utf8str[0]), 0, LLCEFLib::KM_MODIFIER_NONE, 0, 0, 0);
+    if (!native_key_data.has("event_chars") || !native_key_data.has("event_umodchars") ||
+            !native_key_data.has("event_keycode") || !native_key_data.has("event_modifiers"))
+        return;
+    uint32_t unicodeChar = native_key_data["event_chars"].asInteger();
+    uint32_t unmodifiedChar = native_key_data["event_umodchars"].asInteger();
+    uint32_t keyCode = native_key_data["event_keycode"].asInteger();
+    uint32_t rawmodifiers = native_key_data["event_modifiers"].asInteger();
+    
+    mLLCEFLib->injectUnicodeText(unicodeChar, unmodifiedChar, keyCode, rawmodifiers);
+    
 #elif LL_WINDOWS
 	U32 msg = ll_U32_from_sd(native_key_data["msg"]);
 	U32 wparam = ll_U32_from_sd(native_key_data["w_param"]);
-- 
GitLab