Photon 1.0.0
Loading...
Searching...
No Matches
style.h
Go to the documentation of this file.
1#ifndef LH_STYLE_H
2#define LH_STYLE_H
3
4#include "css_tokenizer.h"
5
6namespace litehtml
7{
8 struct invalid {}; // indicates "not found" condition in style::get_property
9 struct inherit {}; // "inherit" was specified as the value of this property
10
12 invalid,
13 inherit,
14 int,
15 int_vector,
16 css_length,
17 length_vector,
18 float,
19 web_color,
20 vector<image>,
21 string,
22 string_vector,
23 size_vector,
24 css_token_vector
25 >
26 {
27 bool m_important = false;
28 bool m_has_var = false; // css_token_vector, parsing is delayed because of var()
29
31 template<class T> property_value(const T& val, bool important, bool has_var = false)
32 : base(val), m_important(important), m_has_var(has_var) {}
33 };
34
35 class html_tag;
36 typedef std::map<string_id, property_value> props_map;
37
38 // represents a style block, eg. "color: black; display: inline"
39 class style
40 {
41 public:
42 typedef std::shared_ptr<style> ptr;
43 typedef std::vector<style::ptr> vector;
44 private:
46 static std::map<string_id, string> m_valid_values;
47 public:
48 void add(const css_token_vector& tokens, const string& baseurl = "", document_container* container = nullptr);
49 void add(const string& txt, const string& baseurl = "", document_container* container = nullptr);
50
51 void add_property(string_id name, const css_token_vector& tokens, const string& baseurl = "", bool important = false, document_container* container = nullptr);
52 void add_property(string_id name, const string& val, const string& baseurl = "", bool important = false, document_container* container = nullptr);
53
55
56 void combine(const style& src);
57 void clear()
58 {
59 m_properties.clear();
60 }
61
62 void subst_vars(const html_tag* el);
63
64 private:
65 void inherit_property(string_id name, bool important);
66
67 void parse_background(const css_token_vector& tokens, const string& baseurl, bool important, document_container* container);
69 // parse the value of background-image property, which is comma-separated list of <bg-image>s
70 void parse_background_image(const css_token_vector& tokens, const string& baseurl, bool important, document_container* container);
71
72 // parse comma-separated list of keywords
74 void parse_background_position(const css_token_vector& tokens, bool important);
75 void parse_background_size(const css_token_vector& tokens, bool important);
76
77 void parse_border(const css_token_vector& tokens, bool important, document_container* container);
78 void parse_border_side(string_id name, const css_token_vector& tokens, bool important, document_container* container);
79 void parse_border_radius(const css_token_vector& tokens, bool important);
80
81 bool parse_list_style_image(const css_token& tok, string& url);
82 void parse_list_style(const css_token_vector& tokens, string baseurl, bool important);
83
84 void parse_font(css_token_vector tokens, bool important);
85
86 void parse_flex_flow(const css_token_vector& tokens, bool important);
87 void parse_flex(const css_token_vector& tokens, bool important);
88 void parse_align_self(string_id name, const css_token_vector& tokens, bool important);
89
91 void add_length_property(string_id name, css_token val, string keywords, int options, bool important);
92 template<class T> void add_four_properties(string_id top_name, T val[4], int n, bool important);
93 void remove_property(string_id name, bool important);
94 };
95
96 bool parse_url(const css_token& token, string& url);
97 bool parse_length(const css_token& tok, css_length& length, int options, string keywords = "");
98 bool parse_angle(const css_token& tok, float& angle, bool percents_allowed = false);
99 bool parse_bg_position(const css_token_vector& tokens, int& index, css_length& x, css_length& y, bool convert_keywords_to_percents);
100
101 template<typename Enum>
102 bool parse_keyword(const css_token& tok, Enum& val, string keywords, int first_keyword_value = 0)
103 {
104 int value_index(const string& val, const string& strings, int defValue = -1, char delim = ';');
105 int idx = value_index(tok.ident(), keywords);
106 if (idx == -1) return false;
107 val = (Enum)(first_keyword_value + idx);
108 return true;
109 }
110
111} // namespace litehtml
112
113#endif // LH_STYLE_H
Definition background.h:91
Definition document_container.h:34
Definition html_tag.h:18
Definition style.h:40
void subst_vars(const html_tag *el)
Definition style.cpp:1504
void parse_background(const css_token_vector &tokens, const string &baseurl, bool important, document_container *container)
Definition style.cpp:750
void parse_background_image(const css_token_vector &tokens, const string &baseurl, bool important, document_container *container)
Definition style.cpp:950
void combine(const style &src)
Definition style.cpp:1423
void parse_background_position(const css_token_vector &tokens, bool important)
Definition style.cpp:1036
static std::map< string_id, string > m_valid_values
Definition style.h:46
const property_value & get_property(string_id name) const
Definition style.cpp:1431
void parse_font(css_token_vector tokens, bool important)
Definition style.cpp:1191
void parse_border(const css_token_vector &tokens, bool important, document_container *container)
Definition style.cpp:650
void parse_border_side(string_id name, const css_token_vector &tokens, bool important, document_container *container)
Definition style.cpp:671
void parse_list_style(const css_token_vector &tokens, string baseurl, bool important)
Definition style.cpp:518
bool parse_list_style_image(const css_token &tok, string &url)
Definition style.cpp:505
void parse_keyword_comma_list(string_id name, const css_token_vector &tokens, bool important)
Definition style.cpp:1018
std::vector< style::ptr > vector
Definition style.h:43
void remove_property(string_id name, bool important)
Definition style.cpp:1411
void clear()
Definition style.h:57
void parse_background_size(const css_token_vector &tokens, bool important)
Definition style.cpp:1058
void add_property(string_id name, const css_token_vector &tokens, const string &baseurl="", bool important=false, document_container *container=nullptr)
Definition style.cpp:166
void parse_border_radius(const css_token_vector &tokens, bool important)
Definition style.cpp:572
void add(const css_token_vector &tokens, const string &baseurl="", document_container *container=nullptr)
Definition style.cpp:113
props_map m_properties
Definition style.h:45
void add_parsed_property(string_id name, const property_value &propval)
Definition style.cpp:1395
bool parse_bg_layer(const css_token_vector &tokens, document_container *container, background &bg, bool final_layer)
Definition style.cpp:793
void parse_flex_flow(const css_token_vector &tokens, bool important)
Definition style.cpp:1325
void add_length_property(string_id name, css_token val, string keywords, int options, bool important)
Definition style.cpp:158
void parse_flex(const css_token_vector &tokens, bool important)
Definition style.cpp:1239
void add_four_properties(string_id top_name, T val[4], int n, bool important)
Definition style.cpp:730
void inherit_property(string_id name, bool important)
Definition style.cpp:146
void parse_align_self(string_id name, const css_token_vector &tokens, bool important)
Definition style.cpp:1353
std::shared_ptr< style > ptr
Definition style.h:42
Definition url.h:41
FMT_CONSTEXPR text_style bg(detail::color_type background) noexcept
Definition color.h:363
Definition background.h:12
bool parse_length(const css_token &tok, css_length &length, int options, string keywords="")
Definition style.cpp:685
vector< css_token > css_token_vector
Definition css_tokenizer.h:151
bool parse_bg_position(const css_token_vector &tokens, int &index, css_length &x, css_length &y, bool convert_keywords_to_percents)
Definition style.cpp:896
bool parse_angle(const css_token &tok, float &angle, bool percents_allowed=false)
Definition gradient.cpp:353
bool has_var(const css_token_vector &tokens)
Definition style.cpp:134
const char * name
Definition encodings.cpp:1358
bool parse_keyword(const css_token &tok, Enum &val, string keywords, int first_keyword_value=0)
Definition style.h:102
std::map< string_id, property_value > props_map
Definition style.h:36
int value_index(const string &val, const string &strings, int defValue=-1, char delim=';')
Definition html.cpp:76
bool parse_url(const css_token &token, string &url)
Definition style.cpp:999
Definition css_tokenizer.h:69
string ident() const
Definition css_tokenizer.cpp:12
Definition style.h:9
Definition style.h:8
Definition style.h:26
bool m_has_var
Definition style.h:28
property_value(const T &val, bool important, bool has_var=false)
Definition style.h:31
property_value()
Definition style.h:30
bool m_important
Definition style.h:27
Definition types.h:38