Merge pull request #1493 from lightpanda-io/document_visibility

Add Document.hidden and visibilityState properties
This commit is contained in:
Pierre Tachoire
2026-02-08 10:42:33 +01:00
committed by GitHub
2 changed files with 15 additions and 0 deletions

View File

@@ -13,6 +13,8 @@
testing.expectEqual(undefined, document.getCurrentScript);
testing.expectEqual("http://127.0.0.1:9582/src/browser/tests/document/document.html", document.URL);
testing.expectEqual(window, document.defaultView);
testing.expectEqual(false, document.hidden);
testing.expectEqual("visible", document.visibilityState);
</script>
<script id=headAndbody>

View File

@@ -796,6 +796,17 @@ pub fn setAdoptedStyleSheets(self: *Document, sheets: js.Object) !void {
self._adopted_style_sheets = try sheets.persist();
}
pub fn getHidden(_: *const Document) bool {
// it's hidden when, for example, the decive is locked, or user is on a
// a different tab.
return false;
}
pub fn getVisibilityState(_: *const Document) []const u8 {
// See getHidden above, possible options are "visible" or "hidden"
return "visible";
}
// Validates that nodes can be inserted into a Document, respecting Document constraints:
// - At most one Element child
// - At most one DocumentType child
@@ -991,6 +1002,8 @@ pub const JsApi = struct {
pub const lastElementChild = bridge.accessor(Document.getLastElementChild, null, .{});
pub const childElementCount = bridge.accessor(Document.getChildElementCount, null, .{});
pub const adoptedStyleSheets = bridge.accessor(Document.getAdoptedStyleSheets, Document.setAdoptedStyleSheets, .{});
pub const hidden = bridge.accessor(Document.getHidden, null, .{});
pub const visibilityState = bridge.accessor(Document.getVisibilityState, null, .{});
pub const defaultView = bridge.accessor(struct {
fn defaultView(_: *const Document, page: *Page) *@import("Window.zig") {