1 16 package com.google.gwt.user.client; 17 18 import com.google.gwt.core.client.GWT; 19 import com.google.gwt.core.client.GWT.UncaughtExceptionHandler; 20 import com.google.gwt.user.client.impl.DOMImpl; 21 22 import java.util.ArrayList ; 23 24 30 public class DOM { 31 32 private static DOMImpl impl; 33 private static Element sCaptureElem; 34 35 private static ArrayList sEventPreviewStack = new ArrayList (); 37 38 static { 39 impl = (DOMImpl) GWT.create(DOMImpl.class); 40 impl.init(); 41 } 42 43 52 public static void addEventPreview(EventPreview preview) { 53 sEventPreviewStack.add(preview); 56 } 57 58 64 public static void appendChild(Element parent, Element child) { 65 impl.appendChild(parent, child); 66 } 67 68 77 public static boolean compare(Element elem1, Element elem2) { 78 return impl.compare(elem1, elem2); 79 } 80 81 86 public static Element createAnchor() { 87 return impl.createElement("A"); 88 } 89 90 95 public static Element createButton() { 96 return impl.createElement("button"); 97 } 98 99 104 public static Element createCaption() { 105 return impl.createElement("caption"); 106 } 107 108 113 public static Element createCol() { 114 return impl.createElement("col"); 115 } 116 117 122 public static Element createColGroup() { 123 return impl.createElement("colgroup"); 124 } 125 126 131 public static Element createDiv() { 132 return impl.createElement("div"); 133 } 134 135 141 public static Element createElement(String tagName) { 142 return impl.createElement(tagName); 143 } 144 145 150 public static Element createFieldSet() { 151 return impl.createElement("fieldset"); 152 } 153 154 159 public static Element createForm() { 160 return impl.createElement("form"); 161 } 162 163 168 public static Element createIFrame() { 169 return impl.createElement("iframe"); 170 } 171 172 177 public static Element createImg() { 178 return impl.createElement("img"); 179 } 180 181 186 public static Element createInputCheck() { 187 return impl.createInputElement("checkbox"); 188 } 189 190 195 public static Element createInputPassword() { 196 return impl.createInputElement("password"); 197 } 198 199 206 public static Element createInputRadio(String group) { 207 return impl.createInputRadioElement(group); 208 } 209 210 215 public static Element createInputText() { 216 return impl.createInputElement("text"); 217 } 218 219 224 public static Element createLabel() { 225 return impl.createElement("label"); 226 } 227 228 233 public static Element createLegend() { 234 return impl.createElement("legend"); 235 } 236 237 242 public static Element createOptions() { 243 return impl.createElement("options"); 244 } 245 246 254 public static Element createSelect() { 255 return DOM.createSelect(false); 256 } 257 258 263 public static Element createSelect(boolean multiple) { 264 return impl.createSelectElement(multiple); 265 } 266 267 272 public static Element createSpan() { 273 return impl.createElement("span"); 274 } 275 276 281 public static Element createTable() { 282 return impl.createElement("table"); 283 } 284 285 290 public static Element createTBody() { 291 return impl.createElement("tbody"); 292 } 293 294 299 public static Element createTD() { 300 return impl.createElement("td"); 301 } 302 303 308 public static Element createTextArea() { 309 return impl.createElement("textarea"); 310 } 311 312 317 public static Element createTFoot() { 318 return impl.createElement("tfoot"); 319 } 320 321 326 public static Element createTH() { 327 return impl.createElement("th"); 328 } 329 330 335 public static Element createTHead() { 336 return impl.createElement("thead"); 337 } 338 339 344 public static Element createTR() { 345 return impl.createElement("tr"); 346 } 347 348 355 public static void eventCancelBubble(Event evt, boolean cancel) { 356 impl.eventCancelBubble(evt, cancel); 357 } 358 359 365 public static boolean eventGetAltKey(Event evt) { 366 return impl.eventGetAltKey(evt); 367 } 368 369 376 public static int eventGetButton(Event evt) { 377 return impl.eventGetButton(evt); 378 } 379 380 386 public static int eventGetClientX(Event evt) { 387 return impl.eventGetClientX(evt); 388 } 389 390 396 public static int eventGetClientY(Event evt) { 397 return impl.eventGetClientY(evt); 398 } 399 400 406 public static boolean eventGetCtrlKey(Event evt) { 407 return impl.eventGetCtrlKey(evt); 408 } 409 410 417 public static Element eventGetFromElement(Event evt) { 418 return impl.eventGetFromElement(evt); 419 } 420 421 434 public static int eventGetKeyCode(Event evt) { 435 return impl.eventGetKeyCode(evt); 436 } 437 438 444 public static boolean eventGetMetaKey(Event evt) { 445 return impl.eventGetMetaKey(evt); 446 } 447 448 464 public static int eventGetMouseWheelVelocityY(Event evt) { 465 return impl.eventGetMouseWheelVelocityY(evt); 466 } 467 468 474 public static boolean eventGetRepeat(Event evt) { 475 return impl.eventGetRepeat(evt); 476 } 477 478 484 public static int eventGetScreenX(Event evt) { 485 return impl.eventGetScreenX(evt); 486 } 487 488 494 public static int eventGetScreenY(Event evt) { 495 return impl.eventGetScreenY(evt); 496 } 497 498 504 public static boolean eventGetShiftKey(Event evt) { 505 return impl.eventGetShiftKey(evt); 506 } 507 508 514 public static Element eventGetTarget(Event evt) { 515 return impl.eventGetTarget(evt); 516 } 517 518 525 public static Element eventGetToElement(Event evt) { 526 return impl.eventGetToElement(evt); 527 } 528 529 535 public static int eventGetType(Event evt) { 536 return impl.eventGetTypeInt(evt); 537 } 538 539 545 public static String eventGetTypeString(Event evt) { 546 return impl.eventGetType(evt); 547 } 548 549 554 public static void eventPreventDefault(Event evt) { 555 impl.eventPreventDefault(evt); 556 } 557 558 564 public static void eventSetKeyCode(Event evt, char key) { 565 impl.eventSetKeyCode(evt, key); 566 } 567 568 575 public static String eventToString(Event evt) { 576 return impl.eventToString(evt); 577 } 578 579 586 public static int getAbsoluteLeft(Element elem) { 587 return impl.getAbsoluteLeft(elem); 588 } 589 590 597 public static int getAbsoluteTop(Element elem) { 598 return impl.getAbsoluteTop(elem); 599 } 600 601 610 public static String getAttribute(Element elem, String attr) { 611 return getElementProperty(elem, attr); 612 } 613 614 623 public static boolean getBooleanAttribute(Element elem, String attr) { 624 return getElementPropertyBoolean(elem, attr); 625 } 626 627 633 public static Element getCaptureElement() { 634 return sCaptureElem; 635 } 636 637 644 public static Element getChild(Element parent, int index) { 645 return impl.getChild(parent, index); 646 } 647 648 654 public static int getChildCount(Element parent) { 655 return impl.getChildCount(parent); 656 } 657 658 666 public static int getChildIndex(Element parent, Element child) { 667 return impl.getChildIndex(parent, child); 668 } 669 670 677 public static String getElementAttribute(Element elem, String attr) { 678 return impl.getElementAttribute(elem, attr); 679 } 680 681 688 public static Element getElementById(String id) { 689 return impl.getElementById(id); 690 } 691 698 public static String getElementProperty(Element elem, String prop) { 699 return impl.getElementProperty(elem, prop); 700 } 701 702 709 public static boolean getElementPropertyBoolean(Element elem, String prop) { 710 return impl.getElementPropertyBoolean(elem, prop); 711 } 712 713 720 public static int getElementPropertyInt(Element elem, String prop) { 721 return impl.getElementPropertyInt(elem, prop); 722 } 723 724 731 public static int getEventsSunk(Element elem) { 732 return impl.getEventsSunk(elem); 733 } 734 735 741 public static Element getFirstChild(Element elem) { 742 return impl.getFirstChild(elem); 743 } 744 745 753 public static String getImgSrc(Element img) { 754 return impl.getImgSrc(img); 755 } 756 757 763 public static String getInnerHTML(Element elem) { 764 return impl.getInnerHTML(elem); 765 } 766 767 774 public static String getInnerText(Element elem) { 775 return impl.getInnerText(elem); 776 } 777 778 787 public static int getIntAttribute(Element elem, String attr) { 788 return getElementPropertyInt(elem, attr); 789 } 790 791 798 public static int getIntStyleAttribute(Element elem, String attr) { 799 return impl.getIntStyleAttribute(elem, attr); 800 } 801 802 808 public static Element getNextSibling(Element elem) { 809 return impl.getNextSibling(elem); 810 } 811 812 818 public static Element getParent(Element elem) { 819 return impl.getParent(elem); 820 } 821 822 829 public static String getStyleAttribute(Element elem, String attr) { 830 return impl.getStyleAttribute(elem, attr); 831 } 832 833 842 public static void insertBefore(Element parent, Element child, Element before) { 843 impl.insertBefore(parent, child, before); 844 } 845 846 855 public static void insertChild(Element parent, Element child, int index) { 856 impl.insertChild(parent, child, index); 857 } 858 859 869 public static void insertListItem(Element select, String item, String value, 870 int index) { 871 impl.insertListItem(select, item, value, index); 872 } 873 874 882 public static boolean isOrHasChild(Element parent, Element child) { 883 return impl.isOrHasChild(parent, child); 884 } 885 886 893 public static void releaseCapture(Element elem) { 894 if ((sCaptureElem != null) && compare(elem, sCaptureElem)) { 895 sCaptureElem = null; 896 } 897 impl.releaseCapture(elem); 898 } 899 900 906 public static void removeChild(Element parent, Element child) { 907 impl.removeChild(parent, child); 908 } 909 910 916 public static void removeElementAttribute(Element elem, String attr) { 917 impl.removeElementAttribute(elem, attr); 918 } 919 920 926 public static void removeEventPreview(EventPreview preview) { 927 sEventPreviewStack.remove(preview); 931 } 932 933 945 public static void scrollIntoView(Element elem) { 946 impl.scrollIntoView(elem); 947 } 948 949 958 public static void setAttribute(Element elem, String attr, String value) { 959 setElementProperty(elem, attr, value); 960 } 961 962 971 public static void setBooleanAttribute(Element elem, String attr, 972 boolean value) { 973 setElementPropertyBoolean(elem, attr, value); 974 } 975 976 982 public static void setCapture(Element elem) { 983 sCaptureElem = elem; 984 impl.setCapture(elem); 985 } 986 987 994 public static void setElementAttribute(Element elem, String attr, 995 String value) { 996 impl.setElementAttribute(elem, attr, value); 997 } 998 999 1006 public static void setElementProperty(Element elem, String prop, 1007 String value) { 1008 impl.setElementProperty(elem, prop, value); 1009 } 1010 1011 1018 public static void setElementPropertyBoolean(Element elem, String prop, 1019 boolean value) { 1020 impl.setElementPropertyBoolean(elem, prop, value); 1021 } 1022 1023 1030 public static void setElementPropertyInt(Element elem, String prop, 1031 int value) { 1032 impl.setElementPropertyInt(elem, prop, value); 1033 } 1034 1035 1042 public static void setEventListener(Element elem, EventListener listener) { 1043 impl.setEventListener(elem, listener); 1044 } 1045 1046 1053 public static void setImgSrc(Element img, String src) { 1054 impl.setImgSrc(img, src); 1055 } 1056 1057 1063 public static void setInnerHTML(Element elem, String html) { 1064 impl.setInnerHTML(elem, html); 1065 } 1066 1067 1074 public static void setInnerText(Element elem, String text) { 1075 impl.setInnerText(elem, text); 1076 } 1077 1078 1087 public static void setIntAttribute(Element elem, String attr, int value) { 1088 setElementPropertyInt(elem, attr, value); 1089 } 1090 1091 1098 public static void setIntStyleAttribute(Element elem, String attr, 1099 int value) { 1100 impl.setIntStyleAttribute(elem, attr, value); 1101 } 1102 1103 1110 public static void setOptionText(Element select, String text, int index) { 1111 impl.setOptionText(select, text, index); 1112 } 1113 1114 1121 public static void setStyleAttribute(Element elem, String attr, 1122 String value) { 1123 impl.setStyleAttribute(elem, attr, value); 1124 } 1125 1126 1135 public static void sinkEvents(Element elem, int eventBits) { 1136 impl.sinkEvents(elem, eventBits); 1137 } 1138 1139 1146 public static String toString(Element elem) { 1147 return impl.toString(elem); 1148 } 1149 1150 1158 static void dispatchEvent(Event evt, Element elem, EventListener listener) { 1159 UncaughtExceptionHandler handler = GWT.getUncaughtExceptionHandler(); 1160 if (handler != null) { 1161 dispatchEventAndCatch(evt, elem, listener, handler); 1162 } else { 1163 dispatchEventImpl(evt, elem, listener); 1164 } 1165 } 1166 1167 1174 static boolean previewEvent(Event evt) { 1175 boolean ret = true; 1177 if (sEventPreviewStack.size() > 0) { 1178 EventPreview preview = 1179 (EventPreview) sEventPreviewStack.get(sEventPreviewStack.size() - 1); 1180 if (!(ret = preview.onEventPreview(evt))) { 1181 eventCancelBubble(evt, true); 1184 eventPreventDefault(evt); 1185 } 1186 } 1187 1188 return ret; 1189 } 1190 1191 private static void dispatchEventAndCatch(Event evt, Element elem, 1192 EventListener listener, UncaughtExceptionHandler handler) { 1193 try { 1194 dispatchEventImpl(evt, elem, listener); 1195 } catch (Throwable e) { 1196 handler.onUncaughtException(e); 1197 } 1198 } 1199 1200 private static void dispatchEventImpl(Event evt, Element elem, 1201 EventListener listener) { 1202 if (elem == sCaptureElem) { 1204 if (eventGetType(evt) == Event.ONLOSECAPTURE) { 1206 sCaptureElem = null; 1207 } 1208 } 1209 1210 listener.onBrowserEvent(evt); 1212 } 1213} 1214 | Popular Tags |