mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:17:44 +00:00
Browser+LibWebView: Load and Display ARIA Properites and State
The inspector widget now has a new ARIA tab which displays an individual element's ARIA properties and state. The view itself is pretty basic for now, just being a table- there is definitely room for some better UX here but it's enough for a first cut.
This commit is contained in:
parent
e9840bfd4e
commit
afb07281ad
13 changed files with 179 additions and 17 deletions
77
Userland/Libraries/LibWebView/AriaPropertiesStateModel.cpp
Normal file
77
Userland/Libraries/LibWebView/AriaPropertiesStateModel.cpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Jonah Shafran <jonahshafran@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "AriaPropertiesStateModel.h"
|
||||
|
||||
namespace WebView {
|
||||
|
||||
AriaPropertiesStateModel::AriaPropertiesStateModel(JsonObject properties_state)
|
||||
: m_properties_state(move(properties_state))
|
||||
{
|
||||
m_properties_state.for_each_member([&](auto property_name, JsonValue const& values) {
|
||||
Value value;
|
||||
value.name = property_name;
|
||||
value.value = "";
|
||||
m_values.append(value);
|
||||
values.as_object().for_each_member([&](auto property_name, auto& property_value) {
|
||||
Value value;
|
||||
value.name = property_name;
|
||||
value.value = property_value.to_deprecated_string();
|
||||
m_values.append(value);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
AriaPropertiesStateModel::~AriaPropertiesStateModel() = default;
|
||||
|
||||
int AriaPropertiesStateModel::row_count(GUI::ModelIndex const&) const
|
||||
{
|
||||
return m_values.size();
|
||||
}
|
||||
|
||||
ErrorOr<String> AriaPropertiesStateModel::column_name(int column_index) const
|
||||
{
|
||||
switch (column_index) {
|
||||
case Column::PropertyName:
|
||||
return "Name"_short_string;
|
||||
case Column::PropertyValue:
|
||||
return "Value"_short_string;
|
||||
default:
|
||||
return Error::from_string_view("Unexpected column index"sv);
|
||||
}
|
||||
}
|
||||
|
||||
GUI::Variant AriaPropertiesStateModel::data(GUI::ModelIndex const& index, GUI::ModelRole role) const
|
||||
{
|
||||
auto& value = m_values[index.row()];
|
||||
if (role == GUI::ModelRole::Display) {
|
||||
if (index.column() == Column::PropertyName)
|
||||
return value.name;
|
||||
if (index.column() == Column::PropertyValue)
|
||||
return value.value;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Vector<GUI::ModelIndex> AriaPropertiesStateModel::matches(AK::StringView searching, unsigned int flags, GUI::ModelIndex const& parent)
|
||||
{
|
||||
if (m_values.is_empty())
|
||||
return {};
|
||||
Vector<GUI::ModelIndex> found_indices;
|
||||
for (auto it = m_values.begin(); !it.is_end(); ++it) {
|
||||
GUI::ModelIndex index = this->index(it.index(), Column::PropertyName, parent);
|
||||
if (!string_matches(data(index, GUI::ModelRole::Display).as_string(), searching, flags))
|
||||
continue;
|
||||
|
||||
found_indices.append(index);
|
||||
if (flags & FirstMatchOnly)
|
||||
break;
|
||||
}
|
||||
return found_indices;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue