mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Set url attribute
This commit is contained in:
parent
2a7862540c
commit
37aa21d8db
2 changed files with 12 additions and 7 deletions
|
@ -1501,11 +1501,16 @@ impl Element {
|
|||
};
|
||||
let value = &**attr.value();
|
||||
// XXXManishearth this doesn't handle `javascript:` urls properly
|
||||
document_from_node(self)
|
||||
.base_url()
|
||||
.join(value)
|
||||
.map(|parsed| USVString(parsed.into_string()))
|
||||
.unwrap_or_else(|_| USVString(value.to_owned()))
|
||||
USVString(value.to_owned())
|
||||
}
|
||||
|
||||
pub fn set_url_attribute(&self, local_name: &LocalName, value: USVString) {
|
||||
assert!(*local_name == local_name.to_ascii_lowercase());
|
||||
let base_url = document_from_node(self).base_url();
|
||||
self.set_attribute(
|
||||
local_name,
|
||||
AttrValue::from_resolved_url(&base_url, value.to_string()),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn get_string_attribute(&self, local_name: &LocalName) -> DOMString {
|
||||
|
|
|
@ -112,8 +112,8 @@ macro_rules! make_url_setter(
|
|||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::element::Element;
|
||||
let element = self.upcast::<Element>();
|
||||
element.set_string_attribute(&local_name!($htmlname),
|
||||
DOMString::from(value.0));
|
||||
element.set_url_attribute(&local_name!($htmlname),
|
||||
value);
|
||||
}
|
||||
);
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue