mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Share code between HTMLScriptElement:Text and Node:GetTextContent
Added a function in Node called collect_text_contents which is called from both places. Fixes #3157
This commit is contained in:
parent
8af758f591
commit
d12243df0d
2 changed files with 15 additions and 18 deletions
|
@ -1408,6 +1408,18 @@ impl Node {
|
|||
pub unsafe fn unsafe_get_flags(&self) -> *const NodeFlags {
|
||||
mem::transmute(&self.flags)
|
||||
}
|
||||
|
||||
pub fn collect_text_contents<'a, T: Iterator<JSRef<'a, Node>>>(mut iterator: T) -> String {
|
||||
let mut content = String::new();
|
||||
for node in iterator {
|
||||
let text: Option<&JSRef<Text>> = TextCast::to_ref(&node);
|
||||
match text {
|
||||
Some(text) => content.push_str(text.characterdata.data.borrow().as_slice()),
|
||||
None => (),
|
||||
}
|
||||
}
|
||||
content
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> NodeMethods for JSRef<'a, Node> {
|
||||
|
@ -1553,13 +1565,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
|||
match self.type_id {
|
||||
DocumentFragmentNodeTypeId |
|
||||
ElementNodeTypeId(..) => {
|
||||
let mut content = String::new();
|
||||
for node in self.traverse_preorder() {
|
||||
if node.is_text() {
|
||||
let text: &JSRef<Text> = TextCast::to_ref(&node).unwrap();
|
||||
content.push_str(text.deref().characterdata.data.deref().borrow().as_slice());
|
||||
}
|
||||
}
|
||||
let content = Node::collect_text_contents(self.traverse_preorder());
|
||||
Some(content)
|
||||
}
|
||||
CommentNodeTypeId |
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue