mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Implement basic interface for MutationObserver and MutationRecord.
This commit is contained in:
parent
5421d833de
commit
107ac9ab56
8 changed files with 145 additions and 0 deletions
40
components/script/dom/mutationobserver.rs
Normal file
40
components/script/dom/mutationobserver.rs
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue