Have CharacterData call children_changed on its parent when data is set.

Have CharacterData.SetData call children_changed on its parent when
data is set (if it is a Text node) so that HTMLStyleElement parents can
re-parse. Add variant ChildrenMutation::Text for it to use as the
mutation.

This fixes an issue where an empty <style> element's data is set but the
style is not updated. An HTMLStyleElement parent re-parses in its
children_changed implementation.
This commit is contained in:
Jonathan Chan 2017-06-07 10:16:05 -07:00
parent 3f2d747689
commit 4142665282
8 changed files with 24 additions and 301 deletions

View file

@ -6,6 +6,7 @@
use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods;
use dom::bindings::codegen::Bindings::NodeBinding::NodeBinding::NodeMethods;
use dom::bindings::codegen::Bindings::ProcessingInstructionBinding::ProcessingInstructionMethods;
use dom::bindings::codegen::InheritTypes::{CharacterDataTypeId, NodeTypeId};
use dom::bindings::codegen::UnionTypes::NodeOrString;
@ -16,9 +17,10 @@ use dom::bindings::str::DOMString;
use dom::comment::Comment;
use dom::document::Document;
use dom::element::Element;
use dom::node::{Node, NodeDamage};
use dom::node::{ChildrenMutation, Node, NodeDamage};
use dom::processinginstruction::ProcessingInstruction;
use dom::text::Text;
use dom::virtualmethods::vtable_for;
use dom_struct::dom_struct;
use servo_config::opts;
use std::cell::Ref;
@ -85,6 +87,16 @@ impl CharacterDataMethods for CharacterData {
self.content_changed();
let node = self.upcast::<Node>();
node.ranges().replace_code_units(node, 0, old_length, new_length);
// If this is a Text node, we might need to re-parse (say, if our parent
// is a <style> element.) We don't need to if this is a Comment or
// ProcessingInstruction.
if let Some(_) = self.downcast::<Text>() {
if let Some(parent_node) = node.GetParentNode() {
let mutation = ChildrenMutation::ChangeText;
vtable_for(&parent_node).children_changed(&mutation);
}
}
}
// https://dom.spec.whatwg.org/#dom-characterdata-length

View file

@ -2490,6 +2490,11 @@ pub enum ChildrenMutation<'a> {
next: Option<&'a Node>,
},
ReplaceAll { removed: &'a [&'a Node], added: &'a [&'a Node] },
/// Mutation for when a Text node's data is modified.
/// This doesn't change the structure of the list, which is what the other
/// variants' fields are stored for at the moment, so this can just have no
/// fields.
ChangeText,
}
impl<'a> ChildrenMutation<'a> {
@ -2541,6 +2546,9 @@ impl<'a> ChildrenMutation<'a> {
}
/// Get the child that follows the added or removed children.
/// Currently only used when this mutation might force us to
/// restyle later children (see HAS_SLOW_SELECTOR_LATER_SIBLINGS and
/// Element's implementation of VirtualMethods::children_changed).
pub fn next_child(&self) -> Option<&Node> {
match *self {
ChildrenMutation::Append { .. } => None,
@ -2548,6 +2556,7 @@ impl<'a> ChildrenMutation<'a> {
ChildrenMutation::Prepend { next, .. } => Some(next),
ChildrenMutation::Replace { next, .. } => next,
ChildrenMutation::ReplaceAll { .. } => None,
ChildrenMutation::ChangeText => None,
}
}
@ -2585,6 +2594,7 @@ impl<'a> ChildrenMutation<'a> {
ChildrenMutation::Replace { prev: None, next: None, .. } => unreachable!(),
ChildrenMutation::ReplaceAll { .. } => None,
ChildrenMutation::ChangeText => None,
}
}
}

View file

@ -279,6 +279,7 @@ impl ChildrenList {
self.last_index.set(middle as u32);
}
},
ChildrenMutation::ChangeText => {},
}
}