1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.html;
16
17 import org.htmlunit.css.ComputedCssStyleDeclaration;
18 import org.htmlunit.css.StyleAttributes;
19 import org.htmlunit.html.DomNode;
20 import org.htmlunit.html.HtmlTableCell;
21 import org.htmlunit.html.HtmlTableRow;
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.JsxGetter;
26 import org.htmlunit.javascript.configuration.JsxSetter;
27 import org.htmlunit.javascript.host.event.MouseEvent;
28
29
30
31
32
33
34
35
36
37
38
39
40 @JsxClass(domClass = HtmlTableCell.class)
41 public class HTMLTableCellElement extends HTMLElement {
42
43
44 private static final String VALIGN_DEFAULT_VALUE = "top";
45
46
47
48
49 @Override
50 @JsxConstructor
51 public void jsConstructor() {
52 super.jsConstructor();
53 }
54
55
56
57
58 @Override
59 public int getOffsetHeight() {
60 final MouseEvent event = MouseEvent.getCurrentMouseEvent();
61 if (isAncestorOfEventTarget(event)) {
62 return super.getOffsetHeight();
63 }
64
65 if (isDisplayNone()) {
66 return 0;
67 }
68 final ComputedCssStyleDeclaration style = getWindow().getWebWindow().getComputedStyle(getDomNodeOrDie(), null);
69 return style.getCalculatedHeight(false, true);
70 }
71
72
73
74
75 @Override
76 public int getOffsetWidth() {
77 float w = super.getOffsetWidth();
78 final MouseEvent event = MouseEvent.getCurrentMouseEvent();
79 if (isAncestorOfEventTarget(event)) {
80 return (int) w;
81 }
82
83 if (isDisplayNone()) {
84 return 0;
85 }
86
87 final ComputedCssStyleDeclaration style = getWindow().getWebWindow().getComputedStyle(getDomNodeOrDie(), null);
88 if ("collapse".equals(style.getStyleAttribute(StyleAttributes.Definition.BORDER_COLLAPSE, true))) {
89 final HtmlTableRow row = getRow();
90 if (row != null) {
91 w -= 0.5 * style.getBorderLeftValue();
92 w -= 0.5 * style.getBorderRightValue();
93 }
94 }
95
96 return (int) w;
97 }
98
99
100
101
102
103
104 @JsxGetter
105 public int getCellIndex() {
106 final HtmlTableCell cell = (HtmlTableCell) getDomNodeOrDie();
107 final HtmlTableRow row = cell.getEnclosingRow();
108 if (row == null) {
109 return Integer.valueOf(-1);
110 }
111 return Integer.valueOf(row.getCells().indexOf(cell));
112 }
113
114
115
116
117
118 @JsxGetter
119 public String getAbbr() {
120 return getDomNodeOrDie().getAttributeDirect("abbr");
121 }
122
123
124
125
126
127 @JsxSetter
128 public void setAbbr(final String abbr) {
129 getDomNodeOrDie().setAttribute("abbr", abbr);
130 }
131
132
133
134
135
136 @JsxGetter
137 public String getAxis() {
138 return getDomNodeOrDie().getAttributeDirect("axis");
139 }
140
141
142
143
144
145 @JsxSetter
146 public void setAxis(final String axis) {
147 getDomNodeOrDie().setAttribute("axis", axis);
148 }
149
150
151
152
153
154
155 @JsxGetter
156 public String getBgColor() {
157 return getDomNodeOrDie().getAttribute("bgColor");
158 }
159
160
161
162
163
164
165 @JsxSetter
166 public void setBgColor(final String bgColor) {
167 setColorAttribute("bgColor", bgColor);
168 }
169
170
171
172
173
174 @JsxGetter
175 public int getColSpan() {
176 return ((HtmlTableCell) getDomNodeOrDie()).getColumnSpan();
177 }
178
179
180
181
182
183 @JsxSetter
184 public void setColSpan(final String colSpan) {
185 try {
186 final int i = (int) Double.parseDouble(colSpan);
187 if (i <= 0) {
188 throw new NumberFormatException(colSpan);
189 }
190 getDomNodeOrDie().setAttribute("colSpan", Integer.toString(i));
191 }
192 catch (final NumberFormatException e) {
193 getDomNodeOrDie().setAttribute("colSpan", "1");
194 }
195 }
196
197
198
199
200
201 @JsxGetter
202 public int getRowSpan() {
203 return ((HtmlTableCell) getDomNodeOrDie()).getRowSpan();
204 }
205
206
207
208
209
210 @JsxSetter
211 public void setRowSpan(final String rowSpan) {
212 try {
213 final int i = (int) Double.parseDouble(rowSpan);
214 if (i < 0) {
215 getDomNodeOrDie().setAttribute("rowSpan", "1");
216 return;
217 }
218 if (i <= 0) {
219 throw new NumberFormatException(rowSpan);
220 }
221 getDomNodeOrDie().setAttribute("rowSpan", Integer.toString(i));
222 }
223 catch (final NumberFormatException e) {
224 getDomNodeOrDie().setAttribute("rowSpan", "0");
225 }
226 }
227
228
229
230
231
232
233 @JsxGetter
234 public boolean isNoWrap() {
235 return getDomNodeOrDie().hasAttribute("noWrap");
236 }
237
238
239
240
241
242
243 @JsxSetter
244 public void setNoWrap(final boolean noWrap) {
245 if (noWrap) {
246 getDomNodeOrDie().setAttribute("noWrap", "");
247 }
248 else {
249 getDomNodeOrDie().removeAttribute("noWrap");
250 }
251 }
252
253
254
255
256
257 private HtmlTableRow getRow() {
258 DomNode node = getDomNodeOrDie();
259 while (node != null && !(node instanceof HtmlTableRow)) {
260 node = node.getParentNode();
261 }
262 return (HtmlTableRow) node;
263 }
264
265
266
267
268
269 @JsxGetter(propertyName = "width")
270 public String getWidth_js() {
271 return getWidthOrHeight("width", null);
272 }
273
274
275
276
277
278 @JsxSetter(propertyName = "width")
279 public void setWidth_js(final String width) {
280 setWidthOrHeight("width", width, true);
281 }
282
283
284
285
286
287 @JsxGetter(propertyName = "height")
288 public String getHeight_js() {
289 return getWidthOrHeight("height", null);
290 }
291
292
293
294
295
296 @JsxSetter(propertyName = "height")
297 public void setHeight_js(final String height) {
298 setWidthOrHeight("height", height, true);
299 }
300
301
302
303
304
305 @Override
306 public void setOuterHTML(final Object value) {
307 throw JavaScriptEngine.reportRuntimeError("outerHTML is read-only for tag '"
308 + getDomNodeOrDie().getTagName() + "'");
309 }
310
311
312
313
314
315 @JsxGetter
316 public String getHeaders() {
317 return getDomNodeOrDie().getAttributeDirect("headers");
318 }
319
320
321
322
323
324 @JsxSetter
325 public void setHeaders(final String headers) {
326 getDomNodeOrDie().setAttribute("headers", headers);
327 }
328
329
330
331
332
333 @JsxGetter
334 public String getScope() {
335 return getDomNodeOrDie().getAttributeDirect("scope");
336 }
337
338
339
340
341
342 @JsxSetter
343 public void setScope(final String scope) {
344 getDomNodeOrDie().setAttribute("scope", scope);
345 }
346
347
348
349
350
351 @JsxGetter
352 public String getAlign() {
353 return getAlign(true);
354 }
355
356
357
358
359
360 @JsxSetter
361 public void setAlign(final String align) {
362 setAlign(align, false);
363 }
364
365
366
367
368
369 @JsxGetter
370 public String getVAlign() {
371 return getVAlign(getValidVAlignValues(), VALIGN_DEFAULT_VALUE);
372 }
373
374
375
376
377
378 @JsxSetter
379 public void setVAlign(final Object vAlign) {
380 setVAlign(vAlign, getValidVAlignValues());
381 }
382
383
384
385
386
387 private String[] getValidVAlignValues() {
388 return null;
389 }
390
391
392
393
394
395 @Override
396 @JsxGetter
397 public String getCh() {
398 return super.getCh();
399 }
400
401
402
403
404
405 @Override
406 @JsxSetter
407 public void setCh(final String ch) {
408 super.setCh(ch);
409 }
410
411
412
413
414
415 @Override
416 @JsxGetter
417 public String getChOff() {
418 return super.getChOff();
419 }
420
421
422
423
424
425 @Override
426 @JsxSetter
427 public void setChOff(final String chOff) {
428 super.setChOff(chOff);
429 }
430 }