#ifndef ULTRALIGHT_CAPI_H
#define ULTRALIGHT_CAPI_H
#ifndef __cplusplus
#endif
#include <stddef.h>
#include "JavaScriptCore/JavaScript.h"
#ifdef __OBJC__
#import <AppKit/NSEvent.h>
#endif
#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 unsigned short ULChar16;
#else
typedef wchar_t ULChar16;
#endif
#else
# define ULExport __attribute__((visibility("default")))
#define _thread_local __thread
typedef unsigned short 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;
typedef enum {
kMessageSource_XML = 0,
kMessageSource_JS,
kMessageSource_Network,
kMessageSource_ConsoleAPI,
kMessageSource_Storage,
kMessageSource_AppCache,
kMessageSource_Rendering,
kMessageSource_CSS,
kMessageSource_Security,
kMessageSource_ContentBlocker,
kMessageSource_Other,
} ULMessageSource;
typedef enum {
kMessageLevel_Log = 1,
kMessageLevel_Warning = 2,
kMessageLevel_Error = 3,
kMessageLevel_Debug = 4,
kMessageLevel_Info = 5,
} ULMessageLevel;
typedef enum {
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
} ULCursor;
typedef enum {
kBitmapFormat_A8,
kBitmapFormat_RGBA8
} ULBitmapFormat;
typedef enum {
kKeyEventType_KeyDown,
kKeyEventType_KeyUp,
kKeyEventType_RawKeyDown,
kKeyEventType_Char,
} ULKeyEventType;
typedef enum {
kMouseEventType_MouseMoved,
kMouseEventType_MouseDown,
kMouseEventType_MouseUp,
} ULMouseEventType;
typedef enum {
kMouseButton_None = 0,
kMouseButton_Left,
kMouseButton_Middle,
kMouseButton_Right,
} ULMouseButton;
typedef enum {
kScrollEventType_ScrollByPixel,
kScrollEventType_ScrollByPage,
} ULScrollEventType;
ULExport ULConfig ulCreateConfig();
ULExport void ulDestroyConfig(ULConfig config);
ULExport void ulConfigSetEnableImages(ULConfig config, bool enabled);
ULExport void ulConfigSetEnableJavaScript(ULConfig config, bool enabled);
ULExport void ulConfigSetUseBGRAForOffscreenRendering(ULConfig config,
bool enabled);
ULExport void ulConfigSetDeviceScaleHint(ULConfig config, double value);
ULExport void ulConfigSetFontFamilyStandard(ULConfig config,
ULString font_name);
ULExport void ulConfigSetFontFamilyFixed(ULConfig config, ULString font_name);
ULExport void ulConfigSetFontFamilySerif(ULConfig config, ULString font_name);
ULExport void ulConfigSetFontFamilySansSerif(ULConfig config,
ULString font_name);
ULExport void ulConfigSetUserAgent(ULConfig config, ULString agent_string);
ULExport void ulConfigSetUserStylesheet(ULConfig config, ULString css_string);
ULExport void ulConfigSetForceRepaint(ULConfig config, bool enabled);
ULExport void ulConfigSetAnimationTimerDelay(ULConfig config, double delay);
ULExport void ulConfigSetMemoryCacheSize(ULConfig config, unsigned int size);
ULExport void ulConfigSetPageCacheSize(ULConfig config, unsigned int size);
ULExport ULRenderer ulCreateRenderer(ULConfig config);
ULExport void ulDestroyRenderer(ULRenderer renderer);
ULExport void ulUpdate(ULRenderer renderer);
ULExport void ulRender(ULRenderer renderer);
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) (void* user_data, ULView caller, ULString title);
ULExport void ulViewSetChangeTitleCallback(ULView view,
ULChangeTitleCallback callback,
void* user_data);
typedef void
(*ULChangeURLCallback) (void* user_data, ULView caller, ULString url);
ULExport void ulViewSetChangeURLCallback(ULView view,
ULChangeURLCallback callback,
void* user_data);
typedef void
(*ULChangeTooltipCallback) (void* user_data, ULView caller, ULString tooltip);
ULExport void ulViewSetChangeTooltipCallback(ULView view,
ULChangeTooltipCallback callback,
void* user_data);
typedef void
(*ULChangeCursorCallback) (void* user_data, ULView caller, ULCursor cursor);
ULExport void ulViewSetChangeCursorCallback(ULView view,
ULChangeCursorCallback callback,
void* user_data);
typedef void
(*ULAddConsoleMessageCallback) (void* user_data, 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,
void* user_data);
typedef void
(*ULBeginLoadingCallback) (void* user_data, ULView caller);
ULExport void ulViewSetBeginLoadingCallback(ULView view,
ULBeginLoadingCallback callback,
void* user_data);
typedef void
(*ULFinishLoadingCallback) (void* user_data, ULView caller);
ULExport void ulViewSetFinishLoadingCallback(ULView view,
ULFinishLoadingCallback callback,
void* user_data);
typedef void
(*ULUpdateHistoryCallback) (void* user_data, ULView caller);
ULExport void ulViewSetUpdateHistoryCallback(ULView view,
ULUpdateHistoryCallback callback,
void* user_data);
typedef void
(*ULDOMReadyCallback) (void* user_data, ULView caller);
ULExport void ulViewSetDOMReadyCallback(ULView view,
ULDOMReadyCallback callback,
void* user_data);
ULExport void ulViewSetNeedsPaint(ULView view, bool needs_paint);
ULExport bool ulViewGetNeedsPaint(ULView view);
ULExport ULView ulViewCreateInspectorView(ULView view);
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);
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 should_copy);
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);
ULExport bool ulBitmapWritePNG(ULBitmap bitmap, const char* path);
ULExport ULKeyEvent ulCreateKeyEvent(ULKeyEventType type,
unsigned int modifiers,
int virtual_key_code, int native_key_code,
ULString text, ULString unmodified_text,
bool is_keypad, bool is_auto_repeat,
bool is_system_key);
#ifdef _WIN32
ULExport ULKeyEvent ulCreateKeyEventWindows(ULKeyEventType type,
uintptr_t wparam, intptr_t lparam,
bool is_system_key);
#endif
#ifdef __OBJC__
ULExport ULKeyEvent ulCreateKeyEventMacOS(NSEvent* evt);
#endif
ULExport void ulDestroyKeyEvent(ULKeyEvent evt);
ULExport ULMouseEvent ulCreateMouseEvent(ULMouseEventType type, int x, int y,
ULMouseButton button);
ULExport void ulDestroyMouseEvent(ULMouseEvent evt);
ULExport ULScrollEvent ulCreateScrollEvent(ULScrollEventType type, int delta_x,
int delta_y);
ULExport void ulDestroyScrollEvent(ULScrollEvent evt);
#ifdef __cplusplus
}
#endif
#endif