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_shrink(uint32_t opv,css_style * style,css_select_state * state)17 css_error css__cascade_flex_shrink(uint32_t opv, css_style *style,
18 		css_select_state *state)
19 {
20 	uint16_t value = CSS_FLEX_SHRINK_INHERIT;
21 	css_fixed flex_shrink = 0;
22 
23 	if (isInherit(opv) == false) {
24 		value = CSS_FLEX_SHRINK_SET;
25 
26 		flex_shrink = *((css_fixed *) style->bytecode);
27 		advance_bytecode(style, sizeof(flex_shrink));
28 	}
29 
30 	if (css__outranks_existing(getOpcode(opv), isImportant(opv), state,
31 			isInherit(opv))) {
32 		return set_flex_shrink(state->computed, value, flex_shrink);
33 	}
34 
35 	return CSS_OK;
36 }
37 
css__set_flex_shrink_from_hint(const css_hint * hint,css_computed_style * style)38 css_error css__set_flex_shrink_from_hint(const css_hint *hint,
39 		css_computed_style *style)
40 {
41 	return set_flex_shrink(style, hint->status, hint->data.fixed);
42 }
43 
css__initial_flex_shrink(css_select_state * state)44 css_error css__initial_flex_shrink(css_select_state *state)
45 {
46 	return set_flex_shrink(state->computed, CSS_FLEX_SHRINK_SET, INTTOFIX(1));
47 }
48 
css__compose_flex_shrink(const css_computed_style * parent,const css_computed_style * child,css_computed_style * result)49 css_error css__compose_flex_shrink(const css_computed_style *parent,
50 		const css_computed_style *child,
51 		css_computed_style *result)
52 {
53 	css_fixed flex_shrink = 0;
54 	uint8_t type = get_flex_shrink(child, &flex_shrink);
55 
56 	if (type == CSS_FLEX_SHRINK_INHERIT) {
57 		type = get_flex_shrink(parent, &flex_shrink);
58 	}
59 
60 	return set_flex_shrink(result, type, flex_shrink);
61 }
62 
63