aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorJoel Teichroeb <joel@teichroeb.net>2015-05-17 23:47:35 +0000
committerJoel Teichroeb <joel@teichroeb.net>2015-06-24 10:42:54 -0700
commitd33579183a19796b702576a9eb99805f20a608b1 (patch)
tree66af147867bc83257822f678b6546613438eea7d /components/script
parent012be81eaba1c6328b25a9558ef7d76f25f7439c (diff)
downloadservo-d33579183a19796b702576a9eb99805f20a608b1.tar.gz
servo-d33579183a19796b702576a9eb99805f20a608b1.zip
Implement the Image NamedConstructor for HTMLImageElement
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/htmlimageelement.rs17
-rw-r--r--components/script/dom/webidls/HTMLImageElement.webidl2
2 files changed, 18 insertions, 1 deletions
diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs
index 2ea5442bff6..6580e4f42a5 100644
--- a/components/script/dom/htmlimageelement.rs
+++ b/components/script/dom/htmlimageelement.rs
@@ -7,8 +7,10 @@ use dom::attr::{AttrHelpers, AttrValue};
use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::HTMLImageElementBinding;
use dom::bindings::codegen::Bindings::HTMLImageElementBinding::HTMLImageElementMethods;
+use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast, EventTargetCast, HTMLElementCast,
HTMLImageElementDerived};
+use dom::bindings::error::Fallible;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{LayoutJS, Root};
use dom::bindings::refcounted::Trusted;
@@ -151,6 +153,21 @@ impl HTMLImageElement {
let element = HTMLImageElement::new_inherited(localName, prefix, document);
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 {
diff --git a/components/script/dom/webidls/HTMLImageElement.webidl b/components/script/dom/webidls/HTMLImageElement.webidl
index 71b49229393..defbfb68257 100644
--- a/components/script/dom/webidls/HTMLImageElement.webidl
+++ b/components/script/dom/webidls/HTMLImageElement.webidl
@@ -4,7 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// 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 {
attribute DOMString alt;
attribute DOMString src;