1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/* 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;
use dom::bindings::codegen::Bindings::MutationRecordBinding::MutationRecordBinding::MutationRecordMethods;
use dom::bindings::js::{JS, Root};
use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::str::DOMString;
use dom::node::{Node, window_from_node};
use dom::nodelist::NodeList;
use dom_struct::dom_struct;
use html5ever::{LocalName, Namespace};
#[dom_struct]
pub struct MutationRecord {
reflector_: Reflector,
record_type: DOMString,
target: JS<Node>,
attribute_name: Option<DOMString>,
attribute_namespace: Option<DOMString>,
old_value: Option<DOMString>,
}
impl MutationRecord {
#[allow(unrooted_must_root)]
pub fn attribute_mutated(target: &Node,
attribute_name: &LocalName,
attribute_namespace: Option<&Namespace>,
old_value: Option<DOMString>) -> Root<MutationRecord> {
let record = box MutationRecord::new_inherited("attributes",
target,
Some(DOMString::from(&**attribute_name)),
attribute_namespace.map(|n| DOMString::from(&**n)),
old_value);
reflect_dom_object(record, &*window_from_node(target), MutationRecordBinding::Wrap)
}
fn new_inherited(record_type: &str,
target: &Node,
attribute_name: Option<DOMString>,
attribute_namespace: Option<DOMString>,
old_value: Option<DOMString>) -> MutationRecord {
MutationRecord {
reflector_: Reflector::new(),
record_type: DOMString::from(record_type),
target: JS::from_ref(target),
attribute_name: attribute_name,
attribute_namespace: attribute_namespace,
old_value: old_value,
}
}
}
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> {
Root::from_ref(&*self.target)
}
// https://dom.spec.whatwg.org/#dom-mutationrecord-attributename
fn GetAttributeName(&self) -> Option<DOMString> {
self.attribute_name.clone()
}
// https://dom.spec.whatwg.org/#dom-mutationrecord-attributenamespace
fn GetAttributeNamespace(&self) -> Option<DOMString> {
self.attribute_namespace.clone()
}
// https://dom.spec.whatwg.org/#dom-mutationrecord-oldvalue
fn GetOldValue(&self) -> Option<DOMString> {
self.old_value.clone()
}
// https://dom.spec.whatwg.org/#dom-mutationrecord-addednodes
fn AddedNodes(&self) -> Root<NodeList> {
let window = window_from_node(&*self.target);
NodeList::empty(&window)
}
// https://dom.spec.whatwg.org/#dom-mutationrecord-removednodes
fn RemovedNodes(&self) -> Root<NodeList> {
let window = window_from_node(&*self.target);
NodeList::empty(&window)
}
// https://dom.spec.whatwg.org/#dom-mutationrecord-previoussibling
fn GetPreviousSibling(&self) -> Option<Root<Node>> {
None
}
// https://dom.spec.whatwg.org/#dom-mutationrecord-previoussibling
fn GetNextSibling(&self) -> Option<Root<Node>> {
None
}
}
|