summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-29 23:43:18 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-30 00:00:55 +0200
commit6cda24097b5f3311ceb9f3ea224eb3cb643d8cc3 (patch)
tree561334296962b7cde1eed96569fd15443d936dcc
parent71087422f67e1b46398e223ac51fa8ad371c4b91 (diff)
downloadserenity-6cda24097b5f3311ceb9f3ea224eb3cb643d8cc3.zip
LibWeb: Add the CSSStyleRule interface with some limited functionality
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp4
-rw-r--r--Userland/Libraries/LibWeb/Bindings/CSSRuleWrapperFactory.cpp22
-rw-r--r--Userland/Libraries/LibWeb/Bindings/CSSRuleWrapperFactory.h16
-rw-r--r--Userland/Libraries/LibWeb/CMakeLists.txt2
-rw-r--r--Userland/Libraries/LibWeb/CSS/CSSStyleRule.cpp25
-rw-r--r--Userland/Libraries/LibWeb/CSS/CSSStyleRule.h7
-rw-r--r--Userland/Libraries/LibWeb/CSS/CSSStyleRule.idl6
-rw-r--r--Userland/Libraries/LibWeb/Forward.h3
8 files changed, 84 insertions, 1 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp
index 1f3815ec3a..21ddf8fd0e 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp
@@ -825,6 +825,8 @@ static bool should_emit_wrapper_factory(IDL::Interface const& interface)
return false;
if (interface.name.ends_with("Element"))
return false;
+ if (interface.name.starts_with("CSS") && interface.name.ends_with("Rule"))
+ return false;
return true;
}
@@ -1492,6 +1494,7 @@ void generate_implementation(IDL::Interface const& interface)
#include <LibWeb/Bindings/@wrapper_class@.h>
#include <LibWeb/Bindings/CSSRuleListWrapper.h>
#include <LibWeb/Bindings/CSSRuleWrapper.h>
+#include <LibWeb/Bindings/CSSRuleWrapperFactory.h>
#include <LibWeb/Bindings/CSSStyleSheetWrapper.h>
#include <LibWeb/Bindings/CanvasRenderingContext2DWrapper.h>
#include <LibWeb/Bindings/CommentWrapper.h>
@@ -2688,6 +2691,7 @@ void generate_prototype_implementation(IDL::Interface const& interface)
#include <LibWeb/Bindings/AbortSignalWrapper.h>
#include <LibWeb/Bindings/CSSRuleListWrapper.h>
#include <LibWeb/Bindings/CSSRuleWrapper.h>
+#include <LibWeb/Bindings/CSSRuleWrapperFactory.h>
#include <LibWeb/Bindings/CSSStyleDeclarationWrapper.h>
#include <LibWeb/Bindings/CSSStyleSheetWrapper.h>
#include <LibWeb/Bindings/CanvasRenderingContext2DWrapper.h>
diff --git a/Userland/Libraries/LibWeb/Bindings/CSSRuleWrapperFactory.cpp b/Userland/Libraries/LibWeb/Bindings/CSSRuleWrapperFactory.cpp
new file mode 100644
index 0000000000..54cdc9643e
--- /dev/null
+++ b/Userland/Libraries/LibWeb/Bindings/CSSRuleWrapperFactory.cpp
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <AK/TypeCasts.h>
+#include <LibWeb/Bindings/CSSRuleWrapper.h>
+#include <LibWeb/Bindings/CSSRuleWrapperFactory.h>
+#include <LibWeb/Bindings/CSSStyleRuleWrapper.h>
+#include <LibWeb/CSS/CSSStyleRule.h>
+
+namespace Web::Bindings {
+
+CSSRuleWrapper* wrap(JS::GlobalObject& global_object, CSS::CSSRule& rule)
+{
+ if (is<CSS::CSSStyleRule>(rule))
+ return static_cast<CSSRuleWrapper*>(wrap_impl(global_object, verify_cast<CSS::CSSStyleRule>(rule)));
+ return static_cast<CSSRuleWrapper*>(wrap_impl(global_object, rule));
+}
+
+}
diff --git a/Userland/Libraries/LibWeb/Bindings/CSSRuleWrapperFactory.h b/Userland/Libraries/LibWeb/Bindings/CSSRuleWrapperFactory.h
new file mode 100644
index 0000000000..de30b69dc2
--- /dev/null
+++ b/Userland/Libraries/LibWeb/Bindings/CSSRuleWrapperFactory.h
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibJS/Forward.h>
+#include <LibWeb/Forward.h>
+
+namespace Web::Bindings {
+
+CSSRuleWrapper* wrap(JS::GlobalObject&, CSS::CSSRule&);
+
+}
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt
index f02ee959b7..d530f17050 100644
--- a/Userland/Libraries/LibWeb/CMakeLists.txt
+++ b/Userland/Libraries/LibWeb/CMakeLists.txt
@@ -1,4 +1,5 @@
set(SOURCES
+ Bindings/CSSRuleWrapperFactory.cpp
Bindings/CSSStyleDeclarationWrapperCustom.cpp
Bindings/EventListenerWrapper.cpp
Bindings/EventTargetWrapperFactory.cpp
@@ -343,6 +344,7 @@ endfunction()
libweb_js_wrapper(CSS/CSSRule)
libweb_js_wrapper(CSS/CSSRuleList)
libweb_js_wrapper(CSS/CSSStyleDeclaration)
+libweb_js_wrapper(CSS/CSSStyleRule)
libweb_js_wrapper(CSS/CSSStyleSheet)
libweb_js_wrapper(CSS/MediaQueryList)
libweb_js_wrapper(CSS/Screen)
diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleRule.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleRule.cpp
index 75a570344d..2d5bca15e5 100644
--- a/Userland/Libraries/LibWeb/CSS/CSSStyleRule.cpp
+++ b/Userland/Libraries/LibWeb/CSS/CSSStyleRule.cpp
@@ -18,4 +18,29 @@ CSSStyleRule::~CSSStyleRule()
{
}
+// https://drafts.csswg.org/cssom/#dom-cssstylerule-selectortext
+String CSSStyleRule::selector_text() const
+{
+ TODO();
+}
+
+// https://drafts.csswg.org/cssom/#dom-cssstylerule-selectortext
+void CSSStyleRule::set_selector_text(StringView selector_text)
+{
+ // FIXME: 1. Run the parse a group of selectors algorithm on the given value.
+
+ // FIXME: 2. If the algorithm returns a non-null value replace the associated group of selectors with the returned value.
+
+ // FIXME: 3. Otherwise, if the algorithm returns a null value, do nothing.
+
+ (void)selector_text;
+ TODO();
+}
+
+// https://drafts.csswg.org/cssom/#dom-cssstylerule-style
+CSSStyleDeclaration* CSSStyleRule::style()
+{
+ return m_declaration;
+}
+
}
diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleRule.h b/Userland/Libraries/LibWeb/CSS/CSSStyleRule.h
index b0c636323f..0a1b662a92 100644
--- a/Userland/Libraries/LibWeb/CSS/CSSStyleRule.h
+++ b/Userland/Libraries/LibWeb/CSS/CSSStyleRule.h
@@ -20,6 +20,8 @@ class CSSStyleRule : public CSSRule {
AK_MAKE_NONMOVABLE(CSSStyleRule);
public:
+ using WrapperType = Bindings::CSSStyleRuleWrapper;
+
static NonnullRefPtr<CSSStyleRule> create(NonnullRefPtrVector<Selector>&& selectors, NonnullRefPtr<CSSStyleDeclaration>&& declaration)
{
return adopt_ref(*new CSSStyleRule(move(selectors), move(declaration)));
@@ -33,6 +35,11 @@ public:
virtual StringView class_name() const { return "CSSStyleRule"; };
virtual Type type() const { return Type::Style; };
+ String selector_text() const;
+ void set_selector_text(StringView);
+
+ CSSStyleDeclaration* style();
+
private:
CSSStyleRule(NonnullRefPtrVector<Selector>&&, NonnullRefPtr<CSSStyleDeclaration>&&);
diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleRule.idl b/Userland/Libraries/LibWeb/CSS/CSSStyleRule.idl
new file mode 100644
index 0000000000..89016783ad
--- /dev/null
+++ b/Userland/Libraries/LibWeb/CSS/CSSStyleRule.idl
@@ -0,0 +1,6 @@
+interface CSSStyleRule {
+
+ attribute CSSOMString selectorText;
+ [SameObject, PutForwards=cssText] readonly attribute CSSStyleDeclaration style;
+
+};
diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h
index 39db308396..6ef1f9c6c7 100644
--- a/Userland/Libraries/LibWeb/Forward.h
+++ b/Userland/Libraries/LibWeb/Forward.h
@@ -262,9 +262,10 @@ class URLSearchParamsIterator;
namespace Web::Bindings {
class AbortControllerWrapper;
class AbortSignalWrapper;
-class CSSRuleWrapper;
class CSSRuleListWrapper;
+class CSSRuleWrapper;
class CSSStyleDeclarationWrapper;
+class CSSStyleRuleWrapper;
class CSSStyleSheetWrapper;
class CanvasRenderingContext2DWrapper;
class CharacterDataWrapper;