Class WidgetUtil


  • public class WidgetUtil
    extends Object
    Utility methods which are related to client side code only
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  WidgetUtil.CssSize
      Wrap a css size value and its unit and translate back and forth to the string representation.
      Eg.
      static class  WidgetUtil.ErrorUtil
      Utility methods for displaying error message on components.
      static class  WidgetUtil.TextRectangle  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static double PIXEL_EPSILON
      The allowed value inaccuracy when comparing two double-typed pixel values.
    • Constructor Summary

      Constructors 
      Constructor Description
      WidgetUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void alert​(String string)  
      static void browserDebugger()
      Helper method for debugging purposes.
      static void clearTextSelection()
      JavaScript hack to clear text selection in various browsers.
      static com.google.gwt.dom.client.Element cloneNode​(com.google.gwt.dom.client.Element element, boolean deep)
      Clones given element as in JavaScript.
      static void detachAttach​(com.google.gwt.dom.client.Element element)
      Detaches and re-attaches the element from its parent.
      static String escapeAttribute​(String attribute)
      Escapes the string so it is safe to write inside an HTML attribute.
      static String escapeHTML​(String html)
      Converts html entities to text.
      static <T> T findWidget​(com.google.gwt.dom.client.Element element)
      Helper method to find first instance of any Widget found by traversing DOM upwards from given element.
      static <T> T findWidget​(com.google.gwt.dom.client.Element element, Class<? extends com.google.gwt.user.client.ui.Widget> class1)
      Helper method to find first instance of given Widget type found by traversing DOM upwards from given element.
      static <T> T findWidget​(com.google.gwt.dom.client.Element element, Class<? extends com.google.gwt.user.client.ui.Widget> class1, boolean exactMatch)
      Helper method to find first instance of given Widget type found by traversing DOM upwards from given element.
      static void focus​(com.google.gwt.dom.client.Element el)
      Will (attempt) to focus the given DOM Element.
      static void forceIE8Redraw​(com.google.gwt.dom.client.Element e)
      Performs a hack to trigger a re-layout in the IE8.
      static void forceIERedraw​(com.google.gwt.dom.client.Element e)
      Performs a hack to trigger a re-layout in the IE browser.
      static void forceWebkitRedraw​(com.google.gwt.dom.client.Element element)
      Force webkit to redraw an element
      static String getAbsoluteUrl​(String url)
      Resolve a relative URL to an absolute URL based on the current document's location.
      static double getBorderBottomThickness​(com.google.gwt.dom.client.Element element)
      Returns the thickness of the given element's bottom border.
      static double getBorderLeftAndRightThickness​(com.google.gwt.dom.client.Element element)
      Returns the thickness of the given element's left and right borders.
      static double getBorderLeftThickness​(com.google.gwt.dom.client.Element element)
      Returns the thickness of the given element's left border.
      static double getBorderRightThickness​(com.google.gwt.dom.client.Element element)
      Returns the thickness of the given element's right border.
      static double getBorderTopAndBottomThickness​(com.google.gwt.dom.client.Element element)
      Returns the combined thickness of the given element's top and bottom borders.
      static double getBorderTopThickness​(com.google.gwt.dom.client.Element element)
      Returns the thickness of the given element's top border.
      static WidgetUtil.TextRectangle getBoundingClientRect​(com.google.gwt.dom.client.Element e)  
      static int getChildElementIndex​(com.google.gwt.dom.client.Element childElement)
      Returns the index of the childElement within its parent.
      static com.google.gwt.dom.client.Element getElementFromPoint​(int clientX, int clientY)
      Returns the topmost element of from given coordinates.
      static com.google.gwt.dom.client.Element getElementUnderMouse​(com.google.gwt.dom.client.NativeEvent event)
      Find the element corresponding to the coordinates in the passed mouse event.
      static com.google.gwt.dom.client.Element getFocusedElement()
      Gets the currently focused element.
      static int getKeyCode​(com.google.gwt.event.dom.client.KeyEvent<?> event)
      Helper method for a bug fix #14041.
      static int getNativeScrollbarSize()  
      static int getRequiredHeight​(com.google.gwt.dom.client.Element element)
      Gets the border-box height for the given element, i.e.
      static int getRequiredHeight​(com.google.gwt.user.client.ui.Widget widget)  
      static int getRequiredHeightBoundingClientRect​(com.google.gwt.dom.client.Element element)
      Calculates the height of the element's bounding rectangle.
      static double getRequiredHeightBoundingClientRectDouble​(com.google.gwt.dom.client.Element element)
      Calculates the height of the element's bounding rectangle to subpixel precision.
      static int getRequiredHeightComputedStyle​(com.google.gwt.dom.client.Element element)  
      static double getRequiredHeightComputedStyleDouble​(com.google.gwt.dom.client.Element element)  
      static double getRequiredHeightDouble​(com.google.gwt.dom.client.Element element)
      Gets the border-box height for the given element, i.e.
      static int getRequiredWidth​(com.google.gwt.dom.client.Element element)
      Gets the border-box width for the given element, i.e.
      static int getRequiredWidth​(com.google.gwt.user.client.ui.Widget widget)  
      static int getRequiredWidthBoundingClientRect​(com.google.gwt.dom.client.Element element)
      Calculates the width of the element's bounding rectangle.
      static double getRequiredWidthBoundingClientRectDouble​(com.google.gwt.dom.client.Element element)
      Calculates the width of the element's bounding rectangle to subpixel precision.
      static int getRequiredWidthComputedStyle​(com.google.gwt.dom.client.Element element)  
      static int getRequiredWidthComputedStyleDouble​(com.google.gwt.dom.client.Element element)  
      static double getRequiredWidthDouble​(com.google.gwt.dom.client.Element element)
      Gets the border-box width for the given element, i.e.
      static int getTouchOrMouseClientX​(com.google.gwt.dom.client.NativeEvent event)  
      static int getTouchOrMouseClientX​(com.google.gwt.user.client.Event event)
      A helper method to return the client position from an event.
      static int getTouchOrMouseClientY​(com.google.gwt.dom.client.NativeEvent currentGwtEvent)  
      static int getTouchOrMouseClientY​(com.google.gwt.user.client.Event event)
      A helper method to return the client position from an event.
      static boolean isAttachedAndDisplayed​(com.google.gwt.user.client.ui.Widget widget)
      Kind of stronger version of isAttached().
      static boolean isDisplayed​(com.google.gwt.dom.client.Element element)
      Returns whether the given element is displayed.
      static boolean isFocusedElementEditable()
      Gets currently focused element and checks if it's editable
      static boolean isTouchEvent​(com.google.gwt.dom.client.NativeEvent event)  
      static boolean isTouchEvent​(com.google.gwt.user.client.Event event)  
      static boolean isTouchEventOrLeftMouseButton​(com.google.gwt.user.client.Event event)
      Checks if the given event is either a touch event or caused by the left mouse button
      static boolean mayHaveScrollBars​(com.google.gwt.dom.client.Element pe)
      Detects what is currently the overflow style attribute in given element.
      static int measureHorizontalBorder​(com.google.gwt.dom.client.Element element)  
      static int measureHorizontalPaddingAndBorder​(com.google.gwt.dom.client.Element element, int paddingGuess)  
      static int measureMarginLeft​(com.google.gwt.dom.client.Element element)  
      static int measureVerticalBorder​(com.google.gwt.dom.client.Element element)  
      static int measureVerticalPaddingAndBorder​(com.google.gwt.dom.client.Element element, int paddingGuess)  
      static float parseRelativeSize​(String size)  
      static boolean pixelValuesEqual​(double num1, double num2)
      Compares two double values with the error margin of PIXEL_EPSILON (i.e.
      static void redirect​(String url)
      Redirects the browser to the given url or refreshes the page if url is null
      static double roundSizeDown​(double size)
      Rounds the given size down to a value which the browser will accept.
      static double roundSizeUp​(double size)
      Rounds the given size up to a value which the browser will accept.
      static void runWebkitOverflowAutoFix​(com.google.gwt.dom.client.Element elem)
      Run workaround for webkits overflow auto issue.
      static void runWebkitOverflowAutoFixDeferred​(com.google.gwt.dom.client.Element elem)
      Defers the execution of runWebkitOverflowAutoFix(Element)
      static void scrollIntoViewVertically​(com.google.gwt.dom.client.Element elem)
      Scrolls an element into view vertically only.
      static void setFloat​(com.google.gwt.dom.client.Element element, String value)  
      static int setHeightExcludingPaddingAndBorder​(com.google.gwt.dom.client.Element element, int requestedHeight, int verticalPaddingBorderGuess, boolean requestedHeightIncludesPaddingBorder)  
      static int setHeightExcludingPaddingAndBorder​(com.google.gwt.user.client.ui.Widget widget, String height, int paddingBorderGuess)  
      static void setSelectionRange​(com.google.gwt.dom.client.Element elem, int pos, int length, String direction)
      Sets the selection range of an input element.
      static void setStyleTemporarily​(com.google.gwt.dom.client.Element element, String styleProperty, String tempValue)
      Temporarily sets the styleProperty to tempValue and then resets it to its current value.
      static void setTextSelectionEnabled​(com.google.gwt.dom.client.Element e, boolean enable)
      JavaScript hack to prevent text selection in various browsers.
      static int setWidthExcludingPaddingAndBorder​(com.google.gwt.dom.client.Element element, int requestedWidth, int horizontalPaddingBorderGuess, boolean requestedWidthIncludesPaddingBorder)  
      static int setWidthExcludingPaddingAndBorder​(com.google.gwt.user.client.ui.Widget widget, String width, int paddingBorderGuess)  
      static void simulateClickFromTouchEvent​(com.google.gwt.user.client.Event touchevent, com.google.gwt.user.client.ui.Widget widget)  
      static void sinkOnloadForImages​(com.google.gwt.dom.client.Element element)  
    • Field Detail

      • PIXEL_EPSILON

        public static final double PIXEL_EPSILON
        The allowed value inaccuracy when comparing two double-typed pixel values.

        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.

        See Also:
        Constant Field Values
    • Constructor Detail

      • WidgetUtil

        public WidgetUtil()
    • Method Detail

      • browserDebugger

        public static void browserDebugger()
        Helper method for debugging purposes. Stops execution on firefox browsers on a breakpoint.
      • redirect

        public static void redirect​(String url)
        Redirects the browser to the given url or refreshes the page if url is null
        Parameters:
        url - The url to redirect to or null to refresh
        Since:
        7.6
      • getKeyCode

        public static int getKeyCode​(com.google.gwt.event.dom.client.KeyEvent<?> event)
        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.
        Parameters:
        event -
        Returns:
        return key code
        Since:
        7.2.4
      • getElementFromPoint

        public static com.google.gwt.dom.client.Element getElementFromPoint​(int clientX,
                                                                            int clientY)
        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.
        Parameters:
        x -
        y -
        Returns:
        the element at given coordinates
      • parseRelativeSize

        public static float parseRelativeSize​(String size)
      • escapeHTML

        public static String escapeHTML​(String html)
        Converts html entities to text.
        Parameters:
        html -
        Returns:
        escaped string presentation of given html
      • escapeAttribute

        public static String escapeAttribute​(String attribute)
        Escapes the string so it is safe to write inside an HTML attribute.
        Parameters:
        attribute - The string to escape
        Returns:
        An escaped version of attribute.
      • cloneNode

        public static com.google.gwt.dom.client.Element cloneNode​(com.google.gwt.dom.client.Element element,
                                                                  boolean deep)
        Clones given element as in JavaScript. Deprecate this if there appears similar method into GWT someday.
        Parameters:
        element -
        deep - clone child tree also
        Returns:
      • measureHorizontalPaddingAndBorder

        public static int measureHorizontalPaddingAndBorder​(com.google.gwt.dom.client.Element element,
                                                            int paddingGuess)
      • measureVerticalPaddingAndBorder

        public static int measureVerticalPaddingAndBorder​(com.google.gwt.dom.client.Element element,
                                                          int paddingGuess)
      • measureHorizontalBorder

        public static int measureHorizontalBorder​(com.google.gwt.dom.client.Element element)
      • measureVerticalBorder

        public static int measureVerticalBorder​(com.google.gwt.dom.client.Element element)
      • measureMarginLeft

        public static int measureMarginLeft​(com.google.gwt.dom.client.Element element)
      • setHeightExcludingPaddingAndBorder

        public static int setHeightExcludingPaddingAndBorder​(com.google.gwt.user.client.ui.Widget widget,
                                                             String height,
                                                             int paddingBorderGuess)
      • setWidthExcludingPaddingAndBorder

        public static int setWidthExcludingPaddingAndBorder​(com.google.gwt.user.client.ui.Widget widget,
                                                            String width,
                                                            int paddingBorderGuess)
      • setWidthExcludingPaddingAndBorder

        public static int setWidthExcludingPaddingAndBorder​(com.google.gwt.dom.client.Element element,
                                                            int requestedWidth,
                                                            int horizontalPaddingBorderGuess,
                                                            boolean requestedWidthIncludesPaddingBorder)
      • setHeightExcludingPaddingAndBorder

        public static int setHeightExcludingPaddingAndBorder​(com.google.gwt.dom.client.Element element,
                                                             int requestedHeight,
                                                             int verticalPaddingBorderGuess,
                                                             boolean requestedHeightIncludesPaddingBorder)
      • setFloat

        public static void setFloat​(com.google.gwt.dom.client.Element element,
                                    String value)
      • getNativeScrollbarSize

        public static int getNativeScrollbarSize()
      • runWebkitOverflowAutoFixDeferred

        public static void runWebkitOverflowAutoFixDeferred​(com.google.gwt.dom.client.Element elem)
        Defers the execution of runWebkitOverflowAutoFix(Element)
        Parameters:
        elem - with overflow auto
        Since:
        7.2.6
      • runWebkitOverflowAutoFix

        public static void runWebkitOverflowAutoFix​(com.google.gwt.dom.client.Element elem)
        Run workaround for webkits overflow auto issue. See: our bug #2138 and https://bugs.webkit.org/show_bug.cgi?id=21462
        Parameters:
        elem - with overflow auto
      • alert

        public static void alert​(String string)
      • getRequiredWidth

        public static int getRequiredWidth​(com.google.gwt.dom.client.Element element)
        Gets the border-box width for the given element, i.e. element width + border + padding. Always rounds up to nearest integer.
        Parameters:
        element - The element to check
        Returns:
        The border-box width for the element
      • getRequiredWidthDouble

        public static double getRequiredWidthDouble​(com.google.gwt.dom.client.Element element)
        Gets the border-box width for the given element, i.e. element width + border + padding.
        Parameters:
        element - The element to check
        Returns:
        The border-box width for the element
        Since:
        7.5.1
      • getRequiredHeight

        public static int getRequiredHeight​(com.google.gwt.dom.client.Element element)
        Gets the border-box height for the given element, i.e. element height + border + padding. Always rounds up to nearest integer.
        Parameters:
        element - The element to check
        Returns:
        The border-box height for the element
      • getRequiredHeightDouble

        public static double getRequiredHeightDouble​(com.google.gwt.dom.client.Element element)
        Gets the border-box height for the given element, i.e. element height + border + padding.
        Parameters:
        element - The element to check
        Returns:
        The border-box height for the element
        Since:
        7.5.1
      • getRequiredWidthBoundingClientRect

        public static int getRequiredWidthBoundingClientRect​(com.google.gwt.dom.client.Element element)
        Calculates the width of the element's bounding rectangle.

        In case the browser doesn't support bounding rectangles, the returned value is the offset width.

        Parameters:
        element - the element of which to calculate the width
        Returns:
        the width of the element
      • getRequiredWidthBoundingClientRectDouble

        public static double getRequiredWidthBoundingClientRectDouble​(com.google.gwt.dom.client.Element element)
        Calculates the width of the element's bounding rectangle to subpixel precision.

        In case the browser doesn't support bounding rectangles, the returned value is the offset width.

        Parameters:
        element - the element of which to calculate the width
        Returns:
        the subpixel-accurate width of the element
        Since:
        7.4
      • getRequiredHeightComputedStyle

        public static int getRequiredHeightComputedStyle​(com.google.gwt.dom.client.Element element)
      • getRequiredHeightComputedStyleDouble

        public static double getRequiredHeightComputedStyleDouble​(com.google.gwt.dom.client.Element element)
      • getRequiredWidthComputedStyle

        public static int getRequiredWidthComputedStyle​(com.google.gwt.dom.client.Element element)
      • getRequiredWidthComputedStyleDouble

        public static int getRequiredWidthComputedStyleDouble​(com.google.gwt.dom.client.Element element)
      • getRequiredHeightBoundingClientRect

        public static int getRequiredHeightBoundingClientRect​(com.google.gwt.dom.client.Element element)
        Calculates the height of the element's bounding rectangle.

        In case the browser doesn't support bounding rectangles, the returned value is the offset height.

        Parameters:
        element - the element of which to calculate the height
        Returns:
        the height of the element
      • getRequiredHeightBoundingClientRectDouble

        public static double getRequiredHeightBoundingClientRectDouble​(com.google.gwt.dom.client.Element element)
        Calculates the height of the element's bounding rectangle to subpixel precision.

        In case the browser doesn't support bounding rectangles, the returned value is the offset height.

        Parameters:
        element - the element of which to calculate the height
        Returns:
        the subpixel-accurate height of the element
        Since:
        7.4
      • getRequiredWidth

        public static int getRequiredWidth​(com.google.gwt.user.client.ui.Widget widget)
      • getRequiredHeight

        public static int getRequiredHeight​(com.google.gwt.user.client.ui.Widget widget)
      • mayHaveScrollBars

        public static boolean mayHaveScrollBars​(com.google.gwt.dom.client.Element pe)
        Detects what is currently the overflow style attribute in given element.
        Parameters:
        pe - the element to detect
        Returns:
        true if auto or scroll
      • focus

        public static void focus​(com.google.gwt.dom.client.Element el)
        Will (attempt) to focus the given DOM Element.
        Parameters:
        el - the element to focus
      • findWidget

        public static <T> T findWidget​(com.google.gwt.dom.client.Element element)
        Helper method to find first instance of any Widget found by traversing DOM upwards from given element.

        Note: If element is inside some widget W , and W in turn is wrapped in a Composite C, this method will not find W but returns C. This may also be the case with other Composite-like classes that hijack the event handling of their child widget(s).

        Parameters:
        element - the element where to start seeking of Widget
        Since:
        7.7.11
      • findWidget

        public static <T> T findWidget​(com.google.gwt.dom.client.Element element,
                                       Class<? extends com.google.gwt.user.client.ui.Widget> class1)
        Helper method to find first instance of given Widget type found by traversing DOM upwards from given element.

        Note: If element is inside some widget W , and W in turn is wrapped in a Composite C, this method will not find W. It returns either 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).

        Only accepts the exact class class1 if not null.

        Parameters:
        element - the element where to start seeking of Widget
        class1 - the Widget type to seek for, null for any
      • findWidget

        public static <T> T findWidget​(com.google.gwt.dom.client.Element element,
                                       Class<? extends com.google.gwt.user.client.ui.Widget> class1,
                                       boolean exactMatch)
        Helper method to find first instance of given Widget type found by traversing DOM upwards from given element.

        Note: If element is inside some widget W , and W in turn is wrapped in a Composite C, this method will not find W. It returns either 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).

        Parameters:
        element - the element where to start seeking of Widget
        class1 - the Widget type to seek for
        exactMatch - true to only accept class1, false to also accept its superclasses
        Since:
        7.7.11
      • forceWebkitRedraw

        public static void forceWebkitRedraw​(com.google.gwt.dom.client.Element element)
        Force webkit to redraw an element
        Parameters:
        element - The element that should be redrawn
      • forceIE8Redraw

        public static final void forceIE8Redraw​(com.google.gwt.dom.client.Element e)
        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.
        Parameters:
        e - The element to perform the hack on
      • forceIERedraw

        public static void forceIERedraw​(com.google.gwt.dom.client.Element 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.
        Parameters:
        e - The element to perform the hack on
        Since:
        7.3
      • detachAttach

        public static void detachAttach​(com.google.gwt.dom.client.Element element)
        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.
        Parameters:
        element - The element to detach and re-attach
      • sinkOnloadForImages

        public static void sinkOnloadForImages​(com.google.gwt.dom.client.Element element)
      • getChildElementIndex

        public static int getChildElementIndex​(com.google.gwt.dom.client.Element childElement)
        Returns the index of the childElement within its parent.
        Parameters:
        subElement -
        Returns:
      • setStyleTemporarily

        public static void setStyleTemporarily​(com.google.gwt.dom.client.Element element,
                                               String styleProperty,
                                               String tempValue)
        Temporarily sets the styleProperty to tempValue and then resets it to its current value. Used mainly to work around rendering issues in IE (and possibly in other browsers)
        Parameters:
        element - The target element
        styleProperty - The name of the property to set
        tempValue - The temporary value
      • getTouchOrMouseClientX

        public static int getTouchOrMouseClientX​(com.google.gwt.user.client.Event 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.
        Parameters:
        event -
        Returns:
      • getElementUnderMouse

        public static com.google.gwt.dom.client.Element getElementUnderMouse​(com.google.gwt.dom.client.NativeEvent 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.
        Parameters:
        event - the mouse event to get coordinates from
        Returns:
        the element at the coordinates of the event
      • getTouchOrMouseClientY

        public static int getTouchOrMouseClientY​(com.google.gwt.user.client.Event 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.
        Parameters:
        event -
        Returns:
      • getTouchOrMouseClientY

        public static int getTouchOrMouseClientY​(com.google.gwt.dom.client.NativeEvent currentGwtEvent)
        Parameters:
        currentGwtEvent -
        Returns:
        See Also:
        getTouchOrMouseClientY(Event)
      • getTouchOrMouseClientX

        public static int getTouchOrMouseClientX​(com.google.gwt.dom.client.NativeEvent event)
        Parameters:
        event -
        Returns:
        See Also:
        getTouchOrMouseClientX(Event)
      • isTouchEvent

        public static boolean isTouchEvent​(com.google.gwt.user.client.Event event)
      • isTouchEvent

        public static boolean isTouchEvent​(com.google.gwt.dom.client.NativeEvent event)
      • simulateClickFromTouchEvent

        public static void simulateClickFromTouchEvent​(com.google.gwt.user.client.Event touchevent,
                                                       com.google.gwt.user.client.ui.Widget widget)
      • getFocusedElement

        public static com.google.gwt.dom.client.Element getFocusedElement()
        Gets the currently focused element.
        Returns:
        The active element or null if no active element could be found.
      • isFocusedElementEditable

        public static boolean isFocusedElementEditable()
        Gets currently focused element and checks if it's editable
        Returns:
        true if focused element is editable
        Since:
        7.4
      • isAttachedAndDisplayed

        public static boolean isAttachedAndDisplayed​(com.google.gwt.user.client.ui.Widget widget)
        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.
        Parameters:
        widget -
        Returns:
        true if attached and displayed
      • scrollIntoViewVertically

        public static void scrollIntoViewVertically​(com.google.gwt.dom.client.Element elem)
        Scrolls an element into view vertically only. Modified version of Element.scrollIntoView.
        Parameters:
        elem - The element to scroll into view
      • isTouchEventOrLeftMouseButton

        public static boolean isTouchEventOrLeftMouseButton​(com.google.gwt.user.client.Event event)
        Checks if the given event is either a touch event or caused by the left mouse button
        Parameters:
        event -
        Returns:
        true if the event is a touch event or caused by the left mouse button, false otherwise
      • getAbsoluteUrl

        public static String getAbsoluteUrl​(String url)
        Resolve a relative URL to an absolute URL based on the current document's location.
        Parameters:
        url - a string with the relative URL to resolve
        Returns:
        the corresponding absolute URL as a string
      • setSelectionRange

        public static void setSelectionRange​(com.google.gwt.dom.client.Element elem,
                                             int pos,
                                             int length,
                                             String direction)
        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)
        Parameters:
        elem - the html input element.
        pos - the index of the first selected character.
        length - the selection length.
        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
      • setTextSelectionEnabled

        public static void setTextSelectionEnabled​(com.google.gwt.dom.client.Element e,
                                                   boolean enable)
        JavaScript hack to prevent text selection in various browsers.
        Parameters:
        e - element for enabling or disabling text selection
        enable - true if selection is enabled; false if not
        Since:
        7.6
      • clearTextSelection

        public static void clearTextSelection()
        JavaScript hack to clear text selection in various browsers.
        Since:
        7.6
      • pixelValuesEqual

        public static boolean pixelValuesEqual​(double num1,
                                               double num2)
        Compares two double values with the error margin of PIXEL_EPSILON (i.e. 0.49)
        Parameters:
        num1 - the first value for which to compare equality
        num2 - the second value for which to compare equality
        Returns:
        true if the values are considered equals; false otherwise
        Since:
        7.4
      • getBoundingClientRect

        public static WidgetUtil.TextRectangle getBoundingClientRect​(com.google.gwt.dom.client.Element e)
      • getBorderTopThickness

        public static double getBorderTopThickness​(com.google.gwt.dom.client.Element element)
        Returns the thickness of the given element's top border.

        The value is determined using computed style when available and calculated otherwise.

        Parameters:
        element - the element to measure
        Returns:
        the top border thickness
        Since:
        7.5.0
      • getBorderBottomThickness

        public static double getBorderBottomThickness​(com.google.gwt.dom.client.Element element)
        Returns the thickness of the given element's bottom border.

        The value is determined using computed style when available and calculated otherwise.

        Parameters:
        element - the element to measure
        Returns:
        the bottom border thickness
        Since:
        7.5.0
      • getBorderTopAndBottomThickness

        public static double getBorderTopAndBottomThickness​(com.google.gwt.dom.client.Element element)
        Returns the combined thickness of the given element's top and bottom borders.

        The value is determined using computed style when available and calculated otherwise.

        Parameters:
        element - the element to measure
        Returns:
        the top and bottom border thickness
        Since:
        7.5.0
      • getBorderLeftThickness

        public static double getBorderLeftThickness​(com.google.gwt.dom.client.Element element)
        Returns the thickness of the given element's left border.

        The value is determined using computed style when available and calculated otherwise.

        Parameters:
        element - the element to measure
        Returns:
        the left border thickness
        Since:
        7.5.0
      • getBorderRightThickness

        public static double getBorderRightThickness​(com.google.gwt.dom.client.Element element)
        Returns the thickness of the given element's right border.

        The value is determined using computed style when available and calculated otherwise.

        Parameters:
        element - the element to measure
        Returns:
        the right border thickness
        Since:
        7.5.0
      • getBorderLeftAndRightThickness

        public static double getBorderLeftAndRightThickness​(com.google.gwt.dom.client.Element element)
        Returns the thickness of the given element's left and right borders.

        The value is determined using computed style when available and calculated otherwise.

        Parameters:
        element - the element to measure
        Returns:
        the top border thickness
        Since:
        7.5.0
      • roundSizeUp

        public static double roundSizeUp​(double size)
        Rounds the given size up to a value which the browser will accept. Safari/WebKit uses 1/64th of a pixel to enable using integer math (http://trac.webkit.org/wiki/LayoutUnit). Firefox uses 1/60th of a pixel because it is divisible by three (https://bugzilla.mozilla.org/show_bug.cgi?id=1070940)
        Parameters:
        size - the value to round
        Returns:
        the rounded value
        Since:
        7.5.1
      • roundSizeDown

        public static double roundSizeDown​(double size)
        Rounds the given size down to a value which the browser will accept. Safari/WebKit uses 1/64th of a pixel to enable using integer math (http://trac.webkit.org/wiki/LayoutUnit). Firefox uses 1/60th of a pixel because it is divisible by three (https://bugzilla.mozilla.org/show_bug.cgi?id=1070940) IE9+ uses 1/100th of a pixel
        Parameters:
        size - the value to round
        Returns:
        the rounded value
        Since:
        7.5.1
      • isDisplayed

        public static boolean isDisplayed​(com.google.gwt.dom.client.Element element)
        Returns whether the given element is displayed.

        This method returns false if either the given element or any of its ancestors has the style display: none applied.

        Parameters:
        element - the element to test for visibility
        Returns:
        true if the element is displayed, false otherwise
        Since:
        7.7.13