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.javascript.host.html;
16  
17  import org.htmlunit.html.DomElement;
18  import org.htmlunit.html.HtmlForm;
19  import org.htmlunit.html.HtmlObject;
20  import org.htmlunit.javascript.configuration.JsxClass;
21  import org.htmlunit.javascript.configuration.JsxConstructor;
22  import org.htmlunit.javascript.configuration.JsxFunction;
23  import org.htmlunit.javascript.configuration.JsxGetter;
24  import org.htmlunit.javascript.configuration.JsxSetter;
25  
26  /**
27   * The JavaScript object {@code HTMLObjectElement}.
28   *
29   * @author Ahmed Ashour
30   * @author Ronald Brill
31   * @author Frank Danek
32   *
33   * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement">MDN Documentation</a>
34   */
35  @JsxClass(domClass = HtmlObject.class)
36  public class HTMLObjectElement extends HTMLElement {
37  
38      /**
39       * JavaScript constructor.
40       */
41      @Override
42      @JsxConstructor
43      public void jsConstructor() {
44          super.jsConstructor();
45      }
46  
47      /**
48       * Gets the {@code border} attribute.
49       * @return the {@code border} attribute
50       */
51      @JsxGetter
52      public String getBorder() {
53          return getDomNodeOrDie().getAttributeDirect("border");
54      }
55  
56      /**
57       * Sets the {@code border} attribute.
58       * @param border the {@code border} attribute value
59       */
60      @JsxSetter
61      public void setBorder(final String border) {
62          getDomNodeOrDie().setAttribute("border", border);
63      }
64  
65      /**
66       * Gets the {@code classid} attribute.
67       * @return the {@code classid} attribute
68       */
69      public String getClassid() {
70          return getDomNodeOrDie().getAttributeDirect("classid");
71      }
72  
73      /**
74       * Sets the {@code classid} attribute.
75       * @param classid the {@code classid} attribute value
76       */
77      public void setClassid(final String classid) {
78          getDomNodeOrDie().setAttribute("classid", classid);
79      }
80  
81      /**
82       * Returns the value of the {@code width} property.
83       * @return the value of the {@code width} property
84       */
85      @JsxGetter(propertyName = "width")
86      public String getWidth_js() {
87          return getWidthOrHeight("width", Boolean.TRUE);
88      }
89  
90      /**
91       * Sets the value of the {@code width} property.
92       * @param width the value of the {@code width} property
93       */
94      @JsxSetter(propertyName = "width")
95      public void setWidth_js(final String width) {
96          setWidthOrHeight("width", width, true);
97      }
98  
99      /**
100      * Returns the value of the {@code height} property.
101      * @return the value of the {@code height} property
102      */
103     @JsxGetter(propertyName = "height")
104     public String getHeight_js() {
105         return getWidthOrHeight("height", Boolean.TRUE);
106     }
107 
108     /**
109      * Sets the value of the {@code height} property.
110      * @param height the value of the {@code height} property
111      */
112     @JsxSetter(propertyName = "height")
113     public void setHeight_js(final String height) {
114         setWidthOrHeight("height", height, true);
115     }
116 
117     /**
118      * Returns the value of the {@code align} property.
119      * @return the value of the {@code align} property
120      */
121     @JsxGetter
122     public String getAlign() {
123         return getAlign(true);
124     }
125 
126     /**
127      * Sets the value of the {@code align} property.
128      * @param align the value of the {@code align} property
129      */
130     @JsxSetter
131     public void setAlign(final String align) {
132         setAlign(align, false);
133     }
134 
135     /**
136      * Returns the {@code name} attribute.
137      * @return the {@code name} attribute
138      */
139     @JsxGetter
140     @Override
141     public String getName() {
142         return getDomNodeOrDie().getAttributeDirect(DomElement.NAME_ATTRIBUTE);
143     }
144 
145     /**
146      * Sets the {@code name} attribute.
147      * @param name the {@code name} attribute
148      */
149     @JsxSetter
150     @Override
151     public void setName(final String name) {
152         getDomNodeOrDie().setAttribute(DomElement.NAME_ATTRIBUTE, name);
153     }
154 
155     /**
156      * Returns the value of the JavaScript {@code form} attribute.
157      *
158      * @return the value of the JavaScript {@code form} attribute
159      */
160     @JsxGetter
161     @Override
162     public HTMLFormElement getForm() {
163         final HtmlForm form = getDomNodeOrDie().getEnclosingForm();
164         if (form == null) {
165             return null;
166         }
167         return (HTMLFormElement) getScriptableFor(form);
168     }
169 
170     /**
171      * Checks whether the element has any constraints and whether it satisfies them.
172      * @return {@code true} if the element is valid
173      */
174     @JsxFunction
175     public boolean checkValidity() {
176         return getDomNodeOrDie().isValid();
177     }
178 
179     /**
180      * Returns a {@link ValidityState} object representing the validity states of this element.
181      * @return a {@link ValidityState} object representing the validity states of this element
182      */
183     @JsxGetter
184     public ValidityState getValidity() {
185         final ValidityState validityState = new ValidityState();
186         validityState.setPrototype(getPrototype(validityState.getClass()));
187         validityState.setParentScope(getParentScope());
188         validityState.setDomNode(getDomNodeOrDie());
189         return validityState;
190     }
191 
192     /**
193      * Returns whether the element is a candidate for constraint validation.
194      * @return whether the element is a candidate for constraint validation
195      */
196     @JsxGetter
197     public boolean isWillValidate() {
198         return ((HtmlObject) getDomNodeOrDie()).willValidate();
199     }
200 
201     /**
202      * Sets the custom validity message for the element to the specified message.
203      * @param message the new message
204      */
205     @JsxFunction
206     public void setCustomValidity(final String message) {
207         ((HtmlObject) getDomNodeOrDie()).setCustomValidity(message);
208     }
209 }