org.xwiki.gwt.dom.client
Class Document

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.Document
              extended by org.xwiki.gwt.dom.client.Document

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

Extends the document implementation provided by GWT to add support for selection and range.

Version:
$Id: Document.java 24068 2009-09-26 18:52:09Z mflorea $
See Also:
http://code.google.com/p/google-web-toolkit/issues/detail?id=3006, http://code.google.com/p/google-web-toolkit/issues/detail?id=3053

Field Summary
 
Fields inherited from class com.google.gwt.dom.client.Node
DOCUMENT_NODE, ELEMENT_NODE, TEXT_NODE
 
Constructor Summary
protected Document()
          Default constructor.
 
Method Summary
 void addInnerHTMLListener(InnerHTMLListener listener)
          Registers a new listener for changes to innerHTML property of element within this document.
 void close()
          Closes a document stream for writing.
 com.google.gwt.dom.client.Node createComment(java.lang.String data)
           
 DocumentFragment createDocumentFragment()
          Creates an empty document fragment.
A DocumentFragment is a minimal document object that has no parent.
 Range createRange()
          We've added this method because at the time of writing Document doesn't offer support for creating a range.
 boolean execCommand(java.lang.String command, java.lang.String parameter)
          When an HTML document has been switched to designMode, the document object exposes the execCommand method which allows one to run commands to manipulate the contents of the editable region.
 void fireInnerHTMLChange(Element element)
          Notify all listeners of the change to the given element's innerHTML property.
 java.util.Iterator<com.google.gwt.dom.client.Node> getIterator(com.google.gwt.dom.client.Node startNode)
          Returns an iterator for the depth-first pre-order strategy, starting in startNode.
 Selection getSelection()
          We've added this method because at the time of writing Document doesn't offer support for retrieving the current selection.
 boolean isDesignMode()
           
 void open()
          Opens a document stream for writing.
 boolean queryCommandEnabled(java.lang.String command)
           
 boolean queryCommandState(java.lang.String command)
           
 boolean queryCommandSupported(java.lang.String command)
           
 java.lang.String queryCommandValue(java.lang.String command)
           
 void removeInnerHTMLListener(InnerHTMLListener listener)
          Stop sending notifications to the given listener when the innerHTML property, of some element included in this document, changes.
 void setDesignMode(boolean designMode)
          Puts this document in design mode or in view-only mode.
 void write(java.lang.String html)
          Writes a string of text to a document stream opened by open().
 com.google.gwt.dom.client.Node xImportNode(com.google.gwt.dom.client.Node externalNode, boolean deep)
          Creates a copy of a node from an external document that can be inserted into this document.
We've added this method because at time of writing Document.importNode(Node, boolean) is not well implemented.
 
Methods inherited from class com.google.gwt.dom.client.Document
createAnchorElement, createAreaElement, createBaseElement, createBlockQuoteElement, createBlurEvent, createBRElement, createButtonElement, createCaptionElement, createChangeEvent, createCheckInputElement, createClickEvent, createColElement, createColGroupElement, createContextMenuEvent, createDblClickEvent, createDelElement, createDivElement, createDLElement, createElement, createErrorEvent, createFieldSetElement, createFileInputElement, createFocusEvent, createFormElement, createFrameElement, createFrameSetElement, createHeadElement, createHElement, createHiddenInputElement, createHRElement, createHtmlEvent, createIFrameElement, createImageElement, createImageInputElement, createInsElement, createKeyDownEvent, createKeyEvent, createKeyPressEvent, createKeyUpEvent, createLabelElement, createLegendElement, createLIElement, createLinkElement, createLoadEvent, createMapElement, createMetaElement, createMouseDownEvent, createMouseEvent, createMouseMoveEvent, createMouseOutEvent, createMouseOverEvent, createMouseUpEvent, createObjectElement, createOLElement, createOptGroupElement, createOptionElement, createParamElement, createPasswordInputElement, createPElement, createPreElement, createQElement, createRadioInputElement, createScriptElement, createScriptElement, createScrollEvent, createSelectElement, createSelectElement, createSpanElement, createStyleElement, createSubmitInputElement, createTableElement, createTBodyElement, createTDElement, createTextAreaElement, createTextInputElement, createTextNode, createTFootElement, createTHeadElement, createTHElement, createTitleElement, createTRElement, createULElement, createUniqueId, enableScrolling, get, getBody, getBodyOffsetLeft, getBodyOffsetTop, getClientHeight, getClientWidth, getCompatMode, getDocumentElement, getDomain, getElementById, getElementsByTagName, getReferrer, getScrollHeight, getScrollLeft, getScrollTop, getScrollWidth, getTitle, getURL, importNode, isCSS1Compat, setScrollLeft, setScrollTop, setTitle
 
Methods inherited from class com.google.gwt.dom.client.Node
appendChild, as, cloneNode, getChildNodes, getFirstChild, getLastChild, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPreviousSibling, hasChildNodes, insertBefore, is, 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
 

Constructor Detail

Document

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

Method Detail

createComment

public final com.google.gwt.dom.client.Node createComment(java.lang.String data)
Parameters:
data - contains the data to be added to the comment.
Returns:
the created comment node.

createDocumentFragment

public final DocumentFragment createDocumentFragment()
Creates an empty document fragment.
A DocumentFragment is a minimal document object that has no parent. It supports the following DOM 2 methods: appendChild, cloneNode, hasAttributes, hasChildNodes, insertBefore, normalize, removeChild, replaceChild.
It also supports the following DOM 2 properties: attributes, childNodes, firstChild, lastChild, localName, namespaceURI, nextSibling, nodeName, nodeType, nodeValue, ownerDocument, parentNode, prefix, previousSibling, textContent.
Various other methods can take a document fragment as an argument (e.g. Node interface methods such as appendChild and insertBefore), in which case the children of the fragment are appended or inserted, not the fragment itself.

Returns:
The newly created document fragment.

getSelection

public final Selection getSelection()
We've added this method because at the time of writing Document doesn't offer support for retrieving the current selection.

Returns:
The selection object associated with this document.
See Also:
http://code.google.com/p/google-web-toolkit/issues/detail?id=3053

createRange

public final Range createRange()
We've added this method because at the time of writing Document doesn't offer support for creating a range.

Returns:
A new range for this document.
See Also:
http://code.google.com/p/google-web-toolkit/issues/detail?id=3053

xImportNode

public final com.google.gwt.dom.client.Node xImportNode(com.google.gwt.dom.client.Node externalNode,
                                                        boolean deep)
Creates a copy of a node from an external document that can be inserted into this document.
We've added this method because at time of writing Document.importNode(Node, boolean) is not well implemented.

Parameters:
externalNode - The node from another document to be imported.
deep - Indicates whether the children of the given node need to be imported.
Returns:
a copy of the given node that can be inserted into this document.
See Also:
http://code.google.com/p/google-web-toolkit/issues/detail?id=3006

getIterator

public final java.util.Iterator<com.google.gwt.dom.client.Node> getIterator(com.google.gwt.dom.client.Node startNode)
Returns an iterator for the depth-first pre-order strategy, starting in startNode.

Parameters:
startNode - node to start iteration from
Returns:
the depth-first pre-order iterator
See Also:
DepthFirstPreOrderIterator}, http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html#Traversal-Document

execCommand

public final boolean execCommand(java.lang.String command,
                                 java.lang.String parameter)
When an HTML document has been switched to designMode, the document object exposes the execCommand method which allows one to run commands to manipulate the contents of the editable region. Most commands affect the document's selection (bold, italics, etc), while others insert new elements (adding a link) or affect an entire line (indenting). When using contentEditable, calling execCommand will affect the currently active editable element.

Parameters:
command - The name of the command.
parameter - Some commands (such as insertimage) require an extra value argument (the image's url). Pass an argument of null if no argument is needed.
Returns:
true if the specified command has been successfully executed.

queryCommandValue

public final java.lang.String queryCommandValue(java.lang.String command)
Parameters:
command - The name of the command to query.
Returns:
The current value of the current range for the given command. If a command value has not been explicitly set then it returns null.

queryCommandEnabled

public final boolean queryCommandEnabled(java.lang.String command)
Parameters:
command - The name of the command to query.
Returns:
true if the given command can be executed on the current range.

queryCommandState

public final boolean queryCommandState(java.lang.String command)
Parameters:
command - The name of the command to query.
Returns:
true if the given command has been executed on the current range.

queryCommandSupported

public final boolean queryCommandSupported(java.lang.String command)
Parameters:
command - The name of the command to query.
Returns:
true if the given command is supported by the current browser.

open

public final void open()
Opens a document stream for writing.


close

public final void close()
Closes a document stream for writing.


write

public final void write(java.lang.String html)
Writes a string of text to a document stream opened by open().

Parameters:
html - a string containing the HTML to be written to the document.

addInnerHTMLListener

public final void addInnerHTMLListener(InnerHTMLListener listener)
Registers a new listener for changes to innerHTML property of element within this document.

Parameters:
listener - The listener to be registered.

removeInnerHTMLListener

public final void removeInnerHTMLListener(InnerHTMLListener listener)
Stop sending notifications to the given listener when the innerHTML property, of some element included in this document, changes.

Parameters:
listener - The listener to be unregistered.

fireInnerHTMLChange

public final void fireInnerHTMLChange(Element element)
Notify all listeners of the change to the given element's innerHTML property.

NOTE: Normally, only Element.xSetInnerHTML(String) should call this method.

Parameters:
element - The element whose innerHTML property has changed.
See Also:
Element.xSetInnerHTML(String)

setDesignMode

public final void setDesignMode(boolean designMode)
Puts this document in design mode or in view-only mode.

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.

Parameters:
designMode - true to enter design mode, false to go back to view-only mode

isDesignMode

public final boolean isDesignMode()
Returns:
true if this document is in design mode, false otherwise
See Also:
setDesignMode(boolean)


Copyright © 2004-2009 XWiki. All Rights Reserved.