HTMLElement.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. public:
  22. virtual ~HTMLElement() override;
  23. DeprecatedString title() const { return deprecated_attribute(HTML::AttributeNames::title); }
  24. StringView dir() const;
  25. void set_dir(String const&);
  26. virtual bool is_editable() const final;
  27. StringView content_editable() const;
  28. WebIDL::ExceptionOr<void> set_content_editable(StringView);
  29. String inner_text();
  30. void set_inner_text(StringView);
  31. int offset_top() const;
  32. int offset_left() const;
  33. int offset_width() const;
  34. int offset_height() const;
  35. bool cannot_navigate() const;
  36. DOMStringMap* dataset() { return m_dataset.ptr(); }
  37. DOMStringMap const* dataset() const { return m_dataset.ptr(); }
  38. void focus();
  39. void click();
  40. void blur();
  41. bool fire_a_synthetic_pointer_event(FlyString const& type, DOM::Element& target, bool not_trusted);
  42. // https://html.spec.whatwg.org/multipage/forms.html#category-label
  43. virtual bool is_labelable() const { return false; }
  44. virtual Optional<ARIA::Role> default_role() const override;
  45. DeprecatedString get_an_elements_target() const;
  46. TokenizedFeature::NoOpener get_an_elements_noopener(StringView target) const;
  47. protected:
  48. HTMLElement(DOM::Document&, DOM::QualifiedName);
  49. virtual void initialize(JS::Realm&) override;
  50. virtual void attribute_changed(DeprecatedFlyString const& name, DeprecatedString const& value) override;
  51. virtual void visit_edges(Cell::Visitor&) override;
  52. private:
  53. virtual bool is_html_element() const final { return true; }
  54. // ^HTML::GlobalEventHandlers
  55. virtual DOM::EventTarget& global_event_handlers_to_event_target(FlyString const&) override { return *this; }
  56. enum class ContentEditableState {
  57. True,
  58. False,
  59. Inherit,
  60. };
  61. ContentEditableState m_content_editable_state { ContentEditableState::Inherit };
  62. JS::GCPtr<DOMStringMap> m_dataset;
  63. // https://html.spec.whatwg.org/multipage/interaction.html#locked-for-focus
  64. bool m_locked_for_focus { false };
  65. // https://html.spec.whatwg.org/multipage/interaction.html#click-in-progress-flag
  66. bool m_click_in_progress { false };
  67. };
  68. }
  69. namespace Web::DOM {
  70. template<>
  71. inline bool Node::fast_is<HTML::HTMLElement>() const { return is_html_element(); }
  72. }