Allow element prefix to be set

Implements step 6.1.10 of
https://dom.spec.whatwg.org/#concept-create-element
This commit is contained in:
Connor Brewster 2017-06-23 14:21:50 -06:00
parent dd9bb0550b
commit 37e8b89377
6 changed files with 26 additions and 17 deletions

View file

@ -126,7 +126,7 @@ pub struct Element {
local_name: LocalName,
tag_name: TagName,
namespace: Namespace,
prefix: Option<Prefix>,
prefix: DOMRefCell<Option<Prefix>>,
attrs: DOMRefCell<Vec<JS<Attr>>>,
id_attribute: DOMRefCell<Option<Atom>>,
is: DOMRefCell<Option<LocalName>>,
@ -235,7 +235,7 @@ impl Element {
local_name: local_name,
tag_name: TagName::new(),
namespace: namespace,
prefix: prefix,
prefix: DOMRefCell::new(prefix),
attrs: DOMRefCell::new(vec![]),
id_attribute: DOMRefCell::new(None),
is: DOMRefCell::new(None),
@ -838,8 +838,12 @@ impl Element {
&self.namespace
}
pub fn prefix(&self) -> Option<&Prefix> {
self.prefix.as_ref()
pub fn prefix(&self) -> Ref<Option<Prefix>> {
self.prefix.borrow()
}
pub fn set_prefix(&self, prefix: Option<Prefix>) {
*self.prefix.borrow_mut() = prefix;
}
pub fn attrs(&self) -> Ref<[JS<Attr>]> {
@ -858,7 +862,9 @@ impl Element {
// Steps 3-4.
for element in inclusive_ancestor_elements {
// Step 1.
if element.namespace() != &ns!() && element.prefix().map(|p| &**p) == prefix.as_ref().map(|p| &**p) {
if element.namespace() != &ns!() &&
element.prefix().as_ref().map(|p| &**p) == prefix.as_ref().map(|p| &**p)
{
return element.namespace().clone();
}
@ -1436,13 +1442,13 @@ impl ElementMethods for Element {
// https://dom.spec.whatwg.org/#dom-element-prefix
fn GetPrefix(&self) -> Option<DOMString> {
self.prefix.as_ref().map(|p| DOMString::from(&**p))
self.prefix.borrow().as_ref().map(|p| DOMString::from(&**p))
}
// https://dom.spec.whatwg.org/#dom-element-tagname
fn TagName(&self) -> DOMString {
let name = self.tag_name.or_init(|| {
let qualified_name = match self.prefix {
let qualified_name = match *self.prefix.borrow() {
Some(ref prefix) => {
Cow::Owned(format!("{}:{}", &**prefix, &*self.local_name))
},