summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb
diff options
context:
space:
mode:
authorLuke <luke.wilde@live.co.uk>2020-11-21 19:15:57 +0000
committerAndreas Kling <kling@serenityos.org>2020-11-22 18:20:56 +0100
commit99502708087031172bca0e0dc423b28d82517ea8 (patch)
tree3c7d4b5050d8f7c2987474689f6f713c0a4b311c /Libraries/LibWeb
parente68348298f1f0905d6014c8bd5f6da2a3b6233d8 (diff)
downloadserenity-99502708087031172bca0e0dc423b28d82517ea8.zip
LibWeb: Add HTML::EventNames and UIEvents::EventNames
Diffstat (limited to 'Libraries/LibWeb')
-rw-r--r--Libraries/LibWeb/CMakeLists.txt2
-rw-r--r--Libraries/LibWeb/DOM/Document.cpp7
-rw-r--r--Libraries/LibWeb/DOM/EventDispatcher.cpp3
-rw-r--r--Libraries/LibWeb/DOM/XMLHttpRequest.cpp7
-rw-r--r--Libraries/LibWeb/HTML/EventNames.cpp52
-rw-r--r--Libraries/LibWeb/HTML/EventNames.h85
-rw-r--r--Libraries/LibWeb/HTML/HTMLIFrameElement.cpp3
-rw-r--r--Libraries/LibWeb/HTML/HTMLImageElement.cpp5
-rw-r--r--Libraries/LibWeb/HTML/HTMLInputElement.cpp6
-rw-r--r--Libraries/LibWeb/HTML/HTMLScriptElement.cpp3
-rw-r--r--Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp5
-rw-r--r--Libraries/LibWeb/Page/EventHandler.cpp7
-rw-r--r--Libraries/LibWeb/UIEvents/EventNames.cpp52
-rw-r--r--Libraries/LibWeb/UIEvents/EventNames.h49
-rw-r--r--Libraries/LibWeb/UIEvents/MouseEvent.cpp4
15 files changed, 271 insertions, 19 deletions
diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt
index 54aa0849ea..d552e8b04f 100644
--- a/Libraries/LibWeb/CMakeLists.txt
+++ b/Libraries/LibWeb/CMakeLists.txt
@@ -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
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index 358f4b80be..2cc6af2768 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.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));
}
}
diff --git a/Libraries/LibWeb/DOM/EventDispatcher.cpp b/Libraries/LibWeb/DOM/EventDispatcher.cpp
index 94b02acb39..49bcd9a0ee 100644
--- a/Libraries/LibWeb/DOM/EventDispatcher.cpp
+++ b/Libraries/LibWeb/DOM/EventDispatcher.cpp
@@ -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;
diff --git a/Libraries/LibWeb/DOM/XMLHttpRequest.cpp b/Libraries/LibWeb/DOM/XMLHttpRequest.cpp
index 43e8ddeccb..092ad060c8 100644
--- a/Libraries/LibWeb/DOM/XMLHttpRequest.cpp
+++ b/Libraries/LibWeb/DOM/XMLHttpRequest.cpp
@@ -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));
});
}
diff --git a/Libraries/LibWeb/HTML/EventNames.cpp b/Libraries/LibWeb/HTML/EventNames.cpp
new file mode 100644
index 0000000000..c3bcabe877
--- /dev/null
+++ b/Libraries/LibWeb/HTML/EventNames.cpp
@@ -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;
+}
+
+}
diff --git a/Libraries/LibWeb/HTML/EventNames.h b/Libraries/LibWeb/HTML/EventNames.h
new file mode 100644
index 0000000000..d36056ef01
--- /dev/null
+++ b/Libraries/LibWeb/HTML/EventNames.h
@@ -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
+
+}
diff --git a/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp b/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp
index 115783b747..2f58be732d 100644
--- a/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp
@@ -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));
}
}
diff --git a/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Libraries/LibWeb/HTML/HTMLImageElement.cpp
index d78f911fcf..c2d82fef1b 100644
--- a/Libraries/LibWeb/HTML/HTMLImageElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLImageElement.cpp
@@ -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] {
diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Libraries/LibWeb/HTML/HTMLInputElement.cpp
index 70e87f7eb8..6a63e23435 100644
--- a/Libraries/LibWeb/HTML/HTMLInputElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLInputElement.cpp
@@ -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
diff --git a/Libraries/LibWeb/HTML/HTMLScriptElement.cpp b/Libraries/LibWeb/HTML/HTMLScriptElement.cpp
index 524d9d742c..a71ecd9fbd 100644
--- a/Libraries/LibWeb/HTML/HTMLScriptElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLScriptElement.cpp
@@ -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>)
diff --git a/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp b/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp
index d4dddffc0b..837d5cdd4e 100644
--- a/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp
+++ b/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp
@@ -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();
diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp
index e7e310ab31..8cd28f59dc 100644
--- a/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Libraries/LibWeb/Page/EventHandler.cpp
@@ -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;
}
diff --git a/Libraries/LibWeb/UIEvents/EventNames.cpp b/Libraries/LibWeb/UIEvents/EventNames.cpp
new file mode 100644
index 0000000000..66604a65a9
--- /dev/null
+++ b/Libraries/LibWeb/UIEvents/EventNames.cpp
@@ -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;
+}
+
+}
diff --git a/Libraries/LibWeb/UIEvents/EventNames.h b/Libraries/LibWeb/UIEvents/EventNames.h
new file mode 100644
index 0000000000..3667a32f9b
--- /dev/null
+++ b/Libraries/LibWeb/UIEvents/EventNames.h
@@ -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
+
+}
diff --git a/Libraries/LibWeb/UIEvents/MouseEvent.cpp b/Libraries/LibWeb/UIEvents/MouseEvent.cpp
index ba9993be80..e102a4e138 100644
--- a/Libraries/LibWeb/UIEvents/MouseEvent.cpp
+++ b/Libraries/LibWeb/UIEvents/MouseEvent.cpp
@@ -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);