ParsingContext.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2020-2021, the SerenityOS developers.
  3. * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibJS/Runtime/Realm.h>
  9. #include <LibWeb/DOM/Document.h>
  10. namespace Web::CSS::Parser {
  11. class ParsingContext {
  12. public:
  13. enum class Mode {
  14. Normal,
  15. SVGPresentationAttribute, // See https://svgwg.org/svg2-draft/types.html#presentation-attribute-css-value
  16. };
  17. explicit ParsingContext(JS::Realm&, Mode = Mode::Normal);
  18. explicit ParsingContext(DOM::Document const&, Mode = Mode::Normal);
  19. explicit ParsingContext(DOM::Document const&, URL, Mode = Mode::Normal);
  20. explicit ParsingContext(DOM::ParentNode&, Mode = Mode::Normal);
  21. Mode mode() const { return m_mode; }
  22. bool is_parsing_svg_presentation_attribute() const { return m_mode == Mode::SVGPresentationAttribute; }
  23. bool in_quirks_mode() const;
  24. DOM::Document const* document() const { return m_document; }
  25. HTML::Window const* window() const;
  26. URL complete_url(StringView) const;
  27. PropertyID current_property_id() const { return m_current_property_id; }
  28. void set_current_property_id(PropertyID property_id) { m_current_property_id = property_id; }
  29. JS::Realm& realm() const { return m_realm; }
  30. private:
  31. JS::NonnullGCPtr<JS::Realm> m_realm;
  32. JS::GCPtr<DOM::Document const> m_document;
  33. PropertyID m_current_property_id { PropertyID::Invalid };
  34. URL m_url;
  35. Mode m_mode { Mode::Normal };
  36. };
  37. }