From: <asa...@us...> - 2017-01-26 16:40:50
|
Revision: 13427 http://sourceforge.net/p/htmlunit/code/13427 Author: asashour Date: 2017-01-26 16:40:47 +0000 (Thu, 26 Jan 2017) Log Message: ----------- Notify AttributeChangeListeners only at the end of 'typing()'. Issue 1811 Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DoTypeProcessor.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomText.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButton.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButtonInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlHiddenInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImageInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlResetInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlScript.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSelect.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSubmitInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/MutationObserver.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/MutationObserverTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -350,12 +350,13 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, String attributeValue, + final boolean notifyAttributeChangeListeners) { if (null != attributeValue && "src".equals(qualifiedName)) { attributeValue = attributeValue.trim(); } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); if ("src".equals(qualifiedName) && WebClient.ABOUT_BLANK != attributeValue) { if (isAttachedToPage()) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DoTypeProcessor.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DoTypeProcessor.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DoTypeProcessor.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -46,7 +46,7 @@ import com.gargoylesoftware.htmlunit.html.impl.SelectionDelegate; /** - * The process for {@link HtmlElement#doType(char, boolean)}. + * The process for {@link HtmlElement#doType(char, boolean, boolean)}. * * @author Marc Guillemot * @author Ronald Brill @@ -82,7 +82,7 @@ } void doType(final String currentValue, final SelectionDelegate selectionDelegate, - final char c, final HtmlElement element) { + final char c, final HtmlElement element, final boolean lastType) { int selectionStart = selectionDelegate.getSelectionStart(); int selectionEnd = selectionDelegate.getSelectionEnd(); @@ -124,7 +124,7 @@ } } - typeDone(newValue.toString()); + typeDone(newValue.toString(), lastType); selectionDelegate.setSelectionStart(selectionStart); selectionDelegate.setSelectionEnd(selectionEnd); @@ -170,12 +170,12 @@ clipboard.setContents(stringSelection, this); } - private void typeDone(final String newValue) { + private void typeDone(final String newValue, final boolean notifyAttributeChangeListeners) { if (domNode_ instanceof DomText) { ((DomText) domNode_).setData(newValue); } else { - ((HtmlElement) domNode_).typeDone(newValue); + ((HtmlElement) domNode_).typeDone(newValue, notifyAttributeChangeListeners); } } @@ -187,7 +187,7 @@ } void doType(final String currentValue, final SelectionDelegate selectionDelegate, - final int keyCode, final HtmlElement element) { + final int keyCode, final HtmlElement element, final boolean lastType) { final StringBuilder newValue = new StringBuilder(currentValue); int selectionStart = selectionDelegate.getSelectionStart(); @@ -195,7 +195,7 @@ final Character ch = SPECIAL_KEYS_MAP_.get(keyCode); if (ch != null) { - doType(currentValue, selectionDelegate, ch, element); + doType(currentValue, selectionDelegate, ch, element, lastType); return; } switch (keyCode) { @@ -263,7 +263,7 @@ selectionEnd = selectionStart; } - typeDone(newValue.toString()); + typeDone(newValue.toString(), lastType); selectionDelegate.setSelectionStart(selectionStart); selectionDelegate.setSelectionEnd(selectionEnd); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -463,7 +463,7 @@ */ @Override public void setAttribute(final String attributeName, final String attributeValue) { - setAttributeNS(null, attributeName, attributeValue); + setAttributeNS(null, attributeName, attributeValue, true); } /** @@ -474,8 +474,21 @@ * @param attributeValue the value of the attribute */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, + public final void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + setAttributeNS(namespaceURI, qualifiedName, attributeValue, true); + } + + /** + * Sets the value of the attribute specified by namespace and qualified name. + * + * @param namespaceURI the URI that identifies an XML namespace + * @param qualifiedName the qualified name (prefix:local) of the attribute + * @param attributeValue the value of the attribute + * @param notifyAttributeChangeListeners to notify the associated {@link HtmlAttributeChangeListener}s + */ + protected void setAttributeNS(final String namespaceURI, final String qualifiedName, + final String attributeValue, final boolean notifyAttributeChangeListeners) { final String value = attributeValue; final DomAttr newAttr = new DomAttr(getPage(), namespaceURI, qualifiedName, value, true); newAttr.setParentNode(this); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomText.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomText.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomText.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -169,13 +169,15 @@ * @param c the character you with to simulate typing * @param startAtEnd whether typing should start at the text end or not * @param htmlElement the element in which typing occurs + * @param lastType is this the last character to type */ - protected void doType(final char c, final boolean startAtEnd, final HtmlElement htmlElement) { + protected void doType(final char c, final boolean startAtEnd, final HtmlElement htmlElement, + final boolean lastType) { initDoTypeProcessor(); if (startAtEnd) { selectionDelegate_.setSelectionStart(getData().length()); } - doTypeProcessor_.doType(getData(), selectionDelegate_, c, htmlElement); + doTypeProcessor_.doType(getData(), selectionDelegate_, c, htmlElement, lastType); } /** @@ -184,13 +186,15 @@ * @param keyCode the key code wish to simulate typing * @param startAtEnd whether typing should start at the text end or not * @param htmlElement the element in which typing occurs + * @param lastType is this the last character to type */ - protected void doType(final int keyCode, final boolean startAtEnd, final HtmlElement htmlElement) { + protected void doType(final int keyCode, final boolean startAtEnd, final HtmlElement htmlElement, + final boolean lastType) { initDoTypeProcessor(); if (startAtEnd) { selectionDelegate_.setSelectionStart(getData().length()); } - doTypeProcessor_.doType(getData(), selectionDelegate_, keyCode, htmlElement); + doTypeProcessor_.doType(getData(), selectionDelegate_, keyCode, htmlElement, lastType); } private void initDoTypeProcessor() { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButton.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButton.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButton.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -326,14 +326,15 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { if ("name".equals(qualifiedName)) { if (newNames_.isEmpty()) { newNames_ = new HashSet<>(); } newNames_.add(attributeValue); } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButtonInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButtonInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButtonInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -55,11 +55,12 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { if ("value".equals(qualifiedName)) { setDefaultValue(attributeValue, false); } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -226,14 +226,15 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { if ("value".equals(qualifiedName)) { setDefaultValue(attributeValue, false); } if ("checked".equals(qualifiedName)) { checkedState_ = true; } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -165,22 +165,15 @@ } /** - * Sets the value of the specified attribute. This method may be overridden by subclasses - * which are interested in specific attribute value changes, but such methods <b>must</b> - * invoke <tt>super.setAttributeValue()</tt>, and <b>should</b> consider the value of the - * <tt>cloning</tt> parameter when deciding whether or not to execute custom logic. - * - * @param namespaceURI the URI that identifies an XML namespace - * @param qualifiedName the qualified name of the attribute - * @param attributeValue the value of the attribute + * {@inheritDoc} */ @Override public void setAttributeNS(final String namespaceURI, final String qualifiedName, - final String attributeValue) { + final String attributeValue, final boolean notifyAttributeChangeListeners) { // TODO: Clean up; this is a hack for HtmlElement living within an XmlPage. if (null == getHtmlPageOrNull()) { - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); return; } @@ -200,10 +193,13 @@ else { event = new HtmlAttributeChangeEvent(this, qualifiedName, oldAttributeValue); } - notifyAttributeChangeListeners(event, this, oldAttributeValue); - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); + if (notifyAttributeChangeListeners) { + notifyAttributeChangeListeners(event, this, oldAttributeValue); + } + fireAttributeChangeImpl(event, htmlPage, mappedElement, qualifiedName, attributeValue, oldAttributeValue); } @@ -519,7 +515,7 @@ * @exception IOException if an IO error occurs */ public Page type(final char c) throws IOException { - return type(c, false); + return type(c, false, true); } /** @@ -530,10 +526,11 @@ * * @param c the character you wish to simulate typing * @param startAtEnd whether typing should start at the text end or not + * @param lastType is this the last character to type * @return the page contained in the current window as returned by {@link WebClient#getCurrentWindow()} * @exception IOException if an IO error occurs */ - private Page type(final char c, final boolean startAtEnd) + private Page type(final char c, final boolean startAtEnd, final boolean lastType) throws IOException { if (this instanceof DisabledElement && ((DisabledElement) this).isDisabled()) { return getPage(); @@ -571,7 +568,7 @@ if ((shiftDown == null || !shiftDown.isAborted(shiftDownResult)) && !keyPress.isAborted(keyPressResult)) { - doType(c, startAtEnd); + doType(c, startAtEnd, lastType); } } @@ -616,7 +613,7 @@ * @return the page that occupies this window after typing */ public Page type(final int keyCode) { - return type(keyCode, false, true, true, true); + return type(keyCode, false, true, true, true, true); } /** @@ -637,7 +634,7 @@ final Object[] entry = keys.get(i); final boolean startAtEnd = i == 0 && keyboard.isStartAtEnd(); if (entry.length == 1) { - type((char) entry[0], startAtEnd); + type((char) entry[0], startAtEnd, i == keys.size() - 1); } else { final int key = (int) entry[0]; @@ -670,10 +667,10 @@ default: } - page = type(key, startAtEnd, true, keyPress, keyUp); + page = type(key, startAtEnd, true, keyPress, keyUp, i == keys.size() - 1); } else { - page = type(key, startAtEnd, false, false, true); + page = type(key, startAtEnd, false, false, true, i == keys.size() - 1); } } } @@ -682,7 +679,8 @@ } private Page type(final int keyCode, final boolean startAtEnd, - final boolean fireKeyDown, final boolean fireKeyPress, final boolean fireKeyUp) { + final boolean fireKeyDown, final boolean fireKeyPress, final boolean fireKeyUp, + final boolean lastType) { if (this instanceof DisabledElement && ((DisabledElement) this).isDisabled()) { return getPage(); } @@ -720,7 +718,7 @@ if (keyDown != null && !keyDown.isAborted(keyDownResult) && (keyPress == null || !keyPress.isAborted(keyPressResult))) { - doType(keyCode, startAtEnd); + doType(keyCode, startAtEnd, lastType); } if (this instanceof HtmlTextInput @@ -756,15 +754,16 @@ * Performs the effective type action, called after the keyPress event and before the keyUp event. * @param c the character you with to simulate typing * @param startAtEnd whether typing should start at the text end or not + * @param lastType is this the last character to type */ - protected void doType(final char c, final boolean startAtEnd) { + protected void doType(final char c, final boolean startAtEnd, final boolean lastType) { final DomNode domNode = getDoTypeNode(); if (domNode instanceof DomText) { - ((DomText) domNode).doType(c, startAtEnd, this); + ((DomText) domNode).doType(c, startAtEnd, this, lastType); } else if (domNode instanceof HtmlElement) { try { - ((HtmlElement) domNode).type(c, startAtEnd); + ((HtmlElement) domNode).type(c, startAtEnd, lastType); } catch (final IOException e) { throw new RuntimeException(e); @@ -779,14 +778,15 @@ * * @param keyCode the key code wish to simulate typing * @param startAtEnd whether typing should start at the text end or not + * @param lastType is this the last to type */ - protected void doType(final int keyCode, final boolean startAtEnd) { + protected void doType(final int keyCode, final boolean startAtEnd, final boolean lastType) { final DomNode domNode = getDoTypeNode(); if (domNode instanceof DomText) { - ((DomText) domNode).doType(keyCode, startAtEnd, this); + ((DomText) domNode).doType(keyCode, startAtEnd, this, lastType); } else if (domNode instanceof HtmlElement) { - ((HtmlElement) domNode).type(keyCode, startAtEnd, true, true, true); + ((HtmlElement) domNode).type(keyCode, startAtEnd, true, true, true, lastType); } } @@ -822,8 +822,9 @@ /** * Called from {@link DoTypeProcessor}. * @param newValue the new value + * @param notifyAttributeChangeListeners to notify the associated {@link HtmlAttributeChangeListener}s */ - protected void typeDone(final String newValue) { + protected void typeDone(final String newValue, final boolean notifyAttributeChangeListeners) { // nothing } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -126,31 +126,31 @@ * {@inheritDoc} */ @Override - protected void doType(final char c, final boolean startAtEnd) { + protected void doType(final char c, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this, lastType); } /** * {@inheritDoc} */ @Override - protected void doType(final int keyCode, final boolean startAtEnd) { + protected void doType(final int keyCode, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this, lastType); } /** * {@inheritDoc} */ @Override - protected void typeDone(final String newValue) { + protected void typeDone(final String newValue, final boolean notifyAttributeChangeListeners) { if (newValue.length() <= getMaxLength()) { - setAttribute("value", newValue); + setAttributeNS(null, "value", newValue, notifyAttributeChangeListeners); } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlHiddenInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlHiddenInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlHiddenInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -48,11 +48,12 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { if ("value".equals(qualifiedName)) { setDefaultValue(attributeValue, false); } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -111,13 +111,14 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String value) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String value, + final boolean notifyAttributeChangeListeners) { final HtmlPage htmlPage = getHtmlPageOrNull(); if ("src".equals(qualifiedName) && value != ATTRIBUTE_NOT_DEFINED && htmlPage != null) { final String oldValue = getAttributeNS(namespaceURI, qualifiedName); if (!oldValue.equals(value)) { - super.setAttributeNS(namespaceURI, qualifiedName, value); + super.setAttributeNS(namespaceURI, qualifiedName, value, notifyAttributeChangeListeners); // onload handlers may need to be invoked again, and a new image may need to be downloaded onloadInvoked_ = false; @@ -139,7 +140,7 @@ } } - super.setAttributeNS(namespaceURI, qualifiedName, value); + super.setAttributeNS(namespaceURI, qualifiedName, value, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImageInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImageInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImageInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -166,11 +166,12 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { if ("value".equals(qualifiedName)) { setDefaultValue(attributeValue, false); } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -403,7 +403,7 @@ else { event = new HtmlAttributeChangeEvent(this, "value", defaultValue_); } - notifyAttributeChangeListeners(event, this, defaultValue_); +// notifyAttributeChangeListeners(event, this, defaultValue_); defaultValue_ = defaultValue; } } @@ -559,14 +559,15 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { if ("name".equals(qualifiedName)) { if (newNames_.isEmpty()) { newNames_ = new HashSet<>(); } newNames_.add(attributeValue); } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -50,31 +50,31 @@ * {@inheritDoc} */ @Override - protected void doType(final char c, final boolean startAtEnd) { + protected void doType(final char c, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this, lastType); } /** * {@inheritDoc} */ @Override - protected void doType(final int keyCode, final boolean startAtEnd) { + protected void doType(final int keyCode, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this, lastType); } /** * {@inheritDoc} */ @Override - protected void typeDone(final String newValue) { + protected void typeDone(final String newValue, final boolean notifyAttributeChangeListeners) { if (newValue.length() <= getMaxLength()) { - setAttribute("value", newValue); + setAttributeNS(null, "value", newValue, notifyAttributeChangeListeners); } } @@ -154,8 +154,9 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); if ("value".equals(qualifiedName)) { final SgmlPage page = getPage(); if (page != null && page.isHtmlPage()) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -127,31 +127,31 @@ * {@inheritDoc} */ @Override - protected void doType(final char c, final boolean startAtEnd) { + protected void doType(final char c, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this, lastType); } /** * {@inheritDoc} */ @Override - protected void doType(final int keyCode, final boolean startAtEnd) { + protected void doType(final int keyCode, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this, lastType); } /** * {@inheritDoc} */ @Override - protected void typeDone(final String newValue) { + protected void typeDone(final String newValue, final boolean notifyAttributeChangeListeners) { if (newValue.length() <= getMaxLength()) { - setAttribute("value", newValue); + setAttributeNS(null, "value", newValue, notifyAttributeChangeListeners); } } @@ -167,8 +167,9 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); if ("value".equals(qualifiedName)) { final SgmlPage page = getPage(); if (page != null && page.isHtmlPage()) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -307,14 +307,15 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { if ("value".equals(qualifiedName)) { setDefaultValue(attributeValue, false); } if ("checked".equals(qualifiedName)) { checkedState_ = true; } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlResetInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlResetInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlResetInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -115,11 +115,12 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { if ("value".equals(qualifiedName)) { setDefaultValue(attributeValue, false); } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlScript.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlScript.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlScript.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -180,15 +180,16 @@ * (behavior varies by browser version). {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { // special additional processing for the 'src' if (namespaceURI != null || !"src".equals(qualifiedName)) { - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); return; } final String oldValue = getAttributeNS(namespaceURI, qualifiedName); - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); if (isAttachedToPage()) { // if FF, only execute if the "src" attribute Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSelect.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSelect.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSelect.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -667,14 +667,15 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { if ("name".equals(qualifiedName)) { if (newNames_.isEmpty()) { newNames_ = new HashSet<>(); } newNames_.add(attributeValue); } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSubmitInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSubmitInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSubmitInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -152,11 +152,12 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { if ("value".equals(qualifiedName)) { setDefaultValue(attributeValue, false); } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -111,31 +111,31 @@ * {@inheritDoc} */ @Override - protected void doType(final char c, final boolean startAtEnd) { + protected void doType(final char c, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this, lastType); } /** * {@inheritDoc} */ @Override - protected void doType(final int keyCode, final boolean startAtEnd) { + protected void doType(final int keyCode, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this, lastType); } /** * {@inheritDoc} */ @Override - protected void typeDone(final String newValue) { + protected void typeDone(final String newValue, final boolean notifyAttributeChangeListeners) { if (newValue.length() <= getMaxLength()) { - setAttribute("value", newValue); + setAttributeNS(null, "value", newValue, notifyAttributeChangeListeners); } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -464,29 +464,29 @@ * {@inheritDoc} */ @Override - protected void doType(final char c, final boolean startAtEnd) { + protected void doType(final char c, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getText().length()); } - doTypeProcessor_.doType(getText(), selectionDelegate_, c, this); + doTypeProcessor_.doType(getText(), selectionDelegate_, c, this, lastType); } /** * {@inheritDoc} */ @Override - protected void doType(final int keyCode, final boolean startAtEnd) { + protected void doType(final int keyCode, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getText().length()); } - doTypeProcessor_.doType(getText(), selectionDelegate_, keyCode, this); + doTypeProcessor_.doType(getText(), selectionDelegate_, keyCode, this, lastType); } /** * {@inheritDoc} */ @Override - protected void typeDone(final String newValue) { + protected void typeDone(final String newValue, final boolean notifyAttributeChangeListeners) { setTextInternal(newValue); } @@ -553,14 +553,15 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { if ("name".equals(qualifiedName)) { if (newNames_.isEmpty()) { newNames_ = new HashSet<>(); } newNames_.add(attributeValue); } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -56,31 +56,31 @@ * {@inheritDoc} */ @Override - protected void doType(final char c, final boolean startAtEnd) { + protected void doType(final char c, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this, lastType); } /** * {@inheritDoc} */ @Override - protected void doType(final int keyCode, final boolean startAtEnd) { + protected void doType(final int keyCode, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this, lastType); } /** * {@inheritDoc} */ @Override - protected void typeDone(final String newValue) { + protected void typeDone(final String newValue, final boolean notifyAttributeChangeListeners) { if (newValue.length() <= getMaxLength()) { - setAttribute("value", newValue); + setAttributeNS(null, "value", newValue, notifyAttributeChangeListeners); } } @@ -160,8 +160,9 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); if ("value".equals(qualifiedName)) { final SgmlPage page = getPage(); if (page != null && page.isHtmlPage()) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -126,31 +126,31 @@ * {@inheritDoc} */ @Override - protected void doType(final char c, final boolean startAtEnd) { + protected void doType(final char c, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this, lastType); } /** * {@inheritDoc} */ @Override - protected void doType(final int keyCode, final boolean startAtEnd) { + protected void doType(final int keyCode, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this, lastType); } /** * {@inheritDoc} */ @Override - protected void typeDone(final String newValue) { + protected void typeDone(final String newValue, final boolean notifyAttributeChangeListeners) { if (newValue.length() <= getMaxLength()) { - setAttribute("value", newValue); + setAttributeNS(null, "value", newValue, notifyAttributeChangeListeners); } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/MutationObserver.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/MutationObserver.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/MutationObserver.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -103,6 +103,15 @@ } /** + * Empties the MutationObserver instance's record queue and returns what was in there. + * @return an Array of {@link MutationRecord}s + */ + @JsxFunction + public NativeArray takeRecords() { + return new NativeArray(0); + } + + /** * {@inheritDoc} */ @Override Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -901,7 +901,7 @@ || lineTrimmed.startsWith("if")) { final int difference = getInitialSpaces(next) - getInitialSpaces(line); if (difference > 2) { - addFailure("Too many spaces in " + relativePath + ", line: " + (i + 2)); + addFailure("Too many initial spaces in " + relativePath + ", line: " + (i + 2)); } else if (difference == 1) { addFailure("Add one more space in " + relativePath + ", line: " + (i + 2)); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/MutationObserverTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/MutationObserverTest.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/MutationObserverTest.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -195,14 +195,14 @@ */ @Test @Alerts("[object HTMLHeadingElement]-attributes") - public void test() throws Exception { + public void attributeValue2() throws Exception { final String html = "<html><head><script>\n" + " function makeRed() {\n" + " document.getElementById('headline').setAttribute('style', 'color: red');\n" + " }\n" + " function print(mutation) {\n" - + " alert(mutation.target + '-' + mutation.type);\n" + + " alert(mutation.target + '-' + mutation.type);\n" + " }\n" + " function test() {\n" @@ -227,7 +227,7 @@ + " <input id='id1' type='button' onclick='makeRed()' value='Make Red'>\n" + " </div>\n" + "</body></html>\n"; - WebDriver driver = loadPage2(html); + final WebDriver driver = loadPage2(html); driver.findElement(By.id("id1")).click(); verifyAlerts(driver, getExpectedAlerts()); |