Created
February 1, 2019 22:13
-
-
Save adamjs/d2a650eb0f6ea68c4cd64615318c83f7 to your computer and use it in GitHub Desktop.
Draft C API for Ultralight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef ULTRALIGHT_CAPI_H | |
#define ULTRALIGHT_CAPI_H | |
#ifndef __cplusplus | |
#include <stdbool.h> | |
#endif | |
#include <stddef.h> | |
#include <uchar.h> | |
#include <JavaScriptCore/JavaScript.h> | |
#if defined(__WIN32__) || defined(_WIN32) | |
# if defined(ULTRALIGHT_IMPLEMENTATION) | |
# define ULExport __declspec(dllexport) | |
# else | |
# define ULExport __declspec(dllimport) | |
# endif | |
#define _thread_local __declspec(thread) | |
#ifndef _NATIVE_WCHAR_T_DEFINED | |
#define DISABLE_NATIVE_WCHAR_T | |
typedef char16_t ULChar16; | |
#else | |
typedef wchar_t ULChar16; | |
#endif | |
#else | |
# define ULExport __attribute__((visibility("default"))) | |
#define _thread_local __thread | |
typdef char16_t ULChar16; | |
#endif | |
#ifdef __cplusplus | |
extern "C" { | |
#endif | |
typedef struct C_Config* ULConfig; | |
typedef struct C_Renderer* ULRenderer; | |
typedef struct C_View* ULView; | |
typedef struct C_Bitmap* ULBitmap; | |
typedef struct C_String* ULString; | |
typedef struct C_Buffer* ULBuffer; | |
typedef struct C_RenderTarget* ULRenderTarget; | |
typedef struct C_KeyEvent* ULKeyEvent; | |
typedef struct C_MouseEvent* ULMouseEvent; | |
typedef struct C_ScrollEvent* ULScrollEvent; | |
enum ULMessageSource { | |
kMessageSource_XML = 0, | |
kMessageSource_JS, | |
kMessageSource_Network, | |
kMessageSource_ConsoleAPI, | |
kMessageSource_Storage, | |
kMessageSource_AppCache, | |
kMessageSource_Rendering, | |
kMessageSource_CSS, | |
kMessageSource_Security, | |
kMessageSource_ContentBlocker, | |
kMessageSource_Other, | |
}; | |
enum ULMessageLevel { | |
kMessageLevel_Log = 1, | |
kMessageLevel_Warning = 2, | |
kMessageLevel_Error = 3, | |
kMessageLevel_Debug = 4, | |
kMessageLevel_Info = 5, | |
}; | |
enum ULCursor { | |
kCursor_Pointer = 0, | |
kCursor_Cross, | |
kCursor_Hand, | |
kCursor_IBeam, | |
kCursor_Wait, | |
kCursor_Help, | |
kCursor_EastResize, | |
kCursor_NorthResize, | |
kCursor_NorthEastResize, | |
kCursor_NorthWestResize, | |
kCursor_SouthResize, | |
kCursor_SouthEastResize, | |
kCursor_SouthWestResize, | |
kCursor_WestResize, | |
kCursor_NorthSouthResize, | |
kCursor_EastWestResize, | |
kCursor_NorthEastSouthWestResize, | |
kCursor_NorthWestSouthEastResize, | |
kCursor_ColumnResize, | |
kCursor_RowResize, | |
kCursor_MiddlePanning, | |
kCursor_EastPanning, | |
kCursor_NorthPanning, | |
kCursor_NorthEastPanning, | |
kCursor_NorthWestPanning, | |
kCursor_SouthPanning, | |
kCursor_SouthEastPanning, | |
kCursor_SouthWestPanning, | |
kCursor_WestPanning, | |
kCursor_Move, | |
kCursor_VerticalText, | |
kCursor_Cell, | |
kCursor_ContextMenu, | |
kCursor_Alias, | |
kCursor_Progress, | |
kCursor_NoDrop, | |
kCursor_Copy, | |
kCursor_None, | |
kCursor_NotAllowed, | |
kCursor_ZoomIn, | |
kCursor_ZoomOut, | |
kCursor_Grab, | |
kCursor_Grabbing, | |
kCursor_Custom | |
}; | |
enum ULBitmapFormat { | |
kBitmapFormat_A8, | |
kBitmapFormat_RGBA8 | |
}; | |
/********************* | |
* Config | |
*********************/ | |
ULExport ULConfig ulCreateConfig(); | |
ULExport void ulDestroyConfig(ULConfig config); | |
ULExport void ulSetEnableImages(ULConfig config, bool enabled); | |
ULExport void ulSetEnableJavaScript(ULConfig config, bool enabled); | |
ULExport void ulSetUseBGRAForOffscreenRendering(ULConfig config, bool enabled); | |
ULExport void ulSetDeviceScaleHint(ULConfig config, double value); | |
ULExport void ulSetFontFamilyStandard(ULConfig config, ULString font_name); | |
ULExport void ulSetFontFamilyFixed(ULConfig config, ULString font_name); | |
ULExport void ulSetFontFamilySerif(ULConfig config, ULString font_name); | |
ULExport void ulSetFontFamilySansSerif(ULConfig config, ULString font_name); | |
ULExport void ulSetUserAgent(ULConfig config, ULString agent_string); | |
ULExport void ulSetUserStylesheet(ULConfig config, ULString css_string); | |
/********************* | |
* Renderer | |
*********************/ | |
ULExport ULRenderer ulCreateRenderer(ULConfig config); | |
ULExport void ulDestroyRenderer(ULRenderer renderer); | |
ULExport void ulUpdate(ULRenderer renderer); | |
ULExport void ulRender(ULRenderer renderer); | |
/********************* | |
* View | |
*********************/ | |
ULExport ULView ulCreateView(ULRenderer renderer, unsigned int width, unsigned int height, bool transparent); | |
ULExport void ulDestroyView(ULView view); | |
ULExport ULString ulViewGetURL(ULView view); | |
ULExport ULString ulViewGetTitle(ULView view); | |
ULExport bool ulViewIsLoading(ULView view); | |
ULExport bool ulViewIsBitmapDirty(ULView view); | |
ULExport ULBitmap ulViewGetBitmap(ULView view); | |
ULExport void ulViewLoadHTML(ULView view, ULString html_string); | |
ULExport void ulViewLoadURL(ULView view, ULString url_string); | |
ULExport void ulViewResize(ULView view, unsigned int width, unsigned int height); | |
ULExport JSContextRef ulViewGetJSContext(ULView view); | |
ULExport JSValueRef ulViewEvaluateScript(ULView view, ULString js_string); | |
ULExport bool ulViewCanGoBack(ULView view); | |
ULExport bool ulViewCanGoForward(ULView view); | |
ULExport void ulViewGoBack(ULView view); | |
ULExport void ulViewGoForward(ULView view); | |
ULExport void ulViewGoToHistoryOffset(ULView view, int offset); | |
ULExport void ulViewReload(ULView view); | |
ULExport void ulViewStop(ULView view); | |
ULExport void ulViewFireKeyEvent(ULView view, ULKeyEvent key_event); | |
ULExport void ulViewFireMouseEvent(ULView view, ULMouseEvent mouse_event); | |
ULExport void ulViewFireScrollEvent(ULView view, ULScrollEvent scroll_event); | |
typedef void | |
(*ULChangeTitleCallback) (ULView caller, ULString title); | |
ULExport void ulViewSetChangeTitleCallback(ULView view, ULChangeTitleCallback* callback); | |
typedef void | |
(*ULChangeURLCallback) (ULView caller, ULString url); | |
ULExport void ulViewSetChangeURLCallback(ULView view, ULChangeURLCallback* callback); | |
typedef void | |
(*ULChangeTooltipCallback) (ULView caller, ULString tooltip); | |
ULExport void ulViewSetChangeTooltipCallback(ULView view, ULChangeTooltipCallback* callback); | |
typedef void | |
(*ULChangeCursorCallback) (ULView caller, ULCursor cursor); | |
ULExport void ulViewSetChangeCursorCallback(ULView view, ULChangeCursorCallback* callback); | |
typedef void | |
(*ULAddConsoleMessageCallback) (ULView caller, ULMessageSource source, ULMessageLevel level, ULString message, unsigned int line_number, unsigned int column_number, ULString source_id); | |
ULExport void ulViewSetAddConsoleMessageCallback(ULView view, ULAddConsoleMessageCallback* callback); | |
typedef void | |
(*ULBeginLoadingCallback) (ULView caller); | |
ULExport void ulViewSetBeginLoadingCallback(ULView view, ULBeginLoadingCallback* callback); | |
typedef void | |
(*ULFinishLoadingCallback) (ULView caller); | |
ULExport void ulViewSetFinishLoadingCallback(ULView view, ULFinishLoadingCallback* callback); | |
typedef void | |
(*ULUpdateHistoryCallback) (ULView caller); | |
ULExport void ulViewSetUpdateHistoryCallback(ULView view, ULUpdateHistoryCallback* callback); | |
typedef void | |
(*ULDOMReadyCallback) (ULView caller); | |
ULExport void ulViewSetDOMReadyCallback(ULView view, ULDOMReadyCallback* callback); | |
/*********************** | |
* String | |
***********************/ | |
ULExport ULString ulCreateString(const char* str); | |
ULExport ULString ulCreateStringUTF8(const char* str, size_t len); | |
ULExport ULString ulCreateStringUTF16(ULChar16* str, size_t len); | |
ULExport void ulDestroyString(ULString str); | |
ULExport ULChar16* ulStringGetData(ULString str); | |
ULExport size_t ulStringGetLength(ULString str); | |
ULExport bool ulStringIsEmpty(ULString str); | |
/*********************** | |
* Bitmap | |
***********************/ | |
ULExport ULBitmap ulCreateEmptyBitmap(); | |
ULExport ULBitmap ulCreateBitmap(unsigned int width, unsigned int height, ULBitmapFormat format); | |
ULExport ULBitmap ulCreateBitmapFromPixels(unsigned int width, unsigned int height, ULBitmapFormat format, | |
unsigned int row_bytes, const void* pixels, size_t size, bool owns_pixels); | |
ULExport ULBitmap ulCreateBitmapFromCopy(ULBitmap existing_bitmap); | |
ULExport void ulDestroyBitmap(ULBitmap bitmap); | |
ULExport unsigned int ulBitmapGetWidth(ULBitmap bitmap); | |
ULExport unsigned int ulBitmapGetHeight(ULBitmap bitmap); | |
ULExport ULBitmapFormat ulBitmapGetFormat(ULBitmap bitmap); | |
ULExport unsigned int ulBitmapGetBpp(ULBitmap bitmap); | |
ULExport unsigned int ulBitmapGetRowBytes(ULBitmap bitmap); | |
ULExport size_t ulBitmapGetSize(ULBitmap bitmap); | |
ULExport bool ulBitmapOwnsPixels(ULBitmap bitmap); | |
ULExport void* ulBitmapLockPixels(ULBitmap bitmap); | |
ULExport void ulBitmapUnlockPixels(ULBitmap bitmap); | |
ULExport void* ulBitmapRawPixels(ULBitmap bitmap); | |
ULExport bool ulBitmapIsEmpty(ULBitmap bitmap); | |
ULExport void ulBitmapErase(ULBitmap bitmap); | |
#ifdef __cplusplus | |
} | |
#endif | |
#endif // ULTRALIGHT_CAPI_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment