mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-02-04 06:23:45 +00:00
add Audio constructor
This commit is contained in:
@@ -238,6 +238,15 @@
|
|||||||
testing.expectEqual('[object HTMLAudioElement]', audio.toString());
|
testing.expectEqual('[object HTMLAudioElement]', audio.toString());
|
||||||
testing.expectEqual(true, audio.paused);
|
testing.expectEqual(true, audio.paused);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create with `Audio` constructor.
|
||||||
|
{
|
||||||
|
const audio = new Audio();
|
||||||
|
testing.expectEqual(true, audio instanceof HTMLAudioElement);
|
||||||
|
testing.expectEqual("[object HTMLAudioElement]", audio.toString());
|
||||||
|
testing.expectEqual(true, audio.paused);
|
||||||
|
testing.expectEqual("auto", audio.getAttribute("preload"));
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script id="create_video_element">
|
<script id="create_video_element">
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
const js = @import("../../../js/js.zig");
|
const js = @import("../../../js/js.zig");
|
||||||
|
const Page = @import("../../../Page.zig");
|
||||||
|
|
||||||
const Node = @import("../../Node.zig");
|
const Node = @import("../../Node.zig");
|
||||||
const Element = @import("../../Element.zig");
|
const Element = @import("../../Element.zig");
|
||||||
@@ -26,6 +27,21 @@ const Audio = @This();
|
|||||||
|
|
||||||
_proto: *Media,
|
_proto: *Media,
|
||||||
|
|
||||||
|
pub fn constructor(maybe_url: ?[]const u8, page: *Page) !*Media {
|
||||||
|
const node = try page.createElementNS(.html, "audio", null);
|
||||||
|
const el = node.as(Element);
|
||||||
|
|
||||||
|
const list = try el.getOrCreateAttributeList(page);
|
||||||
|
// Always set to "auto" initially.
|
||||||
|
_ = try list.putSafe("preload", "auto", el, page);
|
||||||
|
// Set URL if provided.
|
||||||
|
if (maybe_url) |url| {
|
||||||
|
_ = try list.putSafe("src", url, el, page);
|
||||||
|
}
|
||||||
|
|
||||||
|
return node.as(Media);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn asMedia(self: *Audio) *Media {
|
pub fn asMedia(self: *Audio) *Media {
|
||||||
return self._proto;
|
return self._proto;
|
||||||
}
|
}
|
||||||
@@ -43,7 +59,10 @@ pub const JsApi = struct {
|
|||||||
|
|
||||||
pub const Meta = struct {
|
pub const Meta = struct {
|
||||||
pub const name = "HTMLAudioElement";
|
pub const name = "HTMLAudioElement";
|
||||||
|
pub const constructor_alias = "Audio";
|
||||||
pub const prototype_chain = bridge.prototypeChain();
|
pub const prototype_chain = bridge.prototypeChain();
|
||||||
pub var class_id: bridge.ClassId = undefined;
|
pub var class_id: bridge.ClassId = undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const constructor = bridge.constructor(Audio.constructor, .{});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user