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_direction(uint32_t opv,css_style * style,css_select_state * state)17 css_error css__cascade_flex_direction(uint32_t opv, css_style *style,
18 		css_select_state *state)
19 {
20 	uint16_t value = CSS_FLEX_DIRECTION_INHERIT;
21 
22 	UNUSED(style);
23 
24 	if (isInherit(opv) == false) {
25 		switch (getValue(opv)) {
26 		case FLEX_DIRECTION_ROW:
27 			value = CSS_FLEX_DIRECTION_ROW;
28 			break;
29 		case FLEX_DIRECTION_ROW_REVERSE:
30 			value = CSS_FLEX_DIRECTION_ROW_REVERSE;
31 			break;
32 		case FLEX_DIRECTION_COLUMN:
33 			value = CSS_FLEX_DIRECTION_COLUMN;
34 			break;
35 		case FLEX_DIRECTION_COLUMN_REVERSE:
36 			value = CSS_FLEX_DIRECTION_COLUMN_REVERSE;
37 			break;
38 		}
39 	}
40 
41 	if (css__outranks_existing(getOpcode(opv), isImportant(opv), state,
42 			isInherit(opv))) {
43 		return set_flex_direction(state->computed, value);
44 	}
45 
46 	return CSS_OK;
47 }
48 
css__set_flex_direction_from_hint(const css_hint * hint,css_computed_style * style)49 css_error css__set_flex_direction_from_hint(const css_hint *hint,
50 		css_computed_style *style)
51 {
52 	return set_flex_direction(style, hint->status);
53 }
54 
css__initial_flex_direction(css_select_state * state)55 css_error css__initial_flex_direction(css_select_state *state)
56 {
57 	return set_flex_direction(state->computed, CSS_FLEX_DIRECTION_ROW);
58 }
59 
css__compose_flex_direction(const css_computed_style * parent,const css_computed_style * child,css_computed_style * result)60 css_error css__compose_flex_direction(const css_computed_style *parent,
61 		const css_computed_style *child,
62 		css_computed_style *result)
63 {
64 	uint8_t type = get_flex_direction(child);
65 
66 	if (type == CSS_FLEX_DIRECTION_INHERIT) {
67 		type = get_flex_direction(parent);
68 	}
69 
70 	return set_flex_direction(result, type);
71 }
72 
73