mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-02-04 06:23:45 +00:00
HTMLElement.click()
This commit is contained in:
@@ -166,3 +166,16 @@
|
|||||||
testing.expectEqual(1, parent.childNodes.length);
|
testing.expectEqual(1, parent.childNodes.length);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script id=click>
|
||||||
|
{
|
||||||
|
let clicked = 0;
|
||||||
|
window.addEventListener('click', (e) => {
|
||||||
|
testing.expectEqual(0, e.clientX);
|
||||||
|
testing.expectEqual(0, e.clientY);
|
||||||
|
clicked += 1;
|
||||||
|
});
|
||||||
|
$('#container').click();
|
||||||
|
testing.expectEqual(1, clicked);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|||||||
@@ -172,6 +172,14 @@ pub fn asElement(self: *HtmlElement) *Element {
|
|||||||
return self._proto;
|
return self._proto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn asNode(self: *HtmlElement) *Node {
|
||||||
|
return self._proto._proto;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn asEventTarget(self: *HtmlElement) *@import("../EventTarget.zig") {
|
||||||
|
return self._proto._proto._proto;
|
||||||
|
}
|
||||||
|
|
||||||
// innerText represents the **rendered** text content of a node and its
|
// innerText represents the **rendered** text content of a node and its
|
||||||
// descendants.
|
// descendants.
|
||||||
pub fn getInnerText(self: *HtmlElement, writer: *std.Io.Writer) !void {
|
pub fn getInnerText(self: *HtmlElement, writer: *std.Io.Writer) !void {
|
||||||
@@ -286,6 +294,25 @@ pub fn insertAdjacentHTML(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn click(self: *HtmlElement, page: *Page) !void {
|
||||||
|
switch (self._type) {
|
||||||
|
inline .button, .input, .textarea, .select => |i| {
|
||||||
|
if (i.getDisabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
else => {},
|
||||||
|
}
|
||||||
|
|
||||||
|
const event = try @import("../event/MouseEvent.zig").init("click", .{
|
||||||
|
.bubbles = true,
|
||||||
|
.cancelable = true,
|
||||||
|
.clientX = 0,
|
||||||
|
.clientY = 0,
|
||||||
|
}, page);
|
||||||
|
try page._event_manager.dispatch(self.asEventTarget(), event.asEvent());
|
||||||
|
}
|
||||||
|
|
||||||
pub const JsApi = struct {
|
pub const JsApi = struct {
|
||||||
pub const bridge = js.Bridge(HtmlElement);
|
pub const bridge = js.Bridge(HtmlElement);
|
||||||
|
|
||||||
@@ -303,8 +330,8 @@ pub const JsApi = struct {
|
|||||||
try self.getInnerText(&buf.writer);
|
try self.getInnerText(&buf.writer);
|
||||||
return buf.written();
|
return buf.written();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const insertAdjacentHTML = bridge.function(HtmlElement.insertAdjacentHTML, .{ .dom_exception = true });
|
pub const insertAdjacentHTML = bridge.function(HtmlElement.insertAdjacentHTML, .{ .dom_exception = true });
|
||||||
|
pub const click = bridge.function(HtmlElement.click, .{});
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Build = struct {
|
pub const Build = struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user