mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
LibWeb: Add HTML::EventNames and UIEvents::EventNames
This commit is contained in:
parent
e68348298f
commit
9950270808
Notes:
sideshowbarker
2024-07-19 01:18:34 +09:00
Author: https://github.com/Lubrsi Commit: https://github.com/SerenityOS/serenity/commit/99502708087 Pull-request: https://github.com/SerenityOS/serenity/pull/4131 Reviewed-by: https://github.com/awesomekling
15 changed files with 271 additions and 19 deletions
|
@ -54,6 +54,7 @@ set(SOURCES
|
|||
FontCache.cpp
|
||||
HTML/AttributeNames.cpp
|
||||
HTML/CanvasRenderingContext2D.cpp
|
||||
HTML/EventNames.cpp
|
||||
HTML/HTMLAnchorElement.cpp
|
||||
HTML/HTMLAreaElement.cpp
|
||||
HTML/HTMLAudioElement.cpp
|
||||
|
@ -187,6 +188,7 @@ set(SOURCES
|
|||
SVG/SVGSVGElement.cpp
|
||||
SVG/TagNames.cpp
|
||||
StylePropertiesModel.cpp
|
||||
UIEvents/EventNames.cpp
|
||||
UIEvents/MouseEvent.cpp
|
||||
URLEncoder.cpp
|
||||
WebContentClient.cpp
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#include <LibWeb/DOM/Window.h>
|
||||
#include <LibWeb/Dump.h>
|
||||
#include <LibWeb/HTML/AttributeNames.h>
|
||||
#include <LibWeb/HTML/EventNames.h>
|
||||
#include <LibWeb/HTML/HTMLBodyElement.h>
|
||||
#include <LibWeb/HTML/HTMLFrameSetElement.h>
|
||||
#include <LibWeb/HTML/HTMLHeadElement.h>
|
||||
|
@ -608,7 +609,7 @@ void Document::set_focused_element(Element* element)
|
|||
void Document::set_ready_state(const String& ready_state)
|
||||
{
|
||||
m_ready_state = ready_state;
|
||||
dispatch_event(Event::create("readystatechange"));
|
||||
dispatch_event(Event::create(HTML::EventNames::readystatechange));
|
||||
}
|
||||
|
||||
Page* Document::page()
|
||||
|
@ -623,7 +624,7 @@ const Page* Document::page() const
|
|||
|
||||
EventTarget* Document::get_parent(const Event& event)
|
||||
{
|
||||
if (event.type() == "load")
|
||||
if (event.type() == HTML::EventNames::load)
|
||||
return nullptr;
|
||||
|
||||
return &window();
|
||||
|
@ -632,7 +633,7 @@ EventTarget* Document::get_parent(const Event& event)
|
|||
void Document::completely_finish_loading()
|
||||
{
|
||||
// FIXME: This needs to handle iframes.
|
||||
dispatch_event(DOM::Event::create("load"));
|
||||
dispatch_event(DOM::Event::create(HTML::EventNames::load));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include <LibWeb/DOM/Node.h>
|
||||
#include <LibWeb/DOM/ShadowRoot.h>
|
||||
#include <LibWeb/DOM/Window.h>
|
||||
#include <LibWeb/HTML/EventNames.h>
|
||||
#include <LibWeb/UIEvents/MouseEvent.h>
|
||||
|
||||
namespace Web::DOM {
|
||||
|
@ -199,7 +200,7 @@ bool EventDispatcher::dispatch(NonnullRefPtr<EventTarget> target, NonnullRefPtr<
|
|||
|
||||
event->append_to_path(*target, target_override, related_target, touch_targets, false);
|
||||
|
||||
bool is_activation_event = is<UIEvents::MouseEvent>(*event) && event->type() == "click";
|
||||
bool is_activation_event = is<UIEvents::MouseEvent>(*event) && event->type() == HTML::EventNames::click;
|
||||
|
||||
if (is_activation_event && target->activation_behaviour)
|
||||
activation_target = target;
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <LibWeb/DOM/EventListener.h>
|
||||
#include <LibWeb/DOM/Window.h>
|
||||
#include <LibWeb/DOM/XMLHttpRequest.h>
|
||||
#include <LibWeb/HTML/EventNames.h>
|
||||
#include <LibWeb/Loader/ResourceLoader.h>
|
||||
#include <LibWeb/Origin.h>
|
||||
|
||||
|
@ -83,7 +84,7 @@ void XMLHttpRequest::send()
|
|||
if (!weak_this)
|
||||
return;
|
||||
const_cast<XMLHttpRequest&>(*weak_this).set_ready_state(ReadyState::Done);
|
||||
const_cast<XMLHttpRequest&>(*weak_this).dispatch_event(DOM::Event::create("error"));
|
||||
const_cast<XMLHttpRequest&>(*weak_this).dispatch_event(DOM::Event::create(HTML::EventNames::error));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -96,14 +97,14 @@ void XMLHttpRequest::send()
|
|||
return;
|
||||
const_cast<XMLHttpRequest&>(*weak_this).m_response = data;
|
||||
const_cast<XMLHttpRequest&>(*weak_this).set_ready_state(ReadyState::Done);
|
||||
const_cast<XMLHttpRequest&>(*weak_this).dispatch_event(DOM::Event::create("load"));
|
||||
const_cast<XMLHttpRequest&>(*weak_this).dispatch_event(DOM::Event::create(HTML::EventNames::load));
|
||||
},
|
||||
[weak_this = make_weak_ptr()](auto& error) {
|
||||
if (!weak_this)
|
||||
return;
|
||||
dbg() << "XHR failed to load: " << error;
|
||||
const_cast<XMLHttpRequest&>(*weak_this).set_ready_state(ReadyState::Done);
|
||||
const_cast<XMLHttpRequest&>(*weak_this).dispatch_event(DOM::Event::create("error"));
|
||||
const_cast<XMLHttpRequest&>(*weak_this).dispatch_event(DOM::Event::create(HTML::EventNames::error));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
52
Libraries/LibWeb/HTML/EventNames.cpp
Normal file
52
Libraries/LibWeb/HTML/EventNames.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <LibWeb/HTML/EventNames.h>
|
||||
|
||||
namespace Web::HTML::EventNames {
|
||||
|
||||
#define __ENUMERATE_HTML_EVENT(name) FlyString name;
|
||||
ENUMERATE_HTML_EVENTS
|
||||
#undef __ENUMERATE_HTML_EVENT
|
||||
|
||||
// clang-format off
|
||||
// FIXME: clang-format gets confused here. Why?
|
||||
[[gnu::constructor]] static void initialize()
|
||||
// clang-format on
|
||||
{
|
||||
static bool s_initialized = false;
|
||||
if (s_initialized)
|
||||
return;
|
||||
|
||||
#define __ENUMERATE_HTML_EVENT(name) \
|
||||
name = #name;
|
||||
ENUMERATE_HTML_EVENTS
|
||||
#undef __ENUMERATE_HTML_EVENT
|
||||
|
||||
s_initialized = true;
|
||||
}
|
||||
|
||||
}
|
85
Libraries/LibWeb/HTML/EventNames.h
Normal file
85
Libraries/LibWeb/HTML/EventNames.h
Normal file
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/FlyString.h>
|
||||
|
||||
namespace Web::HTML::EventNames {
|
||||
|
||||
// FIXME: Add media events https://html.spec.whatwg.org/multipage/media.html#mediaevents
|
||||
// FIXME: Add app cache events https://html.spec.whatwg.org/multipage/offline.html#appcacheevents
|
||||
// FIXME: Add drag and drop events https://html.spec.whatwg.org/multipage/dnd.html#dndevents
|
||||
|
||||
#define ENUMERATE_HTML_EVENTS \
|
||||
__ENUMERATE_HTML_EVENT(abort) \
|
||||
__ENUMERATE_HTML_EVENT(DOMContentLoaded) \
|
||||
__ENUMERATE_HTML_EVENT(afterprint) \
|
||||
__ENUMERATE_HTML_EVENT(beforeprint) \
|
||||
__ENUMERATE_HTML_EVENT(beforeunload) \
|
||||
__ENUMERATE_HTML_EVENT(blur) \
|
||||
__ENUMERATE_HTML_EVENT(cancel) \
|
||||
__ENUMERATE_HTML_EVENT(change) \
|
||||
__ENUMERATE_HTML_EVENT(click) \
|
||||
__ENUMERATE_HTML_EVENT(close) \
|
||||
__ENUMERATE_HTML_EVENT(connect) \
|
||||
__ENUMERATE_HTML_EVENT(contextmenu) \
|
||||
__ENUMERATE_HTML_EVENT(copy) \
|
||||
__ENUMERATE_HTML_EVENT(cut) \
|
||||
__ENUMERATE_HTML_EVENT(error) \
|
||||
__ENUMERATE_HTML_EVENT(focus) \
|
||||
__ENUMERATE_HTML_EVENT(formdata) \
|
||||
__ENUMERATE_HTML_EVENT(hashchange) \
|
||||
__ENUMERATE_HTML_EVENT(input) \
|
||||
__ENUMERATE_HTML_EVENT(invalid) \
|
||||
__ENUMERATE_HTML_EVENT(languagechange) \
|
||||
__ENUMERATE_HTML_EVENT(load) \
|
||||
__ENUMERATE_HTML_EVENT(message) \
|
||||
__ENUMERATE_HTML_EVENT(messageerror) \
|
||||
__ENUMERATE_HTML_EVENT(offline) \
|
||||
__ENUMERATE_HTML_EVENT(online) \
|
||||
__ENUMERATE_HTML_EVENT(open) \
|
||||
__ENUMERATE_HTML_EVENT(pagehide) \
|
||||
__ENUMERATE_HTML_EVENT(pageshow) \
|
||||
__ENUMERATE_HTML_EVENT(paste) \
|
||||
__ENUMERATE_HTML_EVENT(popstate) \
|
||||
__ENUMERATE_HTML_EVENT(readystatechange) \
|
||||
__ENUMERATE_HTML_EVENT(rejectionhandled) \
|
||||
__ENUMERATE_HTML_EVENT(reset) \
|
||||
__ENUMERATE_HTML_EVENT(securitypolicyviolation) \
|
||||
__ENUMERATE_HTML_EVENT(select) \
|
||||
__ENUMERATE_HTML_EVENT(slotchange) \
|
||||
__ENUMERATE_HTML_EVENT(storage) \
|
||||
__ENUMERATE_HTML_EVENT(submit) \
|
||||
__ENUMERATE_HTML_EVENT(toggle) \
|
||||
__ENUMERATE_HTML_EVENT(unhandledrejection) \
|
||||
__ENUMERATE_HTML_EVENT(unload)
|
||||
|
||||
#define __ENUMERATE_HTML_EVENT(name) extern FlyString name;
|
||||
ENUMERATE_HTML_EVENTS
|
||||
#undef __ENUMERATE_HTML_EVENT
|
||||
|
||||
}
|
|
@ -31,6 +31,7 @@
|
|||
#include <LibWeb/DOM/Event.h>
|
||||
#include <LibWeb/DOM/Window.h>
|
||||
#include <LibWeb/Dump.h>
|
||||
#include <LibWeb/HTML/EventNames.h>
|
||||
#include <LibWeb/HTML/HTMLFormElement.h>
|
||||
#include <LibWeb/HTML/HTMLIFrameElement.h>
|
||||
#include <LibWeb/HTML/Parser/HTMLDocumentParser.h>
|
||||
|
@ -106,7 +107,7 @@ const DOM::Document* HTMLIFrameElement::content_document() const
|
|||
|
||||
void HTMLIFrameElement::content_frame_did_load(Badge<FrameLoader>)
|
||||
{
|
||||
dispatch_event(DOM::Event::create("load"));
|
||||
dispatch_event(DOM::Event::create(EventNames::load));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <LibWeb/CSS/StyleResolver.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
#include <LibWeb/HTML/EventNames.h>
|
||||
#include <LibWeb/HTML/HTMLImageElement.h>
|
||||
#include <LibWeb/Layout/ImageBox.h>
|
||||
#include <LibWeb/Loader/ResourceLoader.h>
|
||||
|
@ -41,13 +42,13 @@ HTMLImageElement::HTMLImageElement(DOM::Document& document, const QualifiedName&
|
|||
{
|
||||
m_image_loader.on_load = [this] {
|
||||
this->document().update_layout();
|
||||
dispatch_event(DOM::Event::create("load"));
|
||||
dispatch_event(DOM::Event::create(EventNames::load));
|
||||
};
|
||||
|
||||
m_image_loader.on_fail = [this] {
|
||||
dbg() << "HTMLImageElement: Resource did fail: " << this->src();
|
||||
this->document().update_layout();
|
||||
dispatch_event(DOM::Event::create("error"));
|
||||
dispatch_event(DOM::Event::create(EventNames::error));
|
||||
};
|
||||
|
||||
m_image_loader.on_animate = [this] {
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <LibGUI/TextBox.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
#include <LibWeb/HTML/EventNames.h>
|
||||
#include <LibWeb/HTML/HTMLFormElement.h>
|
||||
#include <LibWeb/HTML/HTMLInputElement.h>
|
||||
#include <LibWeb/InProcessWebView.h>
|
||||
|
@ -49,7 +50,8 @@ HTMLInputElement::~HTMLInputElement()
|
|||
|
||||
void HTMLInputElement::did_click_button(Badge<Layout::ButtonBox>)
|
||||
{
|
||||
dispatch_event(DOM::Event::create("click"));
|
||||
// FIXME: This should be a PointerEvent.
|
||||
dispatch_event(DOM::Event::create(EventNames::click));
|
||||
|
||||
if (type().equals_ignoring_case("submit")) {
|
||||
if (auto* form = first_ancestor_of_type<HTMLFormElement>()) {
|
||||
|
@ -104,7 +106,7 @@ void HTMLInputElement::set_checked(bool checked)
|
|||
if (layout_node())
|
||||
layout_node()->set_needs_display();
|
||||
|
||||
dispatch_event(DOM::Event::create("change"));
|
||||
dispatch_event(DOM::Event::create(EventNames::change));
|
||||
}
|
||||
|
||||
bool HTMLInputElement::enabled() const
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
#include <LibWeb/DOM/Text.h>
|
||||
#include <LibWeb/HTML/EventNames.h>
|
||||
#include <LibWeb/HTML/HTMLScriptElement.h>
|
||||
#include <LibWeb/Loader/ResourceLoader.h>
|
||||
|
||||
|
@ -58,7 +59,7 @@ void HTMLScriptElement::execute_script()
|
|||
document().run_javascript(m_script_source);
|
||||
|
||||
if (has_attribute(HTML::AttributeNames::src))
|
||||
dispatch_event(DOM::Event::create("load"));
|
||||
dispatch_event(DOM::Event::create(EventNames::load));
|
||||
}
|
||||
|
||||
void HTMLScriptElement::prepare_script(Badge<HTMLDocumentParser>)
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <LibWeb/DOM/Event.h>
|
||||
#include <LibWeb/DOM/Text.h>
|
||||
#include <LibWeb/DOM/Window.h>
|
||||
#include <LibWeb/HTML/EventNames.h>
|
||||
#include <LibWeb/HTML/HTMLFormElement.h>
|
||||
#include <LibWeb/HTML/HTMLHeadElement.h>
|
||||
#include <LibWeb/HTML/HTMLScriptElement.h>
|
||||
|
@ -180,7 +181,7 @@ void HTMLDocumentParser::run(const URL& url)
|
|||
script.execute_script();
|
||||
}
|
||||
|
||||
auto content_loaded_event = DOM::Event::create("DOMContentLoaded");
|
||||
auto content_loaded_event = DOM::Event::create(HTML::EventNames::DOMContentLoaded);
|
||||
content_loaded_event->set_bubbles(true);
|
||||
m_document->dispatch_event(content_loaded_event);
|
||||
|
||||
|
@ -192,7 +193,7 @@ void HTMLDocumentParser::run(const URL& url)
|
|||
// FIXME: Spin the event loop until there is nothing that delays the load event in the Document.
|
||||
|
||||
m_document->set_ready_state("complete");
|
||||
m_document->window().dispatch_event(DOM::Event::create("load"));
|
||||
m_document->window().dispatch_event(DOM::Event::create(HTML::EventNames::load));
|
||||
|
||||
m_document->set_ready_for_post_load_tasks(true);
|
||||
m_document->completely_finish_loading();
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include <LibWeb/Layout/InitialContainingBlockBox.h>
|
||||
#include <LibWeb/Page/EventHandler.h>
|
||||
#include <LibWeb/Page/Frame.h>
|
||||
#include <LibWeb/UIEvents/EventNames.h>
|
||||
#include <LibWeb/UIEvents/MouseEvent.h>
|
||||
|
||||
namespace Web {
|
||||
|
@ -103,7 +104,7 @@ bool EventHandler::handle_mouseup(const Gfx::IntPoint& position, unsigned button
|
|||
return false;
|
||||
}
|
||||
auto offset = compute_mouse_event_offset(position, *result.layout_node);
|
||||
node->dispatch_event(UIEvents::MouseEvent::create("mouseup", offset.x(), offset.y()));
|
||||
node->dispatch_event(UIEvents::MouseEvent::create(UIEvents::EventNames::mouseup, offset.x(), offset.y()));
|
||||
handled_event = true;
|
||||
}
|
||||
|
||||
|
@ -151,7 +152,7 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt
|
|||
page->set_focused_frame({}, m_frame);
|
||||
|
||||
auto offset = compute_mouse_event_offset(position, *result.layout_node);
|
||||
node->dispatch_event(UIEvents::MouseEvent::create("mousedown", offset.x(), offset.y()));
|
||||
node->dispatch_event(UIEvents::MouseEvent::create(UIEvents::EventNames::mousedown, offset.x(), offset.y()));
|
||||
if (!layout_root())
|
||||
return true;
|
||||
|
||||
|
@ -253,7 +254,7 @@ bool EventHandler::handle_mousemove(const Gfx::IntPoint& position, unsigned butt
|
|||
if (hovered_link_element)
|
||||
is_hovering_link = true;
|
||||
auto offset = compute_mouse_event_offset(position, *result.layout_node);
|
||||
node->dispatch_event(UIEvents::MouseEvent::create("mousemove", offset.x(), offset.y()));
|
||||
node->dispatch_event(UIEvents::MouseEvent::create(UIEvents::EventNames::mousemove, offset.x(), offset.y()));
|
||||
if (!layout_root())
|
||||
return true;
|
||||
}
|
||||
|
|
52
Libraries/LibWeb/UIEvents/EventNames.cpp
Normal file
52
Libraries/LibWeb/UIEvents/EventNames.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <LibWeb/UIEvents/EventNames.h>
|
||||
|
||||
namespace Web::UIEvents::EventNames {
|
||||
|
||||
#define __ENUMERATE_UI_EVENT(name) FlyString name;
|
||||
ENUMERATE_UI_EVENTS
|
||||
#undef __ENUMERATE_UI_EVENT
|
||||
|
||||
// clang-format off
|
||||
// FIXME: clang-format gets confused here. Why?
|
||||
[[gnu::constructor]] static void initialize()
|
||||
// clang-format on
|
||||
{
|
||||
static bool s_initialized = false;
|
||||
if (s_initialized)
|
||||
return;
|
||||
|
||||
#define __ENUMERATE_UI_EVENT(name) \
|
||||
name = #name;
|
||||
ENUMERATE_UI_EVENTS
|
||||
#undef __ENUMERATE_UI_EVENT
|
||||
|
||||
s_initialized = true;
|
||||
}
|
||||
|
||||
}
|
49
Libraries/LibWeb/UIEvents/EventNames.h
Normal file
49
Libraries/LibWeb/UIEvents/EventNames.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/FlyString.h>
|
||||
|
||||
namespace Web::UIEvents::EventNames {
|
||||
|
||||
// FIXME: This is not all of the events
|
||||
|
||||
#define ENUMERATE_UI_EVENTS \
|
||||
__ENUMERATE_UI_EVENT(click) \
|
||||
__ENUMERATE_UI_EVENT(mousedown) \
|
||||
__ENUMERATE_UI_EVENT(mouseenter) \
|
||||
__ENUMERATE_UI_EVENT(mouseleave) \
|
||||
__ENUMERATE_UI_EVENT(mousemove) \
|
||||
__ENUMERATE_UI_EVENT(mouseout) \
|
||||
__ENUMERATE_UI_EVENT(mouseover) \
|
||||
__ENUMERATE_UI_EVENT(mouseup)
|
||||
|
||||
#define __ENUMERATE_UI_EVENT(name) extern FlyString name;
|
||||
ENUMERATE_UI_EVENTS
|
||||
#undef __ENUMERATE_UI_EVENT
|
||||
|
||||
}
|
|
@ -24,6 +24,8 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <LibWeb/HTML/EventNames.h>
|
||||
#include <LibWeb/UIEvents/EventNames.h>
|
||||
#include <LibWeb/UIEvents/MouseEvent.h>
|
||||
|
||||
namespace Web::UIEvents {
|
||||
|
@ -42,7 +44,7 @@ MouseEvent::~MouseEvent()
|
|||
|
||||
void MouseEvent::set_event_characteristics()
|
||||
{
|
||||
if (type() == "mousedown" || type() == "mousemove" || type() == "mouseout" || type() == "mouseover" || type() == "mouseup" || type() == "click") {
|
||||
if (type().is_one_of(EventNames::mousedown, EventNames::mousemove, EventNames::mouseout, EventNames::mouseover, EventNames::mouseup, HTML::EventNames::click)) {
|
||||
set_bubbles(true);
|
||||
set_cancelable(true);
|
||||
set_composed(true);
|
||||
|
|
Loading…
Add table
Reference in a new issue