diff options
author | Manish Goregaokar <manishsmail@gmail.com> | 2014-10-14 20:44:38 +0530 |
---|---|---|
committer | Manish Goregaokar <manishsmail@gmail.com> | 2014-10-14 21:24:36 +0530 |
commit | 79cb1af12ae5cab650ff6d72663da17812d267c2 (patch) | |
tree | 8c90f71383bc929a1c4376286143ce2b4c7da68b /components/script/dom/macros.rs | |
parent | 941bd2dad6d10c2c82a4fa894e8344a65b5bb36d (diff) | |
download | servo-79cb1af12ae5cab650ff6d72663da17812d267c2.tar.gz servo-79cb1af12ae5cab650ff6d72663da17812d267c2.zip |
Address review comments
Diffstat (limited to 'components/script/dom/macros.rs')
-rw-r--r-- | components/script/dom/macros.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs index 719d5e93c94..b4b0d4d2ef7 100644 --- a/components/script/dom/macros.rs +++ b/components/script/dom/macros.rs @@ -70,6 +70,52 @@ macro_rules! make_url_getter( } ) +#[macro_export] +macro_rules! make_url_or_base_getter( + ( $attr:ident, $htmlname:expr ) => ( + fn $attr(self) -> DOMString { + use dom::element::{Element, AttributeHandlers}; + use dom::bindings::codegen::InheritTypes::ElementCast; + #[allow(unused_imports)] + use std::ascii::StrAsciiExt; + let element: JSRef<Element> = ElementCast::from_ref(self); + let url = element.get_url_attribute($htmlname); + match url.as_slice() { + "" => { + let window = window_from_node(self).root(); + window.get_url().serialize() + }, + _ => url + } + } + ); + ($attr:ident) => { + make_url_or_base_getter!($attr, stringify!($attr).to_ascii_lower().as_slice()) + } +) + +#[macro_export] +macro_rules! make_enumerated_getter( + ( $attr:ident, $htmlname:expr, $default:expr, $($choices: pat)|+) => ( + fn $attr(self) -> DOMString { + use dom::element::{Element, AttributeHandlers}; + use dom::bindings::codegen::InheritTypes::ElementCast; + #[allow(unused_imports)] + use std::ascii::StrAsciiExt; + let element: JSRef<Element> = ElementCast::from_ref(self); + let val = element.get_string_attribute($htmlname).into_ascii_lower(); + // https://html.spec.whatwg.org/multipage/forms.html#attr-fs-method + match val.as_slice() { + $($choices)|+ => val, + _ => $default.to_string() + } + } + ); + ($attr:ident, $default:expr, $($choices: pat)|+) => { + make_enumerated_getter!($attr, stringify!($attr).to_ascii_lower().as_slice(), $default, $($choices)|+) + } +) + // concat_idents! doesn't work for function name positions, so // we have to specify both the content name and the HTML name here #[macro_export] |