mirror of
https://github.com/servo/servo.git
synced 2025-08-02 04:00:32 +01:00
use create_html_element for HTMLAudioElement and HTMLImageElement
This commit is contained in:
parent
afa1b85766
commit
6e296150f8
2 changed files with 24 additions and 8 deletions
|
@ -10,12 +10,12 @@ use crate::dom::bindings::inheritance::Castable;
|
||||||
use crate::dom::bindings::root::DomRoot;
|
use crate::dom::bindings::root::DomRoot;
|
||||||
use crate::dom::bindings::str::DOMString;
|
use crate::dom::bindings::str::DOMString;
|
||||||
use crate::dom::document::Document;
|
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::htmlmediaelement::HTMLMediaElement;
|
||||||
use crate::dom::node::Node;
|
use crate::dom::node::Node;
|
||||||
use crate::dom::window::Window;
|
use crate::dom::window::Window;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use html5ever::{LocalName, Prefix};
|
use html5ever::{LocalName, Prefix, QualName};
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct HTMLAudioElement {
|
pub struct HTMLAudioElement {
|
||||||
|
@ -50,8 +50,15 @@ impl HTMLAudioElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-audio
|
// https://html.spec.whatwg.org/multipage/#dom-audio
|
||||||
pub fn Audio(window: &Window, src: Option<DOMString>) -> Fallible<DomRoot<HTMLAudioElement>> {
|
pub fn Audio(window: &Window, src: Option<DOMString>) -> Fallible<DomRoot<HTMLAudioElement>> {
|
||||||
let document = window.Document();
|
let element = Element::create(
|
||||||
let audio = HTMLAudioElement::new(local_name!("audio"), None, &document);
|
QualName::new(None, ns!(html), local_name!("audio")),
|
||||||
|
None,
|
||||||
|
&window.Document(),
|
||||||
|
ElementCreator::ScriptCreated,
|
||||||
|
CustomElementCreationMode::Synchronous,
|
||||||
|
);
|
||||||
|
|
||||||
|
let audio = DomRoot::downcast::<HTMLAudioElement>(element).unwrap();
|
||||||
|
|
||||||
audio
|
audio
|
||||||
.upcast::<Element>()
|
.upcast::<Element>()
|
||||||
|
|
|
@ -22,7 +22,9 @@ use crate::dom::bindings::str::{DOMString, USVString};
|
||||||
use crate::dom::document::Document;
|
use crate::dom::document::Document;
|
||||||
use crate::dom::element::{cors_setting_for_element, referrer_policy_for_element};
|
use crate::dom::element::{cors_setting_for_element, referrer_policy_for_element};
|
||||||
use crate::dom::element::{reflect_cross_origin_attribute, set_cross_origin_attribute};
|
use crate::dom::element::{reflect_cross_origin_attribute, set_cross_origin_attribute};
|
||||||
use crate::dom::element::{AttributeMutation, Element, RawLayoutElementHelpers};
|
use crate::dom::element::{
|
||||||
|
AttributeMutation, CustomElementCreationMode, Element, ElementCreator, RawLayoutElementHelpers,
|
||||||
|
};
|
||||||
use crate::dom::event::Event;
|
use crate::dom::event::Event;
|
||||||
use crate::dom::eventtarget::EventTarget;
|
use crate::dom::eventtarget::EventTarget;
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
|
@ -51,7 +53,7 @@ use app_units::{Au, AU_PER_PX};
|
||||||
use cssparser::{Parser, ParserInput};
|
use cssparser::{Parser, ParserInput};
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use euclid::Point2D;
|
use euclid::Point2D;
|
||||||
use html5ever::{LocalName, Prefix};
|
use html5ever::{LocalName, Prefix, QualName};
|
||||||
use ipc_channel::ipc;
|
use ipc_channel::ipc;
|
||||||
use ipc_channel::router::ROUTER;
|
use ipc_channel::router::ROUTER;
|
||||||
use mime::{self, Mime};
|
use mime::{self, Mime};
|
||||||
|
@ -1256,8 +1258,15 @@ impl HTMLImageElement {
|
||||||
width: Option<u32>,
|
width: Option<u32>,
|
||||||
height: Option<u32>,
|
height: Option<u32>,
|
||||||
) -> Fallible<DomRoot<HTMLImageElement>> {
|
) -> Fallible<DomRoot<HTMLImageElement>> {
|
||||||
let document = window.Document();
|
let element = Element::create(
|
||||||
let image = HTMLImageElement::new(local_name!("img"), None, &document);
|
QualName::new(None, ns!(html), local_name!("img")),
|
||||||
|
None,
|
||||||
|
&window.Document(),
|
||||||
|
ElementCreator::ScriptCreated,
|
||||||
|
CustomElementCreationMode::Synchronous,
|
||||||
|
);
|
||||||
|
|
||||||
|
let image = DomRoot::downcast::<HTMLImageElement>(element).unwrap();
|
||||||
if let Some(w) = width {
|
if let Some(w) = width {
|
||||||
image.SetWidth(w);
|
image.SetWidth(w);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue