org.xwiki.gwt.dom.client
Class Element

java.lang.Object
  extended by com.google.gwt.core.client.JavaScriptObject
      extended by com.google.gwt.dom.client.Node
          extended by com.google.gwt.dom.client.Element
              extended by org.xwiki.gwt.dom.client.Element

public class Element
extends com.google.gwt.dom.client.Element

Extends the element implementation provided by GWT to add useful methods. All of them should be removed as soon as they make their way into GWT's API.

Version:
$Id: 9fd22b72c19826d0e7be0e0e0f6f151b7d332261 $

Field Summary
static String INNER_HTML_PLACEHOLDER
          The text used in an element's meta data as a place holder for that element's outer HTML.
static String META_DATA_ATTR
          The name of the DOM attribute storing the HTML of the meta data.
static String META_DATA_REF
          The name of the JavaScript property storing the reference to the meta data.
NOTE: We can't use the same name as for META_DATA_ATTR because IE stores attribute values as JavaScript properties of DOM element objects.
 
Fields inherited from class com.google.gwt.dom.client.Element
DRAGGABLE_AUTO, DRAGGABLE_FALSE, DRAGGABLE_TRUE
 
Fields inherited from class com.google.gwt.dom.client.Node
DOCUMENT_NODE, ELEMENT_NODE, TEXT_NODE
 
Constructor Summary
protected Element()
          Default constructor.
 
Method Summary
static Element as(com.google.gwt.dom.client.Node node)
          Casts a Node to an instance of this type.
 boolean canHaveChildren()
           
 void ensureEditable()
          Ensures this element can be edited in design mode.
 Element expandInnerMetaData()
          Expands inner elements with meta data.
 com.google.gwt.dom.client.Node expandMetaData(boolean deep)
          Expands the meta data of this element and its descendants.
 DocumentFragment extractContents()
          Places all the children of this element in a document fragment and returns it.
NOTE: The element will remain empty after this method call.
 com.google.gwt.core.client.JsArrayString getAttributeNames()
           
 Attribute getAttributeNode(String attributeName)
           
 String getComputedStyleProperty(String propertyName)
          Returns the value of the specified CSS property for this element as it is computed by the browser before the element is displayed.
 DocumentFragment getMetaData()
           
 boolean hasAttributes()
           
 boolean hasClassName(String className)
           
 void removeProperty(String propertyName)
          Removes a property from this element.
 void setMetaData(DocumentFragment metaData)
          Sets the meta data of this element.
 void unwrap()
          Replaces this element with its child nodes.
 void wrap(com.google.gwt.dom.client.Node node)
          Wraps the passed node and takes its place in its parent.
 String xGetAttribute(String name)
          Get the value for the specified attribute in cross browser manner.
 String xGetInnerHTML()
           
 String xGetInnerText()
          We need this method because Element.getInnerText() includes commented text in the output.
 String xGetString()
           
 boolean xHasAttribute(String attributeName)
          Checks if this element has the specified attribute.
 void xRemoveAttribute(String attributeName)
          Removes an attribute by name.
 void xSetAttribute(String name, String value)
          Sets the value for the specified attribute in a cross browser manner.
 void xSetInnerHTML(String html)
          Set inner HTML in cross browser manner and notify the owner document.
 
Methods inherited from class com.google.gwt.dom.client.Element
addClassName, as, blur, dispatchEvent, focus, getAbsoluteBottom, getAbsoluteLeft, getAbsoluteRight, getAbsoluteTop, getAttribute, getClassName, getClientHeight, getClientWidth, getDir, getDraggable, getElementsByTagName, getFirstChildElement, getId, getInnerHTML, getInnerText, getLang, getNextSiblingElement, getOffsetHeight, getOffsetLeft, getOffsetParent, getOffsetTop, getOffsetWidth, getPreviousSiblingElement, getPropertyBoolean, getPropertyDouble, getPropertyInt, getPropertyJSO, getPropertyObject, getPropertyString, getScrollHeight, getScrollLeft, getScrollTop, getScrollWidth, getString, getStyle, getTabIndex, getTagName, getTitle, hasAttribute, hasTagName, is, is, removeAttribute, removeClassName, replaceClassName, scrollIntoView, setAttribute, setClassName, setDir, setDraggable, setId, setInnerHTML, setInnerSafeHtml, setInnerText, setLang, setPropertyBoolean, setPropertyDouble, setPropertyInt, setPropertyJSO, setPropertyObject, setPropertyString, setScrollLeft, setScrollTop, setTabIndex, setTitle
 
Methods inherited from class com.google.gwt.dom.client.Node
appendChild, cloneNode, getChild, getChildCount, getChildNodes, getFirstChild, getLastChild, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentElement, getParentNode, getPreviousSibling, hasChildNodes, hasParentElement, insertAfter, insertBefore, insertFirst, isOrHasChild, removeChild, removeFromParent, replaceChild, setNodeValue
 
Methods inherited from class com.google.gwt.core.client.JavaScriptObject
cast, createArray, createFunction, createObject, equals, hashCode, toSource, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

INNER_HTML_PLACEHOLDER

public static final String INNER_HTML_PLACEHOLDER
The text used in an element's meta data as a place holder for that element's outer HTML.

See Also:
Constant Field Values

META_DATA_REF

public static final String META_DATA_REF
The name of the JavaScript property storing the reference to the meta data.
NOTE: We can't use the same name as for META_DATA_ATTR because IE stores attribute values as JavaScript properties of DOM element objects.

See Also:
Constant Field Values

META_DATA_ATTR

public static final String META_DATA_ATTR
The name of the DOM attribute storing the HTML of the meta data. This HTML is used to recreate the meta data when an element is cloned or copy&pasted.

See Also:
Constant Field Values
Constructor Detail

Element

protected Element()
Default constructor. Needs to be protected because all instances are created from JavaScript.

Method Detail

as

public static Element as(com.google.gwt.dom.client.Node node)
Casts a Node to an instance of this type.

Parameters:
node - the instance to be casted to this type.
Returns:
the given object as an instance of Element.

getAttributeNames

public final com.google.gwt.core.client.JsArrayString getAttributeNames()
Returns:
The names of DOM attributes present on this element.
See Also:
http://code.google.com/p/google-web-toolkit/issues/detail?id=3054

getComputedStyleProperty

public final String getComputedStyleProperty(String propertyName)
Returns the value of the specified CSS property for this element as it is computed by the browser before the element is displayed. The CSS property doesn't have to be applied explicitly or directly on this element. It can be inherited or assumed by default on this element.
NOTE: You have to pass the JavaScript name of the property and not its CSS name. The JavaScript name has camel case style (fontWeight) and it is used like this object.style.propertyJSName = value. The CSS name has dash style (font-weight) and it is used like this propertyCSSName: value;.

Parameters:
propertyName - the script name of the CSS property whose value is returned.
Returns:
the computed value of the specified CSS property for this element.

xSetInnerHTML

public final void xSetInnerHTML(String html)
Set inner HTML in cross browser manner and notify the owner document.

Parameters:
html - the html to set.
See Also:
DOMUtils#setInnerHTML(Element, String)}, http://code.google.com/p/google-web-toolkit/issues/detail?id=3146

xGetInnerHTML

public final String xGetInnerHTML()
Returns:
the extended inner HTML of this element, which includes meta data.
See Also:
Element.getInnerHTML()

xGetString

public final String xGetString()
Returns:
the extended outer HTML of this element, which includes meta data.
See Also:
Element.getString()

expandInnerMetaData

public final Element expandInnerMetaData()
Expands inner elements with meta data.

Returns:
this element

expandMetaData

public final com.google.gwt.dom.client.Node expandMetaData(boolean deep)
Expands the meta data of this element and its descendants.

Parameters:
deep - true to expand the inner elements with meta data, false otherwise
Returns:
this element if it isn't replaced by its meta data, otherwise the document fragment resulted from expanding the meta data

extractContents

public final DocumentFragment extractContents()
Places all the children of this element in a document fragment and returns it.
NOTE: The element will remain empty after this method call.

Returns:
A document fragment containing all the descendants of this element.

unwrap

public final void unwrap()
Replaces this element with its child nodes. In other words, all the child nodes of this element are moved to its parent node and the element is removed from its parent.


wrap

public final void wrap(com.google.gwt.dom.client.Node node)
Wraps the passed node and takes its place in its parent. In other words, it adds the passed element as a child of this element and replaces it in its parent.

Parameters:
node - the node to wrap

getMetaData

public final DocumentFragment getMetaData()
Returns:
the meta data associated with this element.

setMetaData

public final void setMetaData(DocumentFragment metaData)
Sets the meta data of this element.

Parameters:
metaData - a document fragment with additional information regarding this element.

canHaveChildren

public final boolean canHaveChildren()
Returns:
true if HTML Strict DTD specifies that this element can have children, false otherwise

xGetAttribute

public final String xGetAttribute(String name)
Get the value for the specified attribute in cross browser manner.

Parameters:
name - the name of the attribute
Returns:
the value of the attribute
See Also:
DOMUtils.getAttribute(Element, String)

xSetAttribute

public final void xSetAttribute(String name,
                                String value)
Sets the value for the specified attribute in a cross browser manner.

Parameters:
name - the name of the attribute
value - the value of the attribute

xGetInnerText

public final String xGetInnerText()
We need this method because Element.getInnerText() includes commented text in the output.

Returns:
the text between the start and end tags of this element
See Also:
Element.getInnerText(), http://code.google.com/p/google-web-toolkit/issues/detail?id=3275

hasAttributes

public final boolean hasAttributes()
Returns:
true if this element has any attribute, false otherwise

hasClassName

public final boolean hasClassName(String className)
Parameters:
className - a String representing the CSS class to look for
Returns:
true if this element's class attribute contains the given class name, false otherwise

ensureEditable

public final void ensureEditable()
Ensures this element can be edited in design mode. This method is required because in some browsers you can't place the caret inside elements that don't have any visible content and thus you cannot edit them.


removeProperty

public final void removeProperty(String propertyName)
Removes a property from this element.

NOTE: Dynamic properties (expandos) can't be removed from a DOM node in IE 6 and 7. Setting their value to null or undefined makes them appear in the HTML serialization as attributes. Removing the corresponding attribute fails in IE7 if the property value is shared between multiple elements, which can happen if elements are cloned. The only solution we've found is to set the property to an empty JavaScript object in IE. You should test if the value returned by Element.getPropertyObject(String) or Element.getPropertyJSO(String) is not null and also if it matches your expected type.

Parameters:
propertyName - the name of the property to be removed
See Also:
Element.setPropertyBoolean(String, boolean), Element.setPropertyDouble(String, double), Element.setPropertyInt(String, int), Element.setPropertyString(String, String)

xHasAttribute

public final boolean xHasAttribute(String attributeName)
Checks if this element has the specified attribute.

NOTE: We added this method in order to fix an IE7 bug in Element.removeAttribute(String). It seems that Node.cloneNode(boolean) doesn't clone the attributes in IE7 but only copies their references to the clone. As a consequence an attribute can be shared by multiple elements. When we Element.removeAttribute(String) the specified flag is set to false and thus Element.hasAttribute(String), which uses this flag in its IE7 implementation, mistakenly reports the attribute as missing from the rest of the elements that share it.

Parameters:
attributeName - the name of an attribute
Returns:
true if this element has the specified attribute, false otherwise
See Also:
Element.hasAttribute(String), http://code.google.com/p/google-web-toolkit/issues/detail?id=4690

getAttributeNode

public final Attribute getAttributeNode(String attributeName)
Parameters:
attributeName - the name of an attribute
Returns:
the DOM node associated with the specified attribute

xRemoveAttribute

public final void xRemoveAttribute(String attributeName)
Removes an attribute by name.

We added this method to fix a bug in IE7 which allows shared attribute nodes. Removing a shared attribute affects all the element that share it and also can crash the browser if the attribute is remove twice.

Parameters:
attributeName - the name of the attribute to remove
See Also:
xHasAttribute(String)


Copyright © 2004–2014 XWiki. All rights reserved.