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