LibWebView: Replace uses of JsonObject::get_deprecated()/get_ptr()

This commit is contained in:
Sam Atkins 2022-12-21 17:28:30 +00:00 committed by Tim Flynn
parent d8fde14324
commit 3cc376d1a2
Notes: sideshowbarker 2024-07-17 01:14:09 +09:00
4 changed files with 32 additions and 39 deletions

View file

@ -24,8 +24,8 @@ GUI::ModelIndex AccessibilityTreeModel::index(int row, int column, GUI::ModelInd
}
auto const& parent_node = *static_cast<JsonObject const*>(parent.internal_data());
auto const* children = get_children(parent_node);
if (!children)
auto children = get_children(parent_node);
if (!children.has_value())
return create_index(row, column, &m_accessibility_tree);
auto const& child_node = children->at(row).as_object();
@ -52,8 +52,8 @@ GUI::ModelIndex AccessibilityTreeModel::parent_index(GUI::ModelIndex const& inde
auto const* grandparent_node = get_parent(*parent_node);
VERIFY(grandparent_node);
auto const* grandparent_children = get_children(*grandparent_node);
if (!grandparent_children)
auto grandparent_children = get_children(*grandparent_node);
if (!grandparent_children.has_value())
return {};
for (size_t grandparent_child_index = 0; grandparent_child_index < grandparent_children->size(); ++grandparent_child_index) {
@ -71,8 +71,8 @@ int AccessibilityTreeModel::row_count(GUI::ModelIndex const& index) const
return 1;
auto const& node = *static_cast<JsonObject const*>(index.internal_data());
auto const* children = get_children(node);
return children ? children->size() : 0;
auto children = get_children(node);
return children.has_value() ? children->size() : 0;
}
int AccessibilityTreeModel::column_count(const GUI::ModelIndex&) const
@ -83,13 +83,13 @@ int AccessibilityTreeModel::column_count(const GUI::ModelIndex&) const
GUI::Variant AccessibilityTreeModel::data(GUI::ModelIndex const& index, GUI::ModelRole role) const
{
auto const& node = *static_cast<JsonObject const*>(index.internal_data());
auto type = node.get_deprecated("type"sv).as_string_or("unknown"sv);
auto type = node.get_deprecated_string("type"sv).value_or("unknown"sv);
if (role == GUI::ModelRole::Display) {
if (type == "text")
return node.get_deprecated("text"sv).as_string();
return node.get_deprecated_string("text"sv).value();
auto node_role = node.get_deprecated("role"sv).as_string();
auto node_role = node.get_deprecated_string("role"sv).value();
if (type != "element")
return node_role;
@ -104,8 +104,8 @@ void AccessibilityTreeModel::map_accessibility_nodes_to_parent(JsonObject const*
{
m_accessibility_node_to_parent_map.set(node, parent);
auto const* children = get_children(*node);
if (!children)
auto children = get_children(*node);
if (!children.has_value())
return;
children->for_each([&](auto const& child) {

View file

@ -44,11 +44,9 @@ private:
return *parent_node;
}
ALWAYS_INLINE static JsonArray const* get_children(JsonObject const& o)
ALWAYS_INLINE static Optional<JsonArray const&> const get_children(JsonObject const& o)
{
if (auto const* maybe_children = o.get_ptr("children"sv); maybe_children)
return &maybe_children->as_array();
return nullptr;
return o.get_array("children"sv);
}
void map_accessibility_nodes_to_parent(JsonObject const* parent, JsonObject const* child);

View file

@ -37,8 +37,8 @@ GUI::ModelIndex DOMTreeModel::index(int row, int column, const GUI::ModelIndex&
}
auto const& parent_node = *static_cast<JsonObject const*>(parent.internal_data());
auto const* children = get_children(parent_node);
if (!children)
auto children = get_children(parent_node);
if (!children.has_value())
return create_index(row, column, &m_dom_tree);
auto const& child_node = children->at(row).as_object();
@ -67,8 +67,8 @@ GUI::ModelIndex DOMTreeModel::parent_index(const GUI::ModelIndex& index) const
auto const* grandparent_node = get_parent(*parent_node);
VERIFY(grandparent_node);
auto const* grandparent_children = get_children(*grandparent_node);
if (!grandparent_children)
auto grandparent_children = get_children(*grandparent_node);
if (!grandparent_children.has_value())
return {};
for (size_t grandparent_child_index = 0; grandparent_child_index < grandparent_children->size(); ++grandparent_child_index) {
@ -86,8 +86,8 @@ int DOMTreeModel::row_count(const GUI::ModelIndex& index) const
return 1;
auto const& node = *static_cast<JsonObject const*>(index.internal_data());
auto const* children = get_children(node);
return children ? children->size() : 0;
auto children = get_children(node);
return children.has_value() ? children->size() : 0;
}
int DOMTreeModel::column_count(const GUI::ModelIndex&) const
@ -119,8 +119,8 @@ static DeprecatedString with_whitespace_collapsed(StringView string)
GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
{
auto const& node = *static_cast<JsonObject const*>(index.internal_data());
auto node_name = node.get_deprecated("name"sv).as_string();
auto type = node.get_deprecated("type"sv).as_string_or("unknown"sv);
auto node_name = node.get_deprecated_string("name"sv).value_or({});
auto type = node.get_deprecated_string("type"sv).value_or("unknown");
// FIXME: This FIXME can go away when we fix the one below.
#ifdef AK_OS_SERENITY
@ -131,7 +131,7 @@ GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol
return m_tree_view->palette().syntax_comment();
if (type == "pseudo-element"sv)
return m_tree_view->palette().syntax_type();
if (!node.get_deprecated("visible"sv).to_bool(true))
if (!node.get_bool("visible"sv).value_or(true))
return m_tree_view->palette().syntax_comment();
return {};
}
@ -151,9 +151,9 @@ GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol
if (role == GUI::ModelRole::Display) {
if (type == "text")
return with_whitespace_collapsed(node.get_deprecated("text"sv).as_string());
return with_whitespace_collapsed(node.get_deprecated_string("text"sv).value());
if (type == "comment"sv)
return DeprecatedString::formatted("<!--{}-->", node.get_deprecated("data"sv).as_string());
return DeprecatedString::formatted("<!--{}-->", node.get_deprecated_string("data"sv).value());
if (type != "element")
return node_name;
@ -161,7 +161,7 @@ GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol
builder.append('<');
builder.append(node_name.to_lowercase());
if (node.has("attributes"sv)) {
auto attributes = node.get_deprecated("attributes"sv).as_object();
auto attributes = node.get_object("attributes"sv).value();
attributes.for_each_member([&builder](auto& name, JsonValue const& value) {
builder.append(' ');
builder.append(name);
@ -180,10 +180,10 @@ GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol
void DOMTreeModel::map_dom_nodes_to_parent(JsonObject const* parent, JsonObject const* node)
{
m_dom_node_to_parent_map.set(node, parent);
m_node_id_to_dom_node_map.set(node->get_deprecated("id"sv).to_i32(), node);
m_node_id_to_dom_node_map.set(node->get_i32("id"sv).value_or(0), node);
auto const* children = get_children(*node);
if (!children)
auto children = get_children(*node);
if (!children.has_value())
return;
children->for_each([&](auto const& child) {
@ -204,11 +204,8 @@ GUI::ModelIndex DOMTreeModel::index_for_node(i32 node_id, Optional<Web::CSS::Sel
if (!child.has("pseudo-element"sv))
continue;
auto child_pseudo_element = child.get_deprecated("pseudo-element"sv);
if (!child_pseudo_element.is_i32())
continue;
if (child_pseudo_element.as_i32() == to_underlying(pseudo_element.value()))
auto child_pseudo_element = child.get_i32("pseudo-element"sv);
if (child_pseudo_element == to_underlying(pseudo_element.value()))
return create_index(i, 0, &child);
}
} else {

View file

@ -49,11 +49,9 @@ private:
return *parent_node;
}
ALWAYS_INLINE static JsonArray const* get_children(JsonObject const& o)
ALWAYS_INLINE static Optional<JsonArray const&> const get_children(JsonObject const& o)
{
if (auto const* maybe_children = o.get_ptr("children"sv); maybe_children)
return &maybe_children->as_array();
return nullptr;
return o.get_array("children"sv);
}
void map_dom_nodes_to_parent(JsonObject const* parent, JsonObject const* child);