mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-02-04 14:33:47 +00:00
Add Document.gettype
This commit is contained in:
@@ -50,9 +50,9 @@ pub const Opts = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub fn root(doc: *Node.Document, opts: RootOpts, writer: *std.Io.Writer, page: *Page) !void {
|
pub fn root(doc: *Node.Document, opts: RootOpts, writer: *std.Io.Writer, page: *Page) !void {
|
||||||
if (opts.with_base) {
|
if (doc.is(Node.Document.HTMLDocument)) |html_doc| {
|
||||||
if (doc.is(Node.Document.HTMLDocument)) |html_doc| {
|
try writer.writeAll("<!DOCTYPE html>");
|
||||||
try writer.writeAll("<!DOCTYPE html>");
|
if (opts.with_base) {
|
||||||
const parent = if (html_doc.getHead()) |head| head.asNode() else doc.asNode();
|
const parent = if (html_doc.getHead()) |head| head.asNode() else doc.asNode();
|
||||||
const base = try doc.createElement("base", null, page);
|
const base = try doc.createElement("base", null, page);
|
||||||
try base.setAttributeSafe("base", page.url, page);
|
try base.setAttributeSafe("base", page.url, page);
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ const Parser = @import("../parser/Parser.zig");
|
|||||||
const collections = @import("collections.zig");
|
const collections = @import("collections.zig");
|
||||||
const Selector = @import("selector/Selector.zig");
|
const Selector = @import("selector/Selector.zig");
|
||||||
const NodeFilter = @import("NodeFilter.zig");
|
const NodeFilter = @import("NodeFilter.zig");
|
||||||
|
const DocumentType = @import("DocumentType.zig");
|
||||||
const DOMTreeWalker = @import("DOMTreeWalker.zig");
|
const DOMTreeWalker = @import("DOMTreeWalker.zig");
|
||||||
const DOMNodeIterator = @import("DOMNodeIterator.zig");
|
const DOMNodeIterator = @import("DOMNodeIterator.zig");
|
||||||
const DOMImplementation = @import("DOMImplementation.zig");
|
const DOMImplementation = @import("DOMImplementation.zig");
|
||||||
@@ -404,6 +405,10 @@ pub fn elementsFromPoint(self: *Document, x: f64, y: f64, page: *Page) ![]const
|
|||||||
return result.items;
|
return result.items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn getDocType(_: *const Document) ?*DocumentType {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn write(self: *Document, text: []const []const u8, page: *Page) !void {
|
pub fn write(self: *Document, text: []const []const u8, page: *Page) !void {
|
||||||
if (self._type == .xml) {
|
if (self._type == .xml) {
|
||||||
return error.InvalidStateError;
|
return error.InvalidStateError;
|
||||||
@@ -598,6 +603,7 @@ pub const JsApi = struct {
|
|||||||
pub const write = bridge.function(Document.write, .{ .dom_exception = true });
|
pub const write = bridge.function(Document.write, .{ .dom_exception = true });
|
||||||
pub const open = bridge.function(Document.open, .{ .dom_exception = true });
|
pub const open = bridge.function(Document.open, .{ .dom_exception = true });
|
||||||
pub const close = bridge.function(Document.close, .{ .dom_exception = true });
|
pub const close = bridge.function(Document.close, .{ .dom_exception = true });
|
||||||
|
pub const doctype = bridge.accessor(Document.getDocType, null, .{});
|
||||||
|
|
||||||
pub const defaultView = bridge.accessor(struct {
|
pub const defaultView = bridge.accessor(struct {
|
||||||
fn defaultView(_: *const Document, page: *Page) *@import("Window.zig") {
|
fn defaultView(_: *const Document, page: *Page) *@import("Window.zig") {
|
||||||
|
|||||||
@@ -24,11 +24,13 @@ const Page = @import("../Page.zig");
|
|||||||
const Node = @import("Node.zig");
|
const Node = @import("Node.zig");
|
||||||
const Document = @import("Document.zig");
|
const Document = @import("Document.zig");
|
||||||
const Element = @import("Element.zig");
|
const Element = @import("Element.zig");
|
||||||
|
const DocumentType = @import("DocumentType.zig");
|
||||||
const collections = @import("collections.zig");
|
const collections = @import("collections.zig");
|
||||||
|
|
||||||
const HTMLDocument = @This();
|
const HTMLDocument = @This();
|
||||||
|
|
||||||
_proto: *Document,
|
_proto: *Document,
|
||||||
|
_document_type: ?*DocumentType = null,
|
||||||
|
|
||||||
pub fn asDocument(self: *HTMLDocument) *Document {
|
pub fn asDocument(self: *HTMLDocument) *Document {
|
||||||
return self._proto;
|
return self._proto;
|
||||||
@@ -163,6 +165,19 @@ pub fn setCookie(_: *HTMLDocument, cookie_str: []const u8, page: *Page) ![]const
|
|||||||
return cookie_str;
|
return cookie_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn getDocType(self: *HTMLDocument, page: *Page) !*DocumentType {
|
||||||
|
if (self._document_type) |dt| {
|
||||||
|
return dt;
|
||||||
|
}
|
||||||
|
self._document_type = try page._factory.node(DocumentType{
|
||||||
|
._proto = undefined,
|
||||||
|
._name = "html",
|
||||||
|
._public_id = "",
|
||||||
|
._system_id = "",
|
||||||
|
});
|
||||||
|
return self._document_type.?;
|
||||||
|
}
|
||||||
|
|
||||||
pub const JsApi = struct {
|
pub const JsApi = struct {
|
||||||
pub const bridge = js.Bridge(HTMLDocument);
|
pub const bridge = js.Bridge(HTMLDocument);
|
||||||
|
|
||||||
@@ -194,4 +209,5 @@ pub const JsApi = struct {
|
|||||||
pub const location = bridge.accessor(HTMLDocument.getLocation, null, .{ .cache = "location" });
|
pub const location = bridge.accessor(HTMLDocument.getLocation, null, .{ .cache = "location" });
|
||||||
pub const all = bridge.accessor(HTMLDocument.getAll, null, .{});
|
pub const all = bridge.accessor(HTMLDocument.getAll, null, .{});
|
||||||
pub const cookie = bridge.accessor(HTMLDocument.getCookie, HTMLDocument.setCookie, .{});
|
pub const cookie = bridge.accessor(HTMLDocument.getCookie, HTMLDocument.setCookie, .{});
|
||||||
|
pub const doctype = bridge.accessor(HTMLDocument.getDocType, null, .{});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user