com.vaadin.terminal.gwt.client.
Class Util
java.lang.Object
com.vaadin.terminal.gwt.client.Util
- extends Object
public class Util
Constructor Summary | |
---|---|
Util()
|
Method Summary | ||
---|---|---|
static void |
addPngFix(com.google.gwt.user.client.Element el)
Adds transparent PNG fix to image element; only use for IE6. |
|
static void |
alert(String string)
|
|
static void |
browserDebugger()
Helper method for debugging purposes. |
|
static com.google.gwt.user.client.Element |
cloneNode(com.google.gwt.user.client.Element element,
boolean deep)
Clones given element as in JavaScript. |
|
static void |
componentSizeUpdated(Set<Paintable> paintables)
Called when the size of one or more widgets have changed during rendering. |
|
static void |
detachAttach(com.google.gwt.user.client.Element element)
Detaches and re-attaches the element from its parent. |
|
static void |
doIE6PngFix(com.google.gwt.user.client.Element el)
|
|
static boolean |
equals(Object a,
Object b)
|
|
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
|
findWidget(com.google.gwt.user.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 void |
focus(com.google.gwt.user.client.Element el)
Will (attempt) to focus the given DOM Element. |
|
static void |
forceWebkitRedraw(com.google.gwt.user.client.Element element)
Force webkit to redraw an element |
|
static int |
getChildElementIndex(com.google.gwt.user.client.Element childElement)
Returns the index of the childElement within its parent. |
|
static Paintable |
getChildPaintableForElement(ApplicationConnection client,
Container parent,
com.google.gwt.user.client.Element element)
Locates the child component of |
|
static com.google.gwt.user.client.Element |
getElementFromPoint(int clientX,
int clientY)
Returns the topmost element of from given coordinates. |
|
static com.google.gwt.user.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.user.client.Element |
getIEFocusedElement()
Gets the currently focused element for Internet Explorer. |
|
static Container |
getLayout(com.google.gwt.user.client.ui.Widget component)
Returns closest parent Widget in hierarchy that implements Container interface |
|
static int |
getNativeScrollbarSize()
|
|
static Paintable |
getPaintableForElement(ApplicationConnection client,
com.google.gwt.user.client.ui.Widget parent,
com.google.gwt.user.client.Element element)
Locates the nested child component of |
|
static int |
getRequiredHeight(com.google.gwt.dom.client.Element element)
|
|
static int |
getRequiredHeight(com.google.gwt.user.client.ui.Widget widget)
|
|
static int |
getRequiredWidth(com.google.gwt.dom.client.Element element)
|
|
static int |
getRequiredWidth(com.google.gwt.user.client.ui.Widget widget)
|
|
static String |
getSimpleName(Object widget)
|
|
static int |
getTouchOrMouseClientX(com.google.gwt.user.client.Event event)
A helper method to return the client position from an event. |
|
static int |
getTouchOrMouseClientX(com.google.gwt.dom.client.NativeEvent event)
|
|
static int |
getTouchOrMouseClientY(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 boolean |
isAttachedAndDisplayed(com.google.gwt.user.client.ui.Widget widget)
Kind of stronger version of isAttached(). |
|
static boolean |
isCached(UIDL uidl)
|
|
static boolean |
isFF2()
Deprecated. use BrowserInfo class instead |
|
static boolean |
isIE()
Deprecated. use BrowserInfo class instead |
|
static boolean |
isIE6()
Deprecated. use BrowserInfo class instead |
|
static boolean |
isIE7()
Deprecated. use BrowserInfo class instead |
|
static boolean |
isTouchEvent(com.google.gwt.user.client.Event event)
|
|
static boolean |
isTouchEvent(com.google.gwt.dom.client.NativeEvent 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.user.client.Element element)
|
|
static int |
measureHorizontalPaddingAndBorder(com.google.gwt.user.client.Element element,
int paddingGuess)
|
|
static int |
measureMarginLeft(com.google.gwt.user.client.Element element)
|
|
static int |
measureVerticalBorder(com.google.gwt.user.client.Element element)
|
|
static int |
measureVerticalPaddingAndBorder(com.google.gwt.user.client.Element element,
int paddingGuess)
|
|
static void |
notifyParentOfSizeChange(Paintable widget,
boolean lazy)
This helper method can be called if components size have been changed outside rendering phase. |
|
static float |
parseRelativeSize(String size)
|
|
static RenderInformation.FloatSize |
parseRelativeSize(UIDL uidl)
Parses the UIDL parameter and fetches the relative size of the component. |
|
static void |
runIE7ZeroSizedBodyFix()
IE7 sometimes "forgets" to render content. |
|
static void |
runWebkitOverflowAutoFix(com.google.gwt.user.client.Element elem)
Run workaround for webkits overflow auto issue. |
|
static void |
scrollIntoViewVertically(com.google.gwt.user.client.Element elem)
Scrolls an element into view vertically only. |
|
static void |
setFloat(com.google.gwt.user.client.Element element,
String value)
|
|
static int |
setHeightExcludingPaddingAndBorder(com.google.gwt.user.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 |
setIEFocusedElement(com.google.gwt.user.client.Element elem)
Gets the currently focused element for Internet Explorer. |
|
static void |
setStyleTemporarily(com.google.gwt.user.client.Element element,
String styleProperty,
String tempValue)
Temporarily sets the styleProperty to tempValue and then
resets it to its current value. |
|
static int |
setWidthExcludingPaddingAndBorder(com.google.gwt.user.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 |
shakeBodyElement()
Does some very small adjustments to body element. |
|
static void |
simulateClickFromTouchEvent(com.google.gwt.user.client.Event touchevent,
com.google.gwt.user.client.ui.Widget widget)
|
|
static void |
sinkOnloadForImages(com.google.gwt.user.client.Element element)
|
|
static void |
updateRelativeChildrenAndSendSizeUpdateEvent(ApplicationConnection client,
com.google.gwt.user.client.ui.HasWidgets container)
|
|
static void |
updateRelativeChildrenAndSendSizeUpdateEvent(ApplicationConnection client,
com.google.gwt.user.client.ui.HasWidgets container,
Paintable widget)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
Util
public Util()
Method Detail |
---|
browserDebugger
public static void browserDebugger()
Helper method for debugging purposes. Stops execution on firefox browsers on a breakpoint.
getElementFromPoint
public static com.google.gwt.user.client.Element getElementFromPoint(int clientX,
int clientY)
- Parameters:
x
-y
-- Returns:
- the element at given coordinates
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.
notifyParentOfSizeChange
public static void notifyParentOfSizeChange(Paintable widget,
boolean lazy)
- Parameters:
widget
-lazy
- run componentSizeUpdated lazyly
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.
componentSizeUpdated
public static void componentSizeUpdated(Set<Paintable> paintables)
- Parameters:
paintables
-
Called when the size of one or more widgets have changed during rendering. Finds parent container and notifies them of the size change.
parseRelativeSize
public static float parseRelativeSize(String size)
getLayout
public static Container getLayout(com.google.gwt.user.client.ui.Widget component)
- Parameters:
component
-- Returns:
- closest parent Container
Returns closest parent Widget in hierarchy that implements Container interface
isIE
@Deprecated
public static boolean isIE()
- Returns:
- true if IE
Deprecated. use BrowserInfo class instead
Detects if current browser is IE.
isIE6
@Deprecated
public static boolean isIE6()
- Returns:
- true if IE6
Deprecated. use BrowserInfo class instead
Detects if current browser is IE6.
isIE7
@Deprecated
public static boolean isIE7()
- Returns:
Deprecated. use BrowserInfo class instead
isFF2
@Deprecated
public static boolean isFF2()
- Returns:
Deprecated. use BrowserInfo class instead
escapeHTML
public static String escapeHTML(String html)
- Parameters:
html
-- Returns:
- escaped string presentation of given html
Converts html entities to text.
escapeAttribute
public static String escapeAttribute(String attribute)
- Parameters:
attribute
- The string to escape- Returns:
- An escaped version of
attribute .
Escapes the string so it is safe to write inside an HTML attribute.
addPngFix
public static void addPngFix(com.google.gwt.user.client.Element el)
- Parameters:
el
- IMG element
Adds transparent PNG fix to image element; only use for IE6.
doIE6PngFix
public static void doIE6PngFix(com.google.gwt.user.client.Element el)
cloneNode
public static com.google.gwt.user.client.Element cloneNode(com.google.gwt.user.client.Element element,
boolean deep)
- Parameters:
element
-deep
- clone child tree also- Returns:
Clones given element as in JavaScript. Deprecate this if there appears similar method into GWT someday.
measureHorizontalPaddingAndBorder
public static int measureHorizontalPaddingAndBorder(com.google.gwt.user.client.Element element,
int paddingGuess)
measureVerticalPaddingAndBorder
public static int measureVerticalPaddingAndBorder(com.google.gwt.user.client.Element element,
int paddingGuess)
measureHorizontalBorder
public static int measureHorizontalBorder(com.google.gwt.user.client.Element element)
measureVerticalBorder
public static int measureVerticalBorder(com.google.gwt.user.client.Element element)
measureMarginLeft
public static int measureMarginLeft(com.google.gwt.user.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.user.client.Element element,
int requestedWidth,
int horizontalPaddingBorderGuess,
boolean requestedWidthIncludesPaddingBorder)
setHeightExcludingPaddingAndBorder
public static int setHeightExcludingPaddingAndBorder(com.google.gwt.user.client.Element element,
int requestedHeight,
int verticalPaddingBorderGuess,
boolean requestedHeightIncludesPaddingBorder)
getSimpleName
public static String getSimpleName(Object widget)
setFloat
public static void setFloat(com.google.gwt.user.client.Element element,
String value)
getNativeScrollbarSize
public static int getNativeScrollbarSize()
runWebkitOverflowAutoFix
public static void runWebkitOverflowAutoFix(com.google.gwt.user.client.Element elem)
- Parameters:
elem
- with overflow auto
Run workaround for webkits overflow auto issue. See: our bug #2138 and https://bugs.webkit.org/show_bug.cgi?id=21462
parseRelativeSize
public static RenderInformation.FloatSize parseRelativeSize(UIDL uidl)
- Parameters:
uidl
-- Returns:
Parses the UIDL parameter and fetches the relative size of the component. If a dimension is not specified as relative it will return -1. If the UIDL does not contain width or height specifications this will return null.
isCached
public static boolean isCached(UIDL uidl)
alert
public static void alert(String string)
equals
public static boolean equals(Object a,
Object b)
updateRelativeChildrenAndSendSizeUpdateEvent
public static void updateRelativeChildrenAndSendSizeUpdateEvent(ApplicationConnection client,
com.google.gwt.user.client.ui.HasWidgets container)
updateRelativeChildrenAndSendSizeUpdateEvent
public static void updateRelativeChildrenAndSendSizeUpdateEvent(ApplicationConnection client,
com.google.gwt.user.client.ui.HasWidgets container,
Paintable widget)
getRequiredWidth
public static int getRequiredWidth(com.google.gwt.dom.client.Element element)
getRequiredHeight
public static int getRequiredHeight(com.google.gwt.dom.client.Element element)
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)
- Parameters:
pe
- the element to detect- Returns:
- true if auto or scroll
Detects what is currently the overflow style attribute in given element.
runIE7ZeroSizedBodyFix
public static void runIE7ZeroSizedBodyFix()
IE7 sometimes "forgets" to render content. This function runs a hack to workaround the bug if needed. This happens easily in framset. See #3295.
shakeBodyElement
public static void shakeBodyElement()
Does some very small adjustments to body element. We need this just to overcome some IE bugs.
getChildPaintableForElement
public static Paintable getChildPaintableForElement(ApplicationConnection client,
Container parent,
com.google.gwt.user.client.Element element)
- Parameters:
client
- A reference to ApplicationConnectionparent
- The widget that containselement .element
- An element that is a sub element of the parent- Returns:
- The Paintable which the element is a part of. Null if the element does not belong to a child.
Locates the child component of #getPaintableForElement(ApplicationConnection, Container, Element)
for the deepest nested paintable of parent that contains the element.
getPaintableForElement
public static Paintable getPaintableForElement(ApplicationConnection client,
com.google.gwt.user.client.ui.Widget parent,
com.google.gwt.user.client.Element element)
- Parameters:
client
- A reference to ApplicationConnectionparent
- The widget that containselement .element
- An element that is a sub element of the parent- Returns:
- The Paintable which the element is a part of. Null if the element does not belong to a child.
Locates the nested child component of getChildPaintableForElement(ApplicationConnection, Container, Element)
for the immediate child component of parent that contains the element.
focus
public static void focus(com.google.gwt.user.client.Element el)
- Parameters:
el
- the element to focus
Will (attempt) to focus the given DOM Element.
findWidget
public static <T> T findWidget(com.google.gwt.user.client.Element element,
Class<? extends com.google.gwt.user.client.ui.Widget> class1)
- Parameters:
element
- the element where to start seeking of Widgetclass1
- the Widget type to seek for
Helper method to find first instance of given Widget type found by traversing DOM upwards from given element.
forceWebkitRedraw
public static void forceWebkitRedraw(com.google.gwt.user.client.Element element)
- Parameters:
element
- The element that should be redrawn
Force webkit to redraw an element
detachAttach
public static void detachAttach(com.google.gwt.user.client.Element element)
- Parameters:
element
- The element to detach and re-attach
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.
sinkOnloadForImages
public static void sinkOnloadForImages(com.google.gwt.user.client.Element element)
getChildElementIndex
public static int getChildElementIndex(com.google.gwt.user.client.Element childElement)
- Parameters:
subElement
-- Returns:
Returns the index of the childElement within its parent.
setStyleTemporarily
public static void setStyleTemporarily(com.google.gwt.user.client.Element element,
String styleProperty,
String tempValue)
- Parameters:
element
- The target elementstyleProperty
- The name of the property to settempValue
- The temporary value
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)
getTouchOrMouseClientX
public static int getTouchOrMouseClientX(com.google.gwt.user.client.Event event)
- Parameters:
event
-- Returns:
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.
getElementUnderMouse
public static com.google.gwt.user.client.Element getElementUnderMouse(com.google.gwt.dom.client.NativeEvent event)
- Parameters:
event
- the mouse event to get coordinates from- Returns:
- the element at the coordinates of the 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.
getTouchOrMouseClientY
public static int getTouchOrMouseClientY(com.google.gwt.user.client.Event event)
- Parameters:
event
-- Returns:
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.
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)
getIEFocusedElement
public static com.google.gwt.user.client.Element getIEFocusedElement()
- Returns:
- The currently focused element
Gets the currently focused element for Internet Explorer.
setIEFocusedElement
public static void setIEFocusedElement(com.google.gwt.user.client.Element elem)
Gets the currently focused element for Internet Explorer.
isAttachedAndDisplayed
public static boolean isAttachedAndDisplayed(com.google.gwt.user.client.ui.Widget widget)
- Parameters:
widget
-- Returns:
- true if attached and displayed
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.
scrollIntoViewVertically
public static void scrollIntoViewVertically(com.google.gwt.user.client.Element elem)
- Parameters:
elem
- The element to scroll into view
Scrolls an element into view vertically only. Modified version of Element.scrollIntoView.
isTouchEventOrLeftMouseButton
public static boolean isTouchEventOrLeftMouseButton(com.google.gwt.user.client.Event event)
- Parameters:
event
-- Returns:
- true if the event is a touch event or caused by the left mouse button, false otherwise
Checks if the given event is either a touch event or caused by the left mouse button