Class ElementImpl

All Implemented Interfaces:
Cloneable, EventTarget, ModelNode, Element, InnerHTML, Node, NonDocumentTypeChildNode, ParentNode, ScriptableDelegate
Direct Known Subclasses:
HTMLElementImpl

public class ElementImpl extends NodeImpl implements Element

ElementImpl class.

  • Constructor Details

    • ElementImpl

      public ElementImpl(String name)

      Constructor for ElementImpl.

      Parameters:
      name - a String object.
  • Method Details

    • getAttribute

      @JSFunction public String getAttribute(String name)
      Returns element's first attribute whose qualified name is qualifiedName, and null if there is no such attribute otherwise.
      Specified by:
      getAttribute in interface Element
      Parameters:
      name - a String object.
      Returns:
      a String object.
    • getAttributeNS

      @JSFunction public String getAttributeNS(String namespaceURI, String localName) throws DOMException
      Returns element's attribute whose namespace is namespace and local name is localName, and null if there is no such attribute otherwise.
      Specified by:
      getAttributeNS in interface Element
      Parameters:
      namespaceURI - a String object.
      localName - a String object.
      Returns:
      a String object.
      Throws:
      DOMException
    • getAttributeNode

      @JSFunction public Attr getAttributeNode(String name)

      getAttributeNode.

      Specified by:
      getAttributeNode in interface Element
      Parameters:
      name - a String object.
      Returns:
      a Attr object.
    • getAttributeNodeNS

      @JSFunction public Attr getAttributeNodeNS(String namespaceURI, String localName) throws DOMException

      getAttributeNodeNS.

      Specified by:
      getAttributeNodeNS in interface Element
      Parameters:
      namespaceURI - a String object.
      localName - a String object.
      Returns:
      a Attr object.
      Throws:
      DOMException
    • removeAttribute

      public void removeAttribute(String name)
      Removes element's first attribute whose qualified name is qualifiedName.
      Specified by:
      removeAttribute in interface Element
      Parameters:
      name - a String object.
    • removeAttributeNS

      public void removeAttributeNS(String namespaceURI, String localName) throws DOMException
      Removes element's attribute whose namespace is namespace and local name is localName.
      Specified by:
      removeAttributeNS in interface Element
      Parameters:
      namespaceURI - a String object.
      localName - a String object.
      Throws:
      DOMException
    • removeAttributeNode

      public Attr removeAttributeNode(Attr oldAttr)

      removeAttributeNode.

      Specified by:
      removeAttributeNode in interface Element
      Parameters:
      oldAttr - a Attr object.
      Returns:
      a Attr object.
    • setAttribute

      public void setAttribute(String attrName, String value)
      Sets the value of element's first attribute whose qualified name is qualifiedName to value.
      Specified by:
      setAttribute in interface Element
      Parameters:
      attrName - a String object.
      value - a String object.
    • setAttributeNS

      public void setAttributeNS(String namespaceURI, String qName, String value) throws DOMException
      Sets the value of element's attribute whose namespace is namespace and local name is localName to value.
      Specified by:
      setAttributeNS in interface Element
      Parameters:
      namespaceURI - a String object.
      qName - a String object.
      value - a String object.
      Throws:
      DOMException
    • setIdAttribute

      public void setIdAttribute(String localName, boolean isId) throws DOMException

      setIdAttribute.

      Specified by:
      setIdAttribute in interface Element
      Parameters:
      localName - a String object.
      isId - a boolean.
      Throws:
      DOMException
    • setIdAttributeNS

      public void setIdAttributeNS(String namespaceURI, String localName, boolean isId) throws DOMException

      setIdAttributeNode.

      Specified by:
      setIdAttributeNS in interface Element
      Parameters:
      namespaceURI - a String object.
      localName - a String object.
      isId - a boolean.
      Throws:
      DOMException
    • setIdAttributeNode

      public void setIdAttributeNode(Attr idAttr, boolean isId)

      setIdAttributeNode.

      Specified by:
      setIdAttributeNode in interface Element
      Parameters:
      idAttr - a Attr object.
      isId - a boolean.
    • setAttributeNode

      public Attr setAttributeNode(Attr newAttr)

      setAttributeNode.

      Specified by:
      setAttributeNode in interface Element
      Parameters:
      newAttr - a Attr object.
      Returns:
      a Attr object.
    • setAttributeNodeNS

      public Attr setAttributeNodeNS(Attr newAttr) throws DOMException

      setAttributeNodeNS.

      Specified by:
      setAttributeNodeNS in interface Element
      Parameters:
      newAttr - a Attr object.
      Returns:
      a Attr object.
      Throws:
      DOMException
    • getAttributes

      public NamedNodeMap getAttributes()

      getAttributes.

      Specified by:
      getAttributes in interface Node
      Overrides:
      getAttributes in class NodeImpl
      Returns:
      a NamedNodeMap object.
    • getDir

      public String getDir()

      getDir.

      Returns:
      a String object.
    • getId

      public String getId()

      Getter for the field id.

      Specified by:
      getId in interface Element
      Returns:
      a String object.
    • getLang

      public String getLang()

      getLang.

      Returns:
      a String object.
    • getLocalName

      public String getLocalName()

      getLocalName.

      Specified by:
      getLocalName in interface Element
      Specified by:
      getLocalName in interface Node
      Specified by:
      getLocalName in class NodeImpl
      Returns:
      a String object.
    • getNodeName

      public String getNodeName()
      Returns a string appropriate for the type of node.
      Specified by:
      getNodeName in interface Node
      Specified by:
      getNodeName in class NodeImpl
      Returns:
      a String object.
    • getNodeType

      public int getNodeType()
      Returns the type of node.
      Specified by:
      getNodeType in interface Node
      Specified by:
      getNodeType in class NodeImpl
      Returns:
      a Integer object.
    • getNodeValue

      public String getNodeValue() throws DOMException
      Description copied from class: NodeImpl

      getNodeValue.

      Specified by:
      getNodeValue in interface Node
      Specified by:
      getNodeValue in class NodeImpl
      Returns:
      a String object.
      Throws:
      DOMException
    • getRawInnerText

      protected String getRawInnerText(boolean includeComment)
      Gets inner text of the element, possibly including text in comments. This can be used to get Javascript code out of a SCRIPT element.
      Parameters:
      includeComment - a boolean.
      Returns:
      a String object.
    • getTagName

      public String getTagName()
      Returns the HTML-uppercased qualified name.
      Specified by:
      getTagName in interface Element
      Returns:
      a String object.
    • getTitle

      public String getTitle()

      getTitle.

      Returns:
      a String object.
    • hasAttribute

      public boolean hasAttribute(String name)
      Returns true if element has an attribute whose qualified name is qualifiedName, and false otherwise.
      Specified by:
      hasAttribute in interface Element
      Parameters:
      name - a String object.
      Returns:
      a boolean.
    • hasAttributeNS

      public boolean hasAttributeNS(String namespaceURI, String localName) throws DOMException
      Returns true if element has an attribute whose namespace is namespace and local name is localName.
      Specified by:
      hasAttributeNS in interface Element
      Parameters:
      namespaceURI - a String object.
      localName - a String object.
      Returns:
      a boolean.
      Throws:
      DOMException
    • hasAttributes

      public boolean hasAttributes()
      Returns true if element has attributes, and false otherwise.
      Specified by:
      hasAttributes in interface Node
      Returns:
      a boolean.
    • htmlEncodeChildText

      protected String htmlEncodeChildText(String text)

      htmlEncodeChildText.

      Overrides:
      htmlEncodeChildText in class NodeImpl
      Parameters:
      text - a String object.
      Returns:
      a String object.
    • setDir

      public void setDir(String dir)

      setDir.

      Parameters:
      dir - a String object.
    • setId

      public void setId(String id)

      setId.

      Specified by:
      setId in interface Element
      Parameters:
      id - a String object.
    • setInnerText

      public void setInnerText(String newText)

      setInnerText.

      Parameters:
      newText - a String object.
    • setLang

      public void setLang(String lang)

      setLang.

      Parameters:
      lang - a String object.
    • setNodeValue

      public void setNodeValue(String nodeValue)

      setNodeValue.

      Specified by:
      setNodeValue in interface Node
      Specified by:
      setNodeValue in class NodeImpl
      Parameters:
      nodeValue - a String object.
    • setTitle

      public void setTitle(String title)

      setTitle.

      Parameters:
      title - a String object.
    • setInnerHTML

      public void setInnerHTML(String newHtml)

      setInnerHTML.

      Specified by:
      setInnerHTML in interface InnerHTML
      Parameters:
      newHtml - a String object.
    • getClassList

      public DOMTokenList getClassList()
      Allows for manipulation of element's class content attribute as a set of whitespace-separated tokens through a DOMTokenList object.
      Specified by:
      getClassList in interface Element
      Returns:
      a DOMTokenList object.
    • getClassName

      public String getClassName()
      Returns the value of element's class content attribute. Can be set to change it.
      Specified by:
      getClassName in interface Element
      Returns:
      a String object.
    • setClassName

      public void setClassName(String className)

      setClassName.

      Specified by:
      setClassName in interface Element
      Parameters:
      className - a String object.
    • getClientHeight

      public int getClientHeight()

      getClientHeight.

      Specified by:
      getClientHeight in interface Element
      Returns:
      a Integer object.
    • getClientLeft

      public int getClientLeft()

      getClientLeft.

      Specified by:
      getClientLeft in interface Element
      Returns:
      a Integer object.
    • getClientTop

      public int getClientTop()

      getClientTop.

      Specified by:
      getClientTop in interface Element
      Returns:
      a Integer object.
    • getClientWidth

      public Integer getClientWidth()

      getClientWidth.

      Specified by:
      getClientWidth in interface Element
      Returns:
      a Integer object.
    • getInnerHTML

      public String getInnerHTML()

      getInnerHTML.

      Specified by:
      getInnerHTML in interface Element
      Specified by:
      getInnerHTML in interface InnerHTML
      Returns:
      a String object.
    • getInnerText

      public String getInnerText()

      getInnerText.

      Specified by:
      getInnerText in interface Element
      Returns:
      a String object.
    • getOuterHTML

      public String getOuterHTML()

      getOuterHTML.

      Specified by:
      getOuterHTML in interface Element
      Returns:
      a String object.
    • setOuterHTML

      public void setOuterHTML(String newHtml)

      setOuterHTML.

      Specified by:
      setOuterHTML in interface Element
      Parameters:
      newHtml - a String object.
    • getSlot

      public String getSlot()
      Returns the value of element's slot content attribute. Can be set to change it.
      Specified by:
      getSlot in interface Element
      Returns:
      a String object.
    • setSlot

      public void setSlot(String slot)

      setSlot.

      Specified by:
      setSlot in interface Element
      Parameters:
      slot - a String object.
    • closest

      public <E extends Element> E closest(String selector)
      Returns the first (starting at element) inclusive ancestor that matches selectors, and null otherwise.
      Specified by:
      closest in interface Element
      Type Parameters:
      E - a E object.
      Parameters:
      selector - a String object.
      Returns:
      a E object.
    • getAttributeNames

      public String[] getAttributeNames()
      Returns the qualified names of all element's attributes. Can contain duplicates.
      Specified by:
      getAttributeNames in interface Element
      Returns:
      an array of String objects.
    • hasPointerCapture

      public boolean hasPointerCapture(int pointerId)

      hasPointerCapture.

      Specified by:
      hasPointerCapture in interface Element
      Parameters:
      pointerId - a Integer object.
      Returns:
      a boolean.
    • matches

      public boolean matches(String selectors)
      Returns true if matching selectors against element's root yields element, and false otherwise.
      Specified by:
      matches in interface Element
      Parameters:
      selectors - a String object.
      Returns:
      a boolean.
    • releasePointerCapture

      public void releasePointerCapture(int pointerId)

      releasePointerCapture.

      Specified by:
      releasePointerCapture in interface Element
      Parameters:
      pointerId - a Integer object.
    • requestPointerLock

      public void requestPointerLock()

      requestPointerLock.

      Specified by:
      requestPointerLock in interface Element
    • scroll

      public void scroll(int x, int y)

      scroll.

      Specified by:
      scroll in interface Element
      Parameters:
      x - a double.
      y - a double.
    • scrollBy

      public void scrollBy(int x, int y)

      scrollBy.

      Specified by:
      scrollBy in interface Element
      Parameters:
      x - a double.
      y - a double.
    • scrollIntoView

      public void scrollIntoView(boolean arg)

      scrollIntoView.

      Specified by:
      scrollIntoView in interface Element
      Parameters:
      arg - a boolean.
    • scrollIntoView

      public void scrollIntoView()

      scrollIntoView.

      Specified by:
      scrollIntoView in interface Element
    • scrollTo

      public void scrollTo(int x, int y)

      scrollTo.

      Specified by:
      scrollTo in interface Element
      Parameters:
      x - a double.
      y - a double.
    • getScrollHeight

      public double getScrollHeight()

      getScrollHeight.

      Specified by:
      getScrollHeight in interface Element
      Returns:
      a double.
    • getScrollLeft

      public double getScrollLeft()

      getScrollLeft.

      Specified by:
      getScrollLeft in interface Element
      Returns:
      a double.
    • setScrollLeft

      public void setScrollLeft(double left)

      setScrollLeft.

      Specified by:
      setScrollLeft in interface Element
      Parameters:
      left - a Integer object.
    • getScrollTop

      public double getScrollTop()

      getScrollTop.

      Specified by:
      getScrollTop in interface Element
      Returns:
      a double.
    • setScrollTop

      public void setScrollTop(double scroll)

      setScrollTop.

      Specified by:
      setScrollTop in interface Element
      Parameters:
      scroll - a Integer object.
    • getScrollWidth

      public double getScrollWidth()

      getScrollWidth.

      Specified by:
      getScrollWidth in interface Element
      Returns:
      a double.
    • setPointerCapture

      public void setPointerCapture(int pointerId)

      setPointerCapture.

      Specified by:
      setPointerCapture in interface Element
      Parameters:
      pointerId - a Integer object.
    • toggleAttribute

      public boolean toggleAttribute(String qualifiedName, boolean force)
      If force is not given, "toggles" qualifiedName, removing it if it is present and adding it if it is not present. If force is true, adds qualifiedName. If force is false, removes qualifiedName.

      Returns true if qualifiedName is now present, and false otherwise.

      Specified by:
      toggleAttribute in interface Element
      Parameters:
      qualifiedName - a String object.
      force - a boolean.
      Returns:
      a boolean.
    • toggleAttribute

      public boolean toggleAttribute(String qualifiedName)

      toggleAttribute.

      Specified by:
      toggleAttribute in interface Element
      Parameters:
      qualifiedName - a String object.
      Returns:
      a boolean.
    • insertAdjacentElement

      public Node insertAdjacentElement(String where, Node insertedElement)
      Description copied from interface: Element

      insertAdjacentElement.

      Specified by:
      insertAdjacentElement in interface Element
      Parameters:
      where - a String object.
      insertedElement - Node object.
      Returns:
      a Node object.
    • insertAdjacentHTML

      public void insertAdjacentHTML(String position, String text)
      Description copied from interface: Element

      insertAdjacentHTML.

      Specified by:
      insertAdjacentHTML in interface Element
      Parameters:
      position - a String object.
      text - a String object.
    • getBoundingClientRect

      public DOMRect getBoundingClientRect()

      getBoundingClientRect.

      Specified by:
      getBoundingClientRect in interface Element
      Returns:
      a DOMRect object.
    • getClientRects

      public DOMRectList getClientRects()

      getClientRects.

      Specified by:
      getClientRects in interface Element
      Returns:
      a DOMRectList object.
    • getSchemaTypeInfo

      public TypeInfo getSchemaTypeInfo()

      getSchemaTypeInfo.

      Specified by:
      getSchemaTypeInfo in interface Element
      Returns:
      a TypeInfo object.
    • getElementsByClassName

      public HTMLCollection getElementsByClassName(String classNames)
      Returns a HTMLCollection of the elements in the object on which the method was invoked (a document or an element) that have all the classes given by classNames. The classNames argument is interpreted as a space-separated list of classes.
      Specified by:
      getElementsByClassName in interface Element
      Parameters:
      classNames - a String object.
      Returns:
      a HTMLCollection object.
    • getElementsByTagName

      public HTMLCollection getElementsByTagName(String tagname)

      getElementsByTagName.

      Specified by:
      getElementsByTagName in interface Element
      Parameters:
      tagname - a String object.
      Returns:
      a HTMLCollection object.
    • getElementsByTagNameNS

      public HTMLCollection getElementsByTagNameNS(String namespaceURI, String localName)

      getElementsByTagNameNS.

      Specified by:
      getElementsByTagNameNS in interface Element
      Parameters:
      namespaceURI - a String object.
      localName - a String object.
      Returns:
      a HTMLCollection object.
    • getFirstElementChild

      public Element getFirstElementChild()
      Returns the first child that is an element, and null otherwise.
      Specified by:
      getFirstElementChild in interface ParentNode
      Returns:
      a Element object.
    • getLastElementChild

      public Element getLastElementChild()
      Returns the last child that is an element, and null otherwise.
      Specified by:
      getLastElementChild in interface ParentNode
      Returns:
      a Element object.
    • getChildElementCount

      public int getChildElementCount()

      getChildElementCount.

      Specified by:
      getChildElementCount in interface ParentNode
      Returns:
      a Integer object.
    • querySelector

      public Element querySelector(String selectors)
      Returns the first element that is a descendant of node that matches selectors.
      Specified by:
      querySelector in interface ParentNode
      Parameters:
      selectors - a String object.
      Returns:
      a Element object.
    • querySelectorAll

      public NodeList querySelectorAll(String selector)
      Returns all element descendants of node that match selectors.
      Specified by:
      querySelectorAll in interface ParentNode
      Parameters:
      selector - a String object.
      Returns:
      a NodeList object.
    • assignAttributeField

      public void assignAttributeField(String normalName, String value)
    • isEqualNode

      public boolean isEqualNode(Node arg)
      Description copied from class: NodeImpl
      Returns whether node and otherNode have the same properties.
      Specified by:
      isEqualNode in interface Node
      Overrides:
      isEqualNode in class NodeImpl
      Parameters:
      arg - a Node object.
      Returns:
      a boolean.
    • appendOuterHTMLImpl

      public void appendOuterHTMLImpl(StringBuilder buffer)

      appendOuterHTMLImpl.

      Parameters:
      buffer - a StringBuilder object.
    • calculateWidth

      public int calculateWidth(boolean isBorder, boolean isPadding, boolean isClient)
    • calculateHeight

      public int calculateHeight(boolean isBorder, boolean isPadding, boolean isClient)