|
Ultralight C++ API 2.0.0
|
Conversion functions and type traits connecting the DOM and JavaScript APIs.
#include <Ultralight/dom/JSInterop.h>
This header connects the DOM and JavaScript APIs so you can pass DOM elements between C++ and page script.
Convert elements between C++ and page script using the document's context:
Including this header specializes js::TypeTraits for dom::Element, letting bound functions accept and return elements directly. Passing null or undefined from JavaScript to a dom::Element parameter fails with a TypeError, so declare std::optional<dom::Element> to accept them.
Bind functions that take an element and an optional element:
An element converts to JavaScript only with the context of its own frame. Converting an element with a context from another frame or View returns an empty js::Value.
How you retrieve a context depends on the document's frame:
Classes | |
| struct | TypeTraits< dom::Element > |
| dom::Element as its JavaScript object. More... | |
Functions | |
| js::Value | ToJS (const js::Context &context, const Element &element) |
| Get an element's JavaScript object (the same object the page's scripts see for it). | |
| Element | FromJS (const js::Value &value) |
| Get the element a JavaScript value refers to (the inverse of ToJS()). | |
| js::Context | GetJSContext (const Document &document) |
| Get the JavaScript context of a document (the context its page's scripts run in). | |
Namespaces | |
| namespace | ultralight |
| Root namespace for every public Ultralight type, function, and enumeration. | |
| namespace | ultralight::dom |
| Direct C++ access to modify page elements and handle events. | |
| namespace | ultralight::js |
| Type-checked JavaScript bridge between C++ and web pages. | |