mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
anchor: follow up
This commit is contained in:
@@ -154,7 +154,39 @@ pub const HTMLAnchorElement = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_href(self: *parser.Anchor, href: []const u8) !void {
|
pub fn set_href(self: *parser.Anchor, href: []const u8) !void {
|
||||||
return try parser.anchorSetTarget(self, href);
|
return try parser.anchorSetHref(self, href);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_hreflang(self: *parser.Anchor) ![]const u8 {
|
||||||
|
return try parser.anchorGetHrefLang(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_hreflang(self: *parser.Anchor, href: []const u8) !void {
|
||||||
|
return try parser.anchorSetHrefLang(self, href);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_type(self: *parser.Anchor) ![]const u8 {
|
||||||
|
return try parser.anchorGetType(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_type(self: *parser.Anchor, t: []const u8) !void {
|
||||||
|
return try parser.anchorSetType(self, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_rel(self: *parser.Anchor) ![]const u8 {
|
||||||
|
return try parser.anchorGetRel(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_rel(self: *parser.Anchor, t: []const u8) !void {
|
||||||
|
return try parser.anchorSetRel(self, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_text(self: *parser.Anchor) !?[]const u8 {
|
||||||
|
return try parser.nodeTextContent(parser.anchorToNode(self));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_text(self: *parser.Anchor, v: []const u8) !void {
|
||||||
|
return try parser.nodeSetTextContent(parser.anchorToNode(self), v);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -627,8 +659,23 @@ pub fn testExecFn(
|
|||||||
.{ .src = "let a = document.getElementById('link')", .ex = "undefined" },
|
.{ .src = "let a = document.getElementById('link')", .ex = "undefined" },
|
||||||
.{ .src = "a.target", .ex = "" },
|
.{ .src = "a.target", .ex = "" },
|
||||||
.{ .src = "a.target = '_blank'", .ex = "_blank" },
|
.{ .src = "a.target = '_blank'", .ex = "_blank" },
|
||||||
|
.{ .src = "a.target", .ex = "_blank" },
|
||||||
|
.{ .src = "a.target = ''", .ex = "" },
|
||||||
|
|
||||||
.{ .src = "a.href", .ex = "foo" },
|
.{ .src = "a.href", .ex = "foo" },
|
||||||
.{ .src = "a.href = 'https://lightpanda.io/'", .ex = "https://lightpanda.io/" },
|
.{ .src = "a.href = 'https://lightpanda.io/'", .ex = "https://lightpanda.io/" },
|
||||||
|
.{ .src = "a.href", .ex = "https://lightpanda.io/" },
|
||||||
|
.{ .src = "a.href = 'foo'", .ex = "foo" },
|
||||||
|
|
||||||
|
.{ .src = "a.type", .ex = "" },
|
||||||
|
.{ .src = "a.type = 'text/html'", .ex = "text/html" },
|
||||||
|
.{ .src = "a.type", .ex = "text/html" },
|
||||||
|
.{ .src = "a.type = ''", .ex = "" },
|
||||||
|
|
||||||
|
.{ .src = "a.text", .ex = "OK" },
|
||||||
|
.{ .src = "a.text = 'foo'", .ex = "foo" },
|
||||||
|
.{ .src = "a.text", .ex = "foo" },
|
||||||
|
.{ .src = "a.text = 'OK'", .ex = "OK" },
|
||||||
};
|
};
|
||||||
try checkCases(js_env, &anchor);
|
try checkCases(js_env, &anchor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1514,6 +1514,12 @@ pub fn elementHTMLGetTagType(elem_html: *ElementHTML) !Tag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HTMLAnchorElement
|
// HTMLAnchorElement
|
||||||
|
|
||||||
|
// anchorToNode is an helper to convert an element to a node.
|
||||||
|
pub inline fn anchorToNode(a: *Anchor) *Node {
|
||||||
|
return @as(*Node, @ptrCast(a));
|
||||||
|
}
|
||||||
|
|
||||||
pub fn anchorGetTarget(a: *Anchor) ![]const u8 {
|
pub fn anchorGetTarget(a: *Anchor) ![]const u8 {
|
||||||
var res: ?*String = undefined;
|
var res: ?*String = undefined;
|
||||||
const err = c.dom_html_anchor_element_get_target(a, &res);
|
const err = c.dom_html_anchor_element_get_target(a, &res);
|
||||||
@@ -1540,6 +1546,45 @@ pub fn anchorSetHref(a: *Anchor, href: []const u8) !void {
|
|||||||
try DOMErr(err);
|
try DOMErr(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn anchorGetHrefLang(a: *Anchor) ![]const u8 {
|
||||||
|
var res: ?*String = undefined;
|
||||||
|
const err = c.dom_html_anchor_element_get_hreflang(a, &res);
|
||||||
|
try DOMErr(err);
|
||||||
|
if (res == null) return "";
|
||||||
|
return strToData(res.?);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn anchorSetHrefLang(a: *Anchor, href: []const u8) !void {
|
||||||
|
const err = c.dom_html_anchor_element_set_hreflang(a, try strFromData(href));
|
||||||
|
try DOMErr(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn anchorGetType(a: *Anchor) ![]const u8 {
|
||||||
|
var res: ?*String = undefined;
|
||||||
|
const err = c.dom_html_anchor_element_get_type(a, &res);
|
||||||
|
try DOMErr(err);
|
||||||
|
if (res == null) return "";
|
||||||
|
return strToData(res.?);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn anchorSetType(a: *Anchor, t: []const u8) !void {
|
||||||
|
const err = c.dom_html_anchor_element_set_type(a, try strFromData(t));
|
||||||
|
try DOMErr(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn anchorGetRel(a: *Anchor) ![]const u8 {
|
||||||
|
var res: ?*String = undefined;
|
||||||
|
const err = c.dom_html_anchor_element_get_rel(a, &res);
|
||||||
|
try DOMErr(err);
|
||||||
|
if (res == null) return "";
|
||||||
|
return strToData(res.?);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn anchorSetRel(a: *Anchor, rel: []const u8) !void {
|
||||||
|
const err = c.dom_html_anchor_element_set_rel(a, try strFromData(rel));
|
||||||
|
try DOMErr(err);
|
||||||
|
}
|
||||||
|
|
||||||
// ElementsHTML
|
// ElementsHTML
|
||||||
|
|
||||||
pub const MediaElement = struct { base: *c.dom_html_element };
|
pub const MediaElement = struct { base: *c.dom_html_element };
|
||||||
|
|||||||
Reference in New Issue
Block a user