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