Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions src/main/java/org/htmlunit/html/FormFieldWithNameHistory.java

This file was deleted.

41 changes: 1 addition & 40 deletions src/main/java/org/htmlunit/html/HtmlButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
import static org.htmlunit.html.HtmlForm.ATTRIBUTE_FORMNOVALIDATE;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;

import org.apache.commons.logging.Log;
Expand All @@ -47,7 +44,7 @@
* @author Sven Strickroth
*/
public class HtmlButton extends HtmlElement implements DisabledElement, SubmittableElement,
LabelableElement, FormFieldWithNameHistory, ValidatableElement {
LabelableElement, ValidatableElement {

private static final Log LOG = LogFactory.getLog(HtmlButton.class);

Expand All @@ -58,8 +55,6 @@ public class HtmlButton extends HtmlElement implements DisabledElement, Submitta
private static final String TYPE_RESET = "reset";
private static final String TYPE_BUTTON = "button";

private final String originalName_;
private Collection<String> newNames_ = Collections.emptySet();
private String customValidity_;

/**
Expand All @@ -72,7 +67,6 @@ public class HtmlButton extends HtmlElement implements DisabledElement, Submitta
HtmlButton(final String qualifiedName, final SgmlPage page,
final Map<String, DomAttr> attributes) {
super(qualifiedName, page, attributes);
originalName_ = getNameAttribute();
}

/**
Expand Down Expand Up @@ -324,39 +318,6 @@ public final String getOnBlurAttribute() {
return getAttributeDirect("onblur");
}

/**
* {@inheritDoc}
*/
@Override
protected void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue,
final boolean notifyAttributeChangeListeners, final boolean notifyMutationObservers) {
final String qualifiedNameLC = StringUtils.toRootLowerCase(qualifiedName);
if (NAME_ATTRIBUTE.equals(qualifiedNameLC)) {
if (newNames_.isEmpty()) {
newNames_ = new HashSet<>();
}
newNames_.add(attributeValue);
}
super.setAttributeNS(namespaceURI, qualifiedNameLC, attributeValue, notifyAttributeChangeListeners,
notifyMutationObservers);
}

/**
* {@inheritDoc}
*/
@Override
public String getOriginalName() {
return originalName_;
}

/**
* {@inheritDoc}
*/
@Override
public Collection<String> getNewNames() {
return newNames_;
}

/**
* {@inheritDoc}
*/
Expand Down
41 changes: 1 addition & 40 deletions src/main/java/org/htmlunit/html/HtmlFieldSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
*/
package org.htmlunit.html;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;

import org.htmlunit.SgmlPage;
Expand All @@ -32,13 +29,11 @@
* @author Frank Danek
* @author Ronald Brill
*/
public class HtmlFieldSet extends HtmlElement implements DisabledElement, ValidatableElement, FormFieldWithNameHistory {
public class HtmlFieldSet extends HtmlElement implements DisabledElement, ValidatableElement {

/** The HTML tag represented by this element. */
public static final String TAG_NAME = "fieldset";

private final String originalName_;
private Collection<String> newNames_ = Collections.emptySet();
private String customValidity_;

/**
Expand All @@ -51,7 +46,6 @@ public class HtmlFieldSet extends HtmlElement implements DisabledElement, Valida
HtmlFieldSet(final String qualifiedName, final SgmlPage page,
final Map<String, DomAttr> attributes) {
super(qualifiedName, page, attributes);
originalName_ = getAttributeDirect(NAME_ATTRIBUTE);
}

/**
Expand Down Expand Up @@ -91,39 +85,6 @@ public boolean isValidValidityState() {
return !isCustomErrorValidityState();
}

/**
* {@inheritDoc}
*/
@Override
protected void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue,
final boolean notifyAttributeChangeListeners, final boolean notifyMutationObservers) {
final String qualifiedNameLC = StringUtils.toRootLowerCase(qualifiedName);
if (NAME_ATTRIBUTE.equals(qualifiedNameLC)) {
if (newNames_.isEmpty()) {
newNames_ = new HashSet<>();
}
newNames_.add(attributeValue);
}
super.setAttributeNS(namespaceURI, qualifiedNameLC, attributeValue, notifyAttributeChangeListeners,
notifyMutationObservers);
}

/**
* {@inheritDoc}
*/
@Override
public String getOriginalName() {
return originalName_;
}

/**
* {@inheritDoc}
*/
@Override
public Collection<String> getNewNames() {
return newNames_;
}

/**
* {@inheritDoc}
*/
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/org/htmlunit/html/HtmlForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -92,6 +93,13 @@ public class HtmlForm extends HtmlElement {

private boolean isPreventDefault_;

/**
* A map that holds past names (name or id attribute) to elements belonging to this form.
* @see <a href="https://html.spec.whatwg.org/multipage/forms.html#the-form-element:the-form-element-10">
* HTML spec - past names map</a>
*/
private Map<String, HtmlElement> pastNamesMap_;

/**
* Creates an instance.
*
Expand Down Expand Up @@ -1005,4 +1013,34 @@ public final void setNoValidate(final boolean noValidate) {
removeAttribute(ATTRIBUTE_NOVALIDATE);
}
}

/**
* Register an element to the past names map with the specified name.
* @param name name or id attribute of the element
* @param element the element to register
*/
public void registerPastName(final String name, final HtmlElement element) {
if (pastNamesMap_ == null) {
pastNamesMap_ = new HashMap<>();
}
pastNamesMap_.put(name, element);
}

/**
* Return the element registered in the past names map with the specified name.
* If the element is no longer owned by this form, the entry is removed and null is returned.
* @param name name or id attribute of the element
* @return the element, or null if not found or no longer owned by this form
*/
public HtmlElement getNamedElement(final String name) {
if (pastNamesMap_ == null) {
return null;
}
final HtmlElement element = pastNamesMap_.get(name);
if (element != null && element.getEnclosingForm() != this) {
pastNamesMap_.remove(name);
return null;
}
return element;
}
}
41 changes: 1 addition & 40 deletions src/main/java/org/htmlunit/html/HtmlInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
import static org.htmlunit.html.HtmlForm.ATTRIBUTE_FORMNOVALIDATE;

import java.net.MalformedURLException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;

Expand Down Expand Up @@ -61,7 +58,7 @@
* @author Ronny Shapiro
*/
public abstract class HtmlInput extends HtmlElement implements DisabledElement, SubmittableElement,
FormFieldWithNameHistory, ValidatableElement {
ValidatableElement {

private static final Log LOG = LogFactory.getLog(HtmlInput.class);

Expand All @@ -70,8 +67,6 @@ public abstract class HtmlInput extends HtmlElement implements DisabledElement,

private String rawValue_;
private boolean isValueDirty_;
private final String originalName_;
private Collection<String> newNames_ = Collections.emptySet();
private boolean valueModifiedByJavascript_;
private Object valueAtFocus_;
private String customValidity_;
Expand All @@ -97,7 +92,6 @@ public HtmlInput(final String qualifiedName, final SgmlPage page,
final Map<String, DomAttr> attributes) {
super(qualifiedName, page, attributes);
rawValue_ = getValueAttribute();
originalName_ = getNameAttribute();
}

/**
Expand Down Expand Up @@ -633,12 +627,6 @@ static Page executeOnChangeHandlerIfAppropriate(final HtmlElement htmlElement) {
protected void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue,
final boolean notifyAttributeChangeListeners, final boolean notifyMutationObservers) {
final String qualifiedNameLC = StringUtils.toRootLowerCase(qualifiedName);
if (NAME_ATTRIBUTE.equals(qualifiedNameLC)) {
if (newNames_.isEmpty()) {
newNames_ = new HashSet<>();
}
newNames_.add(attributeValue);
}

if (TYPE_ATTRIBUTE.equals(qualifiedNameLC)) {
changeType(attributeValue, true);
Expand All @@ -657,22 +645,6 @@ protected void setAttributeNS(final String namespaceURI, final String qualifiedN
notifyMutationObservers);
}

/**
* {@inheritDoc}
*/
@Override
public String getOriginalName() {
return originalName_;
}

/**
* {@inheritDoc}
*/
@Override
public Collection<String> getNewNames() {
return newNames_;
}

/**
* <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
*
Expand Down Expand Up @@ -940,17 +912,6 @@ protected boolean isMinMaxLengthSupported() {
return false;
}

/**
* {@inheritDoc}
*/
@Override
public DomNode cloneNode(final boolean deep) {
final HtmlInput newnode = (HtmlInput) super.cloneNode(deep);
newnode.newNames_ = new HashSet<>(newNames_);

return newnode;
}

/**
* Returns if the input element has a maximum allowed value length. Refer to the
* <a href="https://www.w3.org/TR/html5/sec-forms.html">HTML 5</a>
Expand Down
Loading
Loading