aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/htmlimageelement.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/script/dom/htmlimageelement.rs')
-rw-r--r--src/components/script/dom/htmlimageelement.rs74
1 files changed, 38 insertions, 36 deletions
diff --git a/src/components/script/dom/htmlimageelement.rs b/src/components/script/dom/htmlimageelement.rs
index d986f5d07e8..04528c54283 100644
--- a/src/components/script/dom/htmlimageelement.rs
+++ b/src/components/script/dom/htmlimageelement.rs
@@ -5,7 +5,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLImageElementBinding;
use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast, HTMLElementCast, HTMLImageElementDerived};
use dom::bindings::error::ErrorResult;
-use dom::bindings::js::{JS, JSRef};
+use dom::bindings::js::{JS, JSRef, Unrooted, RootCollection};
use dom::bindings::trace::Untraceable;
use dom::document::Document;
use dom::element::{Element, HTMLImageElementTypeId};
@@ -43,7 +43,7 @@ impl HTMLImageElement {
}
}
- pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLImageElement> {
+ pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLImageElement> {
let element = HTMLImageElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLImageElementBinding::Wrap)
}
@@ -57,9 +57,10 @@ impl HTMLImageElement {
/// Makes the local `image` member match the status of the `src` attribute and starts
/// prefetching the image. This method must be called after `src` is changed.
fn update_image(&mut self, value: Option<DOMString>, url: Option<Url>) {
+ let roots = RootCollection::new();
let elem = &mut self.htmlelement.element;
- let document = elem.node.owner_doc();
- let window = document.get().window.get();
+ let document = elem.node.owner_doc().root(&roots);
+ let window = document.deref().window.root(&roots);
let image_cache = &window.image_cache_task;
match value {
None => {
@@ -80,22 +81,22 @@ impl HTMLImageElement {
}
pub fn Alt(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString {
- let element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
+ let element: &JSRef<Element> = ElementCast::from_ref(abstract_self);
element.get_string_attribute("alt")
}
- pub fn SetAlt(&mut self, abstract_self: &JSRef<HTMLImageElement>, alt: DOMString) {
- let mut element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
+ pub fn SetAlt(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, alt: DOMString) {
+ let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
element.set_string_attribute("alt", alt)
}
pub fn Src(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString {
- let element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
+ let element: &JSRef<Element> = ElementCast::from_ref(abstract_self);
element.get_string_attribute("src")
}
pub fn SetSrc(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, src: DOMString) {
- let mut element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
+ let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
element.set_url_attribute("src", src)
}
@@ -108,44 +109,44 @@ impl HTMLImageElement {
}
pub fn UseMap(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString {
- let element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
+ let element: &JSRef<Element> = ElementCast::from_ref(abstract_self);
element.get_string_attribute("useMap")
}
pub fn SetUseMap(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, use_map: DOMString) {
- let mut element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
+ let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
element.set_string_attribute("useMap", use_map)
}
pub fn IsMap(&self, abstract_self: &JSRef<HTMLImageElement>) -> bool {
- let element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
+ let element: &JSRef<Element> = ElementCast::from_ref(abstract_self);
from_str::<bool>(element.get_string_attribute("hspace")).unwrap()
}
pub fn SetIsMap(&self, abstract_self: &mut JSRef<HTMLImageElement>, is_map: bool) {
- let mut element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
+ let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
element.set_string_attribute("isMap", is_map.to_str())
}
pub fn Width(&self, abstract_self: &JSRef<HTMLImageElement>) -> u32 {
- let node: JS<Node> = NodeCast::from(&abstract_self.unrooted());
+ let node: &JSRef<Node> = NodeCast::from_ref(abstract_self);
let rect = node.get_bounding_content_box();
to_px(rect.size.width) as u32
}
- pub fn SetWidth(&mut self, abstract_self: &JSRef<HTMLImageElement>, width: u32) {
- let mut elem: JS<Element> = ElementCast::from(&abstract_self.unrooted());
+ pub fn SetWidth(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, width: u32) {
+ let elem: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
elem.set_uint_attribute("width", width)
}
pub fn Height(&self, abstract_self: &JSRef<HTMLImageElement>) -> u32 {
- let node: JS<Node> = NodeCast::from(&abstract_self.unrooted());
+ let node: &JSRef<Node> = NodeCast::from_ref(abstract_self);
let rect = node.get_bounding_content_box();
to_px(rect.size.height) as u32
}
- pub fn SetHeight(&mut self, abstract_self: &JSRef<HTMLImageElement>, height: u32) {
- let mut elem: JS<Element> = ElementCast::from(&abstract_self.unrooted());
+ pub fn SetHeight(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, height: u32) {
+ let elem: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
elem.set_uint_attribute("height", height)
}
@@ -162,87 +163,88 @@ impl HTMLImageElement {
}
pub fn Name(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString {
- let element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
+ let element: &JSRef<Element> = ElementCast::from_ref(abstract_self);
element.get_string_attribute("name")
}
pub fn SetName(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, name: DOMString) {
- let mut element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
+ let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
element.set_string_attribute("name", name)
}
pub fn Align(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString {
- let element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
+ let element: &JSRef<Element> = ElementCast::from_ref(abstract_self);
element.get_string_attribute("longdesc")
}
pub fn SetAlign(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, align: DOMString) {
- let mut element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
+ let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
element.set_string_attribute("align", align)
}
pub fn Hspace(&self, abstract_self: &JSRef<HTMLImageElement>) -> u32 {
- let element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
+ let element: &JSRef<Element> = ElementCast::from_ref(abstract_self);
from_str::<u32>(element.get_string_attribute("hspace")).unwrap()
}
pub fn SetHspace(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, hspace: u32) {
- let mut element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
+ let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
element.set_uint_attribute("hspace", hspace)
}
pub fn Vspace(&self, abstract_self: &JSRef<HTMLImageElement>) -> u32 {
- let element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
+ let element: &JSRef<Element> = ElementCast::from_ref(abstract_self);
from_str::<u32>(element.get_string_attribute("vspace")).unwrap()
}
pub fn SetVspace(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, vspace: u32) {
- let mut element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
+ let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
element.set_uint_attribute("vspace", vspace)
}
pub fn LongDesc(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString {
- let element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
+ let element: &JSRef<Element> = ElementCast::from_ref(abstract_self);
element.get_string_attribute("longdesc")
}
pub fn SetLongDesc(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, longdesc: DOMString) {
- let mut element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
+ let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
element.set_string_attribute("longdesc", longdesc)
}
pub fn Border(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString {
- let element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
+ let element: &JSRef<Element> = ElementCast::from_ref(abstract_self);
element.get_string_attribute("border")
}
pub fn SetBorder(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, border: DOMString) {
- let mut element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
+ let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
element.set_string_attribute("border", border)
}
}
-impl VirtualMethods for JS<HTMLImageElement> {
+impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> {
fn super_type(&self) -> Option<~VirtualMethods:> {
- let htmlelement: JS<HTMLElement> = HTMLElementCast::from(self);
- Some(~htmlelement as ~VirtualMethods:)
+ let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_ref(self);
+ Some(~htmlelement.clone() as ~VirtualMethods:)
}
fn after_set_attr(&mut self, name: DOMString, value: DOMString) {
+ let roots = RootCollection::new();
match self.super_type() {
Some(ref mut s) => s.after_set_attr(name.clone(), value.clone()),
_ => (),
}
if "src" == name {
- let window = window_from_node(self);
+ let window = window_from_node(self).root(&roots);
let url = Some(window.get().get_url());
self.get_mut().update_image(Some(value), url);
}
}
fn before_remove_attr(&mut self, name: DOMString, value: DOMString) {
- match self.super_type() {
+ match self.super_type() {
Some(ref mut s) => s.before_remove_attr(name.clone(), value.clone()),
_ => (),
}