/** * Returns the attributes of this XML element. * @see <a href="http://developer.mozilla.org/en/docs/DOM:element.attributes">Gecko DOM Reference</a> * @return the attributes of this XML element */ public Object jsxGet_attributes() { if (attributes_ == null) { attributes_ = createAttributesObject(); } return attributes_; }
/** * Removes the specified attribute. * @param name the name of the attribute to remove */ public void jsxFunction_removeAttribute(final String name) { getDomNodeOrDie().removeAttribute(name); if (getBrowserVersion().isIE()) { delete(name); } }
/** * {@inheritDoc} */ @Override public HtmlElement getDomNodeOrNull() { return (HtmlElement) super.getDomNodeOrNull(); }
/** * Represents the text content of the node or the concatenated text representing the node and its descendants. * @return the text content of the node or the concatenated text representing the node and its descendants */ public String jsxGet_text() { final StringBuilder buffer = new StringBuilder(); toText(getDomNodeOrDie(), buffer); return buffer.toString(); }
/** * Create the event handler function from the attribute value. * @param eventName the event name (ex: "onclick") * @param attrValue the attribute value */ protected void createEventHandler(final String eventName, final String attrValue) { final DomElement htmlElt = getDomNodeOrDie(); // TODO: check that it is an "allowed" event for the browser, and take care to the case final BaseFunction eventHandler = new EventHandler(htmlElt, eventName, attrValue); setEventHandler(eventName, eventHandler); }
/** * Gets the outerHTML of the node. * @see <a href="http://msdn.microsoft.com/en-us/library/ms534310.aspx">MSDN documentation</a> * @return the contents of this node as HTML */ @JsxGetter({CHROME, FF}) public String getOuterHTML() { final StringBuilder buf = new StringBuilder(); // we can't rely on DomNode.asXml because it adds indentation and new lines printNode(buf, getDomNodeOrDie(), true); return buf.toString(); }
/** * {@inheritDoc} */ @Override public HtmlElement getDomNodeOrDie() { return (HtmlElement) super.getDomNodeOrDie(); }
/** * Gets the specified attribute. * @param attributeName attribute name * @return the value of the specified attribute, <code>null</code> if the attribute is not defined */ public Object jsxFunction_getAttribute(String attributeName) { attributeName = fixAttributeName(attributeName); final String value = getDomNodeOrDie().getAttribute(attributeName); if (value == DomElement.ATTRIBUTE_NOT_DEFINED) { if (getBrowserVersion().isIE()) { for (Scriptable object = this; object != null; object = object.getPrototype()) { final Object property = object.get(attributeName, this); if (property != NOT_FOUND) { return property; } } } return null; } return value; }
/** * Returns the element's width in pixels, possibly including its padding and border. * @param includeBorder whether or not to include the border width in the returned value * @param includePadding whether or not to include the padding width in the returned value * @return the element's width in pixels, possibly including its padding and border */ public int getCalculatedWidth(final boolean includeBorder, final boolean includePadding) { if (!getElement().getDomNodeOrNull().isAttachedToPage()) { return 0; } int width = getCalculatedWidth(); if (!"border-box".equals(getStyleAttribute(BOX_SIZING))) { if (includeBorder) { width += getBorderHorizontal(); } else if (isScrollable(true, true) && !(getElement() instanceof HTMLBodyElement) && getElement().getDomNodeOrDie().isAttachedToPage()) { width -= 17; } if (includePadding) { width += getPaddingHorizontal(); } } return width; }
/** * Replaces all child elements of this element with the supplied value. * @param value the new value for the contents of this element */ @JsxSetter({CHROME, FF}) public void setInnerHTML(final Object value) { final DomNode domNode; try { domNode = getDomNodeOrDie(); } catch (final IllegalStateException e) { Context.throwAsScriptRuntimeEx(e); return; } domNode.removeAllChildren(); final boolean addChildForNull = getBrowserVersion().hasFeature(JS_INNER_HTML_ADD_CHILD_FOR_NULL_VALUE); if ((value == null && addChildForNull) || (value != null && !"".equals(value))) { final String valueAsString = Context.toString(value); parseHtmlSnippet(domNode, valueAsString); } }
/** * Retrieves an object that specifies the bounds of a collection of TextRectangle objects. * @see <a href="http://msdn.microsoft.com/en-us/library/ms536433.aspx">MSDN doc</a> * @return an object that specifies the bounds of a collection of TextRectangle objects */ @JsxFunction public ClientRect getBoundingClientRect() { if (!getDomNodeOrDie().isAttachedToPage() && getBrowserVersion().hasFeature(JS_BOUNDINGCLIENTRECT_THROWS_IF_DISCONNECTED)) { throw Context.reportRuntimeError("Element is not attache to a page"); } final ClientRect textRectangle = new ClientRect(1, 1, 1, 1); textRectangle.setParentScope(getWindow()); textRectangle.setPrototype(getPrototype(textRectangle.getClass())); return textRectangle; }
/** * Replaces all child elements of this element with the supplied value. * @param value the new value for the contents of this element */ @JsxSetter({CHROME, FF}) public void setInnerHTML(final Object value) { final DomNode domNode; try { domNode = getDomNodeOrDie(); } catch (final IllegalStateException e) { Context.throwAsScriptRuntimeEx(e); return; } domNode.removeAllChildren(); getWindow().clearComputedStylesUpToRoot(this); final boolean addChildForNull = getBrowserVersion().hasFeature(JS_INNER_HTML_ADD_CHILD_FOR_NULL_VALUE); if ((value == null && addChildForNull) || (value != null && !"".equals(value))) { final String valueAsString = Context.toString(value); parseHtmlSnippet(domNode, valueAsString); } }
/** * Gets the specified attribute. * @param namespaceURI the namespace URI * @param localName the local name of the attribute to look for * @return the value of the specified attribute, {@code null} if the attribute is not defined */ @JsxFunction public String getAttributeNS(final String namespaceURI, final String localName) { final String value = getDomNodeOrDie().getAttributeNS(namespaceURI, localName); if (ATTRIBUTE_NOT_DEFINED == value && !getBrowserVersion().hasFeature(JS_ELEMENT_GET_ATTRIBUTE_RETURNS_EMPTY)) { return null; } return value; }
/** * Creates an instance and sets its parent scope to the one of the provided element. * @param element the element to which this style is bound */ CSSValue(final Element element, final org.w3c.dom.css.CSSValue cssValue) { setParentScope(element.getParentScope()); setPrototype(getPrototype(getClass())); setDomNode(element.getDomNodeOrNull(), false); wrappedCssValue_ = cssValue; }
/** * Sets the DOM node that corresponds to this JavaScript object. * @param domNode the DOM node */ @Override public void setDomNode(final DomNode domNode) { super.setDomNode(domNode); final String name = domNode.getLocalName(); if ("wbr".equalsIgnoreCase(name) || "basefont".equalsIgnoreCase(name) || "keygen".equalsIgnoreCase(name) || "track".equalsIgnoreCase(name)) { endTagForbidden_ = true; } }
scriptable = new Element();
&& !(scriptObject instanceof HTMLScriptElement) && !(scriptObject instanceof HTMLStyleElement); printChildren(builder, node, isHtml); if (null == htmlElement || !htmlElement.isEndTagForbidden()) { builder.append("</").append(tag).append(">"); final HtmlElement element = (HtmlElement) node; if ("p".equals(element.getTagName())) { if (getBrowserVersion().hasFeature(JS_INNER_TEXT_LF)) { builder.append('\n'); // \r\n because it's to implement something IE specific printChildren(builder, node, html);
/** * Sets the styles for this element. * @param style the style of the element */ protected void setStyle(final String style) { if (!getBrowserVersion().hasFeature(JS_ELEMENT_GET_ATTRIBUTE_RETURNS_EMPTY)) { getStyle().setCssText(style); } }
/** * {@inheritDoc} */ @Override public Object get(final String name, final Scriptable start) { final Object response = super.get(name, start); // IE support .querySelector(All) but not in quirks mode // => TODO: find a better way to handle this! if (response instanceof FunctionObject && ("querySelectorAll".equals(name) || "querySelector".equals(name)) && getBrowserVersion().hasFeature(QUERYSELECTORALL_NOT_IN_QUIRKS)) { final Document doc = getWindow().getDocument(); if (doc instanceof HTMLDocument && ((HTMLDocument) doc).getDocumentMode() < 8) { return NOT_FOUND; } } return response; }
/** * Returns the tag name of this element. * @return the tag name */ public final String jsxGet_tagName() { return jsxGet_nodeName(); }