mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Move all methods on T to JSRef<T> or JS<T> as appropriate.
This commit is contained in:
parent
7daa97c7e5
commit
109410900c
15 changed files with 574 additions and 521 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue