123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278 |
- /*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
- package com.vaadin.client;
-
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Collection;
- import java.util.Iterator;
- import java.util.List;
- import java.util.logging.Level;
- import java.util.logging.Logger;
-
- import com.google.gwt.core.client.GWT;
- import com.google.gwt.core.client.JavaScriptObject;
- import com.google.gwt.dom.client.Element;
- import com.google.gwt.dom.client.NativeEvent;
- import com.google.gwt.event.dom.client.KeyEvent;
- import com.google.gwt.user.client.DOM;
- import com.google.gwt.user.client.Event;
- import com.google.gwt.user.client.ui.HasWidgets;
- import com.google.gwt.user.client.ui.Widget;
- import com.vaadin.client.HasChildMeasurementHintConnector.ChildMeasurementHint;
- import com.vaadin.client.RenderInformation.FloatSize;
- import com.vaadin.client.ui.AbstractLayoutConnector;
- import com.vaadin.client.ui.ManagedLayout;
- import com.vaadin.client.ui.VOverlay;
- import com.vaadin.client.ui.layout.ElementResizeListener;
- import com.vaadin.shared.AbstractComponentState;
- import com.vaadin.shared.ApplicationConstants;
- import com.vaadin.shared.communication.MethodInvocation;
- import com.vaadin.shared.ui.ComponentStateUtil;
- import com.vaadin.shared.util.SharedUtil;
-
- import elemental.js.json.JsJsonValue;
- import elemental.json.JsonValue;
-
- public class Util {
-
- /**
- * Helper method for debugging purposes.
- *
- * Stops execution on firefox browsers on a breakpoint.
- *
- * @deprecated As of 7.4.0, use {@link WidgetUtil#browserDebugger()}
- * instead.
- */
- @Deprecated
- public static void browserDebugger() {
- WidgetUtil.browserDebugger();
- }
-
- /**
- * Helper method for a bug fix #14041. For mozilla getKeyCode return 0 for
- * space bar (because space is considered as char). If return 0 use
- * getCharCode.
- *
- * @deprecated As of 7.4.0, use {@link WidgetUtil#getKeyCode(KeyEvent)}
- * instead.
- *
- * @param event
- * @return return key code
- * @since 7.2.4
- */
- @Deprecated
- public static int getKeyCode(KeyEvent<?> event) {
- return WidgetUtil.getKeyCode(event);
- }
-
- /**
- *
- * Returns the topmost element of from given coordinates.
- *
- * TODO fix crossplat issues clientX vs pageX. See quircksmode. Not critical
- * for vaadin as we scroll div istead of page.
- *
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#getElementFromPoint(int, int)} instead.
- *
- * @param x
- * @param y
- * @return the element at given coordinates
- */
- @Deprecated
- public static com.google.gwt.user.client.Element getElementFromPoint(
- int clientX, int clientY) {
- return DOM.asOld(WidgetUtil.getElementFromPoint(clientX, clientY));
- }
-
- /**
- * This helper method can be called if components size have been changed
- * outside rendering phase. It notifies components parent about the size
- * change so it can react.
- *
- * When using this method, developer should consider if size changes could
- * be notified lazily. If lazy flag is true, method will save widget and
- * wait for a moment until it notifies parents in chunks. This may vastly
- * optimize layout in various situation. Example: if component have a lot of
- * images their onload events may fire "layout phase" many times in a short
- * period.
- *
- * @param widget
- * @param lazy
- * run componentSizeUpdated lazyly
- *
- * @deprecated As of 7.0, use
- * {@link LayoutManager#setNeedsMeasure(ComponentConnector)}
- * instead
- */
- @Deprecated
- public static void notifyParentOfSizeChange(Widget widget, boolean lazy) {
- ComponentConnector connector = findConnectorFor(widget);
- if (connector != null) {
- connector.getLayoutManager().setNeedsMeasure(connector);
- if (!lazy) {
- connector.getLayoutManager().layoutNow();
- }
- }
- }
-
- public static ComponentConnector findConnectorFor(Widget widget) {
- List<ApplicationConnection> runningApplications = ApplicationConfiguration
- .getRunningApplications();
- for (ApplicationConnection applicationConnection : runningApplications) {
- ConnectorMap connectorMap = applicationConnection.getConnectorMap();
- ComponentConnector connector = connectorMap.getConnector(widget);
- if (connector == null) {
- continue;
- }
- if (connector.getConnection() == applicationConnection) {
- return connector;
- }
- }
-
- return null;
- }
-
- /**
- * @deprecated As of 7.4.0, use {@link WidgetUtil#parseRelativeSize(String)}
- * instead.
- */
- @Deprecated
- public static float parseRelativeSize(String size) {
- return WidgetUtil.parseRelativeSize(size);
- }
-
- /**
- * Converts html entities to text.
- *
- * @deprecated As of 7.4.0, use {@link WidgetUtil#escapeHTML(String)}
- * instead.
- *
- * @param html
- * @return escaped string presentation of given html
- */
- @Deprecated
- public static String escapeHTML(String html) {
- return WidgetUtil.escapeHTML(html);
- }
-
- /**
- * Escapes the string so it is safe to write inside an HTML attribute.
- *
- * @deprecated As of 7.4.0, use {@link WidgetUtil#escapeAttribute(String)}
- * instead.
- *
- * @param attribute
- * The string to escape
- * @return An escaped version of <literal>attribute</literal>.
- */
- @Deprecated
- public static String escapeAttribute(String attribute) {
- return WidgetUtil.escapeAttribute(attribute);
- }
-
- /**
- * Clones given element as in JavaScript.
- *
- * Deprecate this if there appears similar method into GWT someday.
- *
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#cloneNode(Element, boolean)} instead.
- *
- * @param element
- * @param deep
- * clone child tree also
- * @return
- */
- @Deprecated
- public static com.google.gwt.user.client.Element cloneNode(Element element,
- boolean deep) {
- return DOM.asOld(WidgetUtil.cloneNode(element, deep));
- }
-
- /**
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#measureHorizontalPaddingAndBorder(Element, int)}
- * instead.
- */
- @Deprecated
- public static int measureHorizontalPaddingAndBorder(Element element,
- int paddingGuess) {
- return WidgetUtil.measureHorizontalPaddingAndBorder(element,
- paddingGuess);
- }
-
- /**
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#measureVerticalPaddingAndBorder(Element, int)}
- * instead.
- */
- @Deprecated
- public static int measureVerticalPaddingAndBorder(Element element,
- int paddingGuess) {
- return WidgetUtil.measureVerticalPaddingAndBorder(element,
- paddingGuess);
- }
-
- /**
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#measureHorizontalBorder(Element)} instead.
- */
- @Deprecated
- public static int measureHorizontalBorder(Element element) {
- return WidgetUtil.measureHorizontalBorder(element);
- }
-
- /**
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#measureVerticalBorder(Element)} instead.
- */
- @Deprecated
- public static int measureVerticalBorder(Element element) {
- return WidgetUtil.measureVerticalBorder(element);
- }
-
- /**
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#measureMarginLeft(Element)} instead.
- */
- @Deprecated
- public static int measureMarginLeft(Element element) {
- return WidgetUtil.measureMarginLeft(element);
- }
-
- /**
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#setHeightExcludingPaddingAndBorder(Widget, String, int)}
- * instead.
- */
- @Deprecated
- public static int setHeightExcludingPaddingAndBorder(Widget widget,
- String height, int paddingBorderGuess) {
- return WidgetUtil.setHeightExcludingPaddingAndBorder(widget, height,
- paddingBorderGuess);
- }
-
- /**
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#setWidthExcludingPaddingAndBorder(Widget, String, int)}
- * instead.
- */
- @Deprecated
- public static int setWidthExcludingPaddingAndBorder(Widget widget,
- String width, int paddingBorderGuess) {
- return WidgetUtil.setWidthExcludingPaddingAndBorder(widget, width,
- paddingBorderGuess);
- }
-
- /**
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#setWidthExcludingPaddingAndBorder(Element, int, int, boolean)}
- * instead.
- */
- @Deprecated
- public static int setWidthExcludingPaddingAndBorder(Element element,
- int requestedWidth, int horizontalPaddingBorderGuess,
- boolean requestedWidthIncludesPaddingBorder) {
- return WidgetUtil.setWidthExcludingPaddingAndBorder(element,
- requestedWidth, horizontalPaddingBorderGuess,
- requestedWidthIncludesPaddingBorder);
- }
-
- /**
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#setHeightExcludingPaddingAndBorder(Element, int, int, boolean)}
- * instead.
- */
- @Deprecated
- public static int setHeightExcludingPaddingAndBorder(Element element,
- int requestedHeight, int verticalPaddingBorderGuess,
- boolean requestedHeightIncludesPaddingBorder) {
- return WidgetUtil.setHeightExcludingPaddingAndBorder(element,
- requestedHeight, verticalPaddingBorderGuess,
- requestedHeightIncludesPaddingBorder);
- }
-
- /**
- * @deprecated As of 7.4, use {@link Class#getSimpleName()} instead.
- */
- @Deprecated
- public static String getSimpleName(Object widget) {
- if (widget == null) {
- return "(null)";
- }
-
- String name = widget.getClass().getName();
- return name.substring(name.lastIndexOf('.') + 1);
- }
-
- /**
- * @deprecated As of 7.4.0, use {@link WidgetUtil#setFloat(Element, String)}
- * instead.
- */
- @Deprecated
- public static void setFloat(Element element, String value) {
- WidgetUtil.setFloat(element, value);
- }
-
- /**
- * @deprecated As of 7.4.0, use {@link WidgetUtil#getNativeScrollbarSize()}
- * instead.
- */
- @Deprecated
- public static int getNativeScrollbarSize() {
- return WidgetUtil.getNativeScrollbarSize();
- }
-
- /**
- * Defers the execution of {@link #runWebkitOverflowAutoFix(Element)}
- *
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#runWebkitOverflowAutoFixDeferred(Element)}
- * instead.
- *
- * @since 7.2.6
- * @param elem
- * with overflow auto
- */
- @Deprecated
- public static void runWebkitOverflowAutoFixDeferred(final Element elem) {
- WidgetUtil.runWebkitOverflowAutoFixDeferred(elem);
- }
-
- /**
- * Run workaround for webkits overflow auto issue.
- *
- * See: our bug #2138 and https://bugs.webkit.org/show_bug.cgi?id=21462
- *
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#runWebkitOverflowAutoFix(Element)} instead.
- *
- * @param elem
- * with overflow auto
- */
- @Deprecated
- public static void runWebkitOverflowAutoFix(final Element elem) {
- WidgetUtil.runWebkitOverflowAutoFix(elem);
- }
-
- /**
- * Parses shared state and fetches the relative size of the component. If a
- * dimension is not specified as relative it will return -1. If the shared
- * state does not contain width or height specifications this will return
- * null.
- *
- * @param state
- * @return
- */
- public static FloatSize parseRelativeSize(AbstractComponentState state) {
- if (ComponentStateUtil.isUndefinedHeight(state)
- && ComponentStateUtil.isUndefinedWidth(state)) {
- return null;
- }
-
- float relativeWidth = WidgetUtil.parseRelativeSize(state.width);
- float relativeHeight = WidgetUtil.parseRelativeSize(state.height);
-
- FloatSize relativeSize = new FloatSize(relativeWidth, relativeHeight);
- return relativeSize;
-
- }
-
- @Deprecated
- public static boolean isCached(UIDL uidl) {
- return uidl.getBooleanAttribute("cached");
- }
-
- /**
- * @deprecated As of 7.4.0, use {@link WidgetUtil#alert(String)} instead.
- */
- @Deprecated
- public static void alert(String string) {
- WidgetUtil.alert(string);
- }
-
- /**
- * Checks if a and b are equals using {@link #equals(Object)}. Handles null
- * values as well. Does not ensure that objects are of the same type.
- * Assumes that the first object's equals method handle equals properly.
- *
- * @param a
- * The first value to compare
- * @param b
- * The second value to compare
- * @return
- * @deprecated As of 7.1 use {@link SharedUtil#equals(Object)} instead
- */
- @Deprecated
- public static boolean equals(Object a, Object b) {
- return SharedUtil.equals(a, b);
- }
-
- public static void updateRelativeChildrenAndSendSizeUpdateEvent(
- ApplicationConnection client, HasWidgets container, Widget widget) {
- notifyParentOfSizeChange(widget, false);
- }
-
- /**
- * Gets the border-box width for the given element, i.e. element width +
- * border + padding. Always rounds up to nearest integer.
- *
- * @deprecated As of 7.4.0, use {@link WidgetUtil#getRequiredWidth(Element)}
- * instead.
- *
- * @param element
- * The element to check
- * @return The border-box width for the element
- */
- @Deprecated
- public static int getRequiredWidth(
- com.google.gwt.dom.client.Element element) {
- return WidgetUtil.getRequiredWidth(element);
- }
-
- /**
- * Gets the border-box height for the given element, i.e. element height +
- * border + padding. Always rounds up to nearest integer.
- *
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#getRequiredHeight(Element)} instead.
- *
- * @param element
- * The element to check
- * @return The border-box height for the element
- */
- @Deprecated
- public static int getRequiredHeight(
- com.google.gwt.dom.client.Element element) {
- return WidgetUtil.getRequiredHeight(element);
- }
-
- /**
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#getRequiredWidthBoundingClientRect(Element)}
- * instead.
- */
- @Deprecated
- public int getRequiredWidthBoundingClientRect(
- com.google.gwt.dom.client.Element element) {
- return WidgetUtil.getRequiredWidthBoundingClientRect(element);
- }
-
- /**
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#getRequiredHeightComputedStyle(Element)}
- * instead.
- */
- @Deprecated
- public static int getRequiredHeightComputedStyle(
- com.google.gwt.dom.client.Element element) {
- return WidgetUtil.getRequiredHeightComputedStyle(element);
- }
-
- /**
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#getRequiredWidthComputedStyle(Element)}
- * instead.
- */
- @Deprecated
- public static int getRequiredWidthComputedStyle(
- com.google.gwt.dom.client.Element element) {
- return WidgetUtil.getRequiredWidthComputedStyle(element);
- }
-
- /**
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#getRequiredHeightBoundingClientRect(Element)}
- * instead.
- */
- @Deprecated
- public static int getRequiredHeightBoundingClientRect(
- com.google.gwt.dom.client.Element element) {
- return WidgetUtil.getRequiredHeightBoundingClientRect(element);
- }
-
- /**
- * @deprecated As of 7.4.0, use {@link WidgetUtil#getRequiredWidth(Widget)}
- * instead.
- */
- @Deprecated
- public static int getRequiredWidth(Widget widget) {
- return WidgetUtil.getRequiredWidth(widget);
- }
-
- /**
- * @deprecated As of 7.4.0, use {@link WidgetUtil#getRequiredHeight(Widget)}
- * instead.
- */
- @Deprecated
- public static int getRequiredHeight(Widget widget) {
- return WidgetUtil.getRequiredHeight(widget);
- }
-
- /**
- * Detects what is currently the overflow style attribute in given element.
- *
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#mayHaveScrollBars(Element)} instead.
- *
- * @param pe
- * the element to detect
- * @return true if auto or scroll
- */
- @Deprecated
- public static boolean mayHaveScrollBars(
- com.google.gwt.dom.client.Element pe) {
- return WidgetUtil.mayHaveScrollBars(pe);
- }
-
- /**
- * Locates the nested child component of <literal>parent</literal> which
- * contains the element <literal>element</literal>. The child component is
- * also returned if "element" is part of its caption. If
- * <literal>element</literal> is not part of any child component, null is
- * returned.
- *
- * This method returns the deepest nested VPaintableWidget.
- *
- * @param client
- * A reference to ApplicationConnection
- * @param parent
- * The widget that contains <literal>element</literal>.
- * @param element
- * An element that is a sub element of the parent
- * @return The VPaintableWidget which the element is a part of. Null if the
- * element does not belong to a child.
- */
- public static ComponentConnector getConnectorForElement(
- ApplicationConnection client, Widget parent, Element element) {
-
- Element browseElement = element;
- Element rootElement = parent.getElement();
-
- while (browseElement != null && browseElement != rootElement) {
-
- ComponentConnector connector = ConnectorMap.get(client)
- .getConnector(browseElement);
-
- if (connector == null) {
- String ownerPid = VCaption.getCaptionOwnerPid(browseElement);
- if (ownerPid != null) {
- connector = (ComponentConnector) ConnectorMap.get(client)
- .getConnector(ownerPid);
- }
- }
-
- if (connector != null) {
- // check that inside the rootElement
- while (browseElement != null && browseElement != rootElement) {
- browseElement = browseElement.getParentElement();
- }
- if (browseElement != rootElement) {
- return null;
- } else {
- return connector;
- }
- }
-
- browseElement = browseElement.getParentElement();
- }
-
- // No connector found, element is possibly inside a VOverlay
- // If the overlay has an owner, try to find the owner's connector
- VOverlay overlay = findWidget(element, VOverlay.class);
- if (overlay != null && overlay.getOwner() != null) {
-
- return getConnectorForElement(client,
- client.getUIConnector().getWidget(),
- overlay.getOwner().getElement());
- } else {
- return null;
- }
- }
-
- /**
- * Will (attempt) to focus the given DOM Element.
- *
- * @deprecated As of 7.4.0, use {@link WidgetUtil#focus(Element)} instead.
- *
- * @param el
- * the element to focus
- */
- @Deprecated
- public static void focus(Element el) {
- WidgetUtil.focus(el);
- }
-
- /**
- * Helper method to find the nearest parent paintable instance by traversing
- * the DOM upwards from given element.
- *
- * @param element
- * the element to start from
- */
- public static ComponentConnector findPaintable(ApplicationConnection client,
- Element element) {
- Widget widget = Util.findWidget(element, null);
- ConnectorMap vPaintableMap = ConnectorMap.get(client);
- while (widget != null && !vPaintableMap.isConnector(widget)) {
- widget = widget.getParent();
- }
- return vPaintableMap.getConnector(widget);
-
- }
-
- /**
- * Helper method to find first instance of given Widget type found by
- * traversing DOM upwards from given element.
- *
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#findWidget(Element, Class)} instead.
- *
- * @param element
- * the element where to start seeking of Widget
- * @param class1
- * the Widget type to seek for
- */
- @Deprecated
- public static <T> T findWidget(Element element,
- Class<? extends Widget> class1) {
- return WidgetUtil.findWidget(element, class1);
- }
-
- /**
- * Force webkit to redraw an element
- *
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#forceWebkitRedraw(Element)} instead.
- *
- * @param element
- * The element that should be redrawn
- */
- @Deprecated
- public static void forceWebkitRedraw(Element element) {
- WidgetUtil.forceWebkitRedraw(element);
- }
-
- /**
- * Performs a hack to trigger a re-layout in the IE8. This is usually
- * necessary in cases where IE8 "forgets" to update child elements when they
- * resize.
- *
- * @deprecated As of 7.4.0, use {@link WidgetUtil#forceIE8Redraw(Element)}
- * instead.
- *
- * @param e
- * The element to perform the hack on
- */
- @Deprecated
- public static final void forceIE8Redraw(Element e) {
- WidgetUtil.forceIE8Redraw(e);
- }
-
- /**
- * Performs a hack to trigger a re-layout in the IE browser. This is usually
- * necessary in cases where IE "forgets" to update child elements when they
- * resize.
- *
- * @deprecated As of 7.4.0, use {@link WidgetUtil#forceIERedraw(Element)}
- * instead.
- *
- * @since 7.3
- * @param e
- * The element to perform the hack on
- */
- @Deprecated
- public static void forceIERedraw(Element e) {
- WidgetUtil.forceIERedraw(e);
- }
-
- /**
- * Detaches and re-attaches the element from its parent. The element is
- * reattached at the same position in the DOM as it was before.
- *
- * Does nothing if the element is not attached to the DOM.
- *
- * @deprecated As of 7.4.0, use {@link WidgetUtil#detachAttach(Element)}
- * instead.
- *
- * @param element
- * The element to detach and re-attach
- */
- @Deprecated
- public static void detachAttach(Element element) {
- WidgetUtil.detachAttach(element);
- }
-
- /**
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#sinkOnloadForImages(Element)} instead.
- */
- @Deprecated
- public static void sinkOnloadForImages(Element element) {
- WidgetUtil.sinkOnloadForImages(element);
- }
-
- /**
- * Returns the index of the childElement within its parent.
- *
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#getChildElementIndex(Element)} instead.
- *
- * @param subElement
- * @return
- */
- @Deprecated
- public static int getChildElementIndex(Element childElement) {
- return WidgetUtil.getChildElementIndex(childElement);
- }
-
- private static void printConnectorInvocations(
- ArrayList<MethodInvocation> invocations, String id,
- ApplicationConnection c) {
- ServerConnector connector = ConnectorMap.get(c).getConnector(id);
- if (connector != null) {
- getLogger().info("\t" + id + " (" + connector.getClass() + ") :");
- } else {
- getLogger().warning("\t" + id
- + ": Warning: no corresponding connector for id " + id);
- }
- for (MethodInvocation invocation : invocations) {
- getLogger().info("\t\t" + getInvocationDebugString(invocation));
- }
- }
-
- /**
- * Produces a string representation of a method invocation, suitable for
- * debug output
- *
- * @since 7.5
- * @param invocation
- * @return
- */
- private static String getInvocationDebugString(
- MethodInvocation invocation) {
- Object[] parameters = invocation.getParameters();
- String formattedParams = null;
- if (ApplicationConstants.UPDATE_VARIABLE_METHOD
- .equals(invocation.getMethodName()) && parameters.length == 2) {
- // name, value
- Object value = parameters[1];
- // TODO paintables inside lists/maps get rendered as
- // components in the debug console
- String formattedValue = value instanceof ServerConnector
- ? ((ServerConnector) value).getConnectorId()
- : String.valueOf(value);
- formattedParams = parameters[0] + " : " + formattedValue;
- }
- if (null == formattedParams) {
- formattedParams = (null != parameters) ? Arrays.toString(parameters)
- : null;
- }
- return invocation.getInterfaceName() + "." + invocation.getMethodName()
- + "(" + formattedParams + ")";
- }
-
- public static void logMethodInvocations(ApplicationConnection c,
- Collection<MethodInvocation> methodInvocations) {
- try {
- getLogger().info("RPC invocations to be sent to the server:");
- String curId = null;
- ArrayList<MethodInvocation> invocations = new ArrayList<MethodInvocation>();
- for (MethodInvocation methodInvocation : methodInvocations) {
- String id = methodInvocation.getConnectorId();
-
- if (curId == null) {
- curId = id;
- } else if (!curId.equals(id)) {
- printConnectorInvocations(invocations, curId, c);
- invocations.clear();
- curId = id;
- }
- invocations.add(methodInvocation);
- }
- if (!invocations.isEmpty()) {
- printConnectorInvocations(invocations, curId, c);
- }
- } catch (Exception e) {
- getLogger().log(Level.SEVERE, "Error logging method invocations",
- e);
- }
- }
-
- /**
- * Temporarily sets the {@code styleProperty} to {@code tempValue} and then
- * resets it to its current value. Used mainly to work around rendering
- * issues in IE (and possibly in other browsers)
- *
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#setStyleTemporarily(Element, String, String)}
- * instead.
- *
- * @param element
- * The target element
- * @param styleProperty
- * The name of the property to set
- * @param tempValue
- * The temporary value
- */
- @Deprecated
- public static void setStyleTemporarily(Element element,
- final String styleProperty, String tempValue) {
- WidgetUtil.setStyleTemporarily(element, styleProperty, tempValue);
- }
-
- /**
- * A helper method to return the client position from an event. Returns
- * position from either first changed touch (if touch event) or from the
- * event itself.
- *
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#getTouchOrMouseClientX(Event)} instead.
- *
- * @param event
- * @return
- */
- @Deprecated
- public static int getTouchOrMouseClientX(Event event) {
- return WidgetUtil.getTouchOrMouseClientX(event);
- }
-
- /**
- * Find the element corresponding to the coordinates in the passed mouse
- * event. Please note that this is not always the same as the target of the
- * event e.g. if event capture is used.
- *
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#getElementUnderMouse(NativeEvent)} instead.
- *
- * @param event
- * the mouse event to get coordinates from
- * @return the element at the coordinates of the event
- */
- @Deprecated
- public static com.google.gwt.user.client.Element getElementUnderMouse(
- NativeEvent event) {
- return DOM.asOld(WidgetUtil.getElementUnderMouse(event));
- }
-
- /**
- * A helper method to return the client position from an event. Returns
- * position from either first changed touch (if touch event) or from the
- * event itself.
- *
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#getTouchOrMouseClientY(Event)} instead.
- *
- * @param event
- * @return
- */
- @Deprecated
- public static int getTouchOrMouseClientY(Event event) {
- return WidgetUtil.getTouchOrMouseClientY(event);
- }
-
- /**
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#getTouchOrMouseClientY(NativeEvent)}
- * instead.
- *
- * @see #getTouchOrMouseClientY(Event)
- * @param currentGwtEvent
- * @return
- */
- @Deprecated
- public static int getTouchOrMouseClientY(NativeEvent currentGwtEvent) {
- return WidgetUtil.getTouchOrMouseClientY(currentGwtEvent);
- }
-
- /**
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#getTouchOrMouseClientX(NativeEvent)}
- * instead.
- *
- * @see #getTouchOrMouseClientX(Event)
- *
- * @param event
- * @return
- */
- @Deprecated
- public static int getTouchOrMouseClientX(NativeEvent event) {
- return WidgetUtil.getTouchOrMouseClientX(event);
- }
-
- /**
- * @deprecated As of 7.4.0, use {@link WidgetUtil#isTouchEvent(Event)}
- * instead.
- */
- @Deprecated
- public static boolean isTouchEvent(Event event) {
- return WidgetUtil.isTouchEvent(event);
- }
-
- /**
- * @deprecated As of 7.4.0, use {@link WidgetUtil#isTouchEvent(NativeEvent)}
- * instead.
- */
- @Deprecated
- public static boolean isTouchEvent(NativeEvent event) {
- return WidgetUtil.isTouchEvent(event);
- }
-
- /**
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#simulateClickFromTouchEvent(Event, Widget)}
- * instead.
- */
- @Deprecated
- public static void simulateClickFromTouchEvent(Event touchevent,
- Widget widget) {
- WidgetUtil.simulateClickFromTouchEvent(touchevent, widget);
- }
-
- /**
- * Gets the currently focused element.
- *
- * @deprecated As of 7.4.0, use {@link WidgetUtil#getFocusedElement()}
- * instead.
- *
- * @return The active element or null if no active element could be found.
- */
- @Deprecated
- public static com.google.gwt.user.client.Element getFocusedElement() {
- return DOM.asOld(WidgetUtil.getFocusedElement());
- }
-
- /**
- * Gets the currently focused element for Internet Explorer.
- *
- * @return The currently focused element
- * @deprecated Use #getFocusedElement instead
- */
- @Deprecated
- public static com.google.gwt.user.client.Element getIEFocusedElement() {
- return getFocusedElement();
- }
-
- /**
- * Gets currently focused element and checks if it's editable
- *
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#isFocusedElementEditable()} instead.
- *
- * @since 7.4
- *
- * @return true if focused element is editable
- */
- @Deprecated
- public static boolean isFocusedElementEditable() {
- return WidgetUtil.isFocusedElementEditable();
- }
-
- /**
- * Kind of stronger version of isAttached(). In addition to std isAttached,
- * this method checks that this widget nor any of its parents is hidden. Can
- * be e.g used to check whether component should react to some events or
- * not.
- *
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#isAttachedAndDisplayed(Widget)} instead.
- *
- * @param widget
- * @return true if attached and displayed
- */
- @Deprecated
- public static boolean isAttachedAndDisplayed(Widget widget) {
- return WidgetUtil.isAttachedAndDisplayed(widget);
- }
-
- /**
- * Scrolls an element into view vertically only. Modified version of
- * Element.scrollIntoView.
- *
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#scrollIntoViewVertically(Element)} instead.
- *
- * @param elem
- * The element to scroll into view
- */
- @Deprecated
- public static void scrollIntoViewVertically(Element elem) {
- WidgetUtil.scrollIntoViewVertically(elem);
- }
-
- /**
- * Checks if the given event is either a touch event or caused by the left
- * mouse button
- *
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#isTouchEventOrLeftMouseButton(Event)}
- * instead.
- *
- * @param event
- * @return true if the event is a touch event or caused by the left mouse
- * button, false otherwise
- */
- @Deprecated
- public static boolean isTouchEventOrLeftMouseButton(Event event) {
- return WidgetUtil.isTouchEventOrLeftMouseButton(event);
- }
-
- /**
- * Performs a shallow comparison of the collections.
- *
- * @param collection1
- * The first collection
- * @param collection2
- * The second collection
- * @return true if the collections contain the same elements in the same
- * order, false otherwise
- */
- public static boolean collectionsEquals(Collection<?> collection1,
- Collection<?> collection2) {
- if (collection1 == null) {
- return collection2 == null;
- }
- if (collection2 == null) {
- return false;
- }
-
- if (collection1.size() != collection2.size()) {
- return false;
- }
-
- Iterator<?> collection1Iterator = collection1.iterator();
- Iterator<?> collection2Iterator = collection2.iterator();
-
- while (collection1Iterator.hasNext()) {
- Object collection1Object = collection1Iterator.next();
- Object collection2Object = collection2Iterator.next();
- if (collection1Object != collection2Object) {
- return false;
- }
- }
-
- return true;
- }
-
- public static String getConnectorString(ServerConnector p) {
- if (p == null) {
- return "null";
- }
- return getSimpleName(p) + " (" + p.getConnectorId() + ")";
- }
-
- /**
- * Resolve a relative URL to an absolute URL based on the current document's
- * location.
- *
- * @deprecated As of 7.4.0, use {@link WidgetUtil#getAbsoluteUrl(String)}
- * instead.
- *
- * @param url
- * a string with the relative URL to resolve
- * @return the corresponding absolute URL as a string
- */
- @Deprecated
- public static String getAbsoluteUrl(String url) {
- return WidgetUtil.getAbsoluteUrl(url);
- }
-
- /**
- * Sets the selection range of an input element.
- *
- * We need this JSNI function to set selection range so that we can use the
- * optional direction attribute to set the anchor to the end and the focus
- * to the start. This makes Firefox work the same way as other browsers
- * (#13477)
- *
- * @deprecated As of 7.4.0, use
- * {@link WidgetUtil#setSelectionRange(Element, int, int, String)}
- * instead.
- *
- * @param elem
- * the html input element.
- * @param pos
- * the index of the first selected character.
- * @param length
- * the selection length.
- * @param direction
- * a string indicating the direction in which the selection was
- * performed. This may be "forward" or "backward", or "none" if
- * the direction is unknown or irrelevant.
- *
- * @since 7.3
- */
- @Deprecated
- public static void setSelectionRange(Element elem, int pos, int length,
- String direction) {
- WidgetUtil.setSelectionRange(elem, pos, length, direction);
- }
-
- /**
- * Converts a native {@link JavaScriptObject} into a {@link JsonValue}. This
- * is a no-op in GWT code compiled to javascript, but needs some special
- * handling to work when run in JVM.
- *
- * @param jso
- * the java script object to represent as json
- * @return the json representation
- */
- public static <T extends JsonValue> T jso2json(JavaScriptObject jso) {
- if (GWT.isProdMode()) {
- return (T) jso.<JsJsonValue> cast();
- } else {
- return elemental.json.Json.instance().parse(stringify(jso));
- }
- }
-
- /**
- * Converts a {@link JsonValue} into a native {@link JavaScriptObject}. This
- * is a no-op in GWT code compiled to javascript, but needs some special
- * handling to work when run in JVM.
- *
- * @param jsonValue
- * the json value
- * @return a native javascript object representation of the json value
- */
- public static JavaScriptObject json2jso(JsonValue jsonValue) {
- if (GWT.isProdMode()) {
- return ((JavaScriptObject) jsonValue.toNative()).cast();
- } else {
- return parse(jsonValue.toJson());
- }
- }
-
- /**
- * Convert a {@link JavaScriptObject} into a string representation.
- *
- * @param json
- * a JavaScript object to be converted to a string
- * @return JSON in string representation
- */
- private native static String stringify(JavaScriptObject json)
- /*-{
- return JSON.stringify(json);
- }-*/;
-
- /**
- * Parse a string containing JSON into a {@link JavaScriptObject}.
- *
- * @param <T>
- * the overlay type to expect from the parse
- * @param jsonAsString
- * @return a JavaScript object constructed from the parse
- */
- public native static <T extends JavaScriptObject> T parse(
- String jsonAsString)
- /*-{
- return JSON.parse(jsonAsString);
- }-*/;
-
- /**
- * Round {@code num} up to {@code exp} decimal positions.
- *
- * @since 7.6
- */
- public static native double round(double num, int exp)
- /*-{
- return +(Math.round(num + "e+" + exp) + "e-" + exp);
- }-*/;
-
- /**
- * Test if we can can skip measuring this connector. We can skip the
- * measurement if its parent is a ChildMeasureHintConnector and has an
- * appropriate mode set.
- *
- * For internal use only. May be removed or replaced in the future.
- */
- public static boolean shouldSkipMeasurementOfConnector(
- ComponentConnector candidate, ComponentConnector parent) {
- Profiler.enter("skipMeasureDueLayoutHint");
- boolean skip = false;
-
- if (parent instanceof HasChildMeasurementHintConnector) {
- ChildMeasurementHint measureMode = ((HasChildMeasurementHintConnector) parent)
- .getChildMeasurementHint();
-
- if (measureMode == ChildMeasurementHint.MEASURE_NEVER) {
- skip = true;
- } else if (measureMode == ChildMeasurementHint.MEASURE_IF_NEEDED) {
- skip = canWeSkipChildMeasurement(candidate);
- }
- }
- Profiler.leave("skipMeasureDueLayoutHint");
- return skip;
- }
-
- /**
- * Test if we can can skip measuring this connector. We can skip the
- * measurement if its parent is a ChildMeasureHintConnector and has an
- * appropriate mode set.
- *
- * This version of the method tries to recursively locate such a parent.
- *
- * For internal use only. May be removed or replaced in the future.
- */
- public static boolean shouldSkipMeasurementOfConnector(
- ComponentConnector candidate) {
- Profiler.enter("skipMeasureDueLayoutHint");
- boolean skip = false;
-
- HasChildMeasurementHintConnector parent = getPossibleChildMeasurementHintParentConnector(
- candidate);
-
- if (parent != null) {
- ChildMeasurementHint measureMode = parent.getChildMeasurementHint();
-
- if (measureMode == ChildMeasurementHint.MEASURE_NEVER) {
- skip = true;
- } else if (measureMode == ChildMeasurementHint.MEASURE_IF_NEEDED) {
- skip = canWeSkipChildMeasurement(candidate);
- }
- }
- Profiler.leave("skipMeasureDueLayoutHint");
- return skip;
- }
-
- /** For internal use only. May be removed or replaced in the future. */
- private static boolean canWeSkipChildMeasurement(ComponentConnector child) {
- // common cases when child measuring is possibly needed
- if (child instanceof ElementResizeListener
- || child instanceof ManagedLayout
- || child instanceof AbstractLayoutConnector) {
- return false;
- }
- return true;
- }
-
- /** For internal use only. May be removed or replaced in the future. */
- private static HasChildMeasurementHintConnector getPossibleChildMeasurementHintParentConnector(
- ComponentConnector candidate) {
- ServerConnector parent = candidate.getParent();
- if (parent != null
- && parent instanceof HasChildMeasurementHintConnector) {
- return (HasChildMeasurementHintConnector) parent;
- }
- return null;
- }
-
- private static Logger getLogger() {
- return Logger.getLogger(Util.class.getName());
- }
- }
|