dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / css / edge_rect.lucb
#==============================================================================================
#
# edge_rect - EdgeRect: the four edges of a rect() shape
#
# DESCRIPTION:
# Port of LibWeb/CSS/EdgeRect.cpp (lines 1-39). The defaulted operator== of EdgeRect.h
# is Luce's structural `==` (its four LengthOrAutos hold no pointers).
#
# Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
# Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
# Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
# Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
# SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================
## Ported from Libraries/LibWeb/CSS/EdgeRect.cpp:15 Web::CSS::EdgeRect::resolved.
# https://www.w3.org/TR/CSS2/visufx.html#value-def-shape
pub func css_edge_rect_resolved(this: const CssEdgeRect*, border_box: gfx.CssPixelRect) -> gfx.CssPixelRect:
# In CSS 2.1, the only valid <shape> value is: rect(<top>, <right>, <bottom>, <left>) where
# <top> and <bottom> specify offsets from the top border edge of the box, and <right>, and
# <left> specify offsets from the left border edge of the box.
# The value 'auto' means that a given edge of the clipping region will be the same as the edge
# of the element's generated border box (i.e., 'auto' means the same as '0' for <top> and
# <left>, the same as the used value of the height plus the sum of vertical padding and border
# widths for <bottom>, and the same as the used value of the width plus the sum of the
# horizontal padding and border widths for <right>, such that four 'auto' values result in the
# clipping region being the same as the element's border box).
let zero = gfx.css_pixels_from_int(0)
let left = gfx.css_pixel_rect_left(&border_box).add(zero if css_length_or_auto_is_auto(&this.left_edge) else css_length_absolute_length_to_px_of(css_length_or_auto_length(&this.left_edge)))
let top = gfx.css_pixel_rect_top(&border_box).add(zero if css_length_or_auto_is_auto(&this.top_edge) else css_length_absolute_length_to_px_of(css_length_or_auto_length(&this.top_edge)))
let right = gfx.css_pixel_rect_left(&border_box).add(gfx.css_pixel_rect_width(&border_box) if css_length_or_auto_is_auto(&this.right_edge) else css_length_absolute_length_to_px_of(css_length_or_auto_length(&this.right_edge)))
let bottom = gfx.css_pixel_rect_top(&border_box).add(gfx.css_pixel_rect_height(&border_box) if css_length_or_auto_is_auto(&this.bottom_edge) else css_length_absolute_length_to_px_of(css_length_or_auto_length(&this.bottom_edge)))
var result: gfx.CssPixelRect = ---
gfx.css_pixel_rect_construct_css_pixels(&result, left, top, right.sub(left), bottom.sub(top))
return result
## `length.absolute_length_to_px()` on a Length value.
func css_length_absolute_length_to_px_of(length: CssLength) -> gfx.CssPixels:
return css_length_absolute_length_to_px(&length)