View Javadoc
1   /*
2    * Copyright (c) 2002-2026 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  import org.htmlunit.javascript.host.event.KeyboardEvent;
22  
23  /**
24   * Wrapper for the HTML element "input".
25   *
26   * @author Mike Bowler
27   * @author David K. Taylor
28   * @author Christian Sell
29   * @author Daniel Gredler
30   * @author Ahmed Ashour
31   * @author Ronald Brill
32   * @author Frank Danek
33   */
34  public class HtmlResetInput extends HtmlInput implements LabelableElement {
35  
36      /**
37       * Value to use if no specified <code>value</code> attribute.
38       */
39      public static final String DEFAULT_VALUE = "Reset";
40  
41      /**
42       * Creates an instance.
43       *
44       * @param qualifiedName the qualified name of the element type to instantiate
45       * @param page the page that contains this element
46       * @param attributes the initial attributes
47       */
48      HtmlResetInput(final String qualifiedName, final SgmlPage page,
49              final Map<String, DomAttr> attributes) {
50          super(qualifiedName, page, attributes);
51      }
52  
53      /**
54       * {@inheritDoc}
55       */
56      @Override
57      protected void doType(final int keyCode, final boolean lastType) throws IOException {
58          if (keyCode == KeyboardEvent.DOM_VK_SPACE) {
59              click();
60              return;
61          }
62  
63          super.doType(keyCode, lastType);
64      }
65  
66      /**
67       * {@inheritDoc}
68       */
69      @Override
70      protected boolean doClickStateUpdate(final boolean shiftKey, final boolean ctrlKey) throws IOException {
71          if (!isDisabled()) {
72              final HtmlForm form = getEnclosingForm();
73              if (form != null) {
74                  form.reset();
75                  return false;
76              }
77          }
78          super.doClickStateUpdate(shiftKey, ctrlKey);
79          return false;
80      }
81  
82      /**
83       * {@inheritDoc}
84       */
85      @Override
86      public void setValue(final String newValue) {
87          unmarkValueDirty();
88          setDefaultValue(newValue);
89      }
90  
91      /**
92       * {@inheritDoc}
93       */
94      @Override
95      public void setDefaultChecked(final boolean defaultChecked) {
96          // Empty.
97      }
98  
99      /**
100      * {@inheritDoc} This method <b>does nothing</b> for reset input elements.
101      * @see SubmittableElement#reset()
102      */
103     @Override
104     public void reset() {
105         // Empty.
106     }
107 
108     /**
109      * {@inheritDoc}
110      */
111     @Override
112     protected boolean isRequiredSupported() {
113         return false;
114     }
115 
116     /**
117      * {@inheritDoc}
118      */
119     @Override
120     public boolean willValidate() {
121         return false;
122     }
123 
124     /**
125      * {@inheritDoc}
126      */
127     @Override
128     protected boolean isCustomValidityValid() {
129         return true;
130     }
131 }