mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-15 15:58:57 +00:00
fix svgElement + allow base tags
This commit is contained in:
@@ -241,18 +241,23 @@ pub fn htmlElement(self: *Factory, child: anytype) !*@TypeOf(child) {
|
||||
|
||||
pub fn svgElement(self: *Factory, tag_name: []const u8, child: anytype) !*@TypeOf(child) {
|
||||
const allocator = self._slab.allocator();
|
||||
const ChildT = @TypeOf(child);
|
||||
|
||||
// will never allocate, can't fail
|
||||
const tag_name_str = String.init(self._page.arena, tag_name, .{}) catch unreachable;
|
||||
if (ChildT == Element.Svg) {
|
||||
return self.element(child);
|
||||
}
|
||||
|
||||
const chain = try PrototypeChain(
|
||||
&.{ EventTarget, Node, Element, Element.Svg, @TypeOf(child) },
|
||||
&.{ EventTarget, Node, Element, Element.Svg, ChildT },
|
||||
).allocate(allocator);
|
||||
|
||||
chain.setRoot(EventTarget.Type);
|
||||
chain.setMiddle(1, Node.Type);
|
||||
chain.setMiddle(2, Element.Type);
|
||||
|
||||
// will never allocate, can't fail
|
||||
const tag_name_str = String.init(self._page.arena, tag_name, .{}) catch unreachable;
|
||||
|
||||
// Manually set Element.Svg with the tag_name
|
||||
chain.set(3, .{
|
||||
._proto = chain.get(2),
|
||||
|
||||
@@ -1177,22 +1177,21 @@ pub fn createElement(self: *Page, ns_: ?[]const u8, name: []const u8, attribute_
|
||||
else => {},
|
||||
}
|
||||
|
||||
// TODO: uncomment
|
||||
// if (namespace == .svg) {
|
||||
// const tag_name = try String.init(self.arena, name, .{});
|
||||
// if (std.ascii.eqlIgnoreCase(name, "svg")) {
|
||||
// return self.createSvgElementT(Element.Svg, name, attribute_iterator, .{
|
||||
// ._proto = undefined,
|
||||
// ._type = .svg,
|
||||
// ._tag_name = tag_name,
|
||||
// });
|
||||
// }
|
||||
if (namespace == .svg) {
|
||||
const tag_name = try String.init(self.arena, name, .{});
|
||||
if (std.ascii.eqlIgnoreCase(name, "svg")) {
|
||||
return self.createSvgElementT(Element.Svg, name, attribute_iterator, .{
|
||||
._proto = undefined,
|
||||
._type = .svg,
|
||||
._tag_name = tag_name,
|
||||
});
|
||||
}
|
||||
|
||||
// // Other SVG elements (rect, circle, text, g, etc.)
|
||||
// const lower = std.ascii.lowerString(&self.buf, name);
|
||||
// const tag = std.meta.stringToEnum(Element.Tag, lower) orelse .unknown;
|
||||
// return self.createSvgElementT(Element.Svg.Generic, name, attribute_iterator, .{ ._proto = undefined, ._tag = tag });
|
||||
// }
|
||||
// Other SVG elements (rect, circle, text, g, etc.)
|
||||
const lower = std.ascii.lowerString(&self.buf, name);
|
||||
const tag = std.meta.stringToEnum(Element.Tag, lower) orelse .unknown;
|
||||
return self.createSvgElementT(Element.Svg.Generic, name, attribute_iterator, .{ ._proto = undefined, ._tag = tag });
|
||||
}
|
||||
|
||||
const tag_name = try String.init(self.arena, name, .{});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user