Skip to content
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

Closed
wants to merge 23 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
73f2c6e
Initial Files for MutationObserverAPI
srivassumit Mar 16, 2017
bee1340
add a vector of MutationObserver objects as a member of ScriptThread
srivassumit Mar 16, 2017
a5af9a2
Merge branch 'master' of https://github.com/servo/servo into Mutation…
srivassumit Mar 16, 2017
4ec5d92
Merge branch 'master' of https://github.com/servo/servo into Mutation…
srivassumit Mar 17, 2017
16c09d4
incomplete code for mutationobserver and mutationrecord
srivassumit Mar 20, 2017
e162f8a
fixed build errors, Constructor is pending
srivassumit Mar 21, 2017
b0af820
Resolving merge conflicts
krishnakarthick1993 Mar 23, 2017
8e6d4e9
added Mutation Observer Constructor
srivassumit Mar 29, 2017
4797cc3
Merge branch 'MutationObserver-dev' of https://github.com/srivassumit…
srivassumit Mar 29, 2017
dd9ea19
Merge branch 'master' of https://github.com/servo/servo into Mutation…
srivassumit Mar 29, 2017
4db8c26
changes for constructor
srivassumit Mar 30, 2017
1a7e2d4
Merge branch 'master' of https://github.com/servo/servo into Mutation…
srivassumit Mar 30, 2017
ef51869
Update mutationrecord.rs
srivassumit Mar 31, 2017
2d10eb7
Update script_thread.rs
srivassumit Mar 31, 2017
3dd78ed
more changes as per review comments
srivassumit Apr 1, 2017
0160982
fixed test test-tidy issues, accessed ScriptThread from mutationobserver
srivassumit Apr 1, 2017
eefb95b
Merge branch 'master' of https://github.com/servo/servo into Mutation…
srivassumit Apr 1, 2017
2cce8c5
modifications for review comments
srivassumit Apr 5, 2017
7115abd
Merge branch 'master' of https://github.com/servo/servo into Mutation…
srivassumit Apr 5, 2017
2821def
changes as per review comments
srivassumit Apr 5, 2017
a82e79d
Merge branch 'master' of https://github.com/servo/servo into Mutatio…
srivassumit Apr 5, 2017
3bd4438
removed unused imports and fixed review comments.
srivassumit Apr 5, 2017
c6739ef
removed unused import
srivassumit Apr 5, 2017
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

incomplete code for mutationobserver and mutationrecord

  • Loading branch information
srivassumit committed Mar 20, 2017
commit 16c09d48b1966437405239af3b4668c690fddc79
@@ -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);

This comment has been minimized.

Copy link
@jdm

jdm Mar 30, 2017

Member

The comments should contain links to the DOM specification like https://dom.spec.whatwg.org/#dom-mutationobserver-observe instead.

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;

This comment has been minimized.

Copy link
@jdm

jdm Mar 30, 2017

Member

Rather than duplicating IDL constructs in the comments, we should be describing what these fields used are for in English prose instead.

record_type: DOMString,

// [SameObject]
// readonly attribute Node target;
target: Root<Node>,

This comment has been minimized.

Copy link
@jdm

jdm Mar 30, 2017

Member

This should be JS<Node> instead.

This comment has been minimized.

Copy link
@srivassumit

srivassumit Mar 31, 2017

Author Contributor

Hi Josh, when I make this change, it gives me the following error:

error[E0053]: method Targethas an incompatible type for trait --> /home/sumit/Dropbox/NCSU/OODD/Servo/MyWork/servo/components/script/dom/mutationrecord.rs:38:25 | 38 | fn Target(&self) -> JS<Node> { | ^^^^^^^^ expected structdom::bindings::js::Root, found struct dom::bindings::js::JS| ::: /home/sumit/Dropbox/NCSU/OODD/Servo/MyWork/servo/target/debug/build/script-bb44ff0630eb7b72/out/Bindings/MutationRecordBinding.rs | 617 | fn Target(&self) -> Root<Node>; | ---------- type in trait | = note: expected typefn(&dom::mutationrecord::MutationRecord) -> dom::bindings::js::Rootdom::node::Nodefound typefn(&dom::mutationrecord::MutationRecord) -> dom::bindings::js::JSdom::node::Node`

It seems that it is expecting a Root element in the '/servo/target/debug/build/script-bb44ff0630eb7b72/out/Bindings/MutationRecordBinding.rs' file

This comment has been minimized.

Copy link
@KiChjang

KiChjang Mar 31, 2017

Member

The field in the struct should be JS<Node>, but the return value of fn Target(&self) should be Root<Node>. Use Root::from_ref(&*self.target) to get a Root<T> from a JS<T>.


// [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,

This comment has been minimized.

Copy link
@jdm

jdm Mar 30, 2017

Member

Given my request to remove the methods we don't implement yet, let's remove all of these members except for record_type and target.


}

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);
}
}

}
@@ -2,9 +2,12 @@
interface MutationRecord
{
readonly attribute DOMString type;
[SameObject] readonly attribute Node target;
[SameObject] readonly attribute NodeList addedNodes;
[SameObject] readonly attribute NodeList removedNodes;
[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;
@@ -46,6 +46,7 @@ use dom::event::{Event, EventBubbles, EventCancelable};
use dom::globalscope::GlobalScope;
use dom::htmlanchorelement::HTMLAnchorElement;
use dom::htmliframeelement::HTMLIFrameElement;
use dom::mutationobserver::MutationObserver;
use dom::node::{Node, NodeDamage, window_from_node};
use dom::serviceworker::TrustedServiceWorkerAddress;
use dom::serviceworkerregistration::ServiceWorkerRegistration;
@@ -726,7 +727,7 @@ impl ScriptThread {

microtask_queue: MicrotaskQueue::default(),

mutation_observers: Vec![],
mutation_observers: vec![],

layout_to_constellation_chan: state.layout_to_constellation_chan,

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.