aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/mutationrecord.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-05-20 15:04:43 -0500
committerGitHub <noreply@github.com>2017-05-20 15:04:43 -0500
commit323760f47e79b49ef8db4484cca1969bc26b5413 (patch)
tree922ea79e79299ff090177517a62f359589d12020 /components/script/dom/mutationrecord.rs
parent05a26a29967b4cb70cac0055d0a177881e047efd (diff)
parent0290e405ce2e090f8b9c581acd9df585aebb0672 (diff)
downloadservo-323760f47e79b49ef8db4484cca1969bc26b5413.tar.gz
servo-323760f47e79b49ef8db4484cca1969bc26b5413.zip
Auto merge of #16933 - MortimerGoro:mutation_children, r=jdm
Implement MutationObserver childList mutations. <!-- Please describe your changes on the following line: --> Implement MutationObserver childList mutations --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [x] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16933) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/mutationrecord.rs')
-rw-r--r--components/script/dom/mutationrecord.rs55
1 files changed, 46 insertions, 9 deletions
diff --git a/components/script/dom/mutationrecord.rs b/components/script/dom/mutationrecord.rs
index 439f4ae02b5..00d96e258c4 100644
--- a/components/script/dom/mutationrecord.rs
+++ b/components/script/dom/mutationrecord.rs
@@ -4,7 +4,7 @@
use dom::bindings::codegen::Bindings::MutationRecordBinding::MutationRecordBinding;
use dom::bindings::codegen::Bindings::MutationRecordBinding::MutationRecordBinding::MutationRecordMethods;
-use dom::bindings::js::{JS, Root};
+use dom::bindings::js::{JS, MutNullableJS, Root};
use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::str::DOMString;
use dom::node::{Node, window_from_node};
@@ -20,6 +20,10 @@ pub struct MutationRecord {
attribute_name: Option<DOMString>,
attribute_namespace: Option<DOMString>,
old_value: Option<DOMString>,
+ added_nodes: MutNullableJS<NodeList>,
+ removed_nodes: MutNullableJS<NodeList>,
+ next_sibling: Option<JS<Node>>,
+ prev_sibling: Option<JS<Node>>,
}
impl MutationRecord {
@@ -32,15 +36,40 @@ impl MutationRecord {
target,
Some(DOMString::from(&**attribute_name)),
attribute_namespace.map(|n| DOMString::from(&**n)),
- old_value);
+ old_value,
+ None, None, None, None);
reflect_dom_object(record, &*window_from_node(target), MutationRecordBinding::Wrap)
}
+ pub fn child_list_mutated(target: &Node,
+ added_nodes: Option<&[&Node]>,
+ removed_nodes: Option<&[&Node]>,
+ next_sibling: Option<&Node>,
+ prev_sibling: Option<&Node>) -> Root<MutationRecord> {
+ let window = window_from_node(target);
+ let added_nodes = added_nodes.map(|list| NodeList::new_simple_list_slice(&window, list));
+ let removed_nodes = removed_nodes.map(|list| NodeList::new_simple_list_slice(&window, list));
+
+ reflect_dom_object(box MutationRecord::new_inherited("childList",
+ target,
+ None, None, None,
+ added_nodes.as_ref().map(|list| &**list),
+ removed_nodes.as_ref().map(|list| &**list),
+ next_sibling,
+ prev_sibling),
+ &*window,
+ MutationRecordBinding::Wrap)
+ }
+
fn new_inherited(record_type: &str,
target: &Node,
attribute_name: Option<DOMString>,
attribute_namespace: Option<DOMString>,
- old_value: Option<DOMString>) -> MutationRecord {
+ old_value: Option<DOMString>,
+ added_nodes: Option<&NodeList>,
+ removed_nodes: Option<&NodeList>,
+ next_sibling: Option<&Node>,
+ prev_sibling: Option<&Node>) -> MutationRecord {
MutationRecord {
reflector_: Reflector::new(),
record_type: DOMString::from(record_type),
@@ -48,6 +77,10 @@ impl MutationRecord {
attribute_name: attribute_name,
attribute_namespace: attribute_namespace,
old_value: old_value,
+ added_nodes: MutNullableJS::new(added_nodes),
+ removed_nodes: MutNullableJS::new(removed_nodes),
+ next_sibling: next_sibling.map(JS::from_ref),
+ prev_sibling: prev_sibling.map(JS::from_ref),
}
}
}
@@ -80,24 +113,28 @@ impl MutationRecordMethods for MutationRecord {
// https://dom.spec.whatwg.org/#dom-mutationrecord-addednodes
fn AddedNodes(&self) -> Root<NodeList> {
- let window = window_from_node(&*self.target);
- NodeList::empty(&window)
+ self.added_nodes.or_init(|| {
+ let window = window_from_node(&*self.target);
+ NodeList::empty(&window)
+ })
}
// https://dom.spec.whatwg.org/#dom-mutationrecord-removednodes
fn RemovedNodes(&self) -> Root<NodeList> {
- let window = window_from_node(&*self.target);
- NodeList::empty(&window)
+ self.removed_nodes.or_init(|| {
+ let window = window_from_node(&*self.target);
+ NodeList::empty(&window)
+ })
}
// https://dom.spec.whatwg.org/#dom-mutationrecord-previoussibling
fn GetPreviousSibling(&self) -> Option<Root<Node>> {
- None
+ self.prev_sibling.as_ref().map(|node| Root::from_ref(&**node))
}
// https://dom.spec.whatwg.org/#dom-mutationrecord-previoussibling
fn GetNextSibling(&self) -> Option<Root<Node>> {
- None
+ self.next_sibling.as_ref().map(|node| Root::from_ref(&**node))
}
}