summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-10-01 18:46:37 +0300
committerAndreas Kling <kling@serenityos.org>2021-10-01 20:14:45 +0200
commit1e8ba0d9d362dffb8e781d0a45155623c8bc2cea (patch)
tree34df82108121129d71a7ac70a6769e19e942aeed /Userland
parentd44857d34d0aebef52374297b846304321d355ac (diff)
downloadserenity-1e8ba0d9d362dffb8e781d0a45155623c8bc2cea.zip
LibWeb: Add the missing SubmitEvent IDL constructor
This commit also removes the SubmitEvent.cpp file, as all of the method implementations were trivial and could be inlined into the header file.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/CMakeLists.txt1
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp4
-rw-r--r--Userland/Libraries/LibWeb/HTML/SubmitEvent.cpp32
-rw-r--r--Userland/Libraries/LibWeb/HTML/SubmitEvent.h25
-rw-r--r--Userland/Libraries/LibWeb/HTML/SubmitEvent.idl6
5 files changed, 30 insertions, 38 deletions
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt
index f5c04f78c4..b2e36a510a 100644
--- a/Userland/Libraries/LibWeb/CMakeLists.txt
+++ b/Userland/Libraries/LibWeb/CMakeLists.txt
@@ -175,7 +175,6 @@ set(SOURCES
HTML/Parser/StackOfOpenElements.cpp
HTML/Scripting/ClassicScript.cpp
HTML/Scripting/Script.cpp
- HTML/SubmitEvent.cpp
HTML/SyntaxHighlighter/SyntaxHighlighter.cpp
HTML/TagNames.cpp
HTML/WebSocket.cpp
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp
index 5d9e3ef437..3c8e3d59d4 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp
@@ -59,7 +59,9 @@ void HTMLFormElement::submit_form(RefPtr<HTMLElement> submitter, bool from_submi
if (submitter != this)
submitter_button = submitter;
- auto submit_event = SubmitEvent::create(EventNames::submit, submitter_button);
+ SubmitEventInit event_init {};
+ event_init.submitter = submitter_button;
+ auto submit_event = SubmitEvent::create(EventNames::submit, event_init);
submit_event->set_bubbles(true);
submit_event->set_cancelable(true);
bool continue_ = dispatch_event(submit_event);
diff --git a/Userland/Libraries/LibWeb/HTML/SubmitEvent.cpp b/Userland/Libraries/LibWeb/HTML/SubmitEvent.cpp
deleted file mode 100644
index fc63ef6ded..0000000000
--- a/Userland/Libraries/LibWeb/HTML/SubmitEvent.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <LibWeb/HTML/HTMLElement.h>
-#include <LibWeb/HTML/SubmitEvent.h>
-
-namespace Web::HTML {
-
-NonnullRefPtr<SubmitEvent> SubmitEvent::create(const FlyString& event_name, RefPtr<HTMLElement> submitter)
-{
- return adopt_ref(*new SubmitEvent(event_name, move(submitter)));
-}
-
-SubmitEvent::SubmitEvent(const FlyString& event_name, RefPtr<HTMLElement> submitter)
- : DOM::Event(event_name)
- , m_submitter(submitter)
-{
-}
-
-SubmitEvent::~SubmitEvent()
-{
-}
-
-RefPtr<HTMLElement> SubmitEvent::submitter() const
-{
- return m_submitter;
-}
-
-}
diff --git a/Userland/Libraries/LibWeb/HTML/SubmitEvent.h b/Userland/Libraries/LibWeb/HTML/SubmitEvent.h
index d8cbcd7246..54922b9a65 100644
--- a/Userland/Libraries/LibWeb/HTML/SubmitEvent.h
+++ b/Userland/Libraries/LibWeb/HTML/SubmitEvent.h
@@ -6,22 +6,39 @@
#pragma once
+#include <LibWeb/Bindings/HTMLElementWrapper.h>
#include <LibWeb/DOM/Event.h>
+#include <LibWeb/HTML/HTMLElement.h>
namespace Web::HTML {
+struct SubmitEventInit : public DOM::EventInit {
+ RefPtr<HTMLElement> submitter { nullptr };
+};
+
class SubmitEvent final : public DOM::Event {
public:
using WrapperType = Bindings::SubmitEventWrapper;
- static NonnullRefPtr<SubmitEvent> create(const FlyString& event_name, RefPtr<HTMLElement> submitter);
+ static NonnullRefPtr<SubmitEvent> create(FlyString const& event_name, SubmitEventInit const& event_init)
+ {
+ return adopt_ref(*new SubmitEvent(event_name, event_init));
+ }
+ static NonnullRefPtr<SubmitEvent> create_with_global_object(Bindings::WindowObject&, FlyString const& event_name, SubmitEventInit const& event_init)
+ {
+ return SubmitEvent::create(event_name, event_init);
+ }
- virtual ~SubmitEvent() override;
+ virtual ~SubmitEvent() override = default;
- RefPtr<HTMLElement> submitter() const;
+ RefPtr<HTMLElement> submitter() const { return m_submitter; }
private:
- SubmitEvent(const FlyString& event_name, RefPtr<HTMLElement> submitter);
+ SubmitEvent(FlyString const& event_name, SubmitEventInit const& event_init)
+ : DOM::Event(event_name, event_init)
+ , m_submitter(event_init.submitter)
+ {
+ }
RefPtr<HTMLElement> m_submitter;
};
diff --git a/Userland/Libraries/LibWeb/HTML/SubmitEvent.idl b/Userland/Libraries/LibWeb/HTML/SubmitEvent.idl
index c816ae663f..30254534eb 100644
--- a/Userland/Libraries/LibWeb/HTML/SubmitEvent.idl
+++ b/Userland/Libraries/LibWeb/HTML/SubmitEvent.idl
@@ -1,5 +1,11 @@
+#import <DOM/Event.idl>
+
interface SubmitEvent : Event {
+ constructor(DOMString type, optional SubmitEventInit eventInitDict = {});
readonly attribute HTMLElement? submitter;
+};
+dictionary SubmitEventInit : EventInit {
+ HTMLElement? submitter = null;
};