|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.vaadin.client.WidgetUtil
public class WidgetUtil
Utility methods which are related to client side code only
| Nested Class Summary | |
|---|---|
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.TextRectangle
|
| Field Summary | |
|---|---|
static double |
PIXEL_EPSILON
The allowed value inaccuracy when comparing two double-typed pixel values. |
| Constructor Summary | |
|---|---|
WidgetUtil()
|
|
| Method Summary | ||
|---|---|---|
static void |
alert(java.lang.String string)
|
|
static void |
browserDebugger()
Helper method for debugging purposes. |
|
static void |
clearTextSelection()
JavaScript hack to clear text selection in various browsers. |
|
static Element |
cloneNode(Element element,
boolean deep)
Clones given element as in JavaScript. |
|
static void |
detachAttach(Element element)
Detaches and re-attaches the element from its parent. |
|
static java.lang.String |
escapeAttribute(java.lang.String attribute)
Escapes the string so it is safe to write inside an HTML attribute. |
|
static java.lang.String |
escapeHTML(java.lang.String html)
Converts html entities to text. |
|
static
|
findWidget(Element element,
java.lang.Class<? extends Widget> class1)
Helper method to find first instance of given Widget type found by traversing DOM upwards from given element. |
|
static void |
focus(Element el)
Will (attempt) to focus the given DOM Element. |
|
static void |
forceIE8Redraw(Element e)
Performs a hack to trigger a re-layout in the IE8. |
|
static void |
forceIERedraw(Element e)
Performs a hack to trigger a re-layout in the IE browser. |
|
static void |
forceWebkitRedraw(Element element)
Force webkit to redraw an element |
|
static java.lang.String |
getAbsoluteUrl(java.lang.String url)
Resolve a relative URL to an absolute URL based on the current document's location. |
|
static double |
getBorderBottomThickness(Element element)
Returns the thickness of the given element's bottom border. |
|
static double |
getBorderLeftAndRightThickness(Element element)
Returns the thickness of the given element's left and right borders. |
|
static double |
getBorderLeftThickness(Element element)
Returns the thickness of the given element's left border. |
|
static double |
getBorderRightThickness(Element element)
Returns the thickness of the given element's right border. |
|
static double |
getBorderTopAndBottomThickness(Element element)
Returns the combined thickness of the given element's top and bottom borders. |
|
static double |
getBorderTopThickness(Element element)
Returns the thickness of the given element's top border. |
|
static WidgetUtil.TextRectangle |
getBoundingClientRect(Element e)
|
|
static int |
getChildElementIndex(Element childElement)
Returns the index of the childElement within its parent. |
|
static Element |
getElementFromPoint(int clientX,
int clientY)
Returns the topmost element of from given coordinates. |
|
static Element |
getElementUnderMouse(NativeEvent event)
Find the element corresponding to the coordinates in the passed mouse event. |
|
static Element |
getFocusedElement()
Gets the currently focused element. |
|
static int |
getKeyCode(
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(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(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(Event event)
A helper method to return the client position from an event. |
|
static int |
getTouchOrMouseClientX(NativeEvent event)
|
|
static int |
getTouchOrMouseClientY(Event event)
A helper method to return the client position from an event. |
|
static int |
getTouchOrMouseClientY(NativeEvent currentGwtEvent)
|
|
static boolean |
isAttachedAndDisplayed(Widget widget)
Kind of stronger version of isAttached(). |
|
static boolean |
isFocusedElementEditable()
Gets currently focused element and checks if it's editable |
|
static boolean |
isTouchEvent(Event event)
|
|
static boolean |
isTouchEvent(NativeEvent event)
|
|
static boolean |
isTouchEventOrLeftMouseButton(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(Element element)
|
|
static int |
measureHorizontalPaddingAndBorder(Element element,
int paddingGuess)
|
|
static int |
measureMarginLeft(Element element)
|
|
static int |
measureVerticalBorder(Element element)
|
|
static int |
measureVerticalPaddingAndBorder(Element element,
int paddingGuess)
|
|
static float |
parseRelativeSize(java.lang.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(java.lang.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(Element elem)
Run workaround for webkits overflow auto issue. |
|
static void |
runWebkitOverflowAutoFixDeferred(Element elem)
Defers the execution of runWebkitOverflowAutoFix(Element) |
|
static void |
scrollIntoViewVertically(Element elem)
Scrolls an element into view vertically only. |
|
static void |
setFloat(Element element,
java.lang.String value)
|
|
static int |
setHeightExcludingPaddingAndBorder(Element element,
int requestedHeight,
int verticalPaddingBorderGuess,
boolean requestedHeightIncludesPaddingBorder)
|
|
static int |
setHeightExcludingPaddingAndBorder(Widget widget,
java.lang.String height,
int paddingBorderGuess)
|
|
static void |
setSelectionRange(Element elem,
int pos,
int length,
java.lang.String direction)
Sets the selection range of an input element. |
|
static void |
setStyleTemporarily(Element element,
java.lang.String styleProperty,
java.lang.String tempValue)
Temporarily sets the styleProperty to tempValue and then
resets it to its current value. |
|
static void |
setTextSelectionEnabled(Element e,
boolean enable)
JavaScript hack to prevent text selection in various browsers. |
|
static int |
setWidthExcludingPaddingAndBorder(Element element,
int requestedWidth,
int horizontalPaddingBorderGuess,
boolean requestedWidthIncludesPaddingBorder)
|
|
static int |
setWidthExcludingPaddingAndBorder(Widget widget,
java.lang.String width,
int paddingBorderGuess)
|
|
static void |
simulateClickFromTouchEvent(Event touchevent,
Widget widget)
|
|
static void |
sinkOnloadForImages(Element element)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final double PIXEL_EPSILON
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.
| Constructor Detail |
|---|
public WidgetUtil()
| Method Detail |
|---|
public static void browserDebugger()
public static void redirect(java.lang.String url)
url - The url to redirect to or null to refreshpublic static int getKeyCode(event)
event -
public static Element getElementFromPoint(int clientX,
int clientY)
x - y -
public static float parseRelativeSize(java.lang.String size)
public static java.lang.String escapeHTML(java.lang.String html)
html -
public static java.lang.String escapeAttribute(java.lang.String attribute)
attribute - The string to escape
public static Element cloneNode(Element element,
boolean deep)
element - deep - clone child tree also
public static int measureHorizontalPaddingAndBorder(Element element,
int paddingGuess)
public static int measureVerticalPaddingAndBorder(Element element,
int paddingGuess)
public static int measureHorizontalBorder(Element element)
public static int measureVerticalBorder(Element element)
public static int measureMarginLeft(Element element)
public static int setHeightExcludingPaddingAndBorder(Widget widget,
java.lang.String height,
int paddingBorderGuess)
public static int setWidthExcludingPaddingAndBorder(Widget widget,
java.lang.String width,
int paddingBorderGuess)
public static int setWidthExcludingPaddingAndBorder(Element element,
int requestedWidth,
int horizontalPaddingBorderGuess,
boolean requestedWidthIncludesPaddingBorder)
public static int setHeightExcludingPaddingAndBorder(Element element,
int requestedHeight,
int verticalPaddingBorderGuess,
boolean requestedHeightIncludesPaddingBorder)
public static void setFloat(Element element,
java.lang.String value)
public static int getNativeScrollbarSize()
public static void runWebkitOverflowAutoFixDeferred(Element elem)
runWebkitOverflowAutoFix(Element)
elem - with overflow autopublic static void runWebkitOverflowAutoFix(Element elem)
elem - with overflow autopublic static void alert(java.lang.String string)
public static int getRequiredWidth(com.google.gwt.dom.client.Element element)
element - The element to check
public static double getRequiredWidthDouble(com.google.gwt.dom.client.Element element)
element - The element to check
public static int getRequiredHeight(com.google.gwt.dom.client.Element element)
element - The element to check
public static double getRequiredHeightDouble(com.google.gwt.dom.client.Element element)
element - The element to check
public static int getRequiredWidthBoundingClientRect(com.google.gwt.dom.client.Element element)
In case the browser doesn't support bounding rectangles, the returned value is the offset width.
element - the element of which to calculate the width
public static double getRequiredWidthBoundingClientRectDouble(com.google.gwt.dom.client.Element element)
In case the browser doesn't support bounding rectangles, the returned value is the offset width.
element - the element of which to calculate the width
public static int getRequiredHeightComputedStyle(com.google.gwt.dom.client.Element element)
public static double getRequiredHeightComputedStyleDouble(com.google.gwt.dom.client.Element element)
public static int getRequiredWidthComputedStyle(com.google.gwt.dom.client.Element element)
public static int getRequiredWidthComputedStyleDouble(com.google.gwt.dom.client.Element element)
public static int getRequiredHeightBoundingClientRect(com.google.gwt.dom.client.Element element)
In case the browser doesn't support bounding rectangles, the returned value is the offset height.
element - the element of which to calculate the height
public static double getRequiredHeightBoundingClientRectDouble(com.google.gwt.dom.client.Element element)
In case the browser doesn't support bounding rectangles, the returned value is the offset height.
element - the element of which to calculate the height
public static int getRequiredWidth(Widget widget)
public static int getRequiredHeight(Widget widget)
public static boolean mayHaveScrollBars(com.google.gwt.dom.client.Element pe)
pe - the element to detect
public static void focus(Element el)
el - the element to focus
public static <T> T findWidget(Element element,
java.lang.Class<? extends Widget> class1)
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).
element - the element where to start seeking of Widgetclass1 - the Widget type to seek forpublic static void forceWebkitRedraw(Element element)
element - The element that should be redrawnpublic static final void forceIE8Redraw(Element e)
e - The element to perform the hack onpublic static void forceIERedraw(Element e)
e - The element to perform the hack onpublic static void detachAttach(Element element)
element - The element to detach and re-attachpublic static void sinkOnloadForImages(Element element)
public static int getChildElementIndex(Element childElement)
subElement -
public static void setStyleTemporarily(Element element,
java.lang.String styleProperty,
java.lang.String tempValue)
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)
element - The target elementstyleProperty - The name of the property to settempValue - The temporary valuepublic static int getTouchOrMouseClientX(Event event)
event -
public static Element getElementUnderMouse(NativeEvent event)
event - the mouse event to get coordinates from
public static int getTouchOrMouseClientY(Event event)
event -
public static int getTouchOrMouseClientY(NativeEvent currentGwtEvent)
currentGwtEvent -
getTouchOrMouseClientY(Event)public static int getTouchOrMouseClientX(NativeEvent event)
event -
getTouchOrMouseClientX(Event)public static boolean isTouchEvent(Event event)
public static boolean isTouchEvent(NativeEvent event)
public static void simulateClickFromTouchEvent(Event touchevent,
Widget widget)
public static Element getFocusedElement()
public static boolean isFocusedElementEditable()
public static boolean isAttachedAndDisplayed(Widget widget)
widget -
public static void scrollIntoViewVertically(Element elem)
elem - The element to scroll into viewpublic static boolean isTouchEventOrLeftMouseButton(Event event)
event -
public static java.lang.String getAbsoluteUrl(java.lang.String url)
url - a string with the relative URL to resolve
public static void setSelectionRange(Element elem,
int pos,
int length,
java.lang.String direction)
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.
public static void setTextSelectionEnabled(Element e,
boolean enable)
e - element for enabling or disabling text selectionenable - true if selection is enabled; false
if notpublic static void clearTextSelection()
public static boolean pixelValuesEqual(double num1,
double num2)
PIXEL_EPSILON (i.e. 0.49)
num1 - the first value for which to compare equalitynum2 - the second value for which to compare equality
public static WidgetUtil.TextRectangle getBoundingClientRect(Element e)
public static double getBorderTopThickness(Element element)
The value is determined using computed style when available and calculated otherwise.
element - the element to measure
public static double getBorderBottomThickness(Element element)
The value is determined using computed style when available and calculated otherwise.
element - the element to measure
public static double getBorderTopAndBottomThickness(Element element)
The value is determined using computed style when available and calculated otherwise.
element - the element to measure
public static double getBorderLeftThickness(Element element)
The value is determined using computed style when available and calculated otherwise.
element - the element to measure
public static double getBorderRightThickness(Element element)
The value is determined using computed style when available and calculated otherwise.
element - the element to measure
public static double getBorderLeftAndRightThickness(Element element)
The value is determined using computed style when available and calculated otherwise.
element - the element to measure
public static double roundSizeUp(double size)
size - the value to round
public static double roundSizeDown(double size)
size - the value to round
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||