diff options
author | Andreas Kling <kling@serenityos.org> | 2022-02-07 00:04:10 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-07 00:04:50 +0100 |
commit | 627ad6c37c7f71026188721315e4821a6aa22f27 (patch) | |
tree | 4d28e1fa747662c9d8f0ca56b5c50c644ca33f88 /Userland/Libraries/LibWeb/UIEvents | |
parent | 386912c01979612d694040f2ca688d6148a63dde (diff) | |
download | serenity-627ad6c37c7f71026188721315e4821a6aa22f27.zip |
LibWeb: Add a proper FocusEvent interface for "focus" and "blur" events
Diffstat (limited to 'Userland/Libraries/LibWeb/UIEvents')
-rw-r--r-- | Userland/Libraries/LibWeb/UIEvents/FocusEvent.cpp | 21 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/UIEvents/FocusEvent.h | 32 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/UIEvents/FocusEvent.idl | 15 |
3 files changed, 68 insertions, 0 deletions
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; + +}; |