Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / layout / canvas_box.lucb

#==============================================================================================
#
#   canvas_box - Layout::CanvasBox: the box of <canvas>
#
#   DESCRIPTION:
#       Port of LibWeb/Layout/CanvasBox.cpp (lines 1-35) and CanvasBox.h: its auto size is the
#       canvas's width and height attributes.
#
#       Copyright (c) 2020, Andreas Kling <andreas@ladybird.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from Libraries/LibWeb/Layout/CanvasBox.cpp:14 Web::Layout::CanvasBox::CanvasBox.
pub func layout_canvas_box_construct(this: LayoutCanvasBox*, document: DomDocument*, element: HtmlCanvasElement*, style: CssComputedProperties*):
    layout_replaced_box_construct(this.layout_replaced_box(), document, element.dom_element(), style)

## Ported from Libraries/LibWeb/Layout/CanvasBox.h:22 Web::Layout::CanvasBox::dom_node.
pub func layout_canvas_box_dom_node(this: LayoutCanvasBox*) -> HtmlCanvasElement*:
    let element = layout_replaced_box_dom_node(this.layout_replaced_box()) else trap("VERIFY: a canvas box has a DOM node")
    return (HtmlCanvasElement*)element

## Ported from Libraries/LibWeb/Layout/CanvasBox.cpp:21 Web::Layout::CanvasBox::compute_auto_content_box_size (override).
pub func layout_canvas_box_compute_auto_content_box_size_impl(base: LayoutBox*) -> CssSizeWithAspectRatio:
    let this = (LayoutCanvasBox*)base
    let width = gfx.css_pixels_from_unsigned(html_canvas_element_width(layout_canvas_box_dom_node(this)))
    let height = gfx.css_pixels_from_unsigned(html_canvas_element_height(layout_canvas_box_dom_node(this)))
    if gfx.eq_css_pixels_int(width, 0) or gfx.eq_css_pixels_int(height, 0):
        return CssSizeWithAspectRatio(width = width, height = height, aspect_ratio = none)
    var aspect_ratio: gfx.CssPixelFraction = ---
    gfx.css_pixel_fraction_construct_css_pixels(&aspect_ratio, width, height)
    return CssSizeWithAspectRatio(width = width, height = height, aspect_ratio = aspect_ratio)

## Ported from Libraries/LibWeb/Layout/CanvasBox.cpp:30 Web::Layout::CanvasBox::create_paintable (override).
pub func layout_canvas_box_create_paintable_impl(base: LayoutNode*) -> PaintPaintable*?:
    return paint_canvas_paintable_create((LayoutCanvasBox*)base).paint_paintable()