use create_html_element for HTMLAudioElement and HTMLImageElement

This commit is contained in:
Warren Fisher 2020-01-04 15:52:45 -04:00
parent afa1b85766
commit 6e296150f8
2 changed files with 24 additions and 8 deletions

View file

@ -10,12 +10,12 @@ use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::document::Document;
use crate::dom::element::Element;
use crate::dom::element::{CustomElementCreationMode, Element, ElementCreator};
use crate::dom::htmlmediaelement::HTMLMediaElement;
use crate::dom::node::Node;
use crate::dom::window::Window;
use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix};
use html5ever::{LocalName, Prefix, QualName};
#[dom_struct]
pub struct HTMLAudioElement {
@ -50,8 +50,15 @@ impl HTMLAudioElement {
// https://html.spec.whatwg.org/multipage/#dom-audio
pub fn Audio(window: &Window, src: Option<DOMString>) -> Fallible<DomRoot<HTMLAudioElement>> {
let document = window.Document();
let audio = HTMLAudioElement::new(local_name!("audio"), None, &document);
let element = Element::create(
QualName::new(None, ns!(html), local_name!("audio")),
None,
&window.Document(),
ElementCreator::ScriptCreated,
CustomElementCreationMode::Synchronous,
);
let audio = DomRoot::downcast::<HTMLAudioElement>(element).unwrap();
audio
.upcast::<Element>()