mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 23:27:44 +00:00
LibWeb: Add a proper FocusEvent interface for "focus" and "blur" events
This commit is contained in:
parent
386912c019
commit
627ad6c37c
9 changed files with 80 additions and 3 deletions
21
Userland/Libraries/LibWeb/UIEvents/FocusEvent.cpp
Normal file
21
Userland/Libraries/LibWeb/UIEvents/FocusEvent.cpp
Normal file
|
@ -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()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
32
Userland/Libraries/LibWeb/UIEvents/FocusEvent.h
Normal file
32
Userland/Libraries/LibWeb/UIEvents/FocusEvent.h
Normal file
|
@ -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&);
|
||||
};
|
||||
|
||||
}
|
15
Userland/Libraries/LibWeb/UIEvents/FocusEvent.idl
Normal file
15
Userland/Libraries/LibWeb/UIEvents/FocusEvent.idl
Normal file
|
@ -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;
|
||||
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue