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: Element.java 24068 2009-09-26 18:52:09Z mflorea $

Field Summary
static java.lang.String CLASS_NAME_SEPARATOR
          The class attribute is a space-separated list of CSS class names.
static java.lang.String INNER_HTML_PLACEHOLDER
          The text used in an element's meta data as a place holder for that element's outer HTML.
static java.lang.String META_DATA_ATTR
          The name of the DOM attribute storing the HTML of the meta data.
static java.lang.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.Node
DOCUMENT_NODE, ELEMENT_NODE, TEXT_NODE
 
Constructor Summary
protected Element()
          Default constructor.
 
Method Summary
 void addClassName(java.lang.String className)
          Adds a new CSS class name to this element's class attribute.
static Element as(com.google.gwt.dom.client.Node node)
          Casts a Node to an instance of this type.
 void ensureEditable()
          Ensures this element can be edited in design mode.
 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()
           
 java.lang.String getComputedStyleProperty(java.lang.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 hasAttribute(java.lang.String attrName)
           
 boolean hasAttributes()
           
 boolean hasClassName(java.lang.String className)
           
 boolean mustBeEmpty()
           
 void removeClassName(java.lang.String className)
          Removes a CSS class name form this element's class attribute.
 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.
 java.lang.String xGetAttribute(java.lang.String name)
          Get the value for the specified attribute in cross browser manner.
 java.lang.String xGetInnerHTML()
           
 java.lang.String xGetInnerText()
          We need this method because Element.getInnerText() includes commented text in the output.
 java.lang.String xGetString()
           
 void xSetAttribute(java.lang.String name, java.lang.String value)
          Sets the value for the specified attribute in a cross browser manner.
 void xSetInnerHTML(java.lang.String html)
          Set inner HTML in cross browser manner and notify the owner document.
 
Methods inherited from class com.google.gwt.dom.client.Element
as, dispatchEvent, getAbsoluteLeft, getAbsoluteTop, getAttribute, getClassName, getClientHeight, getClientWidth, getDir, getElementsByTagName, getFirstChildElement, getId, getInnerHTML, getInnerText, getLang, getNextSiblingElement, getOffsetHeight, getOffsetLeft, getOffsetParent, getOffsetTop, getOffsetWidth, getParentElement, getPropertyBoolean, getPropertyDouble, getPropertyInt, getPropertyString, getScrollHeight, getScrollLeft, getScrollTop, getScrollWidth, getString, getStyle, getTagName, getTitle, is, is, isOrHasChild, removeAttribute, scrollIntoView, setAttribute, setClassName, setDir, setId, setInnerHTML, setInnerText, setLang, setPropertyBoolean, setPropertyDouble, setPropertyInt, setPropertyString, setScrollLeft, setScrollTop, setTitle
 
Methods inherited from class com.google.gwt.dom.client.Node
appendChild, cloneNode, getChildNodes, getFirstChild, getLastChild, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPreviousSibling, hasChildNodes, insertBefore, removeChild, replaceChild, setNodeValue
 
Methods inherited from class com.google.gwt.core.client.JavaScriptObject
cast, createArray, createFunction, createObject, equals, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

INNER_HTML_PLACEHOLDER

public static final java.lang.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 java.lang.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 java.lang.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

CLASS_NAME_SEPARATOR

public static final java.lang.String CLASS_NAME_SEPARATOR
The class attribute is a space-separated list of CSS class names.

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 java.lang.String getComputedStyleProperty(java.lang.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(java.lang.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 java.lang.String xGetInnerHTML()
Returns:
the extended inner HTML of this element, which includes meta data.
See Also:
Element.getInnerHTML()

xGetString

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

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.

mustBeEmpty

public final boolean mustBeEmpty()
Returns:
true if HTML Strict DTD specifies that this element must be empty.

xGetAttribute

public final java.lang.String xGetAttribute(java.lang.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(java.lang.String name,
                                java.lang.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 java.lang.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

hasAttribute

public final boolean hasAttribute(java.lang.String attrName)
Parameters:
attrName - a string representing the name of an attribute
Returns:
true is this element has an attribute with the specified name, false otherwise
See Also:
http://code.google.com/p/google-web-toolkit/issues/detail?id=2852

hasAttributes

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

hasClassName

public final boolean hasClassName(java.lang.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

addClassName

public final void addClassName(java.lang.String className)
Adds a new CSS class name to this element's class attribute. The class attribute is a space-separated list of CSS class names.

Parameters:
className - a String representing the CSS class to be appended to this element's class attribute
See Also:
Element.setClassName(String)

removeClassName

public final void removeClassName(java.lang.String className)
Removes a CSS class name form this element's class attribute. The class attribute is a space-separated list of CSS class names.

Parameters:
className - a String representing the CSS class to be removed from this element's class attribute
See Also:
Element.setClassName(String)

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.



Copyright © 2004-2009 XWiki. All Rights Reserved.