StylePropertiesModel.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/JsonObject.h>
  9. #include <LibGUI/Model.h>
  10. #include <LibWeb/CSS/StyleProperties.h>
  11. namespace Web {
  12. class StylePropertiesModel final : public GUI::Model {
  13. public:
  14. enum Column {
  15. PropertyName,
  16. PropertyValue,
  17. __Count
  18. };
  19. static NonnullRefPtr<StylePropertiesModel> create(StringView properties)
  20. {
  21. auto json_or_error = JsonValue::from_string(properties).release_value_but_fixme_should_propagate_errors();
  22. return adopt_ref(*new StylePropertiesModel(json_or_error.as_object()));
  23. }
  24. virtual ~StylePropertiesModel() override;
  25. virtual int row_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override;
  26. virtual int column_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return Column::__Count; }
  27. virtual String column_name(int) const override;
  28. virtual GUI::Variant data(GUI::ModelIndex const&, GUI::ModelRole) const override;
  29. virtual bool is_searchable() const override { return true; }
  30. virtual Vector<GUI::ModelIndex> matches(StringView, unsigned flags, GUI::ModelIndex const&) override;
  31. private:
  32. explicit StylePropertiesModel(JsonObject);
  33. JsonObject m_properties;
  34. struct Value {
  35. String name;
  36. String value;
  37. };
  38. Vector<Value> m_values;
  39. };
  40. }