Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
web_event_translate.hpp File Reference

Browser-event translation and the CSS-pixel ↔ root-coordinate mapping used by the Emscripten BrowserWindowHost (core/view/platform/web/). More...

#include <pulp/view/input_events.hpp>
#include <pulp/view/overlay_dismissal.hpp>
#include <pulp/view/pointer_dispatch.hpp>
#include <pulp/view/ui_components.hpp>
#include <pulp/view/view.hpp>
#include <pulp/view/window_host.hpp>
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <functional>
#include <memory>
#include <string>
#include <unordered_map>

Go to the source code of this file.

Classes

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

Namespaces

namespace  pulp
namespace  pulp::view
 Hover-cursor tracking for platform window hosts.
namespace  pulp::view::web

Enumerations

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

Functions

Point pulp::view::web::css_to_root (const ViewportMapping &mapping, Point css)
 CSS-pixel point → root-view point. Identity without a design viewport.
Point pulp::view::web::root_to_css (const ViewportMapping &mapping, Point root)
 Root-view point → CSS-pixel point. The exact inverse of css_to_root().
BackingStore pulp::view::web::compute_backing_store (float css_width, float css_height, float device_pixel_ratio)
 The one place the HiDPI factor is applied.
uint16_t pulp::view::web::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 pulp::view::web::translate_button (int w3c_button)
PointerType pulp::view::web::translate_pointer_type (BrowserPointerType type)
MouseEvent pulp::view::web::translate_pointer (const BrowserPointerEvent &event, const ViewportMapping &mapping)
 Browser pointer event → Pulp MouseEvent in ROOT coordinates.
MouseEvent pulp::view::web::translate_wheel (const BrowserWheelEvent &event, const ViewportMapping &mapping)
 Browser wheel event → Pulp wheel MouseEvent in ROOT coordinates.
KeyCode pulp::view::web::translate_key_code (const std::string &key)
 KeyboardEvent.key → KeyCode.
KeyEvent pulp::view::web::translate_key (const BrowserKeyEvent &event)
std::string pulp::view::web::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 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.
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.
void pulp::view::web::remove_web_input_listeners (const std::string &canvas_selector)
void pulp::view::web::notify_browser_host_resized (float css_width, float css_height)
 The canvas element's CSS size changed.
bool pulp::view::web::browser_host_gpu_available ()
 Is the live browser host's GPU surface renderable RIGHT NOW?
float pulp::view::web::device_pixel_ratio ()
 Current devicePixelRatio, and the canvas element's CSS size. Emscripten only.
bool pulp::view::web::canvas_css_size (const std::string &canvas_selector, float &css_width, float &css_height)
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.
void pulp::view::web::set_canvas_visible (const std::string &canvas_selector, bool visible)
 Show/hide the canvas element (style.display). Emscripten only.

Variables

constexpr float pulp::view::web::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 pulp::view::web::kWheelPageFallbackPixels = 400.0f

Detailed Description

Browser-event translation and the CSS-pixel ↔ root-coordinate mapping used by the Emscripten BrowserWindowHost (core/view/platform/web/).

Nothing here depends on Emscripten. The coordinate math, the event-shape mapping, and the View-tree routing are plain C++ so they compile and are unit-testable on a native host (test/test_window_host_web.cpp); web_input.cpp only owns the DOM listener plumbing that feeds them.