-#ifdef SUPPORT_GECKO\r
+/* --- 8< --- 8< --- OffscreenGecko headers --- >8 --- >8 --- */\r
\r
-// includes everything!\r
-#include <OffscreenGecko/browser.h>\r
+/* OffscreenGecko/defs.h */\r
\r
-#ifdef _MSC_VER\r
-# pragma comment( lib, "OffscreenGecko" )\r
+#define OSGK_CLASSTYPE_DEF struct\r
+#define OSGK_CLASSTYPE_REF struct\r
+\r
+#include <assert.h>\r
+#define OSGK_ASSERT(x) assert(x)\r
+\r
+typedef unsigned int OSGK_GeckoResult;\r
+\r
+#if defined(__cplusplus) || defined(__GNUC__)\r
+# define OSGK_INLINE inline\r
+#elif defined(_MSC_VER)\r
+# define OSGK_INLINE __inline\r
+#else\r
+# define OSGK_INLINE\r
#endif\r
\r
+/* OffscreenGecko/baseobj.h */\r
+\r
+struct OSGK_BaseObject_s\r
+{\r
+ int reserved;\r
+};\r
+typedef struct OSGK_BaseObject_s OSGK_BaseObject;\r
+\r
+#define OSGK_DERIVEDTYPE(T) \\r
+ typedef struct T ## _s { \\r
+ OSGK_BaseObject baseobj; \\r
+ } T\r
+\r
+static int (*osgk_addref) (OSGK_BaseObject* obj);\r
+static int (*osgk_release) (OSGK_BaseObject* obj);\r
+\r
+static OSGK_INLINE int osgk_addref_real (OSGK_BaseObject* obj)\r
+{\r
+ return osgk_addref (obj);\r
+}\r
+\r
+static OSGK_INLINE int osgk_release_real (OSGK_BaseObject* obj)\r
+{\r
+ return osgk_release (obj);\r
+}\r
+\r
+#define osgk_addref(obj) osgk_addref_real (&((obj)->baseobj))\r
+#define osgk_release(obj) osgk_release_real (&((obj)->baseobj))\r
+\r
+/* OffscreenGecko/embedding.h */\r
+\r
+OSGK_DERIVEDTYPE(OSGK_EmbeddingOptions);\r
+\r
+static OSGK_EmbeddingOptions* (*osgk_embedding_options_create) (void);\r
+static void (*osgk_embedding_options_add_search_path) (\r
+ OSGK_EmbeddingOptions* options, const char* path);\r
+/*static void (*osgk_embedding_options_add_components_path) (\r
+ OSGK_EmbeddingOptions* options, const char* path);*/\r
+static void (*osgk_embedding_options_set_profile_dir) (\r
+ OSGK_EmbeddingOptions* options, const char* profileDir,\r
+ const char* localProfileDir);\r
+\r
+OSGK_DERIVEDTYPE(OSGK_Embedding);\r
+\r
+#define OSGK_API_VERSION 1\r
+\r
+static OSGK_Embedding* (*osgk_embedding_create2) (\r
+ unsigned int apiVer, OSGK_EmbeddingOptions* options, \r
+ OSGK_GeckoResult* geckoResult);\r
+\r
+static OSGK_INLINE OSGK_Embedding* osgk_embedding_create (\r
+ OSGK_GeckoResult* geckoResult)\r
+{\r
+ return osgk_embedding_create2 (OSGK_API_VERSION, 0, geckoResult);\r
+}\r
+\r
+static OSGK_INLINE OSGK_Embedding* osgk_embedding_create_with_options (\r
+ OSGK_EmbeddingOptions* options, OSGK_GeckoResult* geckoResult)\r
+{\r
+ return osgk_embedding_create2 (OSGK_API_VERSION, options, geckoResult);\r
+}\r
+\r
+/*static OSGK_GeckoMem* (*osgk_embedding_get_gecko_mem) (\r
+ OSGK_Embedding* embedding);*/\r
+\r
+/*static OSGK_ComponentMgr* (*osgk_embedding_get_component_mgr) (\r
+ OSGK_Embedding* embedding);*/\r
+\r
+/*OSGK_CLASSTYPE_DEF nsIComponentManager;\r
+OSGK_CLASSTYPE_DEF nsIComponentRegistrar;\r
+OSGK_CLASSTYPE_DEF nsIServiceManager;*/\r
+\r
+/*static OSGK_CLASSTYPE_REF nsIComponentManager* \r
+(*osgk_embedding_get_gecko_component_manager) (OSGK_Embedding* embedding);*/\r
+/*static OSGK_CLASSTYPE_REF nsIComponentRegistrar* \r
+(*osgk_embedding_get_gecko_component_registrar) (OSGK_Embedding* embedding);*/\r
+/*static OSGK_CLASSTYPE_REF nsIServiceManager* \r
+(*osgk_embedding_get_gecko_service_manager) (OSGK_Embedding* embedding);*/\r
+\r
+enum\r
+{\r
+ jsgPrivileged = 1\r
+};\r
+/*static int (*osgk_embedding_register_js_global) (\r
+ OSGK_Embedding* embedding, const char* name, const char* contractID,\r
+ unsigned int flags, OSGK_String** previousContract,\r
+ OSGK_GeckoResult* geckoResult);*/\r
+\r
+/*static void (*osgk_embedding_clear_focus*) (OSGK_Embedding* embedding);*/\r
+/*void (*osgk_embedding_set_auto_focus) (OSGK_Embedding* embedding, int autoFocus);*/\r
+/*static int (*osgk_embedding_get_auto_focus) (OSGK_Embedding* embedding);*/\r
+\r
+/* OffscreenGecko/browser.h */\r
+OSGK_DERIVEDTYPE(OSGK_Browser);\r
+\r
+static OSGK_Browser* (*osgk_browser_create) (\r
+ OSGK_Embedding* embedding, int width, int height);\r
+static void (*osgk_browser_navigate) (OSGK_Browser* browser,\r
+ const char* uri);\r
+\r
+static int (*osgk_browser_query_dirty) (OSGK_Browser* browser);\r
+static const unsigned char* (*osgk_browser_lock_data) (\r
+ OSGK_Browser* browser, int* isDirty);\r
+static void (*osgk_browser_unlock_data) (OSGK_Browser* browser,\r
+ const unsigned char* data);\r
+\r
+typedef enum OSGK_MouseButton\r
+{\r
+ mbLeft, \r
+ mbRight, \r
+ mbMiddle\r
+} OSGK_MouseButton;\r
+\r
+typedef enum OSGK_MouseButtonEventType\r
+{\r
+ meDown,\r
+ meUp,\r
+ meDoubleClick\r
+} OSGK_MouseButtonEventType;\r
+\r
+static void (*osgk_browser_event_mouse_move) (\r
+ OSGK_Browser* browser, int x, int y);\r
+static void (*osgk_browser_event_mouse_button) (\r
+ OSGK_Browser* browser, OSGK_MouseButton button, \r
+ OSGK_MouseButtonEventType eventType);\r
+\r
+typedef enum OSGK_WheelAxis\r
+{\r
+ waVertical,\r
+ waHorizontal\r
+} OSGK_WheelAxis;\r
+\r
+typedef enum OSGK_WheelDirection\r
+{\r
+ wdPositive,\r
+ wdNegative,\r
+ wdPositivePage,\r
+ wdNegativePage\r
+} OSGK_WheelDirection;\r
+\r
+static void (*osgk_browser_event_mouse_wheel) (\r
+ OSGK_Browser* browser, OSGK_WheelAxis axis, \r
+ OSGK_WheelDirection direction);\r
+\r
+typedef enum OSGK_KeyboardEventType\r
+{\r
+ keDown,\r
+ keUp,\r
+ kePress\r
+} OSGK_KeyboardEventType;\r
+\r
+enum\r
+{\r
+ OSGKKey_First = 0x110000,\r
+\r
+ OSGKKey_Backspace = OSGKKey_First,\r
+ OSGKKey_Tab,\r
+ OSGKKey_Return,\r
+ OSGKKey_Shift,\r
+ OSGKKey_Control,\r
+ OSGKKey_Alt,\r
+ OSGKKey_CapsLock,\r
+ OSGKKey_Escape,\r
+ OSGKKey_Space,\r
+ OSGKKey_PageUp,\r
+ OSGKKey_PageDown,\r
+ OSGKKey_End,\r
+ OSGKKey_Home,\r
+ OSGKKey_Left,\r
+ OSGKKey_Up,\r
+ OSGKKey_Right,\r
+ OSGKKey_Down,\r
+ OSGKKey_Insert,\r
+ OSGKKey_Delete,\r
+ OSGKKey_F1,\r
+ OSGKKey_F2,\r
+ OSGKKey_F3,\r
+ OSGKKey_F4,\r
+ OSGKKey_F5,\r
+ OSGKKey_F6,\r
+ OSGKKey_F7,\r
+ OSGKKey_F8,\r
+ OSGKKey_F9,\r
+ OSGKKey_F10,\r
+ OSGKKey_F11,\r
+ OSGKKey_F12,\r
+ OSGKKey_NumLock,\r
+ OSGKKey_ScrollLock,\r
+ OSGKKey_Meta\r
+};\r
+\r
+static int (*osgk_browser_event_key) (\r
+ OSGK_Browser* browser, unsigned int key,\r
+ OSGK_KeyboardEventType eventType);\r
+\r
+typedef enum OSGK_AntiAliasType\r
+{\r
+ aaNone,\r
+ aaGray,\r
+ aaSubpixel\r
+} OSGK_AntiAliasType;\r
+\r
+/*static void (*osgk_browser_set_antialias) (\r
+ OSGK_Browser* browser, OSGK_AntiAliasType aaType);*/\r
+/*static OSGK_AntiAliasType (*osgk_browser_get_antialias) (OSGK_Browser* browser);*/\r
+\r
+/*static void (*osgk_browser_focus) (OSGK_Browser* browser);*/\r
+\r
+static void (*osgk_browser_resize) (OSGK_Browser* browser,\r
+ int width, int height);\r
+\r
+/* --- >8 --- >8 --- End OffscreenGecko headers --- 8< --- 8< --- */\r
+\r
#include "quakedef.h"\r
#include "cl_dyntexture.h"\r
#include "cl_gecko.h"\r
\r
static clgecko_t cl_geckoinstances[ MAX_GECKO_INSTANCES ];\r
\r
+static dllhandle_t osgk_dll = NULL;\r
+\r
static clgecko_t * cl_gecko_findunusedinstance( void ) {\r
int i;\r
for( i = 0 ; i < MAX_GECKO_INSTANCES ; i++ ) {\r
\r
\r
clgecko_t * CL_Gecko_CreateBrowser( const char *name ) {\r
+ clgecko_t *instance;\r
+\r
+ if (!osgk_dll) return NULL;\r
+\r
// TODO: verify that we dont use a name twice\r
- clgecko_t *instance = cl_gecko_findunusedinstance();\r
+ instance = cl_gecko_findunusedinstance();\r
// TODO: assert != NULL\r
\r
if( cl_geckoembedding == NULL ) {\r
osgk_release( cl_geckoembedding );\r
cl_geckoembedding = NULL;\r
}\r
+\r
+ if (osgk_dll != NULL)\r
+ {\r
+ Sys_UnloadLibrary (&osgk_dll);\r
+ }\r
}\r
\r
static void cl_gecko_create_f( void ) {\r
CL_Gecko_Event_CursorMove( CL_Gecko_FindBrowser( name ), x, y );\r
}\r
\r
+#undef osgk_addref\r
+#undef osgk_release\r
+\r
+static const dllfunction_t osgkFuncs[] =\r
+{\r
+ {"osgk_addref", (void **) &osgk_addref},\r
+ {"osgk_release", (void **) &osgk_release},\r
+ {"osgk_embedding_create2", (void **) &osgk_embedding_create2},\r
+ {"osgk_embedding_options_create", (void **) &osgk_embedding_options_create},\r
+ {"osgk_embedding_options_add_search_path", (void **) &osgk_embedding_options_add_search_path},\r
+ {"osgk_embedding_options_set_profile_dir", (void **) &osgk_embedding_options_set_profile_dir},\r
+ {"osgk_browser_create", (void **) &osgk_browser_create},\r
+ {"osgk_browser_query_dirty", (void **) &osgk_browser_query_dirty},\r
+ {"osgk_browser_navigate", (void **) &osgk_browser_navigate},\r
+ {"osgk_browser_lock_data", (void **) &osgk_browser_lock_data},\r
+ {"osgk_browser_unlock_data", (void **) &osgk_browser_unlock_data},\r
+ {"osgk_browser_resize", (void **) &osgk_browser_resize},\r
+ {"osgk_browser_event_mouse_move", (void **) &osgk_browser_event_mouse_move},\r
+ {"osgk_browser_event_mouse_button", (void **) &osgk_browser_event_mouse_button},\r
+ {"osgk_browser_event_mouse_wheel", (void **) &osgk_browser_event_mouse_wheel},\r
+ {"osgk_browser_event_key", (void **) &osgk_browser_event_key},\r
+ {NULL, NULL}\r
+};\r
+\r
void CL_Gecko_Init( void )\r
{\r
+ const char* dllnames [] =\r
+ {\r
+ #if defined(WIN64)\r
+ "OffscreenGecko64.dll",\r
+ #elif defined(WIN32)\r
+ "OffscreenGecko.dll",\r
+ #elif defined(MACOSX)\r
+ "OffscreenGecko.dylib",\r
+ #else\r
+ "OffscreenGecko.so",\r
+ #endif\r
+ NULL\r
+ };\r
+ \r
+ if (!osgk_dll)\r
+ {\r
+ if (! Sys_LoadLibrary (dllnames, &osgk_dll, osgkFuncs))\r
+ {\r
+ Con_Printf ("Could not load OffscreenGecko, Gecko support unavailable\n");\r
+ }\r
+ }\r
+\r
Cmd_AddCommand( "gecko_create", cl_gecko_create_f, "Create a gecko browser instance" );\r
Cmd_AddCommand( "gecko_destroy", cl_gecko_destroy_f, "Destroy a gecko browser instance" );\r
Cmd_AddCommand( "gecko_navigate", cl_gecko_navigate_f, "Navigate a gecko browser to a URI" );\r
// TODO: error?\r
return false;\r
}\r
-\r
-#endif\r