mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Implement the Image NamedConstructor for HTMLImageElement
This commit is contained in:
parent
012be81eab
commit
d33579183a
6 changed files with 53 additions and 53 deletions
|
@ -7,8 +7,10 @@ use dom::attr::{AttrHelpers, AttrValue};
|
||||||
use dom::bindings::cell::DOMRefCell;
|
use dom::bindings::cell::DOMRefCell;
|
||||||
use dom::bindings::codegen::Bindings::HTMLImageElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLImageElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLImageElementBinding::HTMLImageElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLImageElementBinding::HTMLImageElementMethods;
|
||||||
|
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast, EventTargetCast, HTMLElementCast,
|
use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast, EventTargetCast, HTMLElementCast,
|
||||||
HTMLImageElementDerived};
|
HTMLImageElementDerived};
|
||||||
|
use dom::bindings::error::Fallible;
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{LayoutJS, Root};
|
use dom::bindings::js::{LayoutJS, Root};
|
||||||
use dom::bindings::refcounted::Trusted;
|
use dom::bindings::refcounted::Trusted;
|
||||||
|
@ -151,6 +153,21 @@ impl HTMLImageElement {
|
||||||
let element = HTMLImageElement::new_inherited(localName, prefix, document);
|
let element = HTMLImageElement::new_inherited(localName, prefix, document);
|
||||||
Node::reflect_node(box element, document, HTMLImageElementBinding::Wrap)
|
Node::reflect_node(box element, document, HTMLImageElementBinding::Wrap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn Image(global: GlobalRef,
|
||||||
|
width: Option<u32>,
|
||||||
|
height: Option<u32>) -> Fallible<Root<HTMLImageElement>> {
|
||||||
|
let document = global.as_window().Document();
|
||||||
|
let image = HTMLImageElement::new("img".to_owned(), None, document.r());
|
||||||
|
if let Some(w) = width {
|
||||||
|
image.SetWidth(w);
|
||||||
|
}
|
||||||
|
if let Some(h) = height {
|
||||||
|
image.SetHeight(h);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(image)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait LayoutHTMLImageElementHelpers {
|
pub trait LayoutHTMLImageElementHelpers {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
// https://www.whatwg.org/html/#htmlimageelement
|
// https://www.whatwg.org/html/#htmlimageelement
|
||||||
//[NamedConstructor=Image(optional unsigned long width, optional unsigned long height)]
|
[NamedConstructor=Image(optional unsigned long width, optional unsigned long height)]
|
||||||
interface HTMLImageElement : HTMLElement {
|
interface HTMLImageElement : HTMLElement {
|
||||||
attribute DOMString alt;
|
attribute DOMString alt;
|
||||||
attribute DOMString src;
|
attribute DOMString src;
|
||||||
|
|
|
@ -14117,6 +14117,10 @@
|
||||||
"path": "html/semantics/embedded-content/the-img-element/img.complete.html",
|
"path": "html/semantics/embedded-content/the-img-element/img.complete.html",
|
||||||
"url": "/html/semantics/embedded-content/the-img-element/img.complete.html"
|
"url": "/html/semantics/embedded-content/the-img-element/img.complete.html"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"path": "html/semantics/embedded-content/the-img-element/Image-constructor.html",
|
||||||
|
"url": "/html/semantics/embedded-content/the-img-element/Image-constructor.html"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "html/semantics/embedded-content/the-img-element/relevant-mutations.html",
|
"path": "html/semantics/embedded-content/the-img-element/relevant-mutations.html",
|
||||||
"url": "/html/semantics/embedded-content/the-img-element/relevant-mutations.html"
|
"url": "/html/semantics/embedded-content/the-img-element/relevant-mutations.html"
|
||||||
|
@ -30594,4 +30598,4 @@
|
||||||
"rev": "075802c1d3387d07e31cd5887459d539b1297c8d",
|
"rev": "075802c1d3387d07e31cd5887459d539b1297c8d",
|
||||||
"url_base": "/",
|
"url_base": "/",
|
||||||
"version": 2
|
"version": 2
|
||||||
}
|
}
|
||||||
|
|
|
@ -2745,18 +2745,6 @@
|
||||||
[HTMLImageElement interface: document.createElement("img") must inherit property "lowsrc" with the proper type (14)]
|
[HTMLImageElement interface: document.createElement("img") must inherit property "lowsrc" with the proper type (14)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[HTMLImageElement must be primary interface of new Image()]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Stringification of new Image()]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLImageElement interface: new Image() must inherit property "alt" with the proper type (0)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLImageElement interface: new Image() must inherit property "src" with the proper type (1)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLImageElement interface: new Image() must inherit property "srcset" with the proper type (2)]
|
[HTMLImageElement interface: new Image() must inherit property "srcset" with the proper type (2)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -2766,51 +2754,12 @@
|
||||||
[HTMLImageElement interface: new Image() must inherit property "crossOrigin" with the proper type (4)]
|
[HTMLImageElement interface: new Image() must inherit property "crossOrigin" with the proper type (4)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[HTMLImageElement interface: new Image() must inherit property "useMap" with the proper type (5)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLImageElement interface: new Image() must inherit property "isMap" with the proper type (6)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLImageElement interface: new Image() must inherit property "width" with the proper type (7)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLImageElement interface: new Image() must inherit property "height" with the proper type (8)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLImageElement interface: new Image() must inherit property "naturalWidth" with the proper type (9)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLImageElement interface: new Image() must inherit property "naturalHeight" with the proper type (10)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLImageElement interface: new Image() must inherit property "complete" with the proper type (11)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLImageElement interface: new Image() must inherit property "currentSrc" with the proper type (12)]
|
[HTMLImageElement interface: new Image() must inherit property "currentSrc" with the proper type (12)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[HTMLImageElement interface: new Image() must inherit property "name" with the proper type (13)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLImageElement interface: new Image() must inherit property "lowsrc" with the proper type (14)]
|
[HTMLImageElement interface: new Image() must inherit property "lowsrc" with the proper type (14)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[HTMLImageElement interface: new Image() must inherit property "align" with the proper type (15)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLImageElement interface: new Image() must inherit property "hspace" with the proper type (16)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLImageElement interface: new Image() must inherit property "vspace" with the proper type (17)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLImageElement interface: new Image() must inherit property "longDesc" with the proper type (18)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLImageElement interface: new Image() must inherit property "border" with the proper type (19)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLIFrameElement interface: existence and properties of interface object]
|
[HTMLIFrameElement interface: existence and properties of interface object]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -168,6 +168,7 @@ var interfaceNamesInGlobalScope = [
|
||||||
"HTMLUnknownElement",
|
"HTMLUnknownElement",
|
||||||
"HTMLVideoElement",
|
"HTMLVideoElement",
|
||||||
"ImageData",
|
"ImageData",
|
||||||
|
"Image",
|
||||||
"KeyboardEvent",
|
"KeyboardEvent",
|
||||||
"Location",
|
"Location",
|
||||||
"MessageEvent",
|
"MessageEvent",
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<title>DOM Image constructor Test</title>
|
||||||
|
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
|
||||||
|
<link rel="help" href="https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element" />
|
||||||
|
<meta name="assert" content="Tests the Image constructor for the img-element">
|
||||||
|
<script src="/resources/testharness.js"></script>
|
||||||
|
<script src="/resources/testharnessreport.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
<div id="log"></div>
|
||||||
|
<script>
|
||||||
|
test(function() {
|
||||||
|
var img = new Image();
|
||||||
|
assert_true(img != undefined);
|
||||||
|
}, "Image constructor works");
|
||||||
|
|
||||||
|
test(function() {
|
||||||
|
assert_true(Image.prototype === HTMLImageElement.prototype);
|
||||||
|
}, "Image and HTMLImageElement share a prototype");
|
||||||
|
|
||||||
|
test(function() {
|
||||||
|
assert_true((new Image()).localName === "img");
|
||||||
|
}, "Image localName is img");
|
||||||
|
|
||||||
|
test(function() {
|
||||||
|
assert_true((new Image()).namespaceURI === "http://www.w3.org/1999/xhtml");
|
||||||
|
}, "Image namespace URI is correct");
|
||||||
|
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue