StackOfOpenElements.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/NonnullRefPtrVector.h>
  8. #include <LibWeb/DOM/Element.h>
  9. #include <LibWeb/Forward.h>
  10. namespace Web::HTML {
  11. class StackOfOpenElements {
  12. public:
  13. StackOfOpenElements() { }
  14. ~StackOfOpenElements();
  15. DOM::Element& first() { return m_elements.first(); }
  16. DOM::Element& last() { return m_elements.last(); }
  17. bool is_empty() const { return m_elements.is_empty(); }
  18. void push(NonnullRefPtr<DOM::Element> element) { m_elements.append(move(element)); }
  19. NonnullRefPtr<DOM::Element> pop() { return m_elements.take_last(); }
  20. const DOM::Element& current_node() const { return m_elements.last(); }
  21. DOM::Element& current_node() { return m_elements.last(); }
  22. bool has_in_scope(const FlyString& tag_name) const;
  23. bool has_in_button_scope(const FlyString& tag_name) const;
  24. bool has_in_table_scope(const FlyString& tag_name) const;
  25. bool has_in_list_item_scope(const FlyString& tag_name) const;
  26. bool has_in_select_scope(const FlyString& tag_name) const;
  27. bool has_in_scope(const DOM::Element&) const;
  28. bool contains(const DOM::Element&) const;
  29. bool contains(const FlyString& tag_name) const;
  30. const NonnullRefPtrVector<DOM::Element>& elements() const { return m_elements; }
  31. NonnullRefPtrVector<DOM::Element>& elements() { return m_elements; }
  32. void pop_until_an_element_with_tag_name_has_been_popped(const FlyString&);
  33. DOM::Element* topmost_special_node_below(const DOM::Element&);
  34. struct LastElementResult {
  35. DOM::Element* element;
  36. ssize_t index;
  37. };
  38. LastElementResult last_element_with_tag_name(const FlyString&);
  39. DOM::Element* element_before(const DOM::Element&);
  40. private:
  41. bool has_in_scope_impl(const FlyString& tag_name, const Vector<FlyString>&) const;
  42. bool has_in_scope_impl(const DOM::Element& target_node, const Vector<FlyString>&) const;
  43. NonnullRefPtrVector<DOM::Element> m_elements;
  44. };
  45. }