mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00: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
|
@ -378,6 +378,8 @@ pub mod messageevent;
|
||||||
pub mod mimetype;
|
pub mod mimetype;
|
||||||
pub mod mimetypearray;
|
pub mod mimetypearray;
|
||||||
pub mod mouseevent;
|
pub mod mouseevent;
|
||||||
|
pub mod mutationobserver;
|
||||||
|
pub mod mutationrecord;
|
||||||
pub mod namednodemap;
|
pub mod namednodemap;
|
||||||
pub mod navigator;
|
pub mod navigator;
|
||||||
pub mod navigatorinfo;
|
pub mod navigatorinfo;
|
||||||
|
|
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)
|
||||||
|
}
|
||||||
|
}
|
34
components/script/dom/mutationrecord.rs
Normal file
34
components/script/dom/mutationrecord.rs
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/* 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::MutationRecordBinding::MutationRecordBinding::MutationRecordMethods;
|
||||||
|
use dom::bindings::js::{JS, Root};
|
||||||
|
use dom::bindings::reflector::Reflector;
|
||||||
|
use dom::bindings::str::DOMString;
|
||||||
|
use dom::node::Node;
|
||||||
|
use dom_struct::dom_struct;
|
||||||
|
|
||||||
|
#[dom_struct]
|
||||||
|
pub struct MutationRecord {
|
||||||
|
reflector_: Reflector,
|
||||||
|
|
||||||
|
//property for record type
|
||||||
|
record_type: DOMString,
|
||||||
|
|
||||||
|
//property for target node
|
||||||
|
target: JS<Node>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MutationRecordMethods for MutationRecord {
|
||||||
|
// https://dom.spec.whatwg.org/#dom-mutationrecord-type
|
||||||
|
fn Type(&self) -> DOMString {
|
||||||
|
self.record_type.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#dom-mutationrecord-target
|
||||||
|
fn Target(&self) -> Root<Node> {
|
||||||
|
return Root::from_ref(&*self.target);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
27
components/script/dom/webidls/MutationObserver.webidl
Normal file
27
components/script/dom/webidls/MutationObserver.webidl
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/* 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/. */
|
||||||
|
/*
|
||||||
|
* The origin of this IDL file is:
|
||||||
|
* https://dom.spec.whatwg.org/#mutationobserver
|
||||||
|
*/
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#mutationobserver
|
||||||
|
[Pref="dom.mutation_observer.enabled", Constructor(MutationCallback callback)]
|
||||||
|
interface MutationObserver {
|
||||||
|
//void observe(Node target, optional MutationObserverInit options);
|
||||||
|
//void disconnect();
|
||||||
|
//sequence<MutationRecord> takeRecords();
|
||||||
|
};
|
||||||
|
|
||||||
|
callback MutationCallback = void (sequence<MutationRecord> mutations, MutationObserver observer);
|
||||||
|
|
||||||
|
dictionary MutationObserverInit {
|
||||||
|
boolean childList = false;
|
||||||
|
boolean attributes;
|
||||||
|
boolean characterData;
|
||||||
|
boolean subtree = false;
|
||||||
|
boolean attributeOldValue;
|
||||||
|
boolean characterDataOldValue;
|
||||||
|
sequence<DOMString> attributeFilter;
|
||||||
|
};
|
24
components/script/dom/webidls/MutationRecord.webidl
Normal file
24
components/script/dom/webidls/MutationRecord.webidl
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
/* 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/. */
|
||||||
|
/*
|
||||||
|
* The origin of this IDL file is:
|
||||||
|
* https://dom.spec.whatwg.org/#mutationrecord
|
||||||
|
*/
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#mutationrecord
|
||||||
|
[Pref="dom.mutation_observer.enabled", Exposed=Window]
|
||||||
|
interface MutationRecord {
|
||||||
|
readonly attribute DOMString type;
|
||||||
|
[SameObject]
|
||||||
|
readonly attribute Node target;
|
||||||
|
//[SameObject]
|
||||||
|
//readonly attribute NodeList addedNodes;
|
||||||
|
//[SameObject]
|
||||||
|
//readonly attribute NodeList removedNodes;
|
||||||
|
//readonly attribute Node? previousSibling;
|
||||||
|
//readonly attribute Node? nextSibling;
|
||||||
|
//readonly attribute DOMString? attributeName;
|
||||||
|
//readonly attribute DOMString? attributeNamespace;
|
||||||
|
//readonly attribute DOMString? oldValue;
|
||||||
|
};
|
|
@ -46,6 +46,7 @@ use dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
use dom::globalscope::GlobalScope;
|
use dom::globalscope::GlobalScope;
|
||||||
use dom::htmlanchorelement::HTMLAnchorElement;
|
use dom::htmlanchorelement::HTMLAnchorElement;
|
||||||
use dom::htmliframeelement::HTMLIFrameElement;
|
use dom::htmliframeelement::HTMLIFrameElement;
|
||||||
|
use dom::mutationobserver::MutationObserver;
|
||||||
use dom::node::{Node, NodeDamage, window_from_node};
|
use dom::node::{Node, NodeDamage, window_from_node};
|
||||||
use dom::serviceworker::TrustedServiceWorkerAddress;
|
use dom::serviceworker::TrustedServiceWorkerAddress;
|
||||||
use dom::serviceworkerregistration::ServiceWorkerRegistration;
|
use dom::serviceworkerregistration::ServiceWorkerRegistration;
|
||||||
|
@ -480,6 +481,9 @@ pub struct ScriptThread {
|
||||||
|
|
||||||
microtask_queue: MicrotaskQueue,
|
microtask_queue: MicrotaskQueue,
|
||||||
|
|
||||||
|
/// The unit of related similar-origin browsing contexts' list of MutationObserver objects
|
||||||
|
mutation_observers: DOMRefCell<Vec<JS<MutationObserver>>>,
|
||||||
|
|
||||||
/// A handle to the webvr thread, if available
|
/// A handle to the webvr thread, if available
|
||||||
webvr_thread: Option<IpcSender<WebVRMsg>>,
|
webvr_thread: Option<IpcSender<WebVRMsg>>,
|
||||||
|
|
||||||
|
@ -570,6 +574,15 @@ impl ScriptThreadFactory for ScriptThread {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ScriptThread {
|
impl ScriptThread {
|
||||||
|
pub fn add_mutation_observer(observer: &MutationObserver) {
|
||||||
|
SCRIPT_THREAD_ROOT.with(|root| {
|
||||||
|
let script_thread = unsafe { &*root.get().unwrap() };
|
||||||
|
script_thread.mutation_observers
|
||||||
|
.borrow_mut()
|
||||||
|
.push(JS::from_ref(observer));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn mark_document_with_no_blocked_loads(doc: &Document) {
|
pub fn mark_document_with_no_blocked_loads(doc: &Document) {
|
||||||
SCRIPT_THREAD_ROOT.with(|root| {
|
SCRIPT_THREAD_ROOT.with(|root| {
|
||||||
let script_thread = unsafe { &*root.get().unwrap() };
|
let script_thread = unsafe { &*root.get().unwrap() };
|
||||||
|
@ -722,6 +735,8 @@ impl ScriptThread {
|
||||||
|
|
||||||
microtask_queue: MicrotaskQueue::default(),
|
microtask_queue: MicrotaskQueue::default(),
|
||||||
|
|
||||||
|
mutation_observers: Default::default(),
|
||||||
|
|
||||||
layout_to_constellation_chan: state.layout_to_constellation_chan,
|
layout_to_constellation_chan: state.layout_to_constellation_chan,
|
||||||
|
|
||||||
webvr_thread: state.webvr_thread,
|
webvr_thread: state.webvr_thread,
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
"dom.forcetouch.enabled": false,
|
"dom.forcetouch.enabled": false,
|
||||||
"dom.mouseevent.which.enabled": false,
|
"dom.mouseevent.which.enabled": false,
|
||||||
"dom.mozbrowser.enabled": false,
|
"dom.mozbrowser.enabled": false,
|
||||||
|
"dom.mutation_observer.enabled": false,
|
||||||
"dom.permissions.enabled": false,
|
"dom.permissions.enabled": false,
|
||||||
"dom.permissions.testing.allowed_in_nonsecure_contexts": false,
|
"dom.permissions.testing.allowed_in_nonsecure_contexts": false,
|
||||||
"dom.serviceworker.timeout_seconds": 60,
|
"dom.serviceworker.timeout_seconds": 60,
|
||||||
|
|
2
tests/wpt/metadata/dom/nodes/__dir__.ini
Normal file
2
tests/wpt/metadata/dom/nodes/__dir__.ini
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
prefs: ["dom.mutation_observer.enabled:true"]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue