Skip to content

Commit 8d6ee42

Browse files
committed
anchor: follow up
1 parent df6a905 commit 8d6ee42

File tree

2 files changed

+93
-1
lines changed

2 files changed

+93
-1
lines changed

src/html/elements.zig

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,39 @@ pub const HTMLAnchorElement = struct {
154154
}
155155

156156
pub fn set_href(self: *parser.Anchor, href: []const u8) !void {
157-
return try parser.anchorSetTarget(self, href);
157+
return try parser.anchorSetHref(self, href);
158+
}
159+
160+
pub fn get_hreflang(self: *parser.Anchor) ![]const u8 {
161+
return try parser.anchorGetHrefLang(self);
162+
}
163+
164+
pub fn set_hreflang(self: *parser.Anchor, href: []const u8) !void {
165+
return try parser.anchorSetHrefLang(self, href);
166+
}
167+
168+
pub fn get_type(self: *parser.Anchor) ![]const u8 {
169+
return try parser.anchorGetType(self);
170+
}
171+
172+
pub fn set_type(self: *parser.Anchor, t: []const u8) !void {
173+
return try parser.anchorSetType(self, t);
174+
}
175+
176+
pub fn get_rel(self: *parser.Anchor) ![]const u8 {
177+
return try parser.anchorGetRel(self);
178+
}
179+
180+
pub fn set_rel(self: *parser.Anchor, t: []const u8) !void {
181+
return try parser.anchorSetRel(self, t);
182+
}
183+
184+
pub fn get_text(self: *parser.Anchor) !?[]const u8 {
185+
return try parser.nodeTextContent(parser.anchorToNode(self));
186+
}
187+
188+
pub fn set_text(self: *parser.Anchor, v: []const u8) !void {
189+
return try parser.nodeSetTextContent(parser.anchorToNode(self), v);
158190
}
159191
};
160192

@@ -627,8 +659,23 @@ pub fn testExecFn(
627659
.{ .src = "let a = document.getElementById('link')", .ex = "undefined" },
628660
.{ .src = "a.target", .ex = "" },
629661
.{ .src = "a.target = '_blank'", .ex = "_blank" },
662+
.{ .src = "a.target", .ex = "_blank" },
663+
.{ .src = "a.target = ''", .ex = "" },
664+
630665
.{ .src = "a.href", .ex = "foo" },
631666
.{ .src = "a.href = 'https://lightpanda.io/'", .ex = "https://lightpanda.io/" },
667+
.{ .src = "a.href", .ex = "https://lightpanda.io/" },
668+
.{ .src = "a.href = 'foo'", .ex = "foo" },
669+
670+
.{ .src = "a.type", .ex = "" },
671+
.{ .src = "a.type = 'text/html'", .ex = "text/html" },
672+
.{ .src = "a.type", .ex = "text/html" },
673+
.{ .src = "a.type = ''", .ex = "" },
674+
675+
.{ .src = "a.text", .ex = "OK" },
676+
.{ .src = "a.text = 'foo'", .ex = "foo" },
677+
.{ .src = "a.text", .ex = "foo" },
678+
.{ .src = "a.text = 'OK'", .ex = "OK" },
632679
};
633680
try checkCases(js_env, &anchor);
634681
}

src/netsurf.zig

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,12 @@ pub fn elementHTMLGetTagType(elem_html: *ElementHTML) !Tag {
15141514
}
15151515

15161516
// HTMLAnchorElement
1517+
1518+
// anchorToNode is an helper to convert an element to a node.
1519+
pub inline fn anchorToNode(a: *Anchor) *Node {
1520+
return @as(*Node, @ptrCast(a));
1521+
}
1522+
15171523
pub fn anchorGetTarget(a: *Anchor) ![]const u8 {
15181524
var res: ?*String = undefined;
15191525
const err = c.dom_html_anchor_element_get_target(a, &res);
@@ -1540,6 +1546,45 @@ pub fn anchorSetHref(a: *Anchor, href: []const u8) !void {
15401546
try DOMErr(err);
15411547
}
15421548

1549+
pub fn anchorGetHrefLang(a: *Anchor) ![]const u8 {
1550+
var res: ?*String = undefined;
1551+
const err = c.dom_html_anchor_element_get_hreflang(a, &res);
1552+
try DOMErr(err);
1553+
if (res == null) return "";
1554+
return strToData(res.?);
1555+
}
1556+
1557+
pub fn anchorSetHrefLang(a: *Anchor, href: []const u8) !void {
1558+
const err = c.dom_html_anchor_element_set_hreflang(a, try strFromData(href));
1559+
try DOMErr(err);
1560+
}
1561+
1562+
pub fn anchorGetType(a: *Anchor) ![]const u8 {
1563+
var res: ?*String = undefined;
1564+
const err = c.dom_html_anchor_element_get_type(a, &res);
1565+
try DOMErr(err);
1566+
if (res == null) return "";
1567+
return strToData(res.?);
1568+
}
1569+
1570+
pub fn anchorSetType(a: *Anchor, t: []const u8) !void {
1571+
const err = c.dom_html_anchor_element_set_type(a, try strFromData(t));
1572+
try DOMErr(err);
1573+
}
1574+
1575+
pub fn anchorGetRel(a: *Anchor) ![]const u8 {
1576+
var res: ?*String = undefined;
1577+
const err = c.dom_html_anchor_element_get_rel(a, &res);
1578+
try DOMErr(err);
1579+
if (res == null) return "";
1580+
return strToData(res.?);
1581+
}
1582+
1583+
pub fn anchorSetRel(a: *Anchor, rel: []const u8) !void {
1584+
const err = c.dom_html_anchor_element_set_rel(a, try strFromData(rel));
1585+
try DOMErr(err);
1586+
}
1587+
15431588
// ElementsHTML
15441589

15451590
pub const MediaElement = struct { base: *c.dom_html_element };

0 commit comments

Comments
 (0)