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" where type is "button".
25 *
26 * @author Mike Bowler
27 * @author Christian Sell
28 * @author Daniel Gredler
29 * @author Ahmed Ashour
30 * @author Ronald Brill
31 * @author Frank Danek
32 */
33 public class HtmlButtonInput extends HtmlInput implements LabelableElement {
34
35 /**
36 * Creates an instance.
37 *
38 * @param qualifiedName the qualified name of the element type to instantiate
39 * @param page the page that contains this element
40 * @param attributes the initial attributes
41 */
42 HtmlButtonInput(final String qualifiedName, final SgmlPage page,
43 final Map<String, DomAttr> attributes) {
44 super(qualifiedName, page, attributes);
45 }
46
47 /**
48 * {@inheritDoc} This method <b>does nothing</b> for button input elements.
49 * @see SubmittableElement#reset()
50 */
51 @Override
52 public void reset() {
53 // Empty.
54 }
55
56 /**
57 * {@inheritDoc}
58 */
59 @Override
60 protected void doType(final int keyCode, final boolean lastType) throws IOException {
61 if (keyCode == KeyboardEvent.DOM_VK_SPACE) {
62 click();
63 return;
64 }
65
66 super.doType(keyCode, lastType);
67 }
68
69 /**
70 * {@inheritDoc}
71 */
72 @Override
73 public void setValue(final String newValue) {
74 unmarkValueDirty();
75 setDefaultValue(newValue);
76 }
77
78 /**
79 * {@inheritDoc}
80 */
81 @Override
82 public void setDefaultChecked(final boolean defaultChecked) {
83 // Empty.
84 }
85
86 /**
87 * {@inheritDoc}
88 */
89 @Override
90 protected boolean isRequiredSupported() {
91 return false;
92 }
93
94 /**
95 * {@inheritDoc}
96 */
97 @Override
98 public boolean willValidate() {
99 return false;
100 }
101
102 /**
103 * {@inheritDoc}
104 */
105 @Override
106 protected boolean isCustomValidityValid() {
107 return true;
108 }
109
110 }