1 /*
2 * Copyright (c) 2002-2025 Gargoyle Software Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 package org.htmlunit.javascript.host.dom;
16
17 import java.util.ArrayList;
18
19 import org.htmlunit.corejs.javascript.ScriptableObject;
20 import org.htmlunit.javascript.HtmlUnitScriptable;
21 import org.htmlunit.javascript.configuration.JsxClass;
22 import org.htmlunit.javascript.configuration.JsxConstructor;
23 import org.htmlunit.javascript.configuration.JsxGetter;
24 import org.htmlunit.javascript.host.html.HTMLElement;
25
26 /**
27 * A JavaScript object for {@code MutationRecord}.
28 *
29 * @author Ahmed Ashour
30 * @author Ronald Brill
31 */
32 @JsxClass
33 public class MutationRecord extends HtmlUnitScriptable {
34
35 private String type_;
36 private ScriptableObject target_;
37 private String oldValue_;
38 private String attributeName_;
39
40 private NodeList addedNodes_;
41 private NodeList removedNodes_;
42 private Node previousSibling_;
43 private Node nextSibling_;
44
45 /**
46 * JavaScript constructor.
47 */
48 @JsxConstructor
49 public void jsConstructor() {
50 // nothing to do
51 }
52
53 /**
54 * Sets the {@code type} property.
55 * @param type the {@code type} property
56 */
57 void setType(final String type) {
58 type_ = type;
59 }
60
61 /**
62 * Returns the {@code type} property.
63 * @return the {@code type} property
64 */
65 @JsxGetter
66 public String getType() {
67 return type_;
68 }
69
70 /**
71 * Sets the {@code target} property.
72 * @param target the {@code target} property
73 */
74 void setTarget(final ScriptableObject target) {
75 target_ = target;
76 }
77
78 /**
79 * Returns the {@code target} property.
80 * @return the {@code target} property
81 */
82 @JsxGetter
83 public ScriptableObject getTarget() {
84 return target_;
85 }
86
87 /**
88 * Sets the {@code oldValue} property.
89 * @param oldValue the {@code oldValue} property
90 */
91 void setOldValue(final String oldValue) {
92 oldValue_ = oldValue;
93 }
94
95 /**
96 * Returns the {@code oldValue} property.
97 * @return the {@code oldValue} property
98 */
99 @JsxGetter
100 public String getOldValue() {
101 return oldValue_;
102 }
103
104 /**
105 * Sets the {@code attributeName} property.
106 * @param attributeName the {@code attributeName} property
107 */
108 void setAttributeName(final String attributeName) {
109 attributeName_ = attributeName;
110 }
111
112 /**
113 * Returns the {@code attributeName} property.
114 * @return the {@code attributeName} property
115 */
116 @JsxGetter
117 public String getAttributeName() {
118 return attributeName_;
119 }
120
121 /**
122 * Sets the {@code addedNodes} property.
123 * @param addedNodes the {@code addedNodes} property
124 */
125 void setAddedNodes(final NodeList addedNodes) {
126 addedNodes_ = addedNodes;
127 }
128
129 /**
130 * @return the {@code addedNodes} property
131 */
132 @JsxGetter
133 public NodeList getAddedNodes() {
134 if (addedNodes_ == null && target_ instanceof HTMLElement) {
135 final NodeList addedNodes = new NodeList(((HTMLElement) target_).getDomNodeOrDie(), new ArrayList<>());
136 addedNodes.setParentScope(getParentScope());
137 addedNodes.setPrototype(getPrototype(addedNodes.getClass()));
138
139 addedNodes_ = addedNodes;
140 }
141 return addedNodes_;
142 }
143
144 /**
145 * Sets the {@code removedNodes} property.
146 * @param removedNodes the {@code removedNodes} property
147 */
148 void setRemovedNodes(final NodeList removedNodes) {
149 removedNodes_ = removedNodes;
150 }
151
152 /**
153 * @return the {@code removedNodes} property
154 */
155 @JsxGetter
156 public NodeList getRemovedNodes() {
157 if (removedNodes_ == null && target_ instanceof HTMLElement) {
158 final NodeList removedNodes = new NodeList(((HTMLElement) target_).getDomNodeOrDie(), new ArrayList<>());
159 removedNodes.setParentScope(getParentScope());
160 removedNodes.setPrototype(getPrototype(removedNodes.getClass()));
161
162 removedNodes_ = removedNodes;
163 }
164 return removedNodes_;
165 }
166
167 /**
168 * Sets the {@code previousSibling} property.
169 * @param previousSibling the {@code previousSibling} property
170 */
171 void setPreviousSibling(final Node previousSibling) {
172 previousSibling_ = previousSibling;
173 }
174
175 /**
176 * @return the {@code previousSibling} property
177 */
178 @JsxGetter
179 public Node getPreviousSibling() {
180 return previousSibling_;
181 }
182
183 /**
184 * Sets the {@code nextSibling} property.
185 * @param nextSibling the {@code nextSibling} property
186 */
187 void setNextSibling(final Node nextSibling) {
188 nextSibling_ = nextSibling;
189 }
190
191 /**
192 * @return the {@code nextSibling} property
193 */
194 @JsxGetter
195 public Node getNextSibling() {
196 return nextSibling_;
197 }
198 }