Orcus
css_selector.hpp
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 */
7
8#ifndef INCLUDED_ORCUS_CSS_SELECTOR_HPP
9#define INCLUDED_ORCUS_CSS_SELECTOR_HPP
10
11#include "orcus/env.hpp"
12#include "orcus/pstring.hpp"
13#include "orcus/css_types.hpp"
14
15#include <ostream>
16#include <vector>
17#include <unordered_set>
18#include <unordered_map>
19
20namespace orcus {
21
22struct ORCUS_DLLPUBLIC css_simple_selector_t
23{
24 typedef std::unordered_set<pstring, pstring::hash> classes_type;
25
26 pstring name;
27 pstring id;
28 classes_type classes;
29 css::pseudo_class_t pseudo_classes;
30
32
33 void clear();
34 bool empty() const;
35
36 bool operator== (const css_simple_selector_t& r) const;
37 bool operator!= (const css_simple_selector_t& r) const;
38
39 struct hash
40 {
41 size_t operator() (const css_simple_selector_t& ss) const;
42 };
43};
44
45struct ORCUS_DLLPUBLIC css_chained_simple_selector_t
46{
47 css::combinator_t combinator;
48 css_simple_selector_t simple_selector;
49
50 bool operator== (const css_chained_simple_selector_t& r) const;
51
54 css_chained_simple_selector_t(css::combinator_t op, const css_simple_selector_t& ss);
55};
56
60struct ORCUS_DLLPUBLIC css_selector_t
61{
62 typedef std::vector<css_chained_simple_selector_t> chained_type;
64 chained_type chained;
65
66 void clear();
67
68 bool operator== (const css_selector_t& r) const;
69};
70
74struct ORCUS_DLLPUBLIC css_property_value_t
75{
76 css::property_value_t type;
77
78 union
79 {
80 struct
81 {
86 const char* str;
87 uint32_t length;
88 };
89
90 struct
91 {
92 union
93 {
94 struct
95 {
96 uint8_t red;
97 uint8_t green;
98 uint8_t blue;
99 };
100
101 struct
102 {
103 uint16_t hue;
104 uint8_t saturation;
105 uint8_t lightness;
106 };
107 };
108
109 double alpha;
110 };
111 };
112
113 css_property_value_t();
114 css_property_value_t(const css_property_value_t& r);
115
125
126 css_property_value_t& operator= (const css_property_value_t& r);
127
128 void swap(css_property_value_t& r);
129};
130
131typedef std::unordered_map<pstring, std::vector<css_property_value_t>, pstring::hash> css_properties_t;
132typedef std::unordered_map<css::pseudo_element_t, css_properties_t> css_pseudo_element_properties_t;
133
134ORCUS_DLLPUBLIC std::ostream& operator<< (std::ostream& os, const css_simple_selector_t& v);
135ORCUS_DLLPUBLIC std::ostream& operator<< (std::ostream& os, const css_selector_t& v);
136ORCUS_DLLPUBLIC std::ostream& operator<< (std::ostream& os, const css_property_value_t& v);
137
138}
139
140#endif
141
142/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: pstring.hpp:28
Definition: css_selector.hpp:46
Definition: css_selector.hpp:75
uint8_t saturation
0 to 360 where 0-red, 120-green, and 240-blue
Definition: css_selector.hpp:104
const char * str
Definition: css_selector.hpp:86
uint8_t green
0 to 255
Definition: css_selector.hpp:97
css_property_value_t(const pstring &_str)
uint8_t blue
0 to 255
Definition: css_selector.hpp:98
uint8_t lightness
percentage
Definition: css_selector.hpp:105
Definition: css_selector.hpp:61
Definition: css_selector.hpp:40
Definition: css_selector.hpp:23
Definition: pstring.hpp:83