public IElement getParent() { DomNode p = element.getParentNode(); while (true) { if (p == null) return null; if (p instanceof HtmlElement) return new HtmlUnitElementImpl((HtmlElement) p); // get next parent p = p.getParentNode(); } }
/** * Search for the namespace URI of the given prefix, starting from the specified element. * @param element the element to start searching from * @param prefix the namespace prefix * @return the namespace URI bound to the prefix; or null if there is no such namespace */ public static String lookupNamespaceURI(final DomElement element, final String prefix) { String uri = element.getAttribute("xmlns:" + prefix); if (uri == DomElement.ATTRIBUTE_NOT_DEFINED) { final DomNode parentNode = element.getParentNode(); if (parentNode instanceof DomElement) { uri = lookupNamespaceURI((DomElement) parentNode, prefix); } } return uri; }
/** * Search for the namespace URI of the given prefix, starting from the specified element. * @param element the element to start searching from * @param prefix the namespace prefix * @return the namespace URI bound to the prefix; or null if there is no such namespace */ public static String lookupNamespaceURI(final DomElement element, final String prefix) { String uri = element.getAttribute("xmlns:" + prefix); if (uri == DomElement.ATTRIBUTE_NOT_DEFINED) { final DomNode parentNode = element.getParentNode(); if (parentNode instanceof DomElement) { uri = lookupNamespaceURI((DomElement) parentNode, prefix); } } return uri; }
/** * Search for the namespace URI of the given prefix, starting from the specified element. * @param element the element to start searching from * @param prefix the namespace prefix * @return the namespace URI bound to the prefix; or null if there is no such namespace */ public static String lookupNamespaceURI(final DomElement element, final String prefix) { String uri = element.getAttribute("xmlns:" + prefix); if (uri == DomElement.ATTRIBUTE_NOT_DEFINED) { final DomNode parentNode = element.getParentNode(); if (parentNode instanceof DomElement) { uri = lookupNamespaceURI((DomElement) parentNode, prefix); } } return uri; }
/** * This method implements the control state update part of the click action. * * <p>The default implementation only calls doClickStateUpdate on parent's DomElement (if any). * Subclasses requiring different behavior (like {@link HtmlSubmitInput}) will override this method.</p> * @param shiftKey {@code true} if SHIFT is pressed * @param ctrlKey {@code true} if CTRL is pressed * * @return true if doClickFireEvent method has to be called later on (to signal, * that the value was changed) * @throws IOException if an IO error occurs */ protected boolean doClickStateUpdate(final boolean shiftKey, final boolean ctrlKey) throws IOException { if (propagateClickStateUpdateToParent()) { // needed for instance to perform link doClickAction when a nested element is clicked // it should probably be changed to do this at the event level but currently // this wouldn't work with JS disabled as events are propagated in the host object tree. final DomNode parent = getParentNode(); if (parent instanceof DomElement) { return ((DomElement) parent).doClickStateUpdate(false, false); } } return false; }
/** * This method implements the control state update part of the click action. * * <p>The default implementation only calls doClickStateUpdate on parent's DomElement (if any). * Subclasses requiring different behavior (like {@link HtmlSubmitInput}) will override this method.</p> * @param shiftKey {@code true} if SHIFT is pressed * @param ctrlKey {@code true} if CTRL is pressed * * @return true if doClickFireEvent method has to be called later on (to signal, * that the value was changed) * @throws IOException if an IO error occurs */ protected boolean doClickStateUpdate(final boolean shiftKey, final boolean ctrlKey) throws IOException { if (propagateClickStateUpdateToParent()) { // needed for instance to perform link doClickAction when a nested element is clicked // it should probably be changed to do this at the event level but currently // this wouldn't work with JS disabled as events are propagated in the host object tree. final DomNode parent = getParentNode(); if (parent instanceof DomElement) { return ((DomElement) parent).doClickStateUpdate(false, false); } } return false; }
/** * Search for the namespace URI of the given prefix, starting from the specified element. * The default namespace can be searched for by specifying "" as the prefix. * @param element the element to start searching from * @param prefix the namespace prefix * @return the namespace URI bound to the prefix; or null if there is no such namespace */ public static String lookupNamespaceURI(final DomElement element, final String prefix) { String uri = DomElement.ATTRIBUTE_NOT_DEFINED; if (prefix.isEmpty()) { uri = element.getAttributeDirect("xmlns"); } else { uri = element.getAttribute("xmlns:" + prefix); } if (uri == DomElement.ATTRIBUTE_NOT_DEFINED) { final DomNode parentNode = element.getParentNode(); if (parentNode instanceof DomElement) { uri = lookupNamespaceURI((DomElement) parentNode, prefix); } } return uri; }
/** * Search for the namespace URI of the given prefix, starting from the specified element. * The default namespace can be searched for by specifying "" as the prefix. * @param element the element to start searching from * @param prefix the namespace prefix * @return the namespace URI bound to the prefix; or null if there is no such namespace */ public static String lookupNamespaceURI(final DomElement element, final String prefix) { String uri = DomElement.ATTRIBUTE_NOT_DEFINED; if (prefix.isEmpty()) { uri = element.getAttributeDirect("xmlns"); } else { uri = element.getAttribute("xmlns:" + prefix); } if (uri == DomElement.ATTRIBUTE_NOT_DEFINED) { final DomNode parentNode = element.getParentNode(); if (parentNode instanceof DomElement) { uri = lookupNamespaceURI((DomElement) parentNode, prefix); } } return uri; }
/** * This is overridden instead of {@link #computeElements()} in order to prevent caching at all. * * {@inheritDoc} */ @Override public List<DomNode> getElements() { final List<DomNode> response = new ArrayList<>(); final DomElement domElement = (DomElement) getDomNodeOrDie(); for (DomNode parent = domElement.getParentNode(); parent != null; parent = parent.getParentNode()) { if (parent instanceof HtmlLabel) { response.add(parent); } } final String id = domElement.getId(); if (id != DomElement.ATTRIBUTE_NOT_DEFINED) { for (final DomElement label : domElement.getHtmlPageOrNull().getElementsByTagName("label")) { if (id.equals(label.getAttributeDirect("for"))) { response.add(label); } } } return response; } }
/** * This is overridden instead of {@link #computeElements()} in order to prevent caching at all. * * {@inheritDoc} */ @Override public List<DomNode> getElements() { final List<DomNode> response = new ArrayList<>(); final DomElement domElement = (DomElement) getDomNodeOrDie(); for (DomNode parent = domElement.getParentNode(); parent != null; parent = parent.getParentNode()) { if (parent instanceof HtmlLabel) { response.add(parent); } } final String id = domElement.getId(); if (id != DomElement.ATTRIBUTE_NOT_DEFINED) { for (final DomElement label : domElement.getHtmlPageOrNull().getElementsByTagName("label")) { if (id.equals(label.getAttributeDirect("for"))) { response.add(label); } } } return response; } }
private int getTopForAbsolutePositionWithInheritance() { int top = 0; final String t = getTopWithInheritance(); if (!AUTO.equals(t)) { // No need to calculate displacement caused by sibling nodes. top = pixelValue(t); } else { final String b = getBottomWithInheritance(); if (!AUTO.equals(b)) { // Estimate the vertical displacement caused by *all* siblings. // This is very rough, and doesn't even take position or display types into account. // It also doesn't take into account the fact that the parent's height may be hardcoded in CSS. top = 0; DomNode child = getElement().getDomNodeOrDie().getParentNode().getFirstChild(); while (child != null) { if (child instanceof HtmlElement && child.mayBeDisplayed()) { top += 20; } child = child.getNextSibling(); } top -= pixelValue(b); } } return top; }
private int getTopForAbsolutePositionWithInheritance() { final String t = getTopWithInheritance(); if (!AUTO.equals(t)) { // No need to calculate displacement caused by sibling nodes. return pixelValue(t); } final String b = getBottomWithInheritance(); if (!AUTO.equals(b)) { // Estimate the vertical displacement caused by *all* siblings. // This is very rough, and doesn't even take position or display types into account. // It also doesn't take into account the fact that the parent's height may be hardcoded in CSS. int top = 0; DomNode child = getElement().getDomNodeOrDie().getParentNode().getFirstChild(); while (child != null) { if (child instanceof HtmlElement && child.mayBeDisplayed()) { top += 20; } child = child.getNextSibling(); } top -= pixelValue(b); return top; } return 0; }
final DomNode parentNode = element.getParentNode(); if (parentNode == element.getPage()) { return false;
final DomNode parentNode = element.getParentNode(); if (parentNode == element.getPage()) { return false;