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