1
2
3
4
5
6
7
8 package com.extjs.gxt.ui.client.core;
9
10 import java.util.ArrayList;
11 import java.util.Arrays;
12 import java.util.List;
13 import java.util.Map;
14 import java.util.Set;
15
16 import com.extjs.gxt.ui.client.GXT;
17 import com.extjs.gxt.ui.client.Style;
18 import com.extjs.gxt.ui.client.Style.Direction;
19 import com.extjs.gxt.ui.client.Style.ScrollDir;
20 import com.extjs.gxt.ui.client.core.impl.ComputedStyleImpl;
21 import com.extjs.gxt.ui.client.fx.BaseEffect;
22 import com.extjs.gxt.ui.client.fx.Fx;
23 import com.extjs.gxt.ui.client.fx.FxConfig;
24 import com.extjs.gxt.ui.client.fx.Move;
25 import com.extjs.gxt.ui.client.util.Format;
26 import com.extjs.gxt.ui.client.util.Margins;
27 import com.extjs.gxt.ui.client.util.Markup;
28 import com.extjs.gxt.ui.client.util.Padding;
29 import com.extjs.gxt.ui.client.util.Point;
30 import com.extjs.gxt.ui.client.util.Rectangle;
31 import com.extjs.gxt.ui.client.util.Region;
32 import com.extjs.gxt.ui.client.util.Scroll;
33 import com.extjs.gxt.ui.client.util.Size;
34 import com.extjs.gxt.ui.client.util.TextMetrics;
35 import com.extjs.gxt.ui.client.util.Util;
36 import com.google.gwt.core.client.GWT;
37 import com.google.gwt.core.client.JavaScriptObject;
38 import com.google.gwt.dom.client.Document;
39 import com.google.gwt.dom.client.NodeList;
40 import com.google.gwt.http.client.Request;
41 import com.google.gwt.http.client.RequestBuilder;
42 import com.google.gwt.http.client.RequestCallback;
43 import com.google.gwt.http.client.Response;
44 import com.google.gwt.user.client.Command;
45 import com.google.gwt.user.client.DOM;
46 import com.google.gwt.user.client.DeferredCommand;
47 import com.google.gwt.user.client.Element;
48
49
50
51
52 public class El {
53
54
55
56
57
58
59 public enum VisMode {
60 DISPLAY, VISIBILITY
61 }
62
63 private static Map<String, Boolean> borderBoxMap = new FastMap<Boolean>();
64
65
66
67
68 private static Map<String, El> flyweights = new FastMap<El>();
69
70 private static ComputedStyleImpl computedStyle = GWT.create(ComputedStyleImpl.class);
71 private static JavaScriptObject leftRightTest;
72 private static JavaScriptObject removeStyleNameReCache;
73
74 static {
75 GXT.init();
76 }
77
78
79
80
81
82
83
84 public native static String addUnits(String v, String defaultUnit)
85
86
87
88
89
90
91
92
93
94
95 ;
96
97 public static El fly(com.google.gwt.dom.client.Element element) {
98 return fly(element, "_global");
99 }
100
101
102
103
104
105
106
107
108
109 public static El fly(com.google.gwt.dom.client.Element element, String s) {
110 assert element != null : "Element my not be null";
111 El g = flyweights.get(s);
112 if (g == null) {
113 g = new El(DOM.createDiv());
114 flyweights.put(s, g);
115 }
116 g.dom = (Element) element;
117 return g;
118 }
119
120 public static El fly(Element element) {
121 return fly(element, "_global");
122 }
123
124
125
126
127
128
129
130
131
132 public static El fly(Element element, String s) {
133 assert element != null : "Element my not be null";
134 El g = flyweights.get(s);
135 if (g == null) {
136 g = new El(DOM.createDiv());
137 flyweights.put(s, g);
138 }
139 g.dom = (Element) element;
140 return g;
141 }
142
143
144
145
146
147
148
149 public static boolean isBorderBox(Element element) {
150 assert element != null : "Element may not be null";
151 String tag = element.getTagName().toLowerCase();
152 Boolean r = borderBoxMap.get(tag);
153 if (r == null) {
154 Element testElement = (Element) Document.get().createElement(tag);
155 testElement.getStyle().setPropertyPx("padding", 1);
156 testElement.getStyle().setPropertyPx("width", 100);
157 testElement.getStyle().setProperty("visibility", "hidden");
158 testElement.getStyle().setProperty("position", "absolute");
159 XDOM.getBody().appendChild(testElement);
160 r = testElement.getOffsetWidth() == 100;
161 XDOM.getBody().removeChild(testElement);
162 borderBoxMap.put(tag, r);
163 }
164 return r;
165 }
166
167 private native static void disableTextSelectInternal(Element e, boolean disable)
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197 ;
198
199
200
201
202 public Element dom;
203
204 private VisMode visiblityMode = VisMode.DISPLAY;
205
206 private String originalDisplay = "block";
207 private El _mask;
208 private El _maskMsg;
209 private boolean isClipped;
210 private String[] originalClipped;
211
212
213
214
215
216
217 public El(Element element) {
218 assert element != null : "The element may not be null";
219 this.dom = element;
220 }
221
222
223
224
225
226
227 public El(String html) {
228 this(XDOM.create(html));
229 }
230
231
232
233
234
235
236
237 public El addEventsSunk(int event) {
238 int bits = DOM.getEventsSunk(dom);
239 DOM.sinkEvents(dom, bits | event);
240 return this;
241 }
242
243
244
245
246
247
248
249
250 public El addStyleName(String... styleNames) {
251 if (styleNames != null) {
252 for (String styleName : styleNames) {
253 if (styleName != null && !hasStyleName(styleName)) {
254 styleName = styleName.trim();
255
256
257 setClassName(dom, getClassName(dom) + " " + styleName);
258
259 }
260 }
261 }
262 return this;
263 }
264
265
266
267
268
269
270
271
272 public El toggleStyleName(String styleName) {
273 if (hasStyleName(styleName)) {
274 removeStyleName(styleName);
275 } else {
276 addStyleName(styleName);
277 }
278 return this;
279 }
280
281
282
283
284
285
286
287 public Point adjustForConstraints(Point p) {
288 return getConstrainToXY(XDOM.getBody(), p);
289 }
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327 public El alignTo(Element align, String pos, int[] offsets) {
328 if (offsets == null) {
329 offsets = new int[] {0, 0};
330 }
331 Point p = getAlignToXY(align, pos, offsets);
332 setXY(p);
333 return this;
334 }
335
336
337
338
339
340
341
342 public El appendChild(Element child) {
343 dom.appendChild(child);
344 return new El(child);
345 }
346
347
348
349
350
351
352
353
354
355 public native El applyStyles(String styles)
356
357
358
359
360
361
362 ;
363
364
365
366
367
368
369
370 public El blink(FxConfig config) {
371 BaseEffect.blink(this, config, 50);
372 return this;
373 }
374
375
376
377
378
379
380 public El blur() {
381 return setFocus(false);
382 }
383
384
385
386
387
388
389
390
391 public El boxWrap(String style) {
392 String s = style != null ? style : "x-box";
393 El temp = insertHtml("beforeBegin", Format.substitute("<div class={0}>" + Markup.BBOX, s) + "</div>");
394 temp.child("." + s + "-mc").appendChild(dom);
395 return temp;
396 }
397
398
399
400
401
402
403 public El center() {
404 return center(null);
405 }
406
407
408
409
410
411
412
413
414 public El center(boolean constrainViewport) {
415 return alignTo(XDOM.getBody(), "c-c" + (constrainViewport ? "?" : ""), null);
416 }
417
418
419
420
421
422
423
424 public El center(Element container) {
425 if (container == null) {
426 container = XDOM.getBody();
427 }
428 return alignTo(container, "c-c", null);
429 }
430
431
432
433
434
435
436
437
438 public El child(String selector) {
439 Element child = childElement(selector);
440 return child == null ? null : new El(child);
441 }
442
443
444
445
446
447
448
449
450 public Element childElement(String selector) {
451 return DomQuery.selectNode(selector, dom);
452 }
453
454
455
456
457
458
459
460 public El childNode(int index) {
461 Element e = DOM.getChild(dom, index);
462 return e == null ? null : new El(e);
463 }
464
465
466
467
468
469
470 public native El clearOpacity()
471
472
473
474
475
476
477
478
479 ;
480
481
482
483
484
485
486 public native El click()
487
488
489
490
491
492
493
494
495
496
497 ;
498
499
500
501
502
503
504 public El clip() {
505 if (!isClipped) {
506 isClipped = true;
507 originalClipped = new String[3];
508 originalClipped[0] = getStyleAttribute("overflow");
509 originalClipped[1] = getStyleAttribute("overflowX");
510 originalClipped[2] = getStyleAttribute("overflowY");
511 setStyleAttribute("overflow", "hidden");
512 setStyleAttribute("overflowX", "hidden");
513 setStyleAttribute("overflowY", "hidden");
514 }
515 return this;
516 }
517
518
519
520
521
522
523
524 public Element cloneNode(boolean deep) {
525 return (Element) dom.cloneNode(deep);
526 }
527
528
529
530
531
532
533
534 public El createChild(String html) {
535 return appendChild(XDOM.create(html));
536 }
537
538
539
540
541
542
543
544
545 public El createChild(String html, Element insertBefore) {
546 Element element = XDOM.create(html);
547 int idx = DOM.getChildIndex(dom, insertBefore);
548 insertChild(element, idx);
549 return new El(element);
550 }
551
552
553
554
555
556
557 public El disable() {
558 dom.setPropertyBoolean("disabled", true);
559 return this;
560 }
561
562
563
564
565
566
567
568
569
570
571 public native El disableContextMenu(boolean disable)
572
573
574
575 ;
576
577
578
579
580
581
582
583
584
585
586 public El disableTextSelection(boolean disable) {
587 setStyleName("x-unselectable", disable);
588 setElementAttribute("unselectable", disable ? "on" : "");
589 disableTextSelectInternal(dom, disable);
590 return this;
591 }
592
593
594
595
596
597
598
599
600 public El down(String selector) {
601 Element elem = DomQuery.selectNode(" > " + selector, dom);
602 if (elem != null) {
603 return new El(elem);
604 }
605 return null;
606 }
607
608
609
610
611
612
613 public El enable() {
614 dom.setPropertyBoolean("disabled", false);
615 return this;
616 }
617
618
619
620
621
622
623
624 public El enableDisplayMode(String display) {
625 setVisibilityMode(VisMode.DISPLAY);
626 if (display != null) {
627 originalDisplay = display;
628 }
629 return this;
630 }
631
632 @Override
633 public boolean equals(Object obj) {
634 if (obj instanceof El) {
635 return getId().equals(((El) obj).getId());
636 }
637 return super.equals(obj);
638 }
639
640
641
642
643
644
645
646 public El fadeIn(FxConfig config) {
647 BaseEffect.fadeIn(this, config);
648 return this;
649 }
650
651
652
653
654
655
656
657 public El fadeOut(FxConfig config) {
658 BaseEffect.fadeOut(this, config);
659 return this;
660 }
661
662
663
664
665
666
667
668 public El fadeToggle(FxConfig config) {
669 if (!isVisible()) {
670 BaseEffect.fadeIn(this, config);
671 } else {
672 BaseEffect.fadeOut(this, config);
673 }
674 return this;
675 }
676
677
678
679
680
681
682
683
684 public El findParent(String selector, int maxDepth) {
685 Element elem = findParentElement(selector, maxDepth);
686 if (elem == null) {
687 return null;
688 }
689 return new El(elem);
690 }
691
692
693
694
695
696
697
698
699
700 public Element findParentElement(String selector, int maxDepth) {
701 Element p = dom;
702 Element b = XDOM.getBody();
703 int depth = 0;
704 while (p != null && p.getNodeType() == 1 && (maxDepth == -1 || depth < maxDepth) && p != b) {
705 if (DomQuery.is(p, selector)) {
706 return p;
707 }
708 depth++;
709 p = (Element) p.getParentElement();
710 }
711 return null;
712 }
713
714
715
716
717
718
719 public El firstChild() {
720 Element firstChild = DOM.getFirstChild(dom);
721 return firstChild == null ? null : new El(firstChild);
722 }
723
724
725
726
727
728
729 public El focus() {
730 return setFocus(true);
731 }
732
733 public Point getAlignToXY(Element elem, String p, int ox, int oy) {
734 El el = new El(elem);
735
736 if (p == null) {
737 p = "tl-bl";
738 } else if (p.equals("?")) {
739 p = "tl-bl?";
740 } else if (p.indexOf("-") == -1) {
741 p = "tl-" + p;
742 }
743 p = p.toLowerCase();
744 boolean c = false;
745 String p1 = p.substring(0, p.indexOf("-"));
746 String p2 = p.substring(p.indexOf("-") + 1, ((c = p.contains("?")) ? p.indexOf("?") : p.length()));
747
748
749 Point a1 = getAnchorXY(p1, true);
750 Point a2 = el.getAnchorXY(p2, false);
751
752 int x = a2.x - a1.x + ox;
753 int y = a2.y - a1.y + oy;
754
755 if (c) {
756
757 int w = getWidth();
758 int h = getHeight();
759 Region r = el.getRegion();
760
761 int dw = XDOM.getViewWidth(false) - 10;
762 int dh = XDOM.getViewHeight(false) - 10;
763
764
765
766
767
768
769 char p1y = p1.charAt(0), p1x = p1.charAt(p1.length() - 1);
770 char p2y = p2.charAt(0), p2x = p2.charAt(p2.length() - 1);
771
772 boolean swapY = ((p1y == 't' && p2y == 'b') || (p1y == 'b' && p2y == 't'));
773 boolean swapX = ((p1x == 'r' && p2x == 'l') || (p1x == 'l' && p2x == 'r'));
774
775 int scrollX = XDOM.getBodyScrollLeft() + 5;
776 int scrollY = XDOM.getBodyScrollTop() + 5;
777
778 if ((x + w) > dw + scrollX) {
779 x = swapX ? r.left - w : dw + scrollX - w;
780 }
781 if (x < scrollX) {
782 x = swapX ? r.right : scrollX;
783 }
784
785 if ((y + h) > (dh + scrollY)) {
786 y = swapY ? r.top - h : dh + scrollY - h;
787 }
788 if (y < scrollY) {
789 y = swapY ? r.bottom : scrollY;
790 }
791 }
792
793 return new Point(x, y);
794 }
795
796
797
798
799
800
801
802
803
804
805 public Point getAlignToXY(Element align, String pos, int[] offsets) {
806 if (offsets == null) {
807 offsets = new int[] {0, 0};
808 }
809 return getAlignToXY(align, pos, offsets[0], offsets[1]);
810 }
811
812
813
814
815
816
817
818
819
820
821
822 public Point getAnchorXY(String anchor, boolean local) {
823 if (anchor == null) {
824 return null;
825 }
826 boolean vp = false;
827 int w;
828 int h;
829 if (dom == XDOM.getBody() || dom == XDOM.getDocument()) {
830 vp = true;
831 w = XDOM.getViewWidth(false);
832 h = XDOM.getViewHeight(false);
833 } else {
834 w = getWidth();
835 h = getHeight();
836 }
837
838 int x = 0, y = 0;
839 if (anchor.length() == 1) {
840 if ("c".equalsIgnoreCase(anchor)) {
841 x = (int) Math.round(w * .5);
842 y = (int) Math.round(h * .5);
843 } else if ("t".equalsIgnoreCase(anchor)) {
844 x = (int) Math.round(w * .5);
845 y = 0;
846 } else if ("l".equalsIgnoreCase(anchor)) {
847 x = 0;
848 y = (int) Math.round(h * .5);
849 } else if ("r".equalsIgnoreCase(anchor)) {
850 x = w;
851 y = (int) Math.round(h * .5);
852 } else if ("b".equalsIgnoreCase(anchor)) {
853 x = (int) Math.round(w * .5);
854 y = h;
855 }
856 } else {
857 if ("tl".equalsIgnoreCase(anchor)) {
858 x = 0;
859 y = 0;
860 } else if ("bl".equalsIgnoreCase(anchor)) {
861 x = 0;
862 y = h;
863 } else if ("br".equalsIgnoreCase(anchor)) {
864 x = w;
865 y = h;
866 } else if ("tr".equalsIgnoreCase(anchor)) {
867 x = w;
868 y = 0;
869 }
870 }
871
872 if (local) {
873 return new Point(x, y);
874 }
875 if (vp) {
876 Scroll sc = getScroll();
877 return new Point(x + sc.getScrollLeft(), y + sc.getScrollTop());
878 }
879
880
881 Point o = getXY();
882 return new Point(x + o.x, y + o.y);
883 }
884
885
886
887
888
889
890
891
892
893 public int getBorderWidth(String sides) {
894 int borderWidth = 0;
895 List<String> list = new ArrayList<String>();
896 if (sides.contains("l")) {
897 list.add("borderLeftWidth");
898 }
899 if (sides.contains("r")) {
900 list.add("borderRightWidth");
901 }
902 if (sides.contains("t")) {
903 list.add("borderTopWidth");
904 }
905 if (sides.contains("b")) {
906 list.add("borderBottomWidth");
907 }
908 FastMap<String> map = getStyleAttribute(list);
909 for (String s : map.keySet()) {
910 borderWidth += Util.parseInt(map.get(s), 0);
911 }
912 return borderWidth;
913 }
914
915
916
917
918
919
920
921
922 public int getBottom(boolean local) {
923 return getHeight() + (local ? getTop() : getY());
924 }
925
926
927
928
929
930
931 public Rectangle getBounds() {
932 return getBounds(false, false);
933 }
934
935
936
937
938
939
940
941
942
943 public Rectangle getBounds(boolean local) {
944 return getBounds(local, false);
945 }
946
947
948
949
950
951
952
953
954
955
956 public Rectangle getBounds(boolean local, boolean adjust) {
957 Size s = getSize(adjust);
958 Rectangle rect = new Rectangle();
959 rect.width = s.width;
960 rect.height = s.height;
961 if (local) {
962 rect.x = getLeft(true);
963 rect.y = getTop(true);
964 } else {
965 Point p = getXY();
966 rect.x = p.x;
967 rect.y = p.y;
968 }
969 return rect;
970 }
971
972
973
974
975
976
977
978 public El getChild(int index) {
979 Element child = getChildElement(index);
980 return child == null ? null : new El(child);
981 }
982
983
984
985
986
987
988
989 public Element getChildElement(int index) {
990 return DOM.getChild(dom, index);
991 }
992
993
994
995
996
997
998 public int getChildIndex(Element child) {
999 return DOM.getChildIndex(dom, child);
1000 }
1001
1002
1003
1004
1005
1006
1007 public int getClientHeight() {
1008 return DOM.getElementPropertyInt(dom, "clientHeight");
1009 }
1010
1011
1012
1013
1014
1015
1016 public int getClientWidth() {
1017 return DOM.getElementPropertyInt(dom, "clientWidth");
1018 }
1019
1020
1021
1022
1023
1024
1025
1026 public int getComputedHeight() {
1027 int h = getHeight();
1028 if (h == 0) {
1029 h = getIntStyleAttribute("height");
1030 }
1031 return h;
1032 }
1033
1034
1035
1036
1037
1038
1039
1040 public int getComputedWidth() {
1041 int w = getWidth();
1042 if (w == 0) {
1043 w = getIntStyleAttribute("width");
1044 }
1045 return w;
1046 }
1047
1048
1049
1050
1051
1052
1053
1054 public Size getFrameSize() {
1055 int width = 0;
1056 int height = 0;
1057 List<String> list = new ArrayList<String>();
1058 list.add("paddingLeft");
1059 list.add("borderLeftWidth");
1060
1061 list.add("paddingRight");
1062 list.add("borderRightWidth");
1063
1064 list.add("paddingTop");
1065 list.add("borderTopWidth");
1066
1067 list.add("paddingBottom");
1068 list.add("borderBottomWidth");
1069
1070 FastMap<String> map = getStyleAttribute(list);
1071 for (String s : map.keySet()) {
1072 if (isLeftorRight(s)) {
1073 width += Util.parseInt(map.get(s), 0);
1074 } else {
1075 height += Util.parseInt(map.get(s), 0);
1076 }
1077 }
1078 return new Size(width, height);
1079 }
1080
1081
1082
1083
1084
1085
1086
1087
1088 public int getFrameWidth(String sides) {
1089 int frameWidth = 0;
1090 List<String> list = new ArrayList<String>();
1091 if (sides.contains("l")) {
1092 list.add("paddingLeft");
1093 list.add("borderLeftWidth");
1094 }
1095 if (sides.contains("r")) {
1096 list.add("paddingRight");
1097 list.add("borderRightWidth");
1098 }
1099 if (sides.contains("t")) {
1100 list.add("paddingTop");
1101 list.add("borderTopWidth");
1102 }
1103 if (sides.contains("b")) {
1104 list.add("paddingBottom");
1105 list.add("borderBottomWidth");
1106 }
1107 FastMap<String> map = getStyleAttribute(list);
1108 for (String s : map.keySet()) {
1109 frameWidth += Util.parseInt(map.get(s), 0);
1110 }
1111 return frameWidth;
1112 }
1113
1114
1115
1116
1117
1118
1119 public int getHeight() {
1120 return dom.getOffsetHeight();
1121 }
1122
1123
1124
1125
1126
1127
1128
1129 public int getHeight(boolean content) {
1130 int h = getHeight();
1131 if (content) {
1132 h -= getFrameWidth("tb");
1133 }
1134 return Math.max(0,h);
1135 }
1136
1137
1138
1139
1140
1141
1142 public String getId() {
1143 String id = DOM.getElementProperty(dom, "id");
1144 if (id == null || (id != null && id.length() == 0)) {
1145 id = XDOM.getUniqueId();
1146 setId(id);
1147 }
1148 return id;
1149 }
1150
1151
1152
1153
1154
1155
1156 public String getInnerHtml() {
1157 return DOM.getInnerHTML(dom);
1158 }
1159
1160
1161
1162
1163
1164
1165
1166 public int getIntStyleAttribute(String attr) {
1167 String v = DOM.getStyleAttribute(dom, attr);
1168 if (v == null || v.equals("")) {
1169 return 0;
1170 }
1171 return Util.parseInt(v, 0);
1172 }
1173
1174
1175
1176
1177
1178
1179 public Rectangle getLayoutBounds() {
1180 Rectangle r = getBounds();
1181 r.width -= getFrameWidth("lr");
1182 r.height -= getFrameWidth("tb");
1183 return r;
1184 }
1185
1186
1187
1188
1189
1190
1191 public int getLeft() {
1192 return getLeft(true);
1193 }
1194
1195
1196
1197
1198
1199
1200
1201 public int getLeft(boolean local) {
1202 return local ? Util.parseInt(getStyleAttribute("left"), 0) : getX();
1203 }
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213 public int getMargins(String sides) {
1214 int margin = 0;
1215 List<String> list = new ArrayList<String>();
1216 if (sides.contains("l")) {
1217 list.add("marginLeft");
1218 }
1219 if (sides.contains("r")) {
1220 list.add("marginRight");
1221 }
1222 if (sides.contains("t")) {
1223 list.add("marginTop");
1224 }
1225 if (sides.contains("b")) {
1226 list.add("marginBottom");
1227 }
1228 FastMap<String> map = getStyleAttribute(list);
1229 for (String s : map.keySet()) {
1230 margin += Util.parseInt(map.get(s), 0);
1231 }
1232 return margin;
1233 }
1234
1235
1236
1237
1238
1239
1240
1241
1242 public Point getOffsetsTo(Element to) {
1243 Point o = getXY();
1244 Point e = El.fly(to, "_internal").getXY();
1245 return new Point(o.x - e.x, o.y - e.y);
1246 }
1247
1248
1249
1250
1251
1252
1253 public String getOuterHtml() {
1254 return dom.getAttribute("outerHTML");
1255 }
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265 public int getPadding(String sides) {
1266 int padding = 0;
1267 List<String> list = new ArrayList<String>();
1268 if (sides.contains("l")) {
1269 list.add("paddingLeft");
1270 }
1271 if (sides.contains("r")) {
1272 list.add("paddingRight");
1273 }
1274 if (sides.contains("t")) {
1275 list.add("paddingTop");
1276 }
1277 if (sides.contains("b")) {
1278 list.add("paddingBottom");
1279 }
1280 FastMap<String> map = getStyleAttribute(list);
1281 for (String s : map.keySet()) {
1282 padding += Util.parseInt(map.get(s), 0);
1283 }
1284 return padding;
1285 }
1286
1287
1288
1289
1290
1291
1292 public El getParent() {
1293 Element e = DOM.getParent(dom);
1294 return e == null ? null : new El(e);
1295 }
1296
1297
1298
1299
1300
1301
1302
1303 public Region getRegion() {
1304 Rectangle bounds = getBounds();
1305 Region r = new Region();
1306 r.left = bounds.x;
1307 r.top = bounds.y;
1308 r.right = r.left + bounds.width;
1309 r.bottom = r.top + bounds.height;
1310 return r;
1311 }
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321 public int getRight(boolean local) {
1322 return getWidth() + (local ? getLeft(true) : getX());
1323 }
1324
1325
1326
1327
1328
1329
1330 public Scroll getScroll() {
1331 if (dom == XDOM.getBody() || dom == XDOM.getDocument()) {
1332 return new Scroll(XDOM.getBodyScrollLeft(), XDOM.getBodyScrollTop());
1333 } else {
1334 return new Scroll(getScrollLeft(), getScrollTop());
1335 }
1336 }
1337
1338
1339
1340
1341
1342
1343 public int getScrollLeft() {
1344 return DOM.getElementPropertyInt(dom, "scrollLeft");
1345 }
1346
1347
1348
1349
1350
1351
1352 public int getScrollTop() {
1353 return DOM.getElementPropertyInt(dom, "scrollTop");
1354 }
1355
1356
1357
1358
1359
1360
1361 public Size getSize() {
1362 return getSize(false);
1363 }
1364
1365
1366
1367
1368
1369
1370
1371 public Size getSize(boolean content) {
1372 int w = getWidth();
1373 int h = getHeight();
1374 if (content) {
1375 Size frameWidth = getFrameSize();
1376 w -= frameWidth.width;
1377 h -= frameWidth.height;
1378 }
1379 return new Size(Math.max(0,w),Math.max(0,h));
1380 }
1381
1382 public FastMap<String> getStyleAttribute(List<String> attr) {
1383 return computedStyle.getStyleAttribute(dom, attr);
1384 }
1385
1386
1387
1388
1389
1390
1391
1392 public String getStyleAttribute(String attr) {
1393 return getStyleAttribute(Arrays.asList(attr)).get(attr);
1394 }
1395
1396
1397
1398
1399
1400
1401 public int getStyleHeight() {
1402 String h = dom.getStyle().getProperty("height");
1403 if (h == null || h.equals("")) return 0;
1404 if (h.matches("(auto|em|%|en|ex|pt|in|cm|mm|pc)")) {
1405 return 0;
1406 }
1407 return Util.parseInt(h, 0);
1408 }
1409
1410
1411
1412
1413
1414
1415 public String getStyleName() {
1416
1417
1418 return getClassName(dom);
1419
1420 }
1421
1422 public Size getStyleSize() {
1423 return getStyleSize(true);
1424 }
1425
1426
1427
1428
1429
1430
1431 public Size getStyleSize(boolean contentOnly) {
1432 int h = Util.parseInt(dom.getStyle().getProperty("height"), Style.DEFAULT);
1433 int w = Util.parseInt(dom.getStyle().getProperty("width"), Style.DEFAULT);
1434
1435 boolean isBorderBox = isBorderBox();
1436
1437 if (isBorderBox && contentOnly && w != Style.DEFAULT) {
1438 w -= getFrameWidth("lr");
1439 if (w < 0) {
1440 w = Style.DEFAULT;
1441 }
1442 } else if (!isBorderBox && !contentOnly && w != Style.DEFAULT) {
1443 w += getFrameWidth("lr");
1444 }
1445 if (isBorderBox && contentOnly && h != Style.DEFAULT) {
1446 h -= getFrameWidth("tb");
1447 if (h < 0) {
1448 h = Style.DEFAULT;
1449 }
1450 } else if (!isBorderBox && !contentOnly && h != Style.DEFAULT) {
1451 h += getFrameWidth("tb");
1452 }
1453
1454 int offsetWidth = Style.DEFAULT;
1455 int offsetHeight = Style.DEFAULT;
1456 if (w == Style.DEFAULT && h == Style.DEFAULT) {
1457 Size s = getSize(contentOnly);
1458 offsetWidth = s.width;
1459 offsetHeight = s.height;
1460 if (s.width > 0) {
1461 w = s.width;
1462 }
1463 if (s.height > 0) {
1464 h = s.height;
1465 }
1466 } else if (w == Style.DEFAULT) {
1467 offsetWidth = getWidth(contentOnly);
1468 if (offsetWidth > 0) {
1469 w = offsetWidth;
1470 }
1471 } else if (h == Style.DEFAULT) {
1472 offsetHeight = getHeight(contentOnly);
1473 if (offsetHeight > 0) {
1474 h = offsetHeight;
1475 }
1476 }
1477
1478 List<String> l = new ArrayList<String>();
1479 if (w == Style.DEFAULT) {
1480 l.add("width");
1481 }
1482 if (h == Style.DEFAULT) {
1483 l.add("height");
1484 }
1485 Map<String, String> map = getStyleAttribute(l);
1486 if (map != null) {
1487 String wid = map.get("width");
1488 if (wid != null) {
1489 w = Util.parseInt(wid, Style.DEFAULT);
1490 if (offsetWidth == 0 &&isBorderBox && contentOnly && w != Style.DEFAULT && !GXT.isIE) {
1491 w -= getFrameWidth("lr");
1492 } else if(GXT.isIE && isBorderBox && w != Style.DEFAULT && contentOnly){
1493 w-= getFrameWidth("lr");
1494 } else if(offsetWidth == 0 && !isBorderBox && !contentOnly && w != Style.DEFAULT){
1495 w += getFrameWidth("lr");
1496 }
1497 }
1498 String hei = map.get("height");
1499 if (hei != null) {
1500 h = Util.parseInt(hei, Style.DEFAULT);
1501 if (offsetHeight == 0 && isBorderBox && contentOnly && h != Style.DEFAULT && !GXT.isIE) {
1502 h -= getFrameWidth("tb");
1503 } else if(GXT.isIE && isBorderBox && h != Style.DEFAULT && contentOnly){
1504 h-= getFrameWidth("tb");
1505 } else if(offsetHeight == 0 && !isBorderBox && !contentOnly && h != Style.DEFAULT ){
1506 h+= getFrameWidth("tb");
1507 }
1508 }
1509 }
1510 if (w == Style.DEFAULT && h == Style.DEFAULT) {
1511 return new Size(offsetWidth, offsetHeight);
1512 }
1513 return new Size(w != Style.DEFAULT ? w : offsetWidth, h != Style.DEFAULT ? h : offsetHeight);
1514 }
1515
1516
1517
1518
1519
1520
1521
1522 public int getStyleWidth() {
1523 String w = dom.getStyle().getProperty("width");
1524 if (w == null || w.equals("")) return 0;
1525 if (w.matches("(auto|em|%|en|ex|pt|in|cm|mm|pc)")) {
1526 return 0;
1527 }
1528 return Util.parseInt(w, 0);
1529 }
1530
1531
1532
1533
1534
1535
1536
1537 public Element getSubChild(int depth) {
1538 Element child = dom;
1539 while (depth-- > 0) {
1540 child = DOM.getChild(child, 0);
1541 }
1542 return child;
1543 }
1544
1545
1546
1547
1548
1549
1550 public int getTextWidth() {
1551 String html = getInnerHtml();
1552 TextMetrics metrics = TextMetrics.get();
1553 metrics.bind(dom);
1554 return metrics.getWidth(html);
1555 }
1556
1557
1558
1559
1560
1561
1562 public int getTop() {
1563 return getTop(true);
1564 }
1565
1566
1567
1568
1569
1570
1571
1572 public int getTop(boolean local) {
1573 return local ? Util.parseInt(getStyleAttribute("top"), 0) : getY();
1574 }
1575
1576
1577
1578
1579
1580
1581 public String getValue() {
1582 return DOM.getElementProperty(dom, "value");
1583 }
1584
1585
1586
1587
1588
1589
1590 public int getWidth() {
1591 return dom.getOffsetWidth();
1592 }
1593
1594
1595
1596
1597
1598
1599
1600 public int getWidth(boolean content) {
1601 int w = getWidth();
1602 if (content) {
1603 w -= getFrameWidth("lr");
1604 }
1605 return Math.max(0,w);
1606 }
1607
1608
1609
1610
1611
1612
1613
1614 public int getX() {
1615 return dom.getAbsoluteLeft();
1616 }
1617
1618
1619
1620
1621
1622
1623
1624 public Point getXY() {
1625 return new Point(getX(), getY());
1626 }
1627
1628
1629
1630
1631
1632
1633 public int getY() {
1634 return dom.getAbsoluteTop();
1635 }
1636
1637
1638
1639
1640
1641
1642 public int getZIndex() {
1643 return Util.parseInt(getStyleAttribute("zIndex"), 0);
1644 }
1645
1646
1647
1648
1649
1650
1651
1652 public boolean hasStyleName(String style) {
1653
1654
1655 String cls = getClassName(dom);
1656
1657 return (" " + cls + " ").indexOf(" " + style + " ") != -1 ? true : false;
1658 }
1659
1660
1661
1662
1663
1664
1665 public El hide() {
1666 return setVisible(false);
1667 }
1668
1669
1670
1671
1672
1673
1674
1675 public El insertBefore(Element before) {
1676 before.getParentElement().insertBefore(dom, before);
1677 return this;
1678 }
1679
1680
1681
1682
1683
1684
1685
1686
1687 public El insertBefore(Element child, Element before) {
1688 dom.insertBefore(child, before);
1689 return this;
1690 }
1691
1692
1693
1694
1695
1696
1697
1698
1699 public El insertBefore(Element[] elements, Element before) {
1700 for (int i = 0; i < elements.length; i++) {
1701 insertBefore(elements[i], before);
1702 }
1703 return this;
1704 }
1705
1706
1707
1708
1709
1710
1711
1712
1713 public El insertChild(Element child, int index) {
1714 DOM.insertChild(dom, child, index);
1715 return this;
1716 }
1717
1718
1719
1720
1721
1722
1723
1724
1725 public El insertChild(Element[] children, int index) {
1726 for (int i = children.length - 1; i >= 0; i--) {
1727 DOM.insertChild(dom, children[i], index);
1728 }
1729 return this;
1730 }
1731
1732
1733
1734
1735
1736
1737
1738 public El insertFirst(Element element) {
1739 DOM.insertChild(dom, element, 0);
1740 return this;
1741 }
1742
1743
1744
1745
1746
1747
1748
1749 public El insertFirst(Element[] elems) {
1750 for (int i = 0; i < elems.length; i++) {
1751 DOM.appendChild(dom, elems[i]);
1752 }
1753 return this;
1754 }
1755
1756
1757
1758
1759
1760
1761
1762 public El insertFirst(String html) {
1763 return new El(DomHelper.insertFirst(dom, html));
1764 }
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774 public El insertHtml(String where, String html) {
1775 return new El(DomHelper.insertHtml(where, dom, html));
1776 }
1777
1778
1779
1780
1781
1782
1783
1784 public El insertInto(Element parent) {
1785 fly(parent, "_internal").appendChild(dom);
1786 return this;
1787 }
1788
1789
1790
1791
1792
1793
1794
1795
1796 public El insertInto(Element parent, int index) {
1797 fly(parent, "_internal").insertChild(dom, index);
1798 return this;
1799 }
1800
1801
1802
1803
1804
1805
1806
1807 public El insertLast(Element child) {
1808 int idx = dom.getChildNodes().getLength();
1809 insertChild(child, idx);
1810 return this;
1811 }
1812
1813
1814
1815
1816
1817
1818
1819
1820 public Element insertSibling(Element elem, String where) {
1821 Element refNode = where.equals("before") ? dom : nextSibling();
1822 if (refNode == null) {
1823 DOM.appendChild(DOM.getParent(dom), elem);
1824 } else {
1825 DOM.insertBefore(getParent().dom, elem, refNode);
1826 }
1827 return elem;
1828 }
1829
1830
1831
1832
1833
1834
1835
1836
1837 public El insertSibling(Element[] elems, String where) {
1838 for (int i = 0; i < elems.length; i++) {
1839 insertSibling(elems[i], where);
1840 }
1841 return this;
1842 }
1843
1844
1845
1846
1847
1848
1849
1850
1851 public boolean is(String selector) {
1852 return DomQuery.is(dom, selector);
1853 }
1854
1855
1856
1857
1858
1859
1860 public boolean isBorderBox() {
1861 return isBorderBox(dom);
1862 }
1863
1864
1865
1866
1867
1868
1869 public boolean isConnected() {
1870 return Document.get().getBody().isOrHasChild(dom);
1871 }
1872
1873
1874
1875
1876
1877
1878 public boolean isMasked() {
1879 return _mask != null && _mask.isVisible();
1880 }
1881
1882
1883
1884
1885
1886
1887
1888 public boolean isOrHasChild(Element child) {
1889 return DOM.isOrHasChild(dom, child);
1890 }
1891
1892
1893
1894
1895
1896
1897 public boolean isScrollable() {
1898 return isScrollableX() || isScrollableY();
1899 }
1900
1901
1902
1903
1904
1905
1906 public boolean isScrollableX() {
1907 return dom.getScrollWidth() > dom.getClientWidth();
1908 }
1909
1910
1911
1912
1913
1914
1915 public boolean isScrollableY() {
1916 return dom.getScrollHeight() > dom.getClientHeight();
1917 }
1918
1919 public boolean isStyleAttribute(Map<String, String> map, boolean matchAll) {
1920 Set<String> collection = map.keySet();
1921 FastMap<String> a = getStyleAttribute(new ArrayList<String>(collection));
1922 for (String s : collection) {
1923 if (map.get(s).equals(a.get(s))) {
1924 if (!matchAll) {
1925 return true;
1926 }
1927 } else {
1928 if (matchAll) {
1929 return false;
1930 }
1931 }
1932 }
1933 return false;
1934 }
1935
1936 public boolean isStyleAttribute(String attr, String value) {
1937 String a = getStyleAttribute(attr);
1938 return a != null && a.equals(value);
1939 }
1940
1941
1942
1943
1944
1945
1946
1947 public boolean isVisibility() {
1948 return isStyleAttribute("visibility", "hidden");
1949 }
1950
1951
1952
1953
1954
1955
1956 public boolean isVisible() {
1957 return isVisible(false);
1958 }
1959
1960
1961
1962
1963
1964
1965
1966
1967 public boolean isVisible(boolean deep) {
1968 Map<String, String> map = new FastMap<String>();
1969 map.put("visibility", "hidden");
1970 map.put("display", "none");
1971 boolean vis = !isStyleAttribute(map, false);
1972 El parent = getParent();
1973 Element p = parent != null ? parent.dom : null;
1974 if (p == null) {
1975 return false;
1976 }
1977 if (!deep || !vis) {
1978 return vis;
1979 }
1980 while (p != null && p != XDOM.getBody()) {
1981 if (!fly(p, "_isVisible").isVisible()) {
1982 return false;
1983 }
1984 p = (Element) p.getParentElement();
1985 }
1986
1987 return true;
1988
1989 }
1990
1991
1992
1993
1994
1995
1996 public El lastChild() {
1997 Element e = DOM.getChild(dom, DOM.getChildCount(dom) - 1);
1998 return e == null ? null : new El(e);
1999 }
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009 public Request load(RequestBuilder builder) {
2010 try {
2011 builder.setCallback(new RequestCallback() {
2012
2013 public void onError(Request request, Throwable exception) {
2014 setInnerHtml(exception.getMessage());
2015 }
2016
2017 public void onResponseReceived(Request request, Response response) {
2018 setInnerHtml(response.getText());
2019 }
2020
2021 });
2022 return builder.send();
2023 } catch (Exception e) {
2024 setInnerHtml(e.getMessage());
2025 return null;
2026 }
2027 }
2028
2029
2030
2031
2032 public El makePositionable() {
2033 return makePositionable(false);
2034 }
2035
2036
2037
2038
2039
2040
2041
2042 public El makePositionable(boolean absolute) {
2043 if (absolute) {
2044 setStyleAttribute("position", "absolute");
2045 } else if ("static".equals(getStyleAttribute("position"))) {
2046 setStyleAttribute("position", "relative");
2047 }
2048 return this;
2049 }
2050
2051
2052
2053
2054
2055
2056 public El mask() {
2057 return mask(null, null);
2058 }
2059
2060
2061
2062
2063
2064
2065
2066 public El mask(String message) {
2067 return mask(message, null);
2068 }
2069
2070
2071
2072
2073
2074
2075
2076
2077 public El mask(String message, String messageStyleName) {
2078 if ("static".equals(getStyleAttribute("position"))) {
2079 addStyleName("x-masked-relative");
2080 }
2081 if (_maskMsg != null) {
2082 _maskMsg.remove();
2083 }
2084 if (_mask != null) {
2085 _mask.remove();
2086 }
2087
2088 _mask = new El("<div class='ext-el-mask'></div>");
2089
2090 addStyleName("x-masked");
2091 _mask.setDisplayed(true);
2092
2093 appendChild(_mask.dom);
2094 if (message != null) {
2095 _maskMsg = new El("<div class='ext-el-mask-msg'><div></div></div>");
2096 if (messageStyleName != null) {
2097 _maskMsg.addStyleName(messageStyleName);
2098 }
2099 _maskMsg.firstChild().setInnerHtml(message);
2100 _maskMsg.setDisplayed(true);
2101
2102 appendChild(_maskMsg.dom);
2103 _maskMsg.center(dom);
2104 }
2105 if (GXT.isIE && !(GXT.isIE7 && GXT.isStrict) && "auto".equals(getStyleAttribute("height"))) {
2106 _mask.setSize(getWidth(), getHeight());
2107 }
2108
2109 return _mask;
2110 }
2111
2112
2113
2114
2115
2116
2117 public Element nextSibling() {
2118 return DOM.getNextSibling(dom);
2119 }
2120
2121
2122
2123
2124
2125
2126 public Element previousSibling() {
2127 return dom.getPreviousSibling().cast();
2128 }
2129
2130
2131
2132
2133 public El remove() {
2134 return removeFromParent();
2135 }
2136
2137
2138
2139
2140
2141
2142
2143 public El removeChild(Element child) {
2144 dom.removeChild(child);
2145 return this;
2146 }
2147
2148
2149
2150
2151 public El removeChildren() {
2152 El child = null;
2153 while ((child = firstChild()) != null) {
2154 dom.removeChild(child.dom);
2155 }
2156 setInnerHtml("");
2157 return this;
2158 }
2159
2160
2161
2162
2163 public El removeFromParent() {
2164 com.google.gwt.dom.client.Element p = dom.getParentElement();
2165 if (p != null) {
2166 p.removeChild(dom);
2167 }
2168 return this;
2169 }
2170
2171
2172
2173
2174
2175
2176
2177 public El removeStyleName(String... styleNames) {
2178 for (String s : styleNames) {
2179 removeStyleName(s);
2180 }
2181 return this;
2182 }
2183
2184
2185
2186
2187
2188
2189
2190 public native El removeStyleName(String styleName)
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200 ;
2201
2202
2203
2204
2205
2206
2207 public El repaint() {
2208 addStyleName("x-repaint");
2209 DeferredCommand.addCommand(new Command() {
2210 public void execute() {
2211 removeStyleName("x-repaint");
2212 }
2213 });
2214 return this;
2215 }
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225 public El replaceStyleName(String oldStyle, String newStyle) {
2226 return removeStyleName(oldStyle).addStyleName(newStyle);
2227 }
2228
2229 public El scrollIntoView(Element container, boolean hscroll) {
2230 return scrollIntoView(container, hscroll, null);
2231 }
2232
2233
2234
2235
2236
2237
2238
2239 public El scrollIntoView(Element container, boolean hscroll, int[] offsets) {
2240 if (offsets == null) {
2241 offsets = new int[] {0, 0};
2242 }
2243 Element c = container != null ? container : XDOM.getBody();
2244
2245 Point o = getOffsetsTo(c);
2246 int l = o.x;
2247 int t = o.y;
2248 l = l + c.getScrollLeft();
2249 t = t + c.getScrollTop();
2250 int b = t + getHeight() + offsets[0];
2251 int r = l + getWidth() + offsets[1];
2252
2253 int ch = c.getClientHeight();
2254 int ct = c.getScrollTop();
2255 int cb = ct + ch;
2256
2257 if (getHeight() > ch || t < ct) {
2258 c.setScrollTop(t);
2259 } else if (b > cb) {
2260 c.setScrollTop(b - ch);
2261 }
2262
2263 if (hscroll) {
2264 int cl = c.getScrollLeft();
2265 int cw = c.getClientWidth();
2266 int cr = cl + cw;
2267
2268 if (getWidth() > cw || l < cl) {
2269 c.setScrollLeft(l);
2270 } else if (r > cr) {
2271 c.setScrollLeft(r - cw);
2272 }
2273 }
2274 return this;
2275 }
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285 public El scrollTo(String side, int value) {
2286 if ("left".equalsIgnoreCase(side)) {
2287 setScrollLeft(value);
2288 } else if ("top".equalsIgnoreCase(side)) {
2289 setScrollTop(value);
2290 }
2291 return this;
2292 }
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303 public El scrollTo(String side, int value, FxConfig config) {
2304 ScrollDir dir = ScrollDir.VERTICAL;
2305 if (side.equalsIgnoreCase("left")) {
2306 dir = ScrollDir.HORIZONTAL;
2307 }
2308 BaseEffect.scroll(this, config, dir, value);
2309 return this;
2310 }
2311
2312
2313
2314
2315
2316
2317
2318
2319 public NodeList<Element> select(String selector) {
2320 return DomQuery.select(selector, dom);
2321 }
2322
2323
2324
2325
2326
2327
2328
2329 public El selectNode(String selector) {
2330 Element el = DomQuery.selectNode(selector, dom);
2331 if (el != null) {
2332 return new El(el);
2333 }
2334 return null;
2335 }
2336
2337
2338
2339
2340
2341
2342
2343
2344 public El setBorders(boolean show) {
2345 if (show) {
2346 addStyleName("x-border");
2347 setStyleAttribute("borderWidth", "1px");
2348 } else {
2349 removeStyleName("x-border");
2350 setStyleAttribute("borderWidth", "0px");
2351 }
2352 return this;
2353 }
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364 public El setBounds(int x, int y, int width, int height) {
2365 return setBounds(x, y, width, height, false);
2366 }
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378 public El setBounds(int x, int y, int width, int height, boolean adjust) {
2379 setPagePosition(x, y);
2380 setSize(width, height, adjust);
2381 return this;
2382 }
2383
2384
2385
2386
2387
2388
2389
2390 public El setBounds(Rectangle bounds) {
2391 setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
2392 return this;
2393 }
2394
2395
2396
2397
2398
2399
2400
2401
2402 public El setBounds(Rectangle bounds, boolean content) {
2403 setBounds(bounds.x, bounds.y, bounds.width, bounds.height, content);
2404 return this;
2405 }
2406
2407
2408
2409
2410
2411
2412
2413 public El setDisplayed(boolean display) {
2414 String value = display ? originalDisplay : "none";
2415 setStyleAttribute("display", value);
2416 return this;
2417 }
2418
2419
2420
2421
2422
2423
2424
2425 public El setDisplayed(String display) {
2426 setStyleAttribute("display", display);
2427 return this;
2428 }
2429
2430
2431
2432
2433
2434
2435
2436
2437 public El setElementAttribute(String attr, boolean value) {
2438 DOM.setElementPropertyBoolean(dom, attr, value);
2439 return this;
2440 }
2441
2442
2443
2444
2445
2446
2447
2448
2449 public El setElementAttribute(String attr, int value) {
2450 return setElementAttribute(attr, "" + value);
2451 }
2452
2453
2454
2455
2456
2457
2458
2459
2460 public El setElementAttribute(String attr, String value) {
2461 DOM.setElementAttribute(dom, attr, value);
2462 return this;
2463 }
2464
2465
2466
2467
2468
2469
2470 public void setEnabled(boolean enabled) {
2471 if (!enabled) {
2472 disable();
2473 } else {
2474 enable();
2475 }
2476 }
2477
2478
2479
2480
2481
2482
2483 public native El setFocus(boolean focus)
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495 ;
2496
2497
2498
2499
2500
2501
2502
2503 public El setHeight(int height) {
2504 return setHeight(height, false);
2505 }
2506
2507
2508
2509
2510
2511
2512
2513
2514 public El setHeight(int height, boolean adjust) {
2515 if (adjust && !isBorderBox()) {
2516 height -= getFrameWidth("tb");
2517 }
2518 if (height >= 0) {
2519 dom.getStyle().setPropertyPx("height", height);
2520 }
2521 return this;
2522 }
2523
2524
2525
2526
2527
2528
2529
2530 public El setHeight(String height) {
2531 DOM.setStyleAttribute(dom, "height", addUnits(height, "px"));
2532 return this;
2533 }
2534
2535
2536
2537
2538
2539
2540 public El setIconStyle(String style) {
2541 if (Util.isImagePath(style)) {
2542 setStyleAttribute("backgroundImage", "url(" + style + ")");
2543 } else {
2544 dom.setClassName(style);
2545 }
2546 return this;
2547 }
2548
2549
2550
2551
2552
2553
2554
2555 public El setId(String id) {
2556 if (id == null) {
2557 id = XDOM.getUniqueId();
2558 }
2559 dom.setId(id);
2560 return this;
2561 }
2562
2563
2564
2565
2566
2567
2568
2569 public El setInnerHtml(String html) {
2570 DOM.setInnerHTML(dom, html);
2571 return this;
2572 }
2573
2574
2575
2576
2577
2578
2579
2580
2581 public El setIntElementProperty(String property, int value) {
2582 DOM.setElementPropertyInt(dom, property, value);
2583 return this;
2584 }
2585
2586
2587
2588
2589
2590
2591
2592
2593 public El setLeft(int left) {
2594 dom.getStyle().setPropertyPx("left", left);
2595 return this;
2596 }
2597
2598
2599
2600
2601
2602
2603
2604
2605 public El setLeftTop(int left, int top) {
2606 setLeft(left);
2607 setTop(top);
2608 return this;
2609 }
2610
2611
2612
2613
2614
2615
2616
2617 public El setMargins(Margins margin) {
2618 if (margin != null) {
2619 setStyleAttribute("marginLeft", margin.left + "px");
2620 setStyleAttribute("marginTop", margin.top + "px");
2621 setStyleAttribute("marginRight", margin.right + "px");
2622 setStyleAttribute("marginBottom", margin.bottom + "px");
2623 }
2624 return this;
2625 }
2626
2627
2628
2629
2630
2631
2632
2633 public El setPadding(Padding padding) {
2634 if (padding != null) {
2635 setStyleAttribute("paddingLeft", padding.left + "px");
2636 setStyleAttribute("paddingTop", padding.top + "px");
2637 setStyleAttribute("paddingRight", padding.right + "px");
2638 setStyleAttribute("paddingBottom", padding.bottom + "px");
2639 }
2640 return this;
2641 }
2642
2643
2644
2645
2646
2647
2648
2649
2650 public El setPagePosition(int x, int y) {
2651 setX(x);
2652 setY(y);
2653 return this;
2654 }
2655
2656
2657
2658
2659
2660
2661
2662 public El setScrollLeft(int left) {
2663 DOM.setElementPropertyInt(dom, "scrollLeft", left);
2664 return this;
2665 }
2666
2667
2668
2669
2670
2671
2672
2673 public El setScrollTop(int top) {
2674 DOM.setElementPropertyInt(dom, "scrollTop", top);
2675 return this;
2676 }
2677
2678
2679
2680
2681
2682
2683
2684
2685 public El setSize(int width, int height) {
2686 setSize(width, height, false);
2687 return this;
2688 }
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698 public El setSize(int width, int height, boolean adjust) {
2699 if (adjust && !isBorderBox()) {
2700 Size frameWidth = getFrameSize();
2701 width -= frameWidth.width;
2702 height -= frameWidth.height;
2703 }
2704 if (width >= 0) {
2705 dom.getStyle().setPropertyPx("width", width);
2706 }
2707 if (height >= 0) {
2708 dom.getStyle().setPropertyPx("height", height);
2709 }
2710 return this;
2711 }
2712
2713
2714
2715
2716
2717
2718
2719 public El setSize(Size size) {
2720 setSize(size.width, size.height);
2721 return this;
2722 }
2723
2724
2725
2726
2727
2728
2729
2730
2731 public El setSize(String width, String height) {
2732 setWidth(width);
2733 setHeight(height);
2734 return this;
2735 }
2736
2737
2738
2739
2740
2741
2742
2743
2744 public El setStyleAttribute(String attr, Object value) {
2745 computedStyle.setStyleAttribute(dom, attr, value);
2746 return this;
2747 }
2748
2749
2750
2751
2752
2753
2754
2755 public El setStyleName(String style) {
2756 dom.setClassName(style);
2757 return this;
2758 }
2759
2760
2761
2762
2763
2764
2765
2766
2767 public El setStyleName(String style, boolean add) {
2768 if (add) {
2769 addStyleName(style);
2770 } else {
2771 removeStyleName(style);
2772 }
2773 return this;
2774 }
2775
2776
2777
2778
2779
2780
2781
2782
2783 public El setStyleSize(int width, int height) {
2784 setStyleAttribute("width", width);
2785 setStyleAttribute("height", height);
2786 return this;
2787 }
2788
2789
2790
2791
2792
2793
2794
2795 public El setTabIndex(int index) {
2796 DOM.setElementPropertyInt(dom, "tabIndex", index);
2797 return null;
2798 }
2799
2800
2801
2802
2803
2804
2805
2806 public El setTitle(String title) {
2807 dom.setTitle(title);
2808 return this;
2809 }
2810
2811
2812
2813
2814
2815
2816
2817
2818 public El setTop(int top) {
2819 dom.getStyle().setPropertyPx("top", top);
2820 return this;
2821 }
2822
2823
2824
2825
2826
2827
2828 public El setValue(String value) {
2829 dom.setPropertyString("value", value);
2830 return this;
2831 }
2832
2833
2834
2835
2836
2837
2838
2839
2840 public El setVisibility(boolean visible) {
2841 setStyleAttribute("visibility", visible ? "visible" : "hidden");
2842 return this;
2843 }
2844
2845
2846
2847
2848
2849
2850
2851
2852 public El setVisibilityMode(VisMode visMode) {
2853 visiblityMode = visMode;
2854 return this;
2855 }
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866 public El setVisible(boolean visible) {
2867 if (visiblityMode == VisMode.DISPLAY) {
2868 return setDisplayed(visible);
2869 } else {
2870 return setVisibility(visible);
2871 }
2872 }
2873
2874
2875
2876
2877
2878
2879
2880 public El setWidth(int width) {
2881 return setWidth(width, false);
2882 }
2883
2884
2885
2886
2887
2888
2889
2890
2891 public El setWidth(int width, boolean adjust) {
2892 if (adjust && !isBorderBox()) {
2893 width -= getFrameWidth("lr");
2894 }
2895 if (width >= 0) {
2896 dom.getStyle().setPropertyPx("width", width);
2897 }
2898 return this;
2899 }
2900
2901
2902
2903
2904
2905
2906
2907 public El setWidth(String width) {
2908 DOM.setStyleAttribute(dom, "width", addUnits(width, "px"));
2909 return this;
2910 }
2911
2912
2913
2914
2915
2916
2917
2918
2919 public El setX(int x) {
2920 return setXY(x, Style.DEFAULT);
2921 }
2922
2923
2924
2925
2926
2927
2928
2929
2930 public El setXY(int x, int y) {
2931 return setXY(new Point(x, y));
2932 }
2933
2934
2935
2936
2937
2938
2939
2940
2941 public El setXY(int x, int y, FxConfig config) {
2942 if (config == null) {
2943 setXY(x, y);
2944 } else {
2945 Fx fx = new Fx(config);
2946 fx.run(new Move(this, x, y));
2947 }
2948 return this;
2949 }
2950
2951
2952
2953
2954
2955
2956
2957 public El setXY(Point p) {
2958 makePositionable();
2959 Point pts = translatePoints(p);
2960 if (p.x != Style.DEFAULT) {
2961 setLeft(pts.x);
2962 }
2963 if (p.y != Style.DEFAULT) {
2964 setTop(pts.y);
2965 }
2966 return this;
2967 }
2968
2969
2970
2971
2972
2973
2974
2975
2976 public El setY(int y) {
2977 return setXY(Style.DEFAULT, y);
2978 }
2979
2980
2981
2982
2983
2984
2985
2986 public El setZIndex(int zIndex) {
2987 DOM.setIntStyleAttribute(dom, "zIndex", Math.max(0, zIndex));
2988 return this;
2989 }
2990
2991
2992
2993
2994
2995
2996 public El show() {
2997 return setVisible(true);
2998 }
2999
3000
3001
3002
3003
3004
3005
3006
3007 public El slideIn(Direction direction, FxConfig config) {
3008 BaseEffect.slideIn(this, config, direction);
3009 return this;
3010 }
3011
3012
3013
3014
3015
3016
3017
3018
3019 public El slideOut(Direction direction, FxConfig config) {
3020 BaseEffect.slideOut(this, config, direction);
3021 return this;
3022 }
3023
3024
3025
3026
3027
3028
3029
3030 public El subChild(int depth) {
3031 Element child = dom;
3032 while (depth-- > 0) {
3033 child = DOM.getChild(child, 0);
3034 }
3035 return new El(child);
3036 }
3037
3038
3039
3040
3041
3042
3043 public El sync(boolean show) {
3044 return this;
3045 }
3046
3047 public String toString() {
3048 return getOuterHtml();
3049 }
3050
3051 public Point translatePoints(Point p) {
3052 List<String> list = new ArrayList<String>(3);
3053 list.add("position");
3054 list.add("left");
3055 list.add("top");
3056
3057 Map<String, String> map = getStyleAttribute(list);
3058 boolean relative = "relative".equals(map.get("position"));
3059 int l = Util.parseInt(map.get("left"), -11234);
3060 int t = Util.parseInt(map.get("top"), -11234);
3061
3062 l = l != -11234 ? l : (relative ? 0 : dom.getOffsetLeft());
3063 t = t != -11234 ? t : (relative ? 0 : dom.getOffsetTop());
3064
3065 Point o = getXY();
3066 return new Point(p.x - o.x + l, p.y - o.y + t);
3067 }
3068
3069
3070
3071
3072
3073
3074 public El unclip() {
3075 if (isClipped) {
3076 isClipped = false;
3077 setStyleAttribute("overflow", originalClipped[0]);
3078 setStyleAttribute("overflowX", originalClipped[1]);
3079 setStyleAttribute("overflowY", originalClipped[2]);
3080 }
3081 return this;
3082 }
3083
3084
3085
3086
3087
3088
3089 public El unmask() {
3090 if (_mask != null) {
3091 if (_maskMsg != null) {
3092 _maskMsg.remove();
3093 _maskMsg = null;
3094 }
3095 _mask.setVisible(false);
3096 _mask.remove();
3097 _mask = null;
3098 removeStyleName("x-masked", "x-masked-relative");
3099 }
3100 return this;
3101 }
3102
3103
3104
3105
3106
3107
3108 public El unwrap(Element child, Rectangle bounds) {
3109 El.fly(child, "_internal").setLeftTop(bounds.x, bounds.y);
3110 Element p = dom.getParentElement().cast();
3111 int pos = DOM.getChildIndex(p, dom);
3112 p.removeChild(dom);
3113 DOM.insertChild(p, child, pos);
3114 return this;
3115 }
3116
3117
3118
3119
3120
3121
3122
3123 public El update(String html) {
3124 DOM.setInnerHTML(dom, html);
3125 return this;
3126 }
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136 public El updateZIndex(int adj) {
3137 setZIndex(XDOM.getTopZIndex() + adj);
3138 return this;
3139 }
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149 public Rectangle wrap(Element wrapper) {
3150 El wrap = new El(wrapper);
3151 wrap.setVisible(false);
3152
3153 String pos = getStyleAttribute("position");
3154 wrap.setStyleAttribute("position", pos);
3155
3156 int l = getLeft();
3157 int t = getTop();
3158
3159 setLeft(5000);
3160 setVisible(true);
3161
3162 int h = getComputedHeight();
3163 int w = getComputedWidth();
3164
3165 setLeft(1);
3166 setStyleAttribute("overflow", "hidden");
3167 setVisible(false);
3168
3169 wrap.insertBefore(dom);
3170 wrap.appendChild(dom);
3171
3172 wrap.setStyleAttribute("overflow", "hidden");
3173
3174 wrap.setLeft(l);
3175 wrap.setTop(t);
3176
3177 setTop(0);
3178 setLeft(0);
3179
3180 return new Rectangle(l, t, w, h);
3181 }
3182
3183 protected Point getConstrainToXY(Element elem, Point proposedXY) {
3184 int vw, vh, vx = 0, vy = 0;
3185 if (elem == XDOM.getBody()) {
3186 vw = XDOM.getViewportSize().width;
3187 vh = XDOM.getViewportSize().height;
3188 } else {
3189 vw = fly(elem, "_internal").getWidth();
3190 vh = fly(elem, "_internal").getHeight();
3191 }
3192
3193 Point xy = proposedXY;
3194 int x = xy.x;
3195 int y = xy.y;
3196
3197 int vr = vx + vw;
3198 int vb = vy + vh;
3199
3200 int w = getWidth();
3201 int h = getHeight();
3202
3203 if ((x + w) > vr) {
3204 x = vr - w;
3205 }
3206 if ((y + h) > vb) {
3207 y = vb - h;
3208
3209 }
3210
3211
3212 if (x < vx) {
3213 x = vx;
3214 }
3215 if (y < vy) {
3216 y = vy;
3217 }
3218
3219 return new Point(x, y);
3220 }
3221
3222 private native boolean isLeftorRight(String s)
3223
3224
3225
3226
3227 ;
3228
3229 public static native String getClassName(Element dom)
3230
3231
3232
3233
3234
3235
3236 ;
3237
3238
3239 private static native void setClassName(Element dom, String value)
3240
3241
3242
3243
3244
3245
3246 ;
3247
3248
3249
3250 }