/* * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2021, Sam Atkins * Copyright (c) 2023, Jonah Shafran * Copyright (c) 2023, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include namespace WebView { PropertyTableModel::PropertyTableModel(Type type, JsonValue const& properties) { properties.as_object().for_each_member([&](auto const& property_name, auto const& property_value) { switch (type) { case PropertyTableModel::Type::ARIAProperties: m_values.empend(MUST(String::from_deprecated_string(property_name)), String {}); property_value.as_object().for_each_member([&](auto const& property_name, auto const& property_value) { m_values.empend(MUST(String::from_deprecated_string(property_name)), MUST(String::from_deprecated_string(property_value.to_deprecated_string()))); }); break; case PropertyTableModel::Type::StyleProperties: m_values.empend(MUST(String::from_deprecated_string(property_name)), MUST(String::from_deprecated_string(property_value.to_deprecated_string()))); break; } }); quick_sort(m_values, [](auto const& a, auto const& b) { return a.name < b.name; }); } PropertyTableModel::~PropertyTableModel() = default; int PropertyTableModel::row_count(ModelIndex const&) const { return static_cast(m_values.size()); } int PropertyTableModel::column_count(ModelIndex const&) const { return 2; } ErrorOr PropertyTableModel::column_name(int column_index) const { switch (static_cast(column_index)) { case Column::PropertyName: return "Name"_string; case Column::PropertyValue: return "Value"_string; } VERIFY_NOT_REACHED(); } ModelIndex PropertyTableModel::index(int row, int column, ModelIndex const&) const { return { row, column }; } String PropertyTableModel::text_for_display(ModelIndex const& index) const { auto const& value = m_values[index.row]; switch (static_cast(index.column)) { case Column::PropertyName: return value.name; case Column::PropertyValue: return value.value; } VERIFY_NOT_REACHED(); } }