Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::view::web Namespace Reference

Classes

struct  ViewportMapping
 Maps CSS pixels — the unit every browser pointer event reports — to root-view coordinates. More...
struct  BackingStore
 Canvas backing-store size and the scale factor handed to the Skia surface. More...
struct  BrowserModifiers
struct  BrowserPointerEvent
struct  BrowserWheelEvent
struct  BrowserKeyEvent
class  WebInputRouter
 Routes translated browser events into a live View tree. More...

Enumerations

enum class  BrowserPointerPhase : uint8_t { down , move , up , cancel }
 W3C PointerEvent phase. More...
enum class  BrowserPointerType : uint8_t { mouse , touch , pen }
 W3C PointerEvent.pointerType. More...
enum class  BrowserDeltaMode : uint8_t { pixel = 0 , line = 1 , page = 2 }
 W3C WheelEvent.deltaMode. More...

Functions

Point css_to_root (const ViewportMapping &mapping, Point css)
 CSS-pixel point → root-view point. Identity without a design viewport.
Point root_to_css (const ViewportMapping &mapping, Point root)
 Root-view point → CSS-pixel point. The exact inverse of css_to_root().
BackingStore compute_backing_store (float css_width, float css_height, float device_pixel_ratio)
 The one place the HiDPI factor is applied.
uint16_t translate_modifiers (const BrowserModifiers &mods)
 metaKey is Command on a Mac browser and the Super/Windows key elsewhere, so it sets both kModMeta and kModCmd.
MouseButton translate_button (int w3c_button)
PointerType translate_pointer_type (BrowserPointerType type)
MouseEvent translate_pointer (const BrowserPointerEvent &event, const ViewportMapping &mapping)
 Browser pointer event → Pulp MouseEvent in ROOT coordinates.
MouseEvent translate_wheel (const BrowserWheelEvent &event, const ViewportMapping &mapping)
 Browser wheel event → Pulp wheel MouseEvent in ROOT coordinates.
KeyCode translate_key_code (const std::string &key)
 KeyboardEvent.key → KeyCode.
KeyEvent translate_key (const BrowserKeyEvent &event)
std::string text_for_key (const BrowserKeyEvent &event)
 The text a key-down should also deliver as a TextInputEvent, or "" when the key produces no character.
void install_browser_window_host (std::string canvas_selector="#canvas")
 Register the Emscripten BrowserWindowHost factory so WindowHost::create() returns a canvas-backed host.
void install_web_input_listeners (const std::string &canvas_selector, WebInputRouter &router)
 Attach/detach the DOM listeners (pointer, wheel, key, resize) that feed router.
void remove_web_input_listeners (const std::string &canvas_selector)
void notify_browser_host_resized (float css_width, float css_height)
 The canvas element's CSS size changed.
bool browser_host_gpu_available ()
 Is the live browser host's GPU surface renderable RIGHT NOW?
float device_pixel_ratio ()
 Current devicePixelRatio, and the canvas element's CSS size. Emscripten only.
bool canvas_css_size (const std::string &canvas_selector, float &css_width, float &css_height)
void set_canvas_size (const std::string &canvas_selector, const BackingStore &backing, float css_width, float css_height)
 Size the canvas element: backing store in device pixels, CSS box in CSS pixels.
void set_canvas_visible (const std::string &canvas_selector, bool visible)
 Show/hide the canvas element (style.display). Emscripten only.

Variables

constexpr float kWheelLinePixels = 16.0f
 A wheel line is one text line; a wheel page falls back to this when the mapping carries no CSS height.
constexpr float kWheelPageFallbackPixels = 400.0f

Enumeration Type Documentation

◆ BrowserDeltaMode

enum class pulp::view::web::BrowserDeltaMode : uint8_t
strong

W3C WheelEvent.deltaMode.

Enumerator
pixel 
line 
page 

◆ BrowserPointerPhase

enum class pulp::view::web::BrowserPointerPhase : uint8_t
strong

W3C PointerEvent phase.

Enumerator
down 
move 
up 
cancel 

◆ BrowserPointerType

enum class pulp::view::web::BrowserPointerType : uint8_t
strong

W3C PointerEvent.pointerType.

Enumerator
mouse 
touch 
pen 

Function Documentation

◆ browser_host_gpu_available()

bool pulp::view::web::browser_host_gpu_available ( )

Is the live browser host's GPU surface renderable RIGHT NOW?

False while the WebGL context is lost — the browser can revoke it at any time (context-cap eviction, GPU-process crash, backgrounded mobile tab), and the Ganesh surface then abandons its Skia context and refuses to paint until webglcontextrestored arrives. Exposed so a host page (and the browser pixel fixture) can observe and assert that recovery instead of guessing from a frozen canvas. False when no host is installed. Emscripten only.

◆ canvas_css_size()

bool pulp::view::web::canvas_css_size ( const std::string & canvas_selector,
float & css_width,
float & css_height )

◆ compute_backing_store()

BackingStore pulp::view::web::compute_backing_store ( float css_width,
float css_height,
float device_pixel_ratio )
inline

The one place the HiDPI factor is applied.

canvas.style.{width,height} stay at the CSS size, canvas.{width,height} become the returned device size, and scale_factor is the ratio — so paint scales up while input coordinates stay in CSS pixels.

◆ css_to_root()

Point pulp::view::web::css_to_root ( const ViewportMapping & mapping,
Point css )
inline

CSS-pixel point → root-view point. Identity without a design viewport.

◆ device_pixel_ratio()

float pulp::view::web::device_pixel_ratio ( )

Current devicePixelRatio, and the canvas element's CSS size. Emscripten only.

◆ install_browser_window_host()

void pulp::view::web::install_browser_window_host ( std::string canvas_selector = "#canvas")

Register the Emscripten BrowserWindowHost factory so WindowHost::create() returns a canvas-backed host.

canvas_selector is a CSS selector for the target HTMLCanvasElement. Defined in platform/web/window_host_web.cpp, which is compiled only for Emscripten targets.

◆ install_web_input_listeners()

void pulp::view::web::install_web_input_listeners ( const std::string & canvas_selector,
WebInputRouter & router )

Attach/detach the DOM listeners (pointer, wheel, key, resize) that feed router.

Defined in platform/web/web_input.cpp — Emscripten only.

◆ notify_browser_host_resized()

void pulp::view::web::notify_browser_host_resized ( float css_width,
float css_height )

The canvas element's CSS size changed.

Called by the resize listener in web_input.cpp; handled by the live host in window_host_web.cpp.

◆ remove_web_input_listeners()

void pulp::view::web::remove_web_input_listeners ( const std::string & canvas_selector)

◆ root_to_css()

Point pulp::view::web::root_to_css ( const ViewportMapping & mapping,
Point root )
inline

Root-view point → CSS-pixel point. The exact inverse of css_to_root().

◆ set_canvas_size()

void pulp::view::web::set_canvas_size ( const std::string & canvas_selector,
const BackingStore & backing,
float css_width,
float css_height )

Size the canvas element: backing store in device pixels, CSS box in CSS pixels.

Emscripten only.

◆ set_canvas_visible()

void pulp::view::web::set_canvas_visible ( const std::string & canvas_selector,
bool visible )

Show/hide the canvas element (style.display). Emscripten only.

◆ text_for_key()

std::string pulp::view::web::text_for_key ( const BrowserKeyEvent & event)
inline

The text a key-down should also deliver as a TextInputEvent, or "" when the key produces no character.

KeyboardEvent.key is the printable character itself for character keys and a multi-character NAME ("Enter", "ArrowLeft") otherwise; a non-ASCII character is a multi-byte UTF-8 string whose first byte has the high bit set, which is how it stays distinguishable from a name. Ctrl/Meta chords are commands, not text.

◆ translate_button()

MouseButton pulp::view::web::translate_button ( int w3c_button)
inline

◆ translate_key()

KeyEvent pulp::view::web::translate_key ( const BrowserKeyEvent & event)
inline

◆ translate_key_code()

KeyCode pulp::view::web::translate_key_code ( const std::string & key)
inline

KeyboardEvent.key → KeyCode.

Unmapped names (modifier keys, media keys, …) return KeyCode::unknown, which still reaches the view tree as a KeyEvent so a widget can observe the modifier state.

◆ translate_modifiers()

uint16_t pulp::view::web::translate_modifiers ( const BrowserModifiers & mods)
inline

metaKey is Command on a Mac browser and the Super/Windows key elsewhere, so it sets both kModMeta and kModCmd.

A wasm build is not __APPLE__, so is_main_modifier() resolves to Ctrl there — a shortcut that must follow the host OS reads isCmdDown()/isCtrlDown() explicitly.

◆ translate_pointer()

MouseEvent pulp::view::web::translate_pointer ( const BrowserPointerEvent & event,
const ViewportMapping & mapping )
inline

Browser pointer event → Pulp MouseEvent in ROOT coordinates.

Both position and window_position carry the root point. The host overwrites position with the hit view's local coordinates before dispatch (the macOS host's convention), which it can only do once hit-testing has picked a target.

◆ translate_pointer_type()

PointerType pulp::view::web::translate_pointer_type ( BrowserPointerType type)
inline

◆ translate_wheel()

MouseEvent pulp::view::web::translate_wheel ( const BrowserWheelEvent & event,
const ViewportMapping & mapping )
inline

Browser wheel event → Pulp wheel MouseEvent in ROOT coordinates.

Sign is preserved: WheelEvent.deltaY is positive when the content scrolls DOWN, and Pulp's scroll_delta_y is positive-is-down too (ScrollView adds it straight onto its scroll offset). Non-pixel delta modes are normalized to CSS pixels.

Variable Documentation

◆ kWheelLinePixels

float pulp::view::web::kWheelLinePixels = 16.0f
inlineconstexpr

A wheel line is one text line; a wheel page falls back to this when the mapping carries no CSS height.

◆ kWheelPageFallbackPixels

float pulp::view::web::kWheelPageFallbackPixels = 400.0f
inlineconstexpr