Skip to content

Commit deb9d24

Browse files
committed
SubmitEvent support added
1 parent b104422 commit deb9d24

File tree

8 files changed

+391
-9
lines changed

8 files changed

+391
-9
lines changed

src/changes/changes.xml

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
<body>
1010
<release version="3.2.0" date="Mai xx, 2023" description="Chrome/Edge 112, Firefox 112, Bugfixes">
11+
<action type="add" dev="rbri">
12+
SubmitEvent support added.
13+
</action>
1114
<action type="update" dev="rbri">
1215
Avoid usage of org.w3c.dom.ranges.Range - this is not available on android.
1316
</action>

src/main/java/org/htmlunit/WebConsole.java

+5
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ public Logger getLogger() {
156156
public void print(final Context cx, final Scriptable scope, final Level level,
157157
final Object[] args, final ScriptStackElement[] stack) {
158158

159+
final String log = format(cx, scope, args);
160+
if (log.startsWith("##")) {
161+
System.out.println(log);
162+
}
163+
159164
switch (level) {
160165
case TRACE:
161166
if (logger_.isInfoEnabled()) {

src/main/java/org/htmlunit/html/HtmlForm.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.htmlunit.WebWindow;
5757
import org.htmlunit.httpclient.HttpClientConverter;
5858
import org.htmlunit.javascript.host.event.Event;
59+
import org.htmlunit.javascript.host.event.SubmitEvent;
5960
import org.htmlunit.protocol.javascript.JavaScriptURLConnection;
6061
import org.htmlunit.util.EncodingSniffer;
6162
import org.htmlunit.util.NameValuePair;
@@ -152,8 +153,8 @@ && getAttributeDirect(ATTRIBUTE_NOVALIDATE) != ATTRIBUTE_NOT_DEFINED) {
152153
if (validate && !areChildrenValid()) {
153154
return;
154155
}
155-
156-
final ScriptResult scriptResult = fireEvent(Event.TYPE_SUBMIT);
156+
final ScriptResult scriptResult = fireEvent(new SubmitEvent(this,
157+
((HtmlElement) submitElement).getScriptableObject()));
157158
if (isPreventDefault_) {
158159
// null means 'nothing executed'
159160
if (scriptResult == null) {

src/main/java/org/htmlunit/javascript/configuration/JavaScriptConfiguration.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@
231231
import org.htmlunit.javascript.host.event.SecurityPolicyViolationEvent;
232232
import org.htmlunit.javascript.host.event.SpeechSynthesisEvent;
233233
import org.htmlunit.javascript.host.event.StorageEvent;
234+
import org.htmlunit.javascript.host.event.SubmitEvent;
234235
import org.htmlunit.javascript.host.event.TextEvent;
235236
import org.htmlunit.javascript.host.event.TimeEvent;
236237
import org.htmlunit.javascript.host.event.TouchEvent;
@@ -610,7 +611,7 @@ public final class JavaScriptConfiguration extends AbstractJavaScriptConfigurati
610611
SpeechSynthesis.class, SpeechSynthesisErrorEvent.class, SpeechSynthesisEvent.class,
611612
SpeechSynthesisUtterance.class, SpeechSynthesisVoice.class,
612613
StereoPannerNode.class, Storage.class, StorageEvent.class, StorageManager.class,
613-
StyleMedia.class, StyleSheet.class, StyleSheetList.class, SubtleCrypto.class,
614+
StyleMedia.class, StyleSheet.class, StyleSheetList.class, SubmitEvent.class, SubtleCrypto.class,
614615
SVGAElement.class, SVGAngle.class, SVGAnimatedAngle.class,
615616
SVGAnimatedBoolean.class, SVGAnimatedEnumeration.class, SVGAnimatedInteger.class,
616617
SVGAnimatedLength.class, SVGAnimatedLengthList.class, SVGAnimatedNumber.class, SVGAnimatedNumberList.class,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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

Comments
 (0)