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.event;
16  
17  import org.htmlunit.corejs.javascript.ScriptableObject;
18  import org.htmlunit.html.DomNode;
19  import org.htmlunit.javascript.JavaScriptEngine;
20  import org.htmlunit.javascript.configuration.JsxClass;
21  import org.htmlunit.javascript.configuration.JsxConstructor;
22  import org.htmlunit.javascript.configuration.JsxGetter;
23  import org.htmlunit.javascript.host.html.HTMLElement;
24  
25  /**
26   * A JavaScript object for {@code SubmitEvent}.
27   *
28   * @author Ronald Brill
29   */
30  @JsxClass
31  public class SubmitEvent extends Event {
32  
33      private HTMLElement submitter_;
34  
35      /**
36       * Default constructor.
37       */
38      public SubmitEvent() {
39          super();
40      }
41  
42      /**
43       * Ctor.
44       * @param domNode the DOM node that triggered the event
45       * @param submitElement the element that has triggerd this event
46       *
47       */
48      public SubmitEvent(final DomNode domNode, final HTMLElement submitElement) {
49          super(domNode, Event.TYPE_SUBMIT);
50          submitter_ = submitElement;
51      }
52  
53      /**
54       * JavaScript constructor.
55       *
56       * @param type the event type
57       * @param details the event details (optional)
58       */
59      @Override
60      @JsxConstructor
61      public void jsConstructor(final String type, final ScriptableObject details) {
62          super.jsConstructor(type, details);
63  
64          if (details != null && !JavaScriptEngine.isUndefined(details)) {
65              final Object submitter = details.get("submitter");
66              if (submitter instanceof HTMLElement) {
67                  submitter_ = (HTMLElement) submitter;
68              }
69          }
70      }
71  
72      /**
73       * @return the submitter
74       */
75      @JsxGetter
76      public HTMLElement getSubmitter() {
77          return submitter_;
78      }
79  }