mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
Merge pull request #864 from lightpanda-io/link_href
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
add HTMLElementLink get/set href
This commit is contained in:
@@ -895,6 +895,15 @@ pub const HTMLLinkElement = struct {
|
||||
pub fn constructor(page: *Page, js_this: Env.JsThis) !*parser.Element {
|
||||
return constructHtmlElement(page, js_this);
|
||||
}
|
||||
|
||||
pub fn get_href(self: *parser.Link) ![]const u8 {
|
||||
return try parser.linkGetHref(self);
|
||||
}
|
||||
|
||||
pub fn set_href(self: *parser.Link, href: []const u8, page: *const Page) !void {
|
||||
const full = try urlStitch(page.call_arena, href, page.url.raw, .{});
|
||||
return try parser.linkSetHref(self, full);
|
||||
}
|
||||
};
|
||||
|
||||
pub const HTMLMapElement = struct {
|
||||
@@ -1581,6 +1590,16 @@ test "Browser.HTML.Element" {
|
||||
.{ "document.createElement('a').focus()", null },
|
||||
.{ "document.activeElement === focused", "true" },
|
||||
}, .{});
|
||||
|
||||
try runner.testCases(&.{
|
||||
.{ "let l2 = document.createElement('link');", null },
|
||||
.{ "l2.href", "" },
|
||||
.{ "l2.href = 'https://lightpanda.io/opensource-browser/15'", null },
|
||||
.{ "l2.href", "https://lightpanda.io/opensource-browser/15" },
|
||||
|
||||
.{ "l2.href = '/over/9000'", null },
|
||||
.{ "l2.href", "https://lightpanda.io/over/9000" },
|
||||
}, .{});
|
||||
}
|
||||
|
||||
test "Browser.HTML.Element.DataSet" {
|
||||
|
||||
@@ -1830,6 +1830,21 @@ pub fn anchorSetRel(a: *Anchor, rel: []const u8) !void {
|
||||
try DOMErr(err);
|
||||
}
|
||||
|
||||
// HTMLLinkElement
|
||||
|
||||
pub fn linkGetHref(link: *Link) ![]const u8 {
|
||||
var res: ?*String = undefined;
|
||||
const err = c.dom_html_link_element_get_href(link, &res);
|
||||
try DOMErr(err);
|
||||
if (res == null) return "";
|
||||
return strToData(res.?);
|
||||
}
|
||||
|
||||
pub fn linkSetHref(link: *Link, href: []const u8) !void {
|
||||
const err = c.dom_html_link_element_set_href(link, try strFromData(href));
|
||||
try DOMErr(err);
|
||||
}
|
||||
|
||||
// ElementsHTML
|
||||
|
||||
pub const MediaElement = struct { base: *c.dom_html_element };
|
||||
|
||||
Reference in New Issue
Block a user