Skip to content

Commit

Permalink
HTMLImageElement attribute getters and setters
Browse files Browse the repository at this point in the history
  • Loading branch information
ngsankha committed Apr 8, 2014
1 parent 7541b57 commit 58e5fec
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/components/script/dom/bindings/codegen/Bindings.conf
Expand Up @@ -166,7 +166,7 @@ addHTMLElement('HTMLHeadingElement')
addHTMLElement('HTMLHtmlElement')
addHTMLElement('HTMLHRElement')
addHTMLElement('HTMLIFrameElement', needsAbstract=['sandbox'])
addHTMLElement('HTMLImageElement', needsAbstract=['src', 'width', 'height'])
addHTMLElement('HTMLImageElement', needsAbstract=['alt', 'src', 'useMap', 'isMap', 'width', 'height', 'name', 'align', 'hspace', 'vspace', 'longDesc', 'border'])
addHTMLElement('HTMLInputElement')
addHTMLElement('HTMLLabelElement')
addHTMLElement('HTMLLegendElement')
Expand Down
100 changes: 59 additions & 41 deletions src/components/script/dom/htmlimageelement.rs
Expand Up @@ -92,22 +92,24 @@ impl HTMLImageElement {
}
}

pub fn Alt(&self) -> DOMString {
~""
pub fn Alt(&self, abstract_self: &JS<HTMLImageElement>) -> DOMString {
let element: JS<Element> = ElementCast::from(abstract_self);
element.get_string_attribute("alt")
}

pub fn SetAlt(&mut self, _alt: DOMString) -> ErrorResult {
Ok(())
pub fn SetAlt(&mut self, abstract_self: &JS<HTMLImageElement>, alt: DOMString) {
let mut element: JS<Element> = ElementCast::from(abstract_self);
element.set_string_attribute("alt", alt)
}

pub fn Src(&self, _abstract_self: &JS<HTMLImageElement>) -> DOMString {
~""
pub fn Src(&self, abstract_self: &JS<HTMLImageElement>) -> DOMString {
let element: JS<Element> = ElementCast::from(abstract_self);
element.get_string_attribute("src")
}

pub fn SetSrc(&mut self, abstract_self: &mut JS<HTMLImageElement>, src: DOMString) -> ErrorResult {
pub fn SetSrc(&mut self, abstract_self: &mut JS<HTMLImageElement>, src: DOMString) {
let mut element: JS<Element> = ElementCast::from(abstract_self);
element.set_url_attribute("src", src);
Ok(())
element.set_url_attribute("src", src)
}

pub fn CrossOrigin(&self) -> DOMString {
Expand All @@ -118,20 +120,24 @@ impl HTMLImageElement {
Ok(())
}

pub fn UseMap(&self) -> DOMString {
~""
pub fn UseMap(&self, abstract_self: &JS<HTMLImageElement>) -> DOMString {
let element: JS<Element> = ElementCast::from(abstract_self);
element.get_string_attribute("useMap")
}

pub fn SetUseMap(&mut self, _use_map: DOMString) -> ErrorResult {
Ok(())
pub fn SetUseMap(&mut self, abstract_self: &mut JS<HTMLImageElement>, use_map: DOMString) {
let mut element: JS<Element> = ElementCast::from(abstract_self);
element.set_string_attribute("useMap", use_map)
}

pub fn IsMap(&self) -> bool {
false
pub fn IsMap(&self, abstract_self: &JS<HTMLImageElement>) -> bool {
let element: JS<Element> = ElementCast::from(abstract_self);
from_str::<bool>(element.get_string_attribute("hspace")).unwrap()
}

pub fn SetIsMap(&self, _is_map: bool) -> ErrorResult {
Ok(())
pub fn SetIsMap(&self, abstract_self: &mut JS<HTMLImageElement>, is_map: bool) {
let mut element: JS<Element> = ElementCast::from(abstract_self);
element.set_string_attribute("isMap", is_map.to_str())
}

pub fn Width(&self, abstract_self: &JS<HTMLImageElement>) -> u32 {
Expand Down Expand Up @@ -177,52 +183,64 @@ impl HTMLImageElement {
false
}

pub fn Name(&self) -> DOMString {
~""
pub fn Name(&self, abstract_self: &JS<HTMLImageElement>) -> DOMString {
let element: JS<Element> = ElementCast::from(abstract_self);
element.get_string_attribute("name")
}

pub fn SetName(&mut self, _name: DOMString) -> ErrorResult {
Ok(())
pub fn SetName(&mut self, abstract_self: &mut JS<HTMLImageElement>, name: DOMString) {
let mut element: JS<Element> = ElementCast::from(abstract_self);
element.set_string_attribute("name", name)
}

pub fn Align(&self) -> DOMString {
~""
pub fn Align(&self, abstract_self: &JS<HTMLImageElement>) -> DOMString {
let element: JS<Element> = ElementCast::from(abstract_self);
element.get_string_attribute("longdesc")
}

pub fn SetAlign(&mut self, _align: DOMString) -> ErrorResult {
Ok(())
pub fn SetAlign(&mut self, abstract_self: &mut JS<HTMLImageElement>, align: DOMString) {
let mut element: JS<Element> = ElementCast::from(abstract_self);
element.set_string_attribute("align", align)
}

pub fn Hspace(&self) -> u32 {
0
pub fn Hspace(&self, abstract_self: &JS<HTMLImageElement>) -> u32 {
let element: JS<Element> = ElementCast::from(abstract_self);
from_str::<u32>(element.get_string_attribute("hspace")).unwrap()
}

pub fn SetHspace(&mut self, _hspace: u32) -> ErrorResult {
Ok(())
pub fn SetHspace(&mut self, abstract_self: &mut JS<HTMLImageElement>, hspace: u32) {
let mut element: JS<Element> = ElementCast::from(abstract_self);
element.set_uint_attribute("hspace", hspace)
}

pub fn Vspace(&self) -> u32 {
0
pub fn Vspace(&self, abstract_self: &JS<HTMLImageElement>) -> u32 {
let element: JS<Element> = ElementCast::from(abstract_self);
from_str::<u32>(element.get_string_attribute("vspace")).unwrap()
}

pub fn SetVspace(&mut self, _vspace: u32) -> ErrorResult {
Ok(())
pub fn SetVspace(&mut self, abstract_self: &mut JS<HTMLImageElement>, vspace: u32) {
let mut element: JS<Element> = ElementCast::from(abstract_self);
element.set_uint_attribute("vspace", vspace)
}

pub fn LongDesc(&self) -> DOMString {
~""
pub fn LongDesc(&self, abstract_self: &JS<HTMLImageElement>) -> DOMString {
let element: JS<Element> = ElementCast::from(abstract_self);
element.get_string_attribute("longdesc")
}

pub fn SetLongDesc(&mut self, _longdesc: DOMString) -> ErrorResult {
Ok(())
pub fn SetLongDesc(&mut self, abstract_self: &mut JS<HTMLImageElement>, longdesc: DOMString) {
let mut element: JS<Element> = ElementCast::from(abstract_self);
element.set_string_attribute("longdesc", longdesc)
}

pub fn Border(&self) -> DOMString {
~""
pub fn Border(&self, abstract_self: &JS<HTMLImageElement>) -> DOMString {
let element: JS<Element> = ElementCast::from(abstract_self);
element.get_string_attribute("border")
}

pub fn SetBorder(&mut self, _border: DOMString) -> ErrorResult {
Ok(())
pub fn SetBorder(&mut self, abstract_self: &mut JS<HTMLImageElement>, border: DOMString) {
let mut element: JS<Element> = ElementCast::from(abstract_self);
element.set_string_attribute("border", border)
}
}

Expand Down
11 changes: 1 addition & 10 deletions src/components/script/dom/webidls/HTMLImageElement.webidl
Expand Up @@ -13,15 +13,11 @@

[NamedConstructor=Image(optional unsigned long width, optional unsigned long height)]
interface HTMLImageElement : HTMLElement {
[SetterThrows]
attribute DOMString alt;
[SetterThrows]
attribute DOMString src;
[SetterThrows]
attribute DOMString crossOrigin;
[SetterThrows]
attribute DOMString useMap;
[SetterThrows]
attribute boolean isMap;
attribute unsigned long width;
attribute unsigned long height;
Expand All @@ -32,16 +28,11 @@ interface HTMLImageElement : HTMLElement {

// http://www.whatwg.org/specs/web-apps/current-work/#other-elements,-attributes-and-apis
partial interface HTMLImageElement {
[SetterThrows]
attribute DOMString name;
[SetterThrows]
attribute DOMString align;
[SetterThrows]
attribute unsigned long hspace;
[SetterThrows]
attribute unsigned long vspace;
[SetterThrows]
attribute DOMString longDesc;

[TreatNullAs=EmptyString,SetterThrows] attribute DOMString border;
[TreatNullAs=EmptyString] attribute DOMString border;
};

5 comments on commit 58e5fec

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from jdm
at ngsankha@58e5fec

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging sankha93/servo/imageattr = 58e5fec into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sankha93/servo/imageattr = 58e5fec merged ok, testing candidate = 038730c

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 038730c

Please sign in to comment.