From 627ad6c37c7f71026188721315e4821a6aa22f27 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 7 Feb 2022 00:04:10 +0100 Subject: LibWeb: Add a proper FocusEvent interface for "focus" and "blur" events --- Userland/Libraries/LibWeb/UIEvents/FocusEvent.cpp | 21 +++++++++++++++ Userland/Libraries/LibWeb/UIEvents/FocusEvent.h | 32 +++++++++++++++++++++++ Userland/Libraries/LibWeb/UIEvents/FocusEvent.idl | 15 +++++++++++ 3 files changed, 68 insertions(+) create mode 100644 Userland/Libraries/LibWeb/UIEvents/FocusEvent.cpp create mode 100644 Userland/Libraries/LibWeb/UIEvents/FocusEvent.h create mode 100644 Userland/Libraries/LibWeb/UIEvents/FocusEvent.idl (limited to 'Userland/Libraries/LibWeb/UIEvents') 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 + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +namespace Web::UIEvents { + +FocusEvent::FocusEvent(FlyString const& event_name, FocusEventInit const& event_init) + : UIEvent(event_name) +{ + set_related_target(const_cast(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 + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::UIEvents { + +struct FocusEventInit : public UIEventInit { + RefPtr related_target; +}; + +class FocusEvent final : public UIEvent { +public: + using WrapperType = Bindings::FocusEventWrapper; + + virtual ~FocusEvent() override; + + static NonnullRefPtr 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 + +[Exposed=Window] +interface FocusEvent : UIEvent { + + constructor(DOMString type, optional FocusEventInit eventInitDict = {}); + readonly attribute EventTarget? relatedTarget; + +}; + +dictionary FocusEventInit : UIEventInit { + + EventTarget? relatedTarget = null; + +}; -- cgit v1.2.3