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

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
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& parent_node = *static_cast<JsonObject const*>(parent.internal_data());
auto const* children = get_children(parent_node); auto children = get_children(parent_node);
if (!children) if (!children.has_value())
return create_index(row, column, &m_accessibility_tree); return create_index(row, column, &m_accessibility_tree);
auto const& child_node = children->at(row).as_object(); 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); auto const* grandparent_node = get_parent(*parent_node);
VERIFY(grandparent_node); VERIFY(grandparent_node);
auto const* grandparent_children = get_children(*grandparent_node); auto grandparent_children = get_children(*grandparent_node);
if (!grandparent_children) if (!grandparent_children.has_value())
return {}; return {};
for (size_t grandparent_child_index = 0; grandparent_child_index < grandparent_children->size(); ++grandparent_child_index) { 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; return 1;
auto const& node = *static_cast<JsonObject const*>(index.internal_data()); auto const& node = *static_cast<JsonObject const*>(index.internal_data());
auto const* children = get_children(node); auto children = get_children(node);
return children ? children->size() : 0; return children.has_value() ? children->size() : 0;
} }
int AccessibilityTreeModel::column_count(const GUI::ModelIndex&) const 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 GUI::Variant AccessibilityTreeModel::data(GUI::ModelIndex const& index, GUI::ModelRole role) const
{ {
auto const& node = *static_cast<JsonObject const*>(index.internal_data()); 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 (role == GUI::ModelRole::Display) {
if (type == "text") 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") if (type != "element")
return node_role; 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); m_accessibility_node_to_parent_map.set(node, parent);
auto const* children = get_children(*node); auto children = get_children(*node);
if (!children) if (!children.has_value())
return; return;
children->for_each([&](auto const& child) { children->for_each([&](auto const& child) {

View file

@ -44,11 +44,9 @@ private:
return *parent_node; 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 o.get_array("children"sv);
return &maybe_children->as_array();
return nullptr;
} }
void map_accessibility_nodes_to_parent(JsonObject const* parent, JsonObject const* child); 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& parent_node = *static_cast<JsonObject const*>(parent.internal_data());
auto const* children = get_children(parent_node); auto children = get_children(parent_node);
if (!children) if (!children.has_value())
return create_index(row, column, &m_dom_tree); return create_index(row, column, &m_dom_tree);
auto const& child_node = children->at(row).as_object(); 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); auto const* grandparent_node = get_parent(*parent_node);
VERIFY(grandparent_node); VERIFY(grandparent_node);
auto const* grandparent_children = get_children(*grandparent_node); auto grandparent_children = get_children(*grandparent_node);
if (!grandparent_children) if (!grandparent_children.has_value())
return {}; return {};
for (size_t grandparent_child_index = 0; grandparent_child_index < grandparent_children->size(); ++grandparent_child_index) { 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; return 1;
auto const& node = *static_cast<JsonObject const*>(index.internal_data()); auto const& node = *static_cast<JsonObject const*>(index.internal_data());
auto const* children = get_children(node); auto children = get_children(node);
return children ? children->size() : 0; return children.has_value() ? children->size() : 0;
} }
int DOMTreeModel::column_count(const GUI::ModelIndex&) const 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 GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
{ {
auto const& node = *static_cast<JsonObject const*>(index.internal_data()); auto const& node = *static_cast<JsonObject const*>(index.internal_data());
auto node_name = node.get_deprecated("name"sv).as_string(); auto node_name = node.get_deprecated_string("name"sv).value_or({});
auto type = node.get_deprecated("type"sv).as_string_or("unknown"sv); auto type = node.get_deprecated_string("type"sv).value_or("unknown");
// FIXME: This FIXME can go away when we fix the one below. // FIXME: This FIXME can go away when we fix the one below.
#ifdef AK_OS_SERENITY #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(); return m_tree_view->palette().syntax_comment();
if (type == "pseudo-element"sv) if (type == "pseudo-element"sv)
return m_tree_view->palette().syntax_type(); 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 m_tree_view->palette().syntax_comment();
return {}; return {};
} }
@ -151,9 +151,9 @@ GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol
if (role == GUI::ModelRole::Display) { if (role == GUI::ModelRole::Display) {
if (type == "text") 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) 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") if (type != "element")
return node_name; return node_name;
@ -161,7 +161,7 @@ GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol
builder.append('<'); builder.append('<');
builder.append(node_name.to_lowercase()); builder.append(node_name.to_lowercase());
if (node.has("attributes"sv)) { 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) { attributes.for_each_member([&builder](auto& name, JsonValue const& value) {
builder.append(' '); builder.append(' ');
builder.append(name); 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) void DOMTreeModel::map_dom_nodes_to_parent(JsonObject const* parent, JsonObject const* node)
{ {
m_dom_node_to_parent_map.set(node, parent); 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); auto children = get_children(*node);
if (!children) if (!children.has_value())
return; return;
children->for_each([&](auto const& child) { 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)) if (!child.has("pseudo-element"sv))
continue; continue;
auto child_pseudo_element = child.get_deprecated("pseudo-element"sv); auto child_pseudo_element = child.get_i32("pseudo-element"sv);
if (!child_pseudo_element.is_i32()) if (child_pseudo_element == to_underlying(pseudo_element.value()))
continue;
if (child_pseudo_element.as_i32() == to_underlying(pseudo_element.value()))
return create_index(i, 0, &child); return create_index(i, 0, &child);
} }
} else { } else {

View file

@ -49,11 +49,9 @@ private:
return *parent_node; 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 o.get_array("children"sv);
return &maybe_children->as_array();
return nullptr;
} }
void map_dom_nodes_to_parent(JsonObject const* parent, JsonObject const* child); void map_dom_nodes_to_parent(JsonObject const* parent, JsonObject const* child);