mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:48:10 +00:00

These classes only needed Window to get at its realm. Pass a realm directly to construct DOM and WebIDL classes. This change importantly removes the guarantee that a Document will always have a non-null Window object. Only Documents created by a BrowsingContext will have a non-null Window object. Documents created by for example, DocumentFragment, will not have a Window (soon). This incremental commit leaves some workarounds in place to keep other parts of the code building.
49 lines
1.3 KiB
C++
49 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/FlyString.h>
|
|
#include <AK/String.h>
|
|
#include <LibWeb/DOM/CharacterData.h>
|
|
|
|
namespace Web::DOM {
|
|
|
|
class Text : public CharacterData {
|
|
WEB_PLATFORM_OBJECT(Text, CharacterData);
|
|
|
|
public:
|
|
virtual ~Text() override = default;
|
|
|
|
static JS::NonnullGCPtr<Text> construct_impl(JS::Realm& window, String const& data);
|
|
|
|
// ^Node
|
|
virtual FlyString node_name() const override { return "#text"; }
|
|
virtual bool is_editable() const override { return m_always_editable || CharacterData::is_editable(); }
|
|
|
|
void set_always_editable(bool b) { m_always_editable = b; }
|
|
|
|
void set_owner_input_element(Badge<HTML::HTMLInputElement>, HTML::HTMLInputElement&);
|
|
HTML::HTMLInputElement* owner_input_element() { return m_owner_input_element.ptr(); }
|
|
|
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<Text>> split_text(size_t offset);
|
|
|
|
protected:
|
|
Text(Document&, String const&);
|
|
Text(Document&, NodeType, String const&);
|
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
private:
|
|
JS::GCPtr<HTML::HTMLInputElement> m_owner_input_element;
|
|
|
|
bool m_always_editable { false };
|
|
};
|
|
|
|
template<>
|
|
inline bool Node::fast_is<Text>() const { return is_text(); }
|
|
|
|
}
|