CSSNestedDeclarations.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (c) 2024, Sam Atkins <sam@ladybird.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "CSSNestedDeclarations.h"
  7. #include <LibWeb/Bindings/CSSNestedDeclarationsPrototype.h>
  8. #include <LibWeb/Bindings/Intrinsics.h>
  9. namespace Web::CSS {
  10. JS_DEFINE_ALLOCATOR(CSSNestedDeclarations);
  11. JS::NonnullGCPtr<CSSNestedDeclarations> CSSNestedDeclarations::create(JS::Realm& realm, PropertyOwningCSSStyleDeclaration& declaration)
  12. {
  13. return realm.heap().allocate<CSSNestedDeclarations>(realm, realm, declaration);
  14. }
  15. CSSNestedDeclarations::CSSNestedDeclarations(JS::Realm& realm, PropertyOwningCSSStyleDeclaration& declaration)
  16. : CSSRule(realm, Type::NestedDeclarations)
  17. , m_declaration(declaration)
  18. {
  19. m_declaration->set_parent_rule(*this);
  20. }
  21. void CSSNestedDeclarations::initialize(JS::Realm& realm)
  22. {
  23. Base::initialize(realm);
  24. WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSNestedDeclarations);
  25. }
  26. void CSSNestedDeclarations::visit_edges(Cell::Visitor& visitor)
  27. {
  28. Base::visit_edges(visitor);
  29. visitor.visit(m_declaration);
  30. }
  31. CSSStyleDeclaration* CSSNestedDeclarations::style()
  32. {
  33. return m_declaration;
  34. }
  35. String CSSNestedDeclarations::serialized() const
  36. {
  37. // NOTE: There's no proper spec for this yet, only this note:
  38. // "The CSSNestedDeclarations rule serializes as if its declaration block had been serialized directly."
  39. // - https://drafts.csswg.org/css-nesting-1/#ref-for-cssnesteddeclarations%E2%91%A1
  40. // So, we'll do the simple thing and hope it's good.
  41. return m_declaration->serialized();
  42. }
  43. }