|
Ultralight C++ API 2.0.0
|
#include <Ultralight/View.h>
Web-page container rendered to an offscreen surface.
The View class is responsible for loading and rendering web-pages to an offscreen surface. It is completely isolated from the OS windowing system, you must forward all input events to it from your application.
You can create a View using Renderer::CreateView():
You can load content asynchronously into a View using View::LoadURL().
Local file URLs (eg, file:///page.html) will be loaded via FileSystem. You can provide your own FileSystem implementation so these files can be loaded from your application's resources.
Views are rendered either to a pixel-buffer (View::surface()) or a GPU texture (View::render_target()) depending on whether CPU or GPU rendering is used (see ViewConfig::is_accelerated).
You can use the Surface or RenderTarget to display the View in your application.
You must forward all input events to the View from your application. This includes keyboard, mouse, and scroll events.
Public Types | |
| using | DOMTriggersInjectionFilter |
| Callback that decides whether an attached set of DOM listeners is applied to a loading page. | |
| using | JSAPIInjectionFilter = bool (*)(void* user_data, const ULJSAPIInjectionRequest* request) |
| Callback that decides whether an attached API's bindings are added to a loading page. | |
Public Member Functions | |
| virtual String | url ()=0 |
| Get the URL of the current page loaded into this View, if any. | |
| virtual String | title ()=0 |
| Get the title of the current page loaded into this View, if any. | |
| virtual uint32_t | width () const =0 |
| Get the width of the View, in pixels. | |
| virtual uint32_t | height () const =0 |
| Get the height of the View, in pixels. | |
| virtual uint32_t | display_id () const =0 |
| Get the display id of the View. | |
| virtual void | set_display_id (uint32_t id)=0 |
| Set the display id of the View. | |
| virtual double | device_scale () const =0 |
| Get the device scale, ie. | |
| virtual void | set_device_scale (double scale)=0 |
| Set the device scale. | |
| virtual bool | is_accelerated () const =0 |
| Whether or not the View is GPU-accelerated. | |
| virtual bool | is_transparent () const =0 |
| Whether or not the View supports transparent backgrounds. | |
| virtual bool | is_loading ()=0 |
| Check if the main frame of the page is currently loading. | |
| virtual bool | is_settled ()=0 |
| Check if the page has settled after loading. | |
| virtual RenderTarget | render_target ()=0 |
| Get the RenderTarget for the View. | |
| virtual Surface * | surface ()=0 |
| Get the Surface for the View (native pixel buffer that the CPU renderer draws into). | |
| virtual void | LoadHTML (const String &html, const String &url="", bool add_to_history=false)=0 |
| Load a raw string of HTML, the View will navigate to it as a new page. | |
| virtual void | LoadURL (const String &url)=0 |
| Load a URL, the View will navigate to it as a new page. | |
| virtual void | Resize (uint32_t width, uint32_t height)=0 |
| Resize View to a certain size. | |
| virtual void | Resize (uint32_t width, uint32_t height, double device_scale)=0 |
| Resize View to a certain size and apply a new device scale in the same pass. | |
| virtual RefPtr< JSContext > | LockJSContext (const String &frame="")=0 |
| Acquire the page's JSContext for use with the JavaScriptCore API. | |
| virtual void * | JavaScriptVM (const String &frame="")=0 |
| Get a handle to the internal JavaScriptCore VM. | |
| virtual String | EvaluateScript (const String &script, String *exception=nullptr, const String &frame="")=0 |
| Evaluate a string of JavaScript and return the result as a String. | |
| virtual ULJSContext | GetJSContext ()=0 |
| Get a ULJS handle to the main frame's JavaScript context. | |
| virtual ULDOMDocument | GetDOMDocument ()=0 |
| Get a ULDOM handle to the current page's document (main frame). | |
| virtual bool | AttachDOMTriggers (ULDOMTriggers triggers, unsigned flags=0, const char *const *origin_rules=nullptr, size_t num_origin_rules=0)=0 |
| Attach a set of DOM listeners to this View. | |
| virtual void | DetachDOMTriggers (ULDOMTriggers triggers)=0 |
| Detach a set of DOM listeners from this View. | |
| virtual void | SetDOMTriggersInjectionFilter (DOMTriggersInjectionFilter filter, void *user_data, void(*destroy_user_data)(void *))=0 |
| Set a filter that decides whether an attached set of DOM listeners is applied to a page. | |
| virtual bool | AttachDOMDataContext (ULDOMDataContext context, unsigned flags=0, const char *const *origin_rules=nullptr, size_t num_origin_rules=0)=0 |
| Attach a data-binding context to this View. | |
| virtual void | DetachDOMDataContext (ULDOMDataContext context)=0 |
| Detach a data-binding context from this View. | |
| virtual bool | AttachJSAPI (ULJSAPI api, unsigned flags=0, const char *const *origin_rules=nullptr, size_t num_origin_rules=0)=0 |
| Attach a JavaScript API to this View. | |
| virtual void | DetachJSAPI (ULJSAPI api)=0 |
| Detach a JavaScript API from this View. | |
| virtual void | SetJSAPIInjectionFilter (JSAPIInjectionFilter filter, void *user_data, void(*destroy_user_data)(void *))=0 |
| Set a filter that decides whether an attached API's bindings are added to a page. | |
| virtual bool | CanGoBack ()=0 |
| Whether or not the View can navigate back in history. | |
| virtual bool | CanGoForward ()=0 |
| Whether or not the View can navigate forward in history. | |
| virtual void | GoBack ()=0 |
| Navigate backwards in history. | |
| virtual void | GoForward ()=0 |
| Navigate forwards in history. | |
| virtual void | GoToHistoryOffset (int offset)=0 |
| Navigate to an arbitrary offset in history. | |
| virtual void | Reload ()=0 |
| Reload current page. | |
| virtual void | Stop ()=0 |
| Stop all page loads. | |
| virtual void | Focus ()=0 |
| Give focus to the View. | |
| virtual void | Unfocus ()=0 |
| Remove focus from the View. | |
| virtual bool | HasFocus ()=0 |
| Whether or not the View has focus. | |
| virtual bool | HasInputFocus ()=0 |
| Whether or not the View has an input element with visible keyboard focus (indicated by a blinking caret). | |
| virtual Editor * | editor ()=0 |
| Get the Editor for the View (executes editing commands against the focused frame). | |
| virtual void | FireKeyEvent (const KeyEvent &evt)=0 |
| Fire a keyboard event. | |
| virtual void | FireMouseEvent (const MouseEvent &evt)=0 |
| Fire a mouse event. | |
| virtual void | FireScrollEvent (const ScrollEvent &evt)=0 |
| Fire a scroll event. | |
| virtual void | set_view_listener (ViewListener *listener)=0 |
| Set a ViewListener to receive callbacks for View-related events. | |
| virtual ViewListener * | view_listener () const =0 |
| Get the active ViewListener (can be nullptr). | |
| virtual void | set_load_listener (LoadListener *listener)=0 |
| Set a LoadListener to receive callbacks for Load-related events. | |
| virtual LoadListener * | load_listener () const =0 |
| Get the active LoadListener (can be nullptr). | |
| virtual void | set_download_listener (DownloadListener *listener)=0 |
| Set a DownloadListener to receive callbacks for download-related events. | |
| virtual DownloadListener * | download_listener () const =0 |
| Get the active DownloadListener (can be nullptr). | |
| virtual void | CancelDownload (DownloadId id)=0 |
| Cancel an active download. | |
| virtual void | set_editor_listener (EditorListener *listener)=0 |
| Set an EditorListener to receive callbacks for editing-related events. | |
| virtual EditorListener * | editor_listener () const =0 |
| Get the active EditorListener (can be nullptr). | |
| virtual void | set_network_listener (NetworkListener *listener)=0 |
| Set a NetworkListener to receive callbacks for network-related events. | |
| virtual NetworkListener * | network_listener () const =0 |
| Get the active NetworkListener (can be nullptr). | |
| virtual void | set_needs_paint (bool needs_paint)=0 |
| Set whether or not this View should be repainted during the next call to Renderer::Render(). | |
| virtual bool | needs_paint () const =0 |
| Whether or not this View should be repainted during the next call to Renderer::Render(). | |
| virtual void | CreateLocalInspectorView ()=0 |
| Create an Inspector View to inspect / debug this View locally. | |
| virtual void | set_compositor_debug_info_enabled (bool enable)=0 |
| Set whether or not to display compositor debug information, specifically: | |
| virtual bool | compositor_debug_info_enabled () const =0 |
| Whether or not compositor debug information is enabled. | |
| virtual void | set_visible (bool visible)=0 |
| Set whether or not this View is visible. | |
| virtual bool | is_visible () const =0 |
| Whether or not this View is visible. | |
| virtual void | set_max_render_fps (uint32_t fps)=0 |
| Set the maximum rate, in frames per second, at which this View advances its animations and repaints. | |
| virtual uint32_t | max_render_fps () const =0 |
| Get the frame-rate cap set for this View, or 0 if none is set. | |
| virtual void | set_preferred_color_scheme (ColorScheme scheme)=0 |
| Set the color scheme this View reports to pages via the prefers-color-scheme CSS media feature. | |
| virtual ColorScheme | preferred_color_scheme () const =0 |
| The color scheme this View reports to pages. | |
| Public Member Functions inherited from RefCounted | |
| virtual void | AddRef () const =0 |
| Increment the reference count (thread-safe). | |
| virtual void | Release () const =0 |
| Decrement the reference count (thread-safe). | |
| virtual int | ref_count () const =0 |
| Get the current reference count. | |
| virtual WeakControlBlock * | weak_control_block () const |
| Get the control block used to track weak references to this object. | |
Protected Member Functions | |
| virtual | ~View () |
| Protected Member Functions inherited from RefCounted | |
| virtual | ~RefCounted () |
Callback that decides whether an attached set of DOM listeners is applied to a loading page.
This is called on the Renderer's thread after the origin rules have been evaluated. See SetDOMTriggersInjectionFilter() and <Ultralight/CAPI/CAPI_DOMTriggers.h>. Most C++ code uses dom::SetInjectionFilter() instead.
| user_data | The user data passed to SetDOMTriggersInjectionFilter(). |
| request | The set of DOM listeners, the page's origin, and the verdict of the origin rules (see ULDOMTriggersInjectionRequest). It's owned by the library and valid only during the callback. Its view member is NULL here (it's set only for a filter set with ulViewSetDOMTriggersInjectionFilter()). |
| using JSAPIInjectionFilter = bool (*)(void* user_data, const ULJSAPIInjectionRequest* request) |
Callback that decides whether an attached API's bindings are added to a loading page.
This is called on the Renderer's thread after the origin rules have been evaluated. See SetJSAPIInjectionFilter() and <Ultralight/CAPI/CAPI_JSAPI.h>. Most C++ code uses js::SetInjectionFilter() instead.
| user_data | The user data passed to SetJSAPIInjectionFilter(). |
| request | The API, the page's origin, and the verdict of the origin rules (see ULJSAPIInjectionRequest). It's owned by the library and valid only during the callback. Its view member is NULL here (it's set only for a filter set with ulViewSetJSAPIInjectionFilter()). |
|
protectedvirtual |
|
pure virtual |
Attach a data-binding context to this View.
Once attached, pages loaded into this View compile their binding markup against the context's published models and stay updated as the context publishes new data (see <Ultralight/dom/data/Context.h>).
One context may attach to any number of Views (one publish serves them all). The View keeps the context attached while an owning handle to it exists (see ulDestroyDOMDataContext()). Attaching an already-attached context updates its flags and origin rules.
| context | The context to attach. |
| flags | A logically ORed set of ULDOMDataContextAttachFlags (none are defined yet, so pass kULDOMDataContextAttachFlags_None). Unknown bits fail the attach. |
| origin_rules | An array of scheme://host[:port] origin patterns for the pages that compile the context's bindings, or nullptr for the default policy (local pages plus your application's own content). See ultralight::OriginRules for the rule syntax. |
| num_origin_rules | The number of entries in origin_rules. |
|
pure virtual |
Attach a set of DOM listeners to this View.
A set of DOM listeners (see <Ultralight/CAPI/CAPI_DOMTriggers.h>) holds event listeners matched by CSS selector and DOM-ready hooks. Once attached, the set is added to the current page (if its document has finished parsing) and to every page the View loads afterward, so you don't need to register again after a navigation. This works with or without JavaScript enabled. Most C++ code uses dom::Triggers::AttachTo() instead.
The View keeps the set attached while an owning handle to it exists (see ulDestroyDOMTriggers()). Attaching it again changes the flags and origin rules for later pages (a page that already has the listeners keeps them).
| triggers | The listeners to attach. |
| flags | A logically ORed set of ULDOMTriggersAttachFlags. Unknown bits fail the attach. |
| origin_rules | An array of scheme://host[:port] origin patterns for the pages that get the set, or nullptr for the default policy (local pages plus your application's own content). Rules replace the default. See ultralight::OriginRules for the rule syntax. |
| num_origin_rules | The number of entries in origin_rules. |
|
pure virtual |
Attach a JavaScript API to this View.
A ULJSAPI (see <Ultralight/CAPI/CAPI_JSAPI.h>) is a set of native bindings under a global namespace such as myApp.
Once attached, the bindings are added to the current page (if any) and to every page the View navigates to afterwards, so you don't need to register them again after a navigation:
The View keeps the API attached while an owning handle to it exists (see ulDestroyJSAPI()). Attaching it again updates its flags and origin rules.
| api | The API to attach. |
| flags | A logically ORed set of ULJSAPIAttachFlags. Unknown bits fail the attach. |
| origin_rules | An array of scheme://host[:port] origin patterns for the pages that get the bindings (eg, https://*.mygame.com), or nullptr for the default policy (local pages plus your application's own content, ie. pages loaded with LoadHTML()). See ultralight::OriginRules for the rule syntax. |
| num_origin_rules | The number of entries in origin_rules. |
|
pure virtual |
Cancel an active download.
No more data arrives for the download, and DownloadListener::OnFailDownload() is called for it during a later Renderer::Update().
| id | The id of the download to cancel (see DownloadListener). |
|
pure virtual |
Whether or not the View can navigate back in history.
|
pure virtual |
Whether or not the View can navigate forward in history.
|
pure virtual |
Whether or not compositor debug information is enabled.
|
pure virtual |
Create an Inspector View to inspect / debug this View locally.
This will only succeed if you have the inspector assets in your filesystem– the inspector will look for file:///inspector/Main.html when it first loads.
You must handle ViewListener::OnCreateInspectorView() so that the library has a View to display the inspector in. This function will call this event only if an inspector view is not currently active.
|
pure virtual |
Detach a data-binding context from this View.
Its pages stop receiving updates, and the page's binding markup recompiles against the remaining attached contexts.
| context | The context to detach. |
|
pure virtual |
Detach a set of DOM listeners from this View.
The listeners stop right away (they're removed from the current page), and no later page gets them.
| triggers | The listeners to detach. |
|
pure virtual |
|
pure virtual |
Get the device scale, ie.
the amount to scale page units to screen pixels.
For example, a value of 1.0 is equivalent to 100% zoom. A value of 2.0 is 200% zoom.
|
pure virtual |
Get the display id of the View.
|
pure virtual |
Get the active DownloadListener (can be nullptr).
|
pure virtual |
Get the Editor for the View (executes editing commands against the focused frame).
You can use this to drive text editing natively: caret motion, selection, deletion, clipboard operations, undo/redo, and typed text insertion (the commands a native Edit menu or keybinding table needs).
|
pure virtual |
Get the active EditorListener (can be nullptr).
|
pure virtual |
Evaluate a string of JavaScript and return the result as a String.
| script | The JavaScript to evaluate. |
| exception | Receives the exception message if the script throws, or an empty string if it doesn't. Pass a nullptr if you don't care about exceptions. |
| frame | The name of the frame to evaluate the script in. Pass an empty string (default) for the main frame, or the name attribute of one of the main frame's iframes. |
|
pure virtual |
Fire a keyboard event.
| evt | The key event. |
|
pure virtual |
Fire a mouse event.
| evt | The mouse event. |
|
pure virtual |
Fire a scroll event.
| evt | The scroll event. |
|
pure virtual |
|
pure virtual |
Get a ULDOM handle to the current page's document (main frame).
The document is available even when JavaScript is disabled (ViewConfig::enable_javascript is false). Most C++ code uses dom::Document instead (see <Ultralight/DOM.h>).
|
pure virtual |
Get a ULJS handle to the main frame's JavaScript context.
Unlike LockJSContext(), the returned handle never keeps the page alive. When the page navigates away or the View is destroyed, the handle stops working and operations on it fail safely. Use it with the functions in <Ultralight/CAPI/CAPI_JSValue.h>. Most C++ code uses js::Context instead (see <Ultralight/JS.h>), which wraps this handle.
|
pure virtual |
Navigate backwards in history.
|
pure virtual |
Navigate forwards in history.
|
pure virtual |
Navigate to an arbitrary offset in history.
| offset | The number of entries to move (negative goes back, positive goes forward). |
|
pure virtual |
Whether or not the View has focus.
|
pure virtual |
Whether or not the View has an input element with visible keyboard focus (indicated by a blinking caret).
You can use this to decide whether or not the View should consume keyboard input events (useful in games with mixed UI and key handling).
|
pure virtual |
Get the height of the View, in pixels.
|
pure virtual |
Whether or not the View is GPU-accelerated.
If this is false, the page will be rendered via the CPU renderer.
|
pure virtual |
Check if the main frame of the page is currently loading.
|
pure virtual |
Check if the page has settled after loading.
This is true once the page's network and layout activity have gone idle following the main frame's onload event. It is the latched, queryable form of the LoadListener::OnPageSettled() event, flipping true when that event fires and resetting to false on each new navigation.
|
pure virtual |
Whether or not the View supports transparent backgrounds.
|
pure virtual |
Whether or not this View is visible.
|
pure virtual |
Get a handle to the internal JavaScriptCore VM.
| frame | The name of the frame to access. Pass an empty string (default) for the main frame, or the name attribute of one of the main frame's iframes. |
|
pure virtual |
Get the active LoadListener (can be nullptr).
|
pure virtual |
Load a raw string of HTML, the View will navigate to it as a new page.
| html | The raw HTML string to load. |
| url | An optional URL for this load (to make it appear as if we loaded this HTML from a certain URL). Can be used for resolving relative URLs and cross-origin rules. |
| add_to_history | Whether or not this load should be added to the session's history (eg, the back/forward list). |
|
pure virtual |
Load a URL, the View will navigate to it as a new page.
| url | The URL to load. |
Acquire the page's JSContext for use with the JavaScriptCore API.
| frame | The name of the frame to access. Pass an empty string (default) for the main frame, or the name attribute of one of the main frame's iframes. |
|
pure virtual |
Get the frame-rate cap set for this View, or 0 if none is set.
|
pure virtual |
Whether or not this View should be repainted during the next call to Renderer::Render().
When this returns false, rendering would reproduce the previous frame, so you can skip rendering or presenting the View. This is always false while the View is hidden, and while max_render_fps() holds back its next frame.
When this returns true, the next call to Renderer::Render() repaints the View. The resulting frame may still be visually identical to the previous frame.
|
pure virtual |
Get the active NetworkListener (can be nullptr).
|
pure virtual |
The color scheme this View reports to pages.
|
pure virtual |
Reload current page.
|
pure virtual |
Get the RenderTarget for the View.
|
pure virtual |
Resize View to a certain size.
| width | The new width, in pixels. |
| height | The new height, in pixels. |
|
pure virtual |
Resize View to a certain size and apply a new device scale in the same pass.
Prefer this over separate set_device_scale() and Resize() calls when both change at once (for example, when a window moves to a display with a different DPI): applying them together resizes the page once instead of twice.
| width | The new width, in pixels. |
| height | The new height, in pixels. |
| device_scale | The new device scale (see set_device_scale()). |
|
pure virtual |
Set whether or not to display compositor debug information, specifically:
| enable | Whether or not to show the debug information. |
|
pure virtual |
Set the device scale.
| scale | The new device scale (see device_scale()). |
|
pure virtual |
Set the display id of the View.
You should call this when the View moves to another display.
| id | The id of the new display (see ViewConfig::display_id). |
|
pure virtual |
Set a DownloadListener to receive callbacks for download-related events.
| listener | A user-defined DownloadListener implementation, ownership remains with the caller. Pass a nullptr to remove the current listener. |
|
pure virtual |
Set an EditorListener to receive callbacks for editing-related events.
| listener | A user-defined EditorListener implementation, ownership remains with the caller. Pass a nullptr to remove the current listener. |
|
pure virtual |
Set a LoadListener to receive callbacks for Load-related events.
| listener | A user-defined LoadListener implementation, ownership remains with the caller. Pass a nullptr to remove the current listener. |
|
pure virtual |
Set the maximum rate, in frames per second, at which this View advances its animations and repaints.
| fps | The frame-rate cap, or 0 to remove it (the View then advances at the display's refresh rate). |
|
pure virtual |
Set whether or not this View should be repainted during the next call to Renderer::Render().
| needs_paint | Whether or not the View needs a repaint. |
|
pure virtual |
Set a NetworkListener to receive callbacks for network-related events.
| listener | A user-defined NetworkListener implementation, ownership remains with the caller. Pass a nullptr to remove the current listener. |
|
pure virtual |
Set the color scheme this View reports to pages via the prefers-color-scheme CSS media feature.
Overrides ViewConfig::preferred_color_scheme for this View. A change re-evaluates prefers-color-scheme media queries on the page, firing matchMedia change listeners and recalculating styles, the same as an OS theme change.
| scheme | The new scheme. Auto follows the system value set via Renderer::set_system_color_scheme(). |
|
pure virtual |
Set a ViewListener to receive callbacks for View-related events.
| listener | A user-defined ViewListener implementation, ownership remains with the caller. Pass a nullptr to remove the current listener. |
|
pure virtual |
Set whether or not this View is visible.
Hiding a View (passing false) stops it from being painted during Renderer::Render and pauses its rendering-driven work: requestAnimationFrame callbacks and CSS animations stop advancing while hidden, and the page's visibilitychange event fires with document.visibilityState set to "hidden".
Showing a View again (passing true) resumes its animations and forces a repaint on the next call to Renderer::Render.
| visible | Whether or not the View is visible. |
|
pure virtual |
Set a filter that decides whether an attached set of DOM listeners is applied to a page.
The filter is consulted after the origin rules, for every attached set and page.
| filter | The filter callback. Pass nullptr to remove the current filter. |
| user_data | User data passed through to the filter on every call. |
| destroy_user_data | Callback invoked exactly once to destroy user_data after the filter is replaced or the View is destroyed (may be nullptr). |
|
pure virtual |
Set a filter that decides whether an attached API's bindings are added to a page.
The filter is consulted after the origin rules, for every attached API and page.
| filter | The filter callback. Pass nullptr to remove the current filter. |
| user_data | User data passed through to the filter on every call. |
| destroy_user_data | Callback invoked exactly once to destroy user_data after the filter is replaced or the View is destroyed (may be nullptr). |
|
pure virtual |
Stop all page loads.
|
pure virtual |
Get the Surface for the View (native pixel buffer that the CPU renderer draws into).
|
pure virtual |
Get the title of the current page loaded into this View, if any.
|
pure virtual |
|
pure virtual |
Get the active ViewListener (can be nullptr).
|
pure virtual |
Get the width of the View, in pixels.