Skip to content

Commit d4b001d

Browse files
committed
DisabledElement now implements Element and provides a default implementation of isDisable()
1 parent bbf5c94 commit d4b001d

9 files changed

Lines changed: 31 additions & 163 deletions

File tree

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
<body>
1010
<release version="5.4.0" date="August xx, 2026" description="Firefox 153, Bugfixes">
11+
<action type="update" dev="rbri">
12+
DisabledElement now implements Element and provides a default implementation of isDisabled().
13+
</action>
1114
<action type="fix" dev="rbri">
1215
Fixed HtmlTextArea.reset(): the text entry cursor/selection is now only moved to the end of the restored
1316
value when that value actually differs from the current one, instead of always being forced to the end.

src/main/java/org/htmlunit/html/DisabledElement.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414
*/
1515
package org.htmlunit.html;
1616

17+
import org.w3c.dom.Element;
18+
import org.w3c.dom.Node;
19+
1720
/**
1821
* A marker interface for those classes that can be disabled.
1922
*
2023
* @author David D. Kilzer
2124
* @author Ronald Brill
2225
*/
23-
public interface DisabledElement {
26+
public interface DisabledElement extends Element {
2427

2528
/** The "disabled" attribute name. */
2629
String ATTRIBUTE_DISABLED = "disabled";
@@ -29,7 +32,22 @@ public interface DisabledElement {
2932
* Returns {@code true} if the disabled attribute is set for this element.
3033
* @return {@code true} if the disabled attribute is set for this element
3134
*/
32-
boolean isDisabled();
35+
default boolean isDisabled() {
36+
if (hasAttribute(ATTRIBUTE_DISABLED)) {
37+
return true;
38+
}
39+
40+
Node node = getParentNode();
41+
while (node != null) {
42+
if (node instanceof DisabledElement element
43+
&& element.isDisabled()) {
44+
return true;
45+
}
46+
node = node.getParentNode();
47+
}
48+
49+
return false;
50+
}
3351

3452
/**
3553
* Returns the value of the attribute {@code disabled}. Refer to the

src/main/java/org/htmlunit/html/HtmlButton.java

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.htmlunit.javascript.host.event.MouseEvent;
2727
import org.htmlunit.util.NameValuePair;
2828
import org.htmlunit.util.StringUtils;
29-
import org.w3c.dom.Node;
3029

3130
/**
3231
* Wrapper for the HTML element "button".
@@ -105,27 +104,6 @@ protected boolean doClickStateUpdate(final boolean shiftKey, final boolean ctrlK
105104
return false;
106105
}
107106

108-
/**
109-
* {@inheritDoc}
110-
*/
111-
@Override
112-
public final boolean isDisabled() {
113-
if (hasAttribute(ATTRIBUTE_DISABLED)) {
114-
return true;
115-
}
116-
117-
Node node = getParentNode();
118-
while (node != null) {
119-
if (node instanceof DisabledElement element
120-
&& element.isDisabled()) {
121-
return true;
122-
}
123-
node = node.getParentNode();
124-
}
125-
126-
return false;
127-
}
128-
129107
/**
130108
* Returns {@code true} if this element is read only.
131109
* @return {@code true} if this element is read only
@@ -245,7 +223,7 @@ public final String getValueAttribute() {
245223
* @return the value of the attribute {@code type} or the default value if that attribute isn't defined
246224
*/
247225
public final String getTypeAttribute() {
248-
return getAttribute(TYPE_ATTRIBUTE);
226+
return getAttributeDirect(TYPE_ATTRIBUTE);
249227
}
250228

251229
/**

src/main/java/org/htmlunit/html/HtmlFieldSet.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,25 +93,4 @@ public boolean isValidValidityState() {
9393
public final String getDisabledAttribute() {
9494
return getAttributeDirect(ATTRIBUTE_DISABLED);
9595
}
96-
97-
/**
98-
* {@inheritDoc}
99-
*/
100-
@Override
101-
public final boolean isDisabled() {
102-
if (hasAttribute(ATTRIBUTE_DISABLED)) {
103-
return true;
104-
}
105-
106-
DomNode node = getParentNode();
107-
while (node != null) {
108-
if (node instanceof DisabledElement element
109-
&& element.isDisabled()) {
110-
return true;
111-
}
112-
node = node.getParentNode();
113-
}
114-
115-
return false;
116-
}
11796
}

src/main/java/org/htmlunit/html/HtmlInput.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -206,27 +206,6 @@ public final String getDisabledAttribute() {
206206
return getAttributeDirect(ATTRIBUTE_DISABLED);
207207
}
208208

209-
/**
210-
* {@inheritDoc}
211-
*/
212-
@Override
213-
public final boolean isDisabled() {
214-
if (hasAttribute(ATTRIBUTE_DISABLED)) {
215-
return true;
216-
}
217-
218-
DomNode node = getParentNode();
219-
while (node != null) {
220-
if (node instanceof DisabledElement element
221-
&& element.isDisabled()) {
222-
return true;
223-
}
224-
node = node.getParentNode();
225-
}
226-
227-
return false;
228-
}
229-
230209
/**
231210
* Returns the value of the attribute {@code readonly}. Refer to the
232211
* <a href="http://www.w3.org/TR/html401/">HTML 4.01</a>
@@ -994,7 +973,12 @@ private boolean isPatternValid() {
994973
}
995974

996975
try (Context cx = HtmlUnitContextFactory.getGlobal().enterContext()) {
976+
// compile the raw pattern first: this is a validity check only (result discarded).
977+
// Wrapping with "^(?:...)$ " cannot mask a genuinely invalid pattern -- the wrapper
978+
// contributes a balanced open/close pair, so any unmatched parent/bracket or other
979+
// structural defect in the raw pattern persists identically once wrapped.
997980
RegExpEngineAccess.compile(cx, pattern, "");
981+
998982
final RegExpEngineAccess.CompiledRegExp compiled
999983
= RegExpEngineAccess.compile(cx, "^(?:" + pattern + ")$", "");
1000984

src/main/java/org/htmlunit/html/HtmlOption.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.htmlunit.html.serializer.HtmlSerializerNormalizedText;
2424
import org.htmlunit.javascript.host.event.Event;
2525
import org.htmlunit.javascript.host.event.MouseEvent;
26-
import org.w3c.dom.Node;
2726

2827
/**
2928
* Wrapper for the HTML element "option".
@@ -167,31 +166,6 @@ public final boolean isDefaultSelected() {
167166
return hasAttribute("selected");
168167
}
169168

170-
/**
171-
* Returns whether this element is disabled.
172-
*
173-
* @return {@code true} if this element is disabled, either because it has
174-
* the {@code disabled} attribute or because it is contained in a
175-
* disabled ancestor element
176-
*/
177-
@Override
178-
public final boolean isDisabled() {
179-
if (hasAttribute(ATTRIBUTE_DISABLED)) {
180-
return true;
181-
}
182-
183-
Node node = getParentNode();
184-
while (node != null) {
185-
if (node instanceof DisabledElement element
186-
&& element.isDisabled()) {
187-
return true;
188-
}
189-
node = node.getParentNode();
190-
}
191-
192-
return false;
193-
}
194-
195169
/**
196170
* {@inheritDoc}
197171
*/

src/main/java/org/htmlunit/html/HtmlOptionGroup.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import java.util.Map;
1818

1919
import org.htmlunit.SgmlPage;
20-
import org.w3c.dom.Node;
2120

2221
/**
2322
* Wrapper for the HTML element "optgroup".
@@ -48,31 +47,6 @@ public class HtmlOptionGroup extends HtmlElement implements DisabledElement {
4847
super(qualifiedName, page, attributes);
4948
}
5049

51-
/**
52-
* Returns whether this element is disabled.
53-
*
54-
* @return {@code true} if this element is disabled, either because it has
55-
* the {@code disabled} attribute or because one of its ancestor
56-
* elements is disabled
57-
*/
58-
@Override
59-
public final boolean isDisabled() {
60-
if (hasAttribute(ATTRIBUTE_DISABLED)) {
61-
return true;
62-
}
63-
64-
Node node = getParentNode();
65-
while (node != null) {
66-
if (node instanceof DisabledElement element
67-
&& element.isDisabled()) {
68-
return true;
69-
}
70-
node = node.getParentNode();
71-
}
72-
73-
return false;
74-
}
75-
7650
/**
7751
* {@inheritDoc}
7852
*/

src/main/java/org/htmlunit/html/HtmlSelect.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -594,27 +594,6 @@ public final String getDisabledAttribute() {
594594
return getAttributeDirect(ATTRIBUTE_DISABLED);
595595
}
596596

597-
/**
598-
* {@inheritDoc}
599-
*/
600-
@Override
601-
public final boolean isDisabled() {
602-
if (hasAttribute(ATTRIBUTE_DISABLED)) {
603-
return true;
604-
}
605-
606-
Node node = getParentNode();
607-
while (node != null) {
608-
if (node instanceof DisabledElement element
609-
&& element.isDisabled()) {
610-
return true;
611-
}
612-
node = node.getParentNode();
613-
}
614-
615-
return false;
616-
}
617-
618597
/**
619598
* Returns the value of the attribute {@code tabindex}. Refer to the <a
620599
* href="http://www.w3.org/TR/html401/">HTML 4.01</a> documentation for details on the use of this attribute.

src/main/java/org/htmlunit/html/HtmlTextArea.java

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.htmlunit.javascript.host.event.MouseEvent;
2525
import org.htmlunit.util.NameValuePair;
2626
import org.htmlunit.util.StringUtils;
27-
import org.w3c.dom.Node;
2827

2928
/**
3029
* Wrapper for the HTML element "textarea".
@@ -289,7 +288,8 @@ public String getDefaultValue() {
289288
}
290289

291290
/**
292-
* {@inheritDoc} This implementation is empty; only checkboxes and radio buttons
291+
* {@inheritDoc}
292+
* This implementation is empty; only check boxes and radio buttons
293293
* really care what the default checked value is.
294294
* @see SubmittableElement#setDefaultChecked(boolean)
295295
* @see HtmlRadioButtonInput#setDefaultChecked(boolean)
@@ -345,27 +345,6 @@ public final String getColumnsAttribute() {
345345
return getAttributeDirect("cols");
346346
}
347347

348-
/**
349-
* {@inheritDoc}
350-
*/
351-
@Override
352-
public final boolean isDisabled() {
353-
if (hasAttribute(ATTRIBUTE_DISABLED)) {
354-
return true;
355-
}
356-
357-
Node node = getParentNode();
358-
while (node != null) {
359-
if (node instanceof DisabledElement element
360-
&& element.isDisabled()) {
361-
return true;
362-
}
363-
node = node.getParentNode();
364-
}
365-
366-
return false;
367-
}
368-
369348
/**
370349
* {@inheritDoc}
371350
*/

0 commit comments

Comments
 (0)