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_text_align(uint32_t opv,css_style * style,css_select_state * state)17 css_error css__cascade_text_align(uint32_t opv, css_style *style,
18 		css_select_state *state)
19 {
20 	uint16_t value = CSS_TEXT_ALIGN_INHERIT;
21 
22 	UNUSED(style);
23 
24 	if (isInherit(opv) == false) {
25 		switch (getValue(opv)) {
26 		case TEXT_ALIGN_LEFT:
27 			value = CSS_TEXT_ALIGN_LEFT;
28 			break;
29 		case TEXT_ALIGN_RIGHT:
30 			value = CSS_TEXT_ALIGN_RIGHT;
31 			break;
32 		case TEXT_ALIGN_CENTER:
33 			value = CSS_TEXT_ALIGN_CENTER;
34 			break;
35 		case TEXT_ALIGN_JUSTIFY:
36 			value = CSS_TEXT_ALIGN_JUSTIFY;
37 			break;
38 		case TEXT_ALIGN_LIBCSS_LEFT:
39 			value = CSS_TEXT_ALIGN_LIBCSS_LEFT;
40 			break;
41 		case TEXT_ALIGN_LIBCSS_CENTER:
42 			value = CSS_TEXT_ALIGN_LIBCSS_CENTER;
43 			break;
44 		case TEXT_ALIGN_LIBCSS_RIGHT:
45 			value = CSS_TEXT_ALIGN_LIBCSS_RIGHT;
46 			break;
47 		}
48 	}
49 
50 	if (css__outranks_existing(getOpcode(opv), isImportant(opv), state,
51 			isInherit(opv))) {
52 		return set_text_align(state->computed, value);
53 	}
54 
55 	return CSS_OK;
56 }
57 
css__set_text_align_from_hint(const css_hint * hint,css_computed_style * style)58 css_error css__set_text_align_from_hint(const css_hint *hint,
59 		css_computed_style *style)
60 {
61 	return set_text_align(style, hint->status);
62 }
63 
css__initial_text_align(css_select_state * state)64 css_error css__initial_text_align(css_select_state *state)
65 {
66 	return set_text_align(state->computed, CSS_TEXT_ALIGN_DEFAULT);
67 }
68 
css__compose_text_align(const css_computed_style * parent,const css_computed_style * child,css_computed_style * result)69 css_error css__compose_text_align(const css_computed_style *parent,
70 		const css_computed_style *child,
71 		css_computed_style *result)
72 {
73 	uint8_t type = get_text_align(child);
74 
75 	if (type == CSS_TEXT_ALIGN_INHERIT) {
76 		type = get_text_align(parent);
77 	} else if (type == CSS_TEXT_ALIGN_INHERIT_IF_NON_MAGIC) {
78 		/* This is purely for the benefit of HTML tables */
79 		type = get_text_align(parent);
80 
81 		/* If the parent's text-align is a magical one,
82 		 * then reset to the default value. Otherwise,
83 		 * inherit as normal. */
84 		if (type == CSS_TEXT_ALIGN_LIBCSS_LEFT ||
85 				type == CSS_TEXT_ALIGN_LIBCSS_CENTER ||
86 				type == CSS_TEXT_ALIGN_LIBCSS_RIGHT)
87 			type = CSS_TEXT_ALIGN_DEFAULT;
88 	}
89 
90 	return set_text_align(result, type);
91 }
92 
93