diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2017-01-06 16:16:48 +0100 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2017-01-07 19:21:02 +0100 |
commit | 0cb09468a0e39b7797f3cd540b8d47e0e1ba55a0 (patch) | |
tree | 067ea6e8a813b272a41124c016850021d2663e59 /components/script/dom/servoparser/html.rs | |
parent | 8caa56454002a66c7c73e7144da20731725b8edf (diff) | |
download | servo-0cb09468a0e39b7797f3cd540b8d47e0e1ba55a0.tar.gz servo-0cb09468a0e39b7797f3cd540b8d47e0e1ba55a0.zip |
Properly insert text in document when parsing
If the last child of a node is a Text child and we are inserting text in that node,
we need to append it to that Text child. Doing that means that
HTMLStyleElement::children_changed gets called less frequently, but that's not a
problem during parsing thanks to the pop hook.
Diffstat (limited to 'components/script/dom/servoparser/html.rs')
-rw-r--r-- | components/script/dom/servoparser/html.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/components/script/dom/servoparser/html.rs b/components/script/dom/servoparser/html.rs index 28f8735891e..4a8f01d639e 100644 --- a/components/script/dom/servoparser/html.rs +++ b/components/script/dom/servoparser/html.rs @@ -20,6 +20,7 @@ use dom::htmltemplateelement::HTMLTemplateElement; use dom::node::Node; use dom::processinginstruction::ProcessingInstruction; use dom::text::Text; +use dom::virtualmethods::vtable_for; use html5ever::Attribute; use html5ever::serialize::{AttrRef, Serializable, Serializer}; use html5ever::serialize::TraversalScope; @@ -124,7 +125,7 @@ struct Sink { document: JS<Document>, } -impl<'a> TreeSink for Sink { +impl TreeSink for Sink { type Output = Self; fn finish(self) -> Self { self } @@ -233,7 +234,11 @@ impl<'a> TreeSink for Sink { while let Some(ref child) = node.GetFirstChild() { new_parent.AppendChild(&child).unwrap(); } + } + fn pop(&mut self, node: JS<Node>) { + let node = Root::from_ref(&*node); + vtable_for(&node).pop(); } } @@ -243,10 +248,13 @@ fn insert(parent: &Node, reference_child: Option<&Node>, child: NodeOrText<JS<No assert!(parent.InsertBefore(&n, reference_child).is_ok()); }, NodeOrText::AppendText(t) => { - // FIXME(ajeffrey): convert directly from tendrils to DOMStrings - let s: String = t.into(); - let text = Text::new(DOMString::from(s), &parent.owner_doc()); - assert!(parent.InsertBefore(text.upcast(), reference_child).is_ok()); + if let Some(text) = parent.GetLastChild().and_then(Root::downcast::<Text>) { + text.upcast::<CharacterData>().append_data(&t); + } else { + let s: String = t.into(); + let text = Text::new(DOMString::from(s), &parent.owner_doc()); + parent.InsertBefore(text.upcast(), reference_child).unwrap(); + } } } } |