1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.dom;
16
17 import org.htmlunit.corejs.javascript.Context;
18 import org.htmlunit.corejs.javascript.Function;
19 import org.htmlunit.corejs.javascript.FunctionObject;
20 import org.htmlunit.corejs.javascript.Scriptable;
21 import org.htmlunit.corejs.javascript.VarScope;
22 import org.htmlunit.javascript.HtmlUnitScriptable;
23 import org.htmlunit.javascript.JavaScriptEngine;
24 import org.htmlunit.javascript.configuration.JsxClass;
25 import org.htmlunit.javascript.configuration.JsxConstructor;
26 import org.htmlunit.javascript.configuration.JsxFunction;
27 import org.htmlunit.javascript.configuration.JsxGetter;
28
29
30
31
32
33
34
35 @JsxClass
36 public class DOMPointReadOnly extends HtmlUnitScriptable {
37
38 private double xVal_;
39 private double yVal_;
40 private double zVal_;
41 private double wVal_;
42
43
44
45
46 public DOMPointReadOnly() {
47 wVal_ = 1;
48 }
49
50
51
52
53
54
55
56
57
58 public DOMPointReadOnly(final double x, final double y, final double z, final double w) {
59 xVal_ = x;
60 yVal_ = y;
61 zVal_ = z;
62 wVal_ = w;
63 }
64
65
66
67
68
69
70
71
72
73
74 @JsxConstructor
75 public static DOMPointReadOnly jsConstructor(final Context cx, final VarScope scope,
76 final Object[] args, final Function ctorObj, final boolean inNewExpr) {
77
78 final DOMPointReadOnly point = new DOMPointReadOnly(0, 0, 0, 1);
79 point.init(args, scope, ctorObj);
80 return point;
81 }
82
83 protected void init(final Object[] args, final VarScope scope, final Function ctorObj) {
84 setParentScope(scope);
85 setPrototype(((FunctionObject) ctorObj).getClassPrototype());
86
87 if (args.length == 0 || JavaScriptEngine.isUndefined(args[0])) {
88 return;
89 }
90
91 if (args.length > 0) {
92 xVal_ = JavaScriptEngine.toNumber(args[0]);
93 }
94
95 if (args.length > 1) {
96 yVal_ = JavaScriptEngine.toNumber(args[1]);
97 }
98
99 if (args.length > 2) {
100 zVal_ = JavaScriptEngine.toNumber(args[2]);
101 }
102
103 if (args.length > 3) {
104 wVal_ = JavaScriptEngine.toNumber(args[3]);
105 }
106 }
107
108
109
110
111 @JsxGetter
112 public double getX() {
113 return xVal_;
114 }
115
116
117
118
119 public void setX(final double x) {
120 xVal_ = x;
121 }
122
123
124
125
126 @JsxGetter
127 public double getY() {
128 return yVal_;
129 }
130
131
132
133
134 public void setY(final double y) {
135 yVal_ = y;
136 }
137
138
139
140
141 @JsxGetter
142 public double getZ() {
143 return zVal_;
144 }
145
146
147
148
149 public void setZ(final double z) {
150 zVal_ = z;
151 }
152
153
154
155
156 @JsxGetter
157 public double getW() {
158 return wVal_;
159 }
160
161
162
163
164 public void setW(final double w) {
165 wVal_ = w;
166 }
167
168
169
170
171 @JsxFunction
172 public Scriptable toJSON() {
173 final Scriptable json = JavaScriptEngine.newObject(getParentScope());
174 json.put("x", json, xVal_);
175 json.put("y", json, yVal_);
176 json.put("z", json, zVal_);
177 json.put("w", json, wVal_);
178 return json;
179 }
180 }