Auto merge of #16883 - jdm:mutationobserver, r=jdm

Mutation Observer API

Rebased from #16668.

- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix (partially) #6633
- [X] There are tests for these changes

<!-- 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/16883)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-05-17 01:21:40 -05:00 committed by GitHub
commit 5da0aa9f11
15 changed files with 432 additions and 180 deletions

View file

@ -7,6 +7,7 @@
use app_units::Au;
use devtools_traits::NodeInfo;
use document_loader::DocumentLoader;
use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods;
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods;
@ -46,6 +47,7 @@ use dom::htmllinkelement::HTMLLinkElement;
use dom::htmlmetaelement::HTMLMetaElement;
use dom::htmlstyleelement::HTMLStyleElement;
use dom::htmltextareaelement::{HTMLTextAreaElement, LayoutHTMLTextAreaElementHelpers};
use dom::mutationobserver::RegisteredObserver;
use dom::nodelist::NodeList;
use dom::processinginstruction::ProcessingInstruction;
use dom::range::WeakRangeVec;
@ -72,7 +74,7 @@ use selectors::matching::matches_selector_list;
use selectors::parser::SelectorList;
use servo_url::ServoUrl;
use std::borrow::ToOwned;
use std::cell::{Cell, UnsafeCell};
use std::cell::{Cell, UnsafeCell, RefMut};
use std::cmp::max;
use std::default::Default;
use std::iter;
@ -138,6 +140,9 @@ pub struct Node {
/// node is finalized.
style_and_layout_data: Cell<Option<OpaqueStyleAndLayoutData>>,
/// Registered observers for this node.
mutation_observers: DOMRefCell<Vec<RegisteredObserver>>,
unique_id: UniqueId,
}
@ -363,6 +368,11 @@ impl Node {
}
}
/// Return all registered mutation observers for this node.
pub fn registered_mutation_observers(&self) -> RefMut<Vec<RegisteredObserver>> {
self.mutation_observers.borrow_mut()
}
/// Dumps the subtree rooted at this node, for debugging.
pub fn dump(&self) {
self.dump_indent(0);
@ -1411,6 +1421,8 @@ impl Node {
style_and_layout_data: Cell::new(None),
mutation_observers: Default::default(),
unique_id: UniqueId::new(),
}
}