mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:57:36 +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
|
@ -918,6 +918,8 @@ static NonnullOwnPtr<Interface> parse_interface(StringView filename, StringView
|
||||||
|
|
||||||
static bool is_wrappable_type(Type const& type)
|
static bool is_wrappable_type(Type const& type)
|
||||||
{
|
{
|
||||||
|
if (type.name == "EventTarget")
|
||||||
|
return true;
|
||||||
if (type.name == "Node")
|
if (type.name == "Node")
|
||||||
return true;
|
return true;
|
||||||
if (type.name == "Document")
|
if (type.name == "Document")
|
||||||
|
|
|
@ -60,6 +60,8 @@
|
||||||
#include <LibWeb/Bindings/EventPrototype.h>
|
#include <LibWeb/Bindings/EventPrototype.h>
|
||||||
#include <LibWeb/Bindings/EventTargetConstructor.h>
|
#include <LibWeb/Bindings/EventTargetConstructor.h>
|
||||||
#include <LibWeb/Bindings/EventTargetPrototype.h>
|
#include <LibWeb/Bindings/EventTargetPrototype.h>
|
||||||
|
#include <LibWeb/Bindings/FocusEventConstructor.h>
|
||||||
|
#include <LibWeb/Bindings/FocusEventPrototype.h>
|
||||||
#include <LibWeb/Bindings/HTMLAnchorElementConstructor.h>
|
#include <LibWeb/Bindings/HTMLAnchorElementConstructor.h>
|
||||||
#include <LibWeb/Bindings/HTMLAnchorElementPrototype.h>
|
#include <LibWeb/Bindings/HTMLAnchorElementPrototype.h>
|
||||||
#include <LibWeb/Bindings/HTMLAreaElementConstructor.h>
|
#include <LibWeb/Bindings/HTMLAreaElementConstructor.h>
|
||||||
|
|
|
@ -272,6 +272,7 @@ set(SOURCES
|
||||||
Selection/Selection.cpp
|
Selection/Selection.cpp
|
||||||
StylePropertiesModel.cpp
|
StylePropertiesModel.cpp
|
||||||
UIEvents/EventNames.cpp
|
UIEvents/EventNames.cpp
|
||||||
|
UIEvents/FocusEvent.cpp
|
||||||
UIEvents/KeyboardEvent.cpp
|
UIEvents/KeyboardEvent.cpp
|
||||||
UIEvents/MouseEvent.cpp
|
UIEvents/MouseEvent.cpp
|
||||||
URL/URL.cpp
|
URL/URL.cpp
|
||||||
|
@ -504,6 +505,7 @@ libweb_js_wrapper(SVG/SVGGraphicsElement)
|
||||||
libweb_js_wrapper(SVG/SVGPathElement)
|
libweb_js_wrapper(SVG/SVGPathElement)
|
||||||
libweb_js_wrapper(SVG/SVGSVGElement)
|
libweb_js_wrapper(SVG/SVGSVGElement)
|
||||||
libweb_js_wrapper(Selection/Selection)
|
libweb_js_wrapper(Selection/Selection)
|
||||||
|
libweb_js_wrapper(UIEvents/FocusEvent)
|
||||||
libweb_js_wrapper(UIEvents/KeyboardEvent)
|
libweb_js_wrapper(UIEvents/KeyboardEvent)
|
||||||
libweb_js_wrapper(UIEvents/MouseEvent)
|
libweb_js_wrapper(UIEvents/MouseEvent)
|
||||||
libweb_js_wrapper(UIEvents/UIEvent)
|
libweb_js_wrapper(UIEvents/UIEvent)
|
||||||
|
|
|
@ -61,6 +61,7 @@
|
||||||
#include <LibWeb/Page/Page.h>
|
#include <LibWeb/Page/Page.h>
|
||||||
#include <LibWeb/SVG/TagNames.h>
|
#include <LibWeb/SVG/TagNames.h>
|
||||||
#include <LibWeb/UIEvents/EventNames.h>
|
#include <LibWeb/UIEvents/EventNames.h>
|
||||||
|
#include <LibWeb/UIEvents/FocusEvent.h>
|
||||||
#include <LibWeb/UIEvents/KeyboardEvent.h>
|
#include <LibWeb/UIEvents/KeyboardEvent.h>
|
||||||
#include <LibWeb/UIEvents/MouseEvent.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")) {
|
} else if (interface_lowercase.is_one_of("event", "events")) {
|
||||||
event = Event::create("");
|
event = Event::create("");
|
||||||
} else if (interface_lowercase == "focusevent") {
|
} else if (interface_lowercase == "focusevent") {
|
||||||
event = Event::create(""); // FIXME: Create FocusEvent
|
event = UIEvents::FocusEvent::create("");
|
||||||
} else if (interface_lowercase == "hashchangeevent") {
|
} else if (interface_lowercase == "hashchangeevent") {
|
||||||
event = Event::create(""); // FIXME: Create HashChangeEvent
|
event = Event::create(""); // FIXME: Create HashChangeEvent
|
||||||
} else if (interface_lowercase == "htmlevents") {
|
} else if (interface_lowercase == "htmlevents") {
|
||||||
|
|
|
@ -333,6 +333,7 @@ class ElementWrapper;
|
||||||
class EventListenerWrapper;
|
class EventListenerWrapper;
|
||||||
class EventTargetWrapper;
|
class EventTargetWrapper;
|
||||||
class EventWrapper;
|
class EventWrapper;
|
||||||
|
class FocusEventWrapper;
|
||||||
class HistoryWrapper;
|
class HistoryWrapper;
|
||||||
class HTMLAnchorElementWrapper;
|
class HTMLAnchorElementWrapper;
|
||||||
class HTMLAreaElementWrapper;
|
class HTMLAreaElementWrapper;
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <LibWeb/Layout/BreakNode.h>
|
#include <LibWeb/Layout/BreakNode.h>
|
||||||
#include <LibWeb/Layout/TextNode.h>
|
#include <LibWeb/Layout/TextNode.h>
|
||||||
#include <LibWeb/UIEvents/EventNames.h>
|
#include <LibWeb/UIEvents/EventNames.h>
|
||||||
|
#include <LibWeb/UIEvents/FocusEvent.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
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.
|
// with related blur target as the related target.
|
||||||
if (blur_event_target) {
|
if (blur_event_target) {
|
||||||
// FIXME: Implement the "fire a focus event" spec operation.
|
// 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->set_related_target(related_blur_target);
|
||||||
blur_event_target->dispatch_event(move(blur_event));
|
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.
|
// with related focus target as the related target.
|
||||||
if (focus_event_target) {
|
if (focus_event_target) {
|
||||||
// FIXME: Implement the "fire a focus event" spec operation.
|
// 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->set_related_target(related_focus_target);
|
||||||
focus_event_target->dispatch_event(move(focus_event));
|
focus_event_target->dispatch_event(move(focus_event));
|
||||||
}
|
}
|
||||||
|
|
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