Skip to main content

blitz_script/
raster.rs

1use blitz_dom::node::RasterImageData;
2use boa_engine::Context;
3
4use crate::state::DomCtx;
5
6/// Read an embedder-marked raster from a native JavaScript callback.
7///
8/// The document remains on its owning thread. Cloning the raster shares its
9/// decoded Blob; this does not copy the pixel allocation or perform layout.
10pub fn raster_image_for_attribute(
11    context: &Context,
12    name: &str,
13    value: &str,
14) -> Option<RasterImageData> {
15    let dom = context.get_data::<DomCtx>()?;
16    let document = dom.doc.try_borrow().ok()?;
17    document.tree().iter().find_map(|(_, node)| {
18        let element = node.element_data()?;
19        if !element.attrs().iter().any(|attribute| {
20            attribute.name.local.as_ref() == name && attribute.value.as_ref() == value
21        }) {
22            return None;
23        }
24        element.raster_image_data().cloned()
25    })
26}