HTMLElement.h 3.0 KB

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