1 /*
2  * This file is part of LibCSS.
3  * Licensed under the MIT License,
4  *                http://www.opensource.org/licenses/mit-license.php
5  * Copyright 2008 John-Mark Bell <jmb@netsurf-browser.org>
6  */
7 
8 #ifndef css_css__parse_properties_utils_h_
9 #define css_css__parse_properties_utils_h_
10 
11 #include "parse/language.h"
12 
is_css_inherit(css_language * c,const css_token * token)13 static inline bool is_css_inherit(css_language *c, const css_token *token)
14 {
15 	bool match;
16 	return ((token->type == CSS_TOKEN_IDENT) &&
17 		(lwc_string_caseless_isequal(
18 			token->idata, c->strings[INHERIT],
19 			&match) == lwc_error_ok && match));
20 }
21 
22 enum border_side_e { BORDER_SIDE_TOP = 0, BORDER_SIDE_RIGHT = 1, BORDER_SIDE_BOTTOM = 2, BORDER_SIDE_LEFT = 3 };
23 
24 /**
25  * Parse border-{top,right,bottom,left} shorthand
26  *
27  * \param c	  Parsing context.
28  * \param vector  Vector of tokens to process.
29  * \param ctx	  Pointer to vector iteration context.
30  * \param result  Result style.
31  * \param side	  The side we're parsing for.
32  * \return CSS_OK on success,
33  *	   CSS_NOMEM on memory exhaustion,
34  *	   CSS_INVALID if the input is not valid
35  *
36  * Post condition: \a *ctx is updated with the next token to process
37  *		   If the input is invalid, then \a *ctx remains unchanged.
38  */
39 css_error css__parse_border_side(css_language *c,
40 		const parserutils_vector *vector, int *ctx,
41 		css_style *result, enum border_side_e side);
42 
43 /**
44  * Parse border-{top,right,bottom,left}-color
45  *
46  * \param c	  Parsing context
47  * \param vector  Vector of tokens to process
48  * \param ctx	  Pointer to vector iteration context
49  * \param result  Pointer to location to receive resulting style
50  * \param op	  Opcode to parse for (encodes side)
51  * \return CSS_OK on success,
52  *	   CSS_NOMEM on memory exhaustion,
53  *	   CSS_INVALID if the input is not valid
54  *
55  * Post condition: \a *ctx is updated with the next token to process
56  *		   If the input is invalid, then \a *ctx remains unchanged.
57  */
58 css_error css__parse_border_side_color(css_language *c,
59 		const parserutils_vector *vector, int *ctx,
60 		css_style *result, enum css_properties_e op);
61 
62 /**
63  * Parse border-{top,right,bottom,left}-style
64  *
65  * \param c	  Parsing context
66  * \param vector  Vector of tokens to process
67  * \param ctx	  Pointer to vector iteration context
68  * \param result  Pointer to location to receive resulting style
69  * \param op	  Opcode to parse for (encodes side)
70  * \return CSS_OK on success,
71  *	   CSS_NOMEM on memory exhaustion,
72  *	   CSS_INVALID if the input is not valid
73  *
74  * Post condition: \a *ctx is updated with the next token to process
75  *		   If the input is invalid, then \a *ctx remains unchanged.
76  */
77 css_error css__parse_border_side_style(css_language *c,
78 		const parserutils_vector *vector, int *ctx,
79 		css_style *result, enum css_properties_e op);
80 
81 
82 /**
83  * Parse border-{top,right,bottom,left}-width
84  *
85  * \param c	  Parsing context
86  * \param vector  Vector of tokens to process
87  * \param ctx	  Pointer to vector iteration context
88  * \param result  Pointer to location to receive resulting style
89  * \param op	  Opcode to parse for (encodes side)
90  * \return CSS_OK on success,
91  *	   CSS_NOMEM on memory exhaustion,
92  *	   CSS_INVALID if the input is not valid
93  *
94  * Post condition: \a *ctx is updated with the next token to process
95  *		   If the input is invalid, then \a *ctx remains unchanged.
96  */
97 css_error css__parse_border_side_width(css_language *c,
98 		const parserutils_vector *vector, int *ctx,
99 		css_style *result, enum css_properties_e op);
100 
101 
102 /**
103  * Parse {top,right,bottom,left}
104  *
105  * \param c       Parsing context
106  * \param vector  Vector of tokens to process
107  * \param ctx     Pointer to vector iteration context
108  * \param op      Opcode to parse for
109  * \param result  Pointer to location to receive resulting style
110  * \return CSS_OK on success,
111  *         CSS_NOMEM on memory exhaustion,
112  *         CSS_INVALID if the input is not valid
113  *
114  * Post condition: \a *ctx is updated with the next token to process
115  *                 If the input is invalid, then \a *ctx remains unchanged.
116  */
117 css_error css__parse_side(css_language *c,
118 		const parserutils_vector *vector, int *ctx,
119 		css_style *result, enum css_properties_e op);
120 
121 
122 /**
123  * Parse margin-{top,right,bottom,left}
124  *
125  * \param c	  Parsing context
126  * \param vector  Vector of tokens to process
127  * \param ctx	  Pointer to vector iteration context
128  * \param result  Pointer to location to receive resulting style
129  * \return CSS_OK on success,
130  *	   CSS_NOMEM on memory exhaustion,
131  *	   CSS_INVALID if the input is not valid
132  *
133  * Post condition: \a *ctx is updated with the next token to process
134  *		   If the input is invalid, then \a *ctx remains unchanged.
135  */
136 css_error css__parse_margin_side(css_language *c,
137 		const parserutils_vector *vector, int *ctx,
138 		css_style *result, enum css_properties_e op);
139 
140 /**
141  * Parse padding-{top,right,bottom,left}
142  *
143  * \param c	  Parsing context
144  * \param vector  Vector of tokens to process
145  * \param ctx	  Pointer to vector iteration context
146  * \param result  Pointer to location to receive resulting style
147  * \return CSS_OK on success,
148  *	   CSS_NOMEM on memory exhaustion,
149  *	   CSS_INVALID if the input is not valid
150  *
151  * Post condition: \a *ctx is updated with the next token to process
152  *		   If the input is invalid, then \a *ctx remains unchanged.
153  */
154 css_error css__parse_padding_side(css_language *c,
155 		const parserutils_vector *vector, int *ctx,
156 		css_style *result, enum css_properties_e op);
157 
158 
159 
160 
161 
162 
163 
164 css_error css__parse_list_style_type_value(css_language *c,
165 		const css_token *token, uint16_t *value);
166 
167 css_error css__parse_colour_specifier(css_language *c,
168 		const parserutils_vector *vector, int *ctx,
169 		uint16_t *value, uint32_t *result);
170 
171 css_error css__parse_named_colour(css_language *c, lwc_string *data,
172 		uint32_t *result);
173 
174 css_error css__parse_hash_colour(lwc_string *data, uint32_t *result);
175 
176 css_error css__parse_unit_specifier(css_language *c,
177 		const parserutils_vector *vector, int *ctx,
178 		uint32_t default_unit,
179 		css_fixed *length, uint32_t *unit);
180 
181 css_error css__parse_unit_keyword(const char *ptr, size_t len,
182 		uint32_t *unit);
183 
184 css_error css__ident_list_or_string_to_string(css_language *c,
185 		const parserutils_vector *vector, int *ctx,
186 		bool (*reserved)(css_language *c, const css_token *ident),
187 		lwc_string **result);
188 
189 css_error css__ident_list_to_string(css_language *c,
190 		const parserutils_vector *vector, int *ctx,
191 		bool (*reserved)(css_language *c, const css_token *ident),
192 		lwc_string **result);
193 
194 css_error css__comma_list_to_style(css_language *c,
195 		const parserutils_vector *vector, int *ctx,
196 		bool (*reserved)(css_language *c, const css_token *ident),
197 		css_code_t (*get_value)(css_language *c,
198 				const css_token *token,
199 				bool first),
200 		css_style *result);
201 
202 #endif
203