Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / layout / video_box.lucb

#==============================================================================================
#
#   video_box - Layout::VideoBox: the box of <video>
#
#   DESCRIPTION:
#       Port of LibWeb/Layout/VideoBox.cpp (lines 1-52) and VideoBox.h: children only with the
#       controls' shadow tree, the natural size of the video and the VideoPaintable.
#
#       Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from Libraries/LibWeb/Layout/VideoBox.cpp:16 Web::Layout::VideoBox::VideoBox.
pub func layout_video_box_construct(this: LayoutVideoBox*, document: DomDocument*, element: DomElement*, style: CssComputedProperties*):
    layout_replaced_box_construct(this.layout_replaced_box(), document, element, style)

## Ported from Libraries/LibWeb/Layout/VideoBox.cpp:21 Web::Layout::VideoBox::dom_node.
pub func layout_video_box_dom_node(this: LayoutVideoBox*) -> HtmlVideoElement*:
    let element = layout_replaced_box_dom_node(this.layout_replaced_box()) else trap("VERIFY: a video box has a DOM node")
    return (HtmlVideoElement*)element

## Ported from Libraries/LibWeb/Layout/VideoBox.cpp:26 Web::Layout::VideoBox::dom_node.
pub func layout_video_box_dom_node_const(this: LayoutVideoBox*) -> HtmlVideoElement*:
    return layout_video_box_dom_node(this)

## Ported from Libraries/LibWeb/Layout/VideoBox.cpp:31 Web::Layout::VideoBox::can_have_children (override).
pub func layout_video_box_can_have_children_impl(base: LayoutNode*) -> bool:
    # If we allow children when controls are disabled, innerText may be non-empty.
    return dom_element_shadow_root(layout_video_box_dom_node((LayoutVideoBox*)base).dom_element()) != none

## Ported from Libraries/LibWeb/Layout/VideoBox.cpp:37 Web::Layout::VideoBox::natural_size (override).
pub func layout_video_box_natural_size_impl(base: LayoutBox*) -> CssSizeWithAspectRatio:
    let natural_size = html_video_element_natural_element_size(layout_video_box_dom_node((LayoutVideoBox*)base)) else return CssSizeWithAspectRatio()
    if gfx.css_pixel_size_is_empty(&natural_size):
        return CssSizeWithAspectRatio(width = gfx.CssPixels.from_int(0), height = gfx.CssPixels.from_int(0), aspect_ratio = none)
    let width = gfx.css_pixel_size_width(&natural_size)
    let height = gfx.css_pixel_size_height(&natural_size)
    return CssSizeWithAspectRatio(width = width, height = height, aspect_ratio = width.div(height))

## Ported from Libraries/LibWeb/Layout/VideoBox.cpp:47 Web::Layout::VideoBox::create_paintable (override).
pub func layout_video_box_create_paintable_impl(base: LayoutNode*) -> PaintPaintable*?:
    return paint_video_paintable_create((LayoutVideoBox*)base).paint_paintable()