AriaPropertiesStateModel.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2023, Jonah Shafran <jonahshafran@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/JsonObject.h>
  8. #include <LibGUI/Model.h>
  9. namespace WebView {
  10. class AriaPropertiesStateModel final : public GUI::Model {
  11. public:
  12. enum Column {
  13. PropertyName,
  14. PropertyValue,
  15. __Count
  16. };
  17. static ErrorOr<NonnullRefPtr<AriaPropertiesStateModel>> create(StringView properties_state)
  18. {
  19. auto json_or_error = TRY(JsonValue::from_string(properties_state));
  20. return adopt_nonnull_ref_or_enomem(new AriaPropertiesStateModel(json_or_error.as_object()));
  21. }
  22. virtual ~AriaPropertiesStateModel() override;
  23. virtual int row_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override;
  24. virtual int column_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return Column::__Count; }
  25. virtual ErrorOr<String> column_name(int) const override;
  26. virtual GUI::Variant data(GUI::ModelIndex const&, GUI::ModelRole) const override;
  27. virtual bool is_searchable() const override { return true; }
  28. virtual Vector<GUI::ModelIndex> matches(StringView, unsigned flags, GUI::ModelIndex const&) override;
  29. private:
  30. explicit AriaPropertiesStateModel(JsonObject);
  31. JsonObject m_properties_state;
  32. struct Value {
  33. DeprecatedString name;
  34. DeprecatedString value;
  35. };
  36. Vector<Value> m_values;
  37. };
  38. }