mirror of
https://github.com/servo/servo.git
synced 2025-06-24 17:14:33 +01:00
auto merge of #2414 : Ms2ger/servo/parser-attribute, r=SimonSapin
This commit is contained in:
commit
a9f08fd7c4
2 changed files with 24 additions and 7 deletions
|
@ -206,7 +206,9 @@ impl<'a> ElementHelpers for JSRef<'a, Element> {
|
||||||
|
|
||||||
pub trait AttributeHandlers {
|
pub trait AttributeHandlers {
|
||||||
fn get_attribute(&self, namespace: Namespace, name: &str) -> Option<Temporary<Attr>>;
|
fn get_attribute(&self, namespace: Namespace, name: &str) -> Option<Temporary<Attr>>;
|
||||||
fn set_attr(&mut self, name: DOMString, value: DOMString) -> ErrorResult;
|
fn set_attribute_from_parser(&mut self, local_name: DOMString,
|
||||||
|
value: DOMString, namespace: Namespace,
|
||||||
|
prefix: Option<DOMString>);
|
||||||
fn set_attribute(&mut self, namespace: Namespace, name: DOMString,
|
fn set_attribute(&mut self, namespace: Namespace, name: DOMString,
|
||||||
value: DOMString) -> ErrorResult;
|
value: DOMString) -> ErrorResult;
|
||||||
fn do_set_attribute(&mut self, local_name: DOMString, value: DOMString,
|
fn do_set_attribute(&mut self, local_name: DOMString, value: DOMString,
|
||||||
|
@ -238,8 +240,14 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_attr(&mut self, name: DOMString, value: DOMString) -> ErrorResult {
|
fn set_attribute_from_parser(&mut self, local_name: DOMString,
|
||||||
self.set_attribute(namespace::Null, name, value)
|
value: DOMString, namespace: Namespace,
|
||||||
|
prefix: Option<DOMString>) {
|
||||||
|
let name = match prefix {
|
||||||
|
None => local_name.clone(),
|
||||||
|
Some(ref prefix) => format!("{:s}:{:s}", *prefix, local_name),
|
||||||
|
};
|
||||||
|
self.do_set_attribute(local_name, value, name, namespace, prefix, |_| false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_attribute(&mut self, namespace: Namespace, name: DOMString,
|
fn set_attribute(&mut self, namespace: Namespace, name: DOMString,
|
||||||
|
|
|
@ -17,7 +17,9 @@ use html::cssparse::{StylesheetProvenance, UrlProvenance, spawn_css_parser};
|
||||||
use script_task::Page;
|
use script_task::Page;
|
||||||
|
|
||||||
use hubbub::hubbub;
|
use hubbub::hubbub;
|
||||||
|
use hubbub::hubbub::{NullNs, XLinkNs, XmlNs, XmlNsNs};
|
||||||
use servo_net::resource_task::{Load, Payload, Done, ResourceTask, load_whole_resource};
|
use servo_net::resource_task::{Load, Payload, Done, ResourceTask, load_whole_resource};
|
||||||
|
use servo_util::namespace;
|
||||||
use servo_util::namespace::Null;
|
use servo_util::namespace::Null;
|
||||||
use servo_util::str::{DOMString, HTML_SPACE_CHARACTERS};
|
use servo_util::str::{DOMString, HTML_SPACE_CHARACTERS};
|
||||||
use servo_util::task::spawn_named;
|
use servo_util::task::spawn_named;
|
||||||
|
@ -327,10 +329,17 @@ pub fn parse_html(page: &Page,
|
||||||
|
|
||||||
debug!("-- attach attrs");
|
debug!("-- attach attrs");
|
||||||
for attr in tag.attributes.iter() {
|
for attr in tag.attributes.iter() {
|
||||||
//FIXME: this should have proper error handling or explicitly drop
|
let (namespace, prefix) = match attr.ns {
|
||||||
// exceptions on the ground
|
NullNs => (namespace::Null, None),
|
||||||
assert!(element.set_attr(attr.name.clone(),
|
XLinkNs => (namespace::XLink, Some("xlink")),
|
||||||
attr.value.clone()).is_ok());
|
XmlNs => (namespace::XML, Some("xml")),
|
||||||
|
XmlNsNs => (namespace::XMLNS, Some("xmlns")),
|
||||||
|
ns => fail!("Not expecting namespace {:?}", ns),
|
||||||
|
};
|
||||||
|
element.set_attribute_from_parser(attr.name.clone(),
|
||||||
|
attr.value.clone(),
|
||||||
|
namespace,
|
||||||
|
prefix.map(|p| p.to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//FIXME: workaround for https://github.com/mozilla/rust/issues/13246;
|
//FIXME: workaround for https://github.com/mozilla/rust/issues/13246;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue