Text.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/DeprecatedFlyString.h>
  8. #include <AK/DeprecatedString.h>
  9. #include <LibWeb/DOM/CharacterData.h>
  10. namespace Web::DOM {
  11. class Text : public CharacterData {
  12. WEB_PLATFORM_OBJECT(Text, CharacterData);
  13. public:
  14. virtual ~Text() override = default;
  15. static WebIDL::ExceptionOr<JS::NonnullGCPtr<Text>> construct_impl(JS::Realm& realm, DeprecatedString const& data);
  16. // ^Node
  17. virtual DeprecatedFlyString node_name() const override { return "#text"; }
  18. virtual bool is_editable() const override { return m_always_editable || CharacterData::is_editable(); }
  19. void set_always_editable(bool b) { m_always_editable = b; }
  20. void set_owner_input_element(Badge<HTML::HTMLInputElement>, HTML::HTMLInputElement&);
  21. HTML::HTMLInputElement* owner_input_element() { return m_owner_input_element.ptr(); }
  22. WebIDL::ExceptionOr<JS::NonnullGCPtr<Text>> split_text(size_t offset);
  23. bool is_password_input() const { return m_is_password_input; }
  24. void set_is_password_input(Badge<HTML::HTMLInputElement>, bool b) { m_is_password_input = b; }
  25. protected:
  26. Text(Document&, DeprecatedString const&);
  27. Text(Document&, NodeType, DeprecatedString const&);
  28. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  29. virtual void visit_edges(Cell::Visitor&) override;
  30. private:
  31. JS::GCPtr<HTML::HTMLInputElement> m_owner_input_element;
  32. bool m_always_editable { false };
  33. bool m_is_password_input { false };
  34. };
  35. template<>
  36. inline bool Node::fast_is<Text>() const { return is_text(); }
  37. }