ladybird/Userland/Libraries/LibWeb/DOM/Position.h
Brian Gianforcaro 1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00

58 lines
1.1 KiB
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/RefPtr.h>
#include <LibWeb/DOM/Node.h>
#include <LibWeb/Forward.h>
namespace Web::DOM {
class Position {
public:
Position() { }
Position(Node&, unsigned offset);
~Position();
bool is_valid() const { return m_node; }
Node* node() { return m_node; }
const Node* node() const { return m_node; }
unsigned offset() const { return m_offset; }
void set_offset(unsigned value) { m_offset = value; }
bool operator==(const Position& other) const
{
return m_node == other.m_node && m_offset == other.m_offset;
}
bool operator!=(const Position& other) const
{
return !(*this == other);
}
String to_string() const;
private:
RefPtr<Node> m_node;
unsigned m_offset { 0 };
};
}
namespace AK {
template<>
struct Formatter<Web::DOM::Position> : Formatter<StringView> {
void format(FormatBuilder& builder, const Web::DOM::Position& value)
{
Formatter<StringView>::format(builder, value.to_string());
}
};
}