HTMLElement.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. [[nodiscard]] String outer_text();
  35. WebIDL::ExceptionOr<void> set_outer_text(String);
  36. int offset_top() const;
  37. int offset_left() const;
  38. int offset_width() const;
  39. int offset_height() const;
  40. JS::GCPtr<Element> offset_parent() const;
  41. bool cannot_navigate() const;
  42. [[nodiscard]] JS::NonnullGCPtr<DOMStringMap> dataset();
  43. void focus();
  44. void click();
  45. void blur();
  46. [[nodiscard]] String access_key_label() const;
  47. bool fire_a_synthetic_pointer_event(FlyString const& type, DOM::Element& target, bool not_trusted);
  48. // https://html.spec.whatwg.org/multipage/forms.html#category-label
  49. virtual bool is_labelable() const { return false; }
  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. protected:
  54. HTMLElement(DOM::Document&, DOM::QualifiedName);
  55. virtual void initialize(JS::Realm&) override;
  56. virtual void attribute_changed(FlyString const& name, Optional<String> const& value) override;
  57. virtual void visit_edges(Cell::Visitor&) override;
  58. private:
  59. virtual bool is_html_element() const final { return true; }
  60. // ^HTML::GlobalEventHandlers
  61. virtual JS::GCPtr<DOM::EventTarget> global_event_handlers_to_event_target(FlyString const&) override { return *this; }
  62. virtual void did_receive_focus() override;
  63. [[nodiscard]] String get_the_text_steps();
  64. JS::GCPtr<DOMStringMap> m_dataset;
  65. enum class ContentEditableState {
  66. True,
  67. False,
  68. Inherit,
  69. };
  70. ContentEditableState m_content_editable_state { ContentEditableState::Inherit };
  71. // https://html.spec.whatwg.org/multipage/interaction.html#locked-for-focus
  72. bool m_locked_for_focus { false };
  73. // https://html.spec.whatwg.org/multipage/interaction.html#click-in-progress-flag
  74. bool m_click_in_progress { false };
  75. };
  76. }
  77. namespace Web::DOM {
  78. template<>
  79. inline bool Node::fast_is<HTML::HTMLElement>() const { return is_html_element(); }
  80. }