diff options
author | Artur Signell <artur@vaadin.com> | 2015-01-09 14:34:45 +0200 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2015-01-09 19:10:58 +0200 |
commit | bf8836bb561e834b8a58bc5075b2d1732217a5d6 (patch) | |
tree | 92484f06760e1f5994099c6df23076c6d4870009 | |
parent | 79a9182ab0e2711b75c7ac0d07c740c036d12097 (diff) | |
download | vaadin-framework-bf8836bb561e834b8a58bc5075b2d1732217a5d6.tar.gz vaadin-framework-bf8836bb561e834b8a58bc5075b2d1732217a5d6.zip |
Separate pure client side util methods to a new class (#15553, #15544)
* Deprecated old methods in Util for backwards compatibility
Change-Id: I9de5e6b930d9f2c0268967dc7b1cf465e6310280
86 files changed, 2106 insertions, 1444 deletions
diff --git a/client/src/com/vaadin/client/ApplicationConfiguration.java b/client/src/com/vaadin/client/ApplicationConfiguration.java index 0ef37df130..d3be69443e 100644 --- a/client/src/com/vaadin/client/ApplicationConfiguration.java +++ b/client/src/com/vaadin/client/ApplicationConfiguration.java @@ -411,14 +411,14 @@ public class ApplicationConfiguration implements EntryPoint { * desired locations even if the base URL of the page changes later * (e.g. with pushState) */ - serviceUrl = Util.getAbsoluteUrl(serviceUrl); + serviceUrl = WidgetUtil.getAbsoluteUrl(serviceUrl); } // Ensure there's an ending slash (to make appending e.g. UIDL work) if (!useServiceUrlPathParam() && !serviceUrl.endsWith("/")) { serviceUrl += '/'; } - vaadinDirUrl = Util.getAbsoluteUrl(jsoConfiguration + vaadinDirUrl = WidgetUtil.getAbsoluteUrl(jsoConfiguration .getConfigString(ApplicationConstants.VAADIN_DIR_URL)); uiId = jsoConfiguration.getConfigInteger(UIConstants.UI_ID_PARAMETER) .intValue(); diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java index 3b8b7ddc40..cf47b7d3a6 100644 --- a/client/src/com/vaadin/client/ApplicationConnection.java +++ b/client/src/com/vaadin/client/ApplicationConnection.java @@ -62,6 +62,7 @@ import com.google.gwt.user.client.Window.ClosingHandler; import com.google.gwt.user.client.ui.HasWidgets; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ApplicationConfiguration.ErrorMessage; +import com.vaadin.client.ApplicationConnection.ApplicationStoppedEvent; import com.vaadin.client.ResourceLoader.ResourceLoadEvent; import com.vaadin.client.ResourceLoader.ResourceLoadListener; import com.vaadin.client.communication.HasJavaScriptConnectorHelper; @@ -1865,7 +1866,7 @@ public class ApplicationConnection implements HasHandlers { } catch (NoDataException e) { throw new RuntimeException( "Missing data needed to invoke @DelegateToWidget for " - + Util.getSimpleName(component), e); + + WidgetUtil.getSimpleName(component), e); } } @@ -2046,7 +2047,8 @@ public class ApplicationConnection implements HasHandlers { String key = null; if (Profiler.isEnabled()) { key = "updateFromUIDL for " - + Util.getSimpleName(legacyConnector); + + WidgetUtil + .getSimpleName(legacyConnector); Profiler.enter(key); } @@ -2146,12 +2148,12 @@ public class ApplicationConnection implements HasHandlers { Profiler.enter("updateConnectorState inner loop"); if (Profiler.isEnabled()) { Profiler.enter("Decode connector state " - + Util.getSimpleName(connector)); + + WidgetUtil.getSimpleName(connector)); } JavaScriptObject jso = states .getJavaScriptObject(connectorId); - JsonObject stateJson = Util.jso2json(jso); + JsonObject stateJson = WidgetUtil.jso2json(jso); if (connector instanceof HasJavaScriptConnectorHelper) { ((HasJavaScriptConnectorHelper) connector) @@ -2183,7 +2185,7 @@ public class ApplicationConnection implements HasHandlers { if (Profiler.isEnabled()) { Profiler.leave("Decode connector state " - + Util.getSimpleName(connector)); + + WidgetUtil.getSimpleName(connector)); } Profiler.enter("updateConnectorState create event"); @@ -2523,7 +2525,7 @@ public class ApplicationConnection implements HasHandlers { VConsole.log(" * Performing server to client RPC calls"); - JsonArray rpcCalls = Util.jso2json(json + JsonArray rpcCalls = WidgetUtil.jso2json(json .getJavaScriptObject("rpc")); int rpcLength = rpcCalls.length(); @@ -3648,7 +3650,7 @@ public class ApplicationConnection implements HasHandlers { * @return Connector for focused element or null. */ private ComponentConnector getActiveConnector() { - Element focusedElement = Util.getFocusedElement(); + Element focusedElement = WidgetUtil.getFocusedElement(); if (focusedElement == null) { return null; } diff --git a/client/src/com/vaadin/client/BrowserInfo.java b/client/src/com/vaadin/client/BrowserInfo.java index e8b8d8309a..5ca79cb121 100644 --- a/client/src/com/vaadin/client/BrowserInfo.java +++ b/client/src/com/vaadin/client/BrowserInfo.java @@ -343,7 +343,7 @@ public class BrowserInfo { public boolean requiresOverflowAutoFix() { return (getWebkitVersion() > 0 || getOperaVersion() >= 11 || getIEVersion() >= 10 || isFirefox()) - && Util.getNativeScrollbarSize() > 0; + && WidgetUtil.getNativeScrollbarSize() > 0; } /** @@ -359,7 +359,8 @@ public class BrowserInfo { * otherwise <code>false</code> */ public boolean requiresPositionAbsoluteOverflowAutoFix() { - return (getWebkitVersion() > 0) && Util.getNativeScrollbarSize() > 0; + return (getWebkitVersion() > 0) + && WidgetUtil.getNativeScrollbarSize() > 0; } /** diff --git a/client/src/com/vaadin/client/JavaScriptConnectorHelper.java b/client/src/com/vaadin/client/JavaScriptConnectorHelper.java index 11511f9c36..524e1ee9aa 100644 --- a/client/src/com/vaadin/client/JavaScriptConnectorHelper.java +++ b/client/src/com/vaadin/client/JavaScriptConnectorHelper.java @@ -319,7 +319,7 @@ public class JavaScriptConnectorHelper { iface = findWildcardInterface(method); } - JsonArray argumentsArray = Util.jso2json(arguments); + JsonArray argumentsArray = WidgetUtil.jso2json(arguments); Object[] parameters = new Object[arguments.length()]; for (int i = 0; i < parameters.length; i++) { parameters[i] = argumentsArray.get(i); @@ -383,7 +383,7 @@ public class JavaScriptConnectorHelper { }-*/; public Object[] decodeRpcParameters(JsonArray parametersJson) { - return new Object[] { Util.json2jso(parametersJson) }; + return new Object[] { WidgetUtil.json2jso(parametersJson) }; } public void setTag(int tag) { @@ -397,10 +397,11 @@ public class JavaScriptConnectorHelper { if ("com.vaadin.ui.JavaScript$JavaScriptCallbackRpc".equals(iface) && "call".equals(method)) { String callbackName = parametersJson.getString(0); - JavaScriptObject arguments = Util.json2jso(parametersJson.get(1)); + JavaScriptObject arguments = WidgetUtil.json2jso(parametersJson + .get(1)); invokeCallback(getConnectorWrapper(), callbackName, arguments); } else { - JavaScriptObject arguments = Util.json2jso(parametersJson); + JavaScriptObject arguments = WidgetUtil.json2jso(parametersJson); invokeJsRpc(rpcMap, iface, method, arguments); // Also invoke wildcard interface invokeJsRpc(rpcMap, "", method, arguments); diff --git a/client/src/com/vaadin/client/LayoutManager.java b/client/src/com/vaadin/client/LayoutManager.java index 2f39eaedd4..4a2b34a539 100644 --- a/client/src/com/vaadin/client/LayoutManager.java +++ b/client/src/com/vaadin/client/LayoutManager.java @@ -346,7 +346,8 @@ public class LayoutManager { if (Profiler.isEnabled()) { Profiler.enter("ElementResizeListener.onElementResize construct profiler key"); key = "ElementResizeListener.onElementResize for " - + Util.getSimpleName(listener); + + WidgetUtil + .getSimpleName(listener); Profiler.leave("ElementResizeListener.onElementResize construct profiler key"); Profiler.enter(key); } @@ -389,7 +390,7 @@ public class LayoutManager { String key = null; if (Profiler.isEnabled()) { key = "layoutHorizontally() for " - + Util.getSimpleName(cl); + + WidgetUtil.getSimpleName(cl); Profiler.enter(key); } @@ -411,7 +412,8 @@ public class LayoutManager { try { String key = null; if (Profiler.isEnabled()) { - key = "layout() for " + Util.getSimpleName(rr); + key = "layout() for " + + WidgetUtil.getSimpleName(rr); Profiler.enter(key); } @@ -444,7 +446,7 @@ public class LayoutManager { String key = null; if (Profiler.isEnabled()) { key = "layoutVertically() for " - + Util.getSimpleName(cl); + + WidgetUtil.getSimpleName(cl); Profiler.enter(key); } @@ -466,7 +468,8 @@ public class LayoutManager { try { String key = null; if (Profiler.isEnabled()) { - key = "layout() for " + Util.getSimpleName(rr); + key = "layout() for " + + WidgetUtil.getSimpleName(rr); Profiler.enter(key); } @@ -545,7 +548,7 @@ public class LayoutManager { String key = null; if (Profiler.isEnabled()) { key = "layout PostLayoutListener for " - + Util.getSimpleName(connector); + + WidgetUtil.getSimpleName(connector); Profiler.enter(key); } diff --git a/client/src/com/vaadin/client/LayoutManagerIE8.java b/client/src/com/vaadin/client/LayoutManagerIE8.java index 941ac589b2..9fb6819e83 100644 --- a/client/src/com/vaadin/client/LayoutManagerIE8.java +++ b/client/src/com/vaadin/client/LayoutManagerIE8.java @@ -94,7 +94,7 @@ public class LayoutManagerIE8 extends LayoutManager { * the containing element. To force a reflow by modifying the magical * zoom property. */ - Util.forceIE8Redraw(RootPanel.get().getElement()); + WidgetUtil.forceIE8Redraw(RootPanel.get().getElement()); Profiler.leave("LayoutManagerIE8.performBrowserLayoutHacks"); } } diff --git a/client/src/com/vaadin/client/MeasuredSize.java b/client/src/com/vaadin/client/MeasuredSize.java index 2531ff9389..8520635a4d 100644 --- a/client/src/com/vaadin/client/MeasuredSize.java +++ b/client/src/com/vaadin/client/MeasuredSize.java @@ -236,7 +236,7 @@ public class MeasuredSize { Profiler.leave("Measure borders"); Profiler.enter("Measure height"); - int requiredHeight = Util.getRequiredHeight(element); + int requiredHeight = WidgetUtil.getRequiredHeight(element); int marginHeight = sumHeights(margins); int oldHeight = height; int oldWidth = width; @@ -247,7 +247,7 @@ public class MeasuredSize { Profiler.leave("Measure height"); Profiler.enter("Measure width"); - int requiredWidth = Util.getRequiredWidth(element); + int requiredWidth = WidgetUtil.getRequiredWidth(element); int marginWidth = sumWidths(margins); if (setOuterWidth(requiredWidth + marginWidth)) { debugSizeChange(element, "Width (outer)", oldWidth, width); diff --git a/client/src/com/vaadin/client/MouseEventDetailsBuilder.java b/client/src/com/vaadin/client/MouseEventDetailsBuilder.java index 313fe682fd..11ebe3925c 100644 --- a/client/src/com/vaadin/client/MouseEventDetailsBuilder.java +++ b/client/src/com/vaadin/client/MouseEventDetailsBuilder.java @@ -57,8 +57,8 @@ public class MouseEventDetailsBuilder { Element relativeToElement) { MouseEventDetails mouseEventDetails = new MouseEventDetails(); mouseEventDetails.setType(Event.getTypeInt(evt.getType())); - mouseEventDetails.setClientX(Util.getTouchOrMouseClientX(evt)); - mouseEventDetails.setClientY(Util.getTouchOrMouseClientY(evt)); + mouseEventDetails.setClientX(WidgetUtil.getTouchOrMouseClientX(evt)); + mouseEventDetails.setClientY(WidgetUtil.getTouchOrMouseClientY(evt)); if (evt.getButton() == NativeEvent.BUTTON_LEFT) { mouseEventDetails.setButton(MouseButton.LEFT); } else if (evt.getButton() == NativeEvent.BUTTON_RIGHT) { diff --git a/client/src/com/vaadin/client/RenderSpace.java b/client/src/com/vaadin/client/RenderSpace.java index 5a7440b682..dff774aa6f 100644 --- a/client/src/com/vaadin/client/RenderSpace.java +++ b/client/src/com/vaadin/client/RenderSpace.java @@ -34,7 +34,7 @@ public class RenderSpace extends Size { public RenderSpace(int width, int height, boolean useNativeScrollbarSize) { super(width, height); if (useNativeScrollbarSize) { - scrollBarSize = Util.getNativeScrollbarSize(); + scrollBarSize = WidgetUtil.getNativeScrollbarSize(); } } diff --git a/client/src/com/vaadin/client/ResourceLoader.java b/client/src/com/vaadin/client/ResourceLoader.java index ceede263fc..9e9ce5ac49 100644 --- a/client/src/com/vaadin/client/ResourceLoader.java +++ b/client/src/com/vaadin/client/ResourceLoader.java @@ -225,7 +225,7 @@ public class ResourceLoader { */ public void loadScript(final String scriptUrl, final ResourceLoadListener resourceLoadListener, boolean async) { - final String url = Util.getAbsoluteUrl(scriptUrl); + final String url = WidgetUtil.getAbsoluteUrl(scriptUrl); ResourceLoadEvent event = new ResourceLoadEvent(this, url, false); if (loadedResources.contains(url)) { if (resourceLoadListener != null) { @@ -307,7 +307,7 @@ public class ResourceLoader { */ public void preloadResource(String url, ResourceLoadListener resourceLoadListener) { - url = Util.getAbsoluteUrl(url); + url = WidgetUtil.getAbsoluteUrl(url); ResourceLoadEvent event = new ResourceLoadEvent(this, url, true); if (loadedResources.contains(url) || preloadedResources.contains(url)) { // Already loaded or preloaded -> just fire listener @@ -424,7 +424,7 @@ public class ResourceLoader { */ public void loadStylesheet(final String stylesheetUrl, final ResourceLoadListener resourceLoadListener) { - final String url = Util.getAbsoluteUrl(stylesheetUrl); + final String url = WidgetUtil.getAbsoluteUrl(stylesheetUrl); final ResourceLoadEvent event = new ResourceLoadEvent(this, url, false); if (loadedResources.contains(url)) { if (resourceLoadListener != null) { diff --git a/client/src/com/vaadin/client/SuperDevMode.java b/client/src/com/vaadin/client/SuperDevMode.java index f1020b3d25..e1ffbbe94d 100644 --- a/client/src/com/vaadin/client/SuperDevMode.java +++ b/client/src/com/vaadin/client/SuperDevMode.java @@ -89,7 +89,7 @@ public class SuperDevMode { VConsole.error("JSONP compile call failed"); // Don't log exception as they are shown as // notifications - VConsole.error(Util.getSimpleName(caught) + ": " + VConsole.error(WidgetUtil.getSimpleName(caught) + ": " + caught.getMessage()); failed(); diff --git a/client/src/com/vaadin/client/Util.java b/client/src/com/vaadin/client/Util.java index 8b23bf433b..7885be5d68 100644 --- a/client/src/com/vaadin/client/Util.java +++ b/client/src/com/vaadin/client/Util.java @@ -16,40 +16,18 @@ package com.vaadin.client; -import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Map; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.core.client.JavaScriptObject; -import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; -import com.google.gwt.dom.client.AnchorElement; -import com.google.gwt.dom.client.DivElement; -import com.google.gwt.dom.client.Document; + import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.NativeEvent; -import com.google.gwt.dom.client.Node; -import com.google.gwt.dom.client.NodeList; -import com.google.gwt.dom.client.Style; -import com.google.gwt.dom.client.Style.Display; -import com.google.gwt.dom.client.Style.Unit; -import com.google.gwt.dom.client.Touch; import com.google.gwt.event.dom.client.KeyEvent; -import com.google.gwt.regexp.shared.MatchResult; -import com.google.gwt.regexp.shared.RegExp; -import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; -import com.google.gwt.user.client.EventListener; -import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.HasWidgets; -import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.RenderInformation.FloatSize; import com.vaadin.client.ui.VOverlay; @@ -59,79 +37,66 @@ 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. - * + * */ - public static native void browserDebugger() - /*-{ - if($wnd.console) - debugger; - }-*/; + @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. - * + * * @param event * @return return key code * @since 7.2.4 */ + @Deprecated public static int getKeyCode(KeyEvent<?> event) { - int keyCode = event.getNativeEvent().getKeyCode(); - if (keyCode == 0) { - keyCode = event.getNativeEvent().getCharCode(); - } - return keyCode; + 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. - * + * * @param x * @param y * @return the element at given coordinates */ - public static native com.google.gwt.user.client.Element getElementFromPoint( - int clientX, int clientY) - /*-{ - var el = $wnd.document.elementFromPoint(clientX, clientY); - // Call elementFromPoint two times to make sure IE8 also returns something sensible if the application is running in an iframe - el = $wnd.document.elementFromPoint(clientX, clientY); - if(el != null && el.nodeType == 3) { - el = el.parentNode; - } - return el; - }-*/; + @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 @@ -164,318 +129,124 @@ public class Util { return null; } + @Deprecated public static float parseRelativeSize(String size) { - if (size == null || !size.endsWith("%")) { - return -1; - } - - try { - return Float.parseFloat(size.substring(0, size.length() - 1)); - } catch (Exception e) { - VConsole.log("Unable to parse relative size"); - return -1; - } + return WidgetUtil.parseRelativeSize(size); } - private static final Element escapeHtmlHelper = DOM.createDiv(); - /** * Converts html entities to text. - * + * * @param html * @return escaped string presentation of given html */ + @Deprecated public static String escapeHTML(String html) { - DOM.setInnerText(escapeHtmlHelper, html); - String escapedText = DOM.getInnerHTML(escapeHtmlHelper); - if (BrowserInfo.get().isIE8()) { - // #7478 IE8 "incorrectly" returns "<br>" for newlines set using - // setInnerText. The same for " " which is converted to " " - escapedText = escapedText.replaceAll("<(BR|br)>", "\n"); - escapedText = escapedText.replaceAll(" ", " "); - } - return escapedText; + return WidgetUtil.escapeHTML(html); } /** * Escapes the string so it is safe to write inside an HTML attribute. - * + * * @param attribute * The string to escape * @return An escaped version of <literal>attribute</literal>. */ + @Deprecated public static String escapeAttribute(String attribute) { - if (attribute == null) { - return ""; - } - attribute = attribute.replace("\"", """); - attribute = attribute.replace("'", "'"); - attribute = attribute.replace(">", ">"); - attribute = attribute.replace("<", "<"); - attribute = attribute.replace("&", "&"); - return attribute; + return WidgetUtil.escapeAttribute(attribute); } /** * Clones given element as in JavaScript. - * + * * Deprecate this if there appears similar method into GWT someday. - * + * * @param element * @param deep * clone child tree also * @return */ - public static native com.google.gwt.user.client.Element cloneNode( - Element element, boolean deep) - /*-{ - return element.cloneNode(deep); - }-*/; + @Deprecated + public static com.google.gwt.user.client.Element cloneNode(Element element, + boolean deep) { + return DOM.asOld(WidgetUtil.cloneNode(element, deep)); + } + @Deprecated public static int measureHorizontalPaddingAndBorder(Element element, int paddingGuess) { - String originalWidth = DOM.getStyleAttribute(element, "width"); - - int originalOffsetWidth = element.getOffsetWidth(); - int widthGuess = (originalOffsetWidth - paddingGuess); - if (widthGuess < 1) { - widthGuess = 1; - } - element.getStyle().setWidth(widthGuess, Unit.PX); - int padding = element.getOffsetWidth() - widthGuess; - - element.getStyle().setProperty("width", originalWidth); - - return padding; + return WidgetUtil.measureHorizontalPaddingAndBorder(element, + paddingGuess); } + @Deprecated public static int measureVerticalPaddingAndBorder(Element element, int paddingGuess) { - String originalHeight = DOM.getStyleAttribute(element, "height"); - int originalOffsetHeight = element.getOffsetHeight(); - int widthGuess = (originalOffsetHeight - paddingGuess); - if (widthGuess < 1) { - widthGuess = 1; - } - element.getStyle().setHeight(widthGuess, Unit.PX); - int padding = element.getOffsetHeight() - widthGuess; - - element.getStyle().setProperty("height", originalHeight); - return padding; + return WidgetUtil + .measureVerticalPaddingAndBorder(element, paddingGuess); } + @Deprecated public static int measureHorizontalBorder(Element element) { - int borders; - - if (BrowserInfo.get().isIE()) { - String width = element.getStyle().getProperty("width"); - String height = element.getStyle().getProperty("height"); - - int offsetWidth = element.getOffsetWidth(); - int offsetHeight = element.getOffsetHeight(); - if (offsetHeight < 1) { - offsetHeight = 1; - } - if (offsetWidth < 1) { - offsetWidth = 10; - } - element.getStyle().setPropertyPx("height", offsetHeight); - element.getStyle().setPropertyPx("width", offsetWidth); - - borders = element.getOffsetWidth() - element.getClientWidth(); - - element.getStyle().setProperty("width", width); - element.getStyle().setProperty("height", height); - } else { - borders = element.getOffsetWidth() - - element.getPropertyInt("clientWidth"); - } - assert borders >= 0; - - return borders; + return WidgetUtil.measureHorizontalBorder(element); } + @Deprecated public static int measureVerticalBorder(Element element) { - int borders; - if (BrowserInfo.get().isIE()) { - String width = element.getStyle().getProperty("width"); - String height = element.getStyle().getProperty("height"); - - int offsetWidth = element.getOffsetWidth(); - int offsetHeight = element.getOffsetHeight(); - if (offsetHeight < 1) { - offsetHeight = 1; - } - if (offsetWidth < 1) { - offsetWidth = 10; - } - element.getStyle().setPropertyPx("width", offsetWidth); - - element.getStyle().setPropertyPx("height", offsetHeight); - - borders = element.getOffsetHeight() - - element.getPropertyInt("clientHeight"); - - element.getStyle().setProperty("height", height); - element.getStyle().setProperty("width", width); - } else { - borders = element.getOffsetHeight() - - element.getPropertyInt("clientHeight"); - } - assert borders >= 0; - - return borders; + return WidgetUtil.measureVerticalBorder(element); } + @Deprecated public static int measureMarginLeft(Element element) { - return element.getAbsoluteLeft() - - element.getParentElement().getAbsoluteLeft(); + return WidgetUtil.measureMarginLeft(element); } + @Deprecated public static int setHeightExcludingPaddingAndBorder(Widget widget, String height, int paddingBorderGuess) { - if (height.equals("")) { - setHeight(widget, ""); - return paddingBorderGuess; - } else if (height.endsWith("px")) { - int pixelHeight = Integer.parseInt(height.substring(0, - height.length() - 2)); - return setHeightExcludingPaddingAndBorder(widget.getElement(), - pixelHeight, paddingBorderGuess, false); - } else { - // Set the height in unknown units - setHeight(widget, height); - // Use the offsetWidth - return setHeightExcludingPaddingAndBorder(widget.getElement(), - widget.getOffsetHeight(), paddingBorderGuess, true); - } - } - - private static void setWidth(Widget widget, String width) { - widget.getElement().getStyle().setProperty("width", width); - } - - private static void setHeight(Widget widget, String height) { - widget.getElement().getStyle().setProperty("height", height); + return WidgetUtil.setHeightExcludingPaddingAndBorder(widget, height, + paddingBorderGuess); } + @Deprecated public static int setWidthExcludingPaddingAndBorder(Widget widget, String width, int paddingBorderGuess) { - if (width.equals("")) { - setWidth(widget, ""); - return paddingBorderGuess; - } else if (width.endsWith("px")) { - int pixelWidth = Integer.parseInt(width.substring(0, - width.length() - 2)); - return setWidthExcludingPaddingAndBorder(widget.getElement(), - pixelWidth, paddingBorderGuess, false); - } else { - setWidth(widget, width); - return setWidthExcludingPaddingAndBorder(widget.getElement(), - widget.getOffsetWidth(), paddingBorderGuess, true); - } + return WidgetUtil.setWidthExcludingPaddingAndBorder(widget, width, + paddingBorderGuess); } + @Deprecated public static int setWidthExcludingPaddingAndBorder(Element element, int requestedWidth, int horizontalPaddingBorderGuess, boolean requestedWidthIncludesPaddingBorder) { - - int widthGuess = requestedWidth - horizontalPaddingBorderGuess; - if (widthGuess < 0) { - widthGuess = 0; - } - - element.getStyle().setWidth(widthGuess, Unit.PX); - int captionOffsetWidth = DOM.getElementPropertyInt(element, - "offsetWidth"); - - int actualPadding = captionOffsetWidth - widthGuess; - - if (requestedWidthIncludesPaddingBorder) { - actualPadding += actualPadding; - } - - if (actualPadding != horizontalPaddingBorderGuess) { - int w = requestedWidth - actualPadding; - if (w < 0) { - // Cannot set negative width even if we would want to - w = 0; - } - element.getStyle().setWidth(w, Unit.PX); - - } - - return actualPadding; - + return WidgetUtil.setWidthExcludingPaddingAndBorder(element, + requestedWidth, horizontalPaddingBorderGuess, + requestedWidthIncludesPaddingBorder); } + @Deprecated public static int setHeightExcludingPaddingAndBorder(Element element, int requestedHeight, int verticalPaddingBorderGuess, boolean requestedHeightIncludesPaddingBorder) { - - int heightGuess = requestedHeight - verticalPaddingBorderGuess; - if (heightGuess < 0) { - heightGuess = 0; - } - - element.getStyle().setHeight(heightGuess, Unit.PX); - int captionOffsetHeight = DOM.getElementPropertyInt(element, - "offsetHeight"); - - int actualPadding = captionOffsetHeight - heightGuess; - - if (requestedHeightIncludesPaddingBorder) { - actualPadding += actualPadding; - } - - if (actualPadding != verticalPaddingBorderGuess) { - int h = requestedHeight - actualPadding; - if (h < 0) { - // Cannot set negative height even if we would want to - h = 0; - } - element.getStyle().setHeight(h, Unit.PX); - - } - - return actualPadding; - + return WidgetUtil.setHeightExcludingPaddingAndBorder(element, + requestedHeight, verticalPaddingBorderGuess, + requestedHeightIncludesPaddingBorder); } + @Deprecated public static String getSimpleName(Object widget) { - if (widget == null) { - return "(null)"; - } - - String name = widget.getClass().getName(); - return name.substring(name.lastIndexOf('.') + 1); + return WidgetUtil.getSimpleName(widget); } + @Deprecated public static void setFloat(Element element, String value) { - if (BrowserInfo.get().isIE()) { - element.getStyle().setProperty("styleFloat", value); - } else { - element.getStyle().setProperty("cssFloat", value); - } + WidgetUtil.setFloat(element, value); } - private static int detectedScrollbarSize = -1; - + @Deprecated public static int getNativeScrollbarSize() { - if (detectedScrollbarSize < 0) { - Element scroller = DOM.createDiv(); - scroller.getStyle().setProperty("width", "50px"); - scroller.getStyle().setProperty("height", "50px"); - scroller.getStyle().setProperty("overflow", "scroll"); - scroller.getStyle().setProperty("position", "absolute"); - scroller.getStyle().setProperty("marginLeft", "-5000px"); - RootPanel.getBodyElement().appendChild(scroller); - detectedScrollbarSize = scroller.getOffsetWidth() - - scroller.getPropertyInt("clientWidth"); - - RootPanel.getBodyElement().removeChild(scroller); - } - return detectedScrollbarSize; + return WidgetUtil.getNativeScrollbarSize(); } /** @@ -485,85 +256,22 @@ public class Util { * @param elem * with overflow auto */ + @Deprecated public static void runWebkitOverflowAutoFixDeferred(final Element elem) { - Scheduler.get().scheduleDeferred(new Command() { - - @Override - public void execute() { - Util.runWebkitOverflowAutoFix(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 - * + * * @param elem * with overflow auto */ + @Deprecated public static void runWebkitOverflowAutoFix(final Element elem) { - // Add max version if fix lands sometime to Webkit - // Starting from Opera 11.00, also a problem in Opera - if (BrowserInfo.get().requiresOverflowAutoFix()) { - final String originalOverflow = elem.getStyle().getProperty( - "overflow"); - if ("hidden".equals(originalOverflow)) { - return; - } - - // check the scrolltop value before hiding the element - final int scrolltop = elem.getScrollTop(); - final int scrollleft = elem.getScrollLeft(); - elem.getStyle().setProperty("overflow", "hidden"); - - Scheduler.get().scheduleDeferred(new Command() { - @Override - public void execute() { - // Dough, Safari scroll auto means actually just a moped - elem.getStyle().setProperty("overflow", originalOverflow); - - if (scrolltop > 0 || elem.getScrollTop() > 0) { - int scrollvalue = scrolltop; - if (scrollvalue == 0) { - // mysterious are the ways of webkits scrollbar - // handling. In some cases webkit reports bad (0) - // scrolltop before hiding the element temporary, - // sometimes after. - scrollvalue = elem.getScrollTop(); - } - // fix another bug where scrollbar remains in wrong - // position - elem.setScrollTop(scrollvalue - 1); - elem.setScrollTop(scrollvalue); - } - - // fix for #6940 : Table horizontal scroll sometimes not - // updated when collapsing/expanding columns - // Also appeared in Safari 5.1 with webkit 534 (#7667) - if ((BrowserInfo.get().isChrome() || (BrowserInfo.get() - .isSafari() && BrowserInfo.get().getWebkitVersion() >= 534)) - && (scrollleft > 0 || elem.getScrollLeft() > 0)) { - int scrollvalue = scrollleft; - - if (scrollvalue == 0) { - // mysterious are the ways of webkits scrollbar - // handling. In some cases webkit may report a bad - // (0) scrollleft before hiding the element - // temporary, sometimes after. - scrollvalue = elem.getScrollLeft(); - } - // fix another bug where scrollbar remains in wrong - // position - elem.setScrollLeft(scrollvalue - 1); - elem.setScrollLeft(scrollvalue); - } - } - }); - } - + WidgetUtil.runWebkitOverflowAutoFix(elem); } /** @@ -571,7 +279,7 @@ public class Util { * 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 */ @@ -581,8 +289,8 @@ public class Util { return null; } - float relativeWidth = Util.parseRelativeSize(state.width); - float relativeHeight = Util.parseRelativeSize(state.height); + float relativeWidth = WidgetUtil.parseRelativeSize(state.width); + float relativeHeight = WidgetUtil.parseRelativeSize(state.height); FloatSize relativeSize = new FloatSize(relativeWidth, relativeHeight); return relativeSize; @@ -594,17 +302,16 @@ public class Util { return uidl.getBooleanAttribute("cached"); } + @Deprecated public static void alert(String string) { - if (true) { - Window.alert(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 @@ -625,242 +332,85 @@ public class Util { /** * Gets the border-box width for the given element, i.e. element width + * border + padding. Always rounds up to nearest integer. - * + * * @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) { - int reqWidth = getRequiredWidthBoundingClientRect(element); - if (BrowserInfo.get().isIE() && !BrowserInfo.get().isIE8()) { - int csSize = getRequiredWidthComputedStyle(element); - if (csSize == reqWidth + 1) { - // If computed style reports one pixel larger than requiredWidth - // we would be rounding in the wrong direction in IE9. Round up - // instead. - // We do not always use csSize as it e.g. for 100% wide Labels - // in GridLayouts produces senseless values (see e.g. - // ThemeTestUI with Runo). - return csSize; - } - } - return reqWidth; + 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. - * + * * @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) { - int reqHeight = getRequiredHeightBoundingClientRect(element); - if (BrowserInfo.get().isIE() && !BrowserInfo.get().isIE8()) { - int csSize = getRequiredHeightComputedStyle(element); - if (csSize == reqHeight + 1) { - // If computed style reports one pixel larger than - // requiredHeight we would be rounding in the wrong direction in - // IE9. Round up instead. - // We do not always use csSize as it e.g. for 100% wide Labels - // in GridLayouts produces senseless values (see e.g. - // ThemeTestUI with Runo). - return csSize; - } - } - return reqHeight; + return WidgetUtil.getRequiredHeight(element); } - /** - * Calculates the width of the element's bounding rectangle. - * <p> - * In case the browser doesn't support bounding rectangles, the returned - * value is the offset width. - * - * @param element - * the element of which to calculate the width - * @return the width of the element - */ - public static int getRequiredWidthBoundingClientRect( + @Deprecated + public int getRequiredWidthBoundingClientRect( com.google.gwt.dom.client.Element element) { - return (int) getRequiredWidthBoundingClientRectDouble(element); + return WidgetUtil.getRequiredWidthBoundingClientRect(element); } - /** - * Calculates the width of the element's bounding rectangle to subpixel - * precision. - * <p> - * In case the browser doesn't support bounding rectangles, the returned - * value is the offset width. - * - * @param element - * the element of which to calculate the width - * @return the subpixel-accurate width of the element - * @since 7.4 - */ - public static native double getRequiredWidthBoundingClientRectDouble( - com.google.gwt.dom.client.Element element) - /*-{ - if (element.getBoundingClientRect) { - var rect = element.getBoundingClientRect(); - return Math.ceil(rect.right - rect.left); - } else { - return element.offsetWidth; - } - }-*/; - - public static native int getRequiredHeightComputedStyle( - com.google.gwt.dom.client.Element element) - /*-{ - var cs = element.ownerDocument.defaultView.getComputedStyle(element); - var heightPx = cs.height; - if(heightPx == 'auto'){ - // Fallback for when IE reports auto - heightPx = @com.vaadin.client.Util::getRequiredHeightBoundingClientRect(Lcom/google/gwt/dom/client/Element;)(element) + 'px'; - } - var borderTopPx = cs.borderTop; - var borderBottomPx = cs.borderBottom; - var paddingTopPx = cs.paddingTop; - var paddingBottomPx = cs.paddingBottom; - - var height = heightPx.substring(0,heightPx.length-2); - var border = borderTopPx.substring(0,borderTopPx.length-2)+borderBottomPx.substring(0,borderBottomPx.length-2); - var padding = paddingTopPx.substring(0,paddingTopPx.length-2)+paddingBottomPx.substring(0,paddingBottomPx.length-2); - return Math.ceil(height+border+padding); - }-*/; - - public static native int getRequiredWidthComputedStyle( - com.google.gwt.dom.client.Element element) - /*-{ - var cs = element.ownerDocument.defaultView.getComputedStyle(element); - var widthPx = cs.width; - if(widthPx == 'auto'){ - // Fallback for when IE reports auto - widthPx = @com.vaadin.client.Util::getRequiredWidthBoundingClientRect(Lcom/google/gwt/dom/client/Element;)(element) + 'px'; - } - var borderLeftPx = cs.borderLeft; - var borderRightPx = cs.borderRight; - var paddingLeftPx = cs.paddingLeft; - var paddingRightPx = cs.paddingRight; - - var width = widthPx.substring(0,widthPx.length-2); - var border = borderLeftPx.substring(0,borderLeftPx.length-2)+borderRightPx.substring(0,borderRightPx.length-2); - var padding = paddingLeftPx.substring(0,paddingLeftPx.length-2)+paddingRightPx.substring(0,paddingRightPx.length-2); - return Math.ceil(width+border+padding); - }-*/; + @Deprecated + public static int getRequiredHeightComputedStyle( + com.google.gwt.dom.client.Element element) { + return WidgetUtil.getRequiredHeightComputedStyle(element); + } - /** - * Calculates the height of the element's bounding rectangle. - * <p> - * In case the browser doesn't support bounding rectangles, the returned - * value is the offset height. - * - * @param element - * the element of which to calculate the height - * @return the height of the element - */ - public static int getRequiredHeightBoundingClientRect( + @Deprecated + public static int getRequiredWidthComputedStyle( com.google.gwt.dom.client.Element element) { - return (int) getRequiredHeightBoundingClientRectDouble(element); + return WidgetUtil.getRequiredWidthComputedStyle(element); } - /** - * Calculates the height of the element's bounding rectangle to subpixel - * precision. - * <p> - * In case the browser doesn't support bounding rectangles, the returned - * value is the offset height. - * - * @param element - * the element of which to calculate the height - * @return the subpixel-accurate height of the element - * @since 7.4 - */ - public static native double getRequiredHeightBoundingClientRectDouble( - com.google.gwt.dom.client.Element element) - /*-{ - var height; - if (element.getBoundingClientRect != null) { - var rect = element.getBoundingClientRect(); - height = Math.ceil(rect.bottom - rect.top); - } else { - height = element.offsetHeight; - } - return height; - }-*/; + @Deprecated + public static int getRequiredHeightBoundingClientRect( + com.google.gwt.dom.client.Element element) { + return WidgetUtil.getRequiredHeightBoundingClientRect(element); + } + @Deprecated public static int getRequiredWidth(Widget widget) { - return getRequiredWidth(widget.getElement()); + return WidgetUtil.getRequiredWidth(widget); } + @Deprecated public static int getRequiredHeight(Widget widget) { - return getRequiredHeight(widget.getElement()); + return WidgetUtil.getRequiredHeight(widget); } /** * Detects what is currently the overflow style attribute in given element. - * + * * @param pe * the element to detect * @return true if auto or scroll */ + @Deprecated public static boolean mayHaveScrollBars(com.google.gwt.dom.client.Element pe) { - String overflow = getComputedStyle(pe, "overflow"); - if (overflow != null) { - if (overflow.equals("auto") || overflow.equals("scroll")) { - return true; - } else { - return false; - } - } else { - return false; - } + return WidgetUtil.mayHaveScrollBars(pe); } /** - * A simple helper method to detect "computed style" (aka style sheets + - * element styles). Values returned differ a lot depending on browsers. - * Always be very careful when using this. - * - * @param el - * the element from which the style property is detected - * @param p - * the property to detect - * @return String value of style property - */ - private static native String getComputedStyle( - com.google.gwt.dom.client.Element el, String p) - /*-{ - try { - - if (el.currentStyle) { - // IE - return el.currentStyle[p]; - } else if (window.getComputedStyle) { - // Sa, FF, Opera - var view = el.ownerDocument.defaultView; - return view.getComputedStyle(el,null).getPropertyValue(p); - } else { - // fall back for non IE, Sa, FF, Opera - return ""; - } - } catch (e) { - return ""; - } - - }-*/; - - /** * 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 @@ -918,23 +468,19 @@ public class Util { /** * Will (attempt) to focus the given DOM Element. - * + * * @param el * the element to focus */ - public static native void focus(Element el) - /*-{ - try { - el.focus(); - } catch (e) { - - } - }-*/; + @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 */ @@ -952,145 +498,84 @@ public class Util { /** * Helper method to find first instance of given Widget type found by * traversing DOM upwards from given element. - * <p> - * <strong>Note:</strong> If {@code element} is inside some widget {@code W} - * , <em>and</em> {@code W} in turn is wrapped in a {@link Composite} - * {@code C}, this method will not find {@code W}. It returns either - * {@code C} or null, depending on whether the class parameter matches. This - * may also be the case with other Composite-like classes that hijack the - * event handling of their child widget(s). - * + * * @param element * the element where to start seeking of Widget * @param class1 * the Widget type to seek for */ - @SuppressWarnings("unchecked") + @Deprecated public static <T> T findWidget(Element element, Class<? extends Widget> class1) { - if (element != null) { - /* First seek for the first EventListener (~Widget) from dom */ - EventListener eventListener = null; - while (eventListener == null && element != null) { - eventListener = Event.getEventListener(element); - if (eventListener == null) { - element = element.getParentElement(); - } - } - if (eventListener instanceof Widget) { - /* - * Then find the first widget of type class1 from widget - * hierarchy - */ - Widget w = (Widget) eventListener; - while (w != null) { - if (class1 == null || w.getClass() == class1) { - return (T) w; - } - w = w.getParent(); - } - } - } - return null; + return WidgetUtil.findWidget(element, class1); } /** * Force webkit to redraw an element - * + * * @param element * The element that should be redrawn */ + @Deprecated public static void forceWebkitRedraw(Element element) { - Style style = element.getStyle(); - String s = style.getProperty("webkitTransform"); - if (s == null || s.length() == 0) { - style.setProperty("webkitTransform", "scale(1)"); - } else { - style.setProperty("webkitTransform", ""); - } + 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. - * + * * @param e * The element to perform the hack on */ + @Deprecated public static final void forceIE8Redraw(Element e) { - if (BrowserInfo.get().isIE8()) { - forceIERedraw(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. - * + * * @since 7.3 * @param e * The element to perform the hack on */ + @Deprecated public static void forceIERedraw(Element e) { - if (BrowserInfo.get().isIE()) { - setStyleTemporarily(e, "zoom", "1"); - } + 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. - * + * * @param element * The element to detach and re-attach */ + @Deprecated public static void detachAttach(Element element) { - if (element == null) { - return; - } - - Node nextSibling = element.getNextSibling(); - Node parent = element.getParentNode(); - if (parent == null) { - return; - } - - parent.removeChild(element); - if (nextSibling == null) { - parent.appendChild(element); - } else { - parent.insertBefore(element, nextSibling); - } - + WidgetUtil.detachAttach(element); } + @Deprecated public static void sinkOnloadForImages(Element element) { - NodeList<com.google.gwt.dom.client.Element> imgElements = element - .getElementsByTagName("img"); - for (int i = 0; i < imgElements.getLength(); i++) { - DOM.sinkEvents(imgElements.getItem(i), Event.ONLOAD); - } - + WidgetUtil.sinkOnloadForImages(element); } /** * Returns the index of the childElement within its parent. - * + * * @param subElement * @return */ + @Deprecated public static int getChildElementIndex(Element childElement) { - int idx = 0; - Node n = childElement; - while ((n = n.getPreviousSibling()) != null) { - idx++; - } - - return idx; + return WidgetUtil.getChildElementIndex(childElement); } private static void printConnectorInvocations( @@ -1155,7 +640,7 @@ public class Util { * 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) - * + * * @param element * The target element * @param styleProperty @@ -1163,162 +648,104 @@ public class Util { * @param tempValue * The temporary value */ + @Deprecated public static void setStyleTemporarily(Element element, final String styleProperty, String tempValue) { - final Style style = element.getStyle(); - final String currentValue = style.getProperty(styleProperty); - - style.setProperty(styleProperty, tempValue); - element.getOffsetWidth(); - style.setProperty(styleProperty, currentValue); - + 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. - * + * * @param event * @return */ + @Deprecated public static int getTouchOrMouseClientX(Event event) { - if (isTouchEvent(event)) { - return event.getChangedTouches().get(0).getClientX(); - } else { - return event.getClientX(); - } + 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. - * + * * @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) { - int pageX = getTouchOrMouseClientX(event); - int pageY = getTouchOrMouseClientY(event); - - return getElementFromPoint(pageX, pageY); + 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. - * + * * @param event * @return */ + @Deprecated public static int getTouchOrMouseClientY(Event event) { - if (isTouchEvent(event)) { - return event.getChangedTouches().get(0).getClientY(); - } else { - return event.getClientY(); - } + return WidgetUtil.getTouchOrMouseClientY(event); } /** - * + * * @see #getTouchOrMouseClientY(Event) * @param currentGwtEvent * @return */ + @Deprecated public static int getTouchOrMouseClientY(NativeEvent currentGwtEvent) { - return getTouchOrMouseClientY(Event.as(currentGwtEvent)); + return WidgetUtil.getTouchOrMouseClientY(currentGwtEvent); } /** * @see #getTouchOrMouseClientX(Event) - * + * * @param event * @return */ + @Deprecated public static int getTouchOrMouseClientX(NativeEvent event) { - return getTouchOrMouseClientX(Event.as(event)); + return WidgetUtil.getTouchOrMouseClientX(event); } + @Deprecated public static boolean isTouchEvent(Event event) { - return event.getType().contains("touch"); + return WidgetUtil.isTouchEvent(event); } + @Deprecated public static boolean isTouchEvent(NativeEvent event) { - return isTouchEvent(Event.as(event)); + return WidgetUtil.isTouchEvent(event); } + @Deprecated public static void simulateClickFromTouchEvent(Event touchevent, Widget widget) { - Touch touch = touchevent.getChangedTouches().get(0); - final NativeEvent createMouseUpEvent = Document.get() - .createMouseUpEvent(0, touch.getScreenX(), touch.getScreenY(), - touch.getClientX(), touch.getClientY(), false, false, - false, false, NativeEvent.BUTTON_LEFT); - final NativeEvent createMouseDownEvent = Document.get() - .createMouseDownEvent(0, touch.getScreenX(), - touch.getScreenY(), touch.getClientX(), - touch.getClientY(), false, false, false, false, - NativeEvent.BUTTON_LEFT); - final NativeEvent createMouseClickEvent = Document.get() - .createClickEvent(0, touch.getScreenX(), touch.getScreenY(), - touch.getClientX(), touch.getClientY(), false, false, - false, false); - - /* - * Get target with element from point as we want the actual element, not - * the one that sunk the event. - */ - final Element target = getElementFromPoint(touch.getClientX(), - touch.getClientY()); - - /* - * Fixes infocusable form fields in Safari of iOS 5.x and some Android - * browsers. - */ - Widget targetWidget = findWidget(target, null); - if (targetWidget instanceof com.google.gwt.user.client.ui.Focusable) { - final com.google.gwt.user.client.ui.Focusable toBeFocusedWidget = (com.google.gwt.user.client.ui.Focusable) targetWidget; - toBeFocusedWidget.setFocus(true); - } else if (targetWidget instanceof Focusable) { - ((Focusable) targetWidget).focus(); - } - - Scheduler.get().scheduleDeferred(new ScheduledCommand() { - @Override - public void execute() { - try { - target.dispatchEvent(createMouseDownEvent); - target.dispatchEvent(createMouseUpEvent); - target.dispatchEvent(createMouseClickEvent); - } catch (Exception e) { - } - - } - }); - + WidgetUtil.simulateClickFromTouchEvent(touchevent, widget); } /** * Gets the currently focused element. - * + * * @return The active element or null if no active element could be found. */ - public native static com.google.gwt.user.client.Element getFocusedElement() - /*-{ - if ($wnd.document.activeElement) { - return $wnd.document.activeElement; - } - - return null; - }-*/; + @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 */ @@ -1334,18 +761,9 @@ public class Util { * * @return true if focused element is editable */ + @Deprecated public static boolean isFocusedElementEditable() { - Element focusedElement = Util.getFocusedElement(); - if (focusedElement != null) { - String tagName = focusedElement.getTagName(); - String contenteditable = focusedElement - .getAttribute("contenteditable"); - - return "textarea".equalsIgnoreCase(tagName) - || "input".equalsIgnoreCase(tagName) - || "true".equalsIgnoreCase(contenteditable); - } - return false; + return WidgetUtil.isFocusedElementEditable(); } /** @@ -1353,87 +771,43 @@ public class Util { * 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. - * + * * @param widget * @return true if attached and displayed */ + @Deprecated public static boolean isAttachedAndDisplayed(Widget widget) { - if (widget.isAttached()) { - /* - * Failfast using offset size, then by iterating the widget tree - */ - boolean notZeroSized = widget.getOffsetHeight() > 0 - || widget.getOffsetWidth() > 0; - return notZeroSized || checkVisibilityRecursively(widget); - } else { - return false; - } - } - - private static boolean checkVisibilityRecursively(Widget widget) { - if (widget.isVisible()) { - Widget parent = widget.getParent(); - if (parent == null) { - return true; // root panel - } else { - return checkVisibilityRecursively(parent); - } - } else { - return false; - } + return WidgetUtil.isAttachedAndDisplayed(widget); } /** * Scrolls an element into view vertically only. Modified version of * Element.scrollIntoView. - * + * * @param elem * The element to scroll into view */ - public static native void scrollIntoViewVertically(Element elem) - /*-{ - var top = elem.offsetTop; - var height = elem.offsetHeight; - - if (elem.parentNode != elem.offsetParent) { - top -= elem.parentNode.offsetTop; - } - - var cur = elem.parentNode; - while (cur && (cur.nodeType == 1)) { - if (top < cur.scrollTop) { - cur.scrollTop = top; - } - if (top + height > cur.scrollTop + cur.clientHeight) { - cur.scrollTop = (top + height) - cur.clientHeight; - } - - var offsetTop = cur.offsetTop; - if (cur.parentNode != cur.offsetParent) { - offsetTop -= cur.parentNode.offsetTop; - } - - top += offsetTop - cur.scrollTop; - cur = cur.parentNode; - } - }-*/; + @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 - * + * * @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) { - boolean touchEvent = Util.isTouchEvent(event); - return touchEvent || event.getButton() == Event.BUTTON_LEFT; + return WidgetUtil.isTouchEventOrLeftMouseButton(event); } /** * Performs a shallow comparison of the collections. - * + * * @param collection1 * The first collection * @param collection2 @@ -1479,31 +853,14 @@ public class Util { /** * Resolve a relative URL to an absolute URL based on the current document's * location. - * + * * @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) { - if (BrowserInfo.get().isIE8()) { - // The hard way - must use innerHTML and attach to DOM in IE8 - DivElement divElement = Document.get().createDivElement(); - divElement.getStyle().setDisplay(Display.NONE); - - RootPanel.getBodyElement().appendChild(divElement); - divElement.setInnerHTML("<a href='" + escapeAttribute(url) - + "' ></a>"); - - AnchorElement a = divElement.getChild(0).cast(); - String href = a.getHref(); - - RootPanel.getBodyElement().removeChild(divElement); - return href; - } else { - AnchorElement a = Document.get().createAnchorElement(); - a.setHref(url); - return a.getHref(); - } + return WidgetUtil.getAbsoluteUrl(url); } /** @@ -1527,254 +884,10 @@ public class Util { * * @since 7.3 */ - public native static void setSelectionRange(Element elem, int pos, - int length, String direction) - /*-{ - try { - elem.setSelectionRange(pos, pos + length, direction); - } catch (e) { - // Firefox throws exception if TextBox is not visible, even if attached - } - }-*/; - - /** - * 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); - }-*/; - - /** - * The allowed value inaccuracy when comparing two double-typed pixel - * values. - * <p> - * Since we're comparing pixels on a screen, epsilon must be less than 1. - * 0.49 was deemed a perfectly fine and beautifully round number. - */ - public static final double PIXEL_EPSILON = 0.49d; - - /** - * Compares two double values with the error margin of - * {@link #PIXEL_EPSILON} (i.e. {@value #PIXEL_EPSILON}) - * - * @param num1 - * the first value for which to compare equality - * @param num2 - * the second value for which to compare equality - * @since 7.4 - * - * @return true if the values are considered equals; false otherwise - */ - public static boolean pixelValuesEqual(final double num1, final double num2) { - return Math.abs(num1 - num2) <= PIXEL_EPSILON; - } - - /** - * Wrap a css size value and its unit and translate back and forth to the - * string representation.<br/> - * Eg. 50%, 123px, ... - * - * @since 7.2.6 - * @author Vaadin Ltd - */ - @SuppressWarnings("serial") - public static class CssSize implements Serializable { - - /* - * Map the size units with their type. - */ - private static Map<String, Unit> type2Unit = new HashMap<String, Style.Unit>(); - static { - for (Unit unit : Unit.values()) { - type2Unit.put(unit.getType(), unit); - } - } - - /** - * Gets the unit value by its type. - * - * @param type - * the type of the unit as found in the style. - * @return the unit value. - */ - public static Unit unitByType(String type) { - return type2Unit.get(type); - } - - /* - * Regex to parse the size. - */ - private static final RegExp sizePattern = RegExp - .compile(SharedUtil.SIZE_PATTERN); - - /** - * Parse the size from string format to {@link CssSize}. - * - * @param s - * the size as string. - * @return a {@link CssSize} object. - */ - public static CssSize fromString(String s) { - if (s == null) { - return null; - } - - s = s.trim(); - if ("".equals(s)) { - return null; - } - - float size = 0; - Unit unit = null; - - MatchResult matcher = sizePattern.exec(s); - if (matcher.getGroupCount() > 1) { - - size = Float.parseFloat(matcher.getGroup(1)); - if (size < 0) { - size = -1; - unit = Unit.PX; - - } else { - String symbol = matcher.getGroup(2); - unit = unitByType(symbol); - } - } else { - throw new IllegalArgumentException("Invalid size argument: \"" - + s + "\" (should match " + sizePattern.getSource() - + ")"); - } - return new CssSize(size, unit); - } - - /** - * Creates a {@link CssSize} using a value and its measurement unit. - * - * @param value - * the value. - * @param unit - * the unit. - * @return the {@link CssSize} object. - */ - public static CssSize fromValueUnit(float value, Unit unit) { - return new CssSize(value, unit); - } - - /* - * The value. - */ - private final float value; - - /* - * The measure unit. - */ - private final Unit unit; - - private CssSize(float value, Unit unit) { - this.value = value; - this.unit = unit; - } - - /** - * Gets the value for this css size. - * - * @return the value. - */ - public float getValue() { - return value; - } - - /** - * Gets the measurement unit for this css size. - * - * @return the unit. - */ - public Unit getUnit() { - return unit; - } - - @Override - public String toString() { - return value + unit.getType(); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof CssSize) { - CssSize size = (CssSize) obj; - return size.value == value && size.unit == unit; - } - - return false; - } - - /** - * Check whether the two sizes are equals. - * - * @param cssSize1 - * the first size to compare. - * @param cssSize2 - * the other size to compare with the first one. - * @return true if the two sizes are equals, otherwise false. - */ - public static boolean equals(String cssSize1, String cssSize2) { - return CssSize.fromString(cssSize1).equals( - CssSize.fromString(cssSize2)); - } - + @Deprecated + public static void setSelectionRange(Element elem, int pos, int length, + String direction) { + WidgetUtil.setSelectionRange(elem, pos, length, direction); } } diff --git a/client/src/com/vaadin/client/VCaption.java b/client/src/com/vaadin/client/VCaption.java index eb19dedf8b..a12097da7d 100644 --- a/client/src/com/vaadin/client/VCaption.java +++ b/client/src/com/vaadin/client/VCaption.java @@ -510,17 +510,17 @@ public class VCaption extends HTML { int width = 0; if (icon != null) { - width += Util.getRequiredWidth(icon.getElement()); + width += WidgetUtil.getRequiredWidth(icon.getElement()); } if (captionText != null) { - width += Util.getRequiredWidth(captionText); + width += WidgetUtil.getRequiredWidth(captionText); } if (requiredFieldIndicator != null) { - width += Util.getRequiredWidth(requiredFieldIndicator); + width += WidgetUtil.getRequiredWidth(requiredFieldIndicator); } if (errorIndicatorElement != null) { - width += Util.getRequiredWidth(errorIndicatorElement); + width += WidgetUtil.getRequiredWidth(errorIndicatorElement); } return width; @@ -531,7 +531,7 @@ public class VCaption extends HTML { int width = 0; if (icon != null) { - width += Util.getRequiredWidth(icon.getElement()); + width += WidgetUtil.getRequiredWidth(icon.getElement()); } if (captionText != null) { int textWidth = captionText.getScrollWidth(); @@ -540,7 +540,7 @@ public class VCaption extends HTML { * In Firefox3 the caption might require more space than the * scrollWidth returns as scrollWidth is rounded down. */ - int requiredWidth = Util.getRequiredWidth(captionText); + int requiredWidth = WidgetUtil.getRequiredWidth(captionText); if (requiredWidth > textWidth) { textWidth = requiredWidth; } @@ -549,10 +549,10 @@ public class VCaption extends HTML { width += textWidth; } if (requiredFieldIndicator != null) { - width += Util.getRequiredWidth(requiredFieldIndicator); + width += WidgetUtil.getRequiredWidth(requiredFieldIndicator); } if (errorIndicatorElement != null) { - width += Util.getRequiredWidth(errorIndicatorElement); + width += WidgetUtil.getRequiredWidth(errorIndicatorElement); } return width; @@ -564,26 +564,26 @@ public class VCaption extends HTML { int h; if (icon != null) { - h = Util.getRequiredHeight(icon.getElement()); + h = WidgetUtil.getRequiredHeight(icon.getElement()); if (h > height) { height = h; } } if (captionText != null) { - h = Util.getRequiredHeight(captionText); + h = WidgetUtil.getRequiredHeight(captionText); if (h > height) { height = h; } } if (requiredFieldIndicator != null) { - h = Util.getRequiredHeight(requiredFieldIndicator); + h = WidgetUtil.getRequiredHeight(requiredFieldIndicator); if (h > height) { height = h; } } if (errorIndicatorElement != null) { - h = Util.getRequiredHeight(errorIndicatorElement); + h = WidgetUtil.getRequiredHeight(errorIndicatorElement); if (h > height) { height = h; } @@ -619,11 +619,13 @@ public class VCaption extends HTML { // DOM.setStyleAttribute(getElement(), "width", maxWidth + "px"); if (requiredFieldIndicator != null) { - availableWidth -= Util.getRequiredWidth(requiredFieldIndicator); + availableWidth -= WidgetUtil + .getRequiredWidth(requiredFieldIndicator); } if (errorIndicatorElement != null) { - availableWidth -= Util.getRequiredWidth(errorIndicatorElement); + availableWidth -= WidgetUtil + .getRequiredWidth(errorIndicatorElement); } if (availableWidth < 0) { @@ -631,8 +633,8 @@ public class VCaption extends HTML { } if (icon != null) { - int iconRequiredWidth = Util - .getRequiredWidth(icon.getElement()); + int iconRequiredWidth = WidgetUtil.getRequiredWidth(icon + .getElement()); if (availableWidth > iconRequiredWidth) { availableWidth -= iconRequiredWidth; } else { @@ -642,7 +644,7 @@ public class VCaption extends HTML { } } if (captionText != null) { - int captionWidth = Util.getRequiredWidth(captionText); + int captionWidth = WidgetUtil.getRequiredWidth(captionText); if (availableWidth > captionWidth) { availableWidth -= captionWidth; diff --git a/client/src/com/vaadin/client/VUIDLBrowser.java b/client/src/com/vaadin/client/VUIDLBrowser.java index 08f4c653a5..137b5241be 100644 --- a/client/src/com/vaadin/client/VUIDLBrowser.java +++ b/client/src/com/vaadin/client/VUIDLBrowser.java @@ -161,7 +161,7 @@ public class VUIDLBrowser extends SimpleTree { } else { setText("Unknown connector (" + connectorId + ")"); } - dir((JsonObject) Util.jso2json(stateChanges), this); + dir((JsonObject) WidgetUtil.jso2json(stateChanges), this); } @Override diff --git a/client/src/com/vaadin/client/WidgetUtil.java b/client/src/com/vaadin/client/WidgetUtil.java new file mode 100644 index 0000000000..2562f8f5ba --- /dev/null +++ b/client/src/com/vaadin/client/WidgetUtil.java @@ -0,0 +1,1479 @@ +/* + * Copyright 2000-2014 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.io.Serializable; +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Logger; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.core.client.JavaScriptObject; +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.dom.client.AnchorElement; +import com.google.gwt.dom.client.DivElement; +import com.google.gwt.dom.client.Document; +import com.google.gwt.dom.client.Element; +import com.google.gwt.dom.client.NativeEvent; +import com.google.gwt.dom.client.Node; +import com.google.gwt.dom.client.NodeList; +import com.google.gwt.dom.client.Style; +import com.google.gwt.dom.client.Style.Display; +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.dom.client.Touch; +import com.google.gwt.event.dom.client.KeyEvent; +import com.google.gwt.regexp.shared.MatchResult; +import com.google.gwt.regexp.shared.RegExp; +import com.google.gwt.user.client.Command; +import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.Event; +import com.google.gwt.user.client.EventListener; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.ui.RootPanel; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.shared.util.SharedUtil; + +import elemental.js.json.JsJsonValue; +import elemental.json.JsonValue; + +/** + * Utility methods which are related to client side code only + */ +public class WidgetUtil { + + /** + * Helper method for debugging purposes. + * + * Stops execution on firefox browsers on a breakpoint. + * + */ + public static native void browserDebugger() + /*-{ + if($wnd.console) + debugger; + }-*/; + + /** + * 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. + * + * @param event + * @return return key code + * @since 7.2.4 + */ + public static int getKeyCode(KeyEvent<?> event) { + int keyCode = event.getNativeEvent().getKeyCode(); + if (keyCode == 0) { + keyCode = event.getNativeEvent().getCharCode(); + } + return keyCode; + } + + /** + * + * 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. + * + * @param x + * @param y + * @return the element at given coordinates + */ + public static native Element getElementFromPoint(int clientX, int clientY) + /*-{ + var el = $wnd.document.elementFromPoint(clientX, clientY); + // Call elementFromPoint two times to make sure IE8 also returns something sensible if the application is running in an iframe + el = $wnd.document.elementFromPoint(clientX, clientY); + if(el != null && el.nodeType == 3) { + el = el.parentNode; + } + return el; + }-*/; + + public static float parseRelativeSize(String size) { + if (size == null || !size.endsWith("%")) { + return -1; + } + + try { + return Float.parseFloat(size.substring(0, size.length() - 1)); + } catch (Exception e) { + getLogger().warning("Unable to parse relative size"); + return -1; + } + } + + private static final Element escapeHtmlHelper = DOM.createDiv(); + + /** + * Converts html entities to text. + * + * @param html + * @return escaped string presentation of given html + */ + public static String escapeHTML(String html) { + DOM.setInnerText(escapeHtmlHelper, html); + String escapedText = DOM.getInnerHTML(escapeHtmlHelper); + if (BrowserInfo.get().isIE8()) { + // #7478 IE8 "incorrectly" returns "<br>" for newlines set using + // setInnerText. The same for " " which is converted to " " + escapedText = escapedText.replaceAll("<(BR|br)>", "\n"); + escapedText = escapedText.replaceAll(" ", " "); + } + return escapedText; + } + + /** + * Escapes the string so it is safe to write inside an HTML attribute. + * + * @param attribute + * The string to escape + * @return An escaped version of <literal>attribute</literal>. + */ + public static String escapeAttribute(String attribute) { + if (attribute == null) { + return ""; + } + attribute = attribute.replace("\"", """); + attribute = attribute.replace("'", "'"); + attribute = attribute.replace(">", ">"); + attribute = attribute.replace("<", "<"); + attribute = attribute.replace("&", "&"); + return attribute; + } + + /** + * Clones given element as in JavaScript. + * + * Deprecate this if there appears similar method into GWT someday. + * + * @param element + * @param deep + * clone child tree also + * @return + */ + public static native Element cloneNode(Element element, boolean deep) + /*-{ + return element.cloneNode(deep); + }-*/; + + public static int measureHorizontalPaddingAndBorder(Element element, + int paddingGuess) { + String originalWidth = DOM.getStyleAttribute(element, "width"); + + int originalOffsetWidth = element.getOffsetWidth(); + int widthGuess = (originalOffsetWidth - paddingGuess); + if (widthGuess < 1) { + widthGuess = 1; + } + element.getStyle().setWidth(widthGuess, Unit.PX); + int padding = element.getOffsetWidth() - widthGuess; + + element.getStyle().setProperty("width", originalWidth); + + return padding; + } + + public static int measureVerticalPaddingAndBorder(Element element, + int paddingGuess) { + String originalHeight = DOM.getStyleAttribute(element, "height"); + int originalOffsetHeight = element.getOffsetHeight(); + int widthGuess = (originalOffsetHeight - paddingGuess); + if (widthGuess < 1) { + widthGuess = 1; + } + element.getStyle().setHeight(widthGuess, Unit.PX); + int padding = element.getOffsetHeight() - widthGuess; + + element.getStyle().setProperty("height", originalHeight); + return padding; + } + + public static int measureHorizontalBorder(Element element) { + int borders; + + if (BrowserInfo.get().isIE()) { + String width = element.getStyle().getProperty("width"); + String height = element.getStyle().getProperty("height"); + + int offsetWidth = element.getOffsetWidth(); + int offsetHeight = element.getOffsetHeight(); + if (offsetHeight < 1) { + offsetHeight = 1; + } + if (offsetWidth < 1) { + offsetWidth = 10; + } + element.getStyle().setPropertyPx("height", offsetHeight); + element.getStyle().setPropertyPx("width", offsetWidth); + + borders = element.getOffsetWidth() - element.getClientWidth(); + + element.getStyle().setProperty("width", width); + element.getStyle().setProperty("height", height); + } else { + borders = element.getOffsetWidth() + - element.getPropertyInt("clientWidth"); + } + assert borders >= 0; + + return borders; + } + + public static int measureVerticalBorder(Element element) { + int borders; + if (BrowserInfo.get().isIE()) { + String width = element.getStyle().getProperty("width"); + String height = element.getStyle().getProperty("height"); + + int offsetWidth = element.getOffsetWidth(); + int offsetHeight = element.getOffsetHeight(); + if (offsetHeight < 1) { + offsetHeight = 1; + } + if (offsetWidth < 1) { + offsetWidth = 10; + } + element.getStyle().setPropertyPx("width", offsetWidth); + + element.getStyle().setPropertyPx("height", offsetHeight); + + borders = element.getOffsetHeight() + - element.getPropertyInt("clientHeight"); + + element.getStyle().setProperty("height", height); + element.getStyle().setProperty("width", width); + } else { + borders = element.getOffsetHeight() + - element.getPropertyInt("clientHeight"); + } + assert borders >= 0; + + return borders; + } + + public static int measureMarginLeft(Element element) { + return element.getAbsoluteLeft() + - element.getParentElement().getAbsoluteLeft(); + } + + public static int setHeightExcludingPaddingAndBorder(Widget widget, + String height, int paddingBorderGuess) { + if (height.equals("")) { + setHeight(widget, ""); + return paddingBorderGuess; + } else if (height.endsWith("px")) { + int pixelHeight = Integer.parseInt(height.substring(0, + height.length() - 2)); + return setHeightExcludingPaddingAndBorder(widget.getElement(), + pixelHeight, paddingBorderGuess, false); + } else { + // Set the height in unknown units + setHeight(widget, height); + // Use the offsetWidth + return setHeightExcludingPaddingAndBorder(widget.getElement(), + widget.getOffsetHeight(), paddingBorderGuess, true); + } + } + + private static void setWidth(Widget widget, String width) { + widget.getElement().getStyle().setProperty("width", width); + } + + private static void setHeight(Widget widget, String height) { + widget.getElement().getStyle().setProperty("height", height); + } + + public static int setWidthExcludingPaddingAndBorder(Widget widget, + String width, int paddingBorderGuess) { + if (width.equals("")) { + setWidth(widget, ""); + return paddingBorderGuess; + } else if (width.endsWith("px")) { + int pixelWidth = Integer.parseInt(width.substring(0, + width.length() - 2)); + return setWidthExcludingPaddingAndBorder(widget.getElement(), + pixelWidth, paddingBorderGuess, false); + } else { + setWidth(widget, width); + return setWidthExcludingPaddingAndBorder(widget.getElement(), + widget.getOffsetWidth(), paddingBorderGuess, true); + } + } + + public static int setWidthExcludingPaddingAndBorder(Element element, + int requestedWidth, int horizontalPaddingBorderGuess, + boolean requestedWidthIncludesPaddingBorder) { + + int widthGuess = requestedWidth - horizontalPaddingBorderGuess; + if (widthGuess < 0) { + widthGuess = 0; + } + + element.getStyle().setWidth(widthGuess, Unit.PX); + int captionOffsetWidth = DOM.getElementPropertyInt(element, + "offsetWidth"); + + int actualPadding = captionOffsetWidth - widthGuess; + + if (requestedWidthIncludesPaddingBorder) { + actualPadding += actualPadding; + } + + if (actualPadding != horizontalPaddingBorderGuess) { + int w = requestedWidth - actualPadding; + if (w < 0) { + // Cannot set negative width even if we would want to + w = 0; + } + element.getStyle().setWidth(w, Unit.PX); + + } + + return actualPadding; + + } + + public static int setHeightExcludingPaddingAndBorder(Element element, + int requestedHeight, int verticalPaddingBorderGuess, + boolean requestedHeightIncludesPaddingBorder) { + + int heightGuess = requestedHeight - verticalPaddingBorderGuess; + if (heightGuess < 0) { + heightGuess = 0; + } + + element.getStyle().setHeight(heightGuess, Unit.PX); + int captionOffsetHeight = DOM.getElementPropertyInt(element, + "offsetHeight"); + + int actualPadding = captionOffsetHeight - heightGuess; + + if (requestedHeightIncludesPaddingBorder) { + actualPadding += actualPadding; + } + + if (actualPadding != verticalPaddingBorderGuess) { + int h = requestedHeight - actualPadding; + if (h < 0) { + // Cannot set negative height even if we would want to + h = 0; + } + element.getStyle().setHeight(h, Unit.PX); + + } + + return actualPadding; + + } + + public static String getSimpleName(Object widget) { + if (widget == null) { + return "(null)"; + } + + String name = widget.getClass().getName(); + return name.substring(name.lastIndexOf('.') + 1); + } + + public static void setFloat(Element element, String value) { + if (BrowserInfo.get().isIE()) { + element.getStyle().setProperty("styleFloat", value); + } else { + element.getStyle().setProperty("cssFloat", value); + } + } + + private static int detectedScrollbarSize = -1; + + public static int getNativeScrollbarSize() { + if (detectedScrollbarSize < 0) { + Element scroller = DOM.createDiv(); + scroller.getStyle().setProperty("width", "50px"); + scroller.getStyle().setProperty("height", "50px"); + scroller.getStyle().setProperty("overflow", "scroll"); + scroller.getStyle().setProperty("position", "absolute"); + scroller.getStyle().setProperty("marginLeft", "-5000px"); + RootPanel.getBodyElement().appendChild(scroller); + detectedScrollbarSize = scroller.getOffsetWidth() + - scroller.getPropertyInt("clientWidth"); + + RootPanel.getBodyElement().removeChild(scroller); + } + return detectedScrollbarSize; + } + + /** + * Defers the execution of {@link #runWebkitOverflowAutoFix(Element)} + * + * @since 7.2.6 + * @param elem + * with overflow auto + */ + public static void runWebkitOverflowAutoFixDeferred(final Element elem) { + Scheduler.get().scheduleDeferred(new Command() { + + @Override + public void execute() { + WidgetUtil.runWebkitOverflowAutoFix(elem); + } + }); + + } + + /** + * Run workaround for webkits overflow auto issue. + * + * See: our bug #2138 and https://bugs.webkit.org/show_bug.cgi?id=21462 + * + * @param elem + * with overflow auto + */ + public static void runWebkitOverflowAutoFix(final Element elem) { + // Add max version if fix lands sometime to Webkit + // Starting from Opera 11.00, also a problem in Opera + if (BrowserInfo.get().requiresOverflowAutoFix()) { + final String originalOverflow = elem.getStyle().getProperty( + "overflow"); + if ("hidden".equals(originalOverflow)) { + return; + } + + // check the scrolltop value before hiding the element + final int scrolltop = elem.getScrollTop(); + final int scrollleft = elem.getScrollLeft(); + elem.getStyle().setProperty("overflow", "hidden"); + + Scheduler.get().scheduleDeferred(new Command() { + @Override + public void execute() { + // Dough, Safari scroll auto means actually just a moped + elem.getStyle().setProperty("overflow", originalOverflow); + + if (scrolltop > 0 || elem.getScrollTop() > 0) { + int scrollvalue = scrolltop; + if (scrollvalue == 0) { + // mysterious are the ways of webkits scrollbar + // handling. In some cases webkit reports bad (0) + // scrolltop before hiding the element temporary, + // sometimes after. + scrollvalue = elem.getScrollTop(); + } + // fix another bug where scrollbar remains in wrong + // position + elem.setScrollTop(scrollvalue - 1); + elem.setScrollTop(scrollvalue); + } + + // fix for #6940 : Table horizontal scroll sometimes not + // updated when collapsing/expanding columns + // Also appeared in Safari 5.1 with webkit 534 (#7667) + if ((BrowserInfo.get().isChrome() || (BrowserInfo.get() + .isSafari() && BrowserInfo.get().getWebkitVersion() >= 534)) + && (scrollleft > 0 || elem.getScrollLeft() > 0)) { + int scrollvalue = scrollleft; + + if (scrollvalue == 0) { + // mysterious are the ways of webkits scrollbar + // handling. In some cases webkit may report a bad + // (0) scrollleft before hiding the element + // temporary, sometimes after. + scrollvalue = elem.getScrollLeft(); + } + // fix another bug where scrollbar remains in wrong + // position + elem.setScrollLeft(scrollvalue - 1); + elem.setScrollLeft(scrollvalue); + } + } + }); + } + + } + + public static void alert(String string) { + if (true) { + Window.alert(string); + } + } + + /** + * Gets the border-box width for the given element, i.e. element width + + * border + padding. Always rounds up to nearest integer. + * + * @param element + * The element to check + * @return The border-box width for the element + */ + public static int getRequiredWidth(com.google.gwt.dom.client.Element element) { + int reqWidth = getRequiredWidthBoundingClientRect(element); + if (BrowserInfo.get().isIE() && !BrowserInfo.get().isIE8()) { + int csSize = getRequiredWidthComputedStyle(element); + if (csSize == reqWidth + 1) { + // If computed style reports one pixel larger than requiredWidth + // we would be rounding in the wrong direction in IE9. Round up + // instead. + // We do not always use csSize as it e.g. for 100% wide Labels + // in GridLayouts produces senseless values (see e.g. + // ThemeTestUI with Runo). + return csSize; + } + } + return reqWidth; + } + + /** + * Gets the border-box height for the given element, i.e. element height + + * border + padding. Always rounds up to nearest integer. + * + * @param element + * The element to check + * @return The border-box height for the element + */ + public static int getRequiredHeight( + com.google.gwt.dom.client.Element element) { + int reqHeight = getRequiredHeightBoundingClientRect(element); + if (BrowserInfo.get().isIE() && !BrowserInfo.get().isIE8()) { + int csSize = getRequiredHeightComputedStyle(element); + if (csSize == reqHeight + 1) { + // If computed style reports one pixel larger than + // requiredHeight we would be rounding in the wrong direction in + // IE9. Round up instead. + // We do not always use csSize as it e.g. for 100% wide Labels + // in GridLayouts produces senseless values (see e.g. + // ThemeTestUI with Runo). + return csSize; + } + } + return reqHeight; + } + + /** + * Calculates the width of the element's bounding rectangle. + * <p> + * In case the browser doesn't support bounding rectangles, the returned + * value is the offset width. + * + * @param element + * the element of which to calculate the width + * @return the width of the element + */ + public static int getRequiredWidthBoundingClientRect( + com.google.gwt.dom.client.Element element) { + return (int) getRequiredWidthBoundingClientRectDouble(element); + } + + /** + * Calculates the width of the element's bounding rectangle to subpixel + * precision. + * <p> + * In case the browser doesn't support bounding rectangles, the returned + * value is the offset width. + * + * @param element + * the element of which to calculate the width + * @return the subpixel-accurate width of the element + * @since 7.4 + */ + public static native double getRequiredWidthBoundingClientRectDouble( + com.google.gwt.dom.client.Element element) + /*-{ + if (element.getBoundingClientRect) { + var rect = element.getBoundingClientRect(); + return Math.ceil(rect.right - rect.left); + } else { + return element.offsetWidth; + } + }-*/; + + public static native int getRequiredHeightComputedStyle( + com.google.gwt.dom.client.Element element) + /*-{ + var cs = element.ownerDocument.defaultView.getComputedStyle(element); + var heightPx = cs.height; + if(heightPx == 'auto'){ + // Fallback for when IE reports auto + heightPx = @com.vaadin.client.WidgetUtil::getRequiredHeightBoundingClientRect(Lcom/google/gwt/dom/client/Element;)(element) + 'px'; + } + var borderTopPx = cs.borderTop; + var borderBottomPx = cs.borderBottom; + var paddingTopPx = cs.paddingTop; + var paddingBottomPx = cs.paddingBottom; + + var height = heightPx.substring(0,heightPx.length-2); + var border = borderTopPx.substring(0,borderTopPx.length-2)+borderBottomPx.substring(0,borderBottomPx.length-2); + var padding = paddingTopPx.substring(0,paddingTopPx.length-2)+paddingBottomPx.substring(0,paddingBottomPx.length-2); + return Math.ceil(height+border+padding); + }-*/; + + public static native int getRequiredWidthComputedStyle( + com.google.gwt.dom.client.Element element) + /*-{ + var cs = element.ownerDocument.defaultView.getComputedStyle(element); + var widthPx = cs.width; + if(widthPx == 'auto'){ + // Fallback for when IE reports auto + widthPx = @com.vaadin.client.WidgetUtil::getRequiredWidthBoundingClientRect(Lcom/google/gwt/dom/client/Element;)(element) + 'px'; + } + var borderLeftPx = cs.borderLeft; + var borderRightPx = cs.borderRight; + var paddingLeftPx = cs.paddingLeft; + var paddingRightPx = cs.paddingRight; + + var width = widthPx.substring(0,widthPx.length-2); + var border = borderLeftPx.substring(0,borderLeftPx.length-2)+borderRightPx.substring(0,borderRightPx.length-2); + var padding = paddingLeftPx.substring(0,paddingLeftPx.length-2)+paddingRightPx.substring(0,paddingRightPx.length-2); + return Math.ceil(width+border+padding); + }-*/; + + /** + * Calculates the height of the element's bounding rectangle. + * <p> + * In case the browser doesn't support bounding rectangles, the returned + * value is the offset height. + * + * @param element + * the element of which to calculate the height + * @return the height of the element + */ + public static int getRequiredHeightBoundingClientRect( + com.google.gwt.dom.client.Element element) { + return (int) getRequiredHeightBoundingClientRectDouble(element); + } + + /** + * Calculates the height of the element's bounding rectangle to subpixel + * precision. + * <p> + * In case the browser doesn't support bounding rectangles, the returned + * value is the offset height. + * + * @param element + * the element of which to calculate the height + * @return the subpixel-accurate height of the element + * @since 7.4 + */ + public static native double getRequiredHeightBoundingClientRectDouble( + com.google.gwt.dom.client.Element element) + /*-{ + var height; + if (element.getBoundingClientRect != null) { + var rect = element.getBoundingClientRect(); + height = Math.ceil(rect.bottom - rect.top); + } else { + height = element.offsetHeight; + } + return height; + }-*/; + + public static int getRequiredWidth(Widget widget) { + return getRequiredWidth(widget.getElement()); + } + + public static int getRequiredHeight(Widget widget) { + return getRequiredHeight(widget.getElement()); + } + + /** + * Detects what is currently the overflow style attribute in given element. + * + * @param pe + * the element to detect + * @return true if auto or scroll + */ + public static boolean mayHaveScrollBars(com.google.gwt.dom.client.Element pe) { + String overflow = getComputedStyle(pe, "overflow"); + if (overflow != null) { + if (overflow.equals("auto") || overflow.equals("scroll")) { + return true; + } else { + return false; + } + } else { + return false; + } + } + + /** + * A simple helper method to detect "computed style" (aka style sheets + + * element styles). Values returned differ a lot depending on browsers. + * Always be very careful when using this. + * + * @param el + * the element from which the style property is detected + * @param p + * the property to detect + * @return String value of style property + */ + private static native String getComputedStyle( + com.google.gwt.dom.client.Element el, String p) + /*-{ + try { + + if (el.currentStyle) { + // IE + return el.currentStyle[p]; + } else if (window.getComputedStyle) { + // Sa, FF, Opera + var view = el.ownerDocument.defaultView; + return view.getComputedStyle(el,null).getPropertyValue(p); + } else { + // fall back for non IE, Sa, FF, Opera + return ""; + } + } catch (e) { + return ""; + } + + }-*/; + + /** + * Will (attempt) to focus the given DOM Element. + * + * @param el + * the element to focus + */ + public static native void focus(Element el) + /*-{ + try { + el.focus(); + } catch (e) { + + } + }-*/; + + /** + * Helper method to find first instance of given Widget type found by + * traversing DOM upwards from given element. + * <p> + * <strong>Note:</strong> If {@code element} is inside some widget {@code W} + * , <em>and</em> {@code W} in turn is wrapped in a {@link Composite} + * {@code C}, this method will not find {@code W}. It returns either + * {@code C} or null, depending on whether the class parameter matches. This + * may also be the case with other Composite-like classes that hijack the + * event handling of their child widget(s). + * + * @param element + * the element where to start seeking of Widget + * @param class1 + * the Widget type to seek for + */ + @SuppressWarnings("unchecked") + public static <T> T findWidget(Element element, + Class<? extends Widget> class1) { + if (element != null) { + /* First seek for the first EventListener (~Widget) from dom */ + EventListener eventListener = null; + while (eventListener == null && element != null) { + eventListener = Event.getEventListener(element); + if (eventListener == null) { + element = element.getParentElement(); + } + } + if (eventListener instanceof Widget) { + /* + * Then find the first widget of type class1 from widget + * hierarchy + */ + Widget w = (Widget) eventListener; + while (w != null) { + if (class1 == null || w.getClass() == class1) { + return (T) w; + } + w = w.getParent(); + } + } + } + return null; + } + + /** + * Force webkit to redraw an element + * + * @param element + * The element that should be redrawn + */ + public static void forceWebkitRedraw(Element element) { + Style style = element.getStyle(); + String s = style.getProperty("webkitTransform"); + if (s == null || s.length() == 0) { + style.setProperty("webkitTransform", "scale(1)"); + } else { + style.setProperty("webkitTransform", ""); + } + } + + /** + * 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. + * + * @param e + * The element to perform the hack on + */ + public static final void forceIE8Redraw(Element e) { + if (BrowserInfo.get().isIE8()) { + forceIERedraw(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. + * + * @since 7.3 + * @param e + * The element to perform the hack on + */ + public static void forceIERedraw(Element e) { + if (BrowserInfo.get().isIE()) { + setStyleTemporarily(e, "zoom", "1"); + } + } + + /** + * 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. + * + * @param element + * The element to detach and re-attach + */ + public static void detachAttach(Element element) { + if (element == null) { + return; + } + + Node nextSibling = element.getNextSibling(); + Node parent = element.getParentNode(); + if (parent == null) { + return; + } + + parent.removeChild(element); + if (nextSibling == null) { + parent.appendChild(element); + } else { + parent.insertBefore(element, nextSibling); + } + + } + + public static void sinkOnloadForImages(Element element) { + NodeList<com.google.gwt.dom.client.Element> imgElements = element + .getElementsByTagName("img"); + for (int i = 0; i < imgElements.getLength(); i++) { + DOM.sinkEvents(imgElements.getItem(i), Event.ONLOAD); + } + + } + + /** + * Returns the index of the childElement within its parent. + * + * @param subElement + * @return + */ + public static int getChildElementIndex(Element childElement) { + int idx = 0; + Node n = childElement; + while ((n = n.getPreviousSibling()) != null) { + idx++; + } + + return idx; + } + + /** + * 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) + * + * @param element + * The target element + * @param styleProperty + * The name of the property to set + * @param tempValue + * The temporary value + */ + public static void setStyleTemporarily(Element element, + final String styleProperty, String tempValue) { + final Style style = element.getStyle(); + final String currentValue = style.getProperty(styleProperty); + + style.setProperty(styleProperty, tempValue); + element.getOffsetWidth(); + style.setProperty(styleProperty, currentValue); + + } + + /** + * 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. + * + * @param event + * @return + */ + public static int getTouchOrMouseClientX(Event event) { + if (isTouchEvent(event)) { + return event.getChangedTouches().get(0).getClientX(); + } else { + return event.getClientX(); + } + } + + /** + * 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. + * + * @param event + * the mouse event to get coordinates from + * @return the element at the coordinates of the event + */ + public static Element getElementUnderMouse(NativeEvent event) { + int pageX = getTouchOrMouseClientX(event); + int pageY = getTouchOrMouseClientY(event); + + return getElementFromPoint(pageX, pageY); + } + + /** + * 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. + * + * @param event + * @return + */ + public static int getTouchOrMouseClientY(Event event) { + if (isTouchEvent(event)) { + return event.getChangedTouches().get(0).getClientY(); + } else { + return event.getClientY(); + } + } + + /** + * + * @see #getTouchOrMouseClientY(Event) + * @param currentGwtEvent + * @return + */ + public static int getTouchOrMouseClientY(NativeEvent currentGwtEvent) { + return getTouchOrMouseClientY(Event.as(currentGwtEvent)); + } + + /** + * @see #getTouchOrMouseClientX(Event) + * + * @param event + * @return + */ + public static int getTouchOrMouseClientX(NativeEvent event) { + return getTouchOrMouseClientX(Event.as(event)); + } + + public static boolean isTouchEvent(Event event) { + return event.getType().contains("touch"); + } + + public static boolean isTouchEvent(NativeEvent event) { + return isTouchEvent(Event.as(event)); + } + + public static void simulateClickFromTouchEvent(Event touchevent, + Widget widget) { + Touch touch = touchevent.getChangedTouches().get(0); + final NativeEvent createMouseUpEvent = Document.get() + .createMouseUpEvent(0, touch.getScreenX(), touch.getScreenY(), + touch.getClientX(), touch.getClientY(), false, false, + false, false, NativeEvent.BUTTON_LEFT); + final NativeEvent createMouseDownEvent = Document.get() + .createMouseDownEvent(0, touch.getScreenX(), + touch.getScreenY(), touch.getClientX(), + touch.getClientY(), false, false, false, false, + NativeEvent.BUTTON_LEFT); + final NativeEvent createMouseClickEvent = Document.get() + .createClickEvent(0, touch.getScreenX(), touch.getScreenY(), + touch.getClientX(), touch.getClientY(), false, false, + false, false); + + /* + * Get target with element from point as we want the actual element, not + * the one that sunk the event. + */ + final Element target = getElementFromPoint(touch.getClientX(), + touch.getClientY()); + + /* + * Fixes infocusable form fields in Safari of iOS 5.x and some Android + * browsers. + */ + Widget targetWidget = findWidget(target, null); + if (targetWidget instanceof com.google.gwt.user.client.ui.Focusable) { + final com.google.gwt.user.client.ui.Focusable toBeFocusedWidget = (com.google.gwt.user.client.ui.Focusable) targetWidget; + toBeFocusedWidget.setFocus(true); + } else if (targetWidget instanceof Focusable) { + ((Focusable) targetWidget).focus(); + } + + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + @Override + public void execute() { + try { + target.dispatchEvent(createMouseDownEvent); + target.dispatchEvent(createMouseUpEvent); + target.dispatchEvent(createMouseClickEvent); + } catch (Exception e) { + } + + } + }); + + } + + /** + * Gets the currently focused element. + * + * @return The active element or null if no active element could be found. + */ + public native static Element getFocusedElement() + /*-{ + if ($wnd.document.activeElement) { + return $wnd.document.activeElement; + } + + return null; + }-*/; + + /** + * Gets currently focused element and checks if it's editable + * + * @since 7.4 + * + * @return true if focused element is editable + */ + public static boolean isFocusedElementEditable() { + Element focusedElement = WidgetUtil.getFocusedElement(); + if (focusedElement != null) { + String tagName = focusedElement.getTagName(); + String contenteditable = focusedElement + .getAttribute("contenteditable"); + + return "textarea".equalsIgnoreCase(tagName) + || "input".equalsIgnoreCase(tagName) + || "true".equalsIgnoreCase(contenteditable); + } + return false; + } + + /** + * 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. + * + * @param widget + * @return true if attached and displayed + */ + public static boolean isAttachedAndDisplayed(Widget widget) { + if (widget.isAttached()) { + /* + * Failfast using offset size, then by iterating the widget tree + */ + boolean notZeroSized = widget.getOffsetHeight() > 0 + || widget.getOffsetWidth() > 0; + return notZeroSized || checkVisibilityRecursively(widget); + } else { + return false; + } + } + + private static boolean checkVisibilityRecursively(Widget widget) { + if (widget.isVisible()) { + Widget parent = widget.getParent(); + if (parent == null) { + return true; // root panel + } else { + return checkVisibilityRecursively(parent); + } + } else { + return false; + } + } + + /** + * Scrolls an element into view vertically only. Modified version of + * Element.scrollIntoView. + * + * @param elem + * The element to scroll into view + */ + public static native void scrollIntoViewVertically(Element elem) + /*-{ + var top = elem.offsetTop; + var height = elem.offsetHeight; + + if (elem.parentNode != elem.offsetParent) { + top -= elem.parentNode.offsetTop; + } + + var cur = elem.parentNode; + while (cur && (cur.nodeType == 1)) { + if (top < cur.scrollTop) { + cur.scrollTop = top; + } + if (top + height > cur.scrollTop + cur.clientHeight) { + cur.scrollTop = (top + height) - cur.clientHeight; + } + + var offsetTop = cur.offsetTop; + if (cur.parentNode != cur.offsetParent) { + offsetTop -= cur.parentNode.offsetTop; + } + + top += offsetTop - cur.scrollTop; + cur = cur.parentNode; + } + }-*/; + + /** + * Checks if the given event is either a touch event or caused by the left + * mouse button + * + * @param event + * @return true if the event is a touch event or caused by the left mouse + * button, false otherwise + */ + public static boolean isTouchEventOrLeftMouseButton(Event event) { + boolean touchEvent = WidgetUtil.isTouchEvent(event); + return touchEvent || event.getButton() == Event.BUTTON_LEFT; + } + + /** + * Resolve a relative URL to an absolute URL based on the current document's + * location. + * + * @param url + * a string with the relative URL to resolve + * @return the corresponding absolute URL as a string + */ + public static String getAbsoluteUrl(String url) { + if (BrowserInfo.get().isIE8()) { + // The hard way - must use innerHTML and attach to DOM in IE8 + DivElement divElement = Document.get().createDivElement(); + divElement.getStyle().setDisplay(Display.NONE); + + RootPanel.getBodyElement().appendChild(divElement); + divElement.setInnerHTML("<a href='" + escapeAttribute(url) + + "' ></a>"); + + AnchorElement a = divElement.getChild(0).cast(); + String href = a.getHref(); + + RootPanel.getBodyElement().removeChild(divElement); + return href; + } else { + AnchorElement a = Document.get().createAnchorElement(); + a.setHref(url); + return a.getHref(); + } + } + + /** + * 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) + * + * @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 + */ + public native static void setSelectionRange(Element elem, int pos, + int length, String direction) + /*-{ + try { + elem.setSelectionRange(pos, pos + length, direction); + } catch (e) { + // Firefox throws exception if TextBox is not visible, even if attached + } + }-*/; + + /** + * 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); + }-*/; + + /** + * The allowed value inaccuracy when comparing two double-typed pixel + * values. + * <p> + * Since we're comparing pixels on a screen, epsilon must be less than 1. + * 0.49 was deemed a perfectly fine and beautifully round number. + */ + public static final double PIXEL_EPSILON = 0.49d; + + /** + * Compares two double values with the error margin of + * {@link #PIXEL_EPSILON} (i.e. {@value #PIXEL_EPSILON}) + * + * @param num1 + * the first value for which to compare equality + * @param num2 + * the second value for which to compare equality + * @since 7.4 + * + * @return true if the values are considered equals; false otherwise + */ + public static boolean pixelValuesEqual(final double num1, final double num2) { + return Math.abs(num1 - num2) <= PIXEL_EPSILON; + } + + /** + * Wrap a css size value and its unit and translate back and forth to the + * string representation.<br/> + * Eg. 50%, 123px, ... + * + * @since 7.2.6 + * @author Vaadin Ltd + */ + @SuppressWarnings("serial") + public static class CssSize implements Serializable { + + /* + * Map the size units with their type. + */ + private static Map<String, Unit> type2Unit = new HashMap<String, Style.Unit>(); + static { + for (Unit unit : Unit.values()) { + type2Unit.put(unit.getType(), unit); + } + } + + /** + * Gets the unit value by its type. + * + * @param type + * the type of the unit as found in the style. + * @return the unit value. + */ + public static Unit unitByType(String type) { + return type2Unit.get(type); + } + + /* + * Regex to parse the size. + */ + private static final RegExp sizePattern = RegExp + .compile(SharedUtil.SIZE_PATTERN); + + /** + * Parse the size from string format to {@link CssSize}. + * + * @param s + * the size as string. + * @return a {@link CssSize} object. + */ + public static CssSize fromString(String s) { + if (s == null) { + return null; + } + + s = s.trim(); + if ("".equals(s)) { + return null; + } + + float size = 0; + Unit unit = null; + + MatchResult matcher = sizePattern.exec(s); + if (matcher.getGroupCount() > 1) { + + size = Float.parseFloat(matcher.getGroup(1)); + if (size < 0) { + size = -1; + unit = Unit.PX; + + } else { + String symbol = matcher.getGroup(2); + unit = unitByType(symbol); + } + } else { + throw new IllegalArgumentException("Invalid size argument: \"" + + s + "\" (should match " + sizePattern.getSource() + + ")"); + } + return new CssSize(size, unit); + } + + /** + * Creates a {@link CssSize} using a value and its measurement unit. + * + * @param value + * the value. + * @param unit + * the unit. + * @return the {@link CssSize} object. + */ + public static CssSize fromValueUnit(float value, Unit unit) { + return new CssSize(value, unit); + } + + /* + * The value. + */ + private final float value; + + /* + * The measure unit. + */ + private final Unit unit; + + private CssSize(float value, Unit unit) { + this.value = value; + this.unit = unit; + } + + /** + * Gets the value for this css size. + * + * @return the value. + */ + public float getValue() { + return value; + } + + /** + * Gets the measurement unit for this css size. + * + * @return the unit. + */ + public Unit getUnit() { + return unit; + } + + @Override + public String toString() { + return value + unit.getType(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof CssSize) { + CssSize size = (CssSize) obj; + return size.value == value && size.unit == unit; + } + + return false; + } + + /** + * Check whether the two sizes are equals. + * + * @param cssSize1 + * the first size to compare. + * @param cssSize2 + * the other size to compare with the first one. + * @return true if the two sizes are equals, otherwise false. + */ + public static boolean equals(String cssSize1, String cssSize2) { + return CssSize.fromString(cssSize1).equals( + CssSize.fromString(cssSize2)); + } + + } + + private static Logger getLogger() { + return Logger.getLogger(WidgetUtil.class.getName()); + } + +} diff --git a/client/src/com/vaadin/client/communication/StateChangeEvent.java b/client/src/com/vaadin/client/communication/StateChangeEvent.java index 7db1d1b249..eeb0a76fb9 100644 --- a/client/src/com/vaadin/client/communication/StateChangeEvent.java +++ b/client/src/com/vaadin/client/communication/StateChangeEvent.java @@ -25,7 +25,7 @@ import com.vaadin.client.FastStringSet; import com.vaadin.client.JsArrayObject; import com.vaadin.client.Profiler; import com.vaadin.client.ServerConnector; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler; import com.vaadin.client.metadata.NoDataException; import com.vaadin.client.metadata.Property; @@ -204,7 +204,7 @@ public class StateChangeEvent extends return true; } else if (stateJson != null) { // Check whether it's in the json object - return isInJson(property, Util.json2jso(stateJson)); + return isInJson(property, WidgetUtil.json2jso(stateJson)); } else { // Legacy cases if (changedProperties != null) { diff --git a/client/src/com/vaadin/client/componentlocator/LegacyLocatorStrategy.java b/client/src/com/vaadin/client/componentlocator/LegacyLocatorStrategy.java index 5df9854038..2d374d3ee7 100644 --- a/client/src/com/vaadin/client/componentlocator/LegacyLocatorStrategy.java +++ b/client/src/com/vaadin/client/componentlocator/LegacyLocatorStrategy.java @@ -32,6 +32,7 @@ import com.vaadin.client.ConnectorMap; import com.vaadin.client.ServerConnector; import com.vaadin.client.Util; import com.vaadin.client.VCaption; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.SubPartAware; import com.vaadin.client.ui.VCssLayout; import com.vaadin.client.ui.VGridLayout; @@ -211,10 +212,10 @@ public class LegacyLocatorStrategy implements LocatorStrategy { // widget to which the path is relative. Otherwise, the current // implementation simply interprets the path as if baseElement was // null. - Widget baseWidget = Util.findWidget(baseElement, null); + Widget baseWidget = WidgetUtil.findWidget(baseElement, null); Widget w = getWidgetFromPath(widgetPath, baseWidget); - if (w == null || !Util.isAttachedAndDisplayed(w)) { + if (w == null || !WidgetUtil.isAttachedAndDisplayed(w)) { return null; } if (parts.length == 1) { @@ -333,7 +334,7 @@ public class LegacyLocatorStrategy implements LocatorStrategy { String childIndexString = part.substring("domChild[".length(), part.length() - 1); - if (Util.findWidget(baseElement, null) instanceof VAbstractOrderedLayout) { + if (WidgetUtil.findWidget(baseElement, null) instanceof VAbstractOrderedLayout) { if (element.hasChildNodes()) { Element e = element.getFirstChildElement().cast(); String cn = e.getClassName(); @@ -454,7 +455,7 @@ public class LegacyLocatorStrategy implements LocatorStrategy { if (basePath == null) { return null; } - String simpleName = Util.getSimpleName(w); + String simpleName = WidgetUtil.getSimpleName(w); /* * Check if the parent implements Iterable. At least VPopupView does not @@ -474,7 +475,7 @@ public class LegacyLocatorStrategy implements LocatorStrategy { return basePath + PARENTCHILD_SEPARATOR + simpleName + "[" + pos + "]"; } - String simpleName2 = Util.getSimpleName(child); + String simpleName2 = WidgetUtil.getSimpleName(child); if (simpleName.equals(simpleName2)) { pos++; } @@ -605,8 +606,8 @@ public class LegacyLocatorStrategy implements LocatorStrategy { // the same type before it int nextIndex = 0; for (Widget child : layout) { - boolean matchingType = nextWidgetClassName.equals(Util - .getSimpleName(child)); + boolean matchingType = nextWidgetClassName + .equals(WidgetUtil.getSimpleName(child)); if (matchingType && widgetPosition == 0) { // This is the n:th child that we looked for break; @@ -660,7 +661,7 @@ public class LegacyLocatorStrategy implements LocatorStrategy { while (iterator.hasNext()) { Widget child = iterator.next(); - String simpleName2 = Util.getSimpleName(child); + String simpleName2 = WidgetUtil.getSimpleName(child); if (!widgetClassName.equals(simpleName2) && child instanceof Slot) { @@ -670,7 +671,7 @@ public class LegacyLocatorStrategy implements LocatorStrategy { * directly checking the stuff inside the slot */ child = ((Slot) child).getWidget(); - simpleName2 = Util.getSimpleName(child); + simpleName2 = WidgetUtil.getSimpleName(child); } if (widgetClassName.equals(simpleName2)) { diff --git a/client/src/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java b/client/src/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java index 44bdeddff3..1cc12a0ce2 100644 --- a/client/src/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java +++ b/client/src/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java @@ -29,6 +29,7 @@ import com.vaadin.client.ApplicationConnection; import com.vaadin.client.ComponentConnector; import com.vaadin.client.HasComponentsConnector; import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.metadata.Property; import com.vaadin.client.metadata.TypeDataStore; import com.vaadin.client.ui.AbstractConnector; @@ -644,7 +645,7 @@ public class VaadinFinderLocatorStrategy implements LocatorStrategy { // If the server-side class name didn't match, fall back to testing for // the explicit widget name - String widget = Util.getSimpleName(connector.getWidget()); + String widget = WidgetUtil.getSimpleName(connector.getWidget()); return widgetName.equals(widget) || widgetName.equals(widget + ".class"); diff --git a/client/src/com/vaadin/client/connectors/AbstractRendererConnector.java b/client/src/com/vaadin/client/connectors/AbstractRendererConnector.java index 5bcbe6a286..6f717d41ef 100644 --- a/client/src/com/vaadin/client/connectors/AbstractRendererConnector.java +++ b/client/src/com/vaadin/client/connectors/AbstractRendererConnector.java @@ -16,7 +16,7 @@ package com.vaadin.client.connectors; import com.vaadin.client.ServerConnector; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.communication.JsonDecoder; import com.vaadin.client.extensions.AbstractExtensionConnector; import com.vaadin.client.metadata.NoDataException; @@ -57,7 +57,7 @@ public abstract class AbstractRendererConnector<T> extends if (presentationType == null) { throw new IllegalStateException( "No presentation type found for " - + Util.getSimpleName(this) + + WidgetUtil.getSimpleName(this) + ". This may be caused by some unspecified problem in widgetset compilation."); } } @@ -110,7 +110,7 @@ public abstract class AbstractRendererConnector<T> extends } catch (NoDataException e) { throw new IllegalStateException( "Default implementation of createRenderer() does not work for " - + Util.getSimpleName(this) + + WidgetUtil.getSimpleName(this) + ". This might be caused by explicitely using " + "super.createRenderer() or some unspecified " + "problem with the widgetset compilation.", e); diff --git a/client/src/com/vaadin/client/debug/internal/AnalyzeLayoutsPanel.java b/client/src/com/vaadin/client/debug/internal/AnalyzeLayoutsPanel.java index 1238d88345..56bff25f6b 100644 --- a/client/src/com/vaadin/client/debug/internal/AnalyzeLayoutsPanel.java +++ b/client/src/com/vaadin/client/debug/internal/AnalyzeLayoutsPanel.java @@ -40,7 +40,7 @@ import com.vaadin.client.ComputedStyle; import com.vaadin.client.ConnectorMap; import com.vaadin.client.ServerConnector; import com.vaadin.client.SimpleTree; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.ValueMap; /** @@ -112,9 +112,10 @@ public class AnalyzeLayoutsPanel extends FlowPanel { final ServerConnector parent = connector.getParent(); final String parentId = parent.getConnectorId(); - final Label errorDetails = new Label(Util.getSimpleName(connector) - + "[" + connector.getConnectorId() + "]" + " inside " - + Util.getSimpleName(parent)); + final Label errorDetails = new Label( + WidgetUtil.getSimpleName(connector) + "[" + + connector.getConnectorId() + "]" + " inside " + + WidgetUtil.getSimpleName(parent)); if (parent instanceof ComponentConnector) { final ComponentConnector parentConnector = (ComponentConnector) parent; @@ -172,7 +173,7 @@ public class AnalyzeLayoutsPanel extends FlowPanel { Highlight.show(connector); final SimpleTree errorNode = new SimpleTree( - Util.getSimpleName(connector) + " id: " + pid); + WidgetUtil.getSimpleName(connector) + " id: " + pid); errorNode.addDomHandler(new MouseOverHandler() { @Override public void onMouseOver(MouseOverEvent event) { diff --git a/client/src/com/vaadin/client/debug/internal/ConnectorInfoPanel.java b/client/src/com/vaadin/client/debug/internal/ConnectorInfoPanel.java index 0b49fa7aaf..45cfe24c0d 100644 --- a/client/src/com/vaadin/client/debug/internal/ConnectorInfoPanel.java +++ b/client/src/com/vaadin/client/debug/internal/ConnectorInfoPanel.java @@ -24,7 +24,7 @@ import com.google.gwt.user.client.ui.HTML; import com.vaadin.client.ComponentConnector; import com.vaadin.client.JsArrayObject; import com.vaadin.client.ServerConnector; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.VConsole; import com.vaadin.client.metadata.NoDataException; import com.vaadin.client.metadata.Property; @@ -51,7 +51,7 @@ public class ConnectorInfoPanel extends FlowPanel { ignoreProperties.add("id"); String html = getRowHTML("Id", connector.getConnectorId()); - html += getRowHTML("Connector", Util.getSimpleName(connector)); + html += getRowHTML("Connector", WidgetUtil.getSimpleName(connector)); if (connector instanceof ComponentConnector) { ComponentConnector component = (ComponentConnector) connector; @@ -62,7 +62,7 @@ public class ConnectorInfoPanel extends FlowPanel { AbstractComponentState componentState = component.getState(); html += getRowHTML("Widget", - Util.getSimpleName(component.getWidget())); + WidgetUtil.getSimpleName(component.getWidget())); html += getRowHTML("Caption", componentState.caption); html += getRowHTML("Description", componentState.description); html += getRowHTML("Width", componentState.width + " (actual: " @@ -95,7 +95,8 @@ public class ConnectorInfoPanel extends FlowPanel { return "<div class=\"" + VDebugWindow.STYLENAME + "-row\"><span class=\"caption\">" + caption + "</span><span class=\"value\">" - + Util.escapeHTML(String.valueOf(value)) + "</span></div>"; + + WidgetUtil.escapeHTML(String.valueOf(value)) + + "</span></div>"; } /** diff --git a/client/src/com/vaadin/client/debug/internal/HierarchySection.java b/client/src/com/vaadin/client/debug/internal/HierarchySection.java index 404ac430df..c772a9d267 100644 --- a/client/src/com/vaadin/client/debug/internal/HierarchySection.java +++ b/client/src/com/vaadin/client/debug/internal/HierarchySection.java @@ -35,6 +35,7 @@ import com.vaadin.client.ComponentConnector; import com.vaadin.client.ServerConnector; import com.vaadin.client.Util; import com.vaadin.client.ValueMap; +import com.vaadin.client.WidgetUtil; /** * Provides functionality for examining the UI component hierarchy. @@ -240,7 +241,7 @@ public class HierarchySection implements Section { } if (event.getTypeInt() == Event.ONMOUSEMOVE) { Highlight.hideAll(); - Element eventTarget = Util.getElementFromPoint(event + Element eventTarget = WidgetUtil.getElementFromPoint(event .getNativeEvent().getClientX(), event.getNativeEvent() .getClientY()); if (VDebugWindow.get().getElement().isOrHasChild(eventTarget)) { @@ -272,7 +273,7 @@ public class HierarchySection implements Section { event.consume(); event.getNativeEvent().stopPropagation(); stopFind(); - Element eventTarget = Util.getElementFromPoint(event + Element eventTarget = WidgetUtil.getElementFromPoint(event .getNativeEvent().getClientX(), event.getNativeEvent() .getClientY()); for (ApplicationConnection a : ApplicationConfiguration diff --git a/client/src/com/vaadin/client/debug/internal/TestBenchSection.java b/client/src/com/vaadin/client/debug/internal/TestBenchSection.java index 355565f706..d0b6b10722 100644 --- a/client/src/com/vaadin/client/debug/internal/TestBenchSection.java +++ b/client/src/com/vaadin/client/debug/internal/TestBenchSection.java @@ -41,6 +41,7 @@ import com.vaadin.client.ComponentConnector; import com.vaadin.client.ServerConnector; import com.vaadin.client.Util; import com.vaadin.client.ValueMap; +import com.vaadin.client.WidgetUtil; /** * Provides functionality for picking selectors for Vaadin TestBench. @@ -62,7 +63,8 @@ public class TestBenchSection implements Section { String html = "<div class=\"" + VDebugWindow.STYLENAME + "-selector\"><span class=\"tb-selector\">" - + Util.escapeHTML(path.getElementQuery()) + "</span></div>"; + + WidgetUtil.escapeHTML(path.getElementQuery()) + + "</span></div>"; setHTML(html); addMouseOverHandler(this); @@ -216,7 +218,7 @@ public class TestBenchSection implements Section { } if (event.getTypeInt() == Event.ONMOUSEMOVE || event.getTypeInt() == Event.ONCLICK) { - Element eventTarget = Util.getElementFromPoint(event + Element eventTarget = WidgetUtil.getElementFromPoint(event .getNativeEvent().getClientX(), event.getNativeEvent() .getClientY()); if (VDebugWindow.get().getElement().isOrHasChild(eventTarget)) { @@ -230,8 +232,9 @@ public class TestBenchSection implements Section { // make sure that not finding the highlight element only Highlight.hideAll(); - eventTarget = Util.getElementFromPoint(event.getNativeEvent() - .getClientX(), event.getNativeEvent().getClientY()); + eventTarget = WidgetUtil.getElementFromPoint(event + .getNativeEvent().getClientX(), event.getNativeEvent() + .getClientY()); ComponentConnector connector = findConnector(eventTarget); if (event.getTypeInt() == Event.ONMOUSEMOVE) { diff --git a/client/src/com/vaadin/client/extensions/ResponsiveConnector.java b/client/src/com/vaadin/client/extensions/ResponsiveConnector.java index 8e349bac7b..59e6600949 100644 --- a/client/src/com/vaadin/client/extensions/ResponsiveConnector.java +++ b/client/src/com/vaadin/client/extensions/ResponsiveConnector.java @@ -357,7 +357,7 @@ public class ResponsiveConnector extends AbstractExtensionConnector implements /** * Forces IE8 to reinterpret CSS rules. - * {@link com.vaadin.client.Util#forceIE8Redraw(com.google.gwt.dom.client.Element)} + * {@link com.vaadin.client.WidgetUtil#forceIE8Redraw(com.google.gwt.dom.client.Element)} * doesn't work in this case. * * @param element diff --git a/client/src/com/vaadin/client/extensions/javascriptmanager/JavaScriptManagerConnector.java b/client/src/com/vaadin/client/extensions/javascriptmanager/JavaScriptManagerConnector.java index d48571452e..7950d2f94a 100644 --- a/client/src/com/vaadin/client/extensions/javascriptmanager/JavaScriptManagerConnector.java +++ b/client/src/com/vaadin/client/extensions/javascriptmanager/JavaScriptManagerConnector.java @@ -22,7 +22,7 @@ import java.util.Set; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArray; import com.vaadin.client.ServerConnector; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.communication.JavaScriptMethodInvocation; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.extensions.AbstractExtensionConnector; @@ -116,7 +116,8 @@ public class JavaScriptManagerConnector extends AbstractExtensionConnector { }-*/; public void sendRpc(String name, JsArray<JavaScriptObject> arguments) { - Object[] parameters = new Object[] { name, Util.jso2json(arguments) }; + Object[] parameters = new Object[] { name, + WidgetUtil.jso2json(arguments) }; /* * Must invoke manually as the RPC interface can't be used in GWT diff --git a/client/src/com/vaadin/client/renderers/ClickableRenderer.java b/client/src/com/vaadin/client/renderers/ClickableRenderer.java index bd865e52f6..f5368d31c9 100644 --- a/client/src/com/vaadin/client/renderers/ClickableRenderer.java +++ b/client/src/com/vaadin/client/renderers/ClickableRenderer.java @@ -26,7 +26,7 @@ import com.google.gwt.event.shared.EventHandler; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.user.client.ui.Widget; import com.google.web.bindery.event.shared.HandlerRegistration; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.widget.escalator.Cell; import com.vaadin.client.widget.escalator.RowContainer; import com.vaadin.client.widget.grid.CellReference; @@ -167,15 +167,16 @@ public abstract class ClickableRenderer<T, W extends Widget> extends * <strong>Note:</strong> This method may not work reliably if the grid * in question is wrapped in a {@link Composite} <em>unless</em> the * element is inside another widget that is a child of the wrapped grid; - * please refer to the note in {@link Util#findWidget(Element, Class) - * Util.findWidget} for details. + * please refer to the note in + * {@link WidgetUtil#findWidget(Element, Class) Util.findWidget} for + * details. * * @param e * the element whose parent grid to find * @return the parent grid or null if none found. */ private static Grid<?> findClosestParentGrid(Element e) { - Widget w = Util.findWidget(e, null); + Widget w = WidgetUtil.findWidget(e, null); while (w != null && !(w instanceof Grid)) { w = w.getParent(); diff --git a/client/src/com/vaadin/client/renderers/WidgetRenderer.java b/client/src/com/vaadin/client/renderers/WidgetRenderer.java index cb648c48bf..668ec7b59e 100644 --- a/client/src/com/vaadin/client/renderers/WidgetRenderer.java +++ b/client/src/com/vaadin/client/renderers/WidgetRenderer.java @@ -17,7 +17,7 @@ package com.vaadin.client.renderers; import com.google.gwt.dom.client.TableCellElement; import com.google.gwt.user.client.ui.Widget; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.widget.grid.RendererCellReference; /** @@ -97,7 +97,7 @@ public abstract class WidgetRenderer<T, W extends Widget> extends */ protected static <W extends Widget> W getWidget(TableCellElement e, Class<W> klass) { - W w = Util.findWidget(e.getFirstChildElement(), klass); + W w = WidgetUtil.findWidget(e.getFirstChildElement(), klass); assert w == null || w.getElement() == e.getFirstChildElement() : "Widget not found inside cell"; return w; } diff --git a/client/src/com/vaadin/client/ui/AbstractClickEventHandler.java b/client/src/com/vaadin/client/ui/AbstractClickEventHandler.java index c08656c4d9..a2c54ec7ca 100644 --- a/client/src/com/vaadin/client/ui/AbstractClickEventHandler.java +++ b/client/src/com/vaadin/client/ui/AbstractClickEventHandler.java @@ -32,7 +32,7 @@ import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Event.NativePreviewEvent; import com.google.gwt.user.client.Event.NativePreviewHandler; import com.vaadin.client.ComponentConnector; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.VConsole; public abstract class AbstractClickEventHandler implements MouseDownHandler, @@ -72,8 +72,8 @@ public abstract class AbstractClickEventHandler implements MouseDownHandler, // Event's reported target not always correct if event // capture is in use - Element elementUnderMouse = Util.getElementUnderMouse(event - .getNativeEvent()); + Element elementUnderMouse = WidgetUtil + .getElementUnderMouse(event.getNativeEvent()); if (lastMouseDownTarget != null && elementUnderMouse == lastMouseDownTarget) { mouseUpPreviewMatched = true; @@ -171,7 +171,8 @@ public abstract class AbstractClickEventHandler implements MouseDownHandler, * When getting a mousedown event, we must detect where the * corresponding mouseup event if it's on a different part of the page. */ - lastMouseDownTarget = Util.getElementUnderMouse(event.getNativeEvent()); + lastMouseDownTarget = WidgetUtil.getElementUnderMouse(event + .getNativeEvent()); mouseUpPreviewMatched = false; mouseUpEventPreviewRegistration = Event .addNativePreviewHandler(mouseUpPreviewHandler); @@ -188,7 +189,7 @@ public abstract class AbstractClickEventHandler implements MouseDownHandler, if (hasEventListener() && mouseUpPreviewMatched && lastMouseDownTarget != null - && Util.getElementUnderMouse(event.getNativeEvent()) == lastMouseDownTarget + && WidgetUtil.getElementUnderMouse(event.getNativeEvent()) == lastMouseDownTarget && shouldFireEvent(event)) { // "Click" with left, right or middle button fireClick(event.getNativeEvent()); diff --git a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java index c3f14be40c..17be098a58 100644 --- a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java +++ b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java @@ -32,6 +32,7 @@ import com.vaadin.client.TooltipInfo; import com.vaadin.client.UIDL; import com.vaadin.client.Util; import com.vaadin.client.VConsole; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.metadata.NoDataException; import com.vaadin.client.metadata.Type; @@ -89,7 +90,7 @@ public abstract class AbstractComponentConnector extends AbstractConnector } catch (NoDataException e) { throw new IllegalStateException( "Default implementation of createWidget() does not work for " - + Util.getSimpleName(this) + + WidgetUtil.getSimpleName(this) + ". This might be caused by explicitely using " + "super.createWidget() or some unspecified " + "problem with the widgetset compilation.", e); @@ -106,10 +107,10 @@ public abstract class AbstractComponentConnector extends AbstractConnector public Widget getWidget() { if (widget == null) { Profiler.enter("AbstractComponentConnector.createWidget for " - + Util.getSimpleName(this)); + + WidgetUtil.getSimpleName(this)); widget = createWidget(); Profiler.leave("AbstractComponentConnector.createWidget for " - + Util.getSimpleName(this)); + + WidgetUtil.getSimpleName(this)); } return widget; diff --git a/client/src/com/vaadin/client/ui/AbstractConnector.java b/client/src/com/vaadin/client/ui/AbstractConnector.java index e93ea0f507..a3038058ed 100644 --- a/client/src/com/vaadin/client/ui/AbstractConnector.java +++ b/client/src/com/vaadin/client/ui/AbstractConnector.java @@ -34,6 +34,7 @@ import com.vaadin.client.Profiler; import com.vaadin.client.ServerConnector; import com.vaadin.client.Util; import com.vaadin.client.VConsole; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.communication.RpcProxy; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler; @@ -120,11 +121,13 @@ public abstract class AbstractConnector implements ServerConnector, addStateChangeHandler(this); if (Profiler.isEnabled()) { - Profiler.enter("AbstractConnector.init " + Util.getSimpleName(this)); + Profiler.enter("AbstractConnector.init " + + WidgetUtil.getSimpleName(this)); } init(); if (Profiler.isEnabled()) { - Profiler.leave("AbstractConnector.init " + Util.getSimpleName(this)); + Profiler.leave("AbstractConnector.init " + + WidgetUtil.getSimpleName(this)); } Profiler.leave("AbstractConnector.doInit"); } @@ -214,8 +217,8 @@ public abstract class AbstractConnector implements ServerConnector, public void fireEvent(GwtEvent<?> event) { String profilerKey = null; if (Profiler.isEnabled()) { - profilerKey = "Fire " + Util.getSimpleName(event) + " for " - + Util.getSimpleName(this); + profilerKey = "Fire " + WidgetUtil.getSimpleName(event) + " for " + + WidgetUtil.getSimpleName(this); Profiler.enter(profilerKey); } if (handlerManager != null) { @@ -377,7 +380,7 @@ public abstract class AbstractConnector implements ServerConnector, } catch (NoDataException e) { throw new IllegalStateException( "There is no information about the state for " - + Util.getSimpleName(this) + + WidgetUtil.getSimpleName(this) + ". Did you remember to compile the right widgetset?", e); } @@ -391,7 +394,7 @@ public abstract class AbstractConnector implements ServerConnector, } catch (NoDataException e) { throw new IllegalStateException( "There is no information about the state for " - + Util.getSimpleName(connector) + + WidgetUtil.getSimpleName(connector) + ". Did you remember to compile the right widgetset?", e); } diff --git a/client/src/com/vaadin/client/ui/MediaBaseConnector.java b/client/src/com/vaadin/client/ui/MediaBaseConnector.java index cebb2e3836..fdd9610517 100644 --- a/client/src/com/vaadin/client/ui/MediaBaseConnector.java +++ b/client/src/com/vaadin/client/ui/MediaBaseConnector.java @@ -15,7 +15,7 @@ */ package com.vaadin.client.ui; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.shared.communication.URLReference; import com.vaadin.shared.ui.AbstractMediaState; @@ -78,7 +78,7 @@ public abstract class MediaBaseConnector extends AbstractComponentConnector { if (altText == null || "".equals(altText)) { altText = getDefaultAltHtml(); } else if (!getState().htmlContentAllowed) { - altText = Util.escapeHTML(altText); + altText = WidgetUtil.escapeHTML(altText); } getWidget().setAltText(altText); } diff --git a/client/src/com/vaadin/client/ui/VAbstractSplitPanel.java b/client/src/com/vaadin/client/ui/VAbstractSplitPanel.java index 9d32355b70..b52663b161 100644 --- a/client/src/com/vaadin/client/ui/VAbstractSplitPanel.java +++ b/client/src/com/vaadin/client/ui/VAbstractSplitPanel.java @@ -44,7 +44,7 @@ import com.vaadin.client.ComponentConnector; import com.vaadin.client.ConnectorMap; import com.vaadin.client.LayoutManager; import com.vaadin.client.StyleConstants; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.VConsole; import com.vaadin.client.ui.TouchScrollDelegate.TouchScrollHandler; import com.vaadin.client.ui.VAbstractSplitPanel.SplitterMoveHandler.SplitterMoveEvent; @@ -577,7 +577,7 @@ public class VAbstractSplitPanel extends ComplexPanel { break; } // Only fire click event listeners if the splitter isn't moved - if (Util.isTouchEvent(event) || !resized) { + if (WidgetUtil.isTouchEvent(event) || !resized) { super.onBrowserEvent(event); } else if (DOM.eventGetType(event) == Event.ONMOUSEUP) { // Reset the resized flag after a mouseup has occured so the next @@ -596,8 +596,8 @@ public class VAbstractSplitPanel extends ComplexPanel { DOM.setCapture(getElement()); origX = DOM.getElementPropertyInt(splitter, "offsetLeft"); origY = DOM.getElementPropertyInt(splitter, "offsetTop"); - origMouseX = Util.getTouchOrMouseClientX(event); - origMouseY = Util.getTouchOrMouseClientY(event); + origMouseX = WidgetUtil.getTouchOrMouseClientX(event); + origMouseY = WidgetUtil.getTouchOrMouseClientY(event); event.stopPropagation(); event.preventDefault(); } @@ -606,12 +606,12 @@ public class VAbstractSplitPanel extends ComplexPanel { public void onMouseMove(Event event) { switch (orientation) { case HORIZONTAL: - final int x = Util.getTouchOrMouseClientX(event); + final int x = WidgetUtil.getTouchOrMouseClientX(event); onHorizontalMouseMove(x); break; case VERTICAL: default: - final int y = Util.getTouchOrMouseClientY(event); + final int y = WidgetUtil.getTouchOrMouseClientY(event); onVerticalMouseMove(y); break; } @@ -688,7 +688,7 @@ public class VAbstractSplitPanel extends ComplexPanel { DOM.releaseCapture(getElement()); hideDraggingCurtain(); resizing = false; - if (!Util.isTouchEvent(event)) { + if (!WidgetUtil.isTouchEvent(event)) { onMouseMove(event); } fireEvent(new SplitterMoveEvent(this)); diff --git a/client/src/com/vaadin/client/ui/VAccordion.java b/client/src/com/vaadin/client/ui/VAccordion.java index 422f195af9..06eaecaf70 100644 --- a/client/src/com/vaadin/client/ui/VAccordion.java +++ b/client/src/com/vaadin/client/ui/VAccordion.java @@ -29,7 +29,7 @@ import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.ComplexPanel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ComponentConnector; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.VCaption; import com.vaadin.client.ui.TouchScrollDelegate.TouchScrollHandler; import com.vaadin.shared.ComponentConstants; @@ -203,7 +203,7 @@ public class VAccordion extends VTabsheetBase { } int captionWidth = caption.getRequiredWidth(); - int padding = Util.measureHorizontalPaddingAndBorder( + int padding = WidgetUtil.measureHorizontalPaddingAndBorder( caption.getElement(), 18); return captionWidth + padding; } diff --git a/client/src/com/vaadin/client/ui/VButton.java b/client/src/com/vaadin/client/ui/VButton.java index dcc364c1da..bf321f7f00 100644 --- a/client/src/com/vaadin/client/ui/VButton.java +++ b/client/src/com/vaadin/client/ui/VButton.java @@ -30,6 +30,7 @@ import com.google.gwt.user.client.ui.FocusWidget; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.BrowserInfo; import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; public class VButton extends FocusWidget implements ClickHandler { @@ -373,10 +374,10 @@ public class VButton extends FocusWidget implements ClickHandler { // Set (x,y) client coordinates to the middle of the button int x = getElement().getAbsoluteLeft() - getElement().getScrollLeft() - getElement().getOwnerDocument().getScrollLeft() - + Util.getRequiredWidth(getElement()) / 2; + + WidgetUtil.getRequiredWidth(getElement()) / 2; int y = getElement().getAbsoluteTop() - getElement().getScrollTop() - getElement().getOwnerDocument().getScrollTop() - + Util.getRequiredHeight(getElement()) / 2; + + WidgetUtil.getRequiredHeight(getElement()) / 2; NativeEvent evt = Document.get().createClickEvent(1, 0, 0, x, y, false, false, false, false); getElement().dispatchEvent(evt); diff --git a/client/src/com/vaadin/client/ui/VCalendarPanel.java b/client/src/com/vaadin/client/ui/VCalendarPanel.java index 6fc06bb153..e1b906b6e4 100644 --- a/client/src/com/vaadin/client/ui/VCalendarPanel.java +++ b/client/src/com/vaadin/client/ui/VCalendarPanel.java @@ -54,7 +54,7 @@ import com.google.gwt.user.client.ui.ListBox; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.BrowserInfo; import com.vaadin.client.DateTimeService; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.VConsole; import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.shared.util.SharedUtil; @@ -2065,7 +2065,7 @@ public class VCalendarPanel extends FocusableFlexTable implements return SUBPART_PREV_YEAR; } else if (contains(days, subElement)) { // Day, find out which dayOfMonth and use that as the identifier - Day day = Util.findWidget(subElement, Day.class); + Day day = WidgetUtil.findWidget(subElement, Day.class); if (day != null) { Date date = day.getDate(); int id = date.getDate(); diff --git a/client/src/com/vaadin/client/ui/VContextMenu.java b/client/src/com/vaadin/client/ui/VContextMenu.java index fa6d67fc0c..6028eea52c 100644 --- a/client/src/com/vaadin/client/ui/VContextMenu.java +++ b/client/src/com/vaadin/client/ui/VContextMenu.java @@ -51,7 +51,7 @@ import com.google.gwt.user.client.ui.PopupPanel; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.impl.FocusImpl; import com.vaadin.client.Focusable; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; public class VContextMenu extends VOverlay implements SubPartAware { @@ -89,7 +89,7 @@ public class VContextMenu extends VOverlay implements SubPartAware { addCloseHandler(new CloseHandler<PopupPanel>() { @Override public void onClose(CloseEvent<PopupPanel> event) { - Element currentFocus = Util.getFocusedElement(); + Element currentFocus = WidgetUtil.getFocusedElement(); if (focusedElement != null && (currentFocus == null || menu.getElement().isOrHasChild(currentFocus) || RootPanel @@ -137,11 +137,11 @@ public class VContextMenu extends VOverlay implements SubPartAware { } // Attach onload listeners to all images - Util.sinkOnloadForImages(menu.getElement()); + WidgetUtil.sinkOnloadForImages(menu.getElement()); // Store the currently focused element, which will be re-focused when // context menu is closed - focusedElement = Util.getFocusedElement(); + focusedElement = WidgetUtil.getFocusedElement(); // reset height (if it has been previously set explicitly) setHeight(""); diff --git a/client/src/com/vaadin/client/ui/VCustomLayout.java b/client/src/com/vaadin/client/ui/VCustomLayout.java index f5d572007a..5f8a8197d0 100644 --- a/client/src/com/vaadin/client/ui/VCustomLayout.java +++ b/client/src/com/vaadin/client/ui/VCustomLayout.java @@ -37,6 +37,7 @@ import com.vaadin.client.StyleConstants; import com.vaadin.client.Util; import com.vaadin.client.VCaption; import com.vaadin.client.VCaptionWrapper; +import com.vaadin.client.WidgetUtil; /** * Custom Layout implements complex layout defined with HTML template. @@ -158,7 +159,8 @@ public class VCustomLayout extends ComplexPanel { // TODO prefix img src:s here with a regeps, cannot work further with IE - String relImgPrefix = Util.escapeAttribute(themeUri + "/layouts/"); + String relImgPrefix = WidgetUtil + .escapeAttribute(themeUri + "/layouts/"); // prefix all relative image elements to point to theme dir with a // regexp search diff --git a/client/src/com/vaadin/client/ui/VEmbedded.java b/client/src/com/vaadin/client/ui/VEmbedded.java index acf814471a..f3970f9ac7 100644 --- a/client/src/com/vaadin/client/ui/VEmbedded.java +++ b/client/src/com/vaadin/client/ui/VEmbedded.java @@ -31,6 +31,7 @@ import com.vaadin.client.ConnectorMap; import com.vaadin.client.UIDL; import com.vaadin.client.Util; import com.vaadin.client.VConsole; +import com.vaadin.client.WidgetUtil; import com.vaadin.shared.ui.embedded.EmbeddedConstants; public class VEmbedded extends HTML { @@ -83,8 +84,8 @@ public class VEmbedded extends HTML { */ if (uidl.hasAttribute("classid")) { html.append("classid=\"" - + Util.escapeAttribute(uidl.getStringAttribute("classid")) - + "\" "); + + WidgetUtil.escapeAttribute(uidl + .getStringAttribute("classid")) + "\" "); } else { html.append("classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" "); } @@ -99,8 +100,8 @@ public class VEmbedded extends HTML { */ if (uidl.hasAttribute("codebase")) { html.append("codebase=\"" - + Util.escapeAttribute(uidl.getStringAttribute("codebase")) - + "\" "); + + WidgetUtil.escapeAttribute(uidl + .getStringAttribute("codebase")) + "\" "); } else { html.append("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" "); } @@ -111,29 +112,29 @@ public class VEmbedded extends HTML { String width = paintable.getState().width; // Add width and height - html.append("width=\"" + Util.escapeAttribute(width) + "\" "); - html.append("height=\"" + Util.escapeAttribute(height) + "\" "); + html.append("width=\"" + WidgetUtil.escapeAttribute(width) + "\" "); + html.append("height=\"" + WidgetUtil.escapeAttribute(height) + "\" "); html.append("type=\"application/x-shockwave-flash\" "); // Codetype if (uidl.hasAttribute("codetype")) { html.append("codetype=\"" - + Util.escapeAttribute(uidl.getStringAttribute("codetype")) - + "\" "); + + WidgetUtil.escapeAttribute(uidl + .getStringAttribute("codetype")) + "\" "); } // Standby if (uidl.hasAttribute("standby")) { html.append("standby=\"" - + Util.escapeAttribute(uidl.getStringAttribute("standby")) - + "\" "); + + WidgetUtil.escapeAttribute(uidl + .getStringAttribute("standby")) + "\" "); } // Archive if (uidl.hasAttribute("archive")) { html.append("archive=\"" - + Util.escapeAttribute(uidl.getStringAttribute("archive")) - + "\" "); + + WidgetUtil.escapeAttribute(uidl + .getStringAttribute("archive")) + "\" "); } // End object tag @@ -148,25 +149,25 @@ public class VEmbedded extends HTML { // Add parameters to OBJECT for (String name : parameters.keySet()) { html.append("<param "); - html.append("name=\"" + Util.escapeAttribute(name) + "\" "); - html.append("value=\"" + Util.escapeAttribute(parameters.get(name)) - + "\" "); + html.append("name=\"" + WidgetUtil.escapeAttribute(name) + "\" "); + html.append("value=\"" + + WidgetUtil.escapeAttribute(parameters.get(name)) + "\" "); html.append("/>"); } // Build inner EMBED tag html.append("<embed "); - html.append("src=\"" + Util.escapeAttribute(getSrc(uidl, client)) + html.append("src=\"" + WidgetUtil.escapeAttribute(getSrc(uidl, client)) + "\" "); - html.append("width=\"" + Util.escapeAttribute(width) + "\" "); - html.append("height=\"" + Util.escapeAttribute(height) + "\" "); + html.append("width=\"" + WidgetUtil.escapeAttribute(width) + "\" "); + html.append("height=\"" + WidgetUtil.escapeAttribute(height) + "\" "); html.append("type=\"application/x-shockwave-flash\" "); // Add the parameters to the Embed for (String name : parameters.keySet()) { - html.append(Util.escapeAttribute(name)); + html.append(WidgetUtil.escapeAttribute(name)); html.append("="); - html.append("\"" + Util.escapeAttribute(parameters.get(name)) + html.append("\"" + WidgetUtil.escapeAttribute(parameters.get(name)) + "\""); } diff --git a/client/src/com/vaadin/client/ui/VFilterSelect.java b/client/src/com/vaadin/client/ui/VFilterSelect.java index bb217f2de2..c0575b1ea5 100644 --- a/client/src/com/vaadin/client/ui/VFilterSelect.java +++ b/client/src/com/vaadin/client/ui/VFilterSelect.java @@ -67,8 +67,8 @@ import com.vaadin.client.ComputedStyle; import com.vaadin.client.ConnectorMap; import com.vaadin.client.Focusable; import com.vaadin.client.UIDL; -import com.vaadin.client.Util; import com.vaadin.client.VConsole; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.aria.AriaHelper; import com.vaadin.client.ui.aria.HandlesAriaCaption; import com.vaadin.client.ui.aria.HandlesAriaInvalid; @@ -134,7 +134,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, // options and are not collapsed (#7506) content = " "; } else { - content = Util.escapeHTML(caption); + content = WidgetUtil.escapeHTML(caption); } sb.append("<span>" + content + "</span>"); return sb.toString(); @@ -599,8 +599,8 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, final int naturalMenuWidth = menuFirstChild.getOffsetWidth(); if (popupOuterPadding == -1) { - popupOuterPadding = Util.measureHorizontalPaddingAndBorder( - getElement(), 2); + popupOuterPadding = WidgetUtil + .measureHorizontalPaddingAndBorder(getElement(), 2); } if (naturalMenuWidth < desiredWidth) { @@ -657,7 +657,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, menu.setHeight(menuHeight + "px"); final int naturalMenuWidthPlusScrollBar = naturalMenuWidth - + Util.getNativeScrollbarSize(); + + WidgetUtil.getNativeScrollbarSize(); if (offsetWidth < naturalMenuWidthPlusScrollBar) { menu.setWidth(naturalMenuWidthPlusScrollBar + "px"); } @@ -818,7 +818,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, final MenuItem mi = new MenuItem(s.getDisplayString(), true, s); Roles.getListitemRole().set(mi.getElement()); - Util.sinkOnloadForImages(mi.getElement()); + WidgetUtil.sinkOnloadForImages(mi.getElement()); this.addItem(mi); if (s == currentSuggestion) { @@ -1069,7 +1069,8 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, * the end and the focus to the start. This makes Firefox work * the same way as other browsers (#13477) */ - Util.setSelectionRange(getElement(), pos, length, "backward"); + WidgetUtil.setSelectionRange(getElement(), pos, length, + "backward"); } else { /* @@ -1609,7 +1610,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, } private void forceReflow() { - Util.setStyleTemporarily(tb.getElement(), "zoom", "1"); + WidgetUtil.setStyleTemporarily(tb.getElement(), "zoom", "1"); } /** @@ -1621,7 +1622,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, int availableHeight = 0; availableHeight = getOffsetHeight(); - int iconHeight = Util.getRequiredHeight(selectedItemIcon); + int iconHeight = WidgetUtil.getRequiredHeight(selectedItemIcon); int marginTop = (availableHeight - iconHeight) / 2; selectedItemIcon.getElement().getStyle() .setMarginTop(marginTop, Unit.PX); @@ -1936,7 +1937,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, */ public void updateSuggestionPopupMinWidth() { // used only to calculate minimum width - String captions = Util.escapeHTML(inputPrompt); + String captions = WidgetUtil.escapeHTML(inputPrompt); for (FilterSelectSuggestion suggestion : currentSuggestions) { // Collect captions so we can calculate minimum width for @@ -1944,7 +1945,8 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, if (captions.length() > 0) { captions += "|"; } - captions += Util.escapeHTML(suggestion.getReplacementString()); + captions += WidgetUtil + .escapeHTML(suggestion.getReplacementString()); } // Calculate minimum textarea width @@ -2051,7 +2053,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, */ preventNextBlurEventInIE = false; - Element focusedElement = Util.getIEFocusedElement(); + Element focusedElement = WidgetUtil.getFocusedElement(); if (getElement().isOrHasChild(focusedElement) || suggestionPopup.getElement() .isOrHasChild(focusedElement)) { @@ -2129,7 +2131,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, * when the popup is used to view longer items than the text box is * wide. */ - int w = Util.getRequiredWidth(this); + int w = WidgetUtil.getRequiredWidth(this); if ((!initDone || currentPage + 1 < 0) && suggestionPopupMinWidth > w) { @@ -2150,9 +2152,9 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, // Use util.getRequiredWidth instead of getOffsetWidth here - int iconWidth = selectedItemIcon == null ? 0 : Util + int iconWidth = selectedItemIcon == null ? 0 : WidgetUtil .getRequiredWidth(selectedItemIcon); - int buttonWidth = popupOpener == null ? 0 : Util + int buttonWidth = popupOpener == null ? 0 : WidgetUtil .getRequiredWidth(popupOpener); /* diff --git a/client/src/com/vaadin/client/ui/VFlash.java b/client/src/com/vaadin/client/ui/VFlash.java index cf15f89cb4..eaf53836ee 100644 --- a/client/src/com/vaadin/client/ui/VFlash.java +++ b/client/src/com/vaadin/client/ui/VFlash.java @@ -19,7 +19,7 @@ import java.util.HashMap; import java.util.Map; import com.google.gwt.user.client.ui.HTML; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; public class VFlash extends HTML { @@ -156,7 +156,8 @@ public class VFlash extends HTML { * this by setting his own classid. */ if (classId != null) { - html.append("classid=\"" + Util.escapeAttribute(classId) + "\" "); + html.append("classid=\"" + WidgetUtil.escapeAttribute(classId) + + "\" "); } else { html.append("classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" "); } @@ -170,29 +171,33 @@ public class VFlash extends HTML { * codebase */ if (codebase != null) { - html.append("codebase=\"" + Util.escapeAttribute(codebase) + "\" "); + html.append("codebase=\"" + WidgetUtil.escapeAttribute(codebase) + + "\" "); } else { html.append("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" "); } // Add width and height - html.append("width=\"" + Util.escapeAttribute(width) + "\" "); - html.append("height=\"" + Util.escapeAttribute(height) + "\" "); + html.append("width=\"" + WidgetUtil.escapeAttribute(width) + "\" "); + html.append("height=\"" + WidgetUtil.escapeAttribute(height) + "\" "); html.append("type=\"application/x-shockwave-flash\" "); // Codetype if (codetype != null) { - html.append("codetype=\"" + Util.escapeAttribute(codetype) + "\" "); + html.append("codetype=\"" + WidgetUtil.escapeAttribute(codetype) + + "\" "); } // Standby if (standby != null) { - html.append("standby=\"" + Util.escapeAttribute(standby) + "\" "); + html.append("standby=\"" + WidgetUtil.escapeAttribute(standby) + + "\" "); } // Archive if (archive != null) { - html.append("archive=\"" + Util.escapeAttribute(archive) + "\" "); + html.append("archive=\"" + WidgetUtil.escapeAttribute(archive) + + "\" "); } // End object tag @@ -206,25 +211,25 @@ public class VFlash extends HTML { // Add parameters to OBJECT for (String name : embedParams.keySet()) { html.append("<param "); - html.append("name=\"" + Util.escapeAttribute(name) + "\" "); + html.append("name=\"" + WidgetUtil.escapeAttribute(name) + "\" "); html.append("value=\"" - + Util.escapeAttribute(embedParams.get(name)) + "\" "); + + WidgetUtil.escapeAttribute(embedParams.get(name)) + "\" "); html.append("/>"); } // Build inner EMBED tag html.append("<embed "); - html.append("src=\"" + Util.escapeAttribute(source) + "\" "); - html.append("width=\"" + Util.escapeAttribute(width) + "\" "); - html.append("height=\"" + Util.escapeAttribute(height) + "\" "); + html.append("src=\"" + WidgetUtil.escapeAttribute(source) + "\" "); + html.append("width=\"" + WidgetUtil.escapeAttribute(width) + "\" "); + html.append("height=\"" + WidgetUtil.escapeAttribute(height) + "\" "); html.append("type=\"application/x-shockwave-flash\" "); // Add the parameters to the Embed for (String name : embedParams.keySet()) { - html.append(Util.escapeAttribute(name)); + html.append(WidgetUtil.escapeAttribute(name)); html.append("="); - html.append("\"" + Util.escapeAttribute(embedParams.get(name)) - + "\""); + html.append("\"" + + WidgetUtil.escapeAttribute(embedParams.get(name)) + "\""); } // End embed tag diff --git a/client/src/com/vaadin/client/ui/VLabel.java b/client/src/com/vaadin/client/ui/VLabel.java index 0f996fa6b9..a3572759c4 100644 --- a/client/src/com/vaadin/client/ui/VLabel.java +++ b/client/src/com/vaadin/client/ui/VLabel.java @@ -21,6 +21,7 @@ import com.google.gwt.user.client.ui.HTML; import com.vaadin.client.BrowserInfo; import com.vaadin.client.Util; import com.vaadin.client.VTooltip; +import com.vaadin.client.WidgetUtil; public class VLabel extends HTML { @@ -63,7 +64,7 @@ public class VLabel extends HTML { if (BrowserInfo.get().isIE8()) { // #3983 - IE8 incorrectly replaces \n with <br> so we do the // escaping manually and set as HTML - super.setHTML(Util.escapeHTML(text)); + super.setHTML(WidgetUtil.escapeHTML(text)); } else { super.setText(text); } diff --git a/client/src/com/vaadin/client/ui/VMenuBar.java b/client/src/com/vaadin/client/ui/VMenuBar.java index b5dac3f7ef..08f70f4dde 100644 --- a/client/src/com/vaadin/client/ui/VMenuBar.java +++ b/client/src/com/vaadin/client/ui/VMenuBar.java @@ -50,6 +50,7 @@ import com.vaadin.client.LayoutManager; import com.vaadin.client.TooltipInfo; import com.vaadin.client.UIDL; import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.shared.ui.menubar.MenuBarConstants; public class VMenuBar extends SimpleFocusablePanel implements @@ -234,7 +235,7 @@ public class VMenuBar extends SimpleFocusablePanel implements } String itemText = item.getStringAttribute("text"); if (!htmlContentAllowed) { - itemText = Util.escapeHTML(itemText); + itemText = WidgetUtil.escapeHTML(itemText); } itemHTML.append(itemText); itemHTML.append("</span>"); @@ -658,7 +659,8 @@ public class VMenuBar extends SimpleFocusablePanel implements // Make room for the scroll bar by adjusting the width of the // popup - style.setWidth(contentWidth + Util.getNativeScrollbarSize(), + style.setWidth( + contentWidth + WidgetUtil.getNativeScrollbarSize(), Unit.PX); popup.positionOrSizeUpdated(); } @@ -983,7 +985,7 @@ public class VMenuBar extends SimpleFocusablePanel implements // Sink the onload event for any icons. The onload // events are handled by the parent VMenuBar. - Util.sinkOnloadForImages(getElement()); + WidgetUtil.sinkOnloadForImages(getElement()); } @Override @@ -993,7 +995,7 @@ public class VMenuBar extends SimpleFocusablePanel implements @Override public void setText(String text) { - setHTML(Util.escapeHTML(text)); + setHTML(WidgetUtil.escapeHTML(text)); } public void setEnabled(boolean enabled) { diff --git a/client/src/com/vaadin/client/ui/VNotification.java b/client/src/com/vaadin/client/ui/VNotification.java index 1df58bb38f..b995ef840a 100644 --- a/client/src/com/vaadin/client/ui/VNotification.java +++ b/client/src/com/vaadin/client/ui/VNotification.java @@ -37,7 +37,7 @@ import com.vaadin.client.AnimationUtil.AnimationEndListener; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.BrowserInfo; import com.vaadin.client.UIDL; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.aria.AriaHelper; import com.vaadin.shared.Position; import com.vaadin.shared.ui.ui.NotificationRole; @@ -258,7 +258,7 @@ public class VNotification extends VOverlay { * nudge (#8551) */ if (BrowserInfo.get().isAndroid()) { - Util.setStyleTemporarily(getElement(), "display", "none"); + WidgetUtil.setStyleTemporarily(getElement(), "display", "none"); } } @@ -476,7 +476,7 @@ public class VNotification extends VOverlay { String caption = notification .getStringAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_CAPTION); if (onlyPlainText) { - caption = Util.escapeHTML(caption); + caption = WidgetUtil.escapeHTML(caption); caption = caption.replaceAll("\\n", "<br />"); } html += "<h1>" + caption + "</h1>"; @@ -486,7 +486,7 @@ public class VNotification extends VOverlay { String message = notification .getStringAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_MESSAGE); if (onlyPlainText) { - message = Util.escapeHTML(message); + message = WidgetUtil.escapeHTML(message); message = message.replaceAll("\\n", "<br />"); } html += "<p>" + message + "</p>"; diff --git a/client/src/com/vaadin/client/ui/VOptionGroup.java b/client/src/com/vaadin/client/ui/VOptionGroup.java index 34227831b9..588934369b 100644 --- a/client/src/com/vaadin/client/ui/VOptionGroup.java +++ b/client/src/com/vaadin/client/ui/VOptionGroup.java @@ -44,6 +44,7 @@ import com.vaadin.client.ApplicationConnection; import com.vaadin.client.BrowserInfo; import com.vaadin.client.UIDL; import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.shared.EventId; import com.vaadin.shared.ui.optiongroup.OptionGroupConstants; @@ -136,7 +137,7 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler, String itemHtml = opUidl.getStringAttribute("caption"); if (!htmlContentAllowed) { - itemHtml = Util.escapeHTML(itemHtml); + itemHtml = WidgetUtil.escapeHTML(itemHtml); } String iconUrl = opUidl.getStringAttribute("icon"); @@ -160,7 +161,7 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler, op.setStyleName("v-radiobutton"); } if (iconUrl != null && iconUrl.length() != 0) { - Util.sinkOnloadForImages(op.getElement()); + WidgetUtil.sinkOnloadForImages(op.getElement()); op.addHandler(iconLoadHandler, LoadEvent.getType()); } diff --git a/client/src/com/vaadin/client/ui/VOverlay.java b/client/src/com/vaadin/client/ui/VOverlay.java index 9845e89dab..3649afc74f 100644 --- a/client/src/com/vaadin/client/ui/VOverlay.java +++ b/client/src/com/vaadin/client/ui/VOverlay.java @@ -44,6 +44,7 @@ import com.vaadin.client.BrowserInfo; import com.vaadin.client.ComponentConnector; import com.vaadin.client.ComputedStyle; import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; /** * <p> @@ -672,7 +673,7 @@ public class VOverlay extends PopupPanel implements CloseHandler<PopupPanel> { // IE9 and IE10 have a bug, when resize an a element with box-shadow. // IE9 and IE10 need explicit update to remove extra box-shadows if (BrowserInfo.get().isIE9() || BrowserInfo.get().isIE10()) { - Util.forceIERedraw(getElement()); + WidgetUtil.forceIERedraw(getElement()); } } diff --git a/client/src/com/vaadin/client/ui/VPopupView.java b/client/src/com/vaadin/client/ui/VPopupView.java index 1923fc55e6..0f4e68acab 100644 --- a/client/src/com/vaadin/client/ui/VPopupView.java +++ b/client/src/com/vaadin/client/ui/VPopupView.java @@ -33,7 +33,14 @@ import com.google.gwt.event.logical.shared.CloseHandler; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; -import com.google.gwt.user.client.ui.*; +import com.google.gwt.user.client.ui.Focusable; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HasEnabled; +import com.google.gwt.user.client.ui.HasWidgets; +import com.google.gwt.user.client.ui.Label; +import com.google.gwt.user.client.ui.PopupPanel; +import com.google.gwt.user.client.ui.RootPanel; +import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.ComponentConnector; import com.vaadin.client.DeferredWorker; diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index 14e4c658ad..78db5c4096 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -91,6 +91,7 @@ import com.vaadin.client.UIDL; import com.vaadin.client.Util; import com.vaadin.client.VConsole; import com.vaadin.client.VTooltip; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.VScrollTable.VScrollTableBody.VScrollTableRow; import com.vaadin.client.ui.dd.DDUtil; import com.vaadin.client.ui.dd.VAbstractDropHandler; @@ -510,8 +511,8 @@ public class VScrollTable extends FlowPanel implements HasWidgets, @Override public void showContextMenu(Event event) { - int left = Util.getTouchOrMouseClientX(event); - int top = Util.getTouchOrMouseClientY(event); + int left = WidgetUtil.getTouchOrMouseClientX(event); + int top = WidgetUtil.getTouchOrMouseClientY(event); boolean menuShown = handleBodyContextMenu(left, top); if (menuShown) { event.stopPropagation(); @@ -796,8 +797,8 @@ public class VScrollTable extends FlowPanel implements HasWidgets, // Event's reported target not always correct if event // capture is in use - Element elementUnderMouse = Util.getElementUnderMouse(event - .getNativeEvent()); + Element elementUnderMouse = WidgetUtil + .getElementUnderMouse(event.getNativeEvent()); if (lastMouseDownTarget != null && lastMouseDownTarget.isOrHasChild(elementUnderMouse)) { mouseUpPreviewMatched = true; @@ -2244,7 +2245,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, int w = total; w += scrollBody.getCellExtraWidth() * visibleColOrder.length; if (willHaveScrollbarz) { - w += Util.getNativeScrollbarSize(); + w += WidgetUtil.getNativeScrollbarSize(); } setContentWidth(w); } @@ -2257,7 +2258,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, availW -= scrollBody.getCellExtraWidth() * visibleColOrder.length; if (willHaveScrollbarz) { - availW -= Util.getNativeScrollbarSize(); + availW -= WidgetUtil.getNativeScrollbarSize(); } // TODO refactor this code to be the same as in resize timer @@ -2429,10 +2430,10 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } boolean needsSpaceForHorizontalSrollbar = (total > availW); if (needsSpaceForHorizontalSrollbar) { - bodyHeight += Util.getNativeScrollbarSize(); + bodyHeight += WidgetUtil.getNativeScrollbarSize(); } scrollBodyPanel.setHeight(bodyHeight + "px"); - Util.runWebkitOverflowAutoFix(scrollBodyPanel.getElement()); + WidgetUtil.runWebkitOverflowAutoFix(scrollBodyPanel.getElement()); } isNewBody = false; @@ -2463,7 +2464,8 @@ public class VScrollTable extends FlowPanel implements HasWidgets, * Ensures the column alignments are correct at initial loading. <br/> * (child components widths are correct) */ - Util.runWebkitOverflowAutoFixDeferred(scrollBodyPanel.getElement()); + WidgetUtil.runWebkitOverflowAutoFixDeferred(scrollBodyPanel + .getElement()); hadScrollBars = willHaveScrollbarz; } @@ -3118,7 +3120,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, case Event.ONTOUCHSTART: case Event.ONMOUSEDOWN: if (columnReordering - && Util.isTouchEventOrLeftMouseButton(event)) { + && WidgetUtil.isTouchEventOrLeftMouseButton(event)) { if (event.getTypeInt() == Event.ONTOUCHSTART) { /* * prevent using this event in e.g. scrolling @@ -3138,11 +3140,11 @@ public class VScrollTable extends FlowPanel implements HasWidgets, case Event.ONTOUCHEND: case Event.ONTOUCHCANCEL: if (columnReordering - && Util.isTouchEventOrLeftMouseButton(event)) { + && WidgetUtil.isTouchEventOrLeftMouseButton(event)) { dragging = false; DOM.releaseCapture(getElement()); - if (Util.isTouchEvent(event)) { + if (WidgetUtil.isTouchEvent(event)) { /* * Prevent using in e.g. scrolling and prevent generated * events. @@ -3168,7 +3170,8 @@ public class VScrollTable extends FlowPanel implements HasWidgets, if (!moved) { // mouse event was a click to header -> sort column - if (sortable && Util.isTouchEventOrLeftMouseButton(event)) { + if (sortable + && WidgetUtil.isTouchEventOrLeftMouseButton(event)) { if (sortColumn.equals(cid)) { // just toggle order client.updateVariable(paintableId, "sortascending", @@ -3190,7 +3193,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, rowRequestHandler.run(); // run immediately } fireHeaderClickedEvent(event); - if (Util.isTouchEvent(event)) { + if (WidgetUtil.isTouchEvent(event)) { /* * Prevent using in e.g. scrolling and prevent generated * events. @@ -3206,7 +3209,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, break; case Event.ONTOUCHMOVE: case Event.ONMOUSEMOVE: - if (dragging && Util.isTouchEventOrLeftMouseButton(event)) { + if (dragging && WidgetUtil.isTouchEventOrLeftMouseButton(event)) { if (event.getTypeInt() == Event.ONTOUCHMOVE) { /* * prevent using this event in e.g. scrolling @@ -3218,7 +3221,8 @@ public class VScrollTable extends FlowPanel implements HasWidgets, moved = true; } - final int clientX = Util.getTouchOrMouseClientX(event); + final int clientX = WidgetUtil + .getTouchOrMouseClientX(event); final int x = clientX + tHead.hTableWrapper.getScrollLeft(); int slotX = headerX; closestSlot = colIndex; @@ -3256,7 +3260,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, private void onResizeEvent(Event event) { switch (DOM.eventGetType(event)) { case Event.ONMOUSEDOWN: - if (!Util.isTouchEventOrLeftMouseButton(event)) { + if (!WidgetUtil.isTouchEventOrLeftMouseButton(event)) { return; } isResizing = true; @@ -3267,7 +3271,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, DOM.eventPreventDefault(event); break; case Event.ONMOUSEUP: - if (!Util.isTouchEventOrLeftMouseButton(event)) { + if (!WidgetUtil.isTouchEventOrLeftMouseButton(event)) { return; } isResizing = false; @@ -3284,7 +3288,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, fireColumnResizeEvent(cid, originalWidth, getColWidth(cid)); break; case Event.ONMOUSEMOVE: - if (!Util.isTouchEventOrLeftMouseButton(event)) { + if (!WidgetUtil.isTouchEventOrLeftMouseButton(event)) { return; } if (isResizing) { @@ -4722,7 +4726,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, */ public int getRequiredHeight() { return preSpacer.getOffsetHeight() + postSpacer.getOffsetHeight() - + Util.getRequiredHeight(table); + + WidgetUtil.getRequiredHeight(table); } private void constructDOM() { @@ -5936,8 +5940,8 @@ public class VScrollTable extends FlowPanel implements HasWidgets, if (!BrowserInfo.get().isAndroid()) { event.preventDefault(); event.stopPropagation(); - Util.simulateClickFromTouchEvent(touchStart, - this); + WidgetUtil.simulateClickFromTouchEvent( + touchStart, this); } touchStart = null; } @@ -5996,7 +6000,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, */ if (mouseUpPreviewMatched && lastMouseDownTarget != null - && lastMouseDownTarget == getElementTdOrTr(Util + && lastMouseDownTarget == getElementTdOrTr(WidgetUtil .getElementUnderMouse(event))) { // "Click" with left, right or middle button @@ -6123,7 +6127,8 @@ public class VScrollTable extends FlowPanel implements HasWidgets, * Touch has not been handled as neither context or * drag start, handle it as a click. */ - Util.simulateClickFromTouchEvent(touchStart, this); + WidgetUtil.simulateClickFromTouchEvent(touchStart, + this); touchStart = null; } touchContextProvider.cancel(); @@ -6225,7 +6230,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, * the corresponding mouseup event if it's on a * different part of the page. */ - lastMouseDownTarget = getElementTdOrTr(Util + lastMouseDownTarget = getElementTdOrTr(WidgetUtil .getElementUnderMouse(event)); mouseUpPreviewMatched = false; mouseUpEventPreviewRegistration = Event @@ -6370,7 +6375,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, private Element getElementTdOrTr(Element element) { - Widget widget = Util.findWidget(element, null); + Widget widget = WidgetUtil.findWidget(element, null); if (widget != this) { /* @@ -6397,9 +6402,9 @@ public class VScrollTable extends FlowPanel implements HasWidgets, public void showContextMenu(Event event) { if (enabled && actionKeys != null) { // Show context menu if there are registered action handlers - int left = Util.getTouchOrMouseClientX(event) + int left = WidgetUtil.getTouchOrMouseClientX(event) + Window.getScrollLeft(); - int top = Util.getTouchOrMouseClientY(event) + int top = WidgetUtil.getTouchOrMouseClientY(event) + Window.getScrollTop(); showContextMenu(left, top); } @@ -6678,8 +6683,9 @@ public class VScrollTable extends FlowPanel implements HasWidgets, .getVisibleCellCount(); ix++) { spanWidth += tHead.getHeaderCell(ix).getOffsetWidth(); } - Util.setWidthExcludingPaddingAndBorder((Element) getElement() - .getChild(cellIx), spanWidth, 13, false); + WidgetUtil.setWidthExcludingPaddingAndBorder( + (Element) getElement().getChild(cellIx), spanWidth, 13, + false); } } @@ -6869,7 +6875,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, int totalExtraWidth = scrollBody.getCellExtraWidth() * visibleCellCount; if (willHaveScrollbars()) { - totalExtraWidth += Util.getNativeScrollbarSize(); + totalExtraWidth += WidgetUtil.getNativeScrollbarSize(); } availW -= totalExtraWidth; int forceScrollBodyWidth = -1; @@ -6999,7 +7005,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, int bodyHeight = scrollBody.getRequiredHeight(); boolean needsSpaceForHorizontalScrollbar = (availW < usedMinimumWidth); if (needsSpaceForHorizontalScrollbar) { - bodyHeight += Util.getNativeScrollbarSize(); + bodyHeight += WidgetUtil.getNativeScrollbarSize(); } int heightBefore = getOffsetHeight(); scrollBodyPanel.setHeight(bodyHeight + "px"); @@ -7044,7 +7050,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, */ private int getBorderWidth() { if (borderWidth < 0) { - borderWidth = Util.measureHorizontalPaddingAndBorder( + borderWidth = WidgetUtil.measureHorizontalPaddingAndBorder( scrollBodyPanel.getElement(), 2); if (borderWidth < 0) { borderWidth = 0; @@ -7373,7 +7379,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, Class<? extends Widget> clazz = getRowClass(); VScrollTableRow row = null; if (clazz != null) { - row = Util.findWidget(elementOver, clazz); + row = WidgetUtil.findWidget(elementOver, clazz); } if (row != null) { dropDetails.overkey = row.rowKey; @@ -7565,7 +7571,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, * FIXME The next line doesn't always do what expected, because if the * row is not in the DOM it won't scroll to it. */ - Util.scrollIntoViewVertically(row.getElement()); + WidgetUtil.scrollIntoViewVertically(row.getElement()); } /** @@ -7866,7 +7872,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, * ...and sometimes it sends blur events even though the focus * handler is still active. (#10464) */ - Element focusedElement = Util.getIEFocusedElement(); + Element focusedElement = WidgetUtil.getFocusedElement(); if (Util.getConnectorForElement(client, getParent(), focusedElement) == this && focusedElement != null && focusedElement != scrollBodyPanel.getFocusElement()) { @@ -8175,7 +8181,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, @Override public String getSubPartName(com.google.gwt.user.client.Element subElement) { - Widget widget = Util.findWidget(subElement, null); + Widget widget = WidgetUtil.findWidget(subElement, null); if (widget instanceof HeaderCell) { return SUBPART_HEADER + "[" + tHead.visibleCells.indexOf(widget) + "]"; diff --git a/client/src/com/vaadin/client/ui/VSlider.java b/client/src/com/vaadin/client/ui/VSlider.java index 27c8522f37..f5769ddf74 100644 --- a/client/src/com/vaadin/client/ui/VSlider.java +++ b/client/src/com/vaadin/client/ui/VSlider.java @@ -34,7 +34,7 @@ import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HasValue; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.BrowserInfo; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.shared.ui.slider.SliderOrientation; public class VSlider extends SimpleFocusablePanel implements Field, @@ -299,7 +299,7 @@ public class VSlider extends SimpleFocusablePanel implements Field, } else if (DOM.eventGetType(event) == Event.ONMOUSEDOWN) { feedbackPopup.show(); } - if (Util.isTouchEvent(event)) { + if (WidgetUtil.isTouchEvent(event)) { event.preventDefault(); // avoid simulated events event.stopPropagation(); } @@ -423,9 +423,9 @@ public class VSlider extends SimpleFocusablePanel implements Field, */ protected int getEventPosition(Event event) { if (isVertical()) { - return Util.getTouchOrMouseClientY(event); + return WidgetUtil.getTouchOrMouseClientY(event); } else { - return Util.getTouchOrMouseClientX(event); + return WidgetUtil.getTouchOrMouseClientX(event); } } diff --git a/client/src/com/vaadin/client/ui/VTabsheet.java b/client/src/com/vaadin/client/ui/VTabsheet.java index 96af09bb32..c8984ece51 100644 --- a/client/src/com/vaadin/client/ui/VTabsheet.java +++ b/client/src/com/vaadin/client/ui/VTabsheet.java @@ -63,7 +63,7 @@ import com.vaadin.client.BrowserInfo; import com.vaadin.client.ComponentConnector; import com.vaadin.client.Focusable; import com.vaadin.client.TooltipInfo; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.VCaption; import com.vaadin.client.VTooltip; import com.vaadin.client.ui.aria.AriaHelper; @@ -415,7 +415,7 @@ public class VTabsheet extends VTabsheetBase implements Focusable, SubPartAware public int getRequiredWidth() { int width = super.getRequiredWidth(); if (closeButton != null) { - width += Util.getRequiredWidth(closeButton); + width += WidgetUtil.getRequiredWidth(closeButton); } return width; } @@ -1330,7 +1330,7 @@ public class VTabsheet extends VTabsheetBase implements Focusable, SubPartAware /** For internal use only. May be removed or replaced in the future. */ public int getContentAreaBorderWidth() { - return Util.measureHorizontalBorder(contentNode); + return WidgetUtil.measureHorizontalBorder(contentNode); } @Override diff --git a/client/src/com/vaadin/client/ui/VTextArea.java b/client/src/com/vaadin/client/ui/VTextArea.java index bb48b29e61..50930f2fee 100644 --- a/client/src/com/vaadin/client/ui/VTextArea.java +++ b/client/src/com/vaadin/client/ui/VTextArea.java @@ -32,7 +32,7 @@ import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; import com.vaadin.client.BrowserInfo; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.dd.DragImageModifier; /** @@ -310,7 +310,7 @@ public class VTextArea extends VTextField implements DragImageModifier { // and reattach the whole TextArea. // Webkit fails to properly reflow the text when enabling wrapping, // same workaround - Util.detachAttach(getElement()); + WidgetUtil.detachAttach(getElement()); } this.wordwrap = wordwrap; } diff --git a/client/src/com/vaadin/client/ui/VTextField.java b/client/src/com/vaadin/client/ui/VTextField.java index b402ced218..1554bd1a22 100644 --- a/client/src/com/vaadin/client/ui/VTextField.java +++ b/client/src/com/vaadin/client/ui/VTextField.java @@ -34,7 +34,7 @@ import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.TextBoxBase; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.BrowserInfo; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.shared.EventId; import com.vaadin.shared.ui.textfield.TextFieldConstants; @@ -422,7 +422,7 @@ public class VTextField extends TextBoxBase implements Field, ChangeHandler, * @return true iff the value was updated */ protected boolean updateCursorPosition() { - if (Util.isAttachedAndDisplayed(this)) { + if (WidgetUtil.isAttachedAndDisplayed(this)) { int cursorPos = getCursorPos(); if (lastCursorPos != cursorPos) { client.updateVariable(paintableId, diff --git a/client/src/com/vaadin/client/ui/VTree.java b/client/src/com/vaadin/client/ui/VTree.java index 82ffaced1f..6539eb49a9 100644 --- a/client/src/com/vaadin/client/ui/VTree.java +++ b/client/src/com/vaadin/client/ui/VTree.java @@ -60,6 +60,7 @@ import com.vaadin.client.ConnectorMap; import com.vaadin.client.MouseEventDetailsBuilder; import com.vaadin.client.UIDL; import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.aria.AriaHelper; import com.vaadin.client.ui.aria.HandlesAriaCaption; import com.vaadin.client.ui.dd.DDUtil; @@ -346,7 +347,7 @@ public class VTree extends FocusElementPanel implements VHasDropHandler, } private String findCurrentMouseOverKey(Element elementOver) { - TreeNode treeNode = Util.findWidget(elementOver, TreeNode.class); + TreeNode treeNode = WidgetUtil.findWidget(elementOver, TreeNode.class); return treeNode == null ? null : treeNode.key; } @@ -1132,7 +1133,7 @@ public class VTree extends FocusElementPanel implements VHasDropHandler, * Scrolls the caption into view */ public void scrollIntoView() { - Util.scrollIntoViewVertically(nodeCaptionDiv); + WidgetUtil.scrollIntoViewVertically(nodeCaptionDiv); } public void setIcon(String iconUrl, String altText) { @@ -2143,7 +2144,7 @@ public class VTree extends FocusElementPanel implements VHasDropHandler, return "fe"; } - TreeNode treeNode = Util.findWidget(subElement, TreeNode.class); + TreeNode treeNode = WidgetUtil.findWidget(subElement, TreeNode.class); if (treeNode == null) { // Did not click on a node, let somebody else take care of the // locator string diff --git a/client/src/com/vaadin/client/ui/VTreeTable.java b/client/src/com/vaadin/client/ui/VTreeTable.java index 9e5940a2f2..0ba84af4bb 100644 --- a/client/src/com/vaadin/client/ui/VTreeTable.java +++ b/client/src/com/vaadin/client/ui/VTreeTable.java @@ -37,7 +37,7 @@ import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ComputedStyle; import com.vaadin.client.UIDL; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.VTreeTable.VTreeTableScrollBody.VTreeTableRow; public class VTreeTable extends VScrollTable { @@ -418,8 +418,9 @@ public class VTreeTable extends VScrollTable { .getVisibleCellCount(); ix++) { spanWidth += tHead.getHeaderCell(ix).getOffsetWidth(); } - Util.setWidthExcludingPaddingAndBorder((Element) getElement() - .getChild(cellIx), spanWidth, 13, false); + WidgetUtil.setWidthExcludingPaddingAndBorder( + (Element) getElement().getChild(cellIx), spanWidth, 13, + false); } } diff --git a/client/src/com/vaadin/client/ui/VTwinColSelect.java b/client/src/com/vaadin/client/ui/VTwinColSelect.java index 3987460989..5dbd534934 100644 --- a/client/src/com/vaadin/client/ui/VTwinColSelect.java +++ b/client/src/com/vaadin/client/ui/VTwinColSelect.java @@ -39,7 +39,7 @@ import com.google.gwt.user.client.ui.ListBox; import com.google.gwt.user.client.ui.Panel; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.UIDL; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.shared.ui.twincolselect.TwinColSelectConstants; public class VTwinColSelect extends VOptionGroupBase implements KeyDownHandler, @@ -352,7 +352,7 @@ public class VTwinColSelect extends VOptionGroupBase implements KeyDownHandler, /** For internal use only. May be removed or replaced in the future. */ public void setInternalHeights() { - int captionHeight = Util.getRequiredHeight(captionWrapper); + int captionHeight = WidgetUtil.getRequiredHeight(captionWrapper); int totalHeight = getOffsetHeight(); String selectHeight = (totalHeight - captionHeight) + "px"; @@ -394,10 +394,10 @@ public class VTwinColSelect extends VOptionGroupBase implements KeyDownHandler, /** For internal use only. May be removed or replaced in the future. */ public void setInternalWidths() { getElement().getStyle().setPosition(Position.RELATIVE); - int bordersAndPaddings = Util.measureHorizontalPaddingAndBorder( + int bordersAndPaddings = WidgetUtil.measureHorizontalPaddingAndBorder( buttons.getElement(), 0); - int buttonWidth = Util.getRequiredWidth(buttons); + int buttonWidth = WidgetUtil.getRequiredWidth(buttons); int totalWidth = getOffsetWidth(); int spaceForSelect = (totalWidth - buttonWidth - bordersAndPaddings) / 2; @@ -609,14 +609,14 @@ public class VTwinColSelect extends VOptionGroupBase implements KeyDownHandler, if (options.getElement() == subElement) { return SUBPART_OPTION_SELECT; } else { - int idx = Util.getChildElementIndex(subElement); + int idx = WidgetUtil.getChildElementIndex(subElement); return SUBPART_OPTION_SELECT_ITEM + idx; } } else if (selections.getElement().isOrHasChild(subElement)) { if (selections.getElement() == subElement) { return SUBPART_SELECTION_SELECT; } else { - int idx = Util.getChildElementIndex(subElement); + int idx = WidgetUtil.getChildElementIndex(subElement); return SUBPART_SELECTION_SELECT_ITEM + idx; } } else if (add.getElement().isOrHasChild(subElement)) { diff --git a/client/src/com/vaadin/client/ui/VUI.java b/client/src/com/vaadin/client/ui/VUI.java index eae4f6319d..0c1b83ab0f 100644 --- a/client/src/com/vaadin/client/ui/VUI.java +++ b/client/src/com/vaadin/client/ui/VUI.java @@ -44,7 +44,7 @@ import com.vaadin.client.ConnectorMap; import com.vaadin.client.Focusable; import com.vaadin.client.LayoutManager; import com.vaadin.client.Profiler; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.VConsole; import com.vaadin.client.ui.ShortcutActionHandler.ShortcutActionHandlerOwner; import com.vaadin.client.ui.TouchScrollDelegate.TouchScrollHandler; @@ -501,7 +501,7 @@ public class VUI extends SimplePanel implements ResizeHandler, * @param focusedElement */ public void storeFocus() { - storedFocus = Util.getFocusedElement(); + storedFocus = WidgetUtil.getFocusedElement(); } /** diff --git a/client/src/com/vaadin/client/ui/VWindow.java b/client/src/com/vaadin/client/ui/VWindow.java index eb3c89beb0..28918bb393 100644 --- a/client/src/com/vaadin/client/ui/VWindow.java +++ b/client/src/com/vaadin/client/ui/VWindow.java @@ -16,7 +16,7 @@ package com.vaadin.client.ui; -import static com.vaadin.client.Util.isFocusedElementEditable; +import static com.vaadin.client.WidgetUtil.isFocusedElementEditable; import java.util.ArrayList; import java.util.Arrays; @@ -62,7 +62,7 @@ import com.vaadin.client.ComponentConnector; import com.vaadin.client.ConnectorMap; import com.vaadin.client.Focusable; import com.vaadin.client.LayoutManager; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.debug.internal.VDebugWindow; import com.vaadin.client.ui.ShortcutActionHandler.ShortcutActionHandlerOwner; import com.vaadin.client.ui.aria.AriaHelper; @@ -581,7 +581,8 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, * ticket #11994 which was changing the size to 110% was replaced * with this due to ticket #12943 */ - Util.runWebkitOverflowAutoFix(contents.getFirstChildElement()); + WidgetUtil + .runWebkitOverflowAutoFix(contents.getFirstChildElement()); } } @@ -878,7 +879,7 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, public void setCaption(String c, String iconURL, boolean asHtml) { String html = c; if (!asHtml) { - c = Util.escapeHTML(c); + c = WidgetUtil.escapeHTML(c); } // Provide information to assistive device users that a sub window was @@ -1038,7 +1039,7 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, } private void onResizeEvent(Event event) { - if (resizable && Util.isTouchEventOrLeftMouseButton(event)) { + if (resizable && WidgetUtil.isTouchEventOrLeftMouseButton(event)) { switch (event.getTypeInt()) { case Event.ONMOUSEDOWN: case Event.ONTOUCHSTART: @@ -1050,8 +1051,8 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, resizeBox.getStyle().setVisibility(Visibility.HIDDEN); } resizing = true; - startX = Util.getTouchOrMouseClientX(event); - startY = Util.getTouchOrMouseClientY(event); + startX = WidgetUtil.getTouchOrMouseClientX(event); + startY = WidgetUtil.getTouchOrMouseClientY(event); origW = getElement().getOffsetWidth(); origH = getElement().getOffsetHeight(); DOM.setCapture(getElement()); @@ -1117,8 +1118,8 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, return; } - int w = Util.getTouchOrMouseClientX(event) - startX + origW; - int h = Util.getTouchOrMouseClientY(event) - startY + origH; + int w = WidgetUtil.getTouchOrMouseClientX(event) - startX + origW; + int h = WidgetUtil.getTouchOrMouseClientY(event) - startY + origH; w = Math.max(w, getMinWidth()); h = Math.max(h, getMinHeight()); @@ -1181,7 +1182,7 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, } private void onDragEvent(Event event) { - if (!Util.isTouchEventOrLeftMouseButton(event)) { + if (!WidgetUtil.isTouchEventOrLeftMouseButton(event)) { return; } @@ -1216,9 +1217,9 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, centered = false; if (cursorInsideBrowserContentArea(event)) { // Only drag while cursor is inside the browser client area - final int x = Util.getTouchOrMouseClientX(event) - startX + final int x = WidgetUtil.getTouchOrMouseClientX(event) - startX + origX; - final int y = Util.getTouchOrMouseClientY(event) - startY + final int y = WidgetUtil.getTouchOrMouseClientY(event) - startY + origY; setPopupPosition(x, y); } @@ -1230,8 +1231,8 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, if (draggable) { showDraggingCurtain(); dragging = true; - startX = Util.getTouchOrMouseClientX(event); - startY = Util.getTouchOrMouseClientY(event); + startX = WidgetUtil.getTouchOrMouseClientX(event); + startY = WidgetUtil.getTouchOrMouseClientY(event); origX = DOM.getAbsoluteLeft(getElement()); origY = DOM.getAbsoluteTop(getElement()); DOM.setCapture(getElement()); @@ -1279,7 +1280,7 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, if (!DOM.isOrHasChild(getTopmostWindow().getElement(), target)) { // not within the modal window, but let's see if it's in the // debug window - Widget w = Util.findWidget(target, null); + Widget w = WidgetUtil.findWidget(target, null); while (w != null) { if (w instanceof VDebugWindow) { return true; // allow debug-window clicks diff --git a/client/src/com/vaadin/client/ui/accordion/AccordionConnector.java b/client/src/com/vaadin/client/ui/accordion/AccordionConnector.java index 72aa2dbdfd..949e19071c 100644 --- a/client/src/com/vaadin/client/ui/accordion/AccordionConnector.java +++ b/client/src/com/vaadin/client/ui/accordion/AccordionConnector.java @@ -17,7 +17,7 @@ package com.vaadin.client.ui.accordion; import com.vaadin.client.ComponentConnector; import com.vaadin.client.ConnectorHierarchyChangeEvent; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.ui.SimpleManagedLayout; import com.vaadin.client.ui.VAccordion; @@ -106,7 +106,8 @@ public class AccordionConnector extends TabsheetBaseConnector implements usedPixels += item.getCaptionHeight(); } else { // This includes the captionNode borders - usedPixels += Util.getRequiredHeight(item.getElement()); + usedPixels += WidgetUtil.getRequiredHeight(item + .getElement()); } } int rootElementInnerHeight = getLayoutManager().getInnerHeight( diff --git a/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java b/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java index 8f5e9d9a59..5a0ec3d2ec 100644 --- a/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java +++ b/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java @@ -35,7 +35,7 @@ import com.vaadin.client.ApplicationConnection; import com.vaadin.client.Paintable; import com.vaadin.client.TooltipInfo; import com.vaadin.client.UIDL; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.VConsole; import com.vaadin.client.communication.RpcProxy; import com.vaadin.client.communication.StateChangeEvent; @@ -420,7 +420,7 @@ public class CalendarConnector extends AbstractComponentConnector implements @Override public TooltipInfo getTooltipInfo(com.google.gwt.dom.client.Element element) { TooltipInfo tooltipInfo = null; - Widget w = Util.findWidget(element, null); + Widget w = WidgetUtil.findWidget(element, null); if (w instanceof HasTooltipKey) { tooltipInfo = GWT.create(TooltipInfo.class); String title = tooltips.get(((HasTooltipKey) w).getTooltipKey()); diff --git a/client/src/com/vaadin/client/ui/calendar/schedule/DateCell.java b/client/src/com/vaadin/client/ui/calendar/schedule/DateCell.java index 448083ba26..39d516b694 100644 --- a/client/src/com/vaadin/client/ui/calendar/schedule/DateCell.java +++ b/client/src/com/vaadin/client/ui/calendar/schedule/DateCell.java @@ -43,7 +43,7 @@ import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.Widget; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; public class DateCell extends FocusableComplexPanel implements MouseDownHandler, MouseMoveHandler, MouseUpHandler, KeyDownHandler, @@ -201,7 +201,7 @@ public class DateCell extends FocusableComplexPanel implements addStyleDependentName("Hsized"); width = getOffsetWidth() - - Util.measureHorizontalBorder(getElement()); + - WidgetUtil.measureHorizontalBorder(getElement()); // Update moveWidth for any DateCellDayEvent child updateEventCellsWidth(); recalculateEventWidths(); @@ -338,7 +338,7 @@ public class DateCell extends FocusableComplexPanel implements } public int getSlotBorder() { - return Util.measureVerticalBorder(slotElements[0]); + return WidgetUtil.measureVerticalBorder(slotElements[0]); } private void drawDayEvents(List<DateCellGroup> groups) { diff --git a/client/src/com/vaadin/client/ui/calendar/schedule/DateCellContainer.java b/client/src/com/vaadin/client/ui/calendar/schedule/DateCellContainer.java index 82af89c794..26f5951987 100644 --- a/client/src/com/vaadin/client/ui/calendar/schedule/DateCellContainer.java +++ b/client/src/com/vaadin/client/ui/calendar/schedule/DateCellContainer.java @@ -23,7 +23,7 @@ import com.google.gwt.event.dom.client.MouseUpEvent; import com.google.gwt.event.dom.client.MouseUpHandler; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.Widget; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.VCalendar; /** @@ -48,7 +48,7 @@ public class DateCellContainer extends FlowPanel implements MouseDownHandler, public static int measureBorderWidth(DateCellContainer dc) { if (borderWidth == -1) { - borderWidth = Util.measureHorizontalBorder(dc.getElement()); + borderWidth = WidgetUtil.measureHorizontalBorder(dc.getElement()); } return borderWidth; } diff --git a/client/src/com/vaadin/client/ui/calendar/schedule/DateCellDayEvent.java b/client/src/com/vaadin/client/ui/calendar/schedule/DateCellDayEvent.java index 3b168b636c..abc9419049 100644 --- a/client/src/com/vaadin/client/ui/calendar/schedule/DateCellDayEvent.java +++ b/client/src/com/vaadin/client/ui/calendar/schedule/DateCellDayEvent.java @@ -41,7 +41,7 @@ import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.HorizontalPanel; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.shared.ui.calendar.DateConstants; /** @@ -184,7 +184,8 @@ public class DateCellDayEvent extends FocusableHTML implements */ private void updateCaptions(boolean bigMode) { String innerHtml; - String escapedCaption = Util.escapeHTML(calendarEvent.getCaption()); + String escapedCaption = WidgetUtil.escapeHTML(calendarEvent + .getCaption()); String timeAsText = calendarEvent.getTimeAsText(); if (bigMode) { innerHtml = "<span>" + timeAsText + "</span><br />" diff --git a/client/src/com/vaadin/client/ui/calendar/schedule/WeekGrid.java b/client/src/com/vaadin/client/ui/calendar/schedule/WeekGrid.java index 545ddadc52..aecaff1931 100644 --- a/client/src/com/vaadin/client/ui/calendar/schedule/WeekGrid.java +++ b/client/src/com/vaadin/client/ui/calendar/schedule/WeekGrid.java @@ -31,7 +31,7 @@ import com.google.gwt.user.client.ui.ScrollPanel; import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.DateTimeService; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.VCalendar; import com.vaadin.shared.ui.calendar.DateConstants; @@ -160,7 +160,7 @@ public class WeekGrid extends SimplePanel { // Otherwise the scroll wrapper is somehow too narrow = horizontal // scroll wrapper.setWidth(content.getOffsetWidth() - + Util.getNativeScrollbarSize() + "px"); + + WidgetUtil.getNativeScrollbarSize() + "px"); this.width = content.getOffsetWidth() - timebar.getOffsetWidth(); @@ -169,7 +169,7 @@ public class WeekGrid extends SimplePanel { - timebar.getOffsetWidth(); if (isVerticalScrollable() && width != -1) { - this.width = this.width - Util.getNativeScrollbarSize(); + this.width = this.width - WidgetUtil.getNativeScrollbarSize(); } updateCellWidths(); } diff --git a/client/src/com/vaadin/client/ui/calendar/schedule/dd/CalendarMonthDropHandler.java b/client/src/com/vaadin/client/ui/calendar/schedule/dd/CalendarMonthDropHandler.java index 9cab421200..39e08e9d70 100644 --- a/client/src/com/vaadin/client/ui/calendar/schedule/dd/CalendarMonthDropHandler.java +++ b/client/src/com/vaadin/client/ui/calendar/schedule/dd/CalendarMonthDropHandler.java @@ -17,7 +17,7 @@ package com.vaadin.client.ui.calendar.schedule.dd; import com.google.gwt.dom.client.Element; import com.google.gwt.user.client.DOM; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.calendar.CalendarConnector; import com.vaadin.client.ui.calendar.schedule.SimpleDayCell; import com.vaadin.client.ui.dd.VAcceptCallback; @@ -51,7 +51,7 @@ public class CalendarMonthDropHandler extends CalendarDropHandler { protected void dragAccepted(VDragEvent drag) { deEmphasis(); currentTargetElement = drag.getElementOver(); - currentTargetDay = Util.findWidget(currentTargetElement, + currentTargetDay = WidgetUtil.findWidget(currentTargetElement, SimpleDayCell.class); emphasis(); } diff --git a/client/src/com/vaadin/client/ui/calendar/schedule/dd/CalendarWeekDropHandler.java b/client/src/com/vaadin/client/ui/calendar/schedule/dd/CalendarWeekDropHandler.java index 853e4b724e..e0edf21e89 100644 --- a/client/src/com/vaadin/client/ui/calendar/schedule/dd/CalendarWeekDropHandler.java +++ b/client/src/com/vaadin/client/ui/calendar/schedule/dd/CalendarWeekDropHandler.java @@ -17,7 +17,7 @@ package com.vaadin.client.ui.calendar.schedule.dd; import com.google.gwt.dom.client.Element; import com.google.gwt.user.client.DOM; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.calendar.CalendarConnector; import com.vaadin.client.ui.calendar.schedule.DateCell; import com.vaadin.client.ui.calendar.schedule.DateCellDayEvent; @@ -52,8 +52,8 @@ public class CalendarWeekDropHandler extends CalendarDropHandler { protected void dragAccepted(VDragEvent drag) { deEmphasis(); currentTargetElement = drag.getElementOver(); - currentTargetDay = Util - .findWidget(currentTargetElement, DateCell.class); + currentTargetDay = WidgetUtil.findWidget(currentTargetElement, + DateCell.class); emphasis(); } @@ -121,7 +121,7 @@ public class CalendarWeekDropHandler extends CalendarDropHandler { return DOM.isOrHasChild(weekGridElement, elementOver) && !DOM.isOrHasChild(timeBarElement, elementOver) && todayBarElement != elementOver - && (Util.findWidget(elementOver, DateCellDayEvent.class) == null); + && (WidgetUtil.findWidget(elementOver, DateCellDayEvent.class) == null); } /* diff --git a/client/src/com/vaadin/client/ui/dd/DDUtil.java b/client/src/com/vaadin/client/ui/dd/DDUtil.java index 77de1f9b1a..fdccd61767 100644 --- a/client/src/com/vaadin/client/ui/dd/DDUtil.java +++ b/client/src/com/vaadin/client/ui/dd/DDUtil.java @@ -18,7 +18,7 @@ package com.vaadin.client.ui.dd; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.user.client.Window; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.shared.ui.dd.HorizontalDropLocation; import com.vaadin.shared.ui.dd.VerticalDropLocation; @@ -33,7 +33,7 @@ public class DDUtil { public static VerticalDropLocation getVerticalDropLocation(Element element, int offsetHeight, NativeEvent event, double topBottomRatio) { - int clientY = Util.getTouchOrMouseClientY(event); + int clientY = WidgetUtil.getTouchOrMouseClientY(event); return getVerticalDropLocation(element, offsetHeight, clientY, topBottomRatio); } @@ -59,7 +59,7 @@ public class DDUtil { public static HorizontalDropLocation getHorizontalDropLocation( Element element, NativeEvent event, double leftRightRatio) { - int clientX = Util.getTouchOrMouseClientX(event); + int clientX = WidgetUtil.getTouchOrMouseClientX(event); // Event coordinates are relative to the viewport, element absolute // position is relative to the document. Make element position relative diff --git a/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java b/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java index 4ee19328d6..844f4c1b9c 100644 --- a/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java +++ b/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java @@ -38,7 +38,7 @@ import com.vaadin.client.ComponentConnector; import com.vaadin.client.MouseEventDetailsBuilder; import com.vaadin.client.Profiler; import com.vaadin.client.UIDL; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.VConsole; import com.vaadin.client.ValueMap; import com.vaadin.client.ui.VOverlay; @@ -92,16 +92,16 @@ public class VDragAndDropManager { targetElement = targetNode.getParentElement(); } - if (Util.isTouchEvent(nativeEvent) || dragElement != null) { + if (WidgetUtil.isTouchEvent(nativeEvent) || dragElement != null) { // to detect the "real" target, hide dragelement temporary and // use elementFromPoint String display = dragElement.getStyle().getDisplay(); dragElement.getStyle().setDisplay(Display.NONE); try { - int x = Util.getTouchOrMouseClientX(nativeEvent); - int y = Util.getTouchOrMouseClientY(nativeEvent); + int x = WidgetUtil.getTouchOrMouseClientX(nativeEvent); + int y = WidgetUtil.getTouchOrMouseClientY(nativeEvent); // Util.browserDebugger(); - targetElement = Util.getElementFromPoint(x, y); + targetElement = WidgetUtil.getElementFromPoint(x, y); if (targetElement == null) { // ApplicationConnection.getConsole().log( // "Event on dragImage, ignored"); @@ -361,10 +361,10 @@ public class VDragAndDropManager { deferredStartRegistration = Event .addNativePreviewHandler(new NativePreviewHandler() { - private int startX = Util + private int startX = WidgetUtil .getTouchOrMouseClientX(currentDrag .getCurrentGwtEvent()); - private int startY = Util + private int startY = WidgetUtil .getTouchOrMouseClientY(currentDrag .getCurrentGwtEvent()); @@ -419,10 +419,10 @@ public class VDragAndDropManager { } case Event.ONMOUSEMOVE: case Event.ONTOUCHMOVE: - int currentX = Util + int currentX = WidgetUtil .getTouchOrMouseClientX(event .getNativeEvent()); - int currentY = Util + int currentY = WidgetUtil .getTouchOrMouseClientY(event .getNativeEvent()); if (Math.abs(startX - currentX) > 3 @@ -462,9 +462,9 @@ public class VDragAndDropManager { private void updateDragImagePosition() { if (currentDrag.getCurrentGwtEvent() != null && dragElement != null) { Style style = dragElement.getStyle(); - int clientY = Util.getTouchOrMouseClientY(currentDrag + int clientY = WidgetUtil.getTouchOrMouseClientY(currentDrag .getCurrentGwtEvent()); - int clientX = Util.getTouchOrMouseClientX(currentDrag + int clientX = WidgetUtil.getTouchOrMouseClientX(currentDrag .getCurrentGwtEvent()); style.setTop(clientY, Unit.PX); style.setLeft(clientX, Unit.PX); @@ -480,7 +480,7 @@ public class VDragAndDropManager { */ private VDropHandler findDragTarget(Element element) { try { - Widget w = Util.findWidget(element, null); + Widget w = WidgetUtil.findWidget(element, null); if (w == null) { return null; } diff --git a/client/src/com/vaadin/client/ui/dd/VDragEvent.java b/client/src/com/vaadin/client/ui/dd/VDragEvent.java index 45f89bdb87..c889dbf34e 100644 --- a/client/src/com/vaadin/client/ui/dd/VDragEvent.java +++ b/client/src/com/vaadin/client/ui/dd/VDragEvent.java @@ -30,7 +30,7 @@ import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.EventListener; import com.vaadin.client.BrowserInfo; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; /** * DragEvent used by Vaadin client side engine. Supports components, items, @@ -262,8 +262,8 @@ public class VDragEvent { if (alignImageToEvent) { int absoluteTop = element.getAbsoluteTop(); int absoluteLeft = element.getAbsoluteLeft(); - int clientX = Util.getTouchOrMouseClientX(startEvent); - int clientY = Util.getTouchOrMouseClientY(startEvent); + int clientX = WidgetUtil.getTouchOrMouseClientX(startEvent); + int clientY = WidgetUtil.getTouchOrMouseClientY(startEvent); int offsetX = absoluteLeft - clientX; int offsetY = absoluteTop - clientY; setDragImage(cloneNode, offsetX, offsetY); diff --git a/client/src/com/vaadin/client/ui/formlayout/FormLayoutConnector.java b/client/src/com/vaadin/client/ui/formlayout/FormLayoutConnector.java index 494a1a87ff..9517619cf3 100644 --- a/client/src/com/vaadin/client/ui/formlayout/FormLayoutConnector.java +++ b/client/src/com/vaadin/client/ui/formlayout/FormLayoutConnector.java @@ -20,7 +20,7 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ComponentConnector; import com.vaadin.client.ConnectorHierarchyChangeEvent; import com.vaadin.client.TooltipInfo; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.ui.AbstractFieldConnector; import com.vaadin.client.ui.AbstractLayoutConnector; @@ -114,14 +114,16 @@ public class FormLayoutConnector extends AbstractLayoutConnector { TooltipInfo info = null; if (element != getWidget().getElement()) { - Object node = Util.findWidget(element, VFormLayout.Caption.class); + Object node = WidgetUtil.findWidget(element, + VFormLayout.Caption.class); if (node != null) { VFormLayout.Caption caption = (VFormLayout.Caption) node; info = caption.getOwner().getTooltipInfo(element); } else { - node = Util.findWidget(element, VFormLayout.ErrorFlag.class); + node = WidgetUtil.findWidget(element, + VFormLayout.ErrorFlag.class); if (node != null) { VFormLayout.ErrorFlag flag = (VFormLayout.ErrorFlag) node; diff --git a/client/src/com/vaadin/client/ui/label/LabelConnector.java b/client/src/com/vaadin/client/ui/label/LabelConnector.java index 07defcc64d..fc94f27cf0 100644 --- a/client/src/com/vaadin/client/ui/label/LabelConnector.java +++ b/client/src/com/vaadin/client/ui/label/LabelConnector.java @@ -18,7 +18,7 @@ package com.vaadin.client.ui.label; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.PreElement; import com.vaadin.client.Profiler; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.ui.AbstractComponentConnector; import com.vaadin.client.ui.VLabel; @@ -69,7 +69,7 @@ public class LabelConnector extends AbstractComponentConnector { if (sinkOnloads) { Profiler.enter("LabelConnector.onStateChanged sinkOnloads"); - Util.sinkOnloadForImages(getWidget().getElement()); + WidgetUtil.sinkOnloadForImages(getWidget().getElement()); Profiler.leave("LabelConnector.onStateChanged sinkOnloads"); } } diff --git a/client/src/com/vaadin/client/ui/layout/LayoutDependencyTree.java b/client/src/com/vaadin/client/ui/layout/LayoutDependencyTree.java index ae866e3354..a8b6b9b0ce 100644 --- a/client/src/com/vaadin/client/ui/layout/LayoutDependencyTree.java +++ b/client/src/com/vaadin/client/ui/layout/LayoutDependencyTree.java @@ -30,6 +30,7 @@ import com.vaadin.client.Profiler; import com.vaadin.client.ServerConnector; import com.vaadin.client.Util; import com.vaadin.client.VConsole; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.ManagedLayout; import com.vaadin.shared.AbstractComponentState; @@ -586,7 +587,7 @@ public class LayoutDependencyTree { } private static String getCompactConnectorString(ServerConnector connector) { - return Util.getSimpleName(connector) + " (" + return WidgetUtil.getSimpleName(connector) + " (" + connector.getConnectorId() + ")"; } diff --git a/client/src/com/vaadin/client/ui/menubar/MenuBarConnector.java b/client/src/com/vaadin/client/ui/menubar/MenuBarConnector.java index 20cabf9a36..03eeb85165 100644 --- a/client/src/com/vaadin/client/ui/menubar/MenuBarConnector.java +++ b/client/src/com/vaadin/client/ui/menubar/MenuBarConnector.java @@ -25,7 +25,7 @@ import com.vaadin.client.ApplicationConnection; import com.vaadin.client.Paintable; import com.vaadin.client.TooltipInfo; import com.vaadin.client.UIDL; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.AbstractComponentConnector; import com.vaadin.client.ui.ImageIcon; import com.vaadin.client.ui.SimpleManagedLayout; @@ -78,7 +78,7 @@ public class MenuBarConnector extends AbstractComponentConnector implements if (moreItemUIDL.hasAttribute("icon")) { itemHTML.append("<img src=\"" - + Util.escapeAttribute(client + + WidgetUtil.escapeAttribute(client .translateVaadinUri(moreItemUIDL .getStringAttribute("icon"))) + "\" class=\"" + ImageIcon.CLASSNAME diff --git a/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java b/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java index c2157650a5..8fa885c2b9 100644 --- a/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java +++ b/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java @@ -30,6 +30,7 @@ import com.vaadin.client.Profiler; import com.vaadin.client.ServerConnector; import com.vaadin.client.TooltipInfo; import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler; import com.vaadin.client.ui.AbstractFieldConnector; @@ -387,7 +388,7 @@ public abstract class AbstractOrderedLayoutConnector extends @Override public TooltipInfo getTooltipInfo(com.google.gwt.dom.client.Element element) { if (element != getWidget().getElement()) { - Slot slot = Util.findWidget(element, Slot.class); + Slot slot = WidgetUtil.findWidget(element, Slot.class); if (slot != null && slot.getCaptionElement() != null && slot.getParent() == getWidget() && slot.getCaptionElement().isOrHasChild(element)) { diff --git a/client/src/com/vaadin/client/ui/orderedlayout/Slot.java b/client/src/com/vaadin/client/ui/orderedlayout/Slot.java index 4b60f11ab4..b97cf73989 100644 --- a/client/src/com/vaadin/client/ui/orderedlayout/Slot.java +++ b/client/src/com/vaadin/client/ui/orderedlayout/Slot.java @@ -30,7 +30,7 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.BrowserInfo; import com.vaadin.client.LayoutManager; import com.vaadin.client.StyleConstants; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.FontIcon; import com.vaadin.client.ui.Icon; import com.vaadin.client.ui.ImageIcon; @@ -74,7 +74,7 @@ public final class Slot extends SimplePanel { public void onElementResize(ElementResizeEvent e) { Element caption = getCaptionElement(); if (caption != null) { - Util.forceIE8Redraw(caption); + WidgetUtil.forceIE8Redraw(caption); } } }; @@ -493,7 +493,7 @@ public final class Slot extends SimplePanel { // Caption wrappers Widget widget = getWidget(); - final Element focusedElement = Util.getFocusedElement(); + final Element focusedElement = WidgetUtil.getFocusedElement(); // By default focus will not be lost boolean focusLost = false; if (captionText != null || icon != null || error != null || required) { @@ -613,7 +613,7 @@ public final class Slot extends SimplePanel { if (focusLost) { // Find out what element is currently focused. - Element currentFocus = Util.getFocusedElement(); + Element currentFocus = WidgetUtil.getFocusedElement(); if (currentFocus != null && currentFocus.equals(Document.get().getBody())) { // Focus has moved to BodyElement and should be moved back to @@ -627,12 +627,12 @@ public final class Slot extends SimplePanel { @Override public void run() { - if (Util.getFocusedElement() == null) { + if (WidgetUtil.getFocusedElement() == null) { // This should never become an infinite loop and // even if it does it will be stopped once something // is done with the browser. schedule(25); - } else if (Util.getFocusedElement().equals( + } else if (WidgetUtil.getFocusedElement().equals( Document.get().getBody())) { // Focus found it's way to BodyElement. Now it can // be restored diff --git a/client/src/com/vaadin/client/ui/orderedlayout/VAbstractOrderedLayout.java b/client/src/com/vaadin/client/ui/orderedlayout/VAbstractOrderedLayout.java index 4c74358753..2e6d4cf5c8 100644 --- a/client/src/com/vaadin/client/ui/orderedlayout/VAbstractOrderedLayout.java +++ b/client/src/com/vaadin/client/ui/orderedlayout/VAbstractOrderedLayout.java @@ -33,6 +33,7 @@ import com.vaadin.client.BrowserInfo; import com.vaadin.client.LayoutManager; import com.vaadin.client.Profiler; import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.shared.ui.MarginInfo; /** @@ -674,7 +675,7 @@ public class VAbstractOrderedLayout extends FlowPanel { } } } - Util.forceIE8Redraw(getElement()); + WidgetUtil.forceIE8Redraw(getElement()); } /** diff --git a/client/src/com/vaadin/client/ui/table/TableConnector.java b/client/src/com/vaadin/client/ui/table/TableConnector.java index 7fb4bc108a..6a9ef6722e 100644 --- a/client/src/com/vaadin/client/ui/table/TableConnector.java +++ b/client/src/com/vaadin/client/ui/table/TableConnector.java @@ -31,7 +31,7 @@ import com.vaadin.client.Paintable; import com.vaadin.client.ServerConnector; import com.vaadin.client.TooltipInfo; import com.vaadin.client.UIDL; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.AbstractHasComponentsConnector; import com.vaadin.client.ui.PostLayoutListener; import com.vaadin.client.ui.VScrollTable; @@ -342,7 +342,7 @@ public class TableConnector extends AbstractHasComponentsConnector implements @Override public void execute() { // IE8 needs some hacks to measure sizes correctly - Util.forceIE8Redraw(getWidget().getElement()); + WidgetUtil.forceIE8Redraw(getWidget().getElement()); getLayoutManager().setNeedsMeasure(TableConnector.this); ServerConnector parent = getParent(); @@ -394,7 +394,7 @@ public class TableConnector extends AbstractHasComponentsConnector implements TooltipInfo info = null; if (element != getWidget().getElement()) { - Object node = Util.findWidget(element, VScrollTableRow.class); + Object node = WidgetUtil.findWidget(element, VScrollTableRow.class); if (node != null) { VScrollTableRow row = (VScrollTableRow) node; diff --git a/client/src/com/vaadin/client/ui/tabsheet/TabsheetConnector.java b/client/src/com/vaadin/client/ui/tabsheet/TabsheetConnector.java index d49581eaad..469fc6ba95 100644 --- a/client/src/com/vaadin/client/ui/tabsheet/TabsheetConnector.java +++ b/client/src/com/vaadin/client/ui/tabsheet/TabsheetConnector.java @@ -20,7 +20,7 @@ import com.google.gwt.dom.client.Style.Overflow; import com.vaadin.client.ComponentConnector; import com.vaadin.client.ConnectorHierarchyChangeEvent; import com.vaadin.client.TooltipInfo; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.ui.SimpleManagedLayout; import com.vaadin.client.ui.VTabsheet; @@ -139,7 +139,8 @@ public class TabsheetConnector extends TabsheetBaseConnector implements // Find a tooltip for the tab, if the element is a tab if (element != getWidget().getElement()) { - Object node = Util.findWidget(element, VTabsheet.TabCaption.class); + Object node = WidgetUtil.findWidget(element, + VTabsheet.TabCaption.class); if (node != null) { VTabsheet.TabCaption caption = (VTabsheet.TabCaption) node; diff --git a/client/src/com/vaadin/client/ui/textarea/TextAreaConnector.java b/client/src/com/vaadin/client/ui/textarea/TextAreaConnector.java index e9dc3e1dd7..3bc0a86df4 100644 --- a/client/src/com/vaadin/client/ui/textarea/TextAreaConnector.java +++ b/client/src/com/vaadin/client/ui/textarea/TextAreaConnector.java @@ -19,7 +19,7 @@ package com.vaadin.client.ui.textarea; import com.google.gwt.dom.client.Element; import com.google.gwt.event.dom.client.MouseUpEvent; import com.google.gwt.event.dom.client.MouseUpHandler; -import com.vaadin.client.Util.CssSize; +import com.vaadin.client.WidgetUtil.CssSize; import com.vaadin.client.ui.VTextArea; import com.vaadin.client.ui.textfield.TextFieldConnector; import com.vaadin.shared.ui.Connect; diff --git a/client/src/com/vaadin/client/ui/tree/TreeConnector.java b/client/src/com/vaadin/client/ui/tree/TreeConnector.java index 55224b455f..fc3e6ca0fc 100644 --- a/client/src/com/vaadin/client/ui/tree/TreeConnector.java +++ b/client/src/com/vaadin/client/ui/tree/TreeConnector.java @@ -27,7 +27,7 @@ import com.vaadin.client.BrowserInfo; import com.vaadin.client.Paintable; import com.vaadin.client.TooltipInfo; import com.vaadin.client.UIDL; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.VConsole; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.ui.AbstractComponentConnector; @@ -172,7 +172,7 @@ public class TreeConnector extends AbstractComponentConnector implements } // IE8 needs a hack to measure the tree again after update - Util.forceIE8Redraw(getWidget().getElement()); + WidgetUtil.forceIE8Redraw(getWidget().getElement()); getWidget().rendering = false; @@ -333,7 +333,7 @@ public class TreeConnector extends AbstractComponentConnector implements // Try to find a tooltip for a node if (element != getWidget().getElement()) { - Object node = Util.findWidget(element, TreeNode.class); + Object node = WidgetUtil.findWidget(element, TreeNode.class); if (node != null) { TreeNode tnode = (TreeNode) node; diff --git a/client/src/com/vaadin/client/ui/treetable/TreeTableConnector.java b/client/src/com/vaadin/client/ui/treetable/TreeTableConnector.java index 5a42484b28..4aab248e29 100644 --- a/client/src/com/vaadin/client/ui/treetable/TreeTableConnector.java +++ b/client/src/com/vaadin/client/ui/treetable/TreeTableConnector.java @@ -19,7 +19,7 @@ import com.google.gwt.dom.client.Element; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.TooltipInfo; import com.vaadin.client.UIDL; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.FocusableScrollPanel; import com.vaadin.client.ui.VScrollTable.VScrollTableBody.VScrollTableRow; import com.vaadin.client.ui.VTreeTable; @@ -129,7 +129,7 @@ public class TreeTableConnector extends TableConnector { TooltipInfo info = null; if (element != getWidget().getElement()) { - Object node = Util.findWidget(element, VTreeTableRow.class); + Object node = WidgetUtil.findWidget(element, VTreeTableRow.class); if (node != null) { VTreeTableRow row = (VTreeTableRow) node; diff --git a/client/src/com/vaadin/client/ui/window/WindowConnector.java b/client/src/com/vaadin/client/ui/window/WindowConnector.java index b3e3c9f70f..b47152b903 100644 --- a/client/src/com/vaadin/client/ui/window/WindowConnector.java +++ b/client/src/com/vaadin/client/ui/window/WindowConnector.java @@ -38,7 +38,7 @@ import com.vaadin.client.ConnectorHierarchyChangeEvent; import com.vaadin.client.LayoutManager; import com.vaadin.client.Paintable; import com.vaadin.client.UIDL; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.communication.RpcProxy; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.ui.AbstractSingleComponentContainerConnector; @@ -247,7 +247,7 @@ public class WindowConnector extends AbstractSingleComponentContainerConnector Style childStyle = layoutElement.getStyle(); // IE8 needs some hackery to measure its content correctly - Util.forceIE8Redraw(layoutElement); + WidgetUtil.forceIE8Redraw(layoutElement); if (content.isRelativeHeight() && !BrowserInfo.get().isIE9()) { childStyle.setPosition(Position.ABSOLUTE); diff --git a/client/src/com/vaadin/client/widget/escalator/ScrollbarBundle.java b/client/src/com/vaadin/client/widget/escalator/ScrollbarBundle.java index 883bbae0bd..d7122329b7 100644 --- a/client/src/com/vaadin/client/widget/escalator/ScrollbarBundle.java +++ b/client/src/com/vaadin/client/widget/escalator/ScrollbarBundle.java @@ -31,7 +31,7 @@ import com.google.gwt.user.client.Event; import com.google.gwt.user.client.EventListener; import com.google.gwt.user.client.Timer; import com.vaadin.client.DeferredWorker; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.widget.grid.events.ScrollEvent; import com.vaadin.client.widget.grid.events.ScrollHandler; @@ -490,7 +490,7 @@ public abstract class ScrollbarBundle implements DeferredWorker { double oldScrollPos = scrollPos; scrollPos = Math.max(0, Math.min(maxScrollPos, truncate(px))); - if (!Util.pixelValuesEqual(oldScrollPos, scrollPos)) { + if (!WidgetUtil.pixelValuesEqual(oldScrollPos, scrollPos)) { if (isInvisibleScrollbar) { invisibleScrollbarTemporaryResizer.show(); } diff --git a/client/src/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java b/client/src/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java index ea19e04c8e..5024c8bffa 100644 --- a/client/src/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java +++ b/client/src/com/vaadin/client/widget/grid/selection/MultiSelectionRenderer.java @@ -32,7 +32,7 @@ import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Event.NativePreviewEvent; import com.google.gwt.user.client.Event.NativePreviewHandler; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.renderers.ComplexRenderer; import com.vaadin.client.widget.grid.CellReference; import com.vaadin.client.widget.grid.RendererCellReference; @@ -260,7 +260,7 @@ public class MultiSelectionRenderer<T> extends ComplexRenderer<Boolean> { int constrainedPageY = Math.max(bodyAbsoluteTop, Math.min(bodyAbsoluteBottom, pageY)); - int logicalRow = getLogicalRowIndex(Util.getElementFromPoint( + int logicalRow = getLogicalRowIndex(WidgetUtil.getElementFromPoint( initialPageX, constrainedPageY)); int incrementOrDecrement = (logicalRow > lastModifiedLogicalRow) ? 1 @@ -434,8 +434,8 @@ public class MultiSelectionRenderer<T> extends ComplexRenderer<Boolean> { switch (event.getTypeInt()) { case Event.ONMOUSEMOVE: case Event.ONTOUCHMOVE: - pageY = Util.getTouchOrMouseClientY(nativeEvent); - pageX = Util.getTouchOrMouseClientX(nativeEvent); + pageY = WidgetUtil.getTouchOrMouseClientY(nativeEvent); + pageX = WidgetUtil.getTouchOrMouseClientX(nativeEvent); autoScroller.updatePointerCoords(pageX, pageY); break; case Event.ONMOUSEUP: diff --git a/client/src/com/vaadin/client/widgets/Escalator.java b/client/src/com/vaadin/client/widgets/Escalator.java index 57c55d457d..2d131b71c5 100644 --- a/client/src/com/vaadin/client/widgets/Escalator.java +++ b/client/src/com/vaadin/client/widgets/Escalator.java @@ -53,7 +53,7 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.BrowserInfo; import com.vaadin.client.DeferredWorker; import com.vaadin.client.Profiler; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.widget.escalator.Cell; import com.vaadin.client.widget.escalator.ColumnConfiguration; import com.vaadin.client.widget.escalator.EscalatorUpdater; @@ -1061,10 +1061,11 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker final double viewportStartPx = getScrollLeft(); double viewportEndPx = viewportStartPx - + Util.getRequiredWidthBoundingClientRectDouble(getElement()) + + WidgetUtil + .getRequiredWidthBoundingClientRectDouble(getElement()) - frozenPixels; if (verticalScrollbar.showsScrollHandle()) { - viewportEndPx -= Util.getNativeScrollbarSize(); + viewportEndPx -= WidgetUtil.getNativeScrollbarSize(); } final double scrollLeft = getScrollPos(destination, targetStartPx, @@ -1731,9 +1732,8 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker final boolean isVisible = !cell.getStyle().getDisplay() .equals(Display.NONE.getCssName()); if (isVisible) { - maxWidth = Math - .max(maxWidth, - Util.getRequiredWidthBoundingClientRectDouble(cell)); + maxWidth = Math.max(maxWidth, WidgetUtil + .getRequiredWidthBoundingClientRectDouble(cell)); } row = TableRowElement.as(row.getNextSiblingElement()); } @@ -2011,7 +2011,7 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker cellClone.getStyle().clearWidth(); rowElement.insertBefore(cellClone, cellOriginal); - double requiredWidth = Util + double requiredWidth = WidgetUtil .getRequiredWidthBoundingClientRectDouble(cellClone); if (BrowserInfo.get().isIE9()) { @@ -3681,7 +3681,7 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker private TableRowElement getEscalatorRowWithFocus() { TableRowElement rowContainingFocus = null; - final Element focusedElement = Util.getFocusedElement(); + final Element focusedElement = WidgetUtil.getFocusedElement(); if (focusedElement != null && root.isOrHasChild(focusedElement)) { Element e = focusedElement; @@ -4307,12 +4307,13 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker root.appendChild(verticalScrollbar.getElement()); verticalScrollbar.addScrollHandler(scrollHandler); - verticalScrollbar.setScrollbarThickness(Util.getNativeScrollbarSize()); + verticalScrollbar.setScrollbarThickness(WidgetUtil + .getNativeScrollbarSize()); root.appendChild(horizontalScrollbar.getElement()); horizontalScrollbar.addScrollHandler(scrollHandler); - horizontalScrollbar - .setScrollbarThickness(Util.getNativeScrollbarSize()); + horizontalScrollbar.setScrollbarThickness(WidgetUtil + .getNativeScrollbarSize()); horizontalScrollbar .addVisibilityHandler(new ScrollbarBundle.VisibilityHandler() { @Override @@ -4338,18 +4339,18 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker table.appendChild(footElem); Style hCornerStyle = headerDeco.getStyle(); - hCornerStyle.setWidth(Util.getNativeScrollbarSize(), Unit.PX); + hCornerStyle.setWidth(WidgetUtil.getNativeScrollbarSize(), Unit.PX); hCornerStyle.setDisplay(Display.NONE); root.appendChild(headerDeco); Style fCornerStyle = footerDeco.getStyle(); - fCornerStyle.setWidth(Util.getNativeScrollbarSize(), Unit.PX); + fCornerStyle.setWidth(WidgetUtil.getNativeScrollbarSize(), Unit.PX); fCornerStyle.setDisplay(Display.NONE); root.appendChild(footerDeco); Style hWrapperStyle = horizontalScrollbarDeco.getStyle(); hWrapperStyle.setDisplay(Display.NONE); - hWrapperStyle.setHeight(Util.getNativeScrollbarSize(), Unit.PX); + hWrapperStyle.setHeight(WidgetUtil.getNativeScrollbarSize(), Unit.PX); root.appendChild(horizontalScrollbarDeco); setStylePrimaryName("v-escalator"); @@ -4721,10 +4722,10 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker } Profiler.enter("Escalator.recalculateElementSizes"); - widthOfEscalator = Math.max(0, - Util.getRequiredWidthBoundingClientRectDouble(getElement())); - heightOfEscalator = Math.max(0, - Util.getRequiredHeightBoundingClientRectDouble(getElement())); + widthOfEscalator = Math.max(0, WidgetUtil + .getRequiredWidthBoundingClientRectDouble(getElement())); + heightOfEscalator = Math.max(0, WidgetUtil + .getRequiredHeightBoundingClientRectDouble(getElement())); header.recalculateSectionHeight(); body.recalculateSectionHeight(); @@ -4828,7 +4829,7 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker @SuppressWarnings("deprecation") com.google.gwt.user.client.Element castElement = (com.google.gwt.user.client.Element) possibleWidgetNode .cast(); - Widget w = Util.findWidget(castElement, null); + Widget w = WidgetUtil.findWidget(castElement, null); // Ensure findWidget did not traverse past the cell element in the // DOM hierarchy @@ -5086,6 +5087,7 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker * @return escalator's inner width */ public double getInnerWidth() { - return Util.getRequiredWidthBoundingClientRectDouble(tableWrapper); + return WidgetUtil + .getRequiredWidthBoundingClientRectDouble(tableWrapper); } } diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index 1bca9e84ae..d401b4da78 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -59,7 +59,7 @@ import com.google.gwt.user.client.ui.HasWidgets; import com.google.gwt.user.client.ui.ResizeComposite; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.DeferredWorker; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.data.DataChangeHandler; import com.vaadin.client.data.DataSource; import com.vaadin.client.renderers.ComplexRenderer; @@ -1186,8 +1186,10 @@ public class Grid<T> extends ResizeComposite implements int bodyTop = body.getElement().getAbsoluteTop(); int wrapperTop = tableWrapper.getAbsoluteTop(); - double width = Util.getRequiredWidthBoundingClientRectDouble(tr); - double height = Util.getRequiredHeightBoundingClientRectDouble(tr); + double width = WidgetUtil + .getRequiredWidthBoundingClientRectDouble(tr); + double height = WidgetUtil + .getRequiredHeightBoundingClientRectDouble(tr); setBounds(editorOverlay, tr.getOffsetLeft(), rowTop + bodyTop - wrapperTop, width, height); @@ -1276,8 +1278,10 @@ public class Grid<T> extends ResizeComposite implements */ protected Element createCell(TableCellElement td) { DivElement cell = DivElement.as(DOM.createDiv()); - double width = Util.getRequiredWidthBoundingClientRectDouble(td); - double height = Util.getRequiredHeightBoundingClientRectDouble(td); + double width = WidgetUtil + .getRequiredWidthBoundingClientRectDouble(td); + double height = WidgetUtil + .getRequiredHeightBoundingClientRectDouble(td); setBounds(cell, td.getOffsetLeft(), td.getOffsetTop(), width, height); return cell; @@ -3169,7 +3173,7 @@ public class Grid<T> extends ResizeComposite implements Renderer renderer = findRenderer(cell); if (renderer instanceof WidgetRenderer) { try { - Widget w = Util.findWidget(cell.getElement() + Widget w = WidgetUtil.findWidget(cell.getElement() .getFirstChildElement(), Widget.class); if (w != null) { @@ -4516,7 +4520,7 @@ public class Grid<T> extends ResizeComposite implements } private boolean isElementInChildWidget(Element e) { - Widget w = Util.findWidget(e, null); + Widget w = WidgetUtil.findWidget(e, null); if (w == this) { return false; diff --git a/uitest/src/com/vaadin/tests/widgetset/client/BasicExtensionTestConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/BasicExtensionTestConnector.java index 6bd2abec60..18852f51c7 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/BasicExtensionTestConnector.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/BasicExtensionTestConnector.java @@ -19,7 +19,7 @@ package com.vaadin.tests.widgetset.client; import com.google.gwt.dom.client.DivElement; import com.google.gwt.dom.client.Document; import com.vaadin.client.ServerConnector; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.extensions.AbstractExtensionConnector; import com.vaadin.shared.ui.Connect; import com.vaadin.tests.extensions.BasicExtension; @@ -35,8 +35,8 @@ public class BasicExtensionTestConnector extends AbstractExtensionConnector { } private void appendMessage(String action) { - String message = Util.getSimpleName(this) + action - + Util.getSimpleName(target); + String message = WidgetUtil.getSimpleName(this) + action + + WidgetUtil.getSimpleName(target); DivElement element = Document.get().createDivElement(); element.setInnerText(message); diff --git a/uitest/src/com/vaadin/tests/widgetset/client/CustomUIConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/CustomUIConnector.java index b43da8e27e..a6d9291873 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/CustomUIConnector.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/CustomUIConnector.java @@ -18,7 +18,7 @@ package com.vaadin.tests.widgetset.client; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.SpanElement; -import com.vaadin.client.Util; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.ui.UIConnector; import com.vaadin.shared.ui.Connect; import com.vaadin.ui.UI; @@ -33,7 +33,7 @@ public class CustomUIConnector extends UIConnector { public void test() { SpanElement span = Document.get().createSpanElement(); span.setInnerText("This is the " - + Util.getSimpleName(CustomUIConnector.this)); + + WidgetUtil.getSimpleName(CustomUIConnector.this)); Document.get().getBody().insertFirst(span); } }); |