Implement basic interface for MutationObserver and MutationRecord.

This commit is contained in:
Sumit 2017-03-16 15:46:45 -04:00 committed by Josh Matthews
parent 5421d833de
commit 107ac9ab56
8 changed files with 145 additions and 0 deletions

View file

@ -0,0 +1,40 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::Bindings::MutationObserverBinding;
use dom::bindings::codegen::Bindings::MutationObserverBinding::MutationCallback;
use dom::bindings::error::Fallible;
use dom::bindings::js::Root;
use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::window::Window;
use dom_struct::dom_struct;
use script_thread::ScriptThread;
use std::rc::Rc;
#[dom_struct]
pub struct MutationObserver {
reflector_: Reflector,
#[ignore_heap_size_of = "can't measure Rc values"]
callback: Rc<MutationCallback>,
}
impl MutationObserver {
fn new(global: &Window, callback: Rc<MutationCallback>) -> Root<MutationObserver> {
let boxed_observer = box MutationObserver::new_inherited(callback);
reflect_dom_object(boxed_observer, global, MutationObserverBinding::Wrap)
}
fn new_inherited(callback: Rc<MutationCallback>) -> MutationObserver {
MutationObserver {
reflector_: Reflector::new(),
callback: callback,
}
}
pub fn Constructor(global: &Window, callback: Rc<MutationCallback>) -> Fallible<Root<MutationObserver>> {
let observer = MutationObserver::new(global, callback);
ScriptThread::add_mutation_observer(&*observer);
Ok(observer)
}
}