![]() |
Ultralight C++ API 1.4.0
|
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 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 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 RefPtr< JSContext > | LockJSContext ()=0 |
Acquire the page's JSContext for use with the JavaScriptCore API. | |
virtual void * | JavaScriptVM ()=0 |
Get a handle to the internal JavaScriptCore VM. | |
virtual String | EvaluateScript (const String &script, String *exception=nullptr)=0 |
Helper function to evaluate a raw string of JavaScript and return the result as a String. | |
virtual bool | CanGoBack ()=0 |
Whether or not we can navigate backwards in history. | |
virtual bool | CanGoForward ()=0 |
Whether or not we can navigate forwards 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 and unfocus any focused input elements. | |
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 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, if any. | |
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, if any. | |
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, if any. | |
virtual void | CancelDownload (DownloadId id)=0 |
Cancel an active download. | |
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, if any. | |
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 | AddRef () const =0 |
virtual void | Release () const =0 |
virtual int | ref_count () const =0 |
Protected Member Functions | |
virtual | ~View () |
![]() | |
virtual | ~RefCounted () |
|
protectedvirtual |
|
pure virtual |
Cancel an active download.
|
pure virtual |
Whether or not we can navigate backwards in history.
|
pure virtual |
Whether or not we can navigate forwards in history.
|
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 |
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, if any.
Helper function to evaluate a raw string of JavaScript and return the result as a String.
script | A string of JavaScript to evaluate in the main frame. |
exception | A string to store the exception in, if any. Pass a nullptr if you don't care about exceptions. |
|
pure virtual |
Fire a keyboard event.
|
pure virtual |
Fire a mouse event.
|
pure virtual |
Fire a scroll event.
|
pure virtual |
|
pure virtual |
Navigate backwards in history.
|
pure virtual |
Navigate forwards in history.
|
pure virtual |
Navigate to an arbitrary offset in history.
|
pure virtual |
Whether or not the View has focus.
|
pure virtual |
|
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 |
Whether or not the View supports transparent backgrounds.
|
pure virtual |
Get a handle to the internal JavaScriptCore VM.
|
pure virtual |
Get the active LoadListener, if any.
|
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 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.
Acquire the page's JSContext for use with the JavaScriptCore API.
|
pure virtual |
Whether or not this View should be repainted during the next call to Renderer::Render.
|
pure virtual |
Get the active NetworkListener, if any.
|
pure virtual |
Reload current page.
|
pure virtual |
Get the RenderTarget for the View.
|
pure virtual |
Resize View to a certain size.
width | The initial width, in pixels. |
height | The initial height, in pixels. |
|
pure virtual |
Set the device scale.
|
pure virtual |
|
pure virtual |
Set a DownloadListener to receive callbacks for download-related events.
|
pure virtual |
Set a LoadListener to receive callbacks for Load-related events.
|
pure virtual |
Set whether or not this View should be repainted during the next call to Renderer::Render.
|
pure virtual |
Set a NetworkListener to receive callbacks for network-related events.
|
pure virtual |
Set a ViewListener to receive callbacks for View-related events.
|
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, if any.
|
pure virtual |
Get the width of the View, in pixels.