ParsingContext.h 1.7 KB

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