docs
Loading...
Searching...
No Matches
View.h
Go to the documentation of this file.
1///
2/// Copyright (C) 2026 Ultralight, Inc. All rights reserved.
3/// A license is required for commercial use. https://ultralig.ht
4///
5#pragma once
7#include <Ultralight/RefPtr.h>
8#include <Ultralight/Color.h>
9#include <Ultralight/Editor.h>
10#include <Ultralight/KeyEvent.h>
16#include <Ultralight/Bitmap.h>
17#include <Ultralight/Listener.h>
19
20///
21/// Opaque handle to a JavaScript execution context (one page's script world in one View).
22///
23/// Declared in full in `<Ultralight/CAPI/CAPI_JSValue.h>`.
24///
25typedef struct C_JSContext* ULJSContext;
26
27///
28/// Opaque handle to a set of native JavaScript bindings.
29///
30/// Declared in full in `<Ultralight/CAPI/CAPI_JSAPI.h>`.
31///
32typedef struct C_JSAPI* ULJSAPI;
33
34///
35/// Opaque handle to a page's DOM document.
36///
37/// Declared in full in `<Ultralight/CAPI/CAPI_DOMDocument.h>`.
38///
39typedef struct C_DOMDocument* ULDOMDocument;
40
41///
42/// Opaque handle to a set of DOM event listeners and DOM-ready hooks.
43///
44/// Declared in full in `<Ultralight/CAPI/CAPI_DOMTriggers.h>`.
45///
46typedef struct C_DOMTriggers* ULDOMTriggers;
47
48///
49/// Opaque handle to a data-binding context.
50///
51/// Declared in full in `<Ultralight/CAPI/CAPI_DOMData.h>`.
52///
53typedef struct C_DOMDataContext* ULDOMDataContext;
54
55///
56/// The details an API injection filter decides on.
57///
58/// Declared in full in `<Ultralight/CAPI/CAPI_JSAPI.h>`.
59///
61
62///
63/// The details a DOM triggers injection filter decides on.
64///
65/// Declared in full in `<Ultralight/CAPI/CAPI_DOMTriggers.h>`.
66///
68
69namespace ultralight {
70
71///
72/// A page color scheme, as reported to pages via the `prefers-color-scheme` CSS media feature.
73///
74/// @see ViewConfig::preferred_color_scheme
75/// @see View::set_preferred_color_scheme()
76/// @see Renderer::set_system_color_scheme()
77///
78enum class ColorScheme : uint8_t {
79 Auto = 0, ///< Follow the system color scheme set on the Renderer.
80 Light = 1, ///< Always report a light color scheme.
81 Dark = 2, ///< Always report a dark color scheme.
82};
83
84///
85/// Which pages may read the clipboard from script.
86///
87/// @see ViewConfig::clipboard_read_policy
88///
89enum class ClipboardReadPolicy : uint8_t {
90 Deny = 0, ///< Refuse every script-initiated clipboard read.
91 AllowForAppContent = 1, ///< Grant reads from your application's own content only.
92 Allow = 2, ///< Grant reads from any page.
93};
94
95///
96/// View-specific configuration settings.
97///
98/// @see Renderer::CreateView()
99///
101
102 ///
103 /// A user-generated id for the display (monitor, TV, or screen) that this View will be shown on.
104 ///
105 /// Animations are driven based on the physical refresh rate of the display. Multiple Views can
106 /// share the same display.
107 ///
108 /// @note This is automatically managed for you when App::Create() is used and the View is
109 /// hosted in a Window. A View you create yourself in an App should use the id of the
110 /// Monitor it is shown on (Monitor::display_id()).
111 ///
112 /// @see Renderer::RefreshDisplay(), Renderer::SetDisplayRefreshRate()
113 ///
114 uint32_t display_id = 0;
115
116 ///
117 /// Whether to render using the GPU renderer (accelerated) or the CPU renderer (unaccelerated).
118 ///
119 /// When true, the View renders to an offscreen GPU texture using the GPU driver set with
120 /// Platform::set_gpu_driver(). You can get the texture's details with View::render_target().
121 ///
122 /// When false (the default), the View renders to an offscreen pixel buffer using the
123 /// multithreaded CPU renderer. You can provide this pixel buffer yourself-- see
124 /// Platform::set_surface_factory() and View::surface().
125 ///
126 /// \parblock
127 /// @note You must set a GPU driver before creating an accelerated View (the process exits
128 /// with an error otherwise).
129 /// \endparblock
130 ///
131 /// \parblock
132 /// @note This is automatically managed for you when App::Create() is used.
133 /// \endparblock
134 ///
135 bool is_accelerated = false;
136
137 ///
138 /// The initial device scale, ie. the amount to scale page units to screen pixels. This should
139 /// be set to the scaling factor of the device that the View is displayed on.
140 ///
141 /// \parblock
142 /// @note 1.0 is equal to 100% zoom (no scaling), 2.0 is equal to 200% zoom (2x scaling).
143 /// \endparblock
144 ///
145 /// \parblock
146 /// @note This is automatically managed for you when App::Create() is used.
147 /// \endparblock
148 ///
150
151 ///
152 /// Whether or not this View should support transparency.
153 ///
154 /// The page needs a transparent background too:
155 ///
156 /// ```
157 /// html, body { background: transparent; }
158 /// ```
159 ///
160 bool is_transparent = false;
161
162 ///
163 /// The base color the page renders on before any page styling applies.
164 ///
165 /// This is the color visible while a page loads and wherever the page itself paints nothing. Dark
166 /// applications should set a dark base so pages never flash white during load. An unset color
167 /// (the default) means opaque white.
168 ///
169 /// @note `is_transparent` takes precedence. A transparent View keeps a fully transparent base.
170 /// On an opaque View a translucent color is composited over white, so the View itself
171 /// stays opaque.
172 ///
174
175 ///
176 /// The color scheme this View reports to pages via the `prefers-color-scheme` CSS media feature.
177 ///
178 /// Auto (the default) follows the system scheme set via Renderer::set_system_color_scheme(),
179 /// which is Light until you (or App) set a different one. Light or Dark pins the scheme
180 /// for this View regardless of the system value.
181 ///
182 /// \parblock
183 /// @note The scheme is a signal to the page, which styles itself via media queries. Built-in UI
184 /// (form controls, scrollbars, the default white canvas) keeps its light appearance under
185 /// a dark scheme.
186 /// \endparblock
187 ///
188 /// \parblock
189 /// @note This is automatically managed for you when App::Create() is used (the OS setting
190 /// is fed to the Renderer and tracked as it changes).
191 /// \endparblock
192 ///
193 /// @see View::set_preferred_color_scheme()
194 ///
196
197 ///
198 /// Whether or not the View should initially have input focus.
199 ///
200 /// @see View::Focus()
201 ///
202 bool initial_focus = true;
203
204 ///
205 /// Whether or not images should be enabled.
206 ///
207 bool enable_images = true;
208
209 ///
210 /// Whether or not JavaScript should be enabled.
211 ///
212 bool enable_javascript = true;
213
214 ///
215 /// Whether or not compositing should be enabled.
216 ///
217 /// When enabled, certain content (eg, 3D transforms, `will-change`, animated transforms or
218 /// opacity, and video) paints into separate composited layers, making transform and opacity
219 /// changes cheap to animate.
220 ///
221 bool enable_compositor = true;
222
223 ///
224 /// Whether or not to enable extra compositor debug information, specifically:
225 /// - Visualize compositor layers and tile boundaries
226 /// - Display repaint counters for each layer
227 ///
228 /// @note Only valid when the compositor is enabled.
229 ///
231
232 ///
233 /// Whether or not the HTML5 Canvas Filters API (`CanvasRenderingContext2D.filter`) is enabled.
234 ///
235 /// @note Reference filters (`url(#x)`) render unfiltered. The filter string is still readable
236 /// for feature detection.
237 ///
239
240 ///
241 /// Whether or not text editing should follow the host OS's native conventions instead of
242 /// the library's cross-platform behavior.
243 ///
244 /// When false (the default), text selection and editing behave identically on every
245 /// platform (a directionless selection is promoted to forward, the convention Windows
246 /// browsers use). Set this to true for desktop applications that should feel native to
247 /// each platform (eg, non-directional selections and Mac-style shift-click extension on
248 /// macOS).
249 ///
250 /// @note App turns this on for the Views it creates for a bare AddPanel() (see
251 /// Settings::match_native_editing_behavior). A ViewConfig you pass yourself keeps
252 /// this value.
253 ///
255
256 ///
257 /// Policy governing script-initiated clipboard reads (eg, a page's own Paste button calling
258 /// `document.execCommand('paste')`).
259 ///
260 /// AllowForAppContent (the default) grants requests from your application's own content (local
261 /// `file:///` pages and pages loaded from application-supplied data, eg, View::LoadHTML()) and
262 /// refuses them from other pages. Allow grants requests from any page. Deny refuses them all.
263 ///
264 /// \parblock
265 /// @note The library only considers requests made during a user gesture such as a click or key
266 /// press. Script running outside a gesture is always refused.
267 /// \endparblock
268 ///
269 /// \parblock
270 /// @note Pastes the user performs directly (Ctrl+V, or Editor::Execute() with
271 /// EditorCommand::Paste) are never affected by this policy.
272 /// \endparblock
273 ///
275
276 ///
277 /// Whether to throttle JavaScript timers (setTimeout / setInterval) while this View is hidden.
278 ///
279 /// When false (the default), timers keep running at their normal rate while the View is hidden,
280 /// so background logic continues to tick.
281 ///
282 /// When true, repeating timers in a hidden View are aligned to roughly one-second boundaries (so
283 /// a fast interval effectively drops to about 1 Hz), reducing CPU usage for off-screen Views.
284 /// Timers return to their normal rate once the View is shown again.
285 ///
286 /// @note This does not affect requestAnimationFrame, which is always suspended while a View is
287 /// hidden regardless of this setting.
288 ///
289 /// @see View::set_visible()
290 ///
292
293 ///
294 /// The maximum rate, in frames per second, at which this View advances its animations and
295 /// repaints.
296 ///
297 /// This caps the View's whole frame loop: requestAnimationFrame callbacks, CSS and Web
298 /// animations, smooth scrolling, and painting all advance at no more than this rate. Use it to
299 /// spend less CPU and GPU on a View that is on-screen but not the focus of attention (a secondary
300 /// panel, a minimap, a paused menu behind a modal).
301 ///
302 /// A value of 0 (the default) leaves the View unthrottled, advancing at the display's refresh
303 /// rate, the same as a normal browser tab.
304 ///
305 /// \parblock
306 /// @note Page content changes (from script, the DOM API, or data bindings) also wait for the
307 /// next capped frame. Input events, a resize, and showing the View paint right away.
308 /// \endparblock
309 ///
310 /// \parblock
311 /// @note This is independent of View::set_visible() and enable_hidden_timer_throttling. Hiding a
312 /// View stops it entirely. This setting slows a View that remains visible.
313 /// \endparblock
314 ///
315 /// \parblock
316 /// @note The View is always capped at your edition's maximum frame rate.
317 /// \endparblock
318 ///
319 uint32_t max_render_fps = 0;
320
321 ///
322 /// Whether or not a script can open a window with `window.open()` without a user gesture.
323 ///
324 /// When false (the default), Ultralight behaves like a typical browser: a `window.open()` call
325 /// succeeds only while the page is handling a user gesture, such as from a click handler. A call
326 /// made on its own (on page load, or from a timer) is blocked as a popup. Set this to true to
327 /// let scripts call `window.open()` at any time. The same gesture rule applies to a form
328 /// submission that targets a new window.
329 ///
330 /// @note Even when this is allowed, a window is only created if your
331 /// ViewListener::OnCreateChildView() handler returns one; return nullptr there to block
332 /// it.
333 ///
335
336 ///
337 /// Whether or not pages loaded from `file:///` URLs can access content from any origin.
338 ///
339 /// When true (the default), a `file:///` page can read other frames' documents and make
340 /// requests to any origin without cross-origin checks. Set this to false to give `file:///`
341 /// pages the same cross-origin rules as web pages (they stay same-origin with other
342 /// `file:///` pages).
343 ///
345
346 ///
347 /// The default font family (used for text that doesn't set one).
348 ///
349 /// @note App replaces these font_family_* defaults with ones that match the host OS for the
350 /// Views it creates for a bare AddPanel() (see Settings::auto_font_families).
351 ///
352 String font_family_standard = "Times New Roman";
353
354 ///
355 /// The default monospace font family (eg, for `pre` and `code`).
356 ///
357 String font_family_fixed = "Courier New";
358
359 ///
360 /// The default font family for the CSS `serif` generic.
361 ///
362 String font_family_serif = "Times New Roman";
363
364 ///
365 /// The default font family for the CSS `sans-serif` generic.
366 ///
368
369 ///
370 /// The default font family for the CSS `cursive` generic.
371 ///
372 String font_family_cursive = "Comic Sans MS";
373
374 ///
375 /// The default font family for the CSS `fantasy` generic.
376 ///
378
379 ///
380 /// The default font family for the CSS `-webkit-pictograph` generic. Leave it empty to use
381 /// font_family_standard.
382 ///
384
385 ///
386 /// The default font size, in pixels.
387 ///
388 uint32_t font_size_default = 16;
389
390 ///
391 /// The default font size for monospace text (eg, `pre` and `code`), in pixels.
392 ///
393 uint32_t font_size_fixed = 13;
394
395 ///
396 /// Custom user-agent string. You can use this to override the default user-agent string.
397 ///
398 /// @pre Not available in the Free edition (the default user-agent string is always used).
399 ///
401};
402
403///
404/// Web-page container rendered to an offscreen surface.
405///
406/// The View class is responsible for loading and rendering web-pages to an offscreen surface. It
407/// is completely isolated from the OS windowing system, you must forward all input events to it
408/// from your application.
409///
410/// ## Creating a View
411///
412/// You can create a View using Renderer::CreateView():
413///
414/// ```
415/// // Create a ViewConfig with the desired settings
416/// ViewConfig view_config;
417///
418/// // Create a View, 500 by 500 pixels in size, using the default Session
419/// RefPtr<View> view = renderer->CreateView(500, 500, view_config, nullptr);
420/// ```
421///
422/// @note When using App::Create(), the library creates a View for you when you add a panel to
423/// a window (see `<AppCore/Layout.h>`).
424///
425/// ## Loading Content into a View
426///
427/// You can load content asynchronously into a View using View::LoadURL().
428///
429/// ```
430/// // Load a URL into the View
431/// view->LoadURL("https://en.wikipedia.org/wiki/Main_Page");
432/// ```
433///
434/// ### Local File URLs
435///
436/// Local file URLs (eg, `file:///page.html`) will be loaded via FileSystem. You can provide your
437/// own FileSystem implementation so these files can be loaded from your application's resources.
438///
439/// ### Displaying Views in Your Application
440///
441/// Views are rendered either to a pixel-buffer (View::surface()) or a GPU texture
442/// (View::render_target()) depending on whether CPU or GPU rendering is used (see
443/// ViewConfig::is_accelerated).
444///
445/// You can use the Surface or RenderTarget to display the View in your application.
446///
447/// ```
448/// // Get the Surface for the View (assuming CPU rendering)
449/// Surface* surface = view->surface();
450///
451/// // Check if the Surface is dirty (pixels have changed)
452/// if (!surface->dirty_bounds().IsEmpty()) {
453/// // Cast to the default Surface implementation (BitmapSurface) and get
454/// // the underlying Bitmap.
455/// RefPtr<Bitmap> bitmap = static_cast<BitmapSurface*>(surface)->bitmap();
456///
457/// // Use the bitmap pixels here...
458///
459/// // Clear the dirty bounds after you're done displaying the pixels
460/// surface->ClearDirtyBounds();
461/// }
462/// ```
463///
464/// ## Input Events
465///
466/// You must forward all input events to the View from your application. This includes keyboard,
467/// mouse, and scroll events.
468///
469/// ```
470/// // Forward a mouse-move event to the View
471/// MouseEvent evt;
472/// evt.type = MouseEvent::kType_MouseMoved;
473/// evt.x = 100;
474/// evt.y = 100;
475/// evt.button = MouseEvent::kButton_None;
476/// view->FireMouseEvent(evt);
477/// ```
478///
479/// @note The View API is not thread-safe, all calls must be made on the same thread that the
480/// Renderer or App was created on (AttachDOMDataContext() and DetachDOMDataContext() are
481/// the exceptions).
482///
483class UExport View : public RefCounted {
484 public:
485 ///
486 /// Get the URL of the current page loaded into this View, if any.
487 ///
488 virtual String url() = 0;
489
490 ///
491 /// Get the title of the current page loaded into this View, if any.
492 ///
493 virtual String title() = 0;
494
495 ///
496 /// Get the width of the View, in pixels.
497 ///
498 virtual uint32_t width() const = 0;
499
500 ///
501 /// Get the height of the View, in pixels.
502 ///
503 virtual uint32_t height() const = 0;
504
505 ///
506 /// Get the display id of the View.
507 ///
508 /// @see ViewConfig::display_id, Renderer::RefreshDisplay()
509 ///
510 virtual uint32_t display_id() const = 0;
511
512 ///
513 /// Set the display id of the View.
514 ///
515 /// You should call this when the View moves to another display.
516 ///
517 /// @param id The id of the new display (see ViewConfig::display_id).
518 ///
519 /// @note This is automatically managed for you for Views hosted in an AppCore Window.
520 ///
521 virtual void set_display_id(uint32_t id) = 0;
522
523 ///
524 /// Get the device scale, ie. the amount to scale page units to screen pixels.
525 ///
526 /// For example, a value of 1.0 is equivalent to 100% zoom. A value of 2.0 is 200% zoom.
527 ///
528 virtual double device_scale() const = 0;
529
530 ///
531 /// Set the device scale.
532 ///
533 /// @param scale The new device scale (see device_scale()).
534 ///
535 /// @note To change the View's size at the same time, use Resize(width, height, device_scale)
536 /// instead, which applies both in one pass.
537 ///
538 virtual void set_device_scale(double scale) = 0;
539
540 ///
541 /// Whether or not the View is GPU-accelerated. If this is false, the page will be rendered
542 /// via the CPU renderer.
543 ///
544 virtual bool is_accelerated() const = 0;
545
546 ///
547 /// Whether or not the View supports transparent backgrounds.
548 ///
549 virtual bool is_transparent() const = 0;
550
551 ///
552 /// Check if the main frame of the page is currently loading.
553 ///
554 virtual bool is_loading() = 0;
555
556 ///
557 /// Check if the page has settled after loading.
558 ///
559 /// This is true once the page's network and layout activity have gone idle following the main
560 /// frame's onload event. It is the latched, queryable form of the LoadListener::OnPageSettled()
561 /// event, flipping true when that event fires and resetting to false on each new navigation.
562 ///
563 /// @note Settling covers network and layout activity only. See LoadListener::OnPageSettled() for
564 /// what settling does not promise and for the run-loop calls the library needs in order to
565 /// observe it.
566 ///
567 virtual bool is_settled() = 0;
568
569 ///
570 /// Get the RenderTarget for the View.
571 ///
572 /// @pre Only valid if this View is using the GPU renderer (see ViewConfig::is_accelerated).
573 ///
574 /// @note You can use this with your GPUDriver implementation to bind and display the
575 /// corresponding texture in your application.
576 ///
578
579 ///
580 /// Get the Surface for the View (native pixel buffer that the CPU renderer draws into).
581 ///
582 /// @pre Only valid if the View uses the CPU renderer (see ViewConfig::is_accelerated). This
583 /// returns nullptr if the View uses the GPU renderer.
584 ///
585 /// @note The default Surface is BitmapSurface, but you can provide your own Surface
586 /// implementation with Platform::set_surface_factory().
587 ///
588 virtual Surface* surface() = 0;
589
590 ///
591 /// Load a raw string of HTML, the View will navigate to it as a new page.
592 ///
593 /// @param html The raw HTML string to load.
594 ///
595 /// @param url An optional URL for this load (to make it appear as if we loaded this HTML
596 /// from a certain URL). Can be used for resolving relative URLs and cross-origin
597 /// rules.
598 ///
599 /// @param add_to_history Whether or not this load should be added to the session's history
600 /// (eg, the back/forward list).
601 ///
602 virtual void LoadHTML(const String& html, const String& url = "", bool add_to_history = false)
603 = 0;
604
605 ///
606 /// Load a URL, the View will navigate to it as a new page.
607 ///
608 /// @param url The URL to load.
609 ///
610 /// @note You can use file URLs (eg, `file:///page.html`), but you must provide your own
611 /// FileSystem if you aren't using AppCore.
612 ///
613 /// @see Platform::set_file_system()
614 ///
615 virtual void LoadURL(const String& url) = 0;
616
617 ///
618 /// Resize View to a certain size.
619 ///
620 /// @param width The new width, in pixels.
621 ///
622 /// @param height The new height, in pixels.
623 ///
624 virtual void Resize(uint32_t width, uint32_t height) = 0;
625
626 ///
627 /// Resize View to a certain size and apply a new device scale in the same pass.
628 ///
629 /// Prefer this over separate set_device_scale() and Resize() calls when both change at
630 /// once (for example, when a window moves to a display with a different DPI): applying
631 /// them together resizes the page once instead of twice.
632 ///
633 /// @param width The new width, in pixels.
634 ///
635 /// @param height The new height, in pixels.
636 ///
637 /// @param device_scale The new device scale (see set_device_scale()).
638 ///
639 virtual void Resize(uint32_t width, uint32_t height, double device_scale) = 0;
640
641 ///
642 /// Acquire the page's JSContext for use with the JavaScriptCore API.
643 ///
644 /// @param frame The name of the frame to access. Pass an empty string (default) for the main
645 /// frame, or the name attribute of one of the main frame's iframes.
646 ///
647 /// @return Returns a RefPtr to the JSContext for the frame, or nullptr if the frame doesn't
648 /// exist or can't run scripts (eg, when ViewConfig::enable_javascript is false).
649 ///
650 /// \parblock
651 /// @note You can use the underlying JSContextRef with the JavaScriptCore C API to marshal
652 /// C/C++ objects to and from JavaScript, bind callbacks, and call JS functions directly.
653 /// \endparblock
654 ///
655 /// \parblock
656 /// @note The JSContextRef is reset on each page navigation. You should set up your
657 /// JavaScript state in LoadListener::OnWindowObjectReady() or
658 /// LoadListener::OnDOMReady().
659 /// \endparblock
660 ///
661 /// \parblock
662 /// @note This locks the JavaScript VM for the current thread until the returned JSContext's
663 /// ref-count drops to zero. The lock is recursive, so you can call this more than once.
664 /// \endparblock
665 ///
666 virtual RefPtr<JSContext> LockJSContext(const String& frame = "") = 0;
667
668 ///
669 /// Get a handle to the internal JavaScriptCore VM.
670 ///
671 /// @param frame The name of the frame to access. Pass an empty string (default) for the main
672 /// frame, or the name attribute of one of the main frame's iframes.
673 ///
674 /// @return Returns a pointer to the VM, or nullptr if the frame doesn't exist or can't run
675 /// scripts. Every frame and View shares one VM.
676 ///
677 virtual void* JavaScriptVM(const String& frame = "") = 0;
678
679 ///
680 /// Evaluate a string of JavaScript and return the result as a String.
681 ///
682 /// @param script The JavaScript to evaluate.
683 ///
684 /// @param exception Receives the exception message if the script throws, or an empty string
685 /// if it doesn't. Pass a nullptr if you don't care about exceptions.
686 ///
687 /// @param frame The name of the frame to evaluate the script in. Pass an empty string
688 /// (default) for the main frame, or the name attribute of one of the main
689 /// frame's iframes.
690 ///
691 /// @return Returns the result converted to a String (eg, `undefined` becomes "undefined"), or
692 /// an empty string if the frame doesn't exist or can't run scripts.
693 ///
694 /// \parblock
695 /// @note You don't need to lock the JS context, this does it for you.
696 /// \endparblock
697 ///
698 /// \parblock
699 /// @note For typed access to the result, use the ultralight::js layer instead: acquire the
700 /// page's context with js::Context (see `<Ultralight/JS.h>`) and call
701 /// Context::Evaluate(), which returns a js::Result holding the completion value or
702 /// the script's exception rather than a flattened string.
703 /// \endparblock
704 ///
705 /// \parblock
706 /// @note For raw JavaScriptCore access, lock the JS context and call JSEvaluateScript() in
707 /// the JavaScriptCore C API.
708 /// \endparblock
709 ///
710 /// @see <JavaScriptCore/JSBase.h>
711 ///
712 virtual String EvaluateScript(const String& script, String* exception = nullptr, const String& frame = "") = 0;
713
714 ///
715 /// Get a ULJS handle to the main frame's JavaScript context.
716 ///
717 /// Unlike LockJSContext(), the returned handle never keeps the page alive. When the page
718 /// navigates away or the View is destroyed, the handle stops working and operations on it fail
719 /// safely. Use it with the functions in `<Ultralight/CAPI/CAPI_JSValue.h>`. Most C++ code uses
720 /// js::Context instead (see `<Ultralight/JS.h>`), which wraps this handle.
721 ///
722 /// @return Returns a new ULJSContext handle for the current page, or NULL if the main frame
723 /// can't run scripts (eg, when ViewConfig::enable_javascript is false, or the document
724 /// is sandboxed against scripts). You must call ulDestroyJSContext() when finished.
725 ///
726 /// @note Each page gets a fresh context. After a navigation, call this again to obtain a
727 /// handle to the new page's context. LoadListener::OnWindowObjectReady() and
728 /// LoadListener::OnDOMReady() are good acquisition points.
729 ///
731
732 ///
733 /// Get a ULDOM handle to the current page's document (main frame).
734 ///
735 /// The document is available even when JavaScript is disabled (ViewConfig::enable_javascript is
736 /// false). Most C++ code uses dom::Document instead (see `<Ultralight/DOM.h>`).
737 ///
738 /// @return Returns the document (NULL if the main frame has none). You must call
739 /// ulDestroyDOMDocument() when finished.
740 ///
741 /// @note The handle stops working when the page goes away, so get it again for each page (eg, in
742 /// LoadListener::OnDOMReady()). Before your page loads, and while a new page is loading,
743 /// this returns the previous document.
744 ///
746
747 ///
748 /// Callback that decides whether an attached set of DOM listeners is applied to a loading
749 /// page.
750 ///
751 /// This is called on the Renderer's thread after the origin rules have been evaluated. See
752 /// SetDOMTriggersInjectionFilter() and `<Ultralight/CAPI/CAPI_DOMTriggers.h>`. Most C++ code
753 /// uses dom::SetInjectionFilter() instead.
754 ///
755 /// @param user_data The user data passed to SetDOMTriggersInjectionFilter().
756 ///
757 /// @param request The set of DOM listeners, the page's origin, and the verdict of the
758 /// origin rules (see ULDOMTriggersInjectionRequest). It's owned by the
759 /// library and valid only during the callback. Its `view` member is NULL
760 /// here (it's set only for a filter set with
761 /// ulViewSetDOMTriggersInjectionFilter()).
762 ///
763 /// @return Return true to apply the listeners to this page, or false to skip it. The return
764 /// value is final: it can override the origin rules either way.
765 ///
766 using DOMTriggersInjectionFilter = bool (*)(void* user_data,
767 const ULDOMTriggersInjectionRequest* request);
768
769 ///
770 /// Attach a set of DOM listeners to this View.
771 ///
772 /// A set of DOM listeners (see `<Ultralight/CAPI/CAPI_DOMTriggers.h>`) holds event listeners
773 /// matched by CSS selector and DOM-ready hooks. Once attached, the set is added to the current
774 /// page (if its document has finished parsing) and to every page the View loads afterward, so
775 /// you don't need to register again after a navigation. This works with or without JavaScript
776 /// enabled. Most C++ code uses dom::Triggers::AttachTo() instead.
777 ///
778 /// ```
779 /// ULDOMTriggers triggers = ulCreateDOMTriggers();
780 /// ulDOMTriggersOn(triggers, "#save", "click", kULDOMEventFlags_None, OnSave, ctx, nullptr);
781 /// view->AttachDOMTriggers(triggers);
782 /// // #save is clickable on this page and on every page the View navigates to.
783 /// ```
784 ///
785 /// The View keeps the set attached while an owning handle to it exists (see
786 /// ulDestroyDOMTriggers()). Attaching it again changes the flags and origin rules for later
787 /// pages (a page that already has the listeners keeps them).
788 ///
789 /// @param triggers The listeners to attach.
790 ///
791 /// @param flags A logically ORed set of ULDOMTriggersAttachFlags. Unknown bits
792 /// fail the attach.
793 ///
794 /// @param origin_rules An array of `scheme://host[:port]` origin patterns for the pages
795 /// that get the set, or nullptr for the default policy (local pages
796 /// plus your application's own content). Rules replace the default.
797 /// See ultralight::OriginRules for the rule syntax.
798 ///
799 /// @param num_origin_rules The number of entries in `origin_rules`.
800 ///
801 /// @return Returns true on success, or false if `triggers` is NULL, a flag is unknown, or a
802 /// rule failed to parse (nothing changes then, and a logged warning says why).
803 ///
804 /// \parblock
805 /// @note The origin policy is shared with AttachJSAPI(): same rule syntax, same default,
806 /// evaluated against the page's security origin.
807 /// \endparblock
808 ///
809 /// \parblock
810 /// @note Without kULDOMTriggersAttachFlags_AllFrames, only the main frame gets the set.
811 /// \endparblock
812 ///
813 /// \parblock
814 /// @note A page restored from the back-forward cache (Config::page_cache_size > 0) gets the
815 /// listeners again before its `pageshow` event. Its DOM-ready hooks don't run again, so
816 /// register a restore hook with ulDOMTriggersOnRestore() for work you need on every
817 /// restore.
818 /// \endparblock
819 ///
820 virtual bool AttachDOMTriggers(ULDOMTriggers triggers, unsigned flags = 0,
821 const char* const* origin_rules = nullptr,
822 size_t num_origin_rules = 0) = 0;
823
824 ///
825 /// Detach a set of DOM listeners from this View.
826 ///
827 /// The listeners stop right away (they're removed from the current page), and no later page
828 /// gets them.
829 ///
830 /// @param triggers The listeners to detach.
831 ///
832 virtual void DetachDOMTriggers(ULDOMTriggers triggers) = 0;
833
834 ///
835 /// Set a filter that decides whether an attached set of DOM listeners is applied to a page.
836 ///
837 /// The filter is consulted after the origin rules, for every attached set and page.
838 ///
839 /// @param filter The filter callback. Pass nullptr to remove the current filter.
840 ///
841 /// @param user_data User data passed through to the filter on every call.
842 ///
843 /// @param destroy_user_data Callback invoked exactly once to destroy `user_data` after the
844 /// filter is replaced or the View is destroyed (may be nullptr).
845 ///
846 /// @see dom::SetInjectionFilter()
847 ///
849 void* user_data,
850 void (*destroy_user_data)(void*)) = 0;
851
852 ///
853 /// Attach a data-binding context to this View.
854 ///
855 /// Once attached, pages loaded into this View compile their binding markup against the
856 /// context's published models and stay updated as the context publishes new data (see
857 /// `<Ultralight/dom/data/Context.h>`).
858 ///
859 /// One context may attach to any number of View%s (one publish serves them all). The View
860 /// keeps the context attached while an owning handle to it exists (see
861 /// ulDestroyDOMDataContext()). Attaching an already-attached context updates its flags and
862 /// origin rules.
863 ///
864 /// @param context The context to attach.
865 ///
866 /// @param flags A logically ORed set of ULDOMDataContextAttachFlags (none are
867 /// defined yet, so pass kULDOMDataContextAttachFlags_None). Unknown
868 /// bits fail the attach.
869 ///
870 /// @param origin_rules An array of `scheme://host[:port]` origin patterns for the pages
871 /// that compile the context's bindings, or nullptr for the default
872 /// policy (local pages plus your application's own content). See
873 /// ultralight::OriginRules for the rule syntax.
874 ///
875 /// @param num_origin_rules The number of entries in `origin_rules`.
876 ///
877 /// @return Returns true on success, or false if `context` is NULL, a flag is unknown, or a
878 /// rule failed to parse (nothing changes then, and a logged warning says why).
879 ///
880 /// \parblock
881 /// @note The origin policy is shared with AttachJSAPI(): same rule syntax, same default,
882 /// evaluated against each page's security origin. A page that isn't allowed compiles
883 /// no binding markup: it shows its authored content, and none of its controls stage
884 /// changes or fire actions. A data context has no injection filter, so the origin
885 /// rules alone decide which pages get it.
886 /// \endparblock
887 ///
888 /// \parblock
889 /// @note Safe to call from any thread, including the context's home thread (origin rules
890 /// parse on the calling thread). Unlike most View methods this only records intent, the
891 /// attachment takes effect on the Renderer's thread during the next update.
892 /// \endparblock
893 ///
894 virtual bool AttachDOMDataContext(ULDOMDataContext context, unsigned flags = 0,
895 const char* const* origin_rules = nullptr,
896 size_t num_origin_rules = 0) = 0;
897
898 ///
899 /// Detach a data-binding context from this View.
900 ///
901 /// Its pages stop receiving updates, and the page's binding markup recompiles against the
902 /// remaining attached contexts.
903 ///
904 /// @param context The context to detach.
905 ///
906 /// @note Safe to call from any thread. The attachment is removed immediately, and the page
907 /// recompiles on the Renderer's thread during its next update.
908 ///
909 virtual void DetachDOMDataContext(ULDOMDataContext context) = 0;
910
911 ///
912 /// Callback that decides whether an attached API's bindings are added to a loading page.
913 ///
914 /// This is called on the Renderer's thread after the origin rules have been evaluated. See
915 /// SetJSAPIInjectionFilter() and `<Ultralight/CAPI/CAPI_JSAPI.h>`. Most C++ code uses
916 /// js::SetInjectionFilter() instead.
917 ///
918 /// @param user_data The user data passed to SetJSAPIInjectionFilter().
919 ///
920 /// @param request The API, the page's origin, and the verdict of the origin rules (see
921 /// ULJSAPIInjectionRequest). It's owned by the library and valid only
922 /// during the callback. Its `view` member is NULL here (it's set only for a
923 /// filter set with ulViewSetJSAPIInjectionFilter()).
924 ///
925 /// @return Return true to add the bindings to this page, or false to withhold them. The
926 /// return value is final: it can override the origin rules either way.
927 ///
928 using JSAPIInjectionFilter = bool (*)(void* user_data, const ULJSAPIInjectionRequest* request);
929
930 ///
931 /// Attach a JavaScript API to this View.
932 ///
933 /// A ULJSAPI (see `<Ultralight/CAPI/CAPI_JSAPI.h>`) is a set of native bindings under a global
934 /// namespace such as `myApp`.
935 ///
936 /// Once attached, the bindings are added to the current page (if any) and to every page the
937 /// View navigates to afterwards, so you don't need to register them again after a navigation:
938 ///
939 /// ```
940 /// ULJSAPI api = ulCreateJSAPI("myApp");
941 /// ulJSAPIBindFunction(api, "greet", OnGreet, nullptr, nullptr);
942 /// view->AttachJSAPI(api);
943 /// // Page script on every admitted page: myApp.greet()
944 /// ```
945 ///
946 /// The View keeps the API attached while an owning handle to it exists (see
947 /// ulDestroyJSAPI()). Attaching it again updates its flags and origin rules.
948 ///
949 /// @param api The API to attach.
950 ///
951 /// @param flags A logically ORed set of ULJSAPIAttachFlags. Unknown bits fail
952 /// the attach.
953 ///
954 /// @param origin_rules An array of `scheme://host[:port]` origin patterns for the pages
955 /// that get the bindings (eg, `https://*.mygame.com`), or nullptr
956 /// for the default policy (local pages plus your application's own
957 /// content, ie. pages loaded with LoadHTML()). See
958 /// ultralight::OriginRules for the rule syntax.
959 ///
960 /// @param num_origin_rules The number of entries in `origin_rules`.
961 ///
962 /// @return Returns true on success, or false if `api` is NULL, a flag is unknown, or a rule
963 /// failed to parse (nothing changes then, and a logged warning says why).
964 ///
965 /// \parblock
966 /// @note APIs that share a namespace prefix (eg, `myApp.fs` and `myApp.net`) should all be
967 /// attached before the page loads. An API attached later can't add to a namespace the
968 /// page already has, so its bindings appear after the page's next navigation instead
969 /// (see ulViewAttachJSAPI()).
970 /// \endparblock
971 ///
972 /// \parblock
973 /// @note Without kULJSAPIAttachFlags_AllFrames, the bindings are added to the main frame
974 /// only.
975 /// \endparblock
976 ///
977 /// \parblock
978 /// @note A page restored from the back-forward cache (Config::page_cache_size > 0) resumes
979 /// with working bindings: the API objects it kept (and any function references its
980 /// scripts held) become callable again, and native events reach the page. Page-side
981 /// event subscriptions made with the `on` mixin do **not** survive the round trip, so
982 /// page scripts should re-subscribe in a `pageshow` handler.
983 /// \endparblock
984 ///
985 virtual bool AttachJSAPI(ULJSAPI api, unsigned flags = 0,
986 const char* const* origin_rules = nullptr,
987 size_t num_origin_rules = 0) = 0;
988
989 ///
990 /// Detach a JavaScript API from this View.
991 ///
992 /// Functions and objects already added to the current page remain until the next navigation,
993 /// but event delivery to this View stops immediately.
994 ///
995 /// @param api The API to detach.
996 ///
997 virtual void DetachJSAPI(ULJSAPI api) = 0;
998
999 ///
1000 /// Set a filter that decides whether an attached API's bindings are added to a page.
1001 ///
1002 /// The filter is consulted after the origin rules, for every attached API and page.
1003 ///
1004 /// @param filter The filter callback. Pass nullptr to remove the current filter.
1005 ///
1006 /// @param user_data User data passed through to the filter on every call.
1007 ///
1008 /// @param destroy_user_data Callback invoked exactly once to destroy `user_data` after the
1009 /// filter is replaced or the View is destroyed (may be nullptr).
1010 ///
1011 /// @see js::SetInjectionFilter()
1012 ///
1013 virtual void SetJSAPIInjectionFilter(JSAPIInjectionFilter filter, void* user_data,
1014 void (*destroy_user_data)(void*)) = 0;
1015
1016 ///
1017 /// Whether or not the View can navigate back in history.
1018 ///
1019 virtual bool CanGoBack() = 0;
1020
1021 ///
1022 /// Whether or not the View can navigate forward in history.
1023 ///
1024 virtual bool CanGoForward() = 0;
1025
1026 ///
1027 /// Navigate backwards in history.
1028 ///
1029 virtual void GoBack() = 0;
1030
1031 ///
1032 /// Navigate forwards in history.
1033 ///
1034 virtual void GoForward() = 0;
1035
1036 ///
1037 /// Navigate to an arbitrary offset in history.
1038 ///
1039 /// @param offset The number of entries to move (negative goes back, positive goes forward).
1040 ///
1041 virtual void GoToHistoryOffset(int offset) = 0;
1042
1043 ///
1044 /// Reload current page.
1045 ///
1046 virtual void Reload() = 0;
1047
1048 ///
1049 /// Stop all page loads.
1050 ///
1051 virtual void Stop() = 0;
1052
1053 ///
1054 /// Give focus to the View.
1055 ///
1056 /// You should call this to give visual indication that the View has input focus (changes active
1057 /// text selection colors, for example). The page gets a window `focus` event, and so does the
1058 /// element that had focus before Unfocus().
1059 ///
1060 virtual void Focus() = 0;
1061
1062 ///
1063 /// Remove focus from the View.
1064 ///
1065 /// You should call this to give visual indication that the View has lost input focus. The page
1066 /// gets a window `blur` event.
1067 ///
1068 /// @note The page's focused element gets a blur event but stays focused in the document, and
1069 /// shows focus again the next time you call Focus().
1070 ///
1071 virtual void Unfocus() = 0;
1072
1073 ///
1074 /// Whether or not the View has focus.
1075 ///
1076 virtual bool HasFocus() = 0;
1077
1078 ///
1079 /// Whether or not the View has an input element with visible keyboard focus (indicated by a
1080 /// blinking caret).
1081 ///
1082 /// You can use this to decide whether or not the View should consume keyboard input events
1083 /// (useful in games with mixed UI and key handling).
1084 ///
1085 /// @note This reports text-editing focus specifically: a focused text field, text area, or
1086 /// editable (contenteditable) region that can accept typed input. Focused elements that
1087 /// consume keys without editing text (eg, a select or checkbox) report false, as do
1088 /// read-only text fields, and so does everything while the View itself is unfocused
1089 /// (see Unfocus()).
1090 ///
1091 virtual bool HasInputFocus() = 0;
1092
1093 ///
1094 /// Get the Editor for the View (executes editing commands against the focused frame).
1095 ///
1096 /// You can use this to drive text editing natively: caret motion, selection, deletion,
1097 /// clipboard operations, undo/redo, and typed text insertion (the commands a native Edit menu or
1098 /// keybinding table needs).
1099 ///
1100 /// @return Returns the View's Editor instance (owned by the View, this is never NULL).
1101 ///
1102 /// @see Editor
1103 ///
1104 virtual Editor* editor() = 0;
1105
1106 ///
1107 /// Fire a keyboard event.
1108 ///
1109 /// @param evt The key event.
1110 ///
1111 /// @note KeyEvent::kType_Char events insert text into input fields, and so does a legacy
1112 /// KeyEvent::kType_KeyDown that carries text. KeyEvent::kType_RawKeyDown never inserts
1113 /// text.
1114 ///
1115 virtual void FireKeyEvent(const KeyEvent& evt) = 0;
1116
1117 ///
1118 /// Fire a mouse event.
1119 ///
1120 /// @param evt The mouse event.
1121 ///
1122 virtual void FireMouseEvent(const MouseEvent& evt) = 0;
1123
1124 ///
1125 /// Fire a scroll event.
1126 ///
1127 /// @param evt The scroll event.
1128 ///
1129 virtual void FireScrollEvent(const ScrollEvent& evt) = 0;
1130
1131 ///
1132 /// Set a ViewListener to receive callbacks for View-related events.
1133 ///
1134 /// @param listener A user-defined ViewListener implementation, ownership remains with the
1135 /// caller. Pass a nullptr to remove the current listener.
1136 ///
1137 virtual void set_view_listener(ViewListener* listener) = 0;
1138
1139 ///
1140 /// Get the active ViewListener (can be nullptr).
1141 ///
1142 virtual ViewListener* view_listener() const = 0;
1143
1144 ///
1145 /// Set a LoadListener to receive callbacks for Load-related events.
1146 ///
1147 /// @param listener A user-defined LoadListener implementation, ownership remains with the
1148 /// caller. Pass a nullptr to remove the current listener.
1149 ///
1150 virtual void set_load_listener(LoadListener* listener) = 0;
1151
1152 ///
1153 /// Get the active LoadListener (can be nullptr).
1154 ///
1155 virtual LoadListener* load_listener() const = 0;
1156
1157 ///
1158 /// Set a DownloadListener to receive callbacks for download-related events.
1159 ///
1160 /// @param listener A user-defined DownloadListener implementation, ownership remains with the
1161 /// caller. Pass a nullptr to remove the current listener.
1162 ///
1163 virtual void set_download_listener(DownloadListener* listener) = 0;
1164
1165 ///
1166 /// Get the active DownloadListener (can be nullptr).
1167 ///
1169
1170 ///
1171 /// Cancel an active download.
1172 ///
1173 /// No more data arrives for the download, and DownloadListener::OnFailDownload() is called for
1174 /// it during a later Renderer::Update().
1175 ///
1176 /// @param id The id of the download to cancel (see DownloadListener).
1177 ///
1178 virtual void CancelDownload(DownloadId id) = 0;
1179
1180 ///
1181 /// Set an EditorListener to receive callbacks for editing-related events.
1182 ///
1183 /// @param listener A user-defined EditorListener implementation, ownership remains with the
1184 /// caller. Pass a nullptr to remove the current listener.
1185 ///
1186 /// @note An AppCore panel uses its View's editor listener for input method support and
1187 /// Window::OnEditableStateChange(). Replacing it on a hosted View turns both off for
1188 /// that View.
1189 ///
1190 virtual void set_editor_listener(EditorListener* listener) = 0;
1191
1192 ///
1193 /// Get the active EditorListener (can be nullptr).
1194 ///
1195 virtual EditorListener* editor_listener() const = 0;
1196
1197 ///
1198 /// Set a NetworkListener to receive callbacks for network-related events.
1199 ///
1200 /// @param listener A user-defined NetworkListener implementation, ownership remains with the
1201 /// caller. Pass a nullptr to remove the current listener.
1202 ///
1203 /// @pre Not available in the Free edition (the listener is never called there).
1204 ///
1205 virtual void set_network_listener(NetworkListener* listener) = 0;
1206
1207 ///
1208 /// Get the active NetworkListener (can be nullptr).
1209 ///
1210 virtual NetworkListener* network_listener() const = 0;
1211
1212 ///
1213 /// Set whether or not this View should be repainted during the next call to Renderer::Render().
1214 ///
1215 /// @param needs_paint Whether or not the View needs a repaint.
1216 ///
1217 /// @note The library sets this flag automatically when a repaint is due: after a
1218 /// Renderer::RefreshDisplay() call that produces animating or changed content, on
1219 /// resize, when the View is shown, and when the page reacts to user input. You can also
1220 /// set it directly to force a repaint (it still waits for max_render_fps()).
1221 ///
1222 virtual void set_needs_paint(bool needs_paint) = 0;
1223
1224 ///
1225 /// Whether or not this View should be repainted during the next call to Renderer::Render().
1226 ///
1227 /// When this returns false, rendering would reproduce the previous frame, so you can skip
1228 /// rendering or presenting the View. This is always false while the View is hidden, and while
1229 /// max_render_fps() holds back its next frame.
1230 ///
1231 /// When this returns true, the next call to Renderer::Render() repaints the View. The resulting
1232 /// frame may still be visually identical to the previous frame.
1233 ///
1234 /// @note Continue calling Renderer::RefreshDisplay() on every display refresh regardless of
1235 /// this flag. A View whose only pending work is animation callbacks or CSS animations
1236 /// only requests a repaint after that call.
1237 ///
1238 virtual bool needs_paint() const = 0;
1239
1240 ///
1241 /// Create an Inspector View to inspect / debug this View locally.
1242 ///
1243 /// This will only succeed if you have the inspector assets in your filesystem-- the inspector
1244 /// will look for file:///inspector/Main.html when it first loads.
1245 ///
1246 /// You must handle ViewListener::OnCreateInspectorView() so that the library has a View to
1247 /// display the inspector in. This function will call this event only if an inspector view is
1248 /// not currently active.
1249 ///
1250 virtual void CreateLocalInspectorView() = 0;
1251
1252 ///
1253 /// Set whether or not to display compositor debug information, specifically:
1254 /// - Visualize compositor layers and tile boundaries
1255 /// - Display repaint counters for each layer
1256 ///
1257 /// @param enable Whether or not to show the debug information.
1258 ///
1259 /// @note This is only valid when the compositor is enabled.
1260 ///
1261 /// @see ViewConfig::enable_compositor
1262 ///
1263 virtual void set_compositor_debug_info_enabled(bool enable) = 0;
1264
1265 ///
1266 /// Whether or not compositor debug information is enabled.
1267 ///
1268 virtual bool compositor_debug_info_enabled() const = 0;
1269
1270 ///
1271 /// Set whether or not this View is visible.
1272 ///
1273 /// Hiding a View (passing false) stops it from being painted during Renderer::Render and pauses
1274 /// its rendering-driven work: requestAnimationFrame callbacks and CSS animations stop advancing
1275 /// while hidden, and the page's `visibilitychange` event fires with `document.visibilityState`
1276 /// set to "hidden".
1277 ///
1278 /// Showing a View again (passing true) resumes its animations and forces a repaint on the next
1279 /// call to Renderer::Render.
1280 ///
1281 /// @param visible Whether or not the View is visible.
1282 ///
1283 /// \parblock
1284 /// @note Views are visible by default.
1285 /// \endparblock
1286 ///
1287 /// \parblock
1288 /// @note JavaScript timers (setTimeout / setInterval) keep running while hidden unless
1289 /// ViewConfig::enable_hidden_timer_throttling was set when the View was created.
1290 /// \endparblock
1291 ///
1292 virtual void set_visible(bool visible) = 0;
1293
1294 ///
1295 /// Whether or not this View is visible.
1296 ///
1297 /// @see set_visible()
1298 ///
1299 virtual bool is_visible() const = 0;
1300
1301 ///
1302 /// Set the maximum rate, in frames per second, at which this View advances its animations and
1303 /// repaints.
1304 ///
1305 /// @param fps The frame-rate cap, or 0 to remove it (the View then advances at the
1306 /// display's refresh rate).
1307 ///
1308 /// @see ViewConfig::max_render_fps
1309 ///
1310 virtual void set_max_render_fps(uint32_t fps) = 0;
1311
1312 ///
1313 /// Get the frame-rate cap set for this View, or 0 if none is set.
1314 ///
1315 /// @see set_max_render_fps()
1316 ///
1317 virtual uint32_t max_render_fps() const = 0;
1318
1319 ///
1320 /// Set the color scheme this View reports to pages via the `prefers-color-scheme` CSS
1321 /// media feature.
1322 ///
1323 /// Overrides ViewConfig::preferred_color_scheme for this View. A change re-evaluates
1324 /// `prefers-color-scheme` media queries on the page, firing `matchMedia` change listeners and
1325 /// recalculating styles, the same as an OS theme change.
1326 ///
1327 /// @param scheme The new scheme. Auto follows the system value set via
1328 /// Renderer::set_system_color_scheme().
1329 ///
1330 virtual void set_preferred_color_scheme(ColorScheme scheme) = 0;
1331
1332 ///
1333 /// The color scheme this View reports to pages.
1334 ///
1335 /// @see set_preferred_color_scheme()
1336 ///
1338
1339#if UL_HAS(TESTING)
1340 /// \cond ignore
1341 virtual String RenderTreeAsString(uint32_t flags = 0) = 0;
1342 virtual String PageSource() = 0;
1343 virtual String DumpAsText(bool dump_child_frames = true) = 0;
1344 virtual uint32_t damage_verify_mismatches() const = 0;
1345 virtual IntRect damage_verify_last_bounds() const = 0;
1346 virtual RenderTarget damage_verify_render_target() const = 0;
1347 /// \endcond
1348#endif
1349
1350 protected:
1351 virtual ~View();
1352};
1353
1354} // namespace ultralight
#define UExport
Definition Exports.h:22
#define ULTRALIGHT_USER_AGENT
Definition Defines.h:132
struct C_JSContext * ULJSContext
Opaque handle to a JavaScript execution context (one page's script world in one View).
Definition View.h:25
struct C_JSAPI * ULJSAPI
Opaque handle to a set of native JavaScript bindings.
Definition View.h:32
struct C_DOMTriggers * ULDOMTriggers
Opaque handle to a set of DOM event listeners and DOM-ready hooks.
Definition View.h:46
struct ULJSAPIInjectionRequest ULJSAPIInjectionRequest
The details an API injection filter decides on.
Definition View.h:60
struct C_DOMDataContext * ULDOMDataContext
Opaque handle to a data-binding context.
Definition View.h:53
struct C_DOMDocument * ULDOMDocument
Opaque handle to a page's DOM document.
Definition View.h:39
struct ULDOMTriggersInjectionRequest ULDOMTriggersInjectionRequest
The details a DOM triggers injection filter decides on.
Definition View.h:67
An RGBA color value in a certain color space (with CSS parsing helpers).
Definition Color.h:69
User-defined interface to handle downloads for a View.
Definition Listener.h:381
Text-editing interface for a View.
Definition Editor.h:332
User-defined interface to handle editing events for a View.
Definition Listener.h:501
Keyboard event representing a change in keyboard state.
Definition KeyEvent.h:25
User-defined interface to handle load-related events for a View.
Definition Listener.h:218
Mouse event representing a change in mouse state.
Definition MouseEvent.h:26
User-defined interface to handle network requests for a View.
Definition Listener.h:471
Interface for all ref-counted objects that will be managed using the RefPtr<> smart pointer.
Definition RefPtr.h:49
A nullable smart pointer.
Definition RefPtr.h:126
Scroll event representing a change in scroll state.
Definition ScrollEvent.h:21
Unicode string container with conversions for UTF-8, UTF-16, and UTF-32.
Definition String.h:31
User-defined pixel buffer surface.
Definition Surface.h:44
Web-page container rendered to an offscreen surface.
Definition View.h:483
virtual String url()=0
Get the URL of the current page loaded into this View, if any.
virtual bool is_transparent() const =0
Whether or not the View supports transparent backgrounds.
virtual bool is_accelerated() const =0
Whether or not the View is GPU-accelerated.
virtual ColorScheme preferred_color_scheme() const =0
The color scheme this View reports to pages.
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 uint32_t height() const =0
Get the height of the View, in pixels.
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 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 void LoadURL(const String &url)=0
Load a URL, the View will navigate to it as a new page.
virtual void set_view_listener(ViewListener *listener)=0
Set a ViewListener to receive callbacks for View-related events.
virtual String title()=0
Get the title of the current page loaded into this View, if any.
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 bool is_visible() const =0
Whether or not this View is visible.
virtual bool needs_paint() const =0
Whether or not this View should be repainted during the next call to Renderer::Render().
virtual void Resize(uint32_t width, uint32_t height)=0
Resize View to a certain size.
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 void set_compositor_debug_info_enabled(bool enable)=0
Set whether or not to display compositor debug information, specifically:
virtual NetworkListener * network_listener() const =0
Get the active NetworkListener (can be nullptr).
virtual void * JavaScriptVM(const String &frame="")=0
Get a handle to the internal JavaScriptCore VM.
virtual void set_device_scale(double scale)=0
Set the device scale.
virtual RenderTarget render_target()=0
Get the RenderTarget for the View.
virtual void Stop()=0
Stop all page loads.
virtual ViewListener * view_listener() const =0
Get the active ViewListener (can be nullptr).
virtual uint32_t width() const =0
Get the width of the View, in pixels.
virtual void CreateLocalInspectorView()=0
Create an Inspector View to inspect / debug this View locally.
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 EditorListener * editor_listener() const =0
Get the active EditorListener (can be nullptr).
virtual RefPtr< JSContext > LockJSContext(const String &frame="")=0
Acquire the page's JSContext for use with the JavaScriptCore API.
virtual ULJSContext GetJSContext()=0
Get a ULJS handle to the main frame's JavaScript context.
virtual void FireScrollEvent(const ScrollEvent &evt)=0
Fire a scroll event.
virtual void set_download_listener(DownloadListener *listener)=0
Set a DownloadListener to receive callbacks for download-related events.
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 bool CanGoBack()=0
Whether or not the View can navigate back in history.
virtual void DetachDOMDataContext(ULDOMDataContext context)=0
Detach a data-binding context from this View.
virtual Surface * surface()=0
Get the Surface for the View (native pixel buffer that the CPU renderer draws into).
virtual void set_network_listener(NetworkListener *listener)=0
Set a NetworkListener to receive callbacks for network-related events.
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 LoadListener * load_listener() const =0
Get the active LoadListener (can be nullptr).
virtual void FireMouseEvent(const MouseEvent &evt)=0
Fire a mouse event.
virtual ULDOMDocument GetDOMDocument()=0
Get a ULDOM handle to the current page's document (main frame).
bool(*)(void *user_data, const ULJSAPIInjectionRequest *request) JSAPIInjectionFilter
Callback that decides whether an attached API's bindings are added to a loading page.
Definition View.h:928
virtual double device_scale() const =0
Get the device scale, ie.
virtual bool CanGoForward()=0
Whether or not the View can navigate forward in history.
virtual bool HasInputFocus()=0
Whether or not the View has an input element with visible keyboard focus (indicated by a blinking car...
virtual bool HasFocus()=0
Whether or not the View has focus.
virtual void CancelDownload(DownloadId id)=0
Cancel an active download.
virtual void GoToHistoryOffset(int offset)=0
Navigate to an arbitrary offset in history.
virtual void DetachDOMTriggers(ULDOMTriggers triggers)=0
Detach a set of DOM listeners from this View.
virtual bool compositor_debug_info_enabled() const =0
Whether or not compositor debug information is enabled.
virtual void Focus()=0
Give focus to the View.
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 DetachJSAPI(ULJSAPI api)=0
Detach a JavaScript API from this View.
virtual bool is_loading()=0
Check if the main frame of the page is currently loading.
virtual void Unfocus()=0
Remove focus from the View.
virtual DownloadListener * download_listener() const =0
Get the active DownloadListener (can be nullptr).
virtual bool is_settled()=0
Check if the page has settled after loading.
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.
bool(*)(void *user_data, const ULDOMTriggersInjectionRequest *request) DOMTriggersInjectionFilter
Callback that decides whether an attached set of DOM listeners is applied to a loading page.
Definition View.h:766
virtual void set_editor_listener(EditorListener *listener)=0
Set an EditorListener to receive callbacks for editing-related events.
virtual void GoForward()=0
Navigate forwards in history.
virtual void GoBack()=0
Navigate backwards in history.
virtual void set_display_id(uint32_t id)=0
Set the display id of the View.
virtual void set_visible(bool visible)=0
Set whether or not this View is visible.
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 void set_load_listener(LoadListener *listener)=0
Set a LoadListener to receive callbacks for Load-related events.
virtual uint32_t display_id() const =0
Get the display id of the 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 void Reload()=0
Reload current page.
User-defined interface to handle general events for a View.
Definition Listener.h:76
Root namespace for every public Ultralight type, function, and enumeration.
@ Light
Always use the light look.
Definition Window.h:67
@ Dark
Always use the dark look.
Definition Window.h:68
uint32_t DownloadId
A unique ID for a download (see DownloadListener::NextDownloadId()).
Definition Listener.h:359
ClipboardReadPolicy
Which pages may read the clipboard from script.
Definition View.h:89
@ Deny
Refuse every script-initiated clipboard read.
Definition View.h:90
@ Allow
Grant reads from any page.
Definition View.h:92
@ AllowForAppContent
Grant reads from your application's own content only.
Definition View.h:91
ColorScheme
A page color scheme, as reported to pages via the prefers-color-scheme CSS media feature.
Definition View.h:78
@ Auto
Follow the system color scheme set on the Renderer.
Definition View.h:79
@ Auto
The library also hides it the way the OS closes a native menu.
Definition Options.h:29
Integer Rectangle Helper.
Definition Geometry.h:533
Offscreen render target, used when rendering Views via the GPU renderer.
Definition RenderTarget.h:31
View-specific configuration settings.
Definition View.h:100
String font_family_fixed
The default monospace font family (eg, for pre and code).
Definition View.h:357
ClipboardReadPolicy clipboard_read_policy
Policy governing script-initiated clipboard reads (eg, a page's own Paste button calling document....
Definition View.h:274
uint32_t display_id
A user-generated id for the display (monitor, TV, or screen) that this View will be shown on.
Definition View.h:114
String font_family_standard
The default font family (used for text that doesn't set one).
Definition View.h:352
bool match_native_editing_behavior
Whether or not text editing should follow the host OS's native conventions instead of the library's c...
Definition View.h:254
Color background_color
The base color the page renders on before any page styling applies.
Definition View.h:173
String font_family_serif
The default font family for the CSS serif generic.
Definition View.h:362
bool is_transparent
Whether or not this View should support transparency.
Definition View.h:160
uint32_t font_size_default
The default font size, in pixels.
Definition View.h:388
String font_family_fantasy
The default font family for the CSS fantasy generic.
Definition View.h:377
String user_agent
Custom user-agent string.
Definition View.h:400
bool is_accelerated
Whether to render using the GPU renderer (accelerated) or the CPU renderer (unaccelerated).
Definition View.h:135
bool enable_compositor
Whether or not compositing should be enabled.
Definition View.h:221
uint32_t font_size_fixed
The default font size for monospace text (eg, pre and code), in pixels.
Definition View.h:393
bool initial_focus
Whether or not the View should initially have input focus.
Definition View.h:202
bool enable_hidden_timer_throttling
Whether to throttle JavaScript timers (setTimeout / setInterval) while this View is hidden.
Definition View.h:291
bool enable_compositor_debug_info
Whether or not to enable extra compositor debug information, specifically:
Definition View.h:230
bool javascript_can_open_windows_automatically
Whether or not a script can open a window with window.open() without a user gesture.
Definition View.h:334
double initial_device_scale
The initial device scale, ie.
Definition View.h:149
String font_family_pictograph
The default font family for the CSS -webkit-pictograph generic.
Definition View.h:383
uint32_t max_render_fps
The maximum rate, in frames per second, at which this View advances its animations and repaints.
Definition View.h:319
ColorScheme preferred_color_scheme
The color scheme this View reports to pages via the prefers-color-scheme CSS media feature.
Definition View.h:195
bool allow_universal_access_from_file_urls
Whether or not pages loaded from file:/// URLs can access content from any origin.
Definition View.h:344
String font_family_sans_serif
The default font family for the CSS sans-serif generic.
Definition View.h:367
String font_family_cursive
The default font family for the CSS cursive generic.
Definition View.h:372
bool enable_canvas_filters
Whether or not the HTML5 Canvas Filters API (CanvasRenderingContext2D.filter) is enabled.
Definition View.h:238
bool enable_images
Whether or not images should be enabled.
Definition View.h:207
bool enable_javascript
Whether or not JavaScript should be enabled.
Definition View.h:212