Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / page / page.lucb

#==============================================================================================
#
#   page - Web::Page: creating a page and what it keeps alive
#
#   DESCRIPTION:
#       Port of Libraries/LibWeb/Page/Page.cpp lines 37-68 (Page::create, Page::Page,
#       Page::visit_edges), taken ahead of region r28 (which owns Page.cpp) so that pages live
#       in the heap and a full collection can mark them and what they hold (the test pages of
#       every region, the PrincipalHostDefined that visits its page), and lines 160-168
#       (Page::preferred_color_scheme), taken ahead by region r43: every layout node's
#       apply_style asks it. Region r28 ports the rest of Page.cpp and Page.h around these.
#
#       Copyright (c) 2020-2022, Andreas Kling <andreas@ladybird.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from Libraries/LibWeb/Page/Page.cpp:37 Web::Page::create (vm.heap().allocate<Page>(page_client)).
pub func page_create(vm: Vm*, page_client_: PageClient*) -> Page*:
    let heap = vm_heap(vm)
    let this = (Page*)web_heap_allocate_cell(heap, &page_class)
    gc.heap_defer_gc(heap)
    page_construct(this, page_client_)
    gc.heap_undefer_gc(heap)
    return this

## Ported from Libraries/LibWeb/Page/Page.cpp:42 Web::Page::Page, with the default member
## initializers.
pub func page_construct(this: Page*, client: PageClient*):
    page_init_fields(this)
    this.m_current_cursor = gfx.Cursor.standard_cursor(gfx.StandardCursor.arrow)
    this.m_client = client

## Ported from Libraries/LibWeb/Page/Page.cpp:49 Web::Page::visit_edges (override).
pub func page_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
    let this = (Page*)base
    gc.cell_visit_edges_impl(base, visitor)
    gc.cell_visitor_visit_t(visitor, this.m_top_level_traversable)
    gc.cell_visitor_visit_t_2(visitor, this.m_client)
    gc.cell_visitor_visit_t(visitor, this.m_window_rect_observer)
    gc.cell_visitor_visit_t(visitor, this.m_on_pending_dialog_closed)
    gc.cell_visitor_visit_hash_map(visitor, &this.m_pending_clipboard_requests)
    ak.queue_for_each(&this.m_pending_fullscreen_operations, ak.Function1[const PagePendingFullscreenOperation*, unit](call = page_visit_pending_fullscreen_operation, context = visitor))

## Page::visit_edges' visit of one pending fullscreen operation (the for_each lambda).
func page_visit_pending_fullscreen_operation(context: void*?, operation: const PagePendingFullscreenOperation*):
    let visitor = (gc.CellVisitor*)(context else trap("no visitor"))
    match *operation:
        .page_pending_fullscreen_enter(enter_operation):
            gc.cell_visitor_visit_t_2(visitor, enter_operation.element)
            gc.cell_visitor_visit_t_2(visitor, enter_operation.pending_doc)
            gc.cell_visitor_visit_t_2(visitor, enter_operation.promise)
        .page_pending_fullscreen_exit(exit_operation):
            gc.cell_visitor_visit_t_2(visitor, exit_operation.doc)
            gc.cell_visitor_visit_t_2(visitor, exit_operation.promise)

## Ported from Libraries/LibWeb/Page/Page.cpp:160 Web::Page::preferred_color_scheme.
pub func page_preferred_color_scheme(this: Page*) -> CssPreferredColorScheme:
    var preferred_color_scheme = page_client_preferred_color_scheme(this.m_client)

    if preferred_color_scheme == CssPreferredColorScheme.auto:
        let palette = page_palette(this)
        preferred_color_scheme = CssPreferredColorScheme.dark if gfx.palette_is_dark(&palette) else CssPreferredColorScheme.light

    return preferred_color_scheme