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

Implement basic <media> infrastructure #8454

Merged
merged 13 commits into from May 4, 2016

Add stubs for src and currentSrc for HTMLMediaElement.

  • Loading branch information
jdm committed May 3, 2016
commit 53f9307fb7a699749b0671cd476f01c0fd8268a4
@@ -2,10 +2,15 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use dom::attr::Attr;
use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::HTMLMediaElementBinding::HTMLMediaElementMethods;
use dom::bindings::codegen::Bindings::HTMLMediaElementBinding::HTMLMediaElementConstants;
use dom::bindings::inheritance::Castable;
use dom::document::Document;
use dom::element::AttributeMutation;
use dom::htmlelement::HTMLElement;
use dom::virtualmethods::VirtualMethods;
use std::cell::Cell;
use string_cache::Atom;
use util::str::DOMString;
@@ -15,6 +20,7 @@ pub struct HTMLMediaElement {
htmlelement: HTMLElement,
network_state: Cell<u16>,
ready_state: Cell<u16>,
current_src: DOMRefCell<String>,
}

impl HTMLMediaElement {
@@ -26,13 +32,17 @@ impl HTMLMediaElement {
HTMLElement::new_inherited(tag_name, prefix, document),
network_state: Cell::new(HTMLMediaElementConstants::NETWORK_EMPTY),
ready_state: Cell::new(HTMLMediaElementConstants::HAVE_NOTHING),
current_src: DOMRefCell::new("".to_owned()),
}
}

#[inline]
pub fn htmlelement(&self) -> &HTMLElement {
&self.htmlelement
}

fn media_element_load_algorithm(&self, _src: &str) {
}
}

impl HTMLMediaElementMethods for HTMLMediaElement {
@@ -43,4 +53,33 @@ impl HTMLMediaElementMethods for HTMLMediaElement {
fn ReadyState(&self) -> u16 {
self.ready_state.get()
}

// https://html.spec.whatwg.org/multipage/#dom-media-src
make_url_getter!(Src, "src");
// https://html.spec.whatwg.org/multipage/#dom-media-src
make_setter!(SetSrc, "src");

// https://html.spec.whatwg.org/multipage/#dom-media-currentsrc
fn CurrentSrc(&self) -> DOMString {
DOMString::from(self.current_src.borrow().clone())
}
}

impl VirtualMethods for HTMLMediaElement {
fn super_type(&self) -> Option<&VirtualMethods> {
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
}

fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);

match attr.local_name() {
&atom!("src") => {
if let Some(value) = mutation.new_value(attr) {
self.media_element_load_algorithm(&value);
}
}
_ => (),
};
}
}
@@ -29,6 +29,7 @@ use dom::htmlimageelement::HTMLImageElement;
use dom::htmlinputelement::HTMLInputElement;
use dom::htmllabelelement::HTMLLabelElement;
use dom::htmllinkelement::HTMLLinkElement;
use dom::htmlmediaelement::HTMLMediaElement;
use dom::htmlmetaelement::HTMLMetaElement;
use dom::htmlobjectelement::HTMLObjectElement;
use dom::htmloptgroupelement::HTMLOptGroupElement;
@@ -181,6 +182,9 @@ pub fn vtable_for(node: &Node) -> &VirtualMethods {
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => {
node.downcast::<HTMLLinkElement>().unwrap() as &VirtualMethods
}
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLMediaElement(_))) => {
node.downcast::<HTMLMediaElement>().unwrap() as &VirtualMethods
}
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLMetaElement)) => {
node.downcast::<HTMLMetaElement>().unwrap() as &VirtualMethods
}
@@ -11,8 +11,8 @@ interface HTMLMediaElement : HTMLElement {
//readonly attribute MediaError? error;

// network state
// attribute DOMString src;
//readonly attribute DOMString currentSrc;
attribute DOMString src;
readonly attribute DOMString currentSrc;
// attribute DOMString crossOrigin;
const unsigned short NETWORK_EMPTY = 0;
const unsigned short NETWORK_IDLE = 1;
@@ -2622,12 +2622,6 @@
[HTMLMediaElement interface: document.createElement("video") must inherit property "error" with the proper type (0)]
expected: FAIL

[HTMLMediaElement interface: document.createElement("video") must inherit property "src" with the proper type (1)]
expected: FAIL

[HTMLMediaElement interface: document.createElement("video") must inherit property "currentSrc" with the proper type (2)]
expected: FAIL

[HTMLMediaElement interface: document.createElement("video") must inherit property "crossOrigin" with the proper type (3)]
expected: FAIL

@@ -2730,12 +2724,6 @@
[HTMLMediaElement interface: document.createElement("audio") must inherit property "error" with the proper type (0)]
expected: FAIL

[HTMLMediaElement interface: document.createElement("audio") must inherit property "src" with the proper type (1)]
expected: FAIL

[HTMLMediaElement interface: document.createElement("audio") must inherit property "currentSrc" with the proper type (2)]
expected: FAIL

[HTMLMediaElement interface: document.createElement("audio") must inherit property "crossOrigin" with the proper type (3)]
expected: FAIL

@@ -3093,12 +3081,6 @@
[HTMLMediaElement interface: attribute error]
expected: FAIL

[HTMLMediaElement interface: attribute src]
expected: FAIL

[HTMLMediaElement interface: attribute currentSrc]
expected: FAIL

[HTMLMediaElement interface: attribute crossOrigin]
expected: FAIL

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.