ParsingContext.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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(JS::Realm&, URL::URL, Mode = Mode::Normal);
  19. explicit ParsingContext(DOM::Document const&, Mode = Mode::Normal);
  20. explicit ParsingContext(DOM::Document const&, URL::URL, Mode = Mode::Normal);
  21. explicit ParsingContext(DOM::ParentNode&, Mode = Mode::Normal);
  22. Mode mode() const { return m_mode; }
  23. bool is_parsing_svg_presentation_attribute() const { return m_mode == Mode::SVGPresentationAttribute; }
  24. bool in_quirks_mode() const;
  25. DOM::Document const* document() const { return m_document; }
  26. HTML::Window const* window() const;
  27. URL::URL complete_url(StringView) const;
  28. PropertyID current_property_id() const { return m_current_property_id; }
  29. void set_current_property_id(PropertyID property_id) { m_current_property_id = property_id; }
  30. JS::Realm& realm() const { return m_realm; }
  31. private:
  32. JS::NonnullGCPtr<JS::Realm> m_realm;
  33. JS::GCPtr<DOM::Document const> m_document;
  34. PropertyID m_current_property_id { PropertyID::Invalid };
  35. URL::URL m_url;
  36. Mode m_mode { Mode::Normal };
  37. };
  38. }