Photon 1.0.0
Loading...
Searching...
No Matches
stylesheet.h
Go to the documentation of this file.
1#ifndef LH_STYLESHEET_H
2#define LH_STYLESHEET_H
3
4#include "style.h"
5#include "css_selector.h"
6#include "css_tokenizer.h"
7
8namespace litehtml
9{
10
11// https://www.w3.org/TR/cssom-1/#css-declarations
13{
14 using vector = std::vector<raw_declaration>;
15
16 string name; // property name
17 css_token_vector value = {}; // default value is specified here to get rid of gcc warning "missing initializer for member"
18 bool important = false;
19
20 operator bool() const { return name != ""; }
21};
22
23// intermediate half-parsed rule that is used internally by the parser
25{
26public:
28 using vector = std::vector<ptr>;
29
31
32 raw_rule(rule_type type, string name = "") : type(type), name(name) {}
33
35 // An at-rule has a name, a prelude consisting of a list of component values, and an optional block consisting of a simple {} block.
36 string name;
37 // https://www.w3.org/TR/css-syntax-3/#qualified-rule
38 // A qualified rule has a prelude consisting of a list of component values, and a block consisting of a simple {} block.
39 // Note: Most qualified rules will be style rules, where the prelude is a selector and the block a list of declarations.
42};
43
44class css
45{
47public:
48
50 {
51 return m_selectors;
52 }
53
54 template<class Input>
55 void parse_css_stylesheet(const Input& input, string baseurl, shared_ptr<document> doc, media_query_list_list::ptr media = nullptr, bool top_level = true);
56
57 void sort_selectors();
58
59private:
60 bool parse_style_rule(raw_rule::ptr rule, string baseurl, shared_ptr<document> doc, media_query_list_list::ptr media);
61 void parse_import_rule(raw_rule::ptr rule, string baseurl, shared_ptr<document> doc, media_query_list_list::ptr media);
62 void add_selector(const css_selector::ptr& selector);
63};
64
65inline void css::add_selector(const css_selector::ptr& selector)
66{
67 selector->m_order = (int)m_selectors.size();
68 m_selectors.push_back(selector);
69}
70
71
72} // namespace litehtml
73
74#endif // LH_STYLESHEET_H
shared_ptr< css_selector > ptr
Definition css_selector.h:197
std::vector< css_selector::ptr > vector
Definition css_selector.h:198
Definition stylesheet.h:45
void parse_import_rule(raw_rule::ptr rule, string baseurl, shared_ptr< document > doc, media_query_list_list::ptr media)
Definition stylesheet.cpp:71
void parse_css_stylesheet(const Input &input, string baseurl, shared_ptr< document > doc, media_query_list_list::ptr media=nullptr, bool top_level=true)
bool parse_style_rule(raw_rule::ptr rule, string baseurl, shared_ptr< document > doc, media_query_list_list::ptr media)
Definition stylesheet.cpp:107
const css_selector::vector & selectors() const
Definition stylesheet.h:49
void add_selector(const css_selector::ptr &selector)
Definition stylesheet.h:65
css_selector::vector m_selectors
Definition stylesheet.h:46
void sort_selectors()
Definition stylesheet.cpp:131
shared_ptr< media_query_list_list > ptr
Definition media_query.h:99
Definition stylesheet.h:25
css_token block
Definition stylesheet.h:41
rule_type
Definition stylesheet.h:30
@ qualified
Definition stylesheet.h:30
@ at
Definition stylesheet.h:30
rule_type type
Definition stylesheet.h:34
shared_ptr< raw_rule > ptr
Definition stylesheet.h:27
std::vector< ptr > vector
Definition stylesheet.h:28
css_token_vector prelude
Definition stylesheet.h:40
raw_rule(rule_type type, string name="")
Definition stylesheet.h:32
string name
Definition stylesheet.h:36
Definition core.h:1598
type
Definition core.h:681
Definition background.h:12
vector< css_token > css_token_vector
Definition css_tokenizer.h:151
Definition css_tokenizer.h:69
Definition stylesheet.h:13
std::vector< raw_declaration > vector
Definition stylesheet.h:14
bool important
Definition stylesheet.h:18
string name
Definition stylesheet.h:16
annotation input
Definition tag_strings.h:114