PropertyTableModel.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
  4. * Copyright (c) 2023, Jonah Shafran <jonahshafran@gmail.com>
  5. * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
  6. *
  7. * SPDX-License-Identifier: BSD-2-Clause
  8. */
  9. #pragma once
  10. #include <AK/IterationDecision.h>
  11. #include <AK/String.h>
  12. #include <AK/Vector.h>
  13. #include <LibWebView/ModelIndex.h>
  14. namespace WebView {
  15. class PropertyTableModel {
  16. public:
  17. enum class Type {
  18. ARIAProperties,
  19. StyleProperties,
  20. };
  21. enum class Column : int {
  22. PropertyName,
  23. PropertyValue,
  24. };
  25. PropertyTableModel(Type, JsonValue const&);
  26. ~PropertyTableModel();
  27. template<typename Callback>
  28. void for_each_property_name(Callback&& callback)
  29. {
  30. for (size_t i = 0; i < m_values.size(); ++i) {
  31. ModelIndex index { static_cast<int>(i), to_underlying(WebView::PropertyTableModel::Column::PropertyName) };
  32. auto const& property_name = m_values[i].name;
  33. if (callback(index, property_name) == IterationDecision::Break)
  34. break;
  35. }
  36. }
  37. int row_count(ModelIndex const& parent) const;
  38. int column_count(ModelIndex const& parent) const;
  39. ErrorOr<String> column_name(int) const;
  40. ModelIndex index(int row, int column, ModelIndex const& parent) const;
  41. String text_for_display(ModelIndex const& index) const;
  42. private:
  43. struct Value {
  44. String name;
  45. String value;
  46. };
  47. Vector<Value> m_values;
  48. };
  49. }