public abstract class HtmlElement extends DomElement
Modifier and Type | Class and Description |
---|---|
static class |
HtmlElement.DisplayStyle
Enum for the different display styles.
|
DomElement.ChildElementsIterator
DomNode.ChildIterator, DomNode.DescendantDomElementsIterator, DomNode.DescendantDomNodesIterator, DomNode.DescendantElementsIterator<T extends DomNode>, DomNode.DescendantHtmlElementsIterator
Modifier and Type | Field and Description |
---|---|
protected static String |
ATTRIBUTE_CHECKED
Constant 'checked'.
|
protected static String |
ATTRIBUTE_HIDDEN
Constant 'hidden'.
|
protected static String |
ATTRIBUTE_REQUIRED
Constant 'required'.
|
static Short |
TAB_INDEX_OUT_OF_BOUNDS
Constant indicating that a tab index value is out of bounds (less than
0 or greater
than 32767 ). |
ATTRIBUTE_NOT_DEFINED, ATTRIBUTE_VALUE_EMPTY, ID_ATTRIBUTE, NAME_ATTRIBUTE, SRC_ATTRIBUTE, TYPE_ATTRIBUTE, VALUE_ATTRIBUTE
PROPERTY_ELEMENT, READY_STATE_COMPLETE, READY_STATE_INTERACTIVE, READY_STATE_LOADED, READY_STATE_LOADING, READY_STATE_UNINITIALIZED
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
Modifier | Constructor and Description |
---|---|
protected |
HtmlElement(String qualifiedName,
SgmlPage page,
Map<String,DomAttr> attributes)
Creates an instance.
|
protected |
HtmlElement(String namespaceURI,
String qualifiedName,
SgmlPage page,
Map<String,DomAttr> attributes)
Creates an instance of a DOM element that can have a namespace.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
acceptChar(char c)
Indicates if the provided character can by "typed" in the element.
|
void |
addHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
Adds an HtmlAttributeChangeListener to the listener list.
|
HtmlElement |
appendChildIfNoneExists(String tagName)
Appends a child element to this HTML element with the specified tag name
if this HTML element does not already have a child with that tag name.
|
protected void |
checkChildHierarchy(Node childNode)
Check for insertion errors for a new child node.
|
DomNode |
cloneNode(boolean deep) |
protected void |
detach()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
protected void |
doType(char c,
boolean lastType)
Performs the effective type action, called after the keyPress event and before the keyUp event.
|
protected void |
doType(int keyCode,
boolean lastType)
Performs the effective type action, called after the keyPress event and before the keyUp event.
|
protected void |
fireHtmlAttributeAdded(HtmlAttributeChangeEvent event)
Support for reporting HTML attribute changes.
|
protected void |
fireHtmlAttributeRemoved(HtmlAttributeChangeEvent event)
Support for reporting HTML attribute changes.
|
protected void |
fireHtmlAttributeReplaced(HtmlAttributeChangeEvent event)
Support for reporting HTML attribute changes.
|
String |
getCanonicalXPath()
Returns the canonical XPath expression which identifies this node, for instance
"/html/body/table[3]/tbody/tr[5]/td[2]/span/a[3]" . |
HtmlElement.DisplayStyle |
getDefaultStyleDisplay()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
<E extends HtmlElement> |
getElementsByAttribute(String elementName,
String attributeName,
String attributeValue)
Returns all elements which are descendants of this element and match the specified search criteria.
|
HtmlElement |
getEnclosingElement(String tagName)
Returns the first element with the specified tag name that is an ancestor to this element, or
null if no such element is found. |
HtmlForm |
getEnclosingForm()
Returns the form which contains this element, or
null if this element is not inside
of a form. |
HtmlForm |
getEnclosingFormOrDie()
Returns the form which contains this element.
|
String |
getLangAttribute()
Returns the value of the attribute
lang . |
String |
getNodeName() |
String |
getOnClickAttribute()
Returns the value of the attribute
onclick . |
String |
getOnDblClickAttribute()
Returns the value of the attribute
ondblclick . |
<E extends HtmlElement> |
getOneHtmlElementByAttribute(String elementName,
String attributeName,
String attributeValue)
Searches for an element based on the specified criteria, returning the first element which matches
said criteria.
|
String |
getOnKeyDownAttribute()
Returns the value of the attribute
onkeydown . |
String |
getOnKeyPressAttribute()
Returns the value of the attribute
onkeypress . |
String |
getOnKeyUpAttribute()
Returns the value of the attribute
onkeyup . |
String |
getOnMouseDownAttribute()
Returns the value of the attribute
onmousedown . |
String |
getOnMouseMoveAttribute()
Returns the value of the attribute
onmousemove . |
String |
getOnMouseOutAttribute()
Returns the value of the attribute
onmouseout . |
String |
getOnMouseOverAttribute()
Returns the value of the attribute
onmouseover . |
String |
getOnMouseUpAttribute()
Returns the value of the attribute
onmouseup . |
protected String |
getSrcAttributeNormalized()
Helper for src retrieval and normalization.
|
Short |
getTabIndex()
Returns this element's tab index, if it has one.
|
String |
getTextDirectionAttribute()
Returns the value of the attribute
dir . |
String |
getXmlLangAttribute()
Returns the value of the attribute
xml:lang . |
boolean |
handles(Event event)
Indicates if the provided event can be applied to this node.
|
boolean |
hasEventHandlers(String eventName)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
boolean |
isAltPressed()
Returns whether the
ALT is currently pressed. |
protected boolean |
isAttributeCaseSensitive()
Indicates if the attribute names are case sensitive.
|
boolean |
isCtrlPressed()
Returns whether the
CTRL is currently pressed. |
boolean |
isDisplayed()
Returns
true if this node is displayed and can be visible to the user
(ignoring screen size, scrolling limitations, color, font-size, or overlapping nodes). |
boolean |
isHidden() |
boolean |
isOptional() |
boolean |
isRequired() |
protected boolean |
isRequiredSupported()
Returns whether this element supports the
required constraint. |
protected boolean |
isShiftPressed()
Returns whether the
SHIFT is currently pressed. |
protected boolean |
isSubmittableByEnter()
Returns
true if clicking Enter (ASCII 10, or '\n') should submit the enclosed form (if any). |
boolean |
isValid()
Returns whether this element satisfies all form validation constraints set.
|
protected static void |
notifyAttributeChangeListeners(HtmlAttributeChangeEvent event,
HtmlElement element,
String oldAttributeValue,
boolean notifyMutationObservers)
Recursively notifies all
HtmlAttributeChangeListener s. |
void |
removeAttribute(String attributeName)
Removes an attribute specified by name from this element.
|
void |
removeChild(String tagName,
int i)
Removes the
i th child element with the specified tag name
from all relationships, if possible. |
void |
removeHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
Removes an HtmlAttributeChangeListener from the listener list.
|
Attr |
setAttributeNode(Attr attribute)
Sets the specified attribute.
|
protected void |
setAttributeNS(String namespaceURI,
String qualifiedName,
String attributeValue,
boolean notifyAttributeChangeListeners,
boolean notifyMutationObservers)
Sets the value of the attribute specified by namespace and qualified name.
|
void |
setHidden(boolean hidden)
Sets the
hidden property. |
void |
setHidden(String hidden)
Sets the
hidden property. |
void |
setOwningForm(HtmlForm form)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
void |
setRequired(boolean required)
Sets the
required attribute. |
Page |
type(char c)
Simulates typing the specified character while this element has focus, returning the page contained
by this element's window after typing.
|
Page |
type(int keyCode)
Simulates typing the specified key code while this element has focus, returning the page contained
by this element's window after typing.
|
Page |
type(Keyboard keyboard)
Simulates typing the specified
Keyboard while this element has focus, returning the page contained
by this element's window after typing. |
void |
type(String text)
Simulates typing the specified text while this element has focus.
|
protected void |
typeDone(String newValue,
boolean notifyAttributeChangeListeners)
Called from
DoTypeProcessor . |
blur, click, click, click, click, click, dblClick, dblClick, doClickFireChangeEvent, doClickFireClickEvent, doClickStateUpdate, fireEvent, fireEvent, focus, getAttribute, getAttributeDirect, getAttributeNode, getAttributeNodeNS, getAttributeNS, getAttributes, getAttributesMap, getChildElementCount, getChildElements, getElementsByTagName, getElementsByTagNameNS, getEventTargetElement, getFirstElementChild, getId, getLastElementChild, getNodeType, getSchemaTypeInfo, getStaticElementsByTagName, getStyleElement, getStyleElementCaseInSensitive, getStyleMap, getTagName, hasAttribute, hasAttributeNS, hasAttributes, isDisabledElementAndDisabled, isEmptyXmlTagExpanded, isMouseOver, isStateUpdateFirst, matches, mouseDown, mouseDown, mouseMove, mouseMove, mouseOut, mouseOut, mouseOver, mouseOver, mouseUp, mouseUp, preventDefault, printOpeningTagContentAsXml, printXml, propagateClickStateUpdateToParent, removeAttributeNode, removeAttributeNS, removeFocus, removeStyleAttribute, replaceStyleAttribute, rightClick, rightClick, setAttribute, setAttributeNodeNS, setAttributeNS, setDefaults, setId, setIdAttribute, setIdAttributeNode, setIdAttributeNS, setInnerHtml, setNodeValue, toString, writeStyleToElement
getLocalName, getLowercaseName, getNamespaceURI, getPrefix, getQualifiedName, processImportNode, setPrefix
addCharacterDataChangeListener, addDomChangeListener, appendChild, asNormalizedText, asXml, basicRemove, closest, compareDocumentPosition, fireCharacterDataChanged, fireNodeAdded, fireNodeDeleted, getAncestors, getBaseURI, getByXPath, getByXPath, getChildNodes, getChildren, getDescendants, getDomElementDescendants, getEndColumnNumber, getEndLineNumber, getFeature, getFirstByXPath, getFirstByXPath, getFirstChild, getHtmlElementDescendants, getHtmlPageOrNull, getIndex, getLastChild, getNextElementSibling, getNextSibling, getNodeValue, getOwnerDocument, getPage, getParentNode, getPreviousElementSibling, getPreviousSibling, getReadyState, getScriptableObject, getSelectorList, getStartColumnNumber, getStartLineNumber, getTextContent, getUserData, getVisibleText, hasChildNodes, hasFeature, insertBefore, insertBefore, isAncestorOf, isAncestorOfAny, isAttachedToPage, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, mayBeDisplayed, normalize, notifyIncorrectness, onAddedToDocumentFragment, onAddedToPage, onAllChildrenAddedToPage, parseHtmlSnippet, printChildrenAsXml, querySelector, querySelectorAll, quietlyRemoveAndMoveChildrenTo, remove, removeAllChildren, removeCharacterDataChangeListener, removeChild, removeDomChangeListener, replace, replaceChild, setEndLocation, setParentNode, setReadyState, setScriptableObject, setStartLocation, setTextContent, setUserData
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
appendChild, compareDocumentPosition, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setPrefix, setTextContent, setUserData
public static final Short TAB_INDEX_OUT_OF_BOUNDS
0
or greater
than 32767
).getTabIndex()
protected static final String ATTRIBUTE_REQUIRED
protected static final String ATTRIBUTE_CHECKED
protected static final String ATTRIBUTE_HIDDEN
protected HtmlElement(String qualifiedName, SgmlPage page, Map<String,DomAttr> attributes)
qualifiedName
- the qualified name of the element type to instantiatepage
- the page that contains this elementattributes
- a map ready initialized with the attributes for this element, or
null
. The map will be stored as is, not copied.protected HtmlElement(String namespaceURI, String qualifiedName, SgmlPage page, Map<String,DomAttr> attributes)
namespaceURI
- the URI that identifies an XML namespacequalifiedName
- the qualified name of the element type to instantiatepage
- the page that contains this elementattributes
- a map ready initialized with the attributes for this element, or
null
. The map will be stored as is, not copied.protected void setAttributeNS(String namespaceURI, String qualifiedName, String attributeValue, boolean notifyAttributeChangeListeners, boolean notifyMutationObservers)
setAttributeNS
in class DomElement
namespaceURI
- the URI that identifies an XML namespacequalifiedName
- the qualified name (prefix:local) of the attributeattributeValue
- the value of the attributenotifyAttributeChangeListeners
- to notify the associated HtmlAttributeChangeListener
snotifyMutationObservers
- to notify MutationObserver
s or notprotected static void notifyAttributeChangeListeners(HtmlAttributeChangeEvent event, HtmlElement element, String oldAttributeValue, boolean notifyMutationObservers)
HtmlAttributeChangeListener
s.event
- the eventelement
- the elementoldAttributeValue
- the old attribute valuenotifyMutationObservers
- whether to notify MutationObserver
s or notpublic Attr setAttributeNode(Attr attribute)
super.setAttributeNode()
, and should consider the value of the
cloning
parameter when deciding whether or not to execute custom logic.setAttributeNode
in interface Element
setAttributeNode
in class DomElement
attribute
- the attribute to setpublic void removeAttribute(String attributeName)
removeAttribute
in interface Element
removeAttribute
in class DomElement
attributeName
- the attribute attributeNameprotected void fireHtmlAttributeAdded(HtmlAttributeChangeEvent event)
HtmlAttributeChangeEvent
to any
registered HtmlAttributeChangeListener
s.
Note that this method recursively calls this element's parent's
fireHtmlAttributeAdded(HtmlAttributeChangeEvent)
method.
event
- the eventaddHtmlAttributeChangeListener(HtmlAttributeChangeListener)
protected void fireHtmlAttributeReplaced(HtmlAttributeChangeEvent event)
HtmlAttributeChangeEvent
to any
registered HtmlAttributeChangeListener
s.
Note that this method recursively calls this element's parent's
fireHtmlAttributeReplaced(HtmlAttributeChangeEvent)
method.
event
- the eventaddHtmlAttributeChangeListener(HtmlAttributeChangeListener)
protected void fireHtmlAttributeRemoved(HtmlAttributeChangeEvent event)
HtmlAttributeChangeEvent
to any
registered HtmlAttributeChangeListener
s.
Note that this method recursively calls this element's parent's
fireHtmlAttributeRemoved(HtmlAttributeChangeEvent)
method.
event
- the eventaddHtmlAttributeChangeListener(HtmlAttributeChangeListener)
public String getNodeName()
DomElement
getNodeName
in interface Node
getNodeName
in class DomElement
DomElement.getTagName()
public Short getTabIndex()
0
or greater than 32767
), this method
returns TAB_INDEX_OUT_OF_BOUNDS
. If this element does not have
a tab index, or its tab index is otherwise invalid, this method returns null
.public HtmlElement getEnclosingElement(String tagName)
null
if no such element is found.tagName
- the name of the tag searched (case insensitive)public HtmlForm getEnclosingForm()
null
if this element is not inside
of a form.public HtmlForm getEnclosingFormOrDie()
IllegalStateException
.public void type(String text) throws IOException
text
- the text you with to simulate typingIOException
- If an IO error occurspublic Page type(char c) throws IOException
'\n'
submits the enclosed form.c
- the character you wish to simulate typingIOException
- if an IO error occurspublic Page type(int keyCode)
XXXXXXXXXXX
submits the enclosed form.
An example of predefined values is KeyboardEvent.DOM_VK_PAGE_DOWN
.
keyCode
- the key code to simulate typingpublic Page type(Keyboard keyboard) throws IOException
Keyboard
while this element has focus, returning the page contained
by this element's window after typing. Note that it may or may not be the same as the original page,
depending on the JavaScript event handlers, etc.
Note also that for some elements, typing XXXXXXXXXXX
submits the enclosed form.keyboard
- the keyboardIOException
- if an IO error occursprotected void doType(char c, boolean lastType)
c
- the character you with to simulate typinglastType
- is this the last character to typeprotected void doType(int keyCode, boolean lastType)
An example of predefined values is KeyboardEvent.DOM_VK_PAGE_DOWN
.
keyCode
- the key code wish to simulate typinglastType
- is this the last to typeprotected void typeDone(String newValue, boolean notifyAttributeChangeListeners)
DoTypeProcessor
.newValue
- the new valuenotifyAttributeChangeListeners
- to notify the associated HtmlAttributeChangeListener
sprotected boolean acceptChar(char c)
c
- the charactertrue
if it is acceptedprotected boolean isSubmittableByEnter()
true
if clicking Enter (ASCII 10, or '\n') should submit the enclosed form (if any).
The default implementation returns false
.true
if clicking Enter should submit the enclosed form (if any)public final <E extends HtmlElement> E getOneHtmlElementByAttribute(String elementName, String attributeName, String attributeValue) throws ElementNotFoundException
E
- the sub-element typeelementName
- the name of the element to search forattributeName
- the name of the attribute to search forattributeValue
- the value of the attribute to search forElementNotFoundException
- if no element matches the specified search criteriapublic final <E extends HtmlElement> List<E> getElementsByAttribute(String elementName, String attributeName, String attributeValue)
E
- the sub-element typeelementName
- the name of the element to search forattributeName
- the name of the attribute to search forattributeValue
- the value of the attribute to search forpublic final HtmlElement appendChildIfNoneExists(String tagName)
tagName
- the tag name of the child to appendpublic final void removeChild(String tagName, int i)
i
th child element with the specified tag name
from all relationships, if possible.tagName
- the tag name of the child to removei
- the index of the child to removepublic final boolean hasEventHandlers(String eventName)
true
if this element has any JavaScript functions that need to be executed when the
specified event occurs.eventName
- the name of the event, such as "onclick" or "onblur", etcpublic void addHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
listener
- the attribute change listener to be addedremoveHtmlAttributeChangeListener(HtmlAttributeChangeListener)
public void removeHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
listener
- the attribute change listener to be removedaddHtmlAttributeChangeListener(HtmlAttributeChangeListener)
protected void checkChildHierarchy(Node childNode) throws DOMException
checkChildHierarchy
in class DomNode
childNode
- the new child node that is being inserted below this nodeDOMException
- HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does
not allow children of the type of the newChild node, or if the node to insert is one of
this node's ancestors or this node itself, or if this node is of type Document and the
DOM application attempts to insert a second DocumentType or Element node.
WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the
one that created this node.public void setOwningForm(HtmlForm form)
form
- the owning formprotected boolean isAttributeCaseSensitive()
isAttributeCaseSensitive
in class DomElement
false
public final String getLangAttribute()
lang
. Refer to the
HTML 4.01
documentation for details on the use of this attribute.lang
or an empty string if that attribute isn't definedpublic final String getXmlLangAttribute()
xml:lang
. Refer to the
HTML 4.01
documentation for details on the use of this attribute.xml:lang
or an empty string if that attribute isn't definedpublic final String getTextDirectionAttribute()
dir
. Refer to the
HTML 4.01
documentation for details on the use of this attribute.dir
or an empty string if that attribute isn't definedpublic final String getOnClickAttribute()
onclick
. Refer to the
HTML 4.01
documentation for details on the use of this attribute.onclick
or an empty string if that attribute isn't definedpublic final String getOnDblClickAttribute()
ondblclick
. Refer to the
HTML 4.01
documentation for details on the use of this attribute.ondblclick
or an empty string if that attribute isn't definedpublic final String getOnMouseDownAttribute()
onmousedown
. Refer to the
HTML 4.01
documentation for details on the use of this attribute.onmousedown
or an empty string if that attribute isn't definedpublic final String getOnMouseUpAttribute()
onmouseup
. Refer to the
HTML 4.01
documentation for details on the use of this attribute.onmouseup
or an empty string if that attribute isn't definedpublic final String getOnMouseOverAttribute()
onmouseover
. Refer to the
HTML 4.01
documentation for details on the use of this attribute.onmouseover
or an empty string if that attribute isn't definedpublic final String getOnMouseMoveAttribute()
onmousemove
. Refer to the
HTML 4.01
documentation for details on the use of this attribute.onmousemove
or an empty string if that attribute isn't definedpublic final String getOnMouseOutAttribute()
onmouseout
. Refer to the
HTML 4.01
documentation for details on the use of this attribute.onmouseout
or an empty string if that attribute isn't definedpublic final String getOnKeyPressAttribute()
onkeypress
. Refer to the
HTML 4.01
documentation for details on the use of this attribute.onkeypress
or an empty string if that attribute isn't definedpublic final String getOnKeyDownAttribute()
onkeydown
. Refer to the
HTML 4.01
documentation for details on the use of this attribute.onkeydown
or an empty string if that attribute isn't definedpublic final String getOnKeyUpAttribute()
onkeyup
. Refer to the
HTML 4.01
documentation for details on the use of this attribute.onkeyup
or an empty string if that attribute isn't definedpublic String getCanonicalXPath()
Returns the canonical XPath expression which identifies this node, for instance
"/html/body/table[3]/tbody/tr[5]/td[2]/span/a[3]"
.
WARNING: This sort of automated XPath expression is often quite bad at identifying a node, as it is highly sensitive to changes in the DOM tree.
getCanonicalXPath
in class DomNode
DomNode.getByXPath(String)
public boolean isHidden()
public void setHidden(String hidden)
hidden
property.hidden
- the hidden
propertypublic void setHidden(boolean hidden)
hidden
property.hidden
- the hidden
propertypublic boolean isDisplayed()
Returns true
if this node is displayed and can be visible to the user
(ignoring screen size, scrolling limitations, color, font-size, or overlapping nodes).
NOTE: If CSS is
disabled
, this method
does not take this element's style into consideration!
isDisplayed
in class DomNode
true
if the node is visible to the user, false
otherwiseDomNode.mayBeDisplayed()
public HtmlElement.DisplayStyle getDefaultStyleDisplay()
protected final String getSrcAttributeNormalized()
src
with all line breaks removed
or an empty string if that attribute isn't defined.protected void detach()
public boolean handles(Event event)
protected boolean isShiftPressed()
SHIFT
is currently pressed.SHIFT
is currently pressedpublic boolean isCtrlPressed()
CTRL
is currently pressed.CTRL
is currently pressedpublic boolean isAltPressed()
ALT
is currently pressed.ALT
is currently pressedpublic boolean isValid()
protected boolean isRequiredSupported()
required
constraint.required
constraintpublic boolean isRequired()
public boolean isOptional()
public void setRequired(boolean required)
required
attribute.required
- the new attribute valuepublic DomNode cloneNode(boolean deep)
cloneNode
in interface Node
cloneNode
in class DomElement
Copyright © 2002–2024 Gargoyle Software Inc.. All rights reserved.