ParsingContext.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2018-2022, Andreas Kling <andreas@ladybird.org>
  3. * Copyright (c) 2020-2021, the SerenityOS developers.
  4. * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
  5. * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
  6. * Copyright (c) 2022, MacDue <macdue@dueutil.tech>
  7. *
  8. * SPDX-License-Identifier: BSD-2-Clause
  9. */
  10. #include <LibWeb/CSS/Parser/Parser.h>
  11. #include <LibWeb/DOM/Document.h>
  12. namespace Web::CSS::Parser {
  13. ParsingContext::ParsingContext(Mode mode)
  14. : m_mode(mode)
  15. {
  16. }
  17. ParsingContext::ParsingContext(JS::Realm& realm, Mode mode)
  18. : m_realm(realm)
  19. , m_mode(mode)
  20. {
  21. }
  22. ParsingContext::ParsingContext(JS::Realm& realm, URL::URL url, Mode mode)
  23. : m_realm(realm)
  24. , m_url(move(url))
  25. , m_mode(mode)
  26. {
  27. }
  28. ParsingContext::ParsingContext(DOM::Document const& document, URL::URL url, Mode mode)
  29. : m_realm(const_cast<JS::Realm&>(document.realm()))
  30. , m_document(&document)
  31. , m_url(move(url))
  32. , m_mode(mode)
  33. {
  34. }
  35. ParsingContext::ParsingContext(DOM::Document const& document, Mode mode)
  36. : m_realm(const_cast<JS::Realm&>(document.realm()))
  37. , m_document(&document)
  38. , m_url(document.url())
  39. , m_mode(mode)
  40. {
  41. }
  42. ParsingContext::ParsingContext(DOM::ParentNode& parent_node, Mode mode)
  43. : m_realm(parent_node.realm())
  44. , m_document(&parent_node.document())
  45. , m_url(parent_node.document().url())
  46. , m_mode(mode)
  47. {
  48. }
  49. bool ParsingContext::in_quirks_mode() const
  50. {
  51. return m_document ? m_document->in_quirks_mode() : false;
  52. }
  53. // https://www.w3.org/TR/css-values-4/#relative-urls
  54. URL::URL ParsingContext::complete_url(StringView relative_url) const
  55. {
  56. return m_url.complete_url(relative_url);
  57. }
  58. HTML::Window const* ParsingContext::window() const
  59. {
  60. if (!m_document)
  61. return nullptr;
  62. return m_document->window();
  63. }
  64. }