HTMLElement.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.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/TokenizedFeatures.h>
  11. namespace Web::HTML {
  12. // https://html.spec.whatwg.org/multipage/dom.html#attr-dir
  13. #define ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTES \
  14. __ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE(ltr) \
  15. __ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE(rtl) \
  16. __ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE(auto)
  17. class HTMLElement
  18. : public DOM::Element
  19. , public HTML::GlobalEventHandlers {
  20. WEB_PLATFORM_OBJECT(HTMLElement, DOM::Element);
  21. JS_DECLARE_ALLOCATOR(HTMLElement);
  22. public:
  23. virtual ~HTMLElement() override;
  24. Optional<String> title() const { return attribute(HTML::AttributeNames::title); }
  25. StringView dir() const;
  26. void set_dir(String const&);
  27. virtual bool is_editable() const final;
  28. virtual bool is_focusable() const override;
  29. bool is_content_editable() const;
  30. StringView content_editable() const;
  31. WebIDL::ExceptionOr<void> set_content_editable(StringView);
  32. String inner_text();
  33. void set_inner_text(StringView);
  34. int offset_top() const;
  35. int offset_left() const;
  36. int offset_width() const;
  37. int offset_height() const;
  38. JS::GCPtr<Element> offset_parent() const;
  39. bool cannot_navigate() const;
  40. DOMStringMap* dataset() { return m_dataset.ptr(); }
  41. DOMStringMap const* dataset() const { return m_dataset.ptr(); }
  42. void focus();
  43. void click();
  44. void blur();
  45. bool fire_a_synthetic_pointer_event(FlyString const& type, DOM::Element& target, bool not_trusted);
  46. // https://html.spec.whatwg.org/multipage/forms.html#category-label
  47. virtual bool is_labelable() const { return false; }
  48. virtual Optional<ARIA::Role> default_role() const override;
  49. String get_an_elements_target() const;
  50. TokenizedFeature::NoOpener get_an_elements_noopener(StringView target) const;
  51. protected:
  52. HTMLElement(DOM::Document&, DOM::QualifiedName);
  53. virtual void initialize(JS::Realm&) override;
  54. virtual void attribute_changed(FlyString const& name, Optional<String> const& value) override;
  55. virtual void visit_edges(Cell::Visitor&) override;
  56. private:
  57. virtual bool is_html_element() const final { return true; }
  58. // ^HTML::GlobalEventHandlers
  59. virtual JS::GCPtr<DOM::EventTarget> global_event_handlers_to_event_target(FlyString const&) override { return *this; }
  60. virtual void did_receive_focus() override;
  61. JS::GCPtr<DOMStringMap> m_dataset;
  62. enum class ContentEditableState {
  63. True,
  64. False,
  65. Inherit,
  66. };
  67. ContentEditableState m_content_editable_state { ContentEditableState::Inherit };
  68. // https://html.spec.whatwg.org/multipage/interaction.html#locked-for-focus
  69. bool m_locked_for_focus { false };
  70. // https://html.spec.whatwg.org/multipage/interaction.html#click-in-progress-flag
  71. bool m_click_in_progress { false };
  72. };
  73. }
  74. namespace Web::DOM {
  75. template<>
  76. inline bool Node::fast_is<HTML::HTMLElement>() const { return is_html_element(); }
  77. }