mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
LibWeb: Implement the ClipboardEvent IDL interface
We don't actually generate any such events ourselves. But Google Lens will create one with the DataTransfer attribute set to that of any drop event we send it.
This commit is contained in:
parent
268d6dda2f
commit
0b0d44da27
Notes:
github-actions[bot]
2024-08-22 12:23:21 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/0b0d44da275 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1158 Reviewed-by: https://github.com/shannonbooth
7 changed files with 99 additions and 0 deletions
|
@ -4178,6 +4178,7 @@ static void generate_using_namespace_definitions(SourceGenerator& generator)
|
|||
generator.append(R"~~~(
|
||||
// FIXME: This is a total hack until we can figure out the namespace for a given type somehow.
|
||||
using namespace Web::Animations;
|
||||
using namespace Web::Clipboard;
|
||||
using namespace Web::Crypto;
|
||||
using namespace Web::CSS;
|
||||
using namespace Web::DOM;
|
||||
|
|
|
@ -51,6 +51,7 @@ CanvasPattern
|
|||
CanvasRenderingContext2D
|
||||
CharacterData
|
||||
Clipboard
|
||||
ClipboardEvent
|
||||
CloseEvent
|
||||
CloseWatcher
|
||||
Comment
|
||||
|
|
|
@ -24,6 +24,7 @@ set(SOURCES
|
|||
Bindings/OptionConstructor.cpp
|
||||
Bindings/PlatformObject.cpp
|
||||
Clipboard/Clipboard.cpp
|
||||
Clipboard/ClipboardEvent.cpp
|
||||
Crypto/Crypto.cpp
|
||||
Crypto/CryptoAlgorithms.cpp
|
||||
Crypto/CryptoBindings.cpp
|
||||
|
|
41
Userland/Libraries/LibWeb/Clipboard/ClipboardEvent.cpp
Normal file
41
Userland/Libraries/LibWeb/Clipboard/ClipboardEvent.cpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/Runtime/Realm.h>
|
||||
#include <LibWeb/Bindings/ClipboardEventPrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/Clipboard/ClipboardEvent.h>
|
||||
|
||||
namespace Web::Clipboard {
|
||||
|
||||
JS_DEFINE_ALLOCATOR(ClipboardEvent);
|
||||
|
||||
JS::NonnullGCPtr<ClipboardEvent> ClipboardEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, ClipboardEventInit const& event_init)
|
||||
{
|
||||
return realm.heap().allocate<ClipboardEvent>(realm, realm, event_name, event_init);
|
||||
}
|
||||
|
||||
ClipboardEvent::ClipboardEvent(JS::Realm& realm, FlyString const& event_name, ClipboardEventInit const& event_init)
|
||||
: DOM::Event(realm, event_name, event_init)
|
||||
, m_clipboard_data(event_init.clipboard_data)
|
||||
{
|
||||
}
|
||||
|
||||
ClipboardEvent::~ClipboardEvent() = default;
|
||||
|
||||
void ClipboardEvent::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
WEB_SET_PROTOTYPE_FOR_INTERFACE(ClipboardEvent);
|
||||
}
|
||||
|
||||
void ClipboardEvent::visit_edges(JS::Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_clipboard_data);
|
||||
}
|
||||
|
||||
}
|
41
Userland/Libraries/LibWeb/Clipboard/ClipboardEvent.h
Normal file
41
Userland/Libraries/LibWeb/Clipboard/ClipboardEvent.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibJS/Heap/GCPtr.h>
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/HTML/DataTransfer.h>
|
||||
|
||||
namespace Web::Clipboard {
|
||||
|
||||
struct ClipboardEventInit : public DOM::EventInit {
|
||||
JS::GCPtr<HTML::DataTransfer> clipboard_data;
|
||||
};
|
||||
|
||||
// https://w3c.github.io/clipboard-apis/#clipboardevent
|
||||
class ClipboardEvent : public DOM::Event {
|
||||
WEB_PLATFORM_OBJECT(ClipboardEvent, DOM::Event);
|
||||
JS_DECLARE_ALLOCATOR(ClipboardEvent);
|
||||
|
||||
public:
|
||||
static JS::NonnullGCPtr<ClipboardEvent> construct_impl(JS::Realm&, FlyString const& event_name, ClipboardEventInit const& event_init);
|
||||
|
||||
virtual ~ClipboardEvent() override;
|
||||
|
||||
JS::GCPtr<HTML::DataTransfer> clipboard_data() { return m_clipboard_data; }
|
||||
|
||||
private:
|
||||
ClipboardEvent(JS::Realm&, FlyString const& event_name, ClipboardEventInit const& event_init);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(JS::Cell::Visitor&) override;
|
||||
|
||||
JS::GCPtr<HTML::DataTransfer> m_clipboard_data;
|
||||
};
|
||||
|
||||
}
|
13
Userland/Libraries/LibWeb/Clipboard/ClipboardEvent.idl
Normal file
13
Userland/Libraries/LibWeb/Clipboard/ClipboardEvent.idl
Normal file
|
@ -0,0 +1,13 @@
|
|||
#import <DOM/Event.idl>
|
||||
#import <HTML/DataTransfer.idl>
|
||||
|
||||
dictionary ClipboardEventInit : EventInit {
|
||||
DataTransfer? clipboardData = null;
|
||||
};
|
||||
|
||||
// https://w3c.github.io/clipboard-apis/#clipboardevent
|
||||
[Exposed=Window]
|
||||
interface ClipboardEvent : Event {
|
||||
constructor(DOMString type, optional ClipboardEventInit eventInitDict = {});
|
||||
readonly attribute DataTransfer? clipboardData;
|
||||
};
|
|
@ -8,6 +8,7 @@ libweb_js_bindings(Animations/AnimationTimeline)
|
|||
libweb_js_bindings(Animations/DocumentTimeline)
|
||||
libweb_js_bindings(Animations/KeyframeEffect)
|
||||
libweb_js_bindings(Clipboard/Clipboard)
|
||||
libweb_js_bindings(Clipboard/ClipboardEvent)
|
||||
libweb_js_bindings(Crypto/Crypto)
|
||||
libweb_js_bindings(Crypto/CryptoKey)
|
||||
libweb_js_bindings(Crypto/SubtleCrypto)
|
||||
|
|
Loading…
Reference in a new issue