|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.xwiki.gwt.dom.client.DOMUtils
public abstract class DOMUtils
Utility class providing methods for manipulating the DOM tree. Add here only the methods that work with any kind of
DOM node and the methods that have different implementation for different browsers. For specific node types see
Document, Element or Text.
| Field Summary | |
|---|---|
static java.lang.String |
BR
The <br/> tag name. |
static short |
CDATA_NODE
Constant for the CDATA node type. |
static short |
COMMENT_NODE
Constant for the comment node type. |
static short |
DOCUMENT_FRAGMENT_NODE
Constant for the DocumentFragment node type. |
static java.lang.String |
HR
The <hr/> tag name. |
protected static java.lang.String[] |
HTML_EMPTY_TAGS
The list of all HTML tags that must be empty. |
static java.lang.String |
ID
The id attribute. |
static java.lang.String |
UNSUPPORTED_NODE_TYPE
Common error message used when a particular node type is not supported by a method. |
| Constructor Summary | |
|---|---|
DOMUtils()
|
|
| Method Summary | |
|---|---|
boolean |
canHaveChildren(com.google.gwt.dom.client.Node node)
|
com.google.gwt.dom.client.Node |
cloneNode(com.google.gwt.dom.client.Node node,
int offset,
boolean left)
Clones the left or right side of the subtree rooted in the given node. |
com.google.gwt.dom.client.Node |
cloneNode(com.google.gwt.dom.client.Node node,
int startOffset,
int endOffset)
Clones the given DOM node, keeping only the contents between start and end offset. |
com.google.gwt.dom.client.Node |
cloneNode(com.google.gwt.dom.client.Node parent,
com.google.gwt.dom.client.Node descendant,
int offset,
boolean left)
Clones the node specified by its parent and its descendant, including only the left or right part of the tree whose separator is the path from the given descendant to the parent of the cloned node. |
DocumentFragment |
cloneNodeContents(com.google.gwt.dom.client.Node node,
int startOffset,
int endOffset)
Clones the contents of the given node. |
short |
comparePoints(com.google.gwt.dom.client.Node alice,
int aliceOffset,
com.google.gwt.dom.client.Node bob,
int bobOffset)
Compares two points in a Document. |
void |
deleteNodeContents(com.google.gwt.dom.client.Node node,
int offset,
boolean left)
Deletes the left or right side of the subtree rooted in the given node. |
void |
deleteNodeContents(com.google.gwt.dom.client.Node node,
int startOffset,
int endOffset)
Deletes the contents of the given node between the specified offsets. |
void |
deleteNodeContents(com.google.gwt.dom.client.Node parent,
com.google.gwt.dom.client.Node descendant,
int offset,
boolean left)
Given a subtree specified by its root parent and one of the inner nodes, this method deletes the left or right part delimited by the path from the given descendant (inner node) to the root parent. |
void |
deleteSiblings(com.google.gwt.dom.client.Node node,
boolean left)
Deletes left or right siblings of the given node. |
void |
detach(com.google.gwt.dom.client.Node node)
Removes the given node from its parent. |
void |
ensureBlockIsEditable(Element block)
Ensures the given block-level element can be edited in design mode. |
com.google.gwt.dom.client.Node |
extractNode(com.google.gwt.dom.client.Node node,
int offset,
boolean left)
Extracts the left or right side of the subtree rooted in the given node. |
com.google.gwt.dom.client.Node |
extractNode(com.google.gwt.dom.client.Node node,
int startOffset,
int endOffset)
Extracts the given DOM node, keeping only the contents between start and end offset. |
com.google.gwt.dom.client.Node |
extractNode(com.google.gwt.dom.client.Node parent,
com.google.gwt.dom.client.Node descendant,
int offset,
boolean left)
Extracts the node specified by its parent and its descendant, including only the left or right part of the tree whose separator is the path from the given descendant to the parent of the extracted node. |
DocumentFragment |
extractNodeContents(com.google.gwt.dom.client.Node node,
int startOffset,
int endOffset)
Extracts the contents of the given node. |
java.util.List<com.google.gwt.dom.client.Node> |
getAncestors(com.google.gwt.dom.client.Node node)
|
java.lang.String |
getAttribute(Element element,
java.lang.String name)
Returns the value of the named attribute of the specified element. |
com.google.gwt.core.client.JsArrayString |
getAttributeNames(Element element)
|
com.google.gwt.dom.client.Node |
getChild(com.google.gwt.dom.client.Node parent,
com.google.gwt.dom.client.Node descendant)
|
abstract java.lang.String |
getComputedStyleProperty(Element el,
java.lang.String propertyName)
Returns the value of the specified CSS property for the given element as it is computed by the browser before it displays that element. |
com.google.gwt.dom.client.Node |
getFarthestInlineAncestor(com.google.gwt.dom.client.Node node)
Walks from the given node up to the root of the DOM tree as long as the ancestors represent in-line content. |
com.google.gwt.dom.client.Node |
getFirstAncestor(com.google.gwt.dom.client.Node node,
java.lang.String... tagNames)
Searches for the first ancestor with a name from tagNames of the passed node, including the node itself. |
com.google.gwt.dom.client.Node |
getFirstDescendant(com.google.gwt.dom.client.Node node,
java.lang.String tagName)
Searches for the first element descendant with the name tagName. |
com.google.gwt.dom.client.Node |
getFirstLeaf(com.google.gwt.dom.client.Node node)
|
com.google.gwt.dom.client.Node |
getFirstLeaf(Range range)
|
java.lang.String |
getInnerText(Element element)
We need our own implementation because the one provided by GWT includes commented text in the output. |
static DOMUtils |
getInstance()
NOTE: We use deferred binding because some of the methods don't have cross-browser implementation and we want to load the implementation specific to the browser used. |
com.google.gwt.dom.client.Node |
getLastLeaf(com.google.gwt.dom.client.Node node)
|
com.google.gwt.dom.client.Node |
getLastLeaf(Range range)
|
int |
getLength(com.google.gwt.dom.client.Node node)
|
com.google.gwt.dom.client.Node |
getNearestBlockContainer(com.google.gwt.dom.client.Node node)
|
com.google.gwt.dom.client.Node |
getNearestCommonAncestor(com.google.gwt.dom.client.Node alice,
com.google.gwt.dom.client.Node bob)
|
com.google.gwt.dom.client.Node |
getNearestFlowContainer(com.google.gwt.dom.client.Node innerNode)
|
com.google.gwt.dom.client.Node |
getNextLeaf(com.google.gwt.dom.client.Node node)
|
com.google.gwt.dom.client.Node |
getNextLeaf(Range range)
|
com.google.gwt.dom.client.Node |
getNextNode(Range range)
|
int |
getNodeIndex(com.google.gwt.dom.client.Node node)
|
int |
getNormalizedChildCount(com.google.gwt.dom.client.Node node)
|
int |
getNormalizedNodeIndex(com.google.gwt.dom.client.Node node)
Computes the index that can be used with getChildNodes().getItem() to retrieve the given node from
its parent after the parent is serialized and deserialized. |
com.google.gwt.dom.client.Node |
getPreviousLeaf(com.google.gwt.dom.client.Node node)
|
com.google.gwt.dom.client.Node |
getPreviousLeaf(Range range)
|
com.google.gwt.dom.client.Node |
getPreviousNode(Range range)
|
Range |
getTextRange(Range range)
Computes the longest text range included in the specified range. |
boolean |
hasAttribute(Element element,
java.lang.String attributeName)
|
boolean |
hasAttributes(Element element)
|
com.google.gwt.dom.client.Node |
importNode(Document doc,
com.google.gwt.dom.client.Node externalNode,
boolean deep)
Creates a copy of a node from an external document that can be inserted into the given document. |
void |
insertAfter(com.google.gwt.dom.client.Node newChild,
com.google.gwt.dom.client.Node refChild)
Inserts the given child node after the reference node. |
void |
insertAt(com.google.gwt.dom.client.Node parent,
com.google.gwt.dom.client.Node newChild,
int index)
Inserts a node at the specified index under the given parent. |
boolean |
isBlock(com.google.gwt.dom.client.Node node)
|
boolean |
isBlockLevelInlineContainer(com.google.gwt.dom.client.Node node)
|
boolean |
isDesignMode(Document document)
|
boolean |
isFlowContainer(com.google.gwt.dom.client.Node node)
|
boolean |
isInline(com.google.gwt.dom.client.Node node)
|
void |
isolate(com.google.gwt.dom.client.Node node)
Isolates a node from its siblings. |
boolean |
isOrContainsLineBreak(com.google.gwt.dom.client.Node node)
|
boolean |
isSerializable(com.google.gwt.dom.client.Node node)
Specifies if a node's HTML serialization is included in its parent node's HTML serialization. |
boolean |
isSpecialBlock(com.google.gwt.dom.client.Node node)
|
void |
removeAttribute(Element element,
java.lang.String attributeName)
Removes an attribute by name. |
void |
removeProperty(Element element,
java.lang.String propertyName)
Removes a property from an element. |
void |
scrollIntoView(Range range)
Makes sure that a given DOM range is visible by scrolling it into view. |
void |
setAttribute(Element element,
java.lang.String name,
java.lang.String value)
Sets the value of the specified attribute for the given element. |
void |
setDesignMode(Document document,
boolean designMode)
Puts the given document in design mode or in view-only mode. |
void |
setInnerHTML(Element element,
java.lang.String html)
Helps setting the inner HTML for an element, in a cross-browser manner, because IE seems to trim leading comments in the inner HTML. |
com.google.gwt.dom.client.Node |
splitHTMLNode(com.google.gwt.dom.client.Node parent,
com.google.gwt.dom.client.Node descendant,
int offset)
Given a subtree specified by its root parent and one of the inner nodes, this method splits the subtree by the path from the given descendant (inner node) to the root parent. |
com.google.gwt.dom.client.Node |
splitNode(com.google.gwt.dom.client.Node node,
int offset)
Splits the given DOM node at the specified offset. |
com.google.gwt.dom.client.Node |
splitNode(com.google.gwt.dom.client.Node parent,
com.google.gwt.dom.client.Node descendant,
int offset)
Given a subtree specified by its root parent and one of the inner nodes, this method splits the subtree by the path from the given descendant (inner node) to the root parent. |
void |
stop(Window window)
Stop the given window from loading its document. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String UNSUPPORTED_NODE_TYPE
public static final java.lang.String BR
<br/> tag name.
public static final java.lang.String HR
<hr/> tag name.
public static final java.lang.String ID
public static final short COMMENT_NODE
public static final short CDATA_NODE
public static final short DOCUMENT_FRAGMENT_NODE
protected static final java.lang.String[] HTML_EMPTY_TAGS
<tagName/> in the HTML
code.
http://code.google.com/p/google-web-toolkit/issues/detail?id=3192| Constructor Detail |
|---|
public DOMUtils()
| Method Detail |
|---|
public static DOMUtils getInstance()
public abstract java.lang.String getComputedStyleProperty(Element el,
java.lang.String propertyName)
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;.
el - the element for which we retrieve the property value.propertyName - the script name of the CSS property whose value is returned.
public com.google.gwt.dom.client.Node getNextLeaf(com.google.gwt.dom.client.Node node)
node - the node from where to begin the search for the next leaf.
public com.google.gwt.dom.client.Node getNextLeaf(Range range)
range - the range after which to look for a leaf
public com.google.gwt.dom.client.Node getPreviousLeaf(Range range)
range - the range before which to look for a leaf
public com.google.gwt.dom.client.Node getPreviousLeaf(com.google.gwt.dom.client.Node node)
node - the node from where to begin the search for the previous leaf.
public com.google.gwt.dom.client.Node getFirstLeaf(com.google.gwt.dom.client.Node node)
node - the root of the DOM subtree whose first leaf is returned.
public com.google.gwt.dom.client.Node getLastLeaf(com.google.gwt.dom.client.Node node)
node - the root of the DOM subtree whose last leaf is returned.
public int getNodeIndex(com.google.gwt.dom.client.Node node)
node - the node whose index is returned.
public int getNormalizedNodeIndex(com.google.gwt.dom.client.Node node)
getChildNodes().getItem() to retrieve the given node from
its parent after the parent is serialized and deserialized.
node - a DOM node
public boolean isSerializable(com.google.gwt.dom.client.Node node)
node - a DOM node
public int getNormalizedChildCount(com.google.gwt.dom.client.Node node)
node - a DOM node.
getNormalizedNodeIndex(Node)public boolean isInline(com.google.gwt.dom.client.Node node)
node - a DOM node
true if the given DOM node represents in-line contentpublic boolean isBlock(com.google.gwt.dom.client.Node node)
node - a DOM node
true if the given node is a block-level element, false otherwisepublic boolean isBlockLevelInlineContainer(com.google.gwt.dom.client.Node node)
node - a DOM node
true if the given node is a block-level element that can have only in-line content, false
otherwiseHTML_BLOCK_LEVEL_INLINE_CONTAINERSpublic boolean isSpecialBlock(com.google.gwt.dom.client.Node node)
node - a DOM node
true if the given node is a block-level element that can have only special content, false
otherwiseHTML_SPECIAL_BLOCK_LEVEL_ELEMENTSpublic Range getTextRange(Range range)
range - any range
public com.google.gwt.dom.client.Node importNode(Document doc,
com.google.gwt.dom.client.Node externalNode,
boolean deep)
doc - The document in which we want to insert the returned copy.externalNode - The node from another document to be imported.deep - Indicates whether the children of the given node need to be imported.
public com.google.gwt.core.client.JsArrayString getAttributeNames(Element element)
element - The DOM element whose attribute names are returned.
public com.google.gwt.dom.client.Node getFirstAncestor(com.google.gwt.dom.client.Node node,
java.lang.String... tagNames)
tagNames of the passed node, including the node itself.
The search order starts with node and continues to the root of the tree.
node - the node to find ancestor fortagNames - the tag names to look for up in the DOM tree.
tagNames found.
public com.google.gwt.dom.client.Node getFirstDescendant(com.google.gwt.dom.client.Node node,
java.lang.String tagName)
tagName. Searching is done in a DFS order
with node processing on first pass through them.
node - the node to start the search fromtagName - the name of the searched element
tagName of the passed node, in DFS order.
public void setInnerHTML(Element element,
java.lang.String html)
element - element to set the inner HTML forhtml - the HTML string to sethttp://code.google.com/p/google-web-toolkit/issues/detail?id=3146
public com.google.gwt.dom.client.Node getNearestCommonAncestor(com.google.gwt.dom.client.Node alice,
com.google.gwt.dom.client.Node bob)
alice - A DOM node.bob - A DOM node.
public java.util.List<com.google.gwt.dom.client.Node> getAncestors(com.google.gwt.dom.client.Node node)
node - a DOM node
public DocumentFragment cloneNodeContents(com.google.gwt.dom.client.Node node,
int startOffset,
int endOffset)
node - The DOM node whose contents will be cloned.startOffset - the index of the first child to clone or the first character to include in the cloned
contents.endOffset - specifies where the cloned contents end.
public com.google.gwt.dom.client.Node cloneNode(com.google.gwt.dom.client.Node node,
int startOffset,
int endOffset)
node - The DOM node to be cloned.startOffset - specifies where to start the cloning.endOffset - specifies where to end the cloning.
public int getLength(com.google.gwt.dom.client.Node node)
node - A DOM node.
public com.google.gwt.dom.client.Node cloneNode(com.google.gwt.dom.client.Node node,
int offset,
boolean left)
node - The root of the subtree whose left or right side will be cloned.offset - Marks the boundary between the left and the right subtrees. It can be either a character index or a
child index, depending on the type of the given node.left - Specifies which of the subtrees to be cloned.
public com.google.gwt.dom.client.Node cloneNode(com.google.gwt.dom.client.Node parent,
com.google.gwt.dom.client.Node descendant,
int offset,
boolean left)
parent - The parent of the cloned node.descendant - A descendant of the cloned node.offset - The offset within the given descendant. It can be either a character index or a child index
depending on the descendant node type.left - Specifies which subtree to be cloned. Left and right subtrees are delimited by the path from the
given descendant to the parent of the cloned node.
public com.google.gwt.dom.client.Node getChild(com.google.gwt.dom.client.Node parent,
com.google.gwt.dom.client.Node descendant)
parent - the parent node of the retrieved childdescendant - a descendant of the retrieved child
public void insertAfter(com.google.gwt.dom.client.Node newChild,
com.google.gwt.dom.client.Node refChild)
newChild - The child node to be inserted.refChild - The reference node.
public void deleteNodeContents(com.google.gwt.dom.client.Node node,
int startOffset,
int endOffset)
node - The DOM node whose contents will be deleted.startOffset - the index of the first child or the first character to delete, depending on node type.endOffset - specifies where to stop deleting content.
public void deleteNodeContents(com.google.gwt.dom.client.Node node,
int offset,
boolean left)
node - The root of the subtree whose left or right side will be deleted.offset - Marks the boundary between the left and the right subtrees. It can be either a character index or a
child index, depending on the type of the given node.left - Specifies which of the subtrees to be deleted.
public void deleteSiblings(com.google.gwt.dom.client.Node node,
boolean left)
node - The DOM node whose left or right siblings will be deleted.left - Specifies which siblings to delete.
public void deleteNodeContents(com.google.gwt.dom.client.Node parent,
com.google.gwt.dom.client.Node descendant,
int offset,
boolean left)
parent - The parent node of the subtree's root.descendant - An inner node within the specified subtree.offset - The offset within the given descendant. It can be either a character index or a child index
depending on the descendant node type.left - Specifies which side of the subtree to be deleted. Left and right parts are delimited by the path
from the given descendant to the parent of the subtree's root.
public com.google.gwt.dom.client.Node splitNode(com.google.gwt.dom.client.Node node,
int offset)
node - The node to be split.offset - Specifies where to split. It can be either a character index or a child index depending on node
type.
public com.google.gwt.dom.client.Node splitNode(com.google.gwt.dom.client.Node parent,
com.google.gwt.dom.client.Node descendant,
int offset)
parent - The parent node of the subtree's root.descendant - An inner node within the specified subtree.offset - The offset within the given descendant. It can be either a character index or a child index
depending on the descendant node type.
public com.google.gwt.dom.client.Node splitHTMLNode(com.google.gwt.dom.client.Node parent,
com.google.gwt.dom.client.Node descendant,
int offset)
splitNode(Node, Node, int)) does this method ensures that both subtrees are editable in design mode.
This method is required because some browsers like Firefox prevent the user from placing the caret inside empty
block elements such as paragraphs or headers. This empty block elements can be obtained by splitting at the
beginning or at the end of such a block element.
parent - the parent node of the subtree's rootdescendant - an inner node within the specified subtreeoffset - the offset within the given descendant. It can be either a character index or a child index
depending on the descendant node type.
splitNode(Node, Node, int)public boolean isFlowContainer(com.google.gwt.dom.client.Node node)
node - A DOM node.
public com.google.gwt.dom.client.Node getNearestFlowContainer(com.google.gwt.dom.client.Node innerNode)
innerNode - A DOM node.
public void insertAt(com.google.gwt.dom.client.Node parent,
com.google.gwt.dom.client.Node newChild,
int index)
parent - The parent node which will adopt the given node.newChild - The node to be inserted.index - Specifies the position inside the parent node where the new child should be placed.public com.google.gwt.dom.client.Node getFarthestInlineAncestor(com.google.gwt.dom.client.Node node)
node - a DOM node
public com.google.gwt.dom.client.Node getFirstLeaf(Range range)
range - A DOM range.
public com.google.gwt.dom.client.Node getLastLeaf(Range range)
range - A DOM range.
public void detach(com.google.gwt.dom.client.Node node)
node - A DOM node.public com.google.gwt.dom.client.Node getNearestBlockContainer(com.google.gwt.dom.client.Node node)
node - A DOM node
public java.lang.String getAttribute(Element element,
java.lang.String name)
style and class. This method should be used only when the attribute name
is not know.
element - the element to get the attribute forname - the name of the attribute to return
public void setAttribute(Element element,
java.lang.String name,
java.lang.String value)
element - the element whose attribute is setname - the name of the attributevalue - the value of the attribute
public short comparePoints(com.google.gwt.dom.client.Node alice,
int aliceOffset,
com.google.gwt.dom.client.Node bob,
int bobOffset)
Document. Each point is specified by a DOM node and an offset within that node.
alice - first point's nodealiceOffset - first point's offsetbob - second point's nodebobOffset - second point's offset
public java.lang.String getInnerText(Element element)
element - the element whose inner text to return
http://code.google.com/p/google-web-toolkit/issues/detail?id=3275public boolean hasAttributes(Element element)
element - a DOM element
true if the given element has any attributes
public DocumentFragment extractNodeContents(com.google.gwt.dom.client.Node node,
int startOffset,
int endOffset)
node - the DOM node whose contents will be extractedstartOffset - the index of the first child to extract or the first character to include in the extracted
contentsendOffset - specifies where the extracted contents end
public com.google.gwt.dom.client.Node extractNode(com.google.gwt.dom.client.Node parent,
com.google.gwt.dom.client.Node descendant,
int offset,
boolean left)
parent - the parent of the extracted nodedescendant - a descendant of the extracted nodeoffset - the offset within the given descendant. It can be either a character index or a child index
depending on the descendant node type.left - specifies which subtree to be extracted. Left and right subtrees are delimited by the path from the
given descendant to the parent of the extracted node.
public com.google.gwt.dom.client.Node extractNode(com.google.gwt.dom.client.Node node,
int offset,
boolean left)
node - the root of the subtree whose left or right side will be extractedoffset - marks the boundary between the left and the right subtrees. It can be either a character index or a
child index, depending on the type of the given node.left - specifies which of the subtrees to be extracted
public com.google.gwt.dom.client.Node extractNode(com.google.gwt.dom.client.Node node,
int startOffset,
int endOffset)
node - the DOM node to be extractedstartOffset - specifies where to start the extractionendOffset - specifies where to end the extraction
public com.google.gwt.dom.client.Node getNextNode(Range range)
range - a DOM range
public com.google.gwt.dom.client.Node getPreviousNode(Range range)
range - a DOM range
public void scrollIntoView(Range range)
range - a DOM rangepublic void ensureBlockIsEditable(Element block)
block - a block-level DOM elementpublic boolean isOrContainsLineBreak(com.google.gwt.dom.client.Node node)
node - the node to check for line breaks
true if the given node or one of its descendants is a BR (line break), false otherwise
public void setDesignMode(Document document,
boolean designMode)
NOTE: The standard implementation of this method sets the value of the designMode DOM document property.
We set the value of the contentEditable property on the document's body instead, if the browser doesn't
fully support the designMode property.
document - a DOM documentdesignMode - true to enter design mode, false to go back to view-only modepublic boolean isDesignMode(Document document)
document - a DOM document
true if the given document is in design mode, false otherwisesetDesignMode(Document, boolean)public void stop(Window window)
window - the window to be stopped
public void removeProperty(Element element,
java.lang.String propertyName)
element - a DOM elementpropertyName - the name of the property to be removedpublic boolean canHaveChildren(com.google.gwt.dom.client.Node node)
node - a HTML DOM node
true if the given node can have children, following the HTML strict DTD, false otherwise
public boolean hasAttribute(Element element,
java.lang.String attributeName)
element - a DOM elementattributeName - the name of an attribute
true if the given element has the specified attribute, false otherwise
public void removeAttribute(Element element,
java.lang.String attributeName)
element - a DOM elementattributeName - the name of the attribute to removepublic void isolate(com.google.gwt.dom.client.Node node)
em from<ins>a<em>b</em>c</ins><ins>a</ins><ins><em>b</em></ins><ins>c</ins>.
node - the node to isolate
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||