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 2009 John-Mark Bell <jmb@netsurf-browser.org>
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_direction(uint32_t opv,css_style * style,css_select_state * state)17 css_error css__cascade_direction(uint32_t opv, css_style *style,
18 		css_select_state *state)
19 {
20 	uint16_t value = CSS_DIRECTION_INHERIT;
21 
22 	UNUSED(style);
23 
24 	if (isInherit(opv) == false) {
25 		switch (getValue(opv)) {
26 		case DIRECTION_LTR:
27 			value = CSS_DIRECTION_LTR;
28 			break;
29 		case DIRECTION_RTL:
30 			value = CSS_DIRECTION_RTL;
31 			break;
32 		}
33 	}
34 
35 	if (css__outranks_existing(getOpcode(opv), isImportant(opv), state,
36 			isInherit(opv))) {
37 		return set_direction(state->computed, value);
38 	}
39 
40 	return CSS_OK;
41 }
42 
css__set_direction_from_hint(const css_hint * hint,css_computed_style * style)43 css_error css__set_direction_from_hint(const css_hint *hint,
44 		css_computed_style *style)
45 {
46 	return set_direction(style, hint->status);
47 }
48 
css__initial_direction(css_select_state * state)49 css_error css__initial_direction(css_select_state *state)
50 {
51 	return set_direction(state->computed, CSS_DIRECTION_LTR);
52 }
53 
css__compose_direction(const css_computed_style * parent,const css_computed_style * child,css_computed_style * result)54 css_error css__compose_direction(const css_computed_style *parent,
55 		const css_computed_style *child,
56 		css_computed_style *result)
57 {
58 	uint8_t type = get_direction(child);
59 
60 	if (type == CSS_DIRECTION_INHERIT) {
61 		type = get_direction(parent);
62 	}
63 
64 	return set_direction(result, type);
65 }
66 
67