HTMLElement.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (c) 2018-2022, Andreas Kling <andreas@ladybird.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/DOM/Element.h>
  8. #include <LibWeb/HTML/EventNames.h>
  9. #include <LibWeb/HTML/GlobalEventHandlers.h>
  10. #include <LibWeb/HTML/HTMLOrSVGElement.h>
  11. #include <LibWeb/HTML/TokenizedFeatures.h>
  12. namespace Web::HTML {
  13. // https://html.spec.whatwg.org/multipage/dom.html#attr-dir
  14. #define ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTES \
  15. __ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE(ltr) \
  16. __ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE(rtl) \
  17. __ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE(auto)
  18. class HTMLElement
  19. : public DOM::Element
  20. , public HTML::GlobalEventHandlers
  21. , public HTML::HTMLOrSVGElement<HTMLElement> {
  22. WEB_PLATFORM_OBJECT(HTMLElement, DOM::Element);
  23. GC_DECLARE_ALLOCATOR(HTMLElement);
  24. public:
  25. virtual ~HTMLElement() override;
  26. Optional<String> title() const { return attribute(HTML::AttributeNames::title); }
  27. StringView dir() const;
  28. void set_dir(String const&);
  29. virtual bool is_editable() const final;
  30. virtual bool is_focusable() const override;
  31. bool is_content_editable() const;
  32. StringView content_editable() const;
  33. WebIDL::ExceptionOr<void> set_content_editable(StringView);
  34. String inner_text();
  35. void set_inner_text(StringView);
  36. [[nodiscard]] String outer_text();
  37. WebIDL::ExceptionOr<void> set_outer_text(String const&);
  38. int offset_top() const;
  39. int offset_left() const;
  40. int offset_width() const;
  41. int offset_height() const;
  42. GC::Ptr<Element> offset_parent() const;
  43. bool cannot_navigate() const;
  44. void click();
  45. [[nodiscard]] String access_key_label() const;
  46. bool fire_a_synthetic_pointer_event(FlyString const& type, DOM::Element& target, bool not_trusted);
  47. // https://html.spec.whatwg.org/multipage/forms.html#category-label
  48. virtual bool is_labelable() const { return false; }
  49. GC::Ptr<DOM::NodeList> labels();
  50. virtual Optional<ARIA::Role> default_role() const override;
  51. String get_an_elements_target() const;
  52. TokenizedFeature::NoOpener get_an_elements_noopener(StringView target) const;
  53. WebIDL::ExceptionOr<GC::Ref<ElementInternals>> attach_internals();
  54. WebIDL::ExceptionOr<void> set_popover(Optional<String> value);
  55. Optional<String> popover() const;
  56. protected:
  57. HTMLElement(DOM::Document&, DOM::QualifiedName);
  58. virtual void initialize(JS::Realm&) override;
  59. virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override;
  60. virtual WebIDL::ExceptionOr<void> cloned(DOM::Node&, bool) override;
  61. virtual void inserted() override;
  62. virtual void visit_edges(Cell::Visitor&) override;
  63. private:
  64. virtual bool is_html_element() const final { return true; }
  65. virtual void adjust_computed_style(CSS::StyleProperties&) override;
  66. // ^HTML::GlobalEventHandlers
  67. virtual GC::Ptr<DOM::EventTarget> global_event_handlers_to_event_target(FlyString const&) override { return *this; }
  68. virtual void did_receive_focus() override;
  69. virtual void did_lose_focus() override;
  70. [[nodiscard]] String get_the_text_steps();
  71. GC::Ref<DOM::DocumentFragment> rendered_text_fragment(StringView input);
  72. GC::Ptr<DOM::NodeList> m_labels;
  73. // https://html.spec.whatwg.org/multipage/custom-elements.html#attached-internals
  74. GC::Ptr<ElementInternals> m_attached_internals;
  75. enum class ContentEditableState {
  76. True,
  77. False,
  78. Inherit,
  79. };
  80. ContentEditableState m_content_editable_state { ContentEditableState::Inherit };
  81. // https://html.spec.whatwg.org/multipage/interaction.html#click-in-progress-flag
  82. bool m_click_in_progress { false };
  83. };
  84. }
  85. namespace Web::DOM {
  86. template<>
  87. inline bool Node::fast_is<HTML::HTMLElement>() const { return is_html_element(); }
  88. }