Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / html / html_style_element.lucb

#==============================================================================================
#
#   html_style_element - HTML::HTMLStyleElement: <style> and its style block
#
#   DESCRIPTION:
#       Port of LibWeb/HTML/HTMLStyleElement.cpp (lines 1-117) and HTMLStyleElement.h: the
#       constructor (which moves the mixin tables to HTMLStyleElement's, as C++'s vptrs move,
#       and sets up the DOM::StyleElementBase mixin), initialize, the steps that update the
#       style block (DOM::StyleElementBase, region r18) when the children, connectedness or
#       type change, the media attribute, the disabled IDL attribute and the script-blocking
#       style sheet answer.
#
#==============================================================================================

## Ported from HTMLStyleElement.cpp:18 Web::HTML::HTMLStyleElement::HTMLStyleElement.
pub func html_style_element_construct(this: HtmlStyleElement*, document: DomDocument*, qualified_name: DomQualifiedName):
    html_element_construct(this.html_element(), document, qualified_name)
    # The vptrs of the mixin bases move to HTMLStyleElement's tables; the DOM::StyleElementBase base
    # (default-constructed: no sheet, no list, no load event delayer) gets its table.
    let element = this.html_element()
    element.element.slottable_mixin.vtable = &html_style_element_slottable_mixin_vtable
    element.element.aria_mixin.vtable = &html_style_element_aria_mixin_vtable
    element.element.animatable.vtable = &html_style_element_animatable_vtable
    element.global_event_handlers.vtable = &html_style_element_global_event_handlers_vtable
    element.form_associated_element.vtable = &html_style_element_form_associated_element_vtable
    this.style_element_base.vtable = &html_style_element_style_element_base_vtable
    this.style_element_base.class_id = this.cell().class_id

## Ported from HTMLStyleElement.cpp:25 Web::HTML::HTMLStyleElement::initialize (override).
pub func html_style_element_initialize_impl(base: JsCell*, realm: Realm*):
    web_set_prototype_for_interface(base, realm, BindInterfaceName.html_style_element)
    html_element_initialize_impl(base, realm)

## Ported from HTMLStyleElement.cpp:31 Web::HTML::HTMLStyleElement::visit_edges (override).
pub func html_style_element_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
    let this = (HtmlStyleElement*)base
    html_element_visit_edges_impl(base, visitor)
    dom_style_element_base_visit_style_element_edges(&this.style_element_base, visitor)

## Ported from HTMLStyleElement.cpp:37 Web::HTML::HTMLStyleElement::children_changed (override).
pub func html_style_element_children_changed_impl(base: DomNode*, metadata: DomNodeChildrenChangedMetadata):
    let this = (HtmlStyleElement*)base
    dom_element_children_changed_impl(base, metadata)
    dom_style_element_base_update_a_style_block(&this.style_element_base)

## Ported from HTMLStyleElement.cpp:43 Web::HTML::HTMLStyleElement::inserted (override).
pub func html_style_element_inserted_impl(base: DomNode*):
    let this = (HtmlStyleElement*)base
    html_element_inserted_impl(base)
    dom_style_element_base_update_a_style_block(&this.style_element_base)

## Ported from HTMLStyleElement.cpp:49 Web::HTML::HTMLStyleElement::removed_from (override).
pub func html_style_element_removed_from_impl(base: DomNode*, is_subtree_root: DomNodeIsSubtreeRoot, old_ancestor: DomNode*?, old_root: DomNode*):
    let this = (HtmlStyleElement*)base
    html_element_removed_from_impl(base, is_subtree_root, old_ancestor, old_root)
    dom_style_element_base_update_a_style_block(&this.style_element_base)

## Ported from HTMLStyleElement.cpp:55 Web::HTML::HTMLStyleElement::attribute_changed (override).
pub func html_style_element_attribute_changed_impl(base: DomElement*, name: ak.FlyString, old_value: ak.String?, value: ak.String?, namespace_: ak.FlyString?):
    let this = (HtmlStyleElement*)base
    html_element_attribute_changed_impl(base, name, old_value, value, namespace_)

    if ak.fly_string_eq_fly_string(&name, &html_attribute_names_media):
        if let sheet = dom_style_element_base_sheet(&this.style_element_base):
            css_style_sheet_set_media(sheet.css_style_sheet(), value else ak.string_new())
    elif ak.fly_string_eq_fly_string(&name, &html_attribute_names_type):
        dom_style_element_base_update_a_style_block(&this.style_element_base)

## Ported from HTMLStyleElement.cpp:68 Web::HTML::HTMLStyleElement::disabled.
# https://html.spec.whatwg.org/multipage/semantics.html#dom-style-disabled
pub func html_style_element_disabled(this: HtmlStyleElement*) -> bool:
    # 1. If this does not have an associated CSS style sheet, return false.
    let sheet = dom_style_element_base_sheet(&this.style_element_base) else return false

    # 2. If this's associated CSS style sheet's disabled flag is set, return true.
    if css_style_sheet_disabled(sheet.css_style_sheet()):
        return true

    # 3. Return false.
    return false

## Ported from HTMLStyleElement.cpp:83 Web::HTML::HTMLStyleElement::set_disabled.
# https://html.spec.whatwg.org/multipage/semantics.html#dom-style-disabled
pub func html_style_element_set_disabled(this: HtmlStyleElement*, disabled: bool):
    # 1. If this does not have an associated CSS style sheet, return.
    let sheet = dom_style_element_base_sheet(&this.style_element_base) else return

    # 2. If the given value is true, set this's associated CSS style sheet's disabled flag.
    #    Otherwise, unset this's associated CSS style sheet's disabled flag.
    css_style_sheet_set_disabled(sheet.css_style_sheet(), disabled)

## Ported from HTMLStyleElement.cpp:95 Web::HTML::HTMLStyleElement::contributes_a_script_blocking_style_sheet (override).
# https://html.spec.whatwg.org/multipage/semantics.html#contributes-a-script-blocking-style-sheet
pub func html_style_element_contributes_a_script_blocking_style_sheet_impl(base: DomElement*) -> bool:
    # An element el in the context of a Document of an HTML parser or XML parser
    # contributes a script-blocking style sheet if all of the following are true:

    # FIXME: el was created by that Document's parser.

    # el is either a style element or a link element that was an external resource link that contributes to the styling processing model when the el was created by the parser.
    # NOTE: This is a style element, so all good!

    # FIXME: el's media attribute's value matches the environment.

    # FIXME: el's style sheet was enabled when the element was created by the parser.

    # FIXME: The last time the event loop reached step 1, el's root was that Document.

    # FIXME: The user agent hasn't given up on loading that particular style sheet yet.
    #        A user agent may give up on loading a style sheet at any time.

    return false

## Ported from HTMLStyleElement.h:38 Web::HTML::HTMLStyleElement::is_html_style_element (override).
pub func html_style_element_is_html_style_element_impl(base: DomNode*) -> bool:
    return true

## Ported from HTMLStyleElement.h:41 Web::HTML::HTMLStyleElement::as_element (override).
pub func html_style_element_as_element_impl(base: DomStyleElementBase*) -> DomElement*:
    return (DomElement*)((u8*)base - memory.offset_of(HtmlStyleElement, style_element_base))