dymokomi/luce-browser-engine
Source of release 0.6.1
0.6.1 / src / web / css / screen.lucb
#==============================================================================================
#
# screen - CSS::Screen: window.screen, the Web-exposed screen area and its properties
#
# DESCRIPTION:
# Port of LibWeb/CSS/Screen.cpp (lines 1-119) and the inline member of Screen.h
# (line 43). The areas come from the Page; the orientation object is created on demand.
#
# Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
# SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================
# mark: Construction ============================================================================
## Ported from Libraries/LibWeb/CSS/Screen.cpp:20 Web::CSS::Screen::create.
pub func css_screen_create(window: HtmlWindow*) -> CssScreen*:
return realm_create_css_screen(bind_platform_object_realm(window.bind_platform_object()), window)
## Ported from Libraries/LibWeb/CSS/Screen.cpp:25 Web::CSS::Screen::Screen.
pub func css_screen_construct(this: CssScreen*, window: HtmlWindow*):
dom_event_target_construct(this.dom_event_target(), bind_platform_object_realm(window.bind_platform_object()))
this.m_window = window
## Ported from Libraries/LibWeb/CSS/Screen.cpp:31 Web::CSS::Screen::initialize (override).
pub func css_screen_initialize_impl(base: JsCell*, realm: Realm*):
web_set_prototype_for_interface(base, realm, BindInterfaceName.screen)
dom_event_target_initialize_impl(base, realm)
## Ported from Libraries/LibWeb/CSS/Screen.cpp:37 Web::CSS::Screen::visit_edges (override).
pub func css_screen_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
let this = (CssScreen*)base
dom_event_target_visit_edges_impl(base, visitor)
gc.cell_visitor_visit_t(visitor, this.m_window)
# visitor.visit(m_orientation): ScreenOrientation is opaque until phase 3 (no Cell header to visit).
## Ported from Libraries/LibWeb/CSS/Screen.h:43 Web::CSS::Screen::window.
pub func css_screen_window(this: CssScreen*) -> HtmlWindow*:
return this.m_window
# mark: The Screen interface ====================================================================
## Ported from Libraries/LibWeb/CSS/Screen.cpp:45 Web::CSS::Screen::width.
# https://drafts.csswg.org/cssom-view-1/#dom-screen-width
pub func css_screen_width(this: CssScreen*) -> i32:
# The width attribute must return the width of the Web-exposed screen area.
let area = page_web_exposed_screen_area(html_window_page(css_screen_window(this)))
let width = gfx.css_pixel_rect_width(&area)
return gfx.css_pixels_to_int_const(&width)
## Ported from Libraries/LibWeb/CSS/Screen.cpp:52 Web::CSS::Screen::height.
# https://drafts.csswg.org/cssom-view-1/#dom-screen-height
pub func css_screen_height(this: CssScreen*) -> i32:
# The height attribute must return the height of the Web-exposed screen area.
let area = page_web_exposed_screen_area(html_window_page(css_screen_window(this)))
let height = gfx.css_pixel_rect_height(&area)
return gfx.css_pixels_to_int_const(&height)
## Ported from Libraries/LibWeb/CSS/Screen.cpp:59 Web::CSS::Screen::avail_width.
# https://drafts.csswg.org/cssom-view-1/#dom-screen-availwidth
pub func css_screen_avail_width(this: CssScreen*) -> i32:
# The availWidth attribute must return the width of the Web-exposed available screen area.
let area = page_web_exposed_available_screen_area(html_window_page(css_screen_window(this)))
let width = gfx.css_pixel_rect_width(&area)
return gfx.css_pixels_to_int_const(&width)
## Ported from Libraries/LibWeb/CSS/Screen.cpp:66 Web::CSS::Screen::avail_height.
# https://drafts.csswg.org/cssom-view-1/#dom-screen-availheight
pub func css_screen_avail_height(this: CssScreen*) -> i32:
# The availHeight attribute must return the height of the Web-exposed available screen area.
let area = page_web_exposed_available_screen_area(html_window_page(css_screen_window(this)))
let height = gfx.css_pixel_rect_height(&area)
return gfx.css_pixels_to_int_const(&height)
## Ported from Libraries/LibWeb/CSS/Screen.cpp:73 Web::CSS::Screen::color_depth.
# https://drafts.csswg.org/cssom-view-1/#dom-screen-colordepth
pub func css_screen_color_depth(this: CssScreen*) -> u32:
# The colorDepth and pixelDepth attributes should return the number of bits allocated to colors for a pixel in
# the output device, excluding the alpha channel.
return 24
## Ported from Libraries/LibWeb/CSS/Screen.cpp:81 Web::CSS::Screen::pixel_depth.
# https://drafts.csswg.org/cssom-view-1/#dom-screen-pixeldepth
pub func css_screen_pixel_depth(this: CssScreen*) -> u32:
# The colorDepth and pixelDepth attributes should return the number of bits allocated to colors for a pixel in
# the output device, excluding the alpha channel.
return 24
## Ported from Libraries/LibWeb/CSS/Screen.cpp:88 Web::CSS::Screen::orientation.
pub func css_screen_orientation(this: CssScreen*) -> CssScreenOrientation*:
if this.m_orientation == none:
this.m_orientation = css_screen_orientation_create(bind_platform_object_realm(this.bind_platform_object()))
return this.m_orientation else trap("unreachable")
## Ported from Libraries/LibWeb/CSS/Screen.cpp:96 Web::CSS::Screen::is_extended.
# https://w3c.github.io/window-management/#dom-screen-isextended
pub func css_screen_is_extended(this: CssScreen*) -> bool:
# 1. If this's relevant global object's associated Document is not allowed to use
# the policy-controlled feature named "window-management", return false.
if not dom_document_is_allowed_to_use_feature(html_window_associated_document(css_screen_window(this)), DomPolicyControlledFeature.window_management):
return false
# 2. Return true if the device has more than one screen, and false otherwise.
return page_client_screen_count(page_client(html_window_page(css_screen_window(this)))) > 1
## Ported from Libraries/LibWeb/CSS/Screen.cpp:108 Web::CSS::Screen::set_onchange.
# https://w3c.github.io/window-management/#dom-screen-onchange
pub func css_screen_set_onchange(this: CssScreen*, event_handler: IdlCallbackType*?):
dom_event_target_set_event_handler_attribute(this.dom_event_target(), html_event_names_change, event_handler)
## Ported from Libraries/LibWeb/CSS/Screen.cpp:114 Web::CSS::Screen::onchange.
# https://w3c.github.io/window-management/#dom-screen-onchange
pub func css_screen_onchange(this: CssScreen*) -> IdlCallbackType*?:
return dom_event_target_event_handler_attribute(this.dom_event_target(), html_event_names_change)