summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Bindings
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-12 19:24:01 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-12 20:44:50 +0200
commit0bcab6046366892bbcef88e26077b2097af98948 (patch)
tree873e9391048453ce61479c69b97c3c33f1b88626 /Userland/Libraries/LibWeb/Bindings
parent10679b6df2f8e9689588f44331544886c54b32fb (diff)
downloadserenity-0bcab6046366892bbcef88e26077b2097af98948.zip
LibWeb: Make CSSStyleDeclaration an abstract class
This patch moves the CSS property+value storage down to a new subclass of CSSStyleDeclaration called PropertyOwningCSSStyleDeclaration. The JavaScript wrapper for CSSStyleDeclaration now calls virtual functions on the C++ object. This is preparation for supporting computed style CSSStyleDeclaration objects which won't have internal property storage, but rather an internal element pointer. :^)
Diffstat (limited to 'Userland/Libraries/LibWeb/Bindings')
-rw-r--r--Userland/Libraries/LibWeb/Bindings/CSSStyleDeclarationWrapperCustom.cpp35
1 files changed, 3 insertions, 32 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/CSSStyleDeclarationWrapperCustom.cpp b/Userland/Libraries/LibWeb/Bindings/CSSStyleDeclarationWrapperCustom.cpp
index 6a20362c08..d5e572fcf3 100644
--- a/Userland/Libraries/LibWeb/Bindings/CSSStyleDeclarationWrapperCustom.cpp
+++ b/Userland/Libraries/LibWeb/Bindings/CSSStyleDeclarationWrapperCustom.cpp
@@ -4,9 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <AK/ScopeGuard.h>
#include <LibWeb/Bindings/CSSStyleDeclarationWrapper.h>
-#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/DOM/Element.h>
namespace Web::Bindings {
@@ -28,10 +26,8 @@ JS::Value CSSStyleDeclarationWrapper::internal_get(JS::PropertyName const& name,
auto property_id = CSS::property_id_from_string(name.to_string());
if (property_id == CSS::PropertyID::Invalid)
return Base::internal_get(name, receiver);
- for (auto& property : impl().properties()) {
- if (property.property_id == property_id)
- return js_string(vm(), property.value->to_string());
- }
+ if (auto maybe_property = impl().property(property_id); maybe_property.has_value())
+ return js_string(vm(), maybe_property->value->to_string());
return js_string(vm(), String::empty());
}
@@ -48,32 +44,7 @@ bool CSSStyleDeclarationWrapper::internal_set(JS::PropertyName const& name, JS::
if (vm().exception())
return false;
- auto new_value = parse_css_value(CSS::ParsingContext {}, css_text, property_id);
- // FIXME: What are we supposed to do if we can't parse it?
- if (!new_value)
- return false;
-
- ScopeGuard style_invalidation_guard = [&] {
- auto& declaration = verify_cast<CSS::ElementInlineCSSStyleDeclaration>(impl());
- if (auto* element = declaration.element())
- element->invalidate_style();
- };
-
- // FIXME: I don't think '!important' is being handled correctly here..
-
- for (auto& property : impl().m_properties) {
- if (property.property_id == property_id) {
- property.value = new_value.release_nonnull();
- return true;
- }
- }
-
- impl().m_properties.append(CSS::StyleProperty {
- .property_id = property_id,
- .value = new_value.release_nonnull(),
- .important = false,
- });
- return true;
+ return impl().set_property(property_id, css_text);
}
}