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 2017 The NetSurf Project
6  */
7 
8 /** Default values are 'initial value', unless the property is inherited,
9  *  in which case it is 'inherit'. */
10 
11 #define ALIGN_CONTENT_INDEX 9
12 #define ALIGN_CONTENT_SHIFT 17
13 #define ALIGN_CONTENT_MASK 0xe0000
14 
set_align_content(css_computed_style * style,uint8_t type)15 static inline css_error set_align_content(css_computed_style *style, uint8_t
16 		type)
17 {
18 	uint32_t *bits;
19 
20 	bits = &style->i.bits[ALIGN_CONTENT_INDEX];
21 
22 	/* 3bits: ttt : type */
23 	*bits = (*bits & ~ALIGN_CONTENT_MASK) | (((uint32_t)type & 0x7) <<
24 			ALIGN_CONTENT_SHIFT);
25 
26 	return CSS_OK;
27 }
28 #undef ALIGN_CONTENT_INDEX
29 #undef ALIGN_CONTENT_SHIFT
30 #undef ALIGN_CONTENT_MASK
31 
32 #define ALIGN_ITEMS_INDEX 9
33 #define ALIGN_ITEMS_SHIFT 29
34 #define ALIGN_ITEMS_MASK 0xe0000000
35 
set_align_items(css_computed_style * style,uint8_t type)36 static inline css_error set_align_items(css_computed_style *style, uint8_t type)
37 {
38 	uint32_t *bits;
39 
40 	bits = &style->i.bits[ALIGN_ITEMS_INDEX];
41 
42 	/* 3bits: ttt : type */
43 	*bits = (*bits & ~ALIGN_ITEMS_MASK) | (((uint32_t)type & 0x7) <<
44 			ALIGN_ITEMS_SHIFT);
45 
46 	return CSS_OK;
47 }
48 #undef ALIGN_ITEMS_INDEX
49 #undef ALIGN_ITEMS_SHIFT
50 #undef ALIGN_ITEMS_MASK
51 
52 #define ALIGN_SELF_INDEX 9
53 #define ALIGN_SELF_SHIFT 20
54 #define ALIGN_SELF_MASK 0x700000
55 
set_align_self(css_computed_style * style,uint8_t type)56 static inline css_error set_align_self(css_computed_style *style, uint8_t type)
57 {
58 	uint32_t *bits;
59 
60 	bits = &style->i.bits[ALIGN_SELF_INDEX];
61 
62 	/* 3bits: ttt : type */
63 	*bits = (*bits & ~ALIGN_SELF_MASK) | (((uint32_t)type & 0x7) <<
64 			ALIGN_SELF_SHIFT);
65 
66 	return CSS_OK;
67 }
68 #undef ALIGN_SELF_INDEX
69 #undef ALIGN_SELF_SHIFT
70 #undef ALIGN_SELF_MASK
71 
72 #define BACKGROUND_ATTACHMENT_INDEX 10
73 #define BACKGROUND_ATTACHMENT_SHIFT 8
74 #define BACKGROUND_ATTACHMENT_MASK 0x300
75 
set_background_attachment(css_computed_style * style,uint8_t type)76 static inline css_error set_background_attachment(css_computed_style *style,
77 		uint8_t type)
78 {
79 	uint32_t *bits;
80 
81 	bits = &style->i.bits[BACKGROUND_ATTACHMENT_INDEX];
82 
83 	/* 2bits: tt : type */
84 	*bits = (*bits & ~BACKGROUND_ATTACHMENT_MASK) | (((uint32_t)type & 0x3)
85 			<< BACKGROUND_ATTACHMENT_SHIFT);
86 
87 	return CSS_OK;
88 }
89 #undef BACKGROUND_ATTACHMENT_INDEX
90 #undef BACKGROUND_ATTACHMENT_SHIFT
91 #undef BACKGROUND_ATTACHMENT_MASK
92 
93 #define BACKGROUND_COLOR_INDEX 10
94 #define BACKGROUND_COLOR_SHIFT 2
95 #define BACKGROUND_COLOR_MASK 0xc
96 
set_background_color(css_computed_style * style,uint8_t type,css_color color)97 static inline css_error set_background_color(css_computed_style *style, uint8_t
98 		type, css_color color)
99 {
100 	uint32_t *bits;
101 
102 	bits = &style->i.bits[BACKGROUND_COLOR_INDEX];
103 
104 	/* 2bits: tt : type */
105 	*bits = (*bits & ~BACKGROUND_COLOR_MASK) | (((uint32_t)type & 0x3) <<
106 			BACKGROUND_COLOR_SHIFT);
107 
108 	style->i.background_color = color;
109 
110 	return CSS_OK;
111 }
112 #undef BACKGROUND_COLOR_INDEX
113 #undef BACKGROUND_COLOR_SHIFT
114 #undef BACKGROUND_COLOR_MASK
115 
116 #define BACKGROUND_IMAGE_INDEX 14
117 #define BACKGROUND_IMAGE_SHIFT 28
118 #define BACKGROUND_IMAGE_MASK 0x10000000
119 
set_background_image(css_computed_style * style,uint8_t type,lwc_string * string)120 static inline css_error set_background_image(css_computed_style *style, uint8_t
121 		type, lwc_string *string)
122 {
123 	uint32_t *bits;
124 
125 	bits = &style->i.bits[BACKGROUND_IMAGE_INDEX];
126 
127 	/* 1bit: t : type */
128 	*bits = (*bits & ~BACKGROUND_IMAGE_MASK) | (((uint32_t)type & 0x1) <<
129 			BACKGROUND_IMAGE_SHIFT);
130 
131 	lwc_string *old_string = style->i.background_image;
132 
133 	if (string != NULL) {
134 		style->i.background_image = lwc_string_ref(string);
135 	} else {
136 		style->i.background_image = NULL;
137 	}
138 
139 	if (old_string != NULL)
140 		lwc_string_unref(old_string);
141 
142 	return CSS_OK;
143 }
144 #undef BACKGROUND_IMAGE_INDEX
145 #undef BACKGROUND_IMAGE_SHIFT
146 #undef BACKGROUND_IMAGE_MASK
147 
148 #define BACKGROUND_POSITION_INDEX 12
149 #define BACKGROUND_POSITION_SHIFT 10
150 #define BACKGROUND_POSITION_MASK 0x1ffc00
151 
set_background_position(css_computed_style * style,uint8_t type,css_fixed length_a,css_unit unit_a,css_fixed length_b,css_unit unit_b)152 static inline css_error set_background_position(css_computed_style *style,
153 		uint8_t type, css_fixed length_a, css_unit unit_a, css_fixed
154 		length_b, css_unit unit_b)
155 {
156 	uint32_t *bits;
157 
158 	bits = &style->i.bits[BACKGROUND_POSITION_INDEX];
159 
160 	/* 11bits: aaaaabbbbbt : unit_a | unit_b | type */
161 	*bits = (*bits & ~BACKGROUND_POSITION_MASK) | ((((uint32_t)type & 0x1)
162 			| (unit_b << 1) | (unit_a << 6)) <<
163 			BACKGROUND_POSITION_SHIFT);
164 
165 	style->i.background_position_a = length_a;
166 
167 	style->i.background_position_b = length_b;
168 
169 	return CSS_OK;
170 }
171 #undef BACKGROUND_POSITION_INDEX
172 #undef BACKGROUND_POSITION_SHIFT
173 #undef BACKGROUND_POSITION_MASK
174 
175 #define BACKGROUND_REPEAT_INDEX 13
176 #define BACKGROUND_REPEAT_SHIFT 1
177 #define BACKGROUND_REPEAT_MASK 0xe
178 
set_background_repeat(css_computed_style * style,uint8_t type)179 static inline css_error set_background_repeat(css_computed_style *style,
180 		uint8_t type)
181 {
182 	uint32_t *bits;
183 
184 	bits = &style->i.bits[BACKGROUND_REPEAT_INDEX];
185 
186 	/* 3bits: ttt : type */
187 	*bits = (*bits & ~BACKGROUND_REPEAT_MASK) | (((uint32_t)type & 0x7) <<
188 			BACKGROUND_REPEAT_SHIFT);
189 
190 	return CSS_OK;
191 }
192 #undef BACKGROUND_REPEAT_INDEX
193 #undef BACKGROUND_REPEAT_SHIFT
194 #undef BACKGROUND_REPEAT_MASK
195 
196 #define BORDER_BOTTOM_COLOR_INDEX 11
197 #define BORDER_BOTTOM_COLOR_SHIFT 28
198 #define BORDER_BOTTOM_COLOR_MASK 0x30000000
199 
set_border_bottom_color(css_computed_style * style,uint8_t type,css_color color)200 static inline css_error set_border_bottom_color(css_computed_style *style,
201 		uint8_t type, css_color color)
202 {
203 	uint32_t *bits;
204 
205 	bits = &style->i.bits[BORDER_BOTTOM_COLOR_INDEX];
206 
207 	/* 2bits: tt : type */
208 	*bits = (*bits & ~BORDER_BOTTOM_COLOR_MASK) | (((uint32_t)type & 0x3)
209 			<< BORDER_BOTTOM_COLOR_SHIFT);
210 
211 	style->i.border_bottom_color = color;
212 
213 	return CSS_OK;
214 }
215 #undef BORDER_BOTTOM_COLOR_INDEX
216 #undef BORDER_BOTTOM_COLOR_SHIFT
217 #undef BORDER_BOTTOM_COLOR_MASK
218 
219 #define BORDER_BOTTOM_STYLE_INDEX 13
220 #define BORDER_BOTTOM_STYLE_SHIFT 8
221 #define BORDER_BOTTOM_STYLE_MASK 0xf00
222 
set_border_bottom_style(css_computed_style * style,uint8_t type)223 static inline css_error set_border_bottom_style(css_computed_style *style,
224 		uint8_t type)
225 {
226 	uint32_t *bits;
227 
228 	bits = &style->i.bits[BORDER_BOTTOM_STYLE_INDEX];
229 
230 	/* 4bits: tttt : type */
231 	*bits = (*bits & ~BORDER_BOTTOM_STYLE_MASK) | (((uint32_t)type & 0xf)
232 			<< BORDER_BOTTOM_STYLE_SHIFT);
233 
234 	return CSS_OK;
235 }
236 #undef BORDER_BOTTOM_STYLE_INDEX
237 #undef BORDER_BOTTOM_STYLE_SHIFT
238 #undef BORDER_BOTTOM_STYLE_MASK
239 
240 #define BORDER_BOTTOM_WIDTH_INDEX 0
241 #define BORDER_BOTTOM_WIDTH_SHIFT 0
242 #define BORDER_BOTTOM_WIDTH_MASK 0xff
243 
set_border_bottom_width(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)244 static inline css_error set_border_bottom_width(css_computed_style *style,
245 		uint8_t type, css_fixed length, css_unit unit)
246 {
247 	uint32_t *bits;
248 
249 	bits = &style->i.bits[BORDER_BOTTOM_WIDTH_INDEX];
250 
251 	/* 8bits: uuuuuttt : unit | type */
252 	*bits = (*bits & ~BORDER_BOTTOM_WIDTH_MASK) | ((((uint32_t)type & 0x7)
253 			| (unit << 3)) << BORDER_BOTTOM_WIDTH_SHIFT);
254 
255 	style->i.border_bottom_width = length;
256 
257 	return CSS_OK;
258 }
259 #undef BORDER_BOTTOM_WIDTH_INDEX
260 #undef BORDER_BOTTOM_WIDTH_SHIFT
261 #undef BORDER_BOTTOM_WIDTH_MASK
262 
263 #define BORDER_COLLAPSE_INDEX 11
264 #define BORDER_COLLAPSE_SHIFT 16
265 #define BORDER_COLLAPSE_MASK 0x30000
266 
set_border_collapse(css_computed_style * style,uint8_t type)267 static inline css_error set_border_collapse(css_computed_style *style, uint8_t
268 		type)
269 {
270 	uint32_t *bits;
271 
272 	bits = &style->i.bits[BORDER_COLLAPSE_INDEX];
273 
274 	/* 2bits: tt : type */
275 	*bits = (*bits & ~BORDER_COLLAPSE_MASK) | (((uint32_t)type & 0x3) <<
276 			BORDER_COLLAPSE_SHIFT);
277 
278 	return CSS_OK;
279 }
280 #undef BORDER_COLLAPSE_INDEX
281 #undef BORDER_COLLAPSE_SHIFT
282 #undef BORDER_COLLAPSE_MASK
283 
284 #define BORDER_LEFT_COLOR_INDEX 10
285 #define BORDER_LEFT_COLOR_SHIFT 0
286 #define BORDER_LEFT_COLOR_MASK 0x3
287 
set_border_left_color(css_computed_style * style,uint8_t type,css_color color)288 static inline css_error set_border_left_color(css_computed_style *style,
289 		uint8_t type, css_color color)
290 {
291 	uint32_t *bits;
292 
293 	bits = &style->i.bits[BORDER_LEFT_COLOR_INDEX];
294 
295 	/* 2bits: tt : type */
296 	*bits = (*bits & ~BORDER_LEFT_COLOR_MASK) | (((uint32_t)type & 0x3) <<
297 			BORDER_LEFT_COLOR_SHIFT);
298 
299 	style->i.border_left_color = color;
300 
301 	return CSS_OK;
302 }
303 #undef BORDER_LEFT_COLOR_INDEX
304 #undef BORDER_LEFT_COLOR_SHIFT
305 #undef BORDER_LEFT_COLOR_MASK
306 
307 #define BORDER_LEFT_STYLE_INDEX 13
308 #define BORDER_LEFT_STYLE_SHIFT 12
309 #define BORDER_LEFT_STYLE_MASK 0xf000
310 
set_border_left_style(css_computed_style * style,uint8_t type)311 static inline css_error set_border_left_style(css_computed_style *style,
312 		uint8_t type)
313 {
314 	uint32_t *bits;
315 
316 	bits = &style->i.bits[BORDER_LEFT_STYLE_INDEX];
317 
318 	/* 4bits: tttt : type */
319 	*bits = (*bits & ~BORDER_LEFT_STYLE_MASK) | (((uint32_t)type & 0xf) <<
320 			BORDER_LEFT_STYLE_SHIFT);
321 
322 	return CSS_OK;
323 }
324 #undef BORDER_LEFT_STYLE_INDEX
325 #undef BORDER_LEFT_STYLE_SHIFT
326 #undef BORDER_LEFT_STYLE_MASK
327 
328 #define BORDER_LEFT_WIDTH_INDEX 0
329 #define BORDER_LEFT_WIDTH_SHIFT 8
330 #define BORDER_LEFT_WIDTH_MASK 0xff00
331 
set_border_left_width(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)332 static inline css_error set_border_left_width(css_computed_style *style,
333 		uint8_t type, css_fixed length, css_unit unit)
334 {
335 	uint32_t *bits;
336 
337 	bits = &style->i.bits[BORDER_LEFT_WIDTH_INDEX];
338 
339 	/* 8bits: uuuuuttt : unit | type */
340 	*bits = (*bits & ~BORDER_LEFT_WIDTH_MASK) | ((((uint32_t)type & 0x7) | (
341 			unit << 3)) << BORDER_LEFT_WIDTH_SHIFT);
342 
343 	style->i.border_left_width = length;
344 
345 	return CSS_OK;
346 }
347 #undef BORDER_LEFT_WIDTH_INDEX
348 #undef BORDER_LEFT_WIDTH_SHIFT
349 #undef BORDER_LEFT_WIDTH_MASK
350 
351 #define BORDER_RIGHT_COLOR_INDEX 11
352 #define BORDER_RIGHT_COLOR_SHIFT 8
353 #define BORDER_RIGHT_COLOR_MASK 0x300
354 
set_border_right_color(css_computed_style * style,uint8_t type,css_color color)355 static inline css_error set_border_right_color(css_computed_style *style,
356 		uint8_t type, css_color color)
357 {
358 	uint32_t *bits;
359 
360 	bits = &style->i.bits[BORDER_RIGHT_COLOR_INDEX];
361 
362 	/* 2bits: tt : type */
363 	*bits = (*bits & ~BORDER_RIGHT_COLOR_MASK) | (((uint32_t)type & 0x3) <<
364 			BORDER_RIGHT_COLOR_SHIFT);
365 
366 	style->i.border_right_color = color;
367 
368 	return CSS_OK;
369 }
370 #undef BORDER_RIGHT_COLOR_INDEX
371 #undef BORDER_RIGHT_COLOR_SHIFT
372 #undef BORDER_RIGHT_COLOR_MASK
373 
374 #define BORDER_RIGHT_STYLE_INDEX 8
375 #define BORDER_RIGHT_STYLE_SHIFT 0
376 #define BORDER_RIGHT_STYLE_MASK 0xf
377 
set_border_right_style(css_computed_style * style,uint8_t type)378 static inline css_error set_border_right_style(css_computed_style *style,
379 		uint8_t type)
380 {
381 	uint32_t *bits;
382 
383 	bits = &style->i.bits[BORDER_RIGHT_STYLE_INDEX];
384 
385 	/* 4bits: tttt : type */
386 	*bits = (*bits & ~BORDER_RIGHT_STYLE_MASK) | (((uint32_t)type & 0xf) <<
387 			BORDER_RIGHT_STYLE_SHIFT);
388 
389 	return CSS_OK;
390 }
391 #undef BORDER_RIGHT_STYLE_INDEX
392 #undef BORDER_RIGHT_STYLE_SHIFT
393 #undef BORDER_RIGHT_STYLE_MASK
394 
395 #define BORDER_RIGHT_WIDTH_INDEX 1
396 #define BORDER_RIGHT_WIDTH_SHIFT 7
397 #define BORDER_RIGHT_WIDTH_MASK 0x7f80
398 
set_border_right_width(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)399 static inline css_error set_border_right_width(css_computed_style *style,
400 		uint8_t type, css_fixed length, css_unit unit)
401 {
402 	uint32_t *bits;
403 
404 	bits = &style->i.bits[BORDER_RIGHT_WIDTH_INDEX];
405 
406 	/* 8bits: uuuuuttt : unit | type */
407 	*bits = (*bits & ~BORDER_RIGHT_WIDTH_MASK) | ((((uint32_t)type & 0x7) |
408 			(unit << 3)) << BORDER_RIGHT_WIDTH_SHIFT);
409 
410 	style->i.border_right_width = length;
411 
412 	return CSS_OK;
413 }
414 #undef BORDER_RIGHT_WIDTH_INDEX
415 #undef BORDER_RIGHT_WIDTH_SHIFT
416 #undef BORDER_RIGHT_WIDTH_MASK
417 
418 #define BORDER_SPACING_INDEX 12
419 #define BORDER_SPACING_SHIFT 21
420 #define BORDER_SPACING_MASK 0xffe00000
421 
set_border_spacing(css_computed_style * style,uint8_t type,css_fixed length_a,css_unit unit_a,css_fixed length_b,css_unit unit_b)422 static inline css_error set_border_spacing(css_computed_style *style, uint8_t
423 		type, css_fixed length_a, css_unit unit_a, css_fixed length_b,
424 		css_unit unit_b)
425 {
426 	uint32_t *bits;
427 
428 	bits = &style->i.bits[BORDER_SPACING_INDEX];
429 
430 	/* 11bits: aaaaabbbbbt : unit_a | unit_b | type */
431 	*bits = (*bits & ~BORDER_SPACING_MASK) | ((((uint32_t)type & 0x1) | (
432 			unit_b << 1) | (unit_a << 6)) << BORDER_SPACING_SHIFT);
433 
434 	style->i.border_spacing_a = length_a;
435 
436 	style->i.border_spacing_b = length_b;
437 
438 	return CSS_OK;
439 }
440 #undef BORDER_SPACING_INDEX
441 #undef BORDER_SPACING_SHIFT
442 #undef BORDER_SPACING_MASK
443 
444 #define BORDER_TOP_COLOR_INDEX 11
445 #define BORDER_TOP_COLOR_SHIFT 26
446 #define BORDER_TOP_COLOR_MASK 0xc000000
447 
set_border_top_color(css_computed_style * style,uint8_t type,css_color color)448 static inline css_error set_border_top_color(css_computed_style *style, uint8_t
449 		type, css_color color)
450 {
451 	uint32_t *bits;
452 
453 	bits = &style->i.bits[BORDER_TOP_COLOR_INDEX];
454 
455 	/* 2bits: tt : type */
456 	*bits = (*bits & ~BORDER_TOP_COLOR_MASK) | (((uint32_t)type & 0x3) <<
457 			BORDER_TOP_COLOR_SHIFT);
458 
459 	style->i.border_top_color = color;
460 
461 	return CSS_OK;
462 }
463 #undef BORDER_TOP_COLOR_INDEX
464 #undef BORDER_TOP_COLOR_SHIFT
465 #undef BORDER_TOP_COLOR_MASK
466 
467 #define BORDER_TOP_STYLE_INDEX 6
468 #define BORDER_TOP_STYLE_SHIFT 0
469 #define BORDER_TOP_STYLE_MASK 0xf
470 
set_border_top_style(css_computed_style * style,uint8_t type)471 static inline css_error set_border_top_style(css_computed_style *style, uint8_t
472 		type)
473 {
474 	uint32_t *bits;
475 
476 	bits = &style->i.bits[BORDER_TOP_STYLE_INDEX];
477 
478 	/* 4bits: tttt : type */
479 	*bits = (*bits & ~BORDER_TOP_STYLE_MASK) | (((uint32_t)type & 0xf) <<
480 			BORDER_TOP_STYLE_SHIFT);
481 
482 	return CSS_OK;
483 }
484 #undef BORDER_TOP_STYLE_INDEX
485 #undef BORDER_TOP_STYLE_SHIFT
486 #undef BORDER_TOP_STYLE_MASK
487 
488 #define BORDER_TOP_WIDTH_INDEX 1
489 #define BORDER_TOP_WIDTH_SHIFT 15
490 #define BORDER_TOP_WIDTH_MASK 0x7f8000
491 
set_border_top_width(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)492 static inline css_error set_border_top_width(css_computed_style *style, uint8_t
493 		type, css_fixed length, css_unit unit)
494 {
495 	uint32_t *bits;
496 
497 	bits = &style->i.bits[BORDER_TOP_WIDTH_INDEX];
498 
499 	/* 8bits: uuuuuttt : unit | type */
500 	*bits = (*bits & ~BORDER_TOP_WIDTH_MASK) | ((((uint32_t)type & 0x7) | (
501 			unit << 3)) << BORDER_TOP_WIDTH_SHIFT);
502 
503 	style->i.border_top_width = length;
504 
505 	return CSS_OK;
506 }
507 #undef BORDER_TOP_WIDTH_INDEX
508 #undef BORDER_TOP_WIDTH_SHIFT
509 #undef BORDER_TOP_WIDTH_MASK
510 
511 #define BOTTOM_INDEX 7
512 #define BOTTOM_SHIFT 18
513 #define BOTTOM_MASK 0x1fc0000
514 
set_bottom(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)515 static inline css_error set_bottom(css_computed_style *style, uint8_t type,
516 		css_fixed length, css_unit unit)
517 {
518 	uint32_t *bits;
519 
520 	bits = &style->i.bits[BOTTOM_INDEX];
521 
522 	/* 7bits: uuuuutt : unit | type */
523 	*bits = (*bits & ~BOTTOM_MASK) | ((((uint32_t)type & 0x3) | (unit <<
524 			2)) << BOTTOM_SHIFT);
525 
526 	style->i.bottom = length;
527 
528 	return CSS_OK;
529 }
530 #undef BOTTOM_INDEX
531 #undef BOTTOM_SHIFT
532 #undef BOTTOM_MASK
533 
534 #define BOX_SIZING_INDEX 10
535 #define BOX_SIZING_SHIFT 18
536 #define BOX_SIZING_MASK 0xc0000
537 
set_box_sizing(css_computed_style * style,uint8_t type)538 static inline css_error set_box_sizing(css_computed_style *style, uint8_t type)
539 {
540 	uint32_t *bits;
541 
542 	bits = &style->i.bits[BOX_SIZING_INDEX];
543 
544 	/* 2bits: tt : type */
545 	*bits = (*bits & ~BOX_SIZING_MASK) | (((uint32_t)type & 0x3) <<
546 			BOX_SIZING_SHIFT);
547 
548 	return CSS_OK;
549 }
550 #undef BOX_SIZING_INDEX
551 #undef BOX_SIZING_SHIFT
552 #undef BOX_SIZING_MASK
553 
554 #define BREAK_AFTER_INDEX 13
555 #define BREAK_AFTER_SHIFT 28
556 #define BREAK_AFTER_MASK 0xf0000000
557 
set_break_after(css_computed_style * style,uint8_t type)558 static inline css_error set_break_after(css_computed_style *style, uint8_t type)
559 {
560 	uint32_t *bits;
561 
562 	bits = &style->i.bits[BREAK_AFTER_INDEX];
563 
564 	/* 4bits: tttt : type */
565 	*bits = (*bits & ~BREAK_AFTER_MASK) | (((uint32_t)type & 0xf) <<
566 			BREAK_AFTER_SHIFT);
567 
568 	return CSS_OK;
569 }
570 #undef BREAK_AFTER_INDEX
571 #undef BREAK_AFTER_SHIFT
572 #undef BREAK_AFTER_MASK
573 
574 #define BREAK_BEFORE_INDEX 13
575 #define BREAK_BEFORE_SHIFT 24
576 #define BREAK_BEFORE_MASK 0xf000000
577 
set_break_before(css_computed_style * style,uint8_t type)578 static inline css_error set_break_before(css_computed_style *style, uint8_t
579 		type)
580 {
581 	uint32_t *bits;
582 
583 	bits = &style->i.bits[BREAK_BEFORE_INDEX];
584 
585 	/* 4bits: tttt : type */
586 	*bits = (*bits & ~BREAK_BEFORE_MASK) | (((uint32_t)type & 0xf) <<
587 			BREAK_BEFORE_SHIFT);
588 
589 	return CSS_OK;
590 }
591 #undef BREAK_BEFORE_INDEX
592 #undef BREAK_BEFORE_SHIFT
593 #undef BREAK_BEFORE_MASK
594 
595 #define BREAK_INSIDE_INDEX 13
596 #define BREAK_INSIDE_SHIFT 4
597 #define BREAK_INSIDE_MASK 0xf0
598 
set_break_inside(css_computed_style * style,uint8_t type)599 static inline css_error set_break_inside(css_computed_style *style, uint8_t
600 		type)
601 {
602 	uint32_t *bits;
603 
604 	bits = &style->i.bits[BREAK_INSIDE_INDEX];
605 
606 	/* 4bits: tttt : type */
607 	*bits = (*bits & ~BREAK_INSIDE_MASK) | (((uint32_t)type & 0xf) <<
608 			BREAK_INSIDE_SHIFT);
609 
610 	return CSS_OK;
611 }
612 #undef BREAK_INSIDE_INDEX
613 #undef BREAK_INSIDE_SHIFT
614 #undef BREAK_INSIDE_MASK
615 
616 #define CAPTION_SIDE_INDEX 11
617 #define CAPTION_SIDE_SHIFT 24
618 #define CAPTION_SIDE_MASK 0x3000000
619 
set_caption_side(css_computed_style * style,uint8_t type)620 static inline css_error set_caption_side(css_computed_style *style, uint8_t
621 		type)
622 {
623 	uint32_t *bits;
624 
625 	bits = &style->i.bits[CAPTION_SIDE_INDEX];
626 
627 	/* 2bits: tt : type */
628 	*bits = (*bits & ~CAPTION_SIDE_MASK) | (((uint32_t)type & 0x3) <<
629 			CAPTION_SIDE_SHIFT);
630 
631 	return CSS_OK;
632 }
633 #undef CAPTION_SIDE_INDEX
634 #undef CAPTION_SIDE_SHIFT
635 #undef CAPTION_SIDE_MASK
636 
637 #define CLEAR_INDEX 10
638 #define CLEAR_SHIFT 23
639 #define CLEAR_MASK 0x3800000
640 
set_clear(css_computed_style * style,uint8_t type)641 static inline css_error set_clear(css_computed_style *style, uint8_t type)
642 {
643 	uint32_t *bits;
644 
645 	bits = &style->i.bits[CLEAR_INDEX];
646 
647 	/* 3bits: ttt : type */
648 	*bits = (*bits & ~CLEAR_MASK) | (((uint32_t)type & 0x7) << CLEAR_SHIFT);
649 
650 	return CSS_OK;
651 }
652 #undef CLEAR_INDEX
653 #undef CLEAR_SHIFT
654 #undef CLEAR_MASK
655 
656 #define CLIP_INDEX 2
657 #define CLIP_SHIFT 6
658 #define CLIP_MASK 0xffffffc0
set_clip(css_computed_style * style,uint8_t type,css_computed_clip_rect * rect)659 static inline css_error set_clip(
660 		css_computed_style *style, uint8_t type,
661 		css_computed_clip_rect *rect)
662 {
663 	uint32_t *bits;
664 
665 	bits = &style->i.bits[CLIP_INDEX];
666 
667 	/*
668 	26bits: tt tttr rrrr bbbb blll llTR BLyy:
669 	units: top | right | bottom | left
670 	opcodes: top | right | bottom | left | type
671 	*/
672 	*bits = (*bits & ~CLIP_MASK) |
673 			((type & 0x3) << CLIP_SHIFT);
674 
675 	if (type == CSS_CLIP_RECT) {
676 		*bits |= (((rect->top_auto ? 0x20 : 0) |
677 				(rect->right_auto ? 0x10 : 0) |
678 				(rect->bottom_auto ? 0x8 : 0) |
679 				(rect->left_auto ? 0x4 : 0)) << CLIP_SHIFT);
680 
681 		*bits |= (((rect->tunit << 5) | rect->runit)
682 				<< (CLIP_SHIFT + 16));
683 
684 		*bits |= (((rect->bunit << 5) | rect->lunit)
685 				<< (CLIP_SHIFT + 6));
686 
687 		style->i.clip_a = rect->top;
688 		style->i.clip_b = rect->right;
689 		style->i.clip_c = rect->bottom;
690 		style->i.clip_d = rect->left;
691 	}
692 
693 	return CSS_OK;
694 }
695 #undef CLIP_INDEX
696 #undef CLIP_SHIFT
697 #undef CLIP_MASK
698 
699 #define COLOR_INDEX 12
700 #define COLOR_SHIFT 0
701 #define COLOR_MASK 0x1
702 
set_color(css_computed_style * style,uint8_t type,css_color color)703 static inline css_error set_color(css_computed_style *style, uint8_t type,
704 		css_color color)
705 {
706 	uint32_t *bits;
707 
708 	bits = &style->i.bits[COLOR_INDEX];
709 
710 	/* 1bit: t : type */
711 	*bits = (*bits & ~COLOR_MASK) | (((uint32_t)type & 0x1) << COLOR_SHIFT);
712 
713 	style->i.color = color;
714 
715 	return CSS_OK;
716 }
717 #undef COLOR_INDEX
718 #undef COLOR_SHIFT
719 #undef COLOR_MASK
720 
721 #define COLUMN_COUNT_INDEX 11
722 #define COLUMN_COUNT_SHIFT 20
723 #define COLUMN_COUNT_MASK 0x300000
724 
set_column_count(css_computed_style * style,uint8_t type,int32_t integer)725 static inline css_error set_column_count(css_computed_style *style, uint8_t
726 		type, int32_t integer)
727 {
728 	uint32_t *bits;
729 
730 	bits = &style->i.bits[COLUMN_COUNT_INDEX];
731 
732 	/* 2bits: tt : type */
733 	*bits = (*bits & ~COLUMN_COUNT_MASK) | (((uint32_t)type & 0x3) <<
734 			COLUMN_COUNT_SHIFT);
735 
736 	style->i.column_count = integer;
737 
738 	return CSS_OK;
739 }
740 #undef COLUMN_COUNT_INDEX
741 #undef COLUMN_COUNT_SHIFT
742 #undef COLUMN_COUNT_MASK
743 
744 #define COLUMN_FILL_INDEX 11
745 #define COLUMN_FILL_SHIFT 10
746 #define COLUMN_FILL_MASK 0xc00
747 
set_column_fill(css_computed_style * style,uint8_t type)748 static inline css_error set_column_fill(css_computed_style *style, uint8_t type)
749 {
750 	uint32_t *bits;
751 
752 	bits = &style->i.bits[COLUMN_FILL_INDEX];
753 
754 	/* 2bits: tt : type */
755 	*bits = (*bits & ~COLUMN_FILL_MASK) | (((uint32_t)type & 0x3) <<
756 			COLUMN_FILL_SHIFT);
757 
758 	return CSS_OK;
759 }
760 #undef COLUMN_FILL_INDEX
761 #undef COLUMN_FILL_SHIFT
762 #undef COLUMN_FILL_MASK
763 
764 #define COLUMN_GAP_INDEX 4
765 #define COLUMN_GAP_SHIFT 11
766 #define COLUMN_GAP_MASK 0x3f800
767 
set_column_gap(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)768 static inline css_error set_column_gap(css_computed_style *style, uint8_t type,
769 		css_fixed length, css_unit unit)
770 {
771 	uint32_t *bits;
772 
773 	bits = &style->i.bits[COLUMN_GAP_INDEX];
774 
775 	/* 7bits: uuuuutt : unit | type */
776 	*bits = (*bits & ~COLUMN_GAP_MASK) | ((((uint32_t)type & 0x3) | (unit
777 			<< 2)) << COLUMN_GAP_SHIFT);
778 
779 	style->i.column_gap = length;
780 
781 	return CSS_OK;
782 }
783 #undef COLUMN_GAP_INDEX
784 #undef COLUMN_GAP_SHIFT
785 #undef COLUMN_GAP_MASK
786 
787 #define COLUMN_RULE_COLOR_INDEX 10
788 #define COLUMN_RULE_COLOR_SHIFT 10
789 #define COLUMN_RULE_COLOR_MASK 0xc00
790 
set_column_rule_color(css_computed_style * style,uint8_t type,css_color color)791 static inline css_error set_column_rule_color(css_computed_style *style,
792 		uint8_t type, css_color color)
793 {
794 	uint32_t *bits;
795 
796 	bits = &style->i.bits[COLUMN_RULE_COLOR_INDEX];
797 
798 	/* 2bits: tt : type */
799 	*bits = (*bits & ~COLUMN_RULE_COLOR_MASK) | (((uint32_t)type & 0x3) <<
800 			COLUMN_RULE_COLOR_SHIFT);
801 
802 	style->i.column_rule_color = color;
803 
804 	return CSS_OK;
805 }
806 #undef COLUMN_RULE_COLOR_INDEX
807 #undef COLUMN_RULE_COLOR_SHIFT
808 #undef COLUMN_RULE_COLOR_MASK
809 
810 #define COLUMN_RULE_STYLE_INDEX 7
811 #define COLUMN_RULE_STYLE_SHIFT 0
812 #define COLUMN_RULE_STYLE_MASK 0xf
813 
set_column_rule_style(css_computed_style * style,uint8_t type)814 static inline css_error set_column_rule_style(css_computed_style *style,
815 		uint8_t type)
816 {
817 	uint32_t *bits;
818 
819 	bits = &style->i.bits[COLUMN_RULE_STYLE_INDEX];
820 
821 	/* 4bits: tttt : type */
822 	*bits = (*bits & ~COLUMN_RULE_STYLE_MASK) | (((uint32_t)type & 0xf) <<
823 			COLUMN_RULE_STYLE_SHIFT);
824 
825 	return CSS_OK;
826 }
827 #undef COLUMN_RULE_STYLE_INDEX
828 #undef COLUMN_RULE_STYLE_SHIFT
829 #undef COLUMN_RULE_STYLE_MASK
830 
831 #define COLUMN_RULE_WIDTH_INDEX 0
832 #define COLUMN_RULE_WIDTH_SHIFT 24
833 #define COLUMN_RULE_WIDTH_MASK 0xff000000
834 
set_column_rule_width(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)835 static inline css_error set_column_rule_width(css_computed_style *style,
836 		uint8_t type, css_fixed length, css_unit unit)
837 {
838 	uint32_t *bits;
839 
840 	bits = &style->i.bits[COLUMN_RULE_WIDTH_INDEX];
841 
842 	/* 8bits: uuuuuttt : unit | type */
843 	*bits = (*bits & ~COLUMN_RULE_WIDTH_MASK) | ((((uint32_t)type & 0x7) | (
844 			unit << 3)) << COLUMN_RULE_WIDTH_SHIFT);
845 
846 	style->i.column_rule_width = length;
847 
848 	return CSS_OK;
849 }
850 #undef COLUMN_RULE_WIDTH_INDEX
851 #undef COLUMN_RULE_WIDTH_SHIFT
852 #undef COLUMN_RULE_WIDTH_MASK
853 
854 #define COLUMN_SPAN_INDEX 10
855 #define COLUMN_SPAN_SHIFT 6
856 #define COLUMN_SPAN_MASK 0xc0
857 
set_column_span(css_computed_style * style,uint8_t type)858 static inline css_error set_column_span(css_computed_style *style, uint8_t type)
859 {
860 	uint32_t *bits;
861 
862 	bits = &style->i.bits[COLUMN_SPAN_INDEX];
863 
864 	/* 2bits: tt : type */
865 	*bits = (*bits & ~COLUMN_SPAN_MASK) | (((uint32_t)type & 0x3) <<
866 			COLUMN_SPAN_SHIFT);
867 
868 	return CSS_OK;
869 }
870 #undef COLUMN_SPAN_INDEX
871 #undef COLUMN_SPAN_SHIFT
872 #undef COLUMN_SPAN_MASK
873 
874 #define COLUMN_WIDTH_INDEX 5
875 #define COLUMN_WIDTH_SHIFT 4
876 #define COLUMN_WIDTH_MASK 0x7f0
877 
set_column_width(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)878 static inline css_error set_column_width(css_computed_style *style, uint8_t
879 		type, css_fixed length, css_unit unit)
880 {
881 	uint32_t *bits;
882 
883 	bits = &style->i.bits[COLUMN_WIDTH_INDEX];
884 
885 	/* 7bits: uuuuutt : unit | type */
886 	*bits = (*bits & ~COLUMN_WIDTH_MASK) | ((((uint32_t)type & 0x3) | (unit
887 			<< 2)) << COLUMN_WIDTH_SHIFT);
888 
889 	style->i.column_width = length;
890 
891 	return CSS_OK;
892 }
893 #undef COLUMN_WIDTH_INDEX
894 #undef COLUMN_WIDTH_SHIFT
895 #undef COLUMN_WIDTH_MASK
896 
897 #define CONTENT_INDEX 11
898 #define CONTENT_SHIFT 0
899 #define CONTENT_MASK 0x3
set_content(css_computed_style * style,uint8_t type,css_computed_content_item * content)900 static inline css_error set_content(
901 		css_computed_style *style, uint8_t type,
902 		css_computed_content_item *content)
903 {
904 	uint32_t *bits;
905 	css_computed_content_item *oldcontent;
906 	css_computed_content_item *c;
907 
908 	/* 2bits: type */
909 	bits = &style->i.bits[CONTENT_INDEX];
910 	oldcontent = style->content;
911 
912 	*bits = (*bits & ~CONTENT_MASK) |
913 			((type & 0x3) << CONTENT_SHIFT);
914 
915 	for (c = content; c != NULL &&
916 			c->type != CSS_COMPUTED_CONTENT_NONE; c++) {
917 		switch (c->type) {
918 		case CSS_COMPUTED_CONTENT_STRING:
919 			c->data.string = lwc_string_ref(c->data.string);
920 			break;
921 		case CSS_COMPUTED_CONTENT_URI:
922 			c->data.uri = lwc_string_ref(c->data.uri);
923 			break;
924 		case CSS_COMPUTED_CONTENT_ATTR:
925 			c->data.attr = lwc_string_ref(c->data.attr);
926 			break;
927 		case CSS_COMPUTED_CONTENT_COUNTER:
928 			c->data.counter.name =
929 				lwc_string_ref(c->data.counter.name);
930 			break;
931 		case CSS_COMPUTED_CONTENT_COUNTERS:
932 			c->data.counters.name =
933 				lwc_string_ref(c->data.counters.name);
934 			c->data.counters.sep =
935 				lwc_string_ref(c->data.counters.sep);
936 			break;
937 		default:
938 			break;
939 		}
940 	}
941 
942 	style->content = content;
943 
944 	/* Free existing array */
945 	if (oldcontent != NULL) {
946 		for (c = oldcontent;
947 				c->type != CSS_COMPUTED_CONTENT_NONE; c++) {
948 			switch (c->type) {
949 			case CSS_COMPUTED_CONTENT_STRING:
950 				lwc_string_unref(c->data.string);
951 				break;
952 			case CSS_COMPUTED_CONTENT_URI:
953 				lwc_string_unref(c->data.uri);
954 				break;
955 			case CSS_COMPUTED_CONTENT_ATTR:
956 				lwc_string_unref(c->data.attr);
957 				break;
958 			case CSS_COMPUTED_CONTENT_COUNTER:
959 				lwc_string_unref(c->data.counter.name);
960 				break;
961 			case CSS_COMPUTED_CONTENT_COUNTERS:
962 				lwc_string_unref(c->data.counters.name);
963 				lwc_string_unref(c->data.counters.sep);
964 				break;
965 			default:
966 				break;
967 			}
968 		}
969 
970 		if (oldcontent != content)
971 			free(oldcontent);
972 	}
973 
974 	return CSS_OK;
975 }
976 #undef CONTENT_INDEX
977 #undef CONTENT_SHIFT
978 #undef CONTENT_MASK
979 
980 #define COUNTER_INCREMENT_INDEX 14
981 #define COUNTER_INCREMENT_SHIFT 29
982 #define COUNTER_INCREMENT_MASK 0x20000000
983 
set_counter_increment(css_computed_style * style,uint8_t type,css_computed_counter * counter_arr)984 static inline css_error set_counter_increment(css_computed_style *style,
985 		uint8_t type, css_computed_counter *counter_arr)
986 {
987 	uint32_t *bits;
988 
989 	bits = &style->i.bits[COUNTER_INCREMENT_INDEX];
990 
991 	/* 1bit: t : type */
992 	*bits = (*bits & ~COUNTER_INCREMENT_MASK) | (((uint32_t)type & 0x1) <<
993 			COUNTER_INCREMENT_SHIFT);
994 
995 	css_computed_counter *old_counter_arr = style->counter_increment;
996 	css_computed_counter *c;
997 
998 	for (c = counter_arr; c != NULL && c->name != NULL; c++)
999 		c->name = lwc_string_ref(c->name);
1000 
1001 	style->counter_increment = counter_arr;
1002 
1003 	/* Free existing array */
1004 	if (old_counter_arr != NULL) {
1005 		for (c = old_counter_arr; c->name != NULL; c++)
1006 			lwc_string_unref(c->name);
1007 
1008 		if (old_counter_arr != counter_arr)
1009 			free(old_counter_arr);
1010 	}
1011 
1012 	return CSS_OK;
1013 }
1014 #undef COUNTER_INCREMENT_INDEX
1015 #undef COUNTER_INCREMENT_SHIFT
1016 #undef COUNTER_INCREMENT_MASK
1017 
1018 #define COUNTER_RESET_INDEX 14
1019 #define COUNTER_RESET_SHIFT 21
1020 #define COUNTER_RESET_MASK 0x200000
1021 
set_counter_reset(css_computed_style * style,uint8_t type,css_computed_counter * counter_arr)1022 static inline css_error set_counter_reset(css_computed_style *style, uint8_t
1023 		type, css_computed_counter *counter_arr)
1024 {
1025 	uint32_t *bits;
1026 
1027 	bits = &style->i.bits[COUNTER_RESET_INDEX];
1028 
1029 	/* 1bit: t : type */
1030 	*bits = (*bits & ~COUNTER_RESET_MASK) | (((uint32_t)type & 0x1) <<
1031 			COUNTER_RESET_SHIFT);
1032 
1033 	css_computed_counter *old_counter_arr = style->counter_reset;
1034 	css_computed_counter *c;
1035 
1036 	for (c = counter_arr; c != NULL && c->name != NULL; c++)
1037 		c->name = lwc_string_ref(c->name);
1038 
1039 	style->counter_reset = counter_arr;
1040 
1041 	/* Free existing array */
1042 	if (old_counter_arr != NULL) {
1043 		for (c = old_counter_arr; c->name != NULL; c++)
1044 			lwc_string_unref(c->name);
1045 
1046 		if (old_counter_arr != counter_arr)
1047 			free(old_counter_arr);
1048 	}
1049 
1050 	return CSS_OK;
1051 }
1052 #undef COUNTER_RESET_INDEX
1053 #undef COUNTER_RESET_SHIFT
1054 #undef COUNTER_RESET_MASK
1055 
1056 #define CURSOR_INDEX 8
1057 #define CURSOR_SHIFT 4
1058 #define CURSOR_MASK 0x1f0
1059 
set_cursor(css_computed_style * style,uint8_t type,lwc_string ** string_arr)1060 static inline css_error set_cursor(css_computed_style *style, uint8_t type,
1061 		lwc_string **string_arr)
1062 {
1063 	uint32_t *bits;
1064 
1065 	bits = &style->i.bits[CURSOR_INDEX];
1066 
1067 	/* 5bits: ttttt : type */
1068 	*bits = (*bits & ~CURSOR_MASK) | (((uint32_t)type & 0x1f) <<
1069 			CURSOR_SHIFT);
1070 
1071 	lwc_string **old_string_arr = style->cursor;
1072 	lwc_string **s;
1073 
1074 	for (s = string_arr; s != NULL && *s != NULL; s++)
1075 		*s = lwc_string_ref(*s);
1076 
1077 	style->cursor = string_arr;
1078 
1079 	/* Free existing array */
1080 	if (old_string_arr != NULL) {
1081 		for (s = old_string_arr; *s != NULL; s++)
1082 			lwc_string_unref(*s);
1083 
1084 		if (old_string_arr != string_arr)
1085 			free(old_string_arr);
1086 	}
1087 
1088 	return CSS_OK;
1089 }
1090 #undef CURSOR_INDEX
1091 #undef CURSOR_SHIFT
1092 #undef CURSOR_MASK
1093 
1094 #define DIRECTION_INDEX 10
1095 #define DIRECTION_SHIFT 16
1096 #define DIRECTION_MASK 0x30000
1097 
set_direction(css_computed_style * style,uint8_t type)1098 static inline css_error set_direction(css_computed_style *style, uint8_t type)
1099 {
1100 	uint32_t *bits;
1101 
1102 	bits = &style->i.bits[DIRECTION_INDEX];
1103 
1104 	/* 2bits: tt : type */
1105 	*bits = (*bits & ~DIRECTION_MASK) | (((uint32_t)type & 0x3) <<
1106 			DIRECTION_SHIFT);
1107 
1108 	return CSS_OK;
1109 }
1110 #undef DIRECTION_INDEX
1111 #undef DIRECTION_SHIFT
1112 #undef DIRECTION_MASK
1113 
1114 #define DISPLAY_INDEX 3
1115 #define DISPLAY_SHIFT 0
1116 #define DISPLAY_MASK 0x1f
1117 
set_display(css_computed_style * style,uint8_t type)1118 static inline css_error set_display(css_computed_style *style, uint8_t type)
1119 {
1120 	uint32_t *bits;
1121 
1122 	bits = &style->i.bits[DISPLAY_INDEX];
1123 
1124 	/* 5bits: ttttt : type */
1125 	*bits = (*bits & ~DISPLAY_MASK) | (((uint32_t)type & 0x1f) <<
1126 			DISPLAY_SHIFT);
1127 
1128 	return CSS_OK;
1129 }
1130 #undef DISPLAY_INDEX
1131 #undef DISPLAY_SHIFT
1132 #undef DISPLAY_MASK
1133 
1134 #define EMPTY_CELLS_INDEX 10
1135 #define EMPTY_CELLS_SHIFT 14
1136 #define EMPTY_CELLS_MASK 0xc000
1137 
set_empty_cells(css_computed_style * style,uint8_t type)1138 static inline css_error set_empty_cells(css_computed_style *style, uint8_t type)
1139 {
1140 	uint32_t *bits;
1141 
1142 	bits = &style->i.bits[EMPTY_CELLS_INDEX];
1143 
1144 	/* 2bits: tt : type */
1145 	*bits = (*bits & ~EMPTY_CELLS_MASK) | (((uint32_t)type & 0x3) <<
1146 			EMPTY_CELLS_SHIFT);
1147 
1148 	return CSS_OK;
1149 }
1150 #undef EMPTY_CELLS_INDEX
1151 #undef EMPTY_CELLS_SHIFT
1152 #undef EMPTY_CELLS_MASK
1153 
1154 #define FLEX_BASIS_INDEX 4
1155 #define FLEX_BASIS_SHIFT 18
1156 #define FLEX_BASIS_MASK 0x1fc0000
1157 
set_flex_basis(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)1158 static inline css_error set_flex_basis(css_computed_style *style, uint8_t type,
1159 		css_fixed length, css_unit unit)
1160 {
1161 	uint32_t *bits;
1162 
1163 	bits = &style->i.bits[FLEX_BASIS_INDEX];
1164 
1165 	/* 7bits: uuuuutt : unit | type */
1166 	*bits = (*bits & ~FLEX_BASIS_MASK) | ((((uint32_t)type & 0x3) | (unit
1167 			<< 2)) << FLEX_BASIS_SHIFT);
1168 
1169 	style->i.flex_basis = length;
1170 
1171 	return CSS_OK;
1172 }
1173 #undef FLEX_BASIS_INDEX
1174 #undef FLEX_BASIS_SHIFT
1175 #undef FLEX_BASIS_MASK
1176 
1177 #define FLEX_DIRECTION_INDEX 9
1178 #define FLEX_DIRECTION_SHIFT 5
1179 #define FLEX_DIRECTION_MASK 0xe0
1180 
set_flex_direction(css_computed_style * style,uint8_t type)1181 static inline css_error set_flex_direction(css_computed_style *style, uint8_t
1182 		type)
1183 {
1184 	uint32_t *bits;
1185 
1186 	bits = &style->i.bits[FLEX_DIRECTION_INDEX];
1187 
1188 	/* 3bits: ttt : type */
1189 	*bits = (*bits & ~FLEX_DIRECTION_MASK) | (((uint32_t)type & 0x7) <<
1190 			FLEX_DIRECTION_SHIFT);
1191 
1192 	return CSS_OK;
1193 }
1194 #undef FLEX_DIRECTION_INDEX
1195 #undef FLEX_DIRECTION_SHIFT
1196 #undef FLEX_DIRECTION_MASK
1197 
1198 #define FLEX_GROW_INDEX 14
1199 #define FLEX_GROW_SHIFT 23
1200 #define FLEX_GROW_MASK 0x800000
1201 
set_flex_grow(css_computed_style * style,uint8_t type,css_fixed fixed)1202 static inline css_error set_flex_grow(css_computed_style *style, uint8_t type,
1203 		css_fixed fixed)
1204 {
1205 	uint32_t *bits;
1206 
1207 	bits = &style->i.bits[FLEX_GROW_INDEX];
1208 
1209 	/* 1bit: t : type */
1210 	*bits = (*bits & ~FLEX_GROW_MASK) | (((uint32_t)type & 0x1) <<
1211 			FLEX_GROW_SHIFT);
1212 
1213 	style->i.flex_grow = fixed;
1214 
1215 	return CSS_OK;
1216 }
1217 #undef FLEX_GROW_INDEX
1218 #undef FLEX_GROW_SHIFT
1219 #undef FLEX_GROW_MASK
1220 
1221 #define FLEX_SHRINK_INDEX 14
1222 #define FLEX_SHRINK_SHIFT 20
1223 #define FLEX_SHRINK_MASK 0x100000
1224 
set_flex_shrink(css_computed_style * style,uint8_t type,css_fixed fixed)1225 static inline css_error set_flex_shrink(css_computed_style *style, uint8_t
1226 		type, css_fixed fixed)
1227 {
1228 	uint32_t *bits;
1229 
1230 	bits = &style->i.bits[FLEX_SHRINK_INDEX];
1231 
1232 	/* 1bit: t : type */
1233 	*bits = (*bits & ~FLEX_SHRINK_MASK) | (((uint32_t)type & 0x1) <<
1234 			FLEX_SHRINK_SHIFT);
1235 
1236 	style->i.flex_shrink = fixed;
1237 
1238 	return CSS_OK;
1239 }
1240 #undef FLEX_SHRINK_INDEX
1241 #undef FLEX_SHRINK_SHIFT
1242 #undef FLEX_SHRINK_MASK
1243 
1244 #define FLEX_WRAP_INDEX 10
1245 #define FLEX_WRAP_SHIFT 12
1246 #define FLEX_WRAP_MASK 0x3000
1247 
set_flex_wrap(css_computed_style * style,uint8_t type)1248 static inline css_error set_flex_wrap(css_computed_style *style, uint8_t type)
1249 {
1250 	uint32_t *bits;
1251 
1252 	bits = &style->i.bits[FLEX_WRAP_INDEX];
1253 
1254 	/* 2bits: tt : type */
1255 	*bits = (*bits & ~FLEX_WRAP_MASK) | (((uint32_t)type & 0x3) <<
1256 			FLEX_WRAP_SHIFT);
1257 
1258 	return CSS_OK;
1259 }
1260 #undef FLEX_WRAP_INDEX
1261 #undef FLEX_WRAP_SHIFT
1262 #undef FLEX_WRAP_MASK
1263 
1264 #define FLOAT_INDEX 11
1265 #define FLOAT_SHIFT 6
1266 #define FLOAT_MASK 0xc0
1267 
set_float(css_computed_style * style,uint8_t type)1268 static inline css_error set_float(css_computed_style *style, uint8_t type)
1269 {
1270 	uint32_t *bits;
1271 
1272 	bits = &style->i.bits[FLOAT_INDEX];
1273 
1274 	/* 2bits: tt : type */
1275 	*bits = (*bits & ~FLOAT_MASK) | (((uint32_t)type & 0x3) << FLOAT_SHIFT);
1276 
1277 	return CSS_OK;
1278 }
1279 #undef FLOAT_INDEX
1280 #undef FLOAT_SHIFT
1281 #undef FLOAT_MASK
1282 
1283 #define FONT_FAMILY_INDEX 9
1284 #define FONT_FAMILY_SHIFT 26
1285 #define FONT_FAMILY_MASK 0x1c000000
1286 
set_font_family(css_computed_style * style,uint8_t type,lwc_string ** string_arr)1287 static inline css_error set_font_family(css_computed_style *style, uint8_t
1288 		type, lwc_string **string_arr)
1289 {
1290 	uint32_t *bits;
1291 
1292 	bits = &style->i.bits[FONT_FAMILY_INDEX];
1293 
1294 	/* 3bits: ttt : type */
1295 	*bits = (*bits & ~FONT_FAMILY_MASK) | (((uint32_t)type & 0x7) <<
1296 			FONT_FAMILY_SHIFT);
1297 
1298 	lwc_string **old_string_arr = style->font_family;
1299 	lwc_string **s;
1300 
1301 	for (s = string_arr; s != NULL && *s != NULL; s++)
1302 		*s = lwc_string_ref(*s);
1303 
1304 	style->font_family = string_arr;
1305 
1306 	/* Free existing array */
1307 	if (old_string_arr != NULL) {
1308 		for (s = old_string_arr; *s != NULL; s++)
1309 			lwc_string_unref(*s);
1310 
1311 		if (old_string_arr != string_arr)
1312 			free(old_string_arr);
1313 	}
1314 
1315 	return CSS_OK;
1316 }
1317 #undef FONT_FAMILY_INDEX
1318 #undef FONT_FAMILY_SHIFT
1319 #undef FONT_FAMILY_MASK
1320 
1321 #define FONT_SIZE_INDEX 12
1322 #define FONT_SIZE_SHIFT 1
1323 #define FONT_SIZE_MASK 0x3fe
1324 
set_font_size(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)1325 static inline css_error set_font_size(css_computed_style *style, uint8_t type,
1326 		css_fixed length, css_unit unit)
1327 {
1328 	uint32_t *bits;
1329 
1330 	bits = &style->i.bits[FONT_SIZE_INDEX];
1331 
1332 	/* 9bits: uuuuutttt : unit | type */
1333 	*bits = (*bits & ~FONT_SIZE_MASK) | ((((uint32_t)type & 0xf) | (unit <<
1334 			4)) << FONT_SIZE_SHIFT);
1335 
1336 	style->i.font_size = length;
1337 
1338 	return CSS_OK;
1339 }
1340 #undef FONT_SIZE_INDEX
1341 #undef FONT_SIZE_SHIFT
1342 #undef FONT_SIZE_MASK
1343 
1344 #define FONT_STYLE_INDEX 11
1345 #define FONT_STYLE_SHIFT 30
1346 #define FONT_STYLE_MASK 0xc0000000
1347 
set_font_style(css_computed_style * style,uint8_t type)1348 static inline css_error set_font_style(css_computed_style *style, uint8_t type)
1349 {
1350 	uint32_t *bits;
1351 
1352 	bits = &style->i.bits[FONT_STYLE_INDEX];
1353 
1354 	/* 2bits: tt : type */
1355 	*bits = (*bits & ~FONT_STYLE_MASK) | (((uint32_t)type & 0x3) <<
1356 			FONT_STYLE_SHIFT);
1357 
1358 	return CSS_OK;
1359 }
1360 #undef FONT_STYLE_INDEX
1361 #undef FONT_STYLE_SHIFT
1362 #undef FONT_STYLE_MASK
1363 
1364 #define FONT_VARIANT_INDEX 11
1365 #define FONT_VARIANT_SHIFT 22
1366 #define FONT_VARIANT_MASK 0xc00000
1367 
set_font_variant(css_computed_style * style,uint8_t type)1368 static inline css_error set_font_variant(css_computed_style *style, uint8_t
1369 		type)
1370 {
1371 	uint32_t *bits;
1372 
1373 	bits = &style->i.bits[FONT_VARIANT_INDEX];
1374 
1375 	/* 2bits: tt : type */
1376 	*bits = (*bits & ~FONT_VARIANT_MASK) | (((uint32_t)type & 0x3) <<
1377 			FONT_VARIANT_SHIFT);
1378 
1379 	return CSS_OK;
1380 }
1381 #undef FONT_VARIANT_INDEX
1382 #undef FONT_VARIANT_SHIFT
1383 #undef FONT_VARIANT_MASK
1384 
1385 #define FONT_WEIGHT_INDEX 4
1386 #define FONT_WEIGHT_SHIFT 0
1387 #define FONT_WEIGHT_MASK 0xf
1388 
set_font_weight(css_computed_style * style,uint8_t type)1389 static inline css_error set_font_weight(css_computed_style *style, uint8_t type)
1390 {
1391 	uint32_t *bits;
1392 
1393 	bits = &style->i.bits[FONT_WEIGHT_INDEX];
1394 
1395 	/* 4bits: tttt : type */
1396 	*bits = (*bits & ~FONT_WEIGHT_MASK) | (((uint32_t)type & 0xf) <<
1397 			FONT_WEIGHT_SHIFT);
1398 
1399 	return CSS_OK;
1400 }
1401 #undef FONT_WEIGHT_INDEX
1402 #undef FONT_WEIGHT_SHIFT
1403 #undef FONT_WEIGHT_MASK
1404 
1405 #define HEIGHT_INDEX 5
1406 #define HEIGHT_SHIFT 18
1407 #define HEIGHT_MASK 0x1fc0000
1408 
set_height(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)1409 static inline css_error set_height(css_computed_style *style, uint8_t type,
1410 		css_fixed length, css_unit unit)
1411 {
1412 	uint32_t *bits;
1413 
1414 	bits = &style->i.bits[HEIGHT_INDEX];
1415 
1416 	/* 7bits: uuuuutt : unit | type */
1417 	*bits = (*bits & ~HEIGHT_MASK) | ((((uint32_t)type & 0x3) | (unit <<
1418 			2)) << HEIGHT_SHIFT);
1419 
1420 	style->i.height = length;
1421 
1422 	return CSS_OK;
1423 }
1424 #undef HEIGHT_INDEX
1425 #undef HEIGHT_SHIFT
1426 #undef HEIGHT_MASK
1427 
1428 #define JUSTIFY_CONTENT_INDEX 10
1429 #define JUSTIFY_CONTENT_SHIFT 29
1430 #define JUSTIFY_CONTENT_MASK 0xe0000000
1431 
set_justify_content(css_computed_style * style,uint8_t type)1432 static inline css_error set_justify_content(css_computed_style *style, uint8_t
1433 		type)
1434 {
1435 	uint32_t *bits;
1436 
1437 	bits = &style->i.bits[JUSTIFY_CONTENT_INDEX];
1438 
1439 	/* 3bits: ttt : type */
1440 	*bits = (*bits & ~JUSTIFY_CONTENT_MASK) | (((uint32_t)type & 0x7) <<
1441 			JUSTIFY_CONTENT_SHIFT);
1442 
1443 	return CSS_OK;
1444 }
1445 #undef JUSTIFY_CONTENT_INDEX
1446 #undef JUSTIFY_CONTENT_SHIFT
1447 #undef JUSTIFY_CONTENT_MASK
1448 
1449 #define LEFT_INDEX 4
1450 #define LEFT_SHIFT 4
1451 #define LEFT_MASK 0x7f0
1452 
set_left(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)1453 static inline css_error set_left(css_computed_style *style, uint8_t type,
1454 		css_fixed length, css_unit unit)
1455 {
1456 	uint32_t *bits;
1457 
1458 	bits = &style->i.bits[LEFT_INDEX];
1459 
1460 	/* 7bits: uuuuutt : unit | type */
1461 	*bits = (*bits & ~LEFT_MASK) | ((((uint32_t)type & 0x3) | (unit << 2))
1462 			<< LEFT_SHIFT);
1463 
1464 	style->i.left = length;
1465 
1466 	return CSS_OK;
1467 }
1468 #undef LEFT_INDEX
1469 #undef LEFT_SHIFT
1470 #undef LEFT_MASK
1471 
1472 #define LETTER_SPACING_INDEX 1
1473 #define LETTER_SPACING_SHIFT 0
1474 #define LETTER_SPACING_MASK 0x7f
1475 
set_letter_spacing(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)1476 static inline css_error set_letter_spacing(css_computed_style *style, uint8_t
1477 		type, css_fixed length, css_unit unit)
1478 {
1479 	uint32_t *bits;
1480 
1481 	bits = &style->i.bits[LETTER_SPACING_INDEX];
1482 
1483 	/* 7bits: uuuuutt : unit | type */
1484 	*bits = (*bits & ~LETTER_SPACING_MASK) | ((((uint32_t)type & 0x3) | (
1485 			unit << 2)) << LETTER_SPACING_SHIFT);
1486 
1487 	style->i.letter_spacing = length;
1488 
1489 	return CSS_OK;
1490 }
1491 #undef LETTER_SPACING_INDEX
1492 #undef LETTER_SPACING_SHIFT
1493 #undef LETTER_SPACING_MASK
1494 
1495 #define LINE_HEIGHT_INDEX 5
1496 #define LINE_HEIGHT_SHIFT 11
1497 #define LINE_HEIGHT_MASK 0x3f800
1498 
set_line_height(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)1499 static inline css_error set_line_height(css_computed_style *style, uint8_t
1500 		type, css_fixed length, css_unit unit)
1501 {
1502 	uint32_t *bits;
1503 
1504 	bits = &style->i.bits[LINE_HEIGHT_INDEX];
1505 
1506 	/* 7bits: uuuuutt : unit | type */
1507 	*bits = (*bits & ~LINE_HEIGHT_MASK) | ((((uint32_t)type & 0x3) | (unit
1508 			<< 2)) << LINE_HEIGHT_SHIFT);
1509 
1510 	style->i.line_height = length;
1511 
1512 	return CSS_OK;
1513 }
1514 #undef LINE_HEIGHT_INDEX
1515 #undef LINE_HEIGHT_SHIFT
1516 #undef LINE_HEIGHT_MASK
1517 
1518 #define LIST_STYLE_IMAGE_INDEX 13
1519 #define LIST_STYLE_IMAGE_SHIFT 0
1520 #define LIST_STYLE_IMAGE_MASK 0x1
1521 
set_list_style_image(css_computed_style * style,uint8_t type,lwc_string * string)1522 static inline css_error set_list_style_image(css_computed_style *style, uint8_t
1523 		type, lwc_string *string)
1524 {
1525 	uint32_t *bits;
1526 
1527 	bits = &style->i.bits[LIST_STYLE_IMAGE_INDEX];
1528 
1529 	/* 1bit: t : type */
1530 	*bits = (*bits & ~LIST_STYLE_IMAGE_MASK) | (((uint32_t)type & 0x1) <<
1531 			LIST_STYLE_IMAGE_SHIFT);
1532 
1533 	lwc_string *old_string = style->i.list_style_image;
1534 
1535 	if (string != NULL) {
1536 		style->i.list_style_image = lwc_string_ref(string);
1537 	} else {
1538 		style->i.list_style_image = NULL;
1539 	}
1540 
1541 	if (old_string != NULL)
1542 		lwc_string_unref(old_string);
1543 
1544 	return CSS_OK;
1545 }
1546 #undef LIST_STYLE_IMAGE_INDEX
1547 #undef LIST_STYLE_IMAGE_SHIFT
1548 #undef LIST_STYLE_IMAGE_MASK
1549 
1550 #define LIST_STYLE_POSITION_INDEX 14
1551 #define LIST_STYLE_POSITION_SHIFT 30
1552 #define LIST_STYLE_POSITION_MASK 0xc0000000
1553 
set_list_style_position(css_computed_style * style,uint8_t type)1554 static inline css_error set_list_style_position(css_computed_style *style,
1555 		uint8_t type)
1556 {
1557 	uint32_t *bits;
1558 
1559 	bits = &style->i.bits[LIST_STYLE_POSITION_INDEX];
1560 
1561 	/* 2bits: tt : type */
1562 	*bits = (*bits & ~LIST_STYLE_POSITION_MASK) | (((uint32_t)type & 0x3)
1563 			<< LIST_STYLE_POSITION_SHIFT);
1564 
1565 	return CSS_OK;
1566 }
1567 #undef LIST_STYLE_POSITION_INDEX
1568 #undef LIST_STYLE_POSITION_SHIFT
1569 #undef LIST_STYLE_POSITION_MASK
1570 
1571 #define LIST_STYLE_TYPE_INDEX 13
1572 #define LIST_STYLE_TYPE_SHIFT 20
1573 #define LIST_STYLE_TYPE_MASK 0xf00000
1574 
set_list_style_type(css_computed_style * style,uint8_t type)1575 static inline css_error set_list_style_type(css_computed_style *style, uint8_t
1576 		type)
1577 {
1578 	uint32_t *bits;
1579 
1580 	bits = &style->i.bits[LIST_STYLE_TYPE_INDEX];
1581 
1582 	/* 4bits: tttt : type */
1583 	*bits = (*bits & ~LIST_STYLE_TYPE_MASK) | (((uint32_t)type & 0xf) <<
1584 			LIST_STYLE_TYPE_SHIFT);
1585 
1586 	return CSS_OK;
1587 }
1588 #undef LIST_STYLE_TYPE_INDEX
1589 #undef LIST_STYLE_TYPE_SHIFT
1590 #undef LIST_STYLE_TYPE_MASK
1591 
1592 #define MARGIN_BOTTOM_INDEX 3
1593 #define MARGIN_BOTTOM_SHIFT 18
1594 #define MARGIN_BOTTOM_MASK 0x1fc0000
1595 
set_margin_bottom(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)1596 static inline css_error set_margin_bottom(css_computed_style *style, uint8_t
1597 		type, css_fixed length, css_unit unit)
1598 {
1599 	uint32_t *bits;
1600 
1601 	bits = &style->i.bits[MARGIN_BOTTOM_INDEX];
1602 
1603 	/* 7bits: uuuuutt : unit | type */
1604 	*bits = (*bits & ~MARGIN_BOTTOM_MASK) | ((((uint32_t)type & 0x3) | (
1605 			unit << 2)) << MARGIN_BOTTOM_SHIFT);
1606 
1607 	style->i.margin_bottom = length;
1608 
1609 	return CSS_OK;
1610 }
1611 #undef MARGIN_BOTTOM_INDEX
1612 #undef MARGIN_BOTTOM_SHIFT
1613 #undef MARGIN_BOTTOM_MASK
1614 
1615 #define MARGIN_LEFT_INDEX 3
1616 #define MARGIN_LEFT_SHIFT 11
1617 #define MARGIN_LEFT_MASK 0x3f800
1618 
set_margin_left(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)1619 static inline css_error set_margin_left(css_computed_style *style, uint8_t
1620 		type, css_fixed length, css_unit unit)
1621 {
1622 	uint32_t *bits;
1623 
1624 	bits = &style->i.bits[MARGIN_LEFT_INDEX];
1625 
1626 	/* 7bits: uuuuutt : unit | type */
1627 	*bits = (*bits & ~MARGIN_LEFT_MASK) | ((((uint32_t)type & 0x3) | (unit
1628 			<< 2)) << MARGIN_LEFT_SHIFT);
1629 
1630 	style->i.margin_left = length;
1631 
1632 	return CSS_OK;
1633 }
1634 #undef MARGIN_LEFT_INDEX
1635 #undef MARGIN_LEFT_SHIFT
1636 #undef MARGIN_LEFT_MASK
1637 
1638 #define MARGIN_RIGHT_INDEX 6
1639 #define MARGIN_RIGHT_SHIFT 4
1640 #define MARGIN_RIGHT_MASK 0x7f0
1641 
set_margin_right(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)1642 static inline css_error set_margin_right(css_computed_style *style, uint8_t
1643 		type, css_fixed length, css_unit unit)
1644 {
1645 	uint32_t *bits;
1646 
1647 	bits = &style->i.bits[MARGIN_RIGHT_INDEX];
1648 
1649 	/* 7bits: uuuuutt : unit | type */
1650 	*bits = (*bits & ~MARGIN_RIGHT_MASK) | ((((uint32_t)type & 0x3) | (unit
1651 			<< 2)) << MARGIN_RIGHT_SHIFT);
1652 
1653 	style->i.margin_right = length;
1654 
1655 	return CSS_OK;
1656 }
1657 #undef MARGIN_RIGHT_INDEX
1658 #undef MARGIN_RIGHT_SHIFT
1659 #undef MARGIN_RIGHT_MASK
1660 
1661 #define MARGIN_TOP_INDEX 7
1662 #define MARGIN_TOP_SHIFT 4
1663 #define MARGIN_TOP_MASK 0x7f0
1664 
set_margin_top(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)1665 static inline css_error set_margin_top(css_computed_style *style, uint8_t type,
1666 		css_fixed length, css_unit unit)
1667 {
1668 	uint32_t *bits;
1669 
1670 	bits = &style->i.bits[MARGIN_TOP_INDEX];
1671 
1672 	/* 7bits: uuuuutt : unit | type */
1673 	*bits = (*bits & ~MARGIN_TOP_MASK) | ((((uint32_t)type & 0x3) | (unit
1674 			<< 2)) << MARGIN_TOP_SHIFT);
1675 
1676 	style->i.margin_top = length;
1677 
1678 	return CSS_OK;
1679 }
1680 #undef MARGIN_TOP_INDEX
1681 #undef MARGIN_TOP_SHIFT
1682 #undef MARGIN_TOP_MASK
1683 
1684 #define MAX_HEIGHT_INDEX 6
1685 #define MAX_HEIGHT_SHIFT 18
1686 #define MAX_HEIGHT_MASK 0x1fc0000
1687 
set_max_height(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)1688 static inline css_error set_max_height(css_computed_style *style, uint8_t type,
1689 		css_fixed length, css_unit unit)
1690 {
1691 	uint32_t *bits;
1692 
1693 	bits = &style->i.bits[MAX_HEIGHT_INDEX];
1694 
1695 	/* 7bits: uuuuutt : unit | type */
1696 	*bits = (*bits & ~MAX_HEIGHT_MASK) | ((((uint32_t)type & 0x3) | (unit
1697 			<< 2)) << MAX_HEIGHT_SHIFT);
1698 
1699 	style->i.max_height = length;
1700 
1701 	return CSS_OK;
1702 }
1703 #undef MAX_HEIGHT_INDEX
1704 #undef MAX_HEIGHT_SHIFT
1705 #undef MAX_HEIGHT_MASK
1706 
1707 #define MAX_WIDTH_INDEX 3
1708 #define MAX_WIDTH_SHIFT 25
1709 #define MAX_WIDTH_MASK 0xfe000000
1710 
set_max_width(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)1711 static inline css_error set_max_width(css_computed_style *style, uint8_t type,
1712 		css_fixed length, css_unit unit)
1713 {
1714 	uint32_t *bits;
1715 
1716 	bits = &style->i.bits[MAX_WIDTH_INDEX];
1717 
1718 	/* 7bits: uuuuutt : unit | type */
1719 	*bits = (*bits & ~MAX_WIDTH_MASK) | ((((uint32_t)type & 0x3) | (unit <<
1720 			2)) << MAX_WIDTH_SHIFT);
1721 
1722 	style->i.max_width = length;
1723 
1724 	return CSS_OK;
1725 }
1726 #undef MAX_WIDTH_INDEX
1727 #undef MAX_WIDTH_SHIFT
1728 #undef MAX_WIDTH_MASK
1729 
1730 #define MIN_HEIGHT_INDEX 7
1731 #define MIN_HEIGHT_SHIFT 11
1732 #define MIN_HEIGHT_MASK 0x3f800
1733 
set_min_height(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)1734 static inline css_error set_min_height(css_computed_style *style, uint8_t type,
1735 		css_fixed length, css_unit unit)
1736 {
1737 	uint32_t *bits;
1738 
1739 	bits = &style->i.bits[MIN_HEIGHT_INDEX];
1740 
1741 	/* 7bits: uuuuutt : unit | type */
1742 	*bits = (*bits & ~MIN_HEIGHT_MASK) | ((((uint32_t)type & 0x3) | (unit
1743 			<< 2)) << MIN_HEIGHT_SHIFT);
1744 
1745 	style->i.min_height = length;
1746 
1747 	return CSS_OK;
1748 }
1749 #undef MIN_HEIGHT_INDEX
1750 #undef MIN_HEIGHT_SHIFT
1751 #undef MIN_HEIGHT_MASK
1752 
1753 #define MIN_WIDTH_INDEX 6
1754 #define MIN_WIDTH_SHIFT 11
1755 #define MIN_WIDTH_MASK 0x3f800
1756 
set_min_width(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)1757 static inline css_error set_min_width(css_computed_style *style, uint8_t type,
1758 		css_fixed length, css_unit unit)
1759 {
1760 	uint32_t *bits;
1761 
1762 	bits = &style->i.bits[MIN_WIDTH_INDEX];
1763 
1764 	/* 7bits: uuuuutt : unit | type */
1765 	*bits = (*bits & ~MIN_WIDTH_MASK) | ((((uint32_t)type & 0x3) | (unit <<
1766 			2)) << MIN_WIDTH_SHIFT);
1767 
1768 	style->i.min_width = length;
1769 
1770 	return CSS_OK;
1771 }
1772 #undef MIN_WIDTH_INDEX
1773 #undef MIN_WIDTH_SHIFT
1774 #undef MIN_WIDTH_MASK
1775 
1776 #define OPACITY_INDEX 14
1777 #define OPACITY_SHIFT 25
1778 #define OPACITY_MASK 0x2000000
1779 
set_opacity(css_computed_style * style,uint8_t type,css_fixed fixed)1780 static inline css_error set_opacity(css_computed_style *style, uint8_t type,
1781 		css_fixed fixed)
1782 {
1783 	uint32_t *bits;
1784 
1785 	bits = &style->i.bits[OPACITY_INDEX];
1786 
1787 	/* 1bit: t : type */
1788 	*bits = (*bits & ~OPACITY_MASK) | (((uint32_t)type & 0x1) <<
1789 			OPACITY_SHIFT);
1790 
1791 	style->i.opacity = fixed;
1792 
1793 	return CSS_OK;
1794 }
1795 #undef OPACITY_INDEX
1796 #undef OPACITY_SHIFT
1797 #undef OPACITY_MASK
1798 
1799 #define ORDER_INDEX 14
1800 #define ORDER_SHIFT 26
1801 #define ORDER_MASK 0x4000000
1802 
set_order(css_computed_style * style,uint8_t type,int32_t integer)1803 static inline css_error set_order(css_computed_style *style, uint8_t type,
1804 		int32_t integer)
1805 {
1806 	uint32_t *bits;
1807 
1808 	bits = &style->i.bits[ORDER_INDEX];
1809 
1810 	/* 1bit: t : type */
1811 	*bits = (*bits & ~ORDER_MASK) | (((uint32_t)type & 0x1) << ORDER_SHIFT);
1812 
1813 	style->i.order = integer;
1814 
1815 	return CSS_OK;
1816 }
1817 #undef ORDER_INDEX
1818 #undef ORDER_SHIFT
1819 #undef ORDER_MASK
1820 
1821 #define ORPHANS_INDEX 14
1822 #define ORPHANS_SHIFT 22
1823 #define ORPHANS_MASK 0x400000
1824 
set_orphans(css_computed_style * style,uint8_t type,int32_t integer)1825 static inline css_error set_orphans(css_computed_style *style, uint8_t type,
1826 		int32_t integer)
1827 {
1828 	uint32_t *bits;
1829 
1830 	bits = &style->i.bits[ORPHANS_INDEX];
1831 
1832 	/* 1bit: t : type */
1833 	*bits = (*bits & ~ORPHANS_MASK) | (((uint32_t)type & 0x1) <<
1834 			ORPHANS_SHIFT);
1835 
1836 	style->i.orphans = integer;
1837 
1838 	return CSS_OK;
1839 }
1840 #undef ORPHANS_INDEX
1841 #undef ORPHANS_SHIFT
1842 #undef ORPHANS_MASK
1843 
1844 #define OUTLINE_COLOR_INDEX 11
1845 #define OUTLINE_COLOR_SHIFT 12
1846 #define OUTLINE_COLOR_MASK 0x3000
1847 
set_outline_color(css_computed_style * style,uint8_t type,css_color color)1848 static inline css_error set_outline_color(css_computed_style *style, uint8_t
1849 		type, css_color color)
1850 {
1851 	uint32_t *bits;
1852 
1853 	bits = &style->i.bits[OUTLINE_COLOR_INDEX];
1854 
1855 	/* 2bits: tt : type */
1856 	*bits = (*bits & ~OUTLINE_COLOR_MASK) | (((uint32_t)type & 0x3) <<
1857 			OUTLINE_COLOR_SHIFT);
1858 
1859 	style->i.outline_color = color;
1860 
1861 	return CSS_OK;
1862 }
1863 #undef OUTLINE_COLOR_INDEX
1864 #undef OUTLINE_COLOR_SHIFT
1865 #undef OUTLINE_COLOR_MASK
1866 
1867 #define OUTLINE_STYLE_INDEX 5
1868 #define OUTLINE_STYLE_SHIFT 0
1869 #define OUTLINE_STYLE_MASK 0xf
1870 
set_outline_style(css_computed_style * style,uint8_t type)1871 static inline css_error set_outline_style(css_computed_style *style, uint8_t
1872 		type)
1873 {
1874 	uint32_t *bits;
1875 
1876 	bits = &style->i.bits[OUTLINE_STYLE_INDEX];
1877 
1878 	/* 4bits: tttt : type */
1879 	*bits = (*bits & ~OUTLINE_STYLE_MASK) | (((uint32_t)type & 0xf) <<
1880 			OUTLINE_STYLE_SHIFT);
1881 
1882 	return CSS_OK;
1883 }
1884 #undef OUTLINE_STYLE_INDEX
1885 #undef OUTLINE_STYLE_SHIFT
1886 #undef OUTLINE_STYLE_MASK
1887 
1888 #define OUTLINE_WIDTH_INDEX 0
1889 #define OUTLINE_WIDTH_SHIFT 16
1890 #define OUTLINE_WIDTH_MASK 0xff0000
1891 
set_outline_width(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)1892 static inline css_error set_outline_width(css_computed_style *style, uint8_t
1893 		type, css_fixed length, css_unit unit)
1894 {
1895 	uint32_t *bits;
1896 
1897 	bits = &style->i.bits[OUTLINE_WIDTH_INDEX];
1898 
1899 	/* 8bits: uuuuuttt : unit | type */
1900 	*bits = (*bits & ~OUTLINE_WIDTH_MASK) | ((((uint32_t)type & 0x7) | (
1901 			unit << 3)) << OUTLINE_WIDTH_SHIFT);
1902 
1903 	style->i.outline_width = length;
1904 
1905 	return CSS_OK;
1906 }
1907 #undef OUTLINE_WIDTH_INDEX
1908 #undef OUTLINE_WIDTH_SHIFT
1909 #undef OUTLINE_WIDTH_MASK
1910 
1911 #define OVERFLOW_X_INDEX 9
1912 #define OVERFLOW_X_SHIFT 14
1913 #define OVERFLOW_X_MASK 0x1c000
1914 
set_overflow_x(css_computed_style * style,uint8_t type)1915 static inline css_error set_overflow_x(css_computed_style *style, uint8_t type)
1916 {
1917 	uint32_t *bits;
1918 
1919 	bits = &style->i.bits[OVERFLOW_X_INDEX];
1920 
1921 	/* 3bits: ttt : type */
1922 	*bits = (*bits & ~OVERFLOW_X_MASK) | (((uint32_t)type & 0x7) <<
1923 			OVERFLOW_X_SHIFT);
1924 
1925 	return CSS_OK;
1926 }
1927 #undef OVERFLOW_X_INDEX
1928 #undef OVERFLOW_X_SHIFT
1929 #undef OVERFLOW_X_MASK
1930 
1931 #define OVERFLOW_Y_INDEX 9
1932 #define OVERFLOW_Y_SHIFT 11
1933 #define OVERFLOW_Y_MASK 0x3800
1934 
set_overflow_y(css_computed_style * style,uint8_t type)1935 static inline css_error set_overflow_y(css_computed_style *style, uint8_t type)
1936 {
1937 	uint32_t *bits;
1938 
1939 	bits = &style->i.bits[OVERFLOW_Y_INDEX];
1940 
1941 	/* 3bits: ttt : type */
1942 	*bits = (*bits & ~OVERFLOW_Y_MASK) | (((uint32_t)type & 0x7) <<
1943 			OVERFLOW_Y_SHIFT);
1944 
1945 	return CSS_OK;
1946 }
1947 #undef OVERFLOW_Y_INDEX
1948 #undef OVERFLOW_Y_SHIFT
1949 #undef OVERFLOW_Y_MASK
1950 
1951 #define PADDING_BOTTOM_INDEX 8
1952 #define PADDING_BOTTOM_SHIFT 14
1953 #define PADDING_BOTTOM_MASK 0xfc000
1954 
set_padding_bottom(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)1955 static inline css_error set_padding_bottom(css_computed_style *style, uint8_t
1956 		type, css_fixed length, css_unit unit)
1957 {
1958 	uint32_t *bits;
1959 
1960 	bits = &style->i.bits[PADDING_BOTTOM_INDEX];
1961 
1962 	/* 6bits: uuuuut : unit | type */
1963 	*bits = (*bits & ~PADDING_BOTTOM_MASK) | ((((uint32_t)type & 0x1) | (
1964 			unit << 1)) << PADDING_BOTTOM_SHIFT);
1965 
1966 	style->i.padding_bottom = length;
1967 
1968 	return CSS_OK;
1969 }
1970 #undef PADDING_BOTTOM_INDEX
1971 #undef PADDING_BOTTOM_SHIFT
1972 #undef PADDING_BOTTOM_MASK
1973 
1974 #define PADDING_LEFT_INDEX 8
1975 #define PADDING_LEFT_SHIFT 26
1976 #define PADDING_LEFT_MASK 0xfc000000
1977 
set_padding_left(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)1978 static inline css_error set_padding_left(css_computed_style *style, uint8_t
1979 		type, css_fixed length, css_unit unit)
1980 {
1981 	uint32_t *bits;
1982 
1983 	bits = &style->i.bits[PADDING_LEFT_INDEX];
1984 
1985 	/* 6bits: uuuuut : unit | type */
1986 	*bits = (*bits & ~PADDING_LEFT_MASK) | ((((uint32_t)type & 0x1) | (unit
1987 			<< 1)) << PADDING_LEFT_SHIFT);
1988 
1989 	style->i.padding_left = length;
1990 
1991 	return CSS_OK;
1992 }
1993 #undef PADDING_LEFT_INDEX
1994 #undef PADDING_LEFT_SHIFT
1995 #undef PADDING_LEFT_MASK
1996 
1997 #define PADDING_RIGHT_INDEX 8
1998 #define PADDING_RIGHT_SHIFT 20
1999 #define PADDING_RIGHT_MASK 0x3f00000
2000 
set_padding_right(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)2001 static inline css_error set_padding_right(css_computed_style *style, uint8_t
2002 		type, css_fixed length, css_unit unit)
2003 {
2004 	uint32_t *bits;
2005 
2006 	bits = &style->i.bits[PADDING_RIGHT_INDEX];
2007 
2008 	/* 6bits: uuuuut : unit | type */
2009 	*bits = (*bits & ~PADDING_RIGHT_MASK) | ((((uint32_t)type & 0x1) | (
2010 			unit << 1)) << PADDING_RIGHT_SHIFT);
2011 
2012 	style->i.padding_right = length;
2013 
2014 	return CSS_OK;
2015 }
2016 #undef PADDING_RIGHT_INDEX
2017 #undef PADDING_RIGHT_SHIFT
2018 #undef PADDING_RIGHT_MASK
2019 
2020 #define PADDING_TOP_INDEX 2
2021 #define PADDING_TOP_SHIFT 0
2022 #define PADDING_TOP_MASK 0x3f
2023 
set_padding_top(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)2024 static inline css_error set_padding_top(css_computed_style *style, uint8_t
2025 		type, css_fixed length, css_unit unit)
2026 {
2027 	uint32_t *bits;
2028 
2029 	bits = &style->i.bits[PADDING_TOP_INDEX];
2030 
2031 	/* 6bits: uuuuut : unit | type */
2032 	*bits = (*bits & ~PADDING_TOP_MASK) | ((((uint32_t)type & 0x1) | (unit
2033 			<< 1)) << PADDING_TOP_SHIFT);
2034 
2035 	style->i.padding_top = length;
2036 
2037 	return CSS_OK;
2038 }
2039 #undef PADDING_TOP_INDEX
2040 #undef PADDING_TOP_SHIFT
2041 #undef PADDING_TOP_MASK
2042 
2043 #define PAGE_BREAK_AFTER_INDEX 9
2044 #define PAGE_BREAK_AFTER_SHIFT 2
2045 #define PAGE_BREAK_AFTER_MASK 0x1c
2046 
set_page_break_after(css_computed_style * style,uint8_t type)2047 static inline css_error set_page_break_after(css_computed_style *style, uint8_t
2048 		type)
2049 {
2050 	uint32_t *bits;
2051 
2052 	bits = &style->i.bits[PAGE_BREAK_AFTER_INDEX];
2053 
2054 	/* 3bits: ttt : type */
2055 	*bits = (*bits & ~PAGE_BREAK_AFTER_MASK) | (((uint32_t)type & 0x7) <<
2056 			PAGE_BREAK_AFTER_SHIFT);
2057 
2058 	return CSS_OK;
2059 }
2060 #undef PAGE_BREAK_AFTER_INDEX
2061 #undef PAGE_BREAK_AFTER_SHIFT
2062 #undef PAGE_BREAK_AFTER_MASK
2063 
2064 #define PAGE_BREAK_BEFORE_INDEX 9
2065 #define PAGE_BREAK_BEFORE_SHIFT 23
2066 #define PAGE_BREAK_BEFORE_MASK 0x3800000
2067 
set_page_break_before(css_computed_style * style,uint8_t type)2068 static inline css_error set_page_break_before(css_computed_style *style,
2069 		uint8_t type)
2070 {
2071 	uint32_t *bits;
2072 
2073 	bits = &style->i.bits[PAGE_BREAK_BEFORE_INDEX];
2074 
2075 	/* 3bits: ttt : type */
2076 	*bits = (*bits & ~PAGE_BREAK_BEFORE_MASK) | (((uint32_t)type & 0x7) <<
2077 			PAGE_BREAK_BEFORE_SHIFT);
2078 
2079 	return CSS_OK;
2080 }
2081 #undef PAGE_BREAK_BEFORE_INDEX
2082 #undef PAGE_BREAK_BEFORE_SHIFT
2083 #undef PAGE_BREAK_BEFORE_MASK
2084 
2085 #define PAGE_BREAK_INSIDE_INDEX 10
2086 #define PAGE_BREAK_INSIDE_SHIFT 4
2087 #define PAGE_BREAK_INSIDE_MASK 0x30
2088 
set_page_break_inside(css_computed_style * style,uint8_t type)2089 static inline css_error set_page_break_inside(css_computed_style *style,
2090 		uint8_t type)
2091 {
2092 	uint32_t *bits;
2093 
2094 	bits = &style->i.bits[PAGE_BREAK_INSIDE_INDEX];
2095 
2096 	/* 2bits: tt : type */
2097 	*bits = (*bits & ~PAGE_BREAK_INSIDE_MASK) | (((uint32_t)type & 0x3) <<
2098 			PAGE_BREAK_INSIDE_SHIFT);
2099 
2100 	return CSS_OK;
2101 }
2102 #undef PAGE_BREAK_INSIDE_INDEX
2103 #undef PAGE_BREAK_INSIDE_SHIFT
2104 #undef PAGE_BREAK_INSIDE_MASK
2105 
2106 #define POSITION_INDEX 10
2107 #define POSITION_SHIFT 26
2108 #define POSITION_MASK 0x1c000000
2109 
set_position(css_computed_style * style,uint8_t type)2110 static inline css_error set_position(css_computed_style *style, uint8_t type)
2111 {
2112 	uint32_t *bits;
2113 
2114 	bits = &style->i.bits[POSITION_INDEX];
2115 
2116 	/* 3bits: ttt : type */
2117 	*bits = (*bits & ~POSITION_MASK) | (((uint32_t)type & 0x7) <<
2118 			POSITION_SHIFT);
2119 
2120 	return CSS_OK;
2121 }
2122 #undef POSITION_INDEX
2123 #undef POSITION_SHIFT
2124 #undef POSITION_MASK
2125 
2126 #define QUOTES_INDEX 14
2127 #define QUOTES_SHIFT 27
2128 #define QUOTES_MASK 0x8000000
2129 
set_quotes(css_computed_style * style,uint8_t type,lwc_string ** string_arr)2130 static inline css_error set_quotes(css_computed_style *style, uint8_t type,
2131 		lwc_string **string_arr)
2132 {
2133 	uint32_t *bits;
2134 
2135 	bits = &style->i.bits[QUOTES_INDEX];
2136 
2137 	/* 1bit: t : type */
2138 	*bits = (*bits & ~QUOTES_MASK) | (((uint32_t)type & 0x1) <<
2139 			QUOTES_SHIFT);
2140 
2141 	lwc_string **old_string_arr = style->quotes;
2142 	lwc_string **s;
2143 
2144 	for (s = string_arr; s != NULL && *s != NULL; s++)
2145 		*s = lwc_string_ref(*s);
2146 
2147 	style->quotes = string_arr;
2148 
2149 	/* Free existing array */
2150 	if (old_string_arr != NULL) {
2151 		for (s = old_string_arr; *s != NULL; s++)
2152 			lwc_string_unref(*s);
2153 
2154 		if (old_string_arr != string_arr)
2155 			free(old_string_arr);
2156 	}
2157 
2158 	return CSS_OK;
2159 }
2160 #undef QUOTES_INDEX
2161 #undef QUOTES_SHIFT
2162 #undef QUOTES_MASK
2163 
2164 #define RIGHT_INDEX 7
2165 #define RIGHT_SHIFT 25
2166 #define RIGHT_MASK 0xfe000000
2167 
set_right(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)2168 static inline css_error set_right(css_computed_style *style, uint8_t type,
2169 		css_fixed length, css_unit unit)
2170 {
2171 	uint32_t *bits;
2172 
2173 	bits = &style->i.bits[RIGHT_INDEX];
2174 
2175 	/* 7bits: uuuuutt : unit | type */
2176 	*bits = (*bits & ~RIGHT_MASK) | ((((uint32_t)type & 0x3) | (unit << 2))
2177 			<< RIGHT_SHIFT);
2178 
2179 	style->i.right = length;
2180 
2181 	return CSS_OK;
2182 }
2183 #undef RIGHT_INDEX
2184 #undef RIGHT_SHIFT
2185 #undef RIGHT_MASK
2186 
2187 #define TABLE_LAYOUT_INDEX 11
2188 #define TABLE_LAYOUT_SHIFT 4
2189 #define TABLE_LAYOUT_MASK 0x30
2190 
set_table_layout(css_computed_style * style,uint8_t type)2191 static inline css_error set_table_layout(css_computed_style *style, uint8_t
2192 		type)
2193 {
2194 	uint32_t *bits;
2195 
2196 	bits = &style->i.bits[TABLE_LAYOUT_INDEX];
2197 
2198 	/* 2bits: tt : type */
2199 	*bits = (*bits & ~TABLE_LAYOUT_MASK) | (((uint32_t)type & 0x3) <<
2200 			TABLE_LAYOUT_SHIFT);
2201 
2202 	return CSS_OK;
2203 }
2204 #undef TABLE_LAYOUT_INDEX
2205 #undef TABLE_LAYOUT_SHIFT
2206 #undef TABLE_LAYOUT_MASK
2207 
2208 #define TEXT_ALIGN_INDEX 13
2209 #define TEXT_ALIGN_SHIFT 16
2210 #define TEXT_ALIGN_MASK 0xf0000
2211 
set_text_align(css_computed_style * style,uint8_t type)2212 static inline css_error set_text_align(css_computed_style *style, uint8_t type)
2213 {
2214 	uint32_t *bits;
2215 
2216 	bits = &style->i.bits[TEXT_ALIGN_INDEX];
2217 
2218 	/* 4bits: tttt : type */
2219 	*bits = (*bits & ~TEXT_ALIGN_MASK) | (((uint32_t)type & 0xf) <<
2220 			TEXT_ALIGN_SHIFT);
2221 
2222 	return CSS_OK;
2223 }
2224 #undef TEXT_ALIGN_INDEX
2225 #undef TEXT_ALIGN_SHIFT
2226 #undef TEXT_ALIGN_MASK
2227 
2228 #define TEXT_DECORATION_INDEX 8
2229 #define TEXT_DECORATION_SHIFT 9
2230 #define TEXT_DECORATION_MASK 0x3e00
2231 
set_text_decoration(css_computed_style * style,uint8_t type)2232 static inline css_error set_text_decoration(css_computed_style *style, uint8_t
2233 		type)
2234 {
2235 	uint32_t *bits;
2236 
2237 	bits = &style->i.bits[TEXT_DECORATION_INDEX];
2238 
2239 	/* 5bits: ttttt : type */
2240 	*bits = (*bits & ~TEXT_DECORATION_MASK) | (((uint32_t)type & 0x1f) <<
2241 			TEXT_DECORATION_SHIFT);
2242 
2243 	return CSS_OK;
2244 }
2245 #undef TEXT_DECORATION_INDEX
2246 #undef TEXT_DECORATION_SHIFT
2247 #undef TEXT_DECORATION_MASK
2248 
2249 #define TEXT_INDENT_INDEX 3
2250 #define TEXT_INDENT_SHIFT 5
2251 #define TEXT_INDENT_MASK 0x7e0
2252 
set_text_indent(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)2253 static inline css_error set_text_indent(css_computed_style *style, uint8_t
2254 		type, css_fixed length, css_unit unit)
2255 {
2256 	uint32_t *bits;
2257 
2258 	bits = &style->i.bits[TEXT_INDENT_INDEX];
2259 
2260 	/* 6bits: uuuuut : unit | type */
2261 	*bits = (*bits & ~TEXT_INDENT_MASK) | ((((uint32_t)type & 0x1) | (unit
2262 			<< 1)) << TEXT_INDENT_SHIFT);
2263 
2264 	style->i.text_indent = length;
2265 
2266 	return CSS_OK;
2267 }
2268 #undef TEXT_INDENT_INDEX
2269 #undef TEXT_INDENT_SHIFT
2270 #undef TEXT_INDENT_MASK
2271 
2272 #define TEXT_TRANSFORM_INDEX 9
2273 #define TEXT_TRANSFORM_SHIFT 8
2274 #define TEXT_TRANSFORM_MASK 0x700
2275 
set_text_transform(css_computed_style * style,uint8_t type)2276 static inline css_error set_text_transform(css_computed_style *style, uint8_t
2277 		type)
2278 {
2279 	uint32_t *bits;
2280 
2281 	bits = &style->i.bits[TEXT_TRANSFORM_INDEX];
2282 
2283 	/* 3bits: ttt : type */
2284 	*bits = (*bits & ~TEXT_TRANSFORM_MASK) | (((uint32_t)type & 0x7) <<
2285 			TEXT_TRANSFORM_SHIFT);
2286 
2287 	return CSS_OK;
2288 }
2289 #undef TEXT_TRANSFORM_INDEX
2290 #undef TEXT_TRANSFORM_SHIFT
2291 #undef TEXT_TRANSFORM_MASK
2292 
2293 #define TOP_INDEX 6
2294 #define TOP_SHIFT 25
2295 #define TOP_MASK 0xfe000000
2296 
set_top(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)2297 static inline css_error set_top(css_computed_style *style, uint8_t type,
2298 		css_fixed length, css_unit unit)
2299 {
2300 	uint32_t *bits;
2301 
2302 	bits = &style->i.bits[TOP_INDEX];
2303 
2304 	/* 7bits: uuuuutt : unit | type */
2305 	*bits = (*bits & ~TOP_MASK) | ((((uint32_t)type & 0x3) | (unit << 2))
2306 			<< TOP_SHIFT);
2307 
2308 	style->i.top = length;
2309 
2310 	return CSS_OK;
2311 }
2312 #undef TOP_INDEX
2313 #undef TOP_SHIFT
2314 #undef TOP_MASK
2315 
2316 #define UNICODE_BIDI_INDEX 9
2317 #define UNICODE_BIDI_SHIFT 0
2318 #define UNICODE_BIDI_MASK 0x3
2319 
set_unicode_bidi(css_computed_style * style,uint8_t type)2320 static inline css_error set_unicode_bidi(css_computed_style *style, uint8_t
2321 		type)
2322 {
2323 	uint32_t *bits;
2324 
2325 	bits = &style->i.bits[UNICODE_BIDI_INDEX];
2326 
2327 	/* 2bits: tt : type */
2328 	*bits = (*bits & ~UNICODE_BIDI_MASK) | (((uint32_t)type & 0x3) <<
2329 			UNICODE_BIDI_SHIFT);
2330 
2331 	return CSS_OK;
2332 }
2333 #undef UNICODE_BIDI_INDEX
2334 #undef UNICODE_BIDI_SHIFT
2335 #undef UNICODE_BIDI_MASK
2336 
2337 #define VERTICAL_ALIGN_INDEX 1
2338 #define VERTICAL_ALIGN_SHIFT 23
2339 #define VERTICAL_ALIGN_MASK 0xff800000
2340 
set_vertical_align(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)2341 static inline css_error set_vertical_align(css_computed_style *style, uint8_t
2342 		type, css_fixed length, css_unit unit)
2343 {
2344 	uint32_t *bits;
2345 
2346 	bits = &style->i.bits[VERTICAL_ALIGN_INDEX];
2347 
2348 	/* 9bits: uuuuutttt : unit | type */
2349 	*bits = (*bits & ~VERTICAL_ALIGN_MASK) | ((((uint32_t)type & 0xf) | (
2350 			unit << 4)) << VERTICAL_ALIGN_SHIFT);
2351 
2352 	style->i.vertical_align = length;
2353 
2354 	return CSS_OK;
2355 }
2356 #undef VERTICAL_ALIGN_INDEX
2357 #undef VERTICAL_ALIGN_SHIFT
2358 #undef VERTICAL_ALIGN_MASK
2359 
2360 #define VISIBILITY_INDEX 11
2361 #define VISIBILITY_SHIFT 14
2362 #define VISIBILITY_MASK 0xc000
2363 
set_visibility(css_computed_style * style,uint8_t type)2364 static inline css_error set_visibility(css_computed_style *style, uint8_t type)
2365 {
2366 	uint32_t *bits;
2367 
2368 	bits = &style->i.bits[VISIBILITY_INDEX];
2369 
2370 	/* 2bits: tt : type */
2371 	*bits = (*bits & ~VISIBILITY_MASK) | (((uint32_t)type & 0x3) <<
2372 			VISIBILITY_SHIFT);
2373 
2374 	return CSS_OK;
2375 }
2376 #undef VISIBILITY_INDEX
2377 #undef VISIBILITY_SHIFT
2378 #undef VISIBILITY_MASK
2379 
2380 #define WHITE_SPACE_INDEX 10
2381 #define WHITE_SPACE_SHIFT 20
2382 #define WHITE_SPACE_MASK 0x700000
2383 
set_white_space(css_computed_style * style,uint8_t type)2384 static inline css_error set_white_space(css_computed_style *style, uint8_t type)
2385 {
2386 	uint32_t *bits;
2387 
2388 	bits = &style->i.bits[WHITE_SPACE_INDEX];
2389 
2390 	/* 3bits: ttt : type */
2391 	*bits = (*bits & ~WHITE_SPACE_MASK) | (((uint32_t)type & 0x7) <<
2392 			WHITE_SPACE_SHIFT);
2393 
2394 	return CSS_OK;
2395 }
2396 #undef WHITE_SPACE_INDEX
2397 #undef WHITE_SPACE_SHIFT
2398 #undef WHITE_SPACE_MASK
2399 
2400 #define WIDOWS_INDEX 14
2401 #define WIDOWS_SHIFT 24
2402 #define WIDOWS_MASK 0x1000000
2403 
set_widows(css_computed_style * style,uint8_t type,int32_t integer)2404 static inline css_error set_widows(css_computed_style *style, uint8_t type,
2405 		int32_t integer)
2406 {
2407 	uint32_t *bits;
2408 
2409 	bits = &style->i.bits[WIDOWS_INDEX];
2410 
2411 	/* 1bit: t : type */
2412 	*bits = (*bits & ~WIDOWS_MASK) | (((uint32_t)type & 0x1) <<
2413 			WIDOWS_SHIFT);
2414 
2415 	style->i.widows = integer;
2416 
2417 	return CSS_OK;
2418 }
2419 #undef WIDOWS_INDEX
2420 #undef WIDOWS_SHIFT
2421 #undef WIDOWS_MASK
2422 
2423 #define WIDTH_INDEX 5
2424 #define WIDTH_SHIFT 25
2425 #define WIDTH_MASK 0xfe000000
2426 
set_width(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)2427 static inline css_error set_width(css_computed_style *style, uint8_t type,
2428 		css_fixed length, css_unit unit)
2429 {
2430 	uint32_t *bits;
2431 
2432 	bits = &style->i.bits[WIDTH_INDEX];
2433 
2434 	/* 7bits: uuuuutt : unit | type */
2435 	*bits = (*bits & ~WIDTH_MASK) | ((((uint32_t)type & 0x3) | (unit << 2))
2436 			<< WIDTH_SHIFT);
2437 
2438 	style->i.width = length;
2439 
2440 	return CSS_OK;
2441 }
2442 #undef WIDTH_INDEX
2443 #undef WIDTH_SHIFT
2444 #undef WIDTH_MASK
2445 
2446 #define WORD_SPACING_INDEX 4
2447 #define WORD_SPACING_SHIFT 25
2448 #define WORD_SPACING_MASK 0xfe000000
2449 
set_word_spacing(css_computed_style * style,uint8_t type,css_fixed length,css_unit unit)2450 static inline css_error set_word_spacing(css_computed_style *style, uint8_t
2451 		type, css_fixed length, css_unit unit)
2452 {
2453 	uint32_t *bits;
2454 
2455 	bits = &style->i.bits[WORD_SPACING_INDEX];
2456 
2457 	/* 7bits: uuuuutt : unit | type */
2458 	*bits = (*bits & ~WORD_SPACING_MASK) | ((((uint32_t)type & 0x3) | (unit
2459 			<< 2)) << WORD_SPACING_SHIFT);
2460 
2461 	style->i.word_spacing = length;
2462 
2463 	return CSS_OK;
2464 }
2465 #undef WORD_SPACING_INDEX
2466 #undef WORD_SPACING_SHIFT
2467 #undef WORD_SPACING_MASK
2468 
2469 #define WRITING_MODE_INDEX 11
2470 #define WRITING_MODE_SHIFT 18
2471 #define WRITING_MODE_MASK 0xc0000
2472 
set_writing_mode(css_computed_style * style,uint8_t type)2473 static inline css_error set_writing_mode(css_computed_style *style, uint8_t
2474 		type)
2475 {
2476 	uint32_t *bits;
2477 
2478 	bits = &style->i.bits[WRITING_MODE_INDEX];
2479 
2480 	/* 2bits: tt : type */
2481 	*bits = (*bits & ~WRITING_MODE_MASK) | (((uint32_t)type & 0x3) <<
2482 			WRITING_MODE_SHIFT);
2483 
2484 	return CSS_OK;
2485 }
2486 #undef WRITING_MODE_INDEX
2487 #undef WRITING_MODE_SHIFT
2488 #undef WRITING_MODE_MASK
2489 
2490 #define Z_INDEX_INDEX 11
2491 #define Z_INDEX_SHIFT 2
2492 #define Z_INDEX_MASK 0xc
2493 
set_z_index(css_computed_style * style,uint8_t type,int32_t integer)2494 static inline css_error set_z_index(css_computed_style *style, uint8_t type,
2495 		int32_t integer)
2496 {
2497 	uint32_t *bits;
2498 
2499 	bits = &style->i.bits[Z_INDEX_INDEX];
2500 
2501 	/* 2bits: tt : type */
2502 	*bits = (*bits & ~Z_INDEX_MASK) | (((uint32_t)type & 0x3) <<
2503 			Z_INDEX_SHIFT);
2504 
2505 	style->i.z_index = integer;
2506 
2507 	return CSS_OK;
2508 }
2509 #undef Z_INDEX_INDEX
2510 #undef Z_INDEX_SHIFT
2511 #undef Z_INDEX_MASK
2512