Ultralight C API 1.3.0
Loading...
Searching...
No Matches
CAPI_View.h
Go to the documentation of this file.
1/******************************************************************************
2 * This file is a part of Ultralight, an ultra-portable web-browser engine. *
3 * *
4 * See <https://ultralig.ht> for licensing and more. *
5 * *
6 * (C) 2023 Ultralight, Inc. *
7 *****************************************************************************/
8
9///
10/// @file CAPI_View.h
11///
12/// View is a web-page container rendered to an offscreen surface that you display yourself.
13///
14/// The View object is responsible for loading and rendering web-pages to an offscreen surface. It
15/// is completely isolated from the OS windowing system, you must forward all input events to it
16/// from your application.
17///
18/// @note The API is not thread-safe, all calls must be made on the same thread that the
19/// Renderer/App was created on.
20///
21#ifndef ULTRALIGHT_CAPI_VIEW_H
22#define ULTRALIGHT_CAPI_VIEW_H
23
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/******************************************************************************
31 * ViewConfig
32 *****************************************************************************/
33
34///
35/// Create view configuration with default values (see <Ultralight/platform/View.h>).
36///
38
39///
40/// Destroy view configuration.
41///
43
44///
45/// Whether to render using the GPU renderer (accelerated) or the CPU renderer (unaccelerated).
46///
47/// This option is only valid if you're managing the Renderer yourself (eg, you've previously
48/// called ulCreateRenderer() instead of ulCreateApp()).
49///
50/// When true, the View will be rendered to an offscreen GPU texture using the GPU driver set in
51/// ulPlatformSetGPUDriver(). You can fetch details for the texture via ulViewGetRenderTarget().
52///
53/// When false (the default), the View will be rendered to an offscreen pixel buffer using the
54/// multithreaded CPU renderer. This pixel buffer can optionally be provided by the user--
55/// for more info see ulViewGetSurface().
56///
57ULExport void ulViewConfigSetIsAccelerated(ULViewConfig config, bool is_accelerated);
58
59///
60/// Set whether images should be enabled (Default = True).
61///
62ULExport void ulViewConfigSetIsTransparent(ULViewConfig config, bool is_transparent);
63
64///
65/// The initial device scale, ie. the amount to scale page units to screen pixels. This should be
66/// set to the scaling factor of the device that the View is displayed on. (Default = 1.0)
67///
68/// @note 1.0 is equal to 100% zoom (no scaling), 2.0 is equal to 200% zoom (2x scaling)
69///
70ULExport void ulViewConfigSetInitialDeviceScale(ULViewConfig config, double initial_device_scale);
71
72///
73/// Whether or not the View should initially have input focus. (Default = True)
74///
76
77///
78/// Set whether images should be enabled (Default = True).
79///
81
82///
83/// Set whether JavaScript should be enabled (Default = True).
84///
86
87///
88/// Set default font-family to use (Default = Times New Roman).
89///
91
92///
93/// Set default font-family to use for fixed fonts, eg <pre> and <code>
94/// (Default = Courier New).
95///
97
98///
99/// Set default font-family to use for serif fonts (Default = Times New Roman).
100///
102
103///
104/// Set default font-family to use for sans-serif fonts (Default = Arial).
105///
107
108///
109/// Set user agent string (See <Ultralight/platform/Config.h> for the default).
110///
112
113/******************************************************************************
114 * View
115 *****************************************************************************/
116
117///
118/// Create a View with certain size (in pixels).
119///
120/// @note You can pass null to 'session' to use the default session.
121///
122ULExport ULView ulCreateView(ULRenderer renderer, unsigned int width, unsigned int height,
123 ULViewConfig view_config, ULSession session);
124
125///
126/// Destroy a View.
127///
129
130///
131/// Get current URL.
132///
133/// @note Don't destroy the returned string, it is owned by the View.
134///
136
137///
138/// Get current title.
139///
140/// @note Don't destroy the returned string, it is owned by the View.
141///
143
144///
145/// Get the width, in pixels.
146///
147ULExport unsigned int ulViewGetWidth(ULView view);
148
149///
150/// Get the height, in pixels.
151///
152ULExport unsigned int ulViewGetHeight(ULView view);
153
154///
155/// Get the device scale, ie. the amount to scale page units to screen pixels.
156///
157/// For example, a value of 1.0 is equivalent to 100% zoom. A value of 2.0 is 200% zoom.
158///
160
161///
162/// Set the device scale.
163///
164ULExport void ulViewSetDeviceScale(ULView view, double scale);
165
166///
167/// Whether or not the View is GPU-accelerated. If this is false, the page will be rendered
168/// via the CPU renderer.
169///
171
172///
173/// Whether or not the View supports transparent backgrounds.
174///
176
177///
178/// Check if the main frame of the page is currrently loading.
179///
181
182///
183/// Get the RenderTarget for the View.
184///
185/// @note Only valid if this View is GPU accelerated.
186///
187/// You can use this with your GPUDriver implementation to bind and display the
188/// corresponding texture in your application.
189///
191
192///
193/// Get the Surface for the View (native pixel buffer that the CPU renderer draws into).
194///
195/// @note This operation is only valid if you're managing the Renderer yourself (eg, you've
196/// previously called ulCreateRenderer() instead of ulCreateApp()).
197///
198/// This function will return NULL if this View is GPU accelerated.
199///
200/// The default Surface is BitmapSurface but you can provide your own Surface implementation
201/// via ulPlatformSetSurfaceDefinition.
202///
203/// When using the default Surface, you can retrieve the underlying bitmap by casting
204/// ULSurface to ULBitmapSurface and calling ulBitmapSurfaceGetBitmap().
205///
207
208///
209/// Load a raw string of HTML.
210///
211ULExport void ulViewLoadHTML(ULView view, ULString html_string);
212
213///
214/// Load a URL into main frame.
215///
216ULExport void ulViewLoadURL(ULView view, ULString url_string);
217
218///
219/// Resize view to a certain width and height (in pixels).
220///
221ULExport void ulViewResize(ULView view, unsigned int width, unsigned int height);
222
223///
224/// Acquire the page's JSContext for use with JavaScriptCore API.
225///
226/// @note This call locks the context for the current thread. You should call
227/// ulViewUnlockJSContext() after using the context so other worker threads can modify
228/// JavaScript state.
229///
230/// @note The lock is recusive, it's okay to call this multiple times as long as you call
231/// ulViewUnlockJSContext() the same number of times.
232///
234
235///
236/// Unlock the page's JSContext after a previous call to ulViewLockJSContext().
237///
239
240///
241/// Evaluate a string of JavaScript and return result.
242///
243/// @param js_string The string of JavaScript to evaluate.
244///
245/// @param exception The address of a ULString to store a description of the last exception. Pass
246/// NULL to ignore this. Don't destroy the exception string returned, it's owned
247/// by the View.
248///
249/// @note Don't destroy the returned string, it's owned by the View. This value is reset with every
250/// call-- if you want to retain it you should copy the result to a new string via
251/// ulCreateStringFromCopy().
252///
253/// @note An example of using this API:
254/// <pre>
255/// ULString script = ulCreateString("1 + 1");
256/// ULString exception;
257/// ULString result = ulViewEvaluateScript(view, script, &exception);
258/// /* Use the result ("2") and exception description (if any) here. */
259/// ulDestroyString(script);
260/// </pre>
261///
263
264///
265/// Check if can navigate backwards in history.
266///
268
269///
270/// Check if can navigate forwards in history.
271///
273
274///
275/// Navigate backwards in history.
276///
278
279///
280/// Navigate forwards in history.
281///
283
284///
285/// Navigate to arbitrary offset in history.
286///
288
289///
290/// Reload current page.
291///
293
294///
295/// Stop all page loads.
296///
298
299///
300/// Give focus to the View.
301///
302/// You should call this to give visual indication that the View has input focus (changes active
303/// text selection colors, for example).
304///
306
307///
308/// Remove focus from the View and unfocus any focused input elements.
309///
310/// You should call this to give visual indication that the View has lost input focus.
311///
313
314///
315/// Whether or not the View has focus.
316///
318
319///
320/// Whether or not the View has an input element with visible keyboard focus (indicated by a
321/// blinking caret).
322///
323/// You can use this to decide whether or not the View should consume keyboard input events (useful
324/// in games with mixed UI and key handling).
325///
327
328///
329/// Fire a keyboard event.
330///
332
333///
334/// Fire a mouse event.
335///
337
338///
339/// Fire a scroll event.
340///
342
343typedef void (*ULChangeTitleCallback)(void* user_data, ULView caller, ULString title);
344
345///
346/// Set callback for when the page title changes.
347///
349 void* user_data);
350
351typedef void (*ULChangeURLCallback)(void* user_data, ULView caller, ULString url);
352
353///
354/// Set callback for when the page URL changes.
355///
357 void* user_data);
358
359typedef void (*ULChangeTooltipCallback)(void* user_data, ULView caller, ULString tooltip);
360
361///
362/// Set callback for when the tooltip changes (usually result of a mouse hover).
363///
365 void* user_data);
366
367typedef void (*ULChangeCursorCallback)(void* user_data, ULView caller, ULCursor cursor);
368
369///
370/// Set callback for when the mouse cursor changes.
371///
373 void* user_data);
374
375typedef void (*ULAddConsoleMessageCallback)(void* user_data, ULView caller, ULMessageSource source,
376 ULMessageLevel level, ULString message,
377 unsigned int line_number, unsigned int column_number,
378 ULString source_id);
379
380///
381/// Set callback for when a message is added to the console (useful for JavaScript / network errors
382/// and debugging).
383///
385 void* user_data);
386
387typedef ULView (*ULCreateChildViewCallback)(void* user_data, ULView caller, ULString opener_url,
388 ULString target_url, bool is_popup,
389 ULIntRect popup_rect);
390
391///
392/// Set callback for when the page wants to create a new View.
393///
394/// This is usually the result of a user clicking a link with target="_blank" or by JavaScript
395/// calling window.open(url).
396///
397/// To allow creation of these new Views, you should create a new View in this callback, resize it
398/// to your container, and return it. You are responsible for displaying the returned View.
399///
400/// You should return NULL if you want to block the action.
401///
403 void* user_data);
404
405typedef ULView (*ULCreateInspectorViewCallback)(void* user_data, ULView caller, bool is_local,
406 ULString inspected_url);
407
408///
409/// Set callback for when the page wants to create a new View to display the local inspector in.
410///
411/// You should create a new View in this callback, resize it to your
412/// container, and return it. You are responsible for displaying the returned View.
413///
415 void* user_data);
416
417typedef void (*ULBeginLoadingCallback)(void* user_data, ULView caller, unsigned long long frame_id,
418 bool is_main_frame, ULString url);
419
420///
421/// Set callback for when the page begins loading a new URL into a frame.
422///
424 void* user_data);
425
426typedef void (*ULFinishLoadingCallback)(void* user_data, ULView caller, unsigned long long frame_id,
427 bool is_main_frame, ULString url);
428
429///
430/// Set callback for when the page finishes loading a URL into a frame.
431///
433 void* user_data);
434
435typedef void (*ULFailLoadingCallback)(void* user_data, ULView caller, unsigned long long frame_id,
436 bool is_main_frame, ULString url, ULString description,
437 ULString error_domain, int error_code);
438
439///
440/// Set callback for when an error occurs while loading a URL into a frame.
441///
443 void* user_data);
444
445typedef void (*ULWindowObjectReadyCallback)(void* user_data, ULView caller,
446 unsigned long long frame_id, bool is_main_frame,
447 ULString url);
448
449///
450/// Set callback for when the JavaScript window object is reset for a new page load.
451///
452/// This is called before any scripts are executed on the page and is the earliest time to setup any
453/// initial JavaScript state or bindings.
454///
455/// The document is not guaranteed to be loaded/parsed at this point. If you need to make any
456/// JavaScript calls that are dependent on DOM elements or scripts on the page, use DOMReady
457/// instead.
458///
459/// The window object is lazily initialized (this will not be called on pages with no scripts).
460///
462 void* user_data);
463
464typedef void (*ULDOMReadyCallback)(void* user_data, ULView caller, unsigned long long frame_id,
465 bool is_main_frame, ULString url);
466
467///
468/// Set callback for when all JavaScript has been parsed and the document is ready.
469///
470/// This is the best time to make any JavaScript calls that are dependent on DOM elements or scripts
471/// on the page.
472///
473ULExport void ulViewSetDOMReadyCallback(ULView view, ULDOMReadyCallback callback, void* user_data);
474
475typedef void (*ULUpdateHistoryCallback)(void* user_data, ULView caller);
476
477///
478/// Set callback for when the history (back/forward state) is modified.
479///
481 void* user_data);
482
483///
484/// Set whether or not a view should be repainted during the next call to ulRender.
485///
486/// @note This flag is automatically set whenever the page content changes but you can set it
487/// directly in case you need to force a repaint.
488///
489ULExport void ulViewSetNeedsPaint(ULView view, bool needs_paint);
490
491///
492/// Whether or not a view should be painted during the next call to ulRender.
493///
495
496///
497/// Create an Inspector View to inspect / debug this View locally.
498///
499/// This will only succeed if you have the inspector assets in your filesystem-- the inspector
500/// will look for file:///inspector/Main.html when it first loads.
501///
502/// You must handle ulViewSetCreateInspectorViewCallback so that the library has a View to display
503/// the inspector in. This function will call the callback only if an inspector view is not
504/// currently active.
505///
507
508#ifdef __cplusplus
509} // extern "C"
510#endif
511
512#endif // ULTRALIGHT_CAPI_VIEW_H
ULMessageSource
Definition CAPI_Defines.h:66
struct C_View * ULView
Definition CAPI_Defines.h:52
struct C_String * ULString
Definition CAPI_Defines.h:54
struct C_Session * ULSession
Definition CAPI_Defines.h:50
#define ULExport
Definition CAPI_Defines.h:27
struct C_Surface * ULSurface
Definition CAPI_Defines.h:62
ULMessageLevel
Definition CAPI_Defines.h:80
ULCursor
Definition CAPI_Defines.h:88
struct C_MouseEvent * ULMouseEvent
Definition CAPI_Defines.h:57
struct C_ViewConfig * ULViewConfig
Definition CAPI_Defines.h:51
struct C_ScrollEvent * ULScrollEvent
Definition CAPI_Defines.h:58
struct C_Renderer * ULRenderer
Definition CAPI_Defines.h:49
struct C_KeyEvent * ULKeyEvent
Definition CAPI_Defines.h:56
ULExport unsigned int ulViewGetWidth(ULView view)
Get the width, in pixels.
ULExport void ulViewSetDeviceScale(ULView view, double scale)
Set the device scale.
ULExport void ulViewSetChangeCursorCallback(ULView view, ULChangeCursorCallback callback, void *user_data)
Set callback for when the mouse cursor changes.
ULExport bool ulViewHasFocus(ULView view)
Whether or not the View has focus.
ULExport void ulViewLoadURL(ULView view, ULString url_string)
Load a URL into main frame.
ULExport void ulViewGoBack(ULView view)
Navigate backwards in history.
ULExport void ulViewSetBeginLoadingCallback(ULView view, ULBeginLoadingCallback callback, void *user_data)
Set callback for when the page begins loading a new URL into a frame.
ULExport unsigned int ulViewGetHeight(ULView view)
Get the height, in pixels.
void(* ULBeginLoadingCallback)(void *user_data, ULView caller, unsigned long long frame_id, bool is_main_frame, ULString url)
Definition CAPI_View.h:417
ULExport void ulViewGoForward(ULView view)
Navigate forwards in history.
ULExport void ulViewReload(ULView view)
Reload current page.
ULExport ULString ulViewGetTitle(ULView view)
Get current title.
void(* ULChangeCursorCallback)(void *user_data, ULView caller, ULCursor cursor)
Definition CAPI_View.h:367
ULExport void ulViewLoadHTML(ULView view, ULString html_string)
Load a raw string of HTML.
ULExport JSContextRef ulViewLockJSContext(ULView view)
Acquire the page's JSContext for use with JavaScriptCore API.
void(* ULChangeTitleCallback)(void *user_data, ULView caller, ULString title)
Definition CAPI_View.h:343
ULExport void ulViewConfigSetFontFamilyFixed(ULViewConfig config, ULString font_name)
Set default font-family to use for fixed fonts, eg.
ULExport void ulViewFireMouseEvent(ULView view, ULMouseEvent mouse_event)
Fire a mouse event.
ULExport void ulViewGoToHistoryOffset(ULView view, int offset)
Navigate to arbitrary offset in history.
ULExport ULViewConfig ulCreateViewConfig()
Create view configuration with default values (see <Ultralight/platform/View.h>).
ULExport void ulViewSetFinishLoadingCallback(ULView view, ULFinishLoadingCallback callback, void *user_data)
Set callback for when the page finishes loading a URL into a frame.
ULExport void ulViewFireKeyEvent(ULView view, ULKeyEvent key_event)
Fire a keyboard event.
ULExport void ulDestroyView(ULView view)
Destroy a View.
void(* ULFinishLoadingCallback)(void *user_data, ULView caller, unsigned long long frame_id, bool is_main_frame, ULString url)
Definition CAPI_View.h:426
ULExport bool ulViewCanGoBack(ULView view)
Check if can navigate backwards in history.
ULExport ULView ulCreateView(ULRenderer renderer, unsigned int width, unsigned int height, ULViewConfig view_config, ULSession session)
Create a View with certain size (in pixels).
ULExport void ulViewConfigSetEnableImages(ULViewConfig config, bool enabled)
Set whether images should be enabled (Default = True).
ULExport void ulViewSetNeedsPaint(ULView view, bool needs_paint)
Set whether or not a view should be repainted during the next call to ulRender.
ULExport void ulViewSetChangeURLCallback(ULView view, ULChangeURLCallback callback, void *user_data)
Set callback for when the page URL changes.
ULExport bool ulViewIsTransparent(ULView view)
Whether or not the View supports transparent backgrounds.
ULExport void ulDestroyViewConfig(ULViewConfig config)
Destroy view configuration.
ULExport void ulViewFireScrollEvent(ULView view, ULScrollEvent scroll_event)
Fire a scroll event.
ULExport bool ulViewHasInputFocus(ULView view)
Whether or not the View has an input element with visible keyboard focus (indicated by a blinking car...
ULExport void ulViewSetCreateChildViewCallback(ULView view, ULCreateChildViewCallback callback, void *user_data)
Set callback for when the page wants to create a new View.
ULExport void ulViewSetWindowObjectReadyCallback(ULView view, ULWindowObjectReadyCallback callback, void *user_data)
Set callback for when the JavaScript window object is reset for a new page load.
ULExport void ulViewUnfocus(ULView view)
Remove focus from the View and unfocus any focused input elements.
ULExport void ulViewResize(ULView view, unsigned int width, unsigned int height)
Resize view to a certain width and height (in pixels).
ULExport void ulViewSetFailLoadingCallback(ULView view, ULFailLoadingCallback callback, void *user_data)
Set callback for when an error occurs while loading a URL into a frame.
void(* ULWindowObjectReadyCallback)(void *user_data, ULView caller, unsigned long long frame_id, bool is_main_frame, ULString url)
Definition CAPI_View.h:445
ULExport void ulViewSetChangeTitleCallback(ULView view, ULChangeTitleCallback callback, void *user_data)
Set callback for when the page title changes.
ULExport void ulViewSetCreateInspectorViewCallback(ULView view, ULCreateInspectorViewCallback callback, void *user_data)
Set callback for when the page wants to create a new View to display the local inspector in.
ULExport void ulViewConfigSetFontFamilyStandard(ULViewConfig config, ULString font_name)
Set default font-family to use (Default = Times New Roman).
ULExport bool ulViewGetNeedsPaint(ULView view)
Whether or not a view should be painted during the next call to ulRender.
ULExport void ulViewFocus(ULView view)
Give focus to the View.
void(* ULUpdateHistoryCallback)(void *user_data, ULView caller)
Definition CAPI_View.h:475
ULExport ULSurface ulViewGetSurface(ULView view)
Get the Surface for the View (native pixel buffer that the CPU renderer draws into).
ULExport void ulViewConfigSetUserAgent(ULViewConfig config, ULString agent_string)
Set user agent string (See <Ultralight/platform/Config.h> for the default).
ULExport void ulViewConfigSetInitialFocus(ULViewConfig config, bool is_focused)
Whether or not the View should initially have input focus.
ULExport void ulViewSetUpdateHistoryCallback(ULView view, ULUpdateHistoryCallback callback, void *user_data)
Set callback for when the history (back/forward state) is modified.
ULExport double ulViewGetDeviceScale(ULView view)
Get the device scale, ie.
void(* ULAddConsoleMessageCallback)(void *user_data, ULView caller, ULMessageSource source, ULMessageLevel level, ULString message, unsigned int line_number, unsigned int column_number, ULString source_id)
Definition CAPI_View.h:375
ULExport bool ulViewIsAccelerated(ULView view)
Whether or not the View is GPU-accelerated.
ULExport void ulViewSetChangeTooltipCallback(ULView view, ULChangeTooltipCallback callback, void *user_data)
Set callback for when the tooltip changes (usually result of a mouse hover).
ULExport void ulViewConfigSetEnableJavaScript(ULViewConfig config, bool enabled)
Set whether JavaScript should be enabled (Default = True).
ULExport void ulViewCreateLocalInspectorView(ULView view)
Create an Inspector View to inspect / debug this View locally.
ULExport void ulViewUnlockJSContext(ULView view)
Unlock the page's JSContext after a previous call to ulViewLockJSContext().
ULExport void ulViewConfigSetInitialDeviceScale(ULViewConfig config, double initial_device_scale)
The initial device scale, ie.
ULExport void ulViewSetAddConsoleMessageCallback(ULView view, ULAddConsoleMessageCallback callback, void *user_data)
Set callback for when a message is added to the console (useful for JavaScript / network errors and d...
void(* ULChangeURLCallback)(void *user_data, ULView caller, ULString url)
Definition CAPI_View.h:351
ULExport void ulViewConfigSetIsAccelerated(ULViewConfig config, bool is_accelerated)
Whether to render using the GPU renderer (accelerated) or the CPU renderer (unaccelerated).
ULExport void ulViewConfigSetIsTransparent(ULViewConfig config, bool is_transparent)
Set whether images should be enabled (Default = True).
ULExport void ulViewStop(ULView view)
Stop all page loads.
ULExport bool ulViewIsLoading(ULView view)
Check if the main frame of the page is currrently loading.
ULExport ULString ulViewGetURL(ULView view)
Get current URL.
ULExport ULRenderTarget ulViewGetRenderTarget(ULView view)
Get the RenderTarget for the View.
ULExport void ulViewSetDOMReadyCallback(ULView view, ULDOMReadyCallback callback, void *user_data)
Set callback for when all JavaScript has been parsed and the document is ready.
ULExport void ulViewConfigSetFontFamilySansSerif(ULViewConfig config, ULString font_name)
Set default font-family to use for sans-serif fonts (Default = Arial).
ULView(* ULCreateInspectorViewCallback)(void *user_data, ULView caller, bool is_local, ULString inspected_url)
Definition CAPI_View.h:405
ULExport ULString ulViewEvaluateScript(ULView view, ULString js_string, ULString *exception)
Evaluate a string of JavaScript and return result.
void(* ULChangeTooltipCallback)(void *user_data, ULView caller, ULString tooltip)
Definition CAPI_View.h:359
ULExport bool ulViewCanGoForward(ULView view)
Check if can navigate forwards in history.
ULExport void ulViewConfigSetFontFamilySerif(ULViewConfig config, ULString font_name)
Set default font-family to use for serif fonts (Default = Times New Roman).
void(* ULFailLoadingCallback)(void *user_data, ULView caller, unsigned long long frame_id, bool is_main_frame, ULString url, ULString description, ULString error_domain, int error_code)
Definition CAPI_View.h:435
ULView(* ULCreateChildViewCallback)(void *user_data, ULView caller, ULString opener_url, ULString target_url, bool is_popup, ULIntRect popup_rect)
Definition CAPI_View.h:387
void(* ULDOMReadyCallback)(void *user_data, ULView caller, unsigned long long frame_id, bool is_main_frame, ULString url)
Definition CAPI_View.h:464
const struct OpaqueJSContext * JSContextRef
Definition JSBase.h:43
Definition CAPI_Defines.h:242
Definition CAPI_Defines.h:249