Skip to content

Commit

Permalink
Have CharacterData call children_changed on its parent when data is set.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jyc committed Jul 13, 2017
1 parent 3f2d747 commit 4142665
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 301 deletions.
14 changes: 13 additions & 1 deletion components/script/dom/characterdata.rs
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions components/script/dom/node.rs
Expand Up @@ -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> {
Expand Down Expand Up @@ -2541,13 +2546,17 @@ 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,
ChildrenMutation::Insert { next, .. } => Some(next),
ChildrenMutation::Prepend { next, .. } => Some(next),
ChildrenMutation::Replace { next, .. } => next,
ChildrenMutation::ReplaceAll { .. } => None,
ChildrenMutation::ChangeText => None,
}
}

Expand Down Expand Up @@ -2585,6 +2594,7 @@ impl<'a> ChildrenMutation<'a> {

ChildrenMutation::Replace { prev: None, next: None, .. } => unreachable!(),
ChildrenMutation::ReplaceAll { .. } => None,
ChildrenMutation::ChangeText => None,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/nodelist.rs
Expand Up @@ -279,6 +279,7 @@ impl ChildrenList {
self.last_index.set(middle as u32);
}
},
ChildrenMutation::ChangeText => {},
}
}

Expand Down

This file was deleted.

22 changes: 0 additions & 22 deletions tests/wpt/metadata-css/cssom-1_dev/html/selectorSerialize.htm.ini
Expand Up @@ -3,24 +3,6 @@
[:nth-child serialization produces canonical form]
expected: FAIL

[single universal selector shows '*' when serialized.]
expected: FAIL

[single type (simple) selector in the sequence of simple selectors that is not a universal selector]
expected: FAIL

[single class (simple) selector in the sequence of simple selectors that is not a universal selector]
expected: FAIL

[single id (simple) selector in the sequence of simple selectors that is not a universal selector]
expected: FAIL

[single pseudo (simple) selector which does not accept arguments in the sequence of simple selectors that is not a universal selector]
expected: FAIL

[single pseudo (simple) selector "lang" which accepts arguments in the sequence of simple selectors that is not a universal selector]
expected: FAIL

[single pseudo (simple) selector "nth-child" which accepts arguments in the sequence of simple selectors that is not a universal selector]
expected: FAIL

Expand All @@ -32,7 +14,3 @@

[single pseudo (simple) selector ":nth-last-of-type" which accepts arguments in the sequence of simple selectors that is not a universal selector]
expected: FAIL

[single pseudo (simple) selector ":not" which accepts arguments in the sequence of simple selectors that is not a universal selector]
expected: FAIL

@@ -1,59 +1,11 @@
[serialize-namespaced-type-selectors.htm]
type: testharness
[Simple type selector]
expected: FAIL

[Type selector without a namespace]
expected: FAIL

[Type selector with any namespace]
expected: FAIL

[Universal selector]
expected: FAIL

[Universal selector without a namespace]
expected: FAIL

[Universal selector in any namespace]
expected: FAIL

[Type selector with namespace]
expected: FAIL

[Universal selector with namespace]
expected: FAIL

[Simple type selector followed by class]
expected: FAIL

[Simple type selector followed by id]
expected: FAIL

[Simple type selector followed by pseudo class]
expected: FAIL

[Simple type selector followed by pseudo element]
expected: FAIL

[Simple type selector followed by atttribute selector]
expected: FAIL

[Type selector without a namespace followed by class]
expected: FAIL

[Type selector without a namespace followed by id]
expected: FAIL

[Type selector without a namespace followed by pseudo class]
expected: FAIL

[Type selector without a namespace followed by pseudo element]
expected: FAIL

[Type selector without a namespace followed by attribute selector]
expected: FAIL

[Type selector with any namespace followed by class]
expected: FAIL

Expand Down Expand Up @@ -84,21 +36,6 @@
[Universal selector followed by attribute selector]
expected: FAIL

[Universal selector without a namespace followed by class]
expected: FAIL

[Universal selector without a namespace followed by id]
expected: FAIL

[Universal selector without a namespace followed by pseudo class]
expected: FAIL

[Universal selector without a namespace followed by pseudo element]
expected: FAIL

[Universal selector without a namespace followed by attribute selector]
expected: FAIL

[Universal selector in any namespace followed by class]
expected: FAIL

Expand All @@ -114,36 +51,6 @@
[Universal selector in any namespace followed by attribute selector]
expected: FAIL

[Type selector with namespace followed by class]
expected: FAIL

[Type selector with namespace followed by id]
expected: FAIL

[Type selector with namespace followed by pseudo class]
expected: FAIL

[Type selector with namespace followed by pseudo element]
expected: FAIL

[Type selector with namespace followed by attribute selector]
expected: FAIL

[Universal selector with namespace followed by class]
expected: FAIL

[Universal selector with namespace followed by id]
expected: FAIL

[Universal selector with namespace followed by pseudo class]
expected: FAIL

[Universal selector with namespace followed by pseudo element]
expected: FAIL

[Universal selector with namespace followed by attribute selector]
expected: FAIL

[Type selector with namespace equal to default namespace]
expected: FAIL

Expand Down
21 changes: 0 additions & 21 deletions tests/wpt/metadata/cssom/selectorSerialize.html.ini
Expand Up @@ -3,24 +3,6 @@
[:nth-child serialization produces canonical form]
expected: FAIL

[single universal selector shows '*' when serialized.]
expected: FAIL

[single type (simple) selector in the sequence of simple selectors that is not a universal selector]
expected: FAIL

[single class (simple) selector in the sequence of simple selectors that is not a universal selector]
expected: FAIL

[single id (simple) selector in the sequence of simple selectors that is not a universal selector]
expected: FAIL

[single pseudo (simple) selector which does not accept arguments in the sequence of simple selectors that is not a universal selector]
expected: FAIL

[single pseudo (simple) selector "lang" which accepts arguments in the sequence of simple selectors that is not a universal selector]
expected: FAIL

[single pseudo (simple) selector "nth-child" which accepts arguments in the sequence of simple selectors that is not a universal selector]
expected: FAIL

Expand All @@ -33,6 +15,3 @@
[single pseudo (simple) selector ":nth-last-of-type" which accepts arguments in the sequence of simple selectors that is not a universal selector]
expected: FAIL

[single pseudo (simple) selector ":not" which accepts arguments in the sequence of simple selectors that is not a universal selector]
expected: FAIL

0 comments on commit 4142665

Please sign in to comment.