mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Rewrite Document::SetTitle to use a match.
This commit is contained in:
parent
da16e54243
commit
2cbf7f4c7a
1 changed files with 15 additions and 15 deletions
|
@ -307,25 +307,25 @@ impl Document {
|
||||||
child.get().type_id == ElementNodeTypeId(HTMLHeadElementTypeId)
|
child.get().type_id == ElementNodeTypeId(HTMLHeadElementTypeId)
|
||||||
});
|
});
|
||||||
head_node.as_mut().map(|head| {
|
head_node.as_mut().map(|head| {
|
||||||
|
|
||||||
let mut title_node = head.children().find(|child| {
|
let mut title_node = head.children().find(|child| {
|
||||||
child.get().type_id == ElementNodeTypeId(HTMLTitleElementTypeId)
|
child.get().type_id == ElementNodeTypeId(HTMLTitleElementTypeId)
|
||||||
});
|
});
|
||||||
|
|
||||||
title_node.as_mut().map(|title_node| {
|
match title_node {
|
||||||
|
Some(ref mut title_node) => {
|
||||||
for mut title_child in title_node.children() {
|
for mut title_child in title_node.children() {
|
||||||
title_node.RemoveChild(&mut title_child);
|
title_node.RemoveChild(&mut title_child);
|
||||||
}
|
}
|
||||||
let new_text = self.CreateTextNode(abstract_self, title.clone());
|
let new_text = self.CreateTextNode(abstract_self, title.clone());
|
||||||
title_node.AppendChild(&mut NodeCast::from(&new_text));
|
title_node.AppendChild(&mut NodeCast::from(&new_text));
|
||||||
});
|
},
|
||||||
|
None => {
|
||||||
if title_node.is_none() {
|
|
||||||
let mut new_title: JS<Node> =
|
let mut new_title: JS<Node> =
|
||||||
NodeCast::from(&HTMLTitleElement::new(~"title", abstract_self));
|
NodeCast::from(&HTMLTitleElement::new(~"title", abstract_self));
|
||||||
let new_text = self.CreateTextNode(abstract_self, title.clone());
|
let new_text = self.CreateTextNode(abstract_self, title.clone());
|
||||||
new_title.AppendChild(&mut NodeCast::from(&new_text));
|
new_title.AppendChild(&mut NodeCast::from(&new_text));
|
||||||
head.AppendChild(&mut new_title);
|
head.AppendChild(&mut new_title);
|
||||||
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue