2020-08-02 06:47:27 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2021-05-18 17:01:12 -03:00
|
|
|
* Copyright (c) 2021, Max Wipfli <mail@maxwipfli.ch>
|
2020-08-02 06:47:27 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-02 06:47:27 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibWeb/DOM/Node.h>
|
|
|
|
|
#include <LibWeb/DOM/Position.h>
|
2021-05-18 17:01:12 -03:00
|
|
|
#include <LibWeb/DOM/Text.h>
|
2020-08-02 06:47:27 -03:00
|
|
|
|
|
|
|
|
namespace Web::DOM {
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DEFINE_ALLOCATOR(Position);
|
2023-11-19 15:47:52 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
Position::Position(GC::Ptr<Node> node, unsigned offset)
|
2023-09-26 14:34:21 -03:00
|
|
|
: m_node(node)
|
2020-08-02 06:47:27 -03:00
|
|
|
, m_offset(offset)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-11 21:08:07 -03:00
|
|
|
void Position::visit_edges(Visitor& visitor)
|
|
|
|
|
{
|
|
|
|
|
Base::visit_edges(visitor);
|
|
|
|
|
visitor.visit(m_node);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-01 08:53:27 -03:00
|
|
|
ErrorOr<String> Position::to_string() const
|
2020-08-02 06:47:27 -03:00
|
|
|
{
|
2021-01-09 10:02:45 -03:00
|
|
|
if (!node())
|
2023-03-01 08:53:27 -03:00
|
|
|
return String::formatted("DOM::Position(nullptr, {})", offset());
|
2023-09-26 14:34:21 -03:00
|
|
|
return String::formatted("DOM::Position({} ({})), {})", node()->node_name(), node().ptr(), offset());
|
2020-08-02 06:47:27 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|