CSSPropertyRule.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) 2024, Alex Ungurianu <alex@ungurianu.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/FlyString.h>
  8. #include <AK/NonnullRefPtr.h>
  9. #include <AK/Optional.h>
  10. #include <AK/String.h>
  11. #include <LibWeb/CSS/CSSRule.h>
  12. #include <LibWeb/Forward.h>
  13. namespace Web::CSS {
  14. // https://drafts.css-houdini.org/css-properties-values-api/#the-css-property-rule-interface
  15. class CSSPropertyRule final : public CSSRule {
  16. WEB_PLATFORM_OBJECT(CSSPropertyRule, CSSRule);
  17. JS_DECLARE_ALLOCATOR(CSSPropertyRule);
  18. public:
  19. static JS::NonnullGCPtr<CSSPropertyRule> create(JS::Realm&, FlyString name, FlyString syntax, bool inherits, Optional<String> initial_value);
  20. virtual ~CSSPropertyRule() = default;
  21. virtual Type type() const override { return Type::Property; }
  22. FlyString const& name() const { return m_name; }
  23. FlyString const& syntax() const { return m_syntax; }
  24. bool inherits() const { return m_inherits; }
  25. Optional<String> initial_value() const { return m_initial_value; }
  26. private:
  27. CSSPropertyRule(JS::Realm&, FlyString name, FlyString syntax, bool inherits, Optional<String> initial_value);
  28. virtual void initialize(JS::Realm&) override;
  29. virtual String serialized() const override;
  30. FlyString m_name;
  31. FlyString m_syntax;
  32. bool m_inherits;
  33. // FIXME: This should hold an actual CSS value, matching the syntax
  34. Optional<String> m_initial_value;
  35. };
  36. template<>
  37. inline bool CSSRule::fast_is<CSSPropertyRule>() const { return type() == CSSRule::Type::Property; }
  38. }