Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Util.java 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client;
  17. import java.util.ArrayList;
  18. import java.util.Arrays;
  19. import java.util.Collection;
  20. import java.util.Iterator;
  21. import java.util.List;
  22. import com.google.gwt.dom.client.Element;
  23. import com.google.gwt.dom.client.NativeEvent;
  24. import com.google.gwt.event.dom.client.KeyEvent;
  25. import com.google.gwt.user.client.DOM;
  26. import com.google.gwt.user.client.Event;
  27. import com.google.gwt.user.client.ui.HasWidgets;
  28. import com.google.gwt.user.client.ui.Widget;
  29. import com.vaadin.client.RenderInformation.FloatSize;
  30. import com.vaadin.client.ui.VOverlay;
  31. import com.vaadin.shared.AbstractComponentState;
  32. import com.vaadin.shared.ApplicationConstants;
  33. import com.vaadin.shared.communication.MethodInvocation;
  34. import com.vaadin.shared.ui.ComponentStateUtil;
  35. import com.vaadin.shared.util.SharedUtil;
  36. public class Util {
  37. /**
  38. * Helper method for debugging purposes.
  39. *
  40. * Stops execution on firefox browsers on a breakpoint.
  41. *
  42. */
  43. @Deprecated
  44. public static void browserDebugger() {
  45. WidgetUtil.browserDebugger();
  46. }
  47. /**
  48. * Helper method for a bug fix #14041. For mozilla getKeyCode return 0 for
  49. * space bar (because space is considered as char). If return 0 use
  50. * getCharCode.
  51. *
  52. * @param event
  53. * @return return key code
  54. * @since 7.2.4
  55. */
  56. @Deprecated
  57. public static int getKeyCode(KeyEvent<?> event) {
  58. return WidgetUtil.getKeyCode(event);
  59. }
  60. /**
  61. *
  62. * Returns the topmost element of from given coordinates.
  63. *
  64. * TODO fix crossplat issues clientX vs pageX. See quircksmode. Not critical
  65. * for vaadin as we scroll div istead of page.
  66. *
  67. * @param x
  68. * @param y
  69. * @return the element at given coordinates
  70. */
  71. @Deprecated
  72. public static com.google.gwt.user.client.Element getElementFromPoint(
  73. int clientX, int clientY) {
  74. return DOM.asOld(WidgetUtil.getElementFromPoint(clientX, clientY));
  75. }
  76. /**
  77. * This helper method can be called if components size have been changed
  78. * outside rendering phase. It notifies components parent about the size
  79. * change so it can react.
  80. *
  81. * When using this method, developer should consider if size changes could
  82. * be notified lazily. If lazy flag is true, method will save widget and
  83. * wait for a moment until it notifies parents in chunks. This may vastly
  84. * optimize layout in various situation. Example: if component have a lot of
  85. * images their onload events may fire "layout phase" many times in a short
  86. * period.
  87. *
  88. * @param widget
  89. * @param lazy
  90. * run componentSizeUpdated lazyly
  91. *
  92. * @deprecated As of 7.0, use
  93. * {@link LayoutManager#setNeedsMeasure(ComponentConnector)}
  94. * instead
  95. */
  96. @Deprecated
  97. public static void notifyParentOfSizeChange(Widget widget, boolean lazy) {
  98. ComponentConnector connector = findConnectorFor(widget);
  99. if (connector != null) {
  100. connector.getLayoutManager().setNeedsMeasure(connector);
  101. if (!lazy) {
  102. connector.getLayoutManager().layoutNow();
  103. }
  104. }
  105. }
  106. public static ComponentConnector findConnectorFor(Widget widget) {
  107. List<ApplicationConnection> runningApplications = ApplicationConfiguration
  108. .getRunningApplications();
  109. for (ApplicationConnection applicationConnection : runningApplications) {
  110. ConnectorMap connectorMap = applicationConnection.getConnectorMap();
  111. ComponentConnector connector = connectorMap.getConnector(widget);
  112. if (connector == null) {
  113. continue;
  114. }
  115. if (connector.getConnection() == applicationConnection) {
  116. return connector;
  117. }
  118. }
  119. return null;
  120. }
  121. @Deprecated
  122. public static float parseRelativeSize(String size) {
  123. return WidgetUtil.parseRelativeSize(size);
  124. }
  125. /**
  126. * Converts html entities to text.
  127. *
  128. * @param html
  129. * @return escaped string presentation of given html
  130. */
  131. @Deprecated
  132. public static String escapeHTML(String html) {
  133. return WidgetUtil.escapeHTML(html);
  134. }
  135. /**
  136. * Escapes the string so it is safe to write inside an HTML attribute.
  137. *
  138. * @param attribute
  139. * The string to escape
  140. * @return An escaped version of <literal>attribute</literal>.
  141. */
  142. @Deprecated
  143. public static String escapeAttribute(String attribute) {
  144. return WidgetUtil.escapeAttribute(attribute);
  145. }
  146. /**
  147. * Clones given element as in JavaScript.
  148. *
  149. * Deprecate this if there appears similar method into GWT someday.
  150. *
  151. * @param element
  152. * @param deep
  153. * clone child tree also
  154. * @return
  155. */
  156. @Deprecated
  157. public static com.google.gwt.user.client.Element cloneNode(Element element,
  158. boolean deep) {
  159. return DOM.asOld(WidgetUtil.cloneNode(element, deep));
  160. }
  161. @Deprecated
  162. public static int measureHorizontalPaddingAndBorder(Element element,
  163. int paddingGuess) {
  164. return WidgetUtil.measureHorizontalPaddingAndBorder(element,
  165. paddingGuess);
  166. }
  167. @Deprecated
  168. public static int measureVerticalPaddingAndBorder(Element element,
  169. int paddingGuess) {
  170. return WidgetUtil
  171. .measureVerticalPaddingAndBorder(element, paddingGuess);
  172. }
  173. @Deprecated
  174. public static int measureHorizontalBorder(Element element) {
  175. return WidgetUtil.measureHorizontalBorder(element);
  176. }
  177. @Deprecated
  178. public static int measureVerticalBorder(Element element) {
  179. return WidgetUtil.measureVerticalBorder(element);
  180. }
  181. @Deprecated
  182. public static int measureMarginLeft(Element element) {
  183. return WidgetUtil.measureMarginLeft(element);
  184. }
  185. @Deprecated
  186. public static int setHeightExcludingPaddingAndBorder(Widget widget,
  187. String height, int paddingBorderGuess) {
  188. return WidgetUtil.setHeightExcludingPaddingAndBorder(widget, height,
  189. paddingBorderGuess);
  190. }
  191. @Deprecated
  192. public static int setWidthExcludingPaddingAndBorder(Widget widget,
  193. String width, int paddingBorderGuess) {
  194. return WidgetUtil.setWidthExcludingPaddingAndBorder(widget, width,
  195. paddingBorderGuess);
  196. }
  197. @Deprecated
  198. public static int setWidthExcludingPaddingAndBorder(Element element,
  199. int requestedWidth, int horizontalPaddingBorderGuess,
  200. boolean requestedWidthIncludesPaddingBorder) {
  201. return WidgetUtil.setWidthExcludingPaddingAndBorder(element,
  202. requestedWidth, horizontalPaddingBorderGuess,
  203. requestedWidthIncludesPaddingBorder);
  204. }
  205. @Deprecated
  206. public static int setHeightExcludingPaddingAndBorder(Element element,
  207. int requestedHeight, int verticalPaddingBorderGuess,
  208. boolean requestedHeightIncludesPaddingBorder) {
  209. return WidgetUtil.setHeightExcludingPaddingAndBorder(element,
  210. requestedHeight, verticalPaddingBorderGuess,
  211. requestedHeightIncludesPaddingBorder);
  212. }
  213. @Deprecated
  214. public static String getSimpleName(Object widget) {
  215. return WidgetUtil.getSimpleName(widget);
  216. }
  217. @Deprecated
  218. public static void setFloat(Element element, String value) {
  219. WidgetUtil.setFloat(element, value);
  220. }
  221. @Deprecated
  222. public static int getNativeScrollbarSize() {
  223. return WidgetUtil.getNativeScrollbarSize();
  224. }
  225. /**
  226. * Defers the execution of {@link #runWebkitOverflowAutoFix(Element)}
  227. *
  228. * @since 7.2.6
  229. * @param elem
  230. * with overflow auto
  231. */
  232. @Deprecated
  233. public static void runWebkitOverflowAutoFixDeferred(final Element elem) {
  234. WidgetUtil.runWebkitOverflowAutoFixDeferred(elem);
  235. }
  236. /**
  237. * Run workaround for webkits overflow auto issue.
  238. *
  239. * See: our bug #2138 and https://bugs.webkit.org/show_bug.cgi?id=21462
  240. *
  241. * @param elem
  242. * with overflow auto
  243. */
  244. @Deprecated
  245. public static void runWebkitOverflowAutoFix(final Element elem) {
  246. WidgetUtil.runWebkitOverflowAutoFix(elem);
  247. }
  248. /**
  249. * Parses shared state and fetches the relative size of the component. If a
  250. * dimension is not specified as relative it will return -1. If the shared
  251. * state does not contain width or height specifications this will return
  252. * null.
  253. *
  254. * @param state
  255. * @return
  256. */
  257. public static FloatSize parseRelativeSize(AbstractComponentState state) {
  258. if (ComponentStateUtil.isUndefinedHeight(state)
  259. && ComponentStateUtil.isUndefinedWidth(state)) {
  260. return null;
  261. }
  262. float relativeWidth = WidgetUtil.parseRelativeSize(state.width);
  263. float relativeHeight = WidgetUtil.parseRelativeSize(state.height);
  264. FloatSize relativeSize = new FloatSize(relativeWidth, relativeHeight);
  265. return relativeSize;
  266. }
  267. @Deprecated
  268. public static boolean isCached(UIDL uidl) {
  269. return uidl.getBooleanAttribute("cached");
  270. }
  271. @Deprecated
  272. public static void alert(String string) {
  273. WidgetUtil.alert(string);
  274. }
  275. /**
  276. * Checks if a and b are equals using {@link #equals(Object)}. Handles null
  277. * values as well. Does not ensure that objects are of the same type.
  278. * Assumes that the first object's equals method handle equals properly.
  279. *
  280. * @param a
  281. * The first value to compare
  282. * @param b
  283. * The second value to compare
  284. * @return
  285. * @deprecated As of 7.1 use {@link SharedUtil#equals(Object)} instead
  286. */
  287. @Deprecated
  288. public static boolean equals(Object a, Object b) {
  289. return SharedUtil.equals(a, b);
  290. }
  291. public static void updateRelativeChildrenAndSendSizeUpdateEvent(
  292. ApplicationConnection client, HasWidgets container, Widget widget) {
  293. notifyParentOfSizeChange(widget, false);
  294. }
  295. /**
  296. * Gets the border-box width for the given element, i.e. element width +
  297. * border + padding. Always rounds up to nearest integer.
  298. *
  299. * @param element
  300. * The element to check
  301. * @return The border-box width for the element
  302. */
  303. @Deprecated
  304. public static int getRequiredWidth(com.google.gwt.dom.client.Element element) {
  305. return WidgetUtil.getRequiredWidth(element);
  306. }
  307. /**
  308. * Gets the border-box height for the given element, i.e. element height +
  309. * border + padding. Always rounds up to nearest integer.
  310. *
  311. * @param element
  312. * The element to check
  313. * @return The border-box height for the element
  314. */
  315. @Deprecated
  316. public static int getRequiredHeight(
  317. com.google.gwt.dom.client.Element element) {
  318. return WidgetUtil.getRequiredHeight(element);
  319. }
  320. @Deprecated
  321. public int getRequiredWidthBoundingClientRect(
  322. com.google.gwt.dom.client.Element element) {
  323. return WidgetUtil.getRequiredWidthBoundingClientRect(element);
  324. }
  325. @Deprecated
  326. public static int getRequiredHeightComputedStyle(
  327. com.google.gwt.dom.client.Element element) {
  328. return WidgetUtil.getRequiredHeightComputedStyle(element);
  329. }
  330. @Deprecated
  331. public static int getRequiredWidthComputedStyle(
  332. com.google.gwt.dom.client.Element element) {
  333. return WidgetUtil.getRequiredWidthComputedStyle(element);
  334. }
  335. @Deprecated
  336. public static int getRequiredHeightBoundingClientRect(
  337. com.google.gwt.dom.client.Element element) {
  338. return WidgetUtil.getRequiredHeightBoundingClientRect(element);
  339. }
  340. @Deprecated
  341. public static int getRequiredWidth(Widget widget) {
  342. return WidgetUtil.getRequiredWidth(widget);
  343. }
  344. @Deprecated
  345. public static int getRequiredHeight(Widget widget) {
  346. return WidgetUtil.getRequiredHeight(widget);
  347. }
  348. /**
  349. * Detects what is currently the overflow style attribute in given element.
  350. *
  351. * @param pe
  352. * the element to detect
  353. * @return true if auto or scroll
  354. */
  355. @Deprecated
  356. public static boolean mayHaveScrollBars(com.google.gwt.dom.client.Element pe) {
  357. return WidgetUtil.mayHaveScrollBars(pe);
  358. }
  359. /**
  360. * Locates the nested child component of <literal>parent</literal> which
  361. * contains the element <literal>element</literal>. The child component is
  362. * also returned if "element" is part of its caption. If
  363. * <literal>element</literal> is not part of any child component, null is
  364. * returned.
  365. *
  366. * This method returns the deepest nested VPaintableWidget.
  367. *
  368. * @param client
  369. * A reference to ApplicationConnection
  370. * @param parent
  371. * The widget that contains <literal>element</literal>.
  372. * @param element
  373. * An element that is a sub element of the parent
  374. * @return The VPaintableWidget which the element is a part of. Null if the
  375. * element does not belong to a child.
  376. */
  377. public static ComponentConnector getConnectorForElement(
  378. ApplicationConnection client, Widget parent, Element element) {
  379. Element browseElement = element;
  380. Element rootElement = parent.getElement();
  381. while (browseElement != null && browseElement != rootElement) {
  382. ComponentConnector connector = ConnectorMap.get(client)
  383. .getConnector(browseElement);
  384. if (connector == null) {
  385. String ownerPid = VCaption.getCaptionOwnerPid(browseElement);
  386. if (ownerPid != null) {
  387. connector = (ComponentConnector) ConnectorMap.get(client)
  388. .getConnector(ownerPid);
  389. }
  390. }
  391. if (connector != null) {
  392. // check that inside the rootElement
  393. while (browseElement != null && browseElement != rootElement) {
  394. browseElement = browseElement.getParentElement();
  395. }
  396. if (browseElement != rootElement) {
  397. return null;
  398. } else {
  399. return connector;
  400. }
  401. }
  402. browseElement = browseElement.getParentElement();
  403. }
  404. // No connector found, element is possibly inside a VOverlay
  405. // If the overlay has an owner, try to find the owner's connector
  406. VOverlay overlay = findWidget(element, VOverlay.class);
  407. if (overlay != null && overlay.getOwner() != null) {
  408. return getConnectorForElement(client, client.getUIConnector()
  409. .getWidget(), overlay.getOwner().getElement());
  410. } else {
  411. return null;
  412. }
  413. }
  414. /**
  415. * Will (attempt) to focus the given DOM Element.
  416. *
  417. * @param el
  418. * the element to focus
  419. */
  420. @Deprecated
  421. public static void focus(Element el) {
  422. WidgetUtil.focus(el);
  423. }
  424. /**
  425. * Helper method to find the nearest parent paintable instance by traversing
  426. * the DOM upwards from given element.
  427. *
  428. * @param element
  429. * the element to start from
  430. */
  431. public static ComponentConnector findPaintable(
  432. ApplicationConnection client, Element element) {
  433. Widget widget = Util.findWidget(element, null);
  434. ConnectorMap vPaintableMap = ConnectorMap.get(client);
  435. while (widget != null && !vPaintableMap.isConnector(widget)) {
  436. widget = widget.getParent();
  437. }
  438. return vPaintableMap.getConnector(widget);
  439. }
  440. /**
  441. * Helper method to find first instance of given Widget type found by
  442. * traversing DOM upwards from given element.
  443. *
  444. * @param element
  445. * the element where to start seeking of Widget
  446. * @param class1
  447. * the Widget type to seek for
  448. */
  449. @Deprecated
  450. public static <T> T findWidget(Element element,
  451. Class<? extends Widget> class1) {
  452. return WidgetUtil.findWidget(element, class1);
  453. }
  454. /**
  455. * Force webkit to redraw an element
  456. *
  457. * @param element
  458. * The element that should be redrawn
  459. */
  460. @Deprecated
  461. public static void forceWebkitRedraw(Element element) {
  462. WidgetUtil.forceWebkitRedraw(element);
  463. }
  464. /**
  465. * Performs a hack to trigger a re-layout in the IE8. This is usually
  466. * necessary in cases where IE8 "forgets" to update child elements when they
  467. * resize.
  468. *
  469. * @param e
  470. * The element to perform the hack on
  471. */
  472. @Deprecated
  473. public static final void forceIE8Redraw(Element e) {
  474. WidgetUtil.forceIE8Redraw(e);
  475. }
  476. /**
  477. * Performs a hack to trigger a re-layout in the IE browser. This is usually
  478. * necessary in cases where IE "forgets" to update child elements when they
  479. * resize.
  480. *
  481. * @since 7.3
  482. * @param e
  483. * The element to perform the hack on
  484. */
  485. @Deprecated
  486. public static void forceIERedraw(Element e) {
  487. WidgetUtil.forceIERedraw(e);
  488. }
  489. /**
  490. * Detaches and re-attaches the element from its parent. The element is
  491. * reattached at the same position in the DOM as it was before.
  492. *
  493. * Does nothing if the element is not attached to the DOM.
  494. *
  495. * @param element
  496. * The element to detach and re-attach
  497. */
  498. @Deprecated
  499. public static void detachAttach(Element element) {
  500. WidgetUtil.detachAttach(element);
  501. }
  502. @Deprecated
  503. public static void sinkOnloadForImages(Element element) {
  504. WidgetUtil.sinkOnloadForImages(element);
  505. }
  506. /**
  507. * Returns the index of the childElement within its parent.
  508. *
  509. * @param subElement
  510. * @return
  511. */
  512. @Deprecated
  513. public static int getChildElementIndex(Element childElement) {
  514. return WidgetUtil.getChildElementIndex(childElement);
  515. }
  516. private static void printConnectorInvocations(
  517. ArrayList<MethodInvocation> invocations, String id,
  518. ApplicationConnection c) {
  519. ServerConnector connector = ConnectorMap.get(c).getConnector(id);
  520. if (connector != null) {
  521. VConsole.log("\t" + id + " (" + connector.getClass() + ") :");
  522. } else {
  523. VConsole.log("\t" + id
  524. + ": Warning: no corresponding connector for id " + id);
  525. }
  526. for (MethodInvocation invocation : invocations) {
  527. Object[] parameters = invocation.getParameters();
  528. String formattedParams = null;
  529. if (ApplicationConstants.UPDATE_VARIABLE_METHOD.equals(invocation
  530. .getMethodName()) && parameters.length == 2) {
  531. // name, value
  532. Object value = parameters[1];
  533. // TODO paintables inside lists/maps get rendered as
  534. // components in the debug console
  535. String formattedValue = value instanceof ServerConnector ? ((ServerConnector) value)
  536. .getConnectorId() : String.valueOf(value);
  537. formattedParams = parameters[0] + " : " + formattedValue;
  538. }
  539. if (null == formattedParams) {
  540. formattedParams = (null != parameters) ? Arrays
  541. .toString(parameters) : null;
  542. }
  543. VConsole.log("\t\t" + invocation.getInterfaceName() + "."
  544. + invocation.getMethodName() + "(" + formattedParams + ")");
  545. }
  546. }
  547. static void logVariableBurst(ApplicationConnection c,
  548. Collection<MethodInvocation> loggedBurst) {
  549. try {
  550. VConsole.log("Variable burst to be sent to server:");
  551. String curId = null;
  552. ArrayList<MethodInvocation> invocations = new ArrayList<MethodInvocation>();
  553. for (MethodInvocation methodInvocation : loggedBurst) {
  554. String id = methodInvocation.getConnectorId();
  555. if (curId == null) {
  556. curId = id;
  557. } else if (!curId.equals(id)) {
  558. printConnectorInvocations(invocations, curId, c);
  559. invocations.clear();
  560. curId = id;
  561. }
  562. invocations.add(methodInvocation);
  563. }
  564. if (!invocations.isEmpty()) {
  565. printConnectorInvocations(invocations, curId, c);
  566. }
  567. } catch (Exception e) {
  568. VConsole.error(e);
  569. }
  570. }
  571. /**
  572. * Temporarily sets the {@code styleProperty} to {@code tempValue} and then
  573. * resets it to its current value. Used mainly to work around rendering
  574. * issues in IE (and possibly in other browsers)
  575. *
  576. * @param element
  577. * The target element
  578. * @param styleProperty
  579. * The name of the property to set
  580. * @param tempValue
  581. * The temporary value
  582. */
  583. @Deprecated
  584. public static void setStyleTemporarily(Element element,
  585. final String styleProperty, String tempValue) {
  586. WidgetUtil.setStyleTemporarily(element, styleProperty, tempValue);
  587. }
  588. /**
  589. * A helper method to return the client position from an event. Returns
  590. * position from either first changed touch (if touch event) or from the
  591. * event itself.
  592. *
  593. * @param event
  594. * @return
  595. */
  596. @Deprecated
  597. public static int getTouchOrMouseClientX(Event event) {
  598. return WidgetUtil.getTouchOrMouseClientX(event);
  599. }
  600. /**
  601. * Find the element corresponding to the coordinates in the passed mouse
  602. * event. Please note that this is not always the same as the target of the
  603. * event e.g. if event capture is used.
  604. *
  605. * @param event
  606. * the mouse event to get coordinates from
  607. * @return the element at the coordinates of the event
  608. */
  609. @Deprecated
  610. public static com.google.gwt.user.client.Element getElementUnderMouse(
  611. NativeEvent event) {
  612. return DOM.asOld(WidgetUtil.getElementUnderMouse(event));
  613. }
  614. /**
  615. * A helper method to return the client position from an event. Returns
  616. * position from either first changed touch (if touch event) or from the
  617. * event itself.
  618. *
  619. * @param event
  620. * @return
  621. */
  622. @Deprecated
  623. public static int getTouchOrMouseClientY(Event event) {
  624. return WidgetUtil.getTouchOrMouseClientY(event);
  625. }
  626. /**
  627. *
  628. * @see #getTouchOrMouseClientY(Event)
  629. * @param currentGwtEvent
  630. * @return
  631. */
  632. @Deprecated
  633. public static int getTouchOrMouseClientY(NativeEvent currentGwtEvent) {
  634. return WidgetUtil.getTouchOrMouseClientY(currentGwtEvent);
  635. }
  636. /**
  637. * @see #getTouchOrMouseClientX(Event)
  638. *
  639. * @param event
  640. * @return
  641. */
  642. @Deprecated
  643. public static int getTouchOrMouseClientX(NativeEvent event) {
  644. return WidgetUtil.getTouchOrMouseClientX(event);
  645. }
  646. @Deprecated
  647. public static boolean isTouchEvent(Event event) {
  648. return WidgetUtil.isTouchEvent(event);
  649. }
  650. @Deprecated
  651. public static boolean isTouchEvent(NativeEvent event) {
  652. return WidgetUtil.isTouchEvent(event);
  653. }
  654. @Deprecated
  655. public static void simulateClickFromTouchEvent(Event touchevent,
  656. Widget widget) {
  657. WidgetUtil.simulateClickFromTouchEvent(touchevent, widget);
  658. }
  659. /**
  660. * Gets the currently focused element.
  661. *
  662. * @return The active element or null if no active element could be found.
  663. */
  664. @Deprecated
  665. public static com.google.gwt.user.client.Element getFocusedElement() {
  666. return DOM.asOld(WidgetUtil.getFocusedElement());
  667. }
  668. /**
  669. * Gets the currently focused element for Internet Explorer.
  670. *
  671. * @return The currently focused element
  672. * @deprecated Use #getFocusedElement instead
  673. */
  674. @Deprecated
  675. public static com.google.gwt.user.client.Element getIEFocusedElement() {
  676. return getFocusedElement();
  677. }
  678. /**
  679. * Gets currently focused element and checks if it's editable
  680. *
  681. * @since 7.4
  682. *
  683. * @return true if focused element is editable
  684. */
  685. @Deprecated
  686. public static boolean isFocusedElementEditable() {
  687. return WidgetUtil.isFocusedElementEditable();
  688. }
  689. /**
  690. * Kind of stronger version of isAttached(). In addition to std isAttached,
  691. * this method checks that this widget nor any of its parents is hidden. Can
  692. * be e.g used to check whether component should react to some events or
  693. * not.
  694. *
  695. * @param widget
  696. * @return true if attached and displayed
  697. */
  698. @Deprecated
  699. public static boolean isAttachedAndDisplayed(Widget widget) {
  700. return WidgetUtil.isAttachedAndDisplayed(widget);
  701. }
  702. /**
  703. * Scrolls an element into view vertically only. Modified version of
  704. * Element.scrollIntoView.
  705. *
  706. * @param elem
  707. * The element to scroll into view
  708. */
  709. @Deprecated
  710. public static void scrollIntoViewVertically(Element elem) {
  711. WidgetUtil.scrollIntoViewVertically(elem);
  712. }
  713. /**
  714. * Checks if the given event is either a touch event or caused by the left
  715. * mouse button
  716. *
  717. * @param event
  718. * @return true if the event is a touch event or caused by the left mouse
  719. * button, false otherwise
  720. */
  721. @Deprecated
  722. public static boolean isTouchEventOrLeftMouseButton(Event event) {
  723. return WidgetUtil.isTouchEventOrLeftMouseButton(event);
  724. }
  725. /**
  726. * Performs a shallow comparison of the collections.
  727. *
  728. * @param collection1
  729. * The first collection
  730. * @param collection2
  731. * The second collection
  732. * @return true if the collections contain the same elements in the same
  733. * order, false otherwise
  734. */
  735. public static boolean collectionsEquals(Collection collection1,
  736. Collection collection2) {
  737. if (collection1 == null) {
  738. return collection2 == null;
  739. }
  740. if (collection2 == null) {
  741. return false;
  742. }
  743. Iterator<Object> collection1Iterator = collection1.iterator();
  744. Iterator<Object> collection2Iterator = collection2.iterator();
  745. while (collection1Iterator.hasNext()) {
  746. if (!collection2Iterator.hasNext()) {
  747. return false;
  748. }
  749. Object collection1Object = collection1Iterator.next();
  750. Object collection2Object = collection2Iterator.next();
  751. if (collection1Object != collection2Object) {
  752. return false;
  753. }
  754. }
  755. if (collection2Iterator.hasNext()) {
  756. return false;
  757. }
  758. return true;
  759. }
  760. public static String getConnectorString(ServerConnector p) {
  761. if (p == null) {
  762. return "null";
  763. }
  764. return getSimpleName(p) + " (" + p.getConnectorId() + ")";
  765. }
  766. /**
  767. * Resolve a relative URL to an absolute URL based on the current document's
  768. * location.
  769. *
  770. * @param url
  771. * a string with the relative URL to resolve
  772. * @return the corresponding absolute URL as a string
  773. */
  774. @Deprecated
  775. public static String getAbsoluteUrl(String url) {
  776. return WidgetUtil.getAbsoluteUrl(url);
  777. }
  778. /**
  779. * Sets the selection range of an input element.
  780. *
  781. * We need this JSNI function to set selection range so that we can use the
  782. * optional direction attribute to set the anchor to the end and the focus
  783. * to the start. This makes Firefox work the same way as other browsers
  784. * (#13477)
  785. *
  786. * @param elem
  787. * the html input element.
  788. * @param pos
  789. * the index of the first selected character.
  790. * @param length
  791. * the selection length.
  792. * @param direction
  793. * a string indicating the direction in which the selection was
  794. * performed. This may be "forward" or "backward", or "none" if
  795. * the direction is unknown or irrelevant.
  796. *
  797. * @since 7.3
  798. */
  799. @Deprecated
  800. public static void setSelectionRange(Element elem, int pos, int length,
  801. String direction) {
  802. WidgetUtil.setSelectionRange(elem, pos, length, direction);
  803. }
  804. }