Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use create_html_element for HTMLAudioElement and HTMLImageElement #25431

Merged
merged 1 commit into from Jan 21, 2020
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -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>()
@@ -22,7 +22,9 @@ use crate::dom::bindings::str::{DOMString, USVString};
use crate::dom::document::Document;
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::{AttributeMutation, Element, RawLayoutElementHelpers};
use crate::dom::element::{
AttributeMutation, CustomElementCreationMode, Element, ElementCreator, RawLayoutElementHelpers,
};
use crate::dom::event::Event;
use crate::dom::eventtarget::EventTarget;
use crate::dom::globalscope::GlobalScope;
@@ -51,7 +53,7 @@ use app_units::{Au, AU_PER_PX};
use cssparser::{Parser, ParserInput};
use dom_struct::dom_struct;
use euclid::Point2D;
use html5ever::{LocalName, Prefix};
use html5ever::{LocalName, Prefix, QualName};
use ipc_channel::ipc;
use ipc_channel::router::ROUTER;
use mime::{self, Mime};
@@ -1256,8 +1258,15 @@ impl HTMLImageElement {
width: Option<u32>,
height: Option<u32>,
) -> Fallible<DomRoot<HTMLImageElement>> {
let document = window.Document();
let image = HTMLImageElement::new(local_name!("img"), None, &document);
let element = Element::create(
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 {
image.SetWidth(w);
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.