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 Lucas Neves <lcneves@gmail.com>
6  */
7 
8 #include "bytecode/bytecode.h"
9 #include "bytecode/opcodes.h"
10 #include "select/propset.h"
11 #include "select/propget.h"
12 #include "utils/utils.h"
13 
14 #include "select/properties/properties.h"
15 #include "select/properties/helpers.h"
16 
css__cascade_flex_basis(uint32_t opv,css_style * style,css_select_state * state)17 css_error css__cascade_flex_basis(uint32_t opv, css_style *style,
18 		css_select_state *state)
19 {
20 	uint16_t value = CSS_FLEX_BASIS_INHERIT;
21 	css_fixed length = 0;
22 	uint32_t unit = UNIT_PX;
23 
24 	if (isInherit(opv) == false) {
25 		switch (getValue(opv)) {
26 		case FLEX_BASIS_AUTO:
27 			value = CSS_FLEX_BASIS_AUTO;
28 			break;
29 		case FLEX_BASIS_CONTENT:
30 			value = CSS_FLEX_BASIS_CONTENT;
31 			break;
32 		case FLEX_BASIS_SET:
33 			value = CSS_FLEX_BASIS_SET;
34 			length = *((css_fixed *) style->bytecode);
35 			advance_bytecode(style, sizeof(length));
36 			unit = *((uint32_t *) style->bytecode);
37 			advance_bytecode(style, sizeof(unit));
38 			break;
39 		}
40 	}
41 
42 	unit = css__to_css_unit(unit);
43 
44 	if (css__outranks_existing(getOpcode(opv), isImportant(opv), state,
45 			isInherit(opv))) {
46 		return set_flex_basis(state->computed, value, length, unit);
47 	}
48 
49 	return CSS_OK;
50 }
51 
css__set_flex_basis_from_hint(const css_hint * hint,css_computed_style * style)52 css_error css__set_flex_basis_from_hint(const css_hint *hint,
53 		css_computed_style *style)
54 {
55 	return set_flex_basis(style, hint->status,
56 			hint->data.length.value, hint->data.length.unit);
57 }
58 
css__initial_flex_basis(css_select_state * state)59 css_error css__initial_flex_basis(css_select_state *state)
60 {
61 	return set_flex_basis(state->computed, CSS_FLEX_BASIS_AUTO, 0,
62 			CSS_UNIT_PX);
63 }
64 
css__compose_flex_basis(const css_computed_style * parent,const css_computed_style * child,css_computed_style * result)65 css_error css__compose_flex_basis(const css_computed_style *parent,
66 		const css_computed_style *child,
67 		css_computed_style *result)
68 {
69 	css_fixed length = 0;
70 	css_unit unit = CSS_UNIT_PX;
71 	uint8_t type = get_flex_basis(child, &length, &unit);
72 
73 	if (type == CSS_FLEX_BASIS_INHERIT) {
74 		type = get_flex_basis(parent, &length, &unit);
75 	}
76 
77 	return set_flex_basis(result, type, length, unit);
78 }
79 
80