summaryrefslogtreecommitdiffstats
path: root/include/orcus/css_document_tree.hpp
blob: abbc65a98ff7f28eb1234c90a05969e4c9d8bfe3 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#ifndef INCLUDED_ORCUS_CSS_DOCUMENT_TREE_HPP
#define INCLUDED_ORCUS_CSS_DOCUMENT_TREE_HPP

#include "orcus/css_selector.hpp"
#include "orcus/exception.hpp"

#include <string>
#include <memory>

namespace orcus {

/**
 * Class representing CSS rules.
 */
class ORCUS_DLLPUBLIC css_document_tree
{
    struct impl;
    std::unique_ptr<impl> mp_impl;

public:

    class insertion_error : public general_error
    {
    public:
        insertion_error(const std::string& msg);
    };

    css_document_tree(const css_document_tree&) = delete;

    css_document_tree();
    css_document_tree(css_document_tree&& other);
    ~css_document_tree();

    css_document_tree& operator=(css_document_tree&& other);

    /**
     * Load raw string stream containing CSS rules to populate the document
     * tree.
     *
     * @param stream raw CSS rules.
     */
    void load(std::string_view stream);

    /**
     * Insert or replace properties for given selector and pseudo element
     * flags.
     *
     * @param selector selector to store properties for.
     * @param pseudo_elem pseudo element flags for the last simple selector.
     * @param props new properties to insert.
     */
    void insert_properties(
        const css_selector_t& selector,
        css::pseudo_element_t pseudo_elem,
        const css_properties_t& props);

    /**
     * Get properties associated with given selector and one or more pseudo
     * elements.
     *
     * @param selector selector to get properties for.
     * @param pseudo_elem pseudo element flags for the last simple selector.
     *                    This value is a bitfield.
     *
     * @return const pointer to the property set instance, or NULL in case
     *         there is no properties for the given selector.
     */
    const css_properties_t* get_properties(
        const css_selector_t& selector, css::pseudo_element_t pseudo_elem) const;

    /**
     * Get all sets of properties associated with given selector, for all
     * pseudo element values.
     *
     * @param selector selector to get properties for.
     *
     * @return const pointer to the map of property sets with pseudo element
     *         values as the keys, or NULL in case there is no properties for
     *         the given selector.
     */
    const css_pseudo_element_properties_t*
        get_all_properties(const css_selector_t& selector) const;

    void dump() const;

    void swap(css_document_tree& other) noexcept;
};

}

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */