/* * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2021, Max Wipfli * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include namespace Web::DOM { class Position final : public JS::Cell { GC_CELL(Position, JS::Cell); GC_DECLARE_ALLOCATOR(Position); public: [[nodiscard]] static GC::Ref create(JS::Realm& realm, GC::Ref node, unsigned offset) { return realm.create(node, offset); } GC::Ptr node() { return m_node; } GC::Ptr node() const { return m_node; } unsigned offset() const { return m_offset; } bool equals(GC::Ref other) const { return m_node.ptr() == other->m_node.ptr() && m_offset == other->m_offset; } ErrorOr to_string() const; private: Position(GC::Ptr, unsigned offset); virtual void visit_edges(Visitor&) override; GC::Ptr m_node; unsigned m_offset { 0 }; }; } template<> struct AK::Formatter : Formatter { ErrorOr format(FormatBuilder& builder, Web::DOM::Position const& value) { return Formatter::format(builder, TRY(value.to_string())); } };