summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-02-07 00:04:10 +0100
committerAndreas Kling <kling@serenityos.org>2022-02-07 00:04:50 +0100
commit627ad6c37c7f71026188721315e4821a6aa22f27 (patch)
tree4d28e1fa747662c9d8f0ca56b5c50c644ca33f88 /Userland/Libraries/LibWeb
parent386912c01979612d694040f2ca688d6148a63dde (diff)
downloadserenity-627ad6c37c7f71026188721315e4821a6aa22f27.zip
LibWeb: Add a proper FocusEvent interface for "focus" and "blur" events
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h2
-rw-r--r--Userland/Libraries/LibWeb/CMakeLists.txt2
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.cpp3
-rw-r--r--Userland/Libraries/LibWeb/Forward.h1
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLElement.cpp5
-rw-r--r--Userland/Libraries/LibWeb/UIEvents/FocusEvent.cpp21
-rw-r--r--Userland/Libraries/LibWeb/UIEvents/FocusEvent.h32
-rw-r--r--Userland/Libraries/LibWeb/UIEvents/FocusEvent.idl15
8 files changed, 78 insertions, 3 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h
index 10028a0c93..cac70f5aad 100644
--- a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h
+++ b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h
@@ -60,6 +60,8 @@
#include <LibWeb/Bindings/EventPrototype.h>
#include <LibWeb/Bindings/EventTargetConstructor.h>
#include <LibWeb/Bindings/EventTargetPrototype.h>
+#include <LibWeb/Bindings/FocusEventConstructor.h>
+#include <LibWeb/Bindings/FocusEventPrototype.h>
#include <LibWeb/Bindings/HTMLAnchorElementConstructor.h>
#include <LibWeb/Bindings/HTMLAnchorElementPrototype.h>
#include <LibWeb/Bindings/HTMLAreaElementConstructor.h>
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt
index 7451212877..1f59aa84ee 100644
--- a/Userland/Libraries/LibWeb/CMakeLists.txt
+++ b/Userland/Libraries/LibWeb/CMakeLists.txt
@@ -272,6 +272,7 @@ set(SOURCES
Selection/Selection.cpp
StylePropertiesModel.cpp
UIEvents/EventNames.cpp
+ UIEvents/FocusEvent.cpp
UIEvents/KeyboardEvent.cpp
UIEvents/MouseEvent.cpp
URL/URL.cpp
@@ -504,6 +505,7 @@ libweb_js_wrapper(SVG/SVGGraphicsElement)
libweb_js_wrapper(SVG/SVGPathElement)
libweb_js_wrapper(SVG/SVGSVGElement)
libweb_js_wrapper(Selection/Selection)
+libweb_js_wrapper(UIEvents/FocusEvent)
libweb_js_wrapper(UIEvents/KeyboardEvent)
libweb_js_wrapper(UIEvents/MouseEvent)
libweb_js_wrapper(UIEvents/UIEvent)
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp
index f6d6fae338..7e66f898b2 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Document.cpp
@@ -61,6 +61,7 @@
#include <LibWeb/Page/Page.h>
#include <LibWeb/SVG/TagNames.h>
#include <LibWeb/UIEvents/EventNames.h>
+#include <LibWeb/UIEvents/FocusEvent.h>
#include <LibWeb/UIEvents/KeyboardEvent.h>
#include <LibWeb/UIEvents/MouseEvent.h>
@@ -748,7 +749,7 @@ NonnullRefPtr<Event> Document::create_event(const String& interface)
} else if (interface_lowercase.is_one_of("event", "events")) {
event = Event::create("");
} else if (interface_lowercase == "focusevent") {
- event = Event::create(""); // FIXME: Create FocusEvent
+ event = UIEvents::FocusEvent::create("");
} else if (interface_lowercase == "hashchangeevent") {
event = Event::create(""); // FIXME: Create HashChangeEvent
} else if (interface_lowercase == "htmlevents") {
diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h
index e9b1786257..414b387d10 100644
--- a/Userland/Libraries/LibWeb/Forward.h
+++ b/Userland/Libraries/LibWeb/Forward.h
@@ -333,6 +333,7 @@ class ElementWrapper;
class EventListenerWrapper;
class EventTargetWrapper;
class EventWrapper;
+class FocusEventWrapper;
class HistoryWrapper;
class HTMLAnchorElementWrapper;
class HTMLAreaElementWrapper;
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp
index 8ab7f37af2..fd77b0e57d 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp
@@ -22,6 +22,7 @@
#include <LibWeb/Layout/BreakNode.h>
#include <LibWeb/Layout/TextNode.h>
#include <LibWeb/UIEvents/EventNames.h>
+#include <LibWeb/UIEvents/FocusEvent.h>
namespace Web::HTML {
@@ -226,7 +227,7 @@ static void run_focus_update_steps(Vector<DOM::Node&> old_chain, Vector<DOM::Nod
// with related blur target as the related target.
if (blur_event_target) {
// FIXME: Implement the "fire a focus event" spec operation.
- auto blur_event = DOM::Event::create(HTML::EventNames::blur);
+ auto blur_event = UIEvents::FocusEvent::create(HTML::EventNames::blur);
blur_event->set_related_target(related_blur_target);
blur_event_target->dispatch_event(move(blur_event));
}
@@ -269,7 +270,7 @@ static void run_focus_update_steps(Vector<DOM::Node&> old_chain, Vector<DOM::Nod
// with related focus target as the related target.
if (focus_event_target) {
// FIXME: Implement the "fire a focus event" spec operation.
- auto focus_event = DOM::Event::create(HTML::EventNames::focus);
+ auto focus_event = UIEvents::FocusEvent::create(HTML::EventNames::focus);
focus_event->set_related_target(related_focus_target);
focus_event_target->dispatch_event(move(focus_event));
}
diff --git a/Userland/Libraries/LibWeb/UIEvents/FocusEvent.cpp b/Userland/Libraries/LibWeb/UIEvents/FocusEvent.cpp
new file mode 100644
index 0000000000..3397fc7b60
--- /dev/null
+++ b/Userland/Libraries/LibWeb/UIEvents/FocusEvent.cpp
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibWeb/UIEvents/FocusEvent.h>
+
+namespace Web::UIEvents {
+
+FocusEvent::FocusEvent(FlyString const& event_name, FocusEventInit const& event_init)
+ : UIEvent(event_name)
+{
+ set_related_target(const_cast<DOM::EventTarget*>(event_init.related_target.ptr()));
+}
+
+FocusEvent::~FocusEvent()
+{
+}
+
+}
diff --git a/Userland/Libraries/LibWeb/UIEvents/FocusEvent.h b/Userland/Libraries/LibWeb/UIEvents/FocusEvent.h
new file mode 100644
index 0000000000..4a244dbede
--- /dev/null
+++ b/Userland/Libraries/LibWeb/UIEvents/FocusEvent.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibWeb/UIEvents/UIEvent.h>
+
+namespace Web::UIEvents {
+
+struct FocusEventInit : public UIEventInit {
+ RefPtr<DOM::EventTarget> related_target;
+};
+
+class FocusEvent final : public UIEvent {
+public:
+ using WrapperType = Bindings::FocusEventWrapper;
+
+ virtual ~FocusEvent() override;
+
+ static NonnullRefPtr<FocusEvent> create_with_global_object(Bindings::WindowObject&, FlyString const& event_name, FocusEventInit const& event_init)
+ {
+ return adopt_ref(*new FocusEvent(event_name, event_init));
+ }
+
+private:
+ FocusEvent(FlyString const& event_name, FocusEventInit const&);
+};
+
+}
diff --git a/Userland/Libraries/LibWeb/UIEvents/FocusEvent.idl b/Userland/Libraries/LibWeb/UIEvents/FocusEvent.idl
new file mode 100644
index 0000000000..1cba0af8fd
--- /dev/null
+++ b/Userland/Libraries/LibWeb/UIEvents/FocusEvent.idl
@@ -0,0 +1,15 @@
+#import <UIEvents/UIEvent.idl>
+
+[Exposed=Window]
+interface FocusEvent : UIEvent {
+
+ constructor(DOMString type, optional FocusEventInit eventInitDict = {});
+ readonly attribute EventTarget? relatedTarget;
+
+};
+
+dictionary FocusEventInit : UIEventInit {
+
+ EventTarget? relatedTarget = null;
+
+};