Skip to content

Commit ea38845

Browse files
committed
detect HTML document
1 parent 81a0e95 commit ea38845

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/browser/html/elements.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ pub const HTMLImageElement = struct {
640640
pub const prototype = *HTMLImageElement;
641641

642642
pub fn constructor(width: ?u32, height: ?u32, page: *const Page) !*parser.Image {
643-
const element = try parser.documentCreateHTMLElement(parser.documentHTMLToDocument(page.window.document), "img");
643+
const element = try parser.documentCreateElement(parser.documentHTMLToDocument(page.window.document), "img");
644644
const image: *parser.Image = @ptrCast(element);
645645
if (width) |width_| try parser.imageSetWidth(image, width_);
646646
if (height) |height_| try parser.imageSetHeight(image, height_);

src/browser/netsurf.zig

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,20 +2062,20 @@ pub inline fn domImplementationCreateHTMLDocument(title: ?[]const u8) !*Document
20622062
const doc = documentHTMLToDocument(doc_html);
20632063

20642064
// add hierarchy: html, head, body.
2065-
const html = try documentCreateHTMLElement(doc, "html");
2065+
const html = try documentCreateElement(doc, "html");
20662066
_ = try nodeAppendChild(documentToNode(doc), elementToNode(html));
20672067

2068-
const head = try documentCreateHTMLElement(doc, "head");
2068+
const head = try documentCreateElement(doc, "head");
20692069
_ = try nodeAppendChild(elementToNode(html), elementToNode(head));
20702070

20712071
if (title) |t| {
2072-
const htitle = try documentCreateHTMLElement(doc, "title");
2072+
const htitle = try documentCreateElement(doc, "title");
20732073
const txt = try documentCreateTextNode(doc, t);
20742074
_ = try nodeAppendChild(elementToNode(htitle), @as(*Node, @alignCast(@ptrCast(txt))));
20752075
_ = try nodeAppendChild(elementToNode(head), elementToNode(htitle));
20762076
}
20772077

2078-
const body = try documentCreateHTMLElement(doc, "body");
2078+
const body = try documentCreateElement(doc, "body");
20792079
_ = try nodeAppendChild(elementToNode(html), elementToNode(body));
20802080

20812081
return doc_html;
@@ -2156,21 +2156,29 @@ pub inline fn documentCreateDocument(title: ?[]const u8) !*DocumentHTML {
21562156
return doc_html;
21572157
}
21582158

2159-
pub fn documentCreateHTMLElement(doc: *Document, tag_name: []const u8) !*Element {
2159+
fn documentCreateHTMLElement(doc: *Document, tag_name: []const u8) !*Element {
2160+
std.debug.assert(doc.is_html);
2161+
21602162
var elem: ?*Element = undefined;
21612163
const err = c._dom_html_document_create_element(doc, try strFromData(tag_name), &elem);
21622164
try DOMErr(err);
21632165
return elem.?;
21642166
}
21652167

2166-
pub inline fn documentCreateElement(doc: *Document, tag_name: []const u8) !*Element {
2168+
pub fn documentCreateElement(doc: *Document, tag_name: []const u8) !*Element {
2169+
if (doc.is_html) {
2170+
return documentCreateHTMLElement(doc, tag_name);
2171+
}
2172+
21672173
var elem: ?*Element = undefined;
21682174
const err = documentVtable(doc).dom_document_create_element.?(doc, try strFromData(tag_name), &elem);
21692175
try DOMErr(err);
21702176
return elem.?;
21712177
}
21722178

2173-
pub fn documentCreateHTMLElementNS(doc: *Document, ns: []const u8, tag_name: []const u8) !*Element {
2179+
fn documentCreateHTMLElementNS(doc: *Document, ns: []const u8, tag_name: []const u8) !*Element {
2180+
std.debug.assert(doc.is_html);
2181+
21742182
var elem: ?*Element = undefined;
21752183
const err = c._dom_html_document_create_element_ns(
21762184
doc,
@@ -2182,7 +2190,11 @@ pub fn documentCreateHTMLElementNS(doc: *Document, ns: []const u8, tag_name: []c
21822190
return elem.?;
21832191
}
21842192

2185-
pub inline fn documentCreateElementNS(doc: *Document, ns: []const u8, tag_name: []const u8) !*Element {
2193+
pub fn documentCreateElementNS(doc: *Document, ns: []const u8, tag_name: []const u8) !*Element {
2194+
if (doc.is_html) {
2195+
return documentCreateHTMLElementNS(doc, ns, tag_name);
2196+
}
2197+
21862198
var elem: ?*Element = undefined;
21872199
const err = documentVtable(doc).dom_document_create_element_ns.?(
21882200
doc,

0 commit comments

Comments
 (0)