mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-16 00:08:59 +00:00
netsurf: first adaptations
Signed-off-by: Francis Bouvier <francis.bouvier@gmail.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const parser = @import("../parser.zig");
|
const parser = @import("../netsurf.zig");
|
||||||
|
|
||||||
const Node = @import("node.zig").Node;
|
const Node = @import("node.zig").Node;
|
||||||
const Element = @import("element.zig").Element;
|
const Element = @import("element.zig").Element;
|
||||||
@@ -15,19 +15,8 @@ pub const Document = struct {
|
|||||||
// return .{};
|
// return .{};
|
||||||
// }
|
// }
|
||||||
|
|
||||||
pub fn getElementById(self: *parser.Document, elem: *parser.Element, id: []const u8) ?*parser.Element {
|
pub fn getElementById(self: *parser.Document, id: []const u8) ?*parser.Element {
|
||||||
const collection = parser.collectionInit(self, 1);
|
return parser.documentGetElementById(self, id);
|
||||||
defer parser.collectionDeinit(collection);
|
|
||||||
const case_sensitve = true;
|
|
||||||
parser.elementsByAttr(elem, collection, "id", id, case_sensitve) catch |err| {
|
|
||||||
std.debug.print("getElementById error: {s}\n", .{@errorName(err)});
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
if (collection.array.length == 0) {
|
|
||||||
// no results
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return parser.collectionElement(collection, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// JS funcs
|
// JS funcs
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const parser = @import("../parser.zig");
|
const parser = @import("../netsurf.zig");
|
||||||
|
|
||||||
const Node = @import("node.zig").Node;
|
const Node = @import("node.zig").Node;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const parser = @import("../parser.zig");
|
const parser = @import("../netsurf.zig");
|
||||||
|
|
||||||
pub const EventTarget = struct {
|
pub const EventTarget = struct {
|
||||||
pub const Self = parser.EventTarget;
|
pub const Self = parser.EventTarget;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const parser = @import("../parser.zig");
|
const parser = @import("../netsurf.zig");
|
||||||
|
|
||||||
const EventTarget = @import("event_target.zig").EventTarget;
|
const EventTarget = @import("event_target.zig").EventTarget;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const parser = @import("../parser.zig");
|
const parser = @import("../netsurf.zig");
|
||||||
|
|
||||||
const jsruntime = @import("jsruntime");
|
const jsruntime = @import("jsruntime");
|
||||||
const Case = jsruntime.test_utils.Case;
|
const Case = jsruntime.test_utils.Case;
|
||||||
@@ -22,12 +22,13 @@ pub const HTMLDocument = struct {
|
|||||||
return parser.documentHTMLBody(self);
|
return parser.documentHTMLBody(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn _getElementById(self: *parser.DocumentHTML, id: []u8) ?*parser.HTMLElement {
|
pub fn _getElementById(self: *parser.DocumentHTML, id: []u8) ?*parser.ElementHTML {
|
||||||
const body_html = parser.documentHTMLBody(self);
|
const doc = parser.documentHTMLToDocument(self);
|
||||||
const body_dom = @as(*parser.Element, @ptrCast(body_html));
|
const elem = parser.documentGetElementById(doc, id);
|
||||||
const doc_dom = @as(*parser.Document, @ptrCast(self));
|
if (elem) |value| {
|
||||||
const elem_dom = Document.getElementById(doc_dom, body_dom, id);
|
return @as(*parser.ElementHTML, @ptrCast(value));
|
||||||
return @as(*parser.HTMLElement, @ptrCast(elem_dom));
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn _createElement(self: *parser.DocumentHTML, tag_name: []const u8) E.HTMLElements {
|
pub fn _createElement(self: *parser.DocumentHTML, tag_name: []const u8) E.HTMLElements {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const parser = @import("../parser.zig");
|
const parser = @import("../netsurf.zig");
|
||||||
const generate = @import("../generate.zig");
|
const generate = @import("../generate.zig");
|
||||||
|
|
||||||
const Element = @import("../dom/element.zig").Element;
|
const Element = @import("../dom/element.zig").Element;
|
||||||
@@ -7,7 +7,7 @@ const Element = @import("../dom/element.zig").Element;
|
|||||||
// --------------
|
// --------------
|
||||||
|
|
||||||
pub const HTMLElement = struct {
|
pub const HTMLElement = struct {
|
||||||
pub const Self = parser.HTMLElement;
|
pub const Self = parser.ElementHTML;
|
||||||
pub const prototype = *Element;
|
pub const prototype = *Element;
|
||||||
pub const mem_guarantied = true;
|
pub const mem_guarantied = true;
|
||||||
};
|
};
|
||||||
@@ -455,7 +455,7 @@ pub const HTMLVideoElement = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub fn ElementToHTMLElementInterface(elem: *parser.Element) HTMLElements {
|
pub fn ElementToHTMLElementInterface(elem: *parser.Element) HTMLElements {
|
||||||
const tag = parser.nodeTag(parser.elementNode(elem));
|
const tag = parser.elementHTMLGetTagType(@as(*parser.ElementHTML, @ptrCast(elem)));
|
||||||
return switch (tag) {
|
return switch (tag) {
|
||||||
.a => .{ .HTMLAnchorElement = @as(*parser.Anchor, @ptrCast(elem)) },
|
.a => .{ .HTMLAnchorElement = @as(*parser.Anchor, @ptrCast(elem)) },
|
||||||
.area => .{ .HTMLAreaElement = @as(*parser.Area, @ptrCast(elem)) },
|
.area => .{ .HTMLAreaElement = @as(*parser.Area, @ptrCast(elem)) },
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const std = @import("std");
|
|||||||
|
|
||||||
const jsruntime = @import("jsruntime");
|
const jsruntime = @import("jsruntime");
|
||||||
|
|
||||||
const parser = @import("parser.zig");
|
const parser = @import("netsurf.zig");
|
||||||
const DOM = @import("dom.zig");
|
const DOM = @import("dom.zig");
|
||||||
|
|
||||||
const html_test = @import("html_test.zig").html;
|
const html_test = @import("html_test.zig").html;
|
||||||
@@ -55,9 +55,6 @@ pub fn main() !void {
|
|||||||
defer vm.deinit();
|
defer vm.deinit();
|
||||||
|
|
||||||
// document
|
// document
|
||||||
doc = parser.documentHTMLInit();
|
|
||||||
defer parser.documentHTMLDeinit(doc);
|
|
||||||
try parser.documentHTMLParse(doc, html_test);
|
|
||||||
|
|
||||||
// remove socket file of internal server
|
// remove socket file of internal server
|
||||||
// reuse_address (SO_REUSEADDR flag) does not seems to work on unix socket
|
// reuse_address (SO_REUSEADDR flag) does not seems to work on unix socket
|
||||||
@@ -68,6 +65,9 @@ pub fn main() !void {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
var f = "test.html".*;
|
||||||
|
doc = parser.documentHTMLParse(&f);
|
||||||
|
// TODO: defer doc?
|
||||||
|
|
||||||
// alloc
|
// alloc
|
||||||
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const std = @import("std");
|
|||||||
|
|
||||||
const jsruntime = @import("jsruntime");
|
const jsruntime = @import("jsruntime");
|
||||||
|
|
||||||
const parser = @import("parser.zig");
|
const parser = @import("netsurf.zig");
|
||||||
const DOM = @import("dom.zig");
|
const DOM = @import("dom.zig");
|
||||||
|
|
||||||
const html_test = @import("html_test.zig").html;
|
const html_test = @import("html_test.zig").html;
|
||||||
@@ -32,9 +32,9 @@ pub fn main() !void {
|
|||||||
const apis = jsruntime.compile(DOM.Interfaces);
|
const apis = jsruntime.compile(DOM.Interfaces);
|
||||||
|
|
||||||
// document
|
// document
|
||||||
doc = parser.documentHTMLInit();
|
var f = "test.html".*;
|
||||||
defer parser.documentHTMLDeinit(doc);
|
doc = parser.documentHTMLParse(&f);
|
||||||
try parser.documentHTMLParse(doc, html_test);
|
// TODO: defer doc?
|
||||||
|
|
||||||
// create JS vm
|
// create JS vm
|
||||||
const vm = jsruntime.VM.init();
|
const vm = jsruntime.VM.init();
|
||||||
|
|||||||
@@ -3,12 +3,10 @@ const std = @import("std");
|
|||||||
const jsruntime = @import("jsruntime");
|
const jsruntime = @import("jsruntime");
|
||||||
const generate = @import("generate.zig");
|
const generate = @import("generate.zig");
|
||||||
|
|
||||||
const parser = @import("parser.zig");
|
const parser = @import("netsurf.zig");
|
||||||
const DOM = @import("dom.zig");
|
const DOM = @import("dom.zig");
|
||||||
const testExecFn = @import("html/document.zig").testExecFn;
|
const testExecFn = @import("html/document.zig").testExecFn;
|
||||||
|
|
||||||
const html_test = @import("html_test.zig").html;
|
|
||||||
|
|
||||||
var doc: *parser.DocumentHTML = undefined;
|
var doc: *parser.DocumentHTML = undefined;
|
||||||
|
|
||||||
fn testsExecFn(
|
fn testsExecFn(
|
||||||
@@ -38,9 +36,8 @@ test {
|
|||||||
const apis = jsruntime.compile(DOM.Interfaces);
|
const apis = jsruntime.compile(DOM.Interfaces);
|
||||||
|
|
||||||
// document
|
// document
|
||||||
doc = parser.documentHTMLInit();
|
var f = "test.html".*;
|
||||||
defer parser.documentHTMLDeinit(doc);
|
doc = parser.documentHTMLParse(&f);
|
||||||
try parser.documentHTMLParse(doc, html_test);
|
|
||||||
|
|
||||||
// create JS vm
|
// create JS vm
|
||||||
const vm = jsruntime.VM.init();
|
const vm = jsruntime.VM.init();
|
||||||
|
|||||||
Reference in New Issue
Block a user