Browse Source

WebView Mac improvements

Josh Engebretson 10 years ago
parent
commit
f076c6a67f

+ 0 - 5
Source/Atomic/Graphics/OpenGL/OGLGraphics.cpp

@@ -2615,11 +2615,6 @@ unsigned Graphics::GetRGBAFormat()
     return GL_RGBA;
 }
 
-unsigned Graphics::GetBGRAFormat()
-{
-    return GL_BGRA;
-}
-
 unsigned Graphics::GetRGBA16Format()
 {
 #ifndef GL_ES_VERSION_2_0

+ 0 - 2
Source/Atomic/Graphics/OpenGL/OGLGraphics.h

@@ -490,8 +490,6 @@ public:
     static unsigned GetRGBFormat();
     /// Return the API-specific RGBA texture format.
     static unsigned GetRGBAFormat();
-    /// Return the API-specific BGRA texture format.
-    static unsigned GetBGRAFormat();
     /// Return the API-specific RGBA 16-bit texture format.
     static unsigned GetRGBA16Format();
     /// Return the API-specific RGBA 16-bit float texture format.

+ 0 - 3
Source/Atomic/Graphics/OpenGL/OGLTexture.cpp

@@ -319,7 +319,6 @@ unsigned Texture::GetRowDataSize(int width) const
         return (unsigned)(width * 3);
 
     case GL_RGBA:
-    case GL_BGRA:
 #ifndef GL_ES_VERSION_2_0
     case GL_DEPTH24_STENCIL8_EXT:
     case GL_RG16:
@@ -410,8 +409,6 @@ unsigned Texture::GetDataType(unsigned format)
     else if (format == GL_RGBA16F_ARB || format == GL_RGBA32F_ARB || format == GL_RG16F || format == GL_RG32F ||
              format == GL_R16F || format == GL_R32F)
         return GL_FLOAT;
-    else if (format == GL_BGRA)
-        return GL_UNSIGNED_INT_8_8_8_8_REV;
     else
         return GL_UNSIGNED_BYTE;
 #else

+ 0 - 4
Source/Atomic/Graphics/OpenGL/OGLTexture2D.cpp

@@ -244,8 +244,6 @@ bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, con
 
     if (!IsCompressed())
     {
-        if (format == GL_BGRA)
-            format = GL_RGBA;
         if (wholeLevel)
             glTexImage2D(target_, level, format, width, height, 0, GetExternalFormat(format_), GetDataType(format_), data);
         else
@@ -484,8 +482,6 @@ bool Texture2D::Create()
     if (!IsCompressed())
     {
         glGetError();
-        if (format == GL_BGRA)
-            format = GL_RGBA;
         glTexImage2D(target_, 0, format, width_, height_, 0, externalFormat, dataType, 0);
         if (glGetError())
         {

+ 4 - 1
Source/AtomicWebView/WebClient.cpp

@@ -274,7 +274,10 @@ void WebClient::SendKeyEvent(const StringHash eventType, VariantMap& eventData)
     // return does not work at all on cef client with offscreen
     // bad interaction with arrow keys (for example here, after
     // hitting arrow keys, return/text takes a couple presses to register
-    keyEvent.type = keyUp ? KEYEVENT_KEYUP : KEYEVENT_KEYDOWN;
+    if (eventType == "KeyDown")
+        keyEvent.type = KEYEVENT_KEYDOWN;
+    else
+        keyEvent.type = KEYEVENT_KEYUP;
     keyEvent.modifiers = 0;
     keyEvent.native_key_code = 0;
     host->SendKeyEvent(keyEvent);

+ 117 - 0
Source/AtomicWebView/WebKeyboardMac.cpp

@@ -0,0 +1,117 @@
+
+#ifdef ATOMIC_PLATFORM_OSX
+
+#include <include/cef_client.h>
+
+#include <ThirdParty/SDL/include/SDL.h>
+#include <ThirdParty/SDL/include/SDL_syswm.h>
+#include <ThirdParty/SDL/src/events/scancodes_darwin.h>
+
+#include <Atomic/Core/Variant.h>
+#include <Atomic/Input/InputEvents.h>
+#include <Atomic/Input/Input.h>
+#include <Atomic/IO/Log.h>
+
+#include "WebKeyboard.h"
+
+namespace Atomic
+{
+
+static bool SDLScanCodeToDarwinScanCode(SDL_Scancode code, int& darwinScanCode)
+{
+
+    darwinScanCode = -1;
+
+    if (code >= SDL_SCANCODE_A && code <= SDL_SCANCODE_0)
+        return false;
+
+    int numCodes = sizeof(darwin_scancode_table)/sizeof(SDL_Scancode);
+
+    for (int i  = 0; i < numCodes; i++)
+    {
+        if (darwin_scancode_table[i] == code)
+        {
+            darwinScanCode = i;
+            break;
+        }
+    }
+
+    if (darwinScanCode != -1)
+        return true;
+
+    return false;
+
+}
+
+bool ConvertKeyEvent(const StringHash eventType, VariantMap& eventData, CefKeyEvent& keyEvent)
+{
+    if (eventType != "KeyDown" && eventType != "KeyUp")
+    {
+        LOGERROR("ConvertKeyEvent - Unknown event type");
+        return false;
+    }
+
+    if (eventType == "KeyUp")
+        return false;
+
+    WebKeyEvent wk(eventType, eventData);
+
+    if (wk.scanCode == SDL_SCANCODE_RETURN)
+    {
+        if (!wk.keyDown)
+            return false;
+
+        keyEvent.native_key_code = 36;
+        keyEvent.type = KEYEVENT_CHAR;
+        return true;
+    }
+
+    keyEvent.modifiers = EVENTFLAG_NONE;
+
+    if (wk.qual & QUAL_SHIFT)
+        keyEvent.modifiers |= EVENTFLAG_SHIFT_DOWN;
+    if (wk.qual & QUAL_ALT)
+        keyEvent.modifiers |= EVENTFLAG_ALT_DOWN;
+    if (wk.qual & QUAL_CTRL)
+        keyEvent.modifiers |= EVENTFLAG_CONTROL_DOWN;
+
+
+    int darwinScanCode;
+    if (SDLScanCodeToDarwinScanCode((SDL_Scancode) wk.scanCode, darwinScanCode))
+    {
+        keyEvent.native_key_code = darwinScanCode;
+        keyEvent.type = wk.keyDown ? KEYEVENT_KEYDOWN : KEYEVENT_KEYUP;
+    }
+
+    return true;
+}
+
+bool ConvertTextInputEvent(StringHash eventType, VariantMap& eventData, CefKeyEvent& keyEvent)
+{
+    if (eventType != "TextInput")
+    {
+        LOGERROR("ConvertTextInputEvent - Unknown event type");
+        return false;
+    }
+
+    String text = eventData[TextInput::P_TEXT].GetString();
+
+    SDL_Keycode keyCode = SDL_GetKeyFromName(text.CString());
+
+    if (SDL_strlen(text.CString()) == 1)
+    {
+        if (text[0] >= 'A' && text[0] <= 'Z')
+        {
+            keyCode -= 32;
+        }
+    }
+
+    keyEvent.character = (char16) keyCode;
+    keyEvent.type = KEYEVENT_CHAR;
+
+    return true;
+}
+
+}
+
+#endif

+ 0 - 43
Source/AtomicWebView/WebKeyboardSDL.cpp

@@ -1,43 +0,0 @@
-#include <SDL/include/SDL_keycode.h>
-
-#include "WebKeyboardSDL.h"
-
-namespace Atomic
-{
-
-int GetNativeKeyFromSDLScanCode(int scancode)
-{
-#ifdef ATOMIC_PLATFORM_OSX
-    // see scancodes_darwin.h in the SDL sources
-    if (scancode == SDL_SCANCODE_RETURN)
-        return 36;
-    if (scancode == SDL_SCANCODE_LEFT)
-        return 123;
-    if (scancode == SDL_SCANCODE_RIGHT)
-        return 124;
-    if (scancode == SDL_SCANCODE_DOWN)
-        return 125;
-    if (scancode == SDL_SCANCODE_UP)
-        return 126;
-    if (scancode == SDL_SCANCODE_DELETE)
-        return 117;
-    if (scancode == SDL_SCANCODE_BACKSPACE)
-        return 51;
-    if (scancode == SDL_SCANCODE_RGUI)
-        return 54;
-    if (scancode == SDL_SCANCODE_LGUI)
-        return 55;
-    if (scancode == SDL_SCANCODE_Z)
-        return 6;
-
-    return -1;
-
-#else
-
-    return -1;
-
-#endif
-
-}
-
-}

+ 0 - 10
Source/AtomicWebView/WebKeyboardSDL.h

@@ -1,10 +0,0 @@
-
-#pragma once
-
-namespace Atomic
-{
-
-/// Get the native key for a given scancode, return -1 if unknown
-int GetNativeKeyFromSDLScanCode(int scancode);
-
-}

+ 2 - 2
Source/AtomicWebView/WebTexture2D.cpp

@@ -92,6 +92,7 @@ public:
     }
 
 #ifdef ATOMIC_PLATFORM_OSX
+
     void OnPaint(CefRefPtr<CefBrowser> browser, PaintElementType type, const RectList &dirtyRects,
                  const void *buffer, int width, int height) OVERRIDE
     {
@@ -106,10 +107,9 @@ public:
             if (dirtyRects.size() == 1 &&
                     dirtyRects[0] == CefRect(0, 0, webTexture2D_->GetWidth(), webTexture2D_->GetHeight()))
             {
-                Texture2D* tex = webTexture2D_->texture_;
                 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
                 glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
-                tex->SetData(0, 0, 0, width, height, buffer);
+                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, buffer);
             }
             else
             {