Navigable.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/DOM/Document.h>
  7. #include <LibWeb/HTML/BrowsingContext.h>
  8. #include <LibWeb/HTML/DocumentState.h>
  9. #include <LibWeb/HTML/Navigable.h>
  10. #include <LibWeb/HTML/SessionHistoryEntry.h>
  11. namespace Web::HTML {
  12. Navigable::Navigable() = default;
  13. Navigable::~Navigable() = default;
  14. void Navigable::visit_edges(Cell::Visitor& visitor)
  15. {
  16. Base::visit_edges(visitor);
  17. visitor.visit(m_parent);
  18. visitor.visit(m_current_session_history_entry);
  19. visitor.visit(m_active_session_history_entry);
  20. visitor.visit(m_container);
  21. }
  22. // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-document
  23. JS::GCPtr<DOM::Document> Navigable::active_document()
  24. {
  25. // A navigable's active document is its active session history entry's document.
  26. return m_active_session_history_entry->document_state->document();
  27. }
  28. // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-bc
  29. JS::GCPtr<BrowsingContext> Navigable::active_browsing_context()
  30. {
  31. // A navigable's active browsing context is its active document's browsing context.
  32. // If this navigable is a traversable navigable, then its active browsing context will be a top-level browsing context.
  33. if (auto document = active_document())
  34. return document->browsing_context();
  35. return nullptr;
  36. }
  37. // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-wp
  38. JS::GCPtr<HTML::WindowProxy> Navigable::active_window_proxy()
  39. {
  40. // A navigable's active WindowProxy is its active browsing context's associated WindowProxy.
  41. if (auto browsing_context = active_browsing_context())
  42. return browsing_context->window_proxy();
  43. return nullptr;
  44. }
  45. // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-window
  46. JS::GCPtr<HTML::Window> Navigable::active_window()
  47. {
  48. // A navigable's active window is its active WindowProxy's [[Window]].
  49. if (auto window_proxy = active_window_proxy())
  50. return window_proxy->window();
  51. return nullptr;
  52. }
  53. // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-target
  54. String Navigable::target_name() const
  55. {
  56. // FIXME: A navigable's target name is its active session history entry's document state's navigable target name.
  57. dbgln("FIXME: Implement Navigable::target_name()");
  58. return {};
  59. }
  60. // https://html.spec.whatwg.org/multipage/document-sequences.html#nav-container
  61. JS::GCPtr<NavigableContainer> Navigable::container() const
  62. {
  63. // The container of a navigable navigable is the navigable container whose nested navigable is navigable, or null if there is no such element.
  64. return m_container;
  65. }
  66. void Navigable::set_container(JS::GCPtr<NavigableContainer> container)
  67. {
  68. m_container = container;
  69. }
  70. }