1 /*
2 * Copyright (c) 2002-2025 Gargoyle Software Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 package org.htmlunit.html;
16
17 import java.io.IOException;
18 import java.util.Map;
19
20 import org.htmlunit.SgmlPage;
21
22 /**
23 * Wrapper for the HTML element "input".
24 *
25 * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
26 * @author David K. Taylor
27 * @author <a href="mailto:cse@dynabean.de">Christian Sell</a>
28 * @author Daniel Gredler
29 * @author Ahmed Ashour
30 * @author Ronald Brill
31 * @author Frank Danek
32 */
33 public class HtmlResetInput extends HtmlInput implements LabelableElement {
34
35 /**
36 * Value to use if no specified <code>value</code> attribute.
37 */
38 public static final String DEFAULT_VALUE = "Reset";
39
40 /**
41 * Creates an instance.
42 *
43 * @param qualifiedName the qualified name of the element type to instantiate
44 * @param page the page that contains this element
45 * @param attributes the initial attributes
46 */
47 HtmlResetInput(final String qualifiedName, final SgmlPage page,
48 final Map<String, DomAttr> attributes) {
49 super(qualifiedName, page, attributes);
50 }
51
52 /**
53 * {@inheritDoc}
54 */
55 @Override
56 protected boolean doClickStateUpdate(final boolean shiftKey, final boolean ctrlKey) throws IOException {
57 if (!isDisabled()) {
58 final HtmlForm form = getEnclosingForm();
59 if (form != null) {
60 form.reset();
61 return false;
62 }
63 }
64 super.doClickStateUpdate(shiftKey, ctrlKey);
65 return false;
66 }
67
68 /**
69 * {@inheritDoc}
70 */
71 @Override
72 public void setValue(final String newValue) {
73 unmarkValueDirty();
74 setDefaultValue(newValue);
75 }
76
77 /**
78 * {@inheritDoc}
79 */
80 @Override
81 public void setDefaultChecked(final boolean defaultChecked) {
82 // Empty.
83 }
84
85 /**
86 * {@inheritDoc} This method <b>does nothing</b> for reset input elements.
87 * @see SubmittableElement#reset()
88 */
89 @Override
90 public void reset() {
91 // Empty.
92 }
93
94 /**
95 * {@inheritDoc}
96 */
97 @Override
98 protected boolean isRequiredSupported() {
99 return false;
100 }
101
102 /**
103 * {@inheritDoc}
104 */
105 @Override
106 public boolean willValidate() {
107 return false;
108 }
109 }