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.javascript.HtmlUnitScriptable;
22 import org.htmlunit.javascript.JavaScriptEngine;
23 import org.htmlunit.javascript.configuration.JsxClass;
24 import org.htmlunit.javascript.configuration.JsxConstructor;
25 import org.htmlunit.javascript.configuration.JsxFunction;
26 import org.htmlunit.javascript.configuration.JsxGetter;
27 import org.htmlunit.javascript.host.Window;
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 Scriptable 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, ctorObj);
80 return point;
81 }
82
83 protected void init(final Object[] args, final Function ctorObj) {
84 final Window window = getWindow(ctorObj);
85 setParentScope(window);
86 setPrototype(((FunctionObject) ctorObj).getClassPrototype());
87
88 if (args.length == 0 || JavaScriptEngine.isUndefined(args[0])) {
89 return;
90 }
91
92 if (args.length > 0) {
93 xVal_ = JavaScriptEngine.toNumber(args[0]);
94 }
95
96 if (args.length > 1) {
97 yVal_ = JavaScriptEngine.toNumber(args[1]);
98 }
99
100 if (args.length > 2) {
101 zVal_ = JavaScriptEngine.toNumber(args[2]);
102 }
103
104 if (args.length > 3) {
105 wVal_ = JavaScriptEngine.toNumber(args[3]);
106 }
107 }
108
109
110
111
112 @JsxGetter
113 public double getX() {
114 return xVal_;
115 }
116
117
118
119
120 public void setX(final double x) {
121 xVal_ = x;
122 }
123
124
125
126
127 @JsxGetter
128 public double getY() {
129 return yVal_;
130 }
131
132
133
134
135 public void setY(final double y) {
136 yVal_ = y;
137 }
138
139
140
141
142 @JsxGetter
143 public double getZ() {
144 return zVal_;
145 }
146
147
148
149
150 public void setZ(final double z) {
151 zVal_ = z;
152 }
153
154
155
156
157 @JsxGetter
158 public double getW() {
159 return wVal_;
160 }
161
162
163
164
165 public void setW(final double w) {
166 wVal_ = w;
167 }
168
169
170
171
172 @JsxFunction
173 public Scriptable toJSON() {
174 final Scriptable json = JavaScriptEngine.newObject(getParentScope());
175 json.put("x", json, xVal_);
176 json.put("y", json, yVal_);
177 json.put("z", json, zVal_);
178 json.put("w", json, wVal_);
179 return json;
180 }
181 }