New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mutation observer API #16190
Mutation observer API #16190
Changes from 1 commit
73f2c6e
bee1340
a5af9a2
4ec5d92
16c09d4
e162f8a
b0af820
8e6d4e9
4797cc3
dd9ea19
4db8c26
1a7e2d4
ef51869
2d10eb7
3dd78ed
0160982
eefb95b
2cce8c5
7115abd
2821def
a82e79d
3bd4438
c6739ef
File filter...
Jump to…
incomplete code for mutationobserver and mutationrecord
- Loading branch information
| @@ -1,8 +1,37 @@ | ||
| use core::ptr::null; | ||
| use dom_struct::dom_struct; | ||
| use dom::bindings::codegen::Bindings::MutationObserverBinding::MutationObserverBinding::MutationObserverMethods; | ||
| use dom::bindings::codegen::Bindings::MutationObserverBinding::MutationObserverInit; | ||
| use dom::bindings::js::Root; | ||
| use dom::bindings::reflector::Reflector; | ||
| use dom::mutationrecord::MutationRecord; | ||
| use dom::node::Node; | ||
|
|
||
| #[dom_struct] | ||
| pub struct MutationObserver { | ||
| reflector_: Reflector, | ||
| } | ||
|
|
||
| impl MutationObserver { | ||
| } | ||
|
|
||
| impl MutationObserverMethods for MutationObserver { | ||
|
|
||
| //void observe(Node target, optional MutationObserverInit options); | ||
|
||
| fn Observe(&self, target: &Node, options: &MutationObserverInit) { | ||
| // TODO implement | ||
| } | ||
|
|
||
|
|
||
| //void disconnect(); | ||
| fn Disconnect(&self) { | ||
| // TODO implement | ||
| } | ||
|
|
||
| //sequence<MutationRecord> takeRecords(); | ||
| fn TakeRecords(&self) -> Vec<Root<MutationRecord>> { | ||
| return vec![]; | ||
| //TODO implement | ||
| } | ||
|
|
||
| } | ||
| @@ -1,8 +1,124 @@ | ||
| use core::ptr::null; | ||
| use dom_struct::dom_struct; | ||
| use dom::bindings::codegen::Bindings::MutationRecordBinding::MutationRecordBinding::MutationRecordMethods; | ||
| use dom::bindings::js::{JS, Root}; | ||
| use dom::bindings::str::DOMString; | ||
| use dom::bindings::reflector::Reflector; | ||
| use dom::node::Node; | ||
| use dom::nodelist::NodeList; | ||
| use dom::window::Window; | ||
|
|
||
| #[dom_struct] | ||
| pub struct MutationRecord { | ||
| reflector_: Reflector, | ||
|
|
||
| // readonly attribute DOMString record_type; | ||
jdm
Member
|
||
| record_type: DOMString, | ||
|
|
||
| // [SameObject] | ||
| // readonly attribute Node target; | ||
| target: Root<Node>, | ||
srivassumit
Author
Contributor
|
||
|
|
||
| // [SameObject] | ||
| // readonly attribute NodeList addedNodes; | ||
| addedNodes: Root<NodeList>, | ||
|
|
||
| // [SameObject] | ||
| // readonly attribute NodeList removedNodes; | ||
| removedNodes: Root<NodeList>, | ||
|
|
||
| // readonly attribute Node? previousSibling; | ||
| previousSibling: Root<Node>, | ||
|
|
||
| // readonly attribute Node? nextSibling; | ||
| nextSibling: Root<Node>, | ||
|
|
||
| // readonly attribute DOMString? attributeName; | ||
| attributeName: DOMString, | ||
|
|
||
| // readonly attribute DOMString? attributeNamespace; | ||
| attributeNamespace: DOMString, | ||
|
|
||
| // readonly attribute DOMString? oldValue; | ||
| oldValue: DOMString, | ||
jdm
Member
|
||
|
|
||
| } | ||
|
|
||
| impl MutationRecord { | ||
| fn new(window: &Window, record_type: DOMString, target: Root<Node>) -> Root<MutationRecord> { | ||
| MutationRecord { | ||
| reflector_: Reflector::new(), | ||
| record_type: record_type, | ||
| target: target, | ||
| addedNodes: NodeList::empty(window), | ||
| removedNodes: NodeList::empty(window), | ||
| previousSibling: None, | ||
| nextSibling: None, | ||
| attributeName: None, | ||
| attributeNamespace: None, | ||
| oldValue: None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl MutationRecordMethods for MutationRecord { | ||
|
|
||
| fn Type(&self) -> DOMString { | ||
| return self.record_type; | ||
| //return "characterData"; | ||
| //return "childList"; | ||
| } | ||
|
|
||
| fn Target(&self) -> Root<Node> { | ||
| return self.target; | ||
| } | ||
|
|
||
| fn AddedNodes(&self) -> Root<NodeList> { | ||
| return self.addedNodes; | ||
| } | ||
|
|
||
| fn RemovedNodes(&self) -> Root<NodeList> { | ||
| return self.removedNodes; | ||
| } | ||
|
|
||
| fn GetPreviousSibling(&self) -> Option<Root<Node>> { | ||
| if self.previousSibling.is_null() { | ||
| return None; | ||
| } else { | ||
| return Some(self.previousSibling); | ||
| } | ||
| } | ||
|
|
||
| fn GetNextSibling(&self) -> Option<Root<Node>> { | ||
| if self.nextSibling.is_null() { | ||
| return None; | ||
| } else { | ||
| return Some(self.nextSibling); | ||
| } | ||
| } | ||
|
|
||
| fn GetAttributeName(&self) -> Option<DOMString> { | ||
| if self.attributeName.is_null() { | ||
| return None; | ||
| } else { | ||
| return Some(self.attributeName); | ||
| } | ||
| } | ||
|
|
||
| fn GetAttributeNamespace(&self) -> Option<DOMString> { | ||
| if self.attributeNamespace.is_null() { | ||
| return None; | ||
| } else { | ||
| return Some(self.attributeNamespace); | ||
| } | ||
| } | ||
|
|
||
| fn GetOldValue(&self) -> Option<DOMString> { | ||
| if self.oldValue.is_null() { | ||
| return None; | ||
| } else { | ||
| return Some(self.oldValue); | ||
| } | ||
| } | ||
|
|
||
| } | ||
The comments should contain links to the DOM specification like https://dom.spec.whatwg.org/#dom-mutationobserver-observe instead.