1 /* --- 8< --- 8< --- OffscreenGecko headers --- >8 --- >8 --- */
2 /* NOTE: Documentation comments have been omitted. Documentation is
3 available in the OffscreenGecko SDK download. */
5 /* OffscreenGecko/defs.h */
7 #define OSGK_CLASSTYPE_DEF struct
8 #define OSGK_CLASSTYPE_REF struct
11 #define OSGK_ASSERT(x) assert(x)
13 typedef unsigned int OSGK_GeckoResult;
15 #if defined(__cplusplus) || defined(__GNUC__)
16 # define OSGK_INLINE inline
17 #elif defined(_MSC_VER)
18 # define OSGK_INLINE __inline
23 /* OffscreenGecko/baseobj.h */
25 struct OSGK_BaseObject_s
29 typedef struct OSGK_BaseObject_s OSGK_BaseObject;
31 #define OSGK_DERIVEDTYPE(T) \
32 typedef struct T ## _s { \
33 OSGK_BaseObject baseobj; \
36 static int (*osgk_addref) (OSGK_BaseObject* obj);
37 static int (*osgk_release) (OSGK_BaseObject* obj);
39 static OSGK_INLINE int osgk_addref_real (OSGK_BaseObject* obj)
41 return osgk_addref (obj);
44 static OSGK_INLINE int osgk_release_real (OSGK_BaseObject* obj)
46 return osgk_release (obj);
49 #define osgk_addref(obj) osgk_addref_real (&((obj)->baseobj))
50 #define osgk_release(obj) osgk_release_real (&((obj)->baseobj))
52 /* OffscreenGecko/embedding.h */
54 OSGK_DERIVEDTYPE(OSGK_EmbeddingOptions);
56 static OSGK_EmbeddingOptions* (*osgk_embedding_options_create) (void);
57 static void (*osgk_embedding_options_add_search_path) (
58 OSGK_EmbeddingOptions* options, const char* path);
59 /*static void (*osgk_embedding_options_add_components_path) (
60 OSGK_EmbeddingOptions* options, const char* path);*/
61 static void (*osgk_embedding_options_set_profile_dir) (
62 OSGK_EmbeddingOptions* options, const char* profileDir,
63 const char* localProfileDir);
65 OSGK_DERIVEDTYPE(OSGK_Embedding);
67 #define OSGK_API_VERSION 1
69 static OSGK_Embedding* (*osgk_embedding_create2) (
70 unsigned int apiVer, OSGK_EmbeddingOptions* options,
71 OSGK_GeckoResult* geckoResult);
73 static OSGK_INLINE OSGK_Embedding* osgk_embedding_create (
74 OSGK_GeckoResult* geckoResult)
76 return osgk_embedding_create2 (OSGK_API_VERSION, 0, geckoResult);
79 static OSGK_INLINE OSGK_Embedding* osgk_embedding_create_with_options (
80 OSGK_EmbeddingOptions* options, OSGK_GeckoResult* geckoResult)
82 return osgk_embedding_create2 (OSGK_API_VERSION, options, geckoResult);
85 /*static OSGK_GeckoMem* (*osgk_embedding_get_gecko_mem) (
86 OSGK_Embedding* embedding);*/
88 /*static OSGK_ComponentMgr* (*osgk_embedding_get_component_mgr) (
89 OSGK_Embedding* embedding);*/
91 /*OSGK_CLASSTYPE_DEF nsIComponentManager;
92 OSGK_CLASSTYPE_DEF nsIComponentRegistrar;
93 OSGK_CLASSTYPE_DEF nsIServiceManager;*/
95 /*static OSGK_CLASSTYPE_REF nsIComponentManager*
96 (*osgk_embedding_get_gecko_component_manager) (OSGK_Embedding* embedding);*/
97 /*static OSGK_CLASSTYPE_REF nsIComponentRegistrar*
98 (*osgk_embedding_get_gecko_component_registrar) (OSGK_Embedding* embedding);*/
99 /*static OSGK_CLASSTYPE_REF nsIServiceManager*
100 (*osgk_embedding_get_gecko_service_manager) (OSGK_Embedding* embedding);*/
106 /*static int (*osgk_embedding_register_js_global) (
107 OSGK_Embedding* embedding, const char* name, const char* contractID,
108 unsigned int flags, OSGK_String** previousContract,
109 OSGK_GeckoResult* geckoResult);*/
111 /*static void (*osgk_embedding_clear_focus*) (OSGK_Embedding* embedding);*/
112 /*void (*osgk_embedding_set_auto_focus) (OSGK_Embedding* embedding, int autoFocus);*/
113 /*static int (*osgk_embedding_get_auto_focus) (OSGK_Embedding* embedding);*/
115 /* OffscreenGecko/browser.h */
116 OSGK_DERIVEDTYPE(OSGK_Browser);
118 static OSGK_Browser* (*osgk_browser_create) (
119 OSGK_Embedding* embedding, int width, int height);
120 static void (*osgk_browser_navigate) (OSGK_Browser* browser,
123 static int (*osgk_browser_query_dirty) (OSGK_Browser* browser);
124 static const unsigned char* (*osgk_browser_lock_data) (
125 OSGK_Browser* browser, int* isDirty);
126 static void (*osgk_browser_unlock_data) (OSGK_Browser* browser,
127 const unsigned char* data);
129 typedef enum OSGK_MouseButton
136 typedef enum OSGK_MouseButtonEventType
141 } OSGK_MouseButtonEventType;
143 static void (*osgk_browser_event_mouse_move) (
144 OSGK_Browser* browser, int x, int y);
145 static void (*osgk_browser_event_mouse_button) (
146 OSGK_Browser* browser, OSGK_MouseButton button,
147 OSGK_MouseButtonEventType eventType);
149 typedef enum OSGK_WheelAxis
155 typedef enum OSGK_WheelDirection
161 } OSGK_WheelDirection;
163 static void (*osgk_browser_event_mouse_wheel) (
164 OSGK_Browser* browser, OSGK_WheelAxis axis,
165 OSGK_WheelDirection direction);
167 typedef enum OSGK_KeyboardEventType
172 } OSGK_KeyboardEventType;
176 OSGKKey_First = 0x110000,
178 OSGKKey_Backspace = OSGKKey_First,
214 static int (*osgk_browser_event_key) (
215 OSGK_Browser* browser, unsigned int key,
216 OSGK_KeyboardEventType eventType);
218 typedef enum OSGK_AntiAliasType
223 } OSGK_AntiAliasType;
225 /*static void (*osgk_browser_set_antialias) (
226 OSGK_Browser* browser, OSGK_AntiAliasType aaType);*/
227 /*static OSGK_AntiAliasType (*osgk_browser_get_antialias) (OSGK_Browser* browser);*/
229 /*static void (*osgk_browser_focus) (OSGK_Browser* browser);*/
231 static void (*osgk_browser_resize) (OSGK_Browser* browser,
232 int width, int height);
234 /*static int (*osgk_browser_set_user_data) (OSGK_Browser* browser,
235 unsigned int key, void* data, int overrideData);*/
236 /*static int (*osgk_browser_get_user_data) (OSGK_Browser* browser,
237 unsigned int key, void** data);*/
239 /* OffscreenGecko/string.h */
240 OSGK_DERIVEDTYPE(OSGK_String);
242 /*static const char* (*osgk_string_get) (OSGK_String* str);*/
244 /*static OSGK_String* (*osgk_string_create) (const char* str);*/
246 /* OffscreenGecko/scriptvariant.h */
248 OSGK_CLASSTYPE_DEF nsISupports;
250 OSGK_DERIVEDTYPE(OSGK_ScriptVariant);
252 typedef enum OSGK_ScriptVariantType
265 } OSGK_ScriptVariantType;
267 /*static OSGK_ScriptVariantType (*osgk_variant_get_type) (
268 OSGK_ScriptVariant* variant);*/
269 /*static OSGK_ScriptVariant* (*osgk_variant_convert) (
270 OSGK_ScriptVariant* variant, OSGK_ScriptVariantType newType);*/
272 /*static int (*osgk_variant_get_int) (OSGK_ScriptVariant* variant,
274 /*static int (*osgk_variant_get_uint) (OSGK_ScriptVariant* variant,
275 unsigned int* val);*/
276 /*static int (*osgk_variant_get_float) (OSGK_ScriptVariant* variant,
278 /*static int (*osgk_variant_get_double) (OSGK_ScriptVariant* variant,
280 /*static int (*osgk_variant_get_bool) (OSGK_ScriptVariant* variant,
282 /*static int (*osgk_variant_get_char) (OSGK_ScriptVariant* variant,
283 unsigned int* val);*/
284 /*// Does not increase ref count
285 static int (*osgk_variant_get_string) (OSGK_ScriptVariant* variant,
286 OSGK_String** val);*/
287 /*// Does not increase ref count
288 static int (*osgk_variant_get_isupports) (OSGK_ScriptVariant* variant,
289 OSGK_CLASSTYPE_REF nsISupports** val);*/
290 /*static int (*osgk_variant_get_script_object) (OSGK_ScriptVariant* variant,
292 /*static int (*osgk_variant_get_array_size) (OSGK_ScriptVariant* variant,
294 /*static int (*osgk_variant_get_array_item) (OSGK_ScriptVariant* variant,
295 OSGK_ScriptVariant** val);*/
297 /*static OSGK_ScriptVariant* (*osgk_variant_create_empty) (
298 OSGK_Embedding* embedding);*/
299 /*static OSGK_ScriptVariant* (*osgk_variant_create_int) (
300 OSGK_Embedding* embedding, int val);*/
301 /*static OSGK_ScriptVariant* (*osgk_variant_create_uint) (
302 OSGK_Embedding* embedding, unsigned int val);
303 /*static OSGK_ScriptVariant* (*osgk_variant_create_float) (
304 OSGK_Embedding* embedding, float val);
305 /*static OSGK_ScriptVariant* (*osgk_variant_create_double) (
306 OSGK_Embedding* embedding, double val);*/
307 /*OSGK_ScriptVariant* (*osgk_variant_create_bool) (
308 OSGK_Embedding* embedding, int val);*/
309 /*static OSGK_ScriptVariant* (*osgk_variant_create_char) (
310 OSGK_Embedding* embedding, unsigned int val);*/
311 /*static OSGK_ScriptVariant* (*osgk_variant_create_string) (
312 OSGK_Embedding* embedding, OSGK_String* val);*/
313 /*static OSGK_ScriptVariant* (*osgk_variant_create_isupports) (
314 OSGK_Embedding* embedding, OSGK_CLASSTYPE_REF nsISupports* val);*/
315 /*static OSGK_ScriptVariant* (*osgk_variant_create_script_object) (
316 OSGK_Embedding* embedding, void* tag);*/
317 /*static OSGK_ScriptVariant* (*osgk_variant_create_array) (
318 OSGK_Embedding* embedding, size_t numItems, OSGK_ScriptVariant** items);*/
320 /* OffscreenGecko/scriptobjecttemplate.h */
322 OSGK_DERIVEDTYPE(OSGK_ScriptObjectTemplate);
324 typedef enum OSGK_ScriptResult
327 srFailed = 0x80004005L /* actually NS_ERROR_FAILURE */
330 typedef struct OSGK_ScriptObjectCreateParams_s
333 OSGK_Browser* browser;
334 } OSGK_ScriptObjectCreateParams;
336 typedef OSGK_ScriptResult (*OSGK_CreateObjFunc) (
337 OSGK_ScriptObjectCreateParams* params, void** objTag);
338 typedef void (*OSGK_DestroyObjFunc) (void* objTag);
340 /*static OSGK_ScriptObjectTemplate* (*osgk_sot_create) (
341 OSGK_Embedding* embedding,
342 OSGK_CreateObjFunc createFunc, OSGK_DestroyObjFunc destroyFunc,
343 void* createParam);*/
345 typedef OSGK_ScriptVariant* (*OSGK_GetPropertyFunc) (void* objTag,
347 typedef OSGK_ScriptResult (*OSGK_SetPropertyFunc) (void* objTag,
348 void* propTag, OSGK_ScriptVariant* val);
350 /*static int (*osgk_sot_add_property) (
351 OSGK_ScriptObjectTemplate* templ, const char* propName, void* propTag,
352 OSGK_GetPropertyFunc getter, OSGK_SetPropertyFunc setter);*/
354 typedef OSGK_ScriptResult (*OSGK_FunctionCallFunc) (void* objTag,
355 void* methTag, size_t numParams, OSGK_ScriptVariant** params,
356 OSGK_ScriptVariant** returnVal);
358 /*static int (*osgk_sot_add_function) (
359 OSGK_ScriptObjectTemplate* templ, const char* funcName, void* funcTag,
360 OSGK_FunctionCallFunc callFunc);*/
362 /*static OSGK_ScriptVariant* (*osgk_sot_instantiate) (
363 OSGK_ScriptObjectTemplate* templ, void** objTag); */
365 /*static int (*osgk_sot_register) (
366 OSGK_ScriptObjectTemplate* templ, OSGK_Embedding* embedding,
367 const char* name, unsigned int flags);*/
369 /* --- >8 --- >8 --- End OffscreenGecko headers --- 8< --- 8< --- */
371 #include "quakedef.h"
372 #include "cl_dyntexture.h"
373 #include "cl_gecko.h"
376 #define DEFAULT_GECKO_SIZE 512
378 static rtexturepool_t *cl_geckotexturepool;
379 static OSGK_Embedding *cl_geckoembedding;
383 char name[ MAX_QPATH + 32 ];
385 OSGK_Browser *browser;
387 int texWidth, texHeight;
392 static clgecko_t cl_geckoinstances[ MAX_GECKO_INSTANCES ];
394 static dllhandle_t osgk_dll = NULL;
396 static clgecko_t * cl_gecko_findunusedinstance( void ) {
398 for( i = 0 ; i < MAX_GECKO_INSTANCES ; i++ ) {
399 clgecko_t *instance = &cl_geckoinstances[ i ];
400 if( !instance->active ) {
404 if( developer.integer > 0 ) {
405 Con_Printf( "cl_gecko_findunusedinstance: out of geckos\n" );
410 clgecko_t * CL_Gecko_FindBrowser( const char *name ) {
413 if( !name || !*name || strncmp( name, CLGECKOPREFIX, sizeof( CLGECKOPREFIX ) - 1 ) != 0 ) {
414 if( developer.integer > 0 ) {
415 Con_Printf( "CL_Gecko_FindBrowser: Bad gecko texture name '%s'!\n", name );
420 for( i = 0 ; i < MAX_GECKO_INSTANCES ; i++ ) {
421 clgecko_t *instance = &cl_geckoinstances[ i ];
422 if( instance->active && strcmp( instance->name, name ) == 0 ) {
427 if( developer.integer > 0 ) {
428 Con_Printf( "CL_Gecko_FindBrowser: No browser named '%s'!\n", name );
434 static void cl_gecko_updatecallback( rtexture_t *texture, void* callbackData ) {
435 clgecko_t *instance = callbackData;
436 const unsigned char *data;
437 if( instance->browser ) {
438 // TODO: OSGK only supports BGRA right now
439 TIMING_TIMESTATEMENT(data = osgk_browser_lock_data( instance->browser, NULL ));
440 R_UpdateTexture( texture, data, 0, 0, instance->width, instance->height );
441 osgk_browser_unlock_data( instance->browser, data );
445 static void cl_gecko_linktexture( clgecko_t *instance ) {
446 // TODO: assert that instance->texture == NULL
447 instance->texture = R_LoadTexture2D( cl_geckotexturepool, instance->name,
448 instance->texWidth, instance->texHeight, NULL, TEXTYPE_BGRA, TEXF_ALPHA | TEXF_PERSISTENT, NULL );
449 R_MakeTextureDynamic( instance->texture, cl_gecko_updatecallback, instance );
450 CL_LinkDynTexture( instance->name, instance->texture );
453 static void cl_gecko_unlinktexture( clgecko_t *instance ) {
454 if( instance->texture ) {
455 CL_UnlinkDynTexture( instance->name );
456 R_FreeTexture( instance->texture );
457 instance->texture = NULL;
461 void CL_Gecko_Resize( clgecko_t *instance, int width, int height ) {
462 int newWidth, newHeight;
464 // early out if bad parameters are passed (no resize to a texture size bigger than the original texture size)
465 if( !instance || !instance->browser) {
469 newWidth = CeilPowerOf2( width );
470 newHeight = CeilPowerOf2( height );
471 if ((newWidth != instance->texWidth) || (newHeight != instance->texHeight))
473 cl_gecko_unlinktexture( instance );
474 instance->texWidth = newWidth;
475 instance->texHeight = newHeight;
476 cl_gecko_linktexture( instance );
480 /* The gecko area will only cover a part of the texture; to avoid
481 'old' pixels bleeding in at the border clear the texture. */
482 R_ClearTexture( instance->texture );
485 osgk_browser_resize( instance->browser, width, height);
486 instance->width = width;
487 instance->height = height;
490 void CL_Gecko_GetTextureExtent( clgecko_t *instance, float* pwidth, float* pheight )
492 if( !instance || !instance->browser ) {
496 *pwidth = (float)instance->width / instance->texWidth;
497 *pheight = (float)instance->height / instance->texHeight;
501 # define XULRUNNER_DIR_SUFFIX "win64"
503 # define XULRUNNER_DIR_SUFFIX "win32"
504 #elif defined(DP_OS_STR) && defined(DP_ARCH_STR)
505 # define XULRUNNER_DIR_SUFFIX DP_OS_STR "-" DP_ARCH_STR
508 clgecko_t * CL_Gecko_CreateBrowser( const char *name ) {
511 if (!osgk_dll) return NULL;
513 // TODO: verify that we dont use a name twice
514 instance = cl_gecko_findunusedinstance();
515 // TODO: assert != NULL
517 if( cl_geckoembedding == NULL ) {
518 char profile_path [MAX_OSPATH];
519 OSGK_GeckoResult grc;
520 OSGK_EmbeddingOptions *options;
522 if( developer.integer > 0 ) {
523 Con_Printf( "CL_Gecko_CreateBrowser: setting up gecko embedding\n" );
526 options = osgk_embedding_options_create();
527 #ifdef XULRUNNER_DIR_SUFFIX
528 osgk_embedding_options_add_search_path( options, "./xulrunner-" XULRUNNER_DIR_SUFFIX "/" );
530 osgk_embedding_options_add_search_path( options, "./xulrunner/" );
531 dpsnprintf (profile_path, sizeof (profile_path), "%s/xulrunner_profile/", fs_gamedir);
532 osgk_embedding_options_set_profile_dir( options, profile_path, 0 );
533 cl_geckoembedding = osgk_embedding_create_with_options( options, &grc );
534 osgk_release( options );
536 if( cl_geckoembedding == NULL ) {
537 Con_Printf( "CL_Gecko_CreateBrowser: Couldn't retrieve gecko embedding object (%.8x)!\n", grc );
539 } else if( developer.integer > 0 ) {
540 Con_Printf( "CL_Gecko_CreateBrowser: Embedding set up correctly\n" );
544 instance->active = true;
545 strlcpy( instance->name, name, sizeof( instance->name ) );
546 instance->browser = osgk_browser_create( cl_geckoembedding, DEFAULT_GECKO_SIZE, DEFAULT_GECKO_SIZE );
547 if( instance->browser == NULL ) {
548 Con_Printf( "CL_Gecko_CreateBrowser: Browser object creation failed!\n" );
550 // TODO: assert != NULL
552 instance->width = instance->texWidth = DEFAULT_GECKO_SIZE;
553 instance->height = instance->texHeight = DEFAULT_GECKO_SIZE;
554 cl_gecko_linktexture( instance );
559 void CL_Gecko_DestroyBrowser( clgecko_t *instance ) {
560 if( !instance || !instance->active ) {
564 instance->active = false;
565 cl_gecko_unlinktexture( instance );
567 osgk_release( instance->browser );
568 instance->browser = NULL;
571 void CL_Gecko_Frame( void ) {
573 // FIXME: track cl_numgeckoinstances to avoid scanning the entire array?
574 for( i = 0 ; i < MAX_GECKO_INSTANCES ; i++ ) {
575 clgecko_t *instance = &cl_geckoinstances[ i ];
576 if( instance->active ) {
577 if( instance->browser && osgk_browser_query_dirty( instance->browser ) == 1 ) {
578 R_MarkDirtyTexture( instance->texture );
584 static void cl_gecko_start( void )
587 cl_geckotexturepool = R_AllocTexturePool();
589 // recreate textures on module start
590 for( i = 0 ; i < MAX_GECKO_INSTANCES ; i++ ) {
591 clgecko_t *instance = &cl_geckoinstances[ i ];
592 if( instance->active ) {
593 cl_gecko_linktexture( instance );
598 static void cl_gecko_shutdown( void )
601 for( i = 0 ; i < MAX_GECKO_INSTANCES ; i++ ) {
602 clgecko_t *instance = &cl_geckoinstances[ i ];
603 if( instance->active ) {
604 cl_gecko_unlinktexture( instance );
607 R_FreeTexturePool( &cl_geckotexturepool );
610 static void cl_gecko_newmap( void )
615 void CL_Gecko_Shutdown( void ) {
617 for( i = 0 ; i < MAX_GECKO_INSTANCES ; i++ ) {
618 clgecko_t *instance = &cl_geckoinstances[ i ];
619 if( instance->active ) {
620 cl_gecko_unlinktexture( instance );
624 if (cl_geckoembedding != NULL)
626 osgk_release( cl_geckoembedding );
627 cl_geckoembedding = NULL;
630 if (osgk_dll != NULL)
632 Sys_UnloadLibrary (&osgk_dll);
636 static void cl_gecko_create_f( void ) {
637 char name[MAX_QPATH];
641 Con_Print("usage: gecko_create <name>\npcreates a browser (full texture path " CLGECKOPREFIX "<name>)\n");
645 // TODO: use snprintf instead
646 sprintf(name, CLGECKOPREFIX "%s", Cmd_Argv(1));
647 CL_Gecko_CreateBrowser( name );
650 static void cl_gecko_destroy_f( void ) {
651 char name[MAX_QPATH];
655 Con_Print("usage: gecko_destroy <name>\ndestroys a browser\n");
659 // TODO: use snprintf instead
660 sprintf(name, CLGECKOPREFIX "%s", Cmd_Argv(1));
661 CL_Gecko_DestroyBrowser( CL_Gecko_FindBrowser( name ) );
664 static void cl_gecko_navigate_f( void ) {
665 char name[MAX_QPATH];
670 Con_Print("usage: gecko_navigate <name> <URI>\nnavigates to a certain URI\n");
674 // TODO: use snprintf instead
675 sprintf(name, CLGECKOPREFIX "%s", Cmd_Argv(1));
677 CL_Gecko_NavigateToURI( CL_Gecko_FindBrowser( name ), URI );
680 static void cl_gecko_injecttext_f( void ) {
681 char name[MAX_QPATH];
688 Con_Print("usage: gecko_injecttext <name> <text>\ninjects a certain text into the browser\n");
692 // TODO: use snprintf instead
693 sprintf(name, CLGECKOPREFIX "%s", Cmd_Argv(1));
694 instance = CL_Gecko_FindBrowser( name );
696 Con_Printf( "cl_gecko_injecttext_f: gecko instance '%s' couldn't be found!\n", name );
700 text = Cmd_Argv( 2 );
702 for( p = text ; *p ; p++ ) {
722 CL_Gecko_Event_Key( instance, key, CLG_BET_PRESS );
726 static void gl_gecko_movecursor_f( void ) {
727 char name[MAX_QPATH];
732 Con_Print("usage: gecko_movecursor <name> <x> <y>\nmove the cursor to a certain position\n");
736 // TODO: use snprintf instead
737 sprintf(name, CLGECKOPREFIX "%s", Cmd_Argv(1));
738 x = atof( Cmd_Argv( 2 ) );
739 y = atof( Cmd_Argv( 3 ) );
741 CL_Gecko_Event_CursorMove( CL_Gecko_FindBrowser( name ), x, y );
747 static const dllfunction_t osgkFuncs[] =
749 {"osgk_addref", (void **) &osgk_addref},
750 {"osgk_release", (void **) &osgk_release},
751 {"osgk_embedding_create2", (void **) &osgk_embedding_create2},
752 {"osgk_embedding_options_create", (void **) &osgk_embedding_options_create},
753 {"osgk_embedding_options_add_search_path", (void **) &osgk_embedding_options_add_search_path},
754 {"osgk_embedding_options_set_profile_dir", (void **) &osgk_embedding_options_set_profile_dir},
755 {"osgk_browser_create", (void **) &osgk_browser_create},
756 {"osgk_browser_query_dirty", (void **) &osgk_browser_query_dirty},
757 {"osgk_browser_navigate", (void **) &osgk_browser_navigate},
758 {"osgk_browser_lock_data", (void **) &osgk_browser_lock_data},
759 {"osgk_browser_unlock_data", (void **) &osgk_browser_unlock_data},
760 {"osgk_browser_resize", (void **) &osgk_browser_resize},
761 {"osgk_browser_event_mouse_move", (void **) &osgk_browser_event_mouse_move},
762 {"osgk_browser_event_mouse_button", (void **) &osgk_browser_event_mouse_button},
763 {"osgk_browser_event_mouse_wheel", (void **) &osgk_browser_event_mouse_wheel},
764 {"osgk_browser_event_key", (void **) &osgk_browser_event_key},
768 void CL_Gecko_Init( void )
770 const char* dllnames [] =
773 "OffscreenGecko64.dll",
775 "OffscreenGecko.dll",
776 #elif defined(MACOSX)
777 "OffscreenGecko.dylib",
779 "libOffscreenGecko.so",
786 if (! Sys_LoadLibrary (dllnames, &osgk_dll, osgkFuncs))
788 Con_Printf ("Could not load OffscreenGecko, Gecko support unavailable\n");
792 Cmd_AddCommand( "gecko_create", cl_gecko_create_f, "Create a gecko browser instance" );
793 Cmd_AddCommand( "gecko_destroy", cl_gecko_destroy_f, "Destroy a gecko browser instance" );
794 Cmd_AddCommand( "gecko_navigate", cl_gecko_navigate_f, "Navigate a gecko browser to a URI" );
795 Cmd_AddCommand( "gecko_injecttext", cl_gecko_injecttext_f, "Injects text into a browser" );
796 Cmd_AddCommand( "gecko_movecursor", gl_gecko_movecursor_f, "Move the cursor to a certain position" );
798 R_RegisterModule( "CL_Gecko", cl_gecko_start, cl_gecko_shutdown, cl_gecko_newmap );
801 void CL_Gecko_NavigateToURI( clgecko_t *instance, const char *URI ) {
802 if( !instance || !instance->browser ) {
806 if( instance->active ) {
807 osgk_browser_navigate( instance->browser, URI );
811 void CL_Gecko_Event_CursorMove( clgecko_t *instance, float x, float y ) {
812 // TODO: assert x, y \in [0.0, 1.0]
813 int mappedx, mappedy;
815 if( !instance || !instance->browser ) {
819 mappedx = x * instance->width;
820 mappedy = y * instance->height;
821 osgk_browser_event_mouse_move( instance->browser, mappedx, mappedy );
824 typedef struct geckokeymapping_s {
826 unsigned int geckokeycode;
829 static geckokeymapping_t geckokeymappingtable[] = {
830 { K_BACKSPACE, OSGKKey_Backspace },
831 { K_TAB, OSGKKey_Tab },
832 { K_ENTER, OSGKKey_Return },
833 { K_SHIFT, OSGKKey_Shift },
834 { K_CTRL, OSGKKey_Control },
835 { K_ALT, OSGKKey_Alt },
836 { K_CAPSLOCK, OSGKKey_CapsLock },
837 { K_ESCAPE, OSGKKey_Escape },
838 { K_SPACE, OSGKKey_Space },
839 { K_PGUP, OSGKKey_PageUp },
840 { K_PGDN, OSGKKey_PageDown },
841 { K_END, OSGKKey_End },
842 { K_HOME, OSGKKey_Home },
843 { K_LEFTARROW, OSGKKey_Left },
844 { K_UPARROW, OSGKKey_Up },
845 { K_RIGHTARROW, OSGKKey_Right },
846 { K_DOWNARROW, OSGKKey_Down },
847 { K_INS, OSGKKey_Insert },
848 { K_DEL, OSGKKey_Delete },
849 { K_F1, OSGKKey_F1 },
850 { K_F2, OSGKKey_F2 },
851 { K_F3, OSGKKey_F3 },
852 { K_F4, OSGKKey_F4 },
853 { K_F5, OSGKKey_F5 },
854 { K_F6, OSGKKey_F6 },
855 { K_F7, OSGKKey_F7 },
856 { K_F8, OSGKKey_F8 },
857 { K_F9, OSGKKey_F9 },
858 { K_F10, OSGKKey_F10 },
859 { K_F11, OSGKKey_F11 },
860 { K_F12, OSGKKey_F12 },
861 { K_NUMLOCK, OSGKKey_NumLock },
862 { K_SCROLLOCK, OSGKKey_ScrollLock }
865 qboolean CL_Gecko_Event_Key( clgecko_t *instance, keynum_t key, clgecko_buttoneventtype_t eventtype ) {
866 if( !instance || !instance->browser ) {
870 // determine whether its a keyboard event
871 if( key < K_OTHERDEVICESBEGIN ) {
873 OSGK_KeyboardEventType mappedtype = kePress;
874 unsigned int mappedkey = key;
877 // yes! then convert it if necessary!
878 for( i = 0 ; i < sizeof( geckokeymappingtable ) / sizeof( *geckokeymappingtable ) ; i++ ) {
879 const geckokeymapping_t * const mapping = &geckokeymappingtable[ i ];
880 if( key == mapping->keycode ) {
881 mappedkey = mapping->geckokeycode;
886 // convert the eventtype
888 switch( eventtype ) {
895 case CLG_BET_DOUBLECLICK:
896 // TODO: error message
899 mappedtype = kePress;
902 return osgk_browser_event_key( instance->browser, mappedkey, mappedtype ) != 0;
903 } else if( K_MOUSE1 <= key && key <= K_MOUSE3 ) {
904 OSGK_MouseButtonEventType mappedtype = meDoubleClick;
905 OSGK_MouseButton mappedbutton;
907 mappedbutton = (OSGK_MouseButton) (mbLeft + (key - K_MOUSE1));
909 switch( eventtype ) {
916 case CLG_BET_DOUBLECLICK:
917 mappedtype = meDoubleClick;
921 osgk_browser_event_mouse_button( instance->browser, mappedbutton, meDown );
926 osgk_browser_event_mouse_button( instance->browser, mappedbutton, mappedtype );
928 } else if( K_MWHEELUP <= key && key <= K_MWHEELDOWN ) {
929 if( eventtype == CLG_BET_DOWN )
930 osgk_browser_event_mouse_wheel( instance->browser,
931 waVertical, (key == K_MWHEELUP) ? wdNegative : wdPositive );