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.rs53
1 files changed, 33 insertions, 20 deletions
diff --git a/src/components/script/dom/htmlimageelement.rs b/src/components/script/dom/htmlimageelement.rs
index 39c854c1c05..423f49a8f14 100644
--- a/src/components/script/dom/htmlimageelement.rs
+++ b/src/components/script/dom/htmlimageelement.rs
@@ -35,29 +35,18 @@ impl HTMLImageElementDerived for EventTarget {
}
}
-impl HTMLImageElement {
- pub fn new_inherited(localName: DOMString, document: JS<Document>) -> HTMLImageElement {
- HTMLImageElement {
- htmlelement: HTMLElement::new_inherited(HTMLImageElementTypeId, localName, document),
- image: Untraceable::new(None),
- }
- }
-
- 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)
- }
-
- pub fn image<'a>(&'a self) -> &'a Option<Url> {
- &*self.image
- }
+trait PrivateHTMLImageElementHelpers {
+ fn update_image(&mut self, value: Option<DOMString>, url: Option<Url>);
+}
+impl<'a> PrivateHTMLImageElementHelpers for JSRef<'a, 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().root(&roots);
+ let self_alias = self.clone();
+ let node_alias: &JSRef<Node> = NodeCast::from_ref(&self_alias);
+ let document = node_alias.owner_doc().root(&roots);
let window = document.deref().window.root(&roots);
let image_cache = &window.image_cache_task;
match value {
@@ -79,6 +68,30 @@ impl HTMLImageElement {
}
}
+impl HTMLImageElement {
+ pub fn new_inherited(localName: DOMString, document: JS<Document>) -> HTMLImageElement {
+ HTMLImageElement {
+ htmlelement: HTMLElement::new_inherited(HTMLImageElementTypeId, localName, document),
+ image: Untraceable::new(None),
+ }
+ }
+
+ 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)
+ }
+}
+
+pub trait LayoutHTMLImageElementHelpers {
+ unsafe fn image<'a>(&'a self) -> &'a Option<Url>;
+}
+
+impl LayoutHTMLImageElementHelpers for JS<HTMLImageElement> {
+ unsafe fn image<'a>(&'a self) -> &'a Option<Url> {
+ &*(*self.unsafe_get()).image
+ }
+}
+
pub trait HTMLImageElementMethods {
fn Alt(&self) -> DOMString;
fn SetAlt(&mut self, alt: DOMString);
@@ -271,7 +284,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> {
if "src" == name {
let window = window_from_node(self).root(&roots);
let url = Some(window.get().get_url());
- self.get_mut().update_image(Some(value), url);
+ self.update_image(Some(value), url);
}
}
@@ -282,7 +295,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> {
}
if "src" == name {
- self.get_mut().update_image(None, None);
+ self.update_image(None, None);
}
}
}