summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/StylePropertiesModel.h
blob: 8eec03e2f87a04e6ebdc14336e0b7968bd1f2122 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/JsonObject.h>
#include <LibGUI/Model.h>
#include <LibWeb/CSS/StyleProperties.h>

namespace Web {

class StylePropertiesModel final : public GUI::Model {
public:
    enum Column {
        PropertyName,
        PropertyValue,
        __Count
    };

    static NonnullRefPtr<StylePropertiesModel> create(StringView properties)
    {
        auto json_or_error = JsonValue::from_string(properties);
        if (!json_or_error.has_value())
            VERIFY_NOT_REACHED();

        return adopt_ref(*new StylePropertiesModel(json_or_error.value().as_object()));
    }

    virtual ~StylePropertiesModel() override;

    virtual int row_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override;
    virtual int column_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return Column::__Count; }
    virtual String column_name(int) const override;
    virtual GUI::Variant data(GUI::ModelIndex const&, GUI::ModelRole) const override;

private:
    explicit StylePropertiesModel(JsonObject);

    JsonObject m_properties;

    struct Value {
        String name;
        String value;
    };
    Vector<Value> m_values;
};

}