Serenity Operating System
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
8#pragma once
9
10#include <AK/JsonObject.h>
11#include <LibGUI/Model.h>
12#include <LibWeb/CSS/StyleProperties.h>
13
14namespace WebView {
15
16class StylePropertiesModel final : public GUI::Model {
17public:
18 enum Column {
19 PropertyName,
20 PropertyValue,
21 __Count
22 };
23
24 static NonnullRefPtr<StylePropertiesModel> create(StringView properties)
25 {
26 auto json_or_error = JsonValue::from_string(properties).release_value_but_fixme_should_propagate_errors();
27 return adopt_ref(*new StylePropertiesModel(json_or_error.as_object()));
28 }
29
30 virtual ~StylePropertiesModel() override;
31
32 virtual int row_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override;
33 virtual int column_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return Column::__Count; }
34 virtual DeprecatedString column_name(int) const override;
35 virtual GUI::Variant data(GUI::ModelIndex const&, GUI::ModelRole) const override;
36 virtual bool is_searchable() const override { return true; }
37 virtual Vector<GUI::ModelIndex> matches(StringView, unsigned flags, GUI::ModelIndex const&) override;
38
39private:
40 explicit StylePropertiesModel(JsonObject);
41
42 JsonObject m_properties;
43
44 struct Value {
45 DeprecatedString name;
46 DeprecatedString value;
47 };
48 Vector<Value> m_values;
49};
50
51}