1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 19:07:34 +00:00

LibWeb: Rename DOM::Node::id() to unique_id()

The old name was pretty confusing, since it had nothing to do with the
common "id" content attribute.

This makes way for using id() to return the "id" attribute instead. :^)
This commit is contained in:
Andreas Kling 2023-11-02 14:30:00 +01:00
parent 1030776f92
commit 6b580d68a3
8 changed files with 27 additions and 27 deletions

View file

@ -41,7 +41,7 @@ void AccessibilityTreeNode::serialize_tree_as_json(JsonObjectSerializer<StringBu
MUST(object.add("name"sv, name));
auto description = MUST(element->accessible_description(document));
MUST(object.add("description"sv, description));
MUST(object.add("id"sv, element->id()));
MUST(object.add("id"sv, element->unique_id()));
if (has_role)
MUST(object.add("role"sv, ARIA::role_name(*role)));

View file

@ -995,7 +995,7 @@ void Element::serialize_pseudo_elements_as_json(JsonArraySerializer<StringBuilde
auto object = MUST(children_array.add_object());
MUST(object.add("name"sv, DeprecatedString::formatted("::{}", CSS::pseudo_element_name(static_cast<CSS::Selector::PseudoElement>(i)))));
MUST(object.add("type"sv, "pseudo-element"));
MUST(object.add("parent-id"sv, id()));
MUST(object.add("parent-id"sv, unique_id()));
MUST(object.add("pseudo-element"sv, i));
MUST(object.finish());
}

View file

@ -46,33 +46,33 @@
namespace Web::DOM {
static IDAllocator s_node_id_allocator;
static IDAllocator s_unique_id_allocator;
static HashMap<i32, Node*> s_node_directory;
static i32 allocate_node_id(Node* node)
static i32 allocate_unique_id(Node* node)
{
i32 id = s_node_id_allocator.allocate();
i32 id = s_unique_id_allocator.allocate();
s_node_directory.set(id, node);
return id;
}
static void deallocate_node_id(i32 node_id)
static void deallocate_unique_id(i32 node_id)
{
if (!s_node_directory.remove(node_id))
VERIFY_NOT_REACHED();
s_node_id_allocator.deallocate(node_id);
s_unique_id_allocator.deallocate(node_id);
}
Node* Node::from_id(i32 node_id)
Node* Node::from_unique_id(i32 unique_id)
{
return s_node_directory.get(node_id).value_or(nullptr);
return s_node_directory.get(unique_id).value_or(nullptr);
}
Node::Node(JS::Realm& realm, Document& document, NodeType type)
: EventTarget(realm)
, m_document(&document)
, m_type(type)
, m_id(allocate_node_id(this))
, m_unique_id(allocate_unique_id(this))
{
}
@ -86,7 +86,7 @@ Node::~Node() = default;
void Node::finalize()
{
Base::finalize();
deallocate_node_id(m_id);
deallocate_unique_id(m_unique_id);
}
void Node::visit_edges(Cell::Visitor& visitor)
@ -1155,7 +1155,7 @@ bool Node::is_uninteresting_whitespace_node() const
void Node::serialize_tree_as_json(JsonObjectSerializer<StringBuilder>& object) const
{
MUST(object.add("name"sv, node_name()));
MUST(object.add("id"sv, id()));
MUST(object.add("id"sv, unique_id()));
if (is_document()) {
MUST(object.add("type"sv, "document"));
} else if (is_element()) {
@ -1758,7 +1758,7 @@ ErrorOr<String> Node::name_or_description(NameOrDescription target, Document con
auto const* root_node = this;
auto const* current_node = root_node;
StringBuilder total_accumulated_text;
visited_nodes.set(id());
visited_nodes.set(unique_id());
if (is_element()) {
auto const* element = static_cast<DOM::Element const*>(this);
@ -1792,7 +1792,7 @@ ErrorOr<String> Node::name_or_description(NameOrDescription target, Document con
if (!node)
continue;
if (visited_nodes.contains(node->id()))
if (visited_nodes.contains(node->unique_id()))
continue;
// a. Set the current node to the node referenced by the IDREF.
current_node = node;
@ -1842,7 +1842,7 @@ ErrorOr<String> Node::name_or_description(NameOrDescription target, Document con
// iii. For each child node of the current node:
element->for_each_child([&total_accumulated_text, current_node, target, &document, &visited_nodes](
DOM::Node const& child_node) mutable {
if (visited_nodes.contains(child_node.id()))
if (visited_nodes.contains(child_node.unique_id()))
return;
// a. Set the current node to the child node.

View file

@ -235,8 +235,8 @@ public:
bool is_shadow_including_ancestor_of(Node const&) const;
bool is_shadow_including_inclusive_ancestor_of(Node const&) const;
i32 id() const { return m_id; }
static Node* from_id(i32 node_id);
i32 unique_id() const { return m_unique_id; }
static Node* from_unique_id(i32);
WebIDL::ExceptionOr<DeprecatedString> serialize_fragment(DOMParsing::RequireWellFormed) const;
@ -689,7 +689,7 @@ protected:
bool m_needs_style_update { false };
bool m_child_needs_style_update { false };
i32 m_id;
i32 m_unique_id {};
// https://dom.spec.whatwg.org/#registered-observer-list
// "Nodes have a strong reference to registered observers in their registered observer list." https://dom.spec.whatwg.org/#garbage-collection

View file

@ -312,7 +312,7 @@ bool EventHandler::handle_mouseup(CSSPixelPoint position, CSSPixelPoint screen_p
};
if (auto* page = m_browsing_context->page())
page->did_request_media_context_menu(media_element.id(), m_browsing_context->to_top_level_position(position), "", modifiers, move(menu));
page->did_request_media_context_menu(media_element.unique_id(), m_browsing_context->to_top_level_position(position), "", modifiers, move(menu));
} else if (auto* page = m_browsing_context->page()) {
page->client().page_did_request_context_menu(m_browsing_context->to_top_level_position(position));
}

View file

@ -384,7 +384,7 @@ JS::GCPtr<HTML::HTMLMediaElement> Page::media_context_menu_element()
if (!m_media_context_menu_element_id.has_value())
return nullptr;
auto* dom_node = DOM::Node::from_id(*m_media_context_menu_element_id);
auto* dom_node = DOM::Node::from_unique_id(*m_media_context_menu_element_id);
if (dom_node == nullptr)
return nullptr;

View file

@ -517,7 +517,7 @@ Messages::WebContentServer::InspectDomNodeResponse ConnectionFromClient::inspect
return IterationDecision::Continue;
});
Web::DOM::Node* node = Web::DOM::Node::from_id(node_id);
Web::DOM::Node* node = Web::DOM::Node::from_unique_id(node_id);
// Note: Nodes without layout (aka non-visible nodes, don't have style computed)
if (!node || !node->layout_node()) {
return { false, "", "", "", "", "" };
@ -642,7 +642,7 @@ Messages::WebContentServer::GetHoveredNodeIdResponse ConnectionFromClient::get_h
if (auto* document = page().top_level_browsing_context().active_document()) {
auto hovered_node = document->hovered_node();
if (hovered_node)
return hovered_node->id();
return hovered_node->unique_id();
}
return (i32)0;
}

View file

@ -123,7 +123,7 @@ static DeprecatedString get_or_create_a_web_element_reference(Web::DOM::Node con
// FIXME: 2. Add element to the list of known elements of the current browsing context.
// FIXME: 3. Return success with the elements web element reference.
return DeprecatedString::number(element.id());
return DeprecatedString::number(element.unique_id());
}
// https://w3c.github.io/webdriver/#dfn-web-element-reference-object
@ -154,7 +154,7 @@ static ErrorOr<Web::DOM::Element*, Web::WebDriver::Error> get_known_connected_el
if (!element.has_value())
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Element ID is not an integer");
auto* node = Web::DOM::Node::from_id(*element);
auto* node = Web::DOM::Node::from_unique_id(*element);
if (!node || !node->is_element())
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchElement, DeprecatedString::formatted("Could not find element with ID: {}", element_id));
@ -170,7 +170,7 @@ static DeprecatedString get_or_create_a_shadow_root_reference(Web::DOM::ShadowRo
// FIXME: 2. Add shadow to the list of known shadow roots of the current browsing context.
// FIXME: 3. Return success with the shadows shadow root reference.
return DeprecatedString::number(shadow_root.id());
return DeprecatedString::number(shadow_root.unique_id());
}
// https://w3c.github.io/webdriver/#dfn-shadow-root-reference-object
@ -201,7 +201,7 @@ static ErrorOr<Web::DOM::ShadowRoot*, Web::WebDriver::Error> get_known_shadow_ro
if (!shadow_root.has_value())
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Shadow ID is not an integer");
auto* node = Web::DOM::Node::from_id(*shadow_root);
auto* node = Web::DOM::Node::from_unique_id(*shadow_root);
if (!node || !node->is_shadow_root())
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchElement, DeprecatedString::formatted("Could not find shadow root with ID: {}", shadow_id));
@ -982,7 +982,7 @@ Messages::WebDriverClient::GetActiveElementResponse WebDriverConnection::get_act
// 4. If active element is a non-null element, return success with data set to web element reference object for active element.
// Otherwise, return error with error code no such element.
if (active_element)
return DeprecatedString::number(active_element->id());
return DeprecatedString::number(active_element->unique_id());
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchElement, "The current document does not have an active element"sv);
}