summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-09-12 16:55:10 +0100
committerAndreas Kling <kling@serenityos.org>2021-09-12 18:25:45 +0200
commit4155cc7ed53b1339b772640eaf65f1386f8a7bda (patch)
treeee5225b6491e65317a8429625398e0da0afe147e /Userland/Libraries
parenta61857eb0a5ad6adf27fc8451cd38bf16a575fd2 (diff)
downloadserenity-4155cc7ed53b1339b772640eaf65f1386f8a7bda.zip
LibWeb: Start implementing the MediaQueryList interface
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h3
-rw-r--r--Userland/Libraries/LibWeb/CMakeLists.txt2
-rw-r--r--Userland/Libraries/LibWeb/CSS/MediaQueryList.cpp49
-rw-r--r--Userland/Libraries/LibWeb/CSS/MediaQueryList.h58
-rw-r--r--Userland/Libraries/LibWeb/CSS/MediaQueryList.idl9
-rw-r--r--Userland/Libraries/LibWeb/Forward.h1
6 files changed, 122 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h
index e38e77ba47..4e0f1cb356 100644
--- a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h
+++ b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h
@@ -187,6 +187,8 @@
#include <LibWeb/Bindings/ImageConstructor.h>
#include <LibWeb/Bindings/ImageDataConstructor.h>
#include <LibWeb/Bindings/ImageDataPrototype.h>
+#include <LibWeb/Bindings/MediaQueryListConstructor.h>
+#include <LibWeb/Bindings/MediaQueryListPrototype.h>
#include <LibWeb/Bindings/MessageEventConstructor.h>
#include <LibWeb/Bindings/MessageEventPrototype.h>
#include <LibWeb/Bindings/MouseEventConstructor.h>
@@ -334,6 +336,7 @@
ADD_WINDOW_OBJECT_INTERFACE(HTMLUnknownElement) \
ADD_WINDOW_OBJECT_INTERFACE(HTMLVideoElement) \
ADD_WINDOW_OBJECT_INTERFACE(ImageData) \
+ ADD_WINDOW_OBJECT_INTERFACE(MediaQueryList) \
ADD_WINDOW_OBJECT_INTERFACE(MessageEvent) \
ADD_WINDOW_OBJECT_INTERFACE(MouseEvent) \
ADD_WINDOW_OBJECT_INTERFACE(Node) \
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt
index 8d303dd98b..1affda761e 100644
--- a/Userland/Libraries/LibWeb/CMakeLists.txt
+++ b/Userland/Libraries/LibWeb/CMakeLists.txt
@@ -19,6 +19,7 @@ set(SOURCES
CSS/CSSStyleSheet.cpp
CSS/DefaultStyleSheetSource.cpp
CSS/Length.cpp
+ CSS/MediaQueryList.cpp
CSS/Parser/Parser.cpp
CSS/Parser/StyleRules.cpp
CSS/Parser/Token.cpp
@@ -306,6 +307,7 @@ endfunction()
libweb_js_wrapper(CSS/CSSStyleDeclaration)
libweb_js_wrapper(CSS/CSSStyleSheet)
+libweb_js_wrapper(CSS/MediaQueryList)
libweb_js_wrapper(CSS/Screen)
libweb_js_wrapper(CSS/StyleSheet)
libweb_js_wrapper(CSS/StyleSheetList)
diff --git a/Userland/Libraries/LibWeb/CSS/MediaQueryList.cpp b/Userland/Libraries/LibWeb/CSS/MediaQueryList.cpp
new file mode 100644
index 0000000000..43f5695d91
--- /dev/null
+++ b/Userland/Libraries/LibWeb/CSS/MediaQueryList.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibWeb/Bindings/MediaQueryListWrapper.h>
+#include <LibWeb/CSS/MediaQueryList.h>
+#include <LibWeb/DOM/Document.h>
+#include <LibWeb/DOM/EventDispatcher.h>
+
+namespace Web::CSS {
+
+MediaQueryList::MediaQueryList(DOM::Document& document, String media)
+ : DOM::EventTarget(static_cast<Bindings::ScriptExecutionContext&>(document))
+ , m_document(document)
+ , m_media(move(media))
+{
+}
+
+MediaQueryList::~MediaQueryList()
+{
+}
+
+// https://drafts.csswg.org/cssom-view/#dom-mediaquerylist-media
+String MediaQueryList::media() const
+{
+ // TODO: Replace this with a "media query list" and serialize on demand
+ return m_media;
+}
+
+// https://drafts.csswg.org/cssom-view/#dom-mediaquerylist-matches
+bool MediaQueryList::matches() const
+{
+ // TODO: Implement me :^)
+ return false;
+}
+
+bool MediaQueryList::dispatch_event(NonnullRefPtr<DOM::Event> event)
+{
+ return DOM::EventDispatcher::dispatch(*this, event);
+}
+
+JS::Object* MediaQueryList::create_wrapper(JS::GlobalObject& global_object)
+{
+ return wrap(global_object, *this);
+}
+
+}
diff --git a/Userland/Libraries/LibWeb/CSS/MediaQueryList.h b/Userland/Libraries/LibWeb/CSS/MediaQueryList.h
new file mode 100644
index 0000000000..67aa0c4e6f
--- /dev/null
+++ b/Userland/Libraries/LibWeb/CSS/MediaQueryList.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Forward.h>
+#include <AK/RefCounted.h>
+#include <LibWeb/Bindings/Wrappable.h>
+#include <LibWeb/DOM/EventTarget.h>
+#include <LibWeb/Forward.h>
+
+namespace Web::CSS {
+
+// 4.2. The MediaQueryList Interface, https://drafts.csswg.org/cssom-view/#the-mediaquerylist-interface
+class MediaQueryList final
+ : public RefCounted<MediaQueryList>
+ , public DOM::EventTarget
+ , public Bindings::Wrappable {
+
+public:
+ using WrapperType = Bindings::MediaQueryListWrapper;
+
+ using RefCounted::ref;
+ using RefCounted::unref;
+
+ static NonnullRefPtr<MediaQueryList> create(DOM::Document& document, String media)
+ {
+ return adopt_ref(*new MediaQueryList(document, move(media)));
+ }
+
+ virtual ~MediaQueryList() override;
+
+ String media() const;
+ bool matches() const;
+
+ // ^EventTarget
+ virtual void ref_event_target() override { ref(); }
+ virtual void unref_event_target() override { unref(); }
+ virtual bool dispatch_event(NonnullRefPtr<DOM::Event>) override;
+ virtual JS::Object* create_wrapper(JS::GlobalObject&) override;
+
+private:
+ MediaQueryList(DOM::Document&, String);
+
+ DOM::Document& m_document;
+ String m_media;
+};
+
+}
+
+namespace Web::Bindings {
+
+MediaQueryListWrapper* wrap(JS::GlobalObject&, CSS::MediaQueryList&);
+
+}
diff --git a/Userland/Libraries/LibWeb/CSS/MediaQueryList.idl b/Userland/Libraries/LibWeb/CSS/MediaQueryList.idl
new file mode 100644
index 0000000000..d714211554
--- /dev/null
+++ b/Userland/Libraries/LibWeb/CSS/MediaQueryList.idl
@@ -0,0 +1,9 @@
+[Exposed=Window]
+interface MediaQueryList : EventTarget {
+ readonly attribute CSSOMString media;
+ readonly attribute boolean matches;
+ // TODO:
+ // undefined addListener(EventListener? callback);
+ // undefined removeListener(EventListener? callback);
+ // attribute EventHandler onchange;
+};
diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h
index 061336b494..13114612db 100644
--- a/Userland/Libraries/LibWeb/Forward.h
+++ b/Userland/Libraries/LibWeb/Forward.h
@@ -298,6 +298,7 @@ class HTMLUnknownElementWrapper;
class HTMLVideoElementWrapper;
class ImageDataWrapper;
class LocationObject;
+class MediaQueryListWrapper;
class MessageEventWrapper;
class MouseEventWrapper;
class NodeWrapper;