HTMLElement.h 2.9 KB

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