Skip to main content

ReplacedElement

Trait ReplacedElement 

Source
pub trait ReplacedElement: HtmlElement {
    // Required method
    fn intrinsic_sizing(&self) -> IntrinsicSizing;

    // Provided method
    fn notify_intrinsic_size_changed(&self) { ... }
}
Expand description

Shared behavior for replaced elements (img, video, canvas, iframe, svg).

Chrome equivalent: the virtual GetNaturalDimensions() on LayoutReplaced.

§Implementors

  • HtmlImageElement — intrinsic size from decoded image
  • HtmlVideoElement — intrinsic size from video dimensions
  • HtmlCanvasElement — intrinsic size from canvas width/height attributes

§How it connects to layout

During layout, DocumentLayoutView checks item_is_replaced on the Taffy style and reads intrinsic_sizing() for natural dimensions.

Required Methods§

Source

fn intrinsic_sizing(&self) -> IntrinsicSizing

Get the element’s intrinsic (natural) dimensions.

Chrome equivalent: LayoutReplaced::GetNaturalDimensions().

Returns the current intrinsic size. May change when the external resource loads (image decode complete, video metadata received).

Provided Methods§

Source

fn notify_intrinsic_size_changed(&self)

Notify that intrinsic dimensions have changed.

Chrome equivalent: LayoutReplaced::NaturalSizeChanged(). Called when the underlying resource changes size (e.g., image loaded, video resolution changed). Invalidates layout.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§