summaryrefslogtreecommitdiff
path: root/src/select/properties/helpers.h
blob: 16c5d7a866cd27cc28029d421967405d4d553983 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
 * This file is part of LibCSS
 * Licensed under the MIT License,
 *                http://www.opensource.org/licenses/mit-license.php
 * Copyright 2009 John-Mark Bell <jmb@netsurf-browser.org>
 */

#ifndef css_select_properties_helpers_h_
#define css_select_properties_helpers_h_

#include "select/helpers.h"

uint32_t generic_destroy_color(void *bytecode);
uint32_t generic_destroy_uri(void *bytecode);
uint32_t generic_destroy_length(void *bytecode);
uint32_t generic_destroy_number(void *bytecode);

css_error css__cascade_bg_border_color(uint32_t opv, css_style *style,
		css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t, css_color));
css_error css__cascade_uri_none(uint32_t opv, css_style *style,
		css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t,
				lwc_string *));
css_error css__cascade_border_style(uint32_t opv, css_style *style,
		css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t));
css_error css__cascade_border_width(uint32_t opv, css_style *style,
		css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t, css_fixed,
				css_unit));
css_error css__cascade_length_auto(uint32_t opv, css_style *style,
		css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t, css_fixed,
				css_unit));
css_error css__cascade_length_normal(uint32_t opv, css_style *style,
		css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t, css_fixed,
				css_unit));
css_error css__cascade_length_none(uint32_t opv, css_style *style,
		css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t, css_fixed,
				css_unit));
css_error css__cascade_length(uint32_t opv, css_style *style,
		css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t, css_fixed,
				css_unit));
css_error css__cascade_number(uint32_t opv, css_style *style,
		css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t, css_fixed));
css_error css__cascade_page_break_after_before_inside(uint32_t opv,
		css_style *style, css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t));
css_error css__cascade_break_after_before_inside(uint32_t opv,
		css_style *style, css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t));
css_error css__cascade_counter_increment_reset(uint32_t opv, css_style *style,
		css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t,
				css_computed_counter *));

/** Copy NULL terminated array of lwc_string pointers. */
static inline css_error css__copy_lwc_string_array(
		bool ref,
		lwc_string *const*orig,
		lwc_string ***copy_out)
{
	size_t count = 0;
	lwc_string **copy = NULL;

	if (orig != NULL) {
		for (lwc_string *const*i = orig; (*i) != NULL; i++) {
			count++;
		}

		copy = malloc((count + 1) * sizeof(*copy));
		if (copy == NULL) {
			return CSS_NOMEM;
		}

		if (ref) {
			for (size_t i = 0; i < count; i++) {
				copy[i] = lwc_string_ref(orig[i]);
			}
			copy[count] = NULL;
		} else {
			memcpy(copy, orig, (count + 1) * sizeof(*copy));
		}
	}

	*copy_out = copy;
	return CSS_OK;
}

/** Copy NULL-name terminated array of css_computed_counter items. */
static inline css_error css__copy_computed_counter_array(
		bool ref,
		const css_computed_counter *orig,
		css_computed_counter **copy_out)
{
	size_t count = 0;
	css_computed_counter *copy = NULL;

	if (orig != NULL) {
		for (const css_computed_counter *i = orig;
				i->name != NULL; i++) {
			count++;
		}

		copy = malloc((count + 1) * sizeof(*copy));
		if (copy == NULL) {
			return CSS_NOMEM;
		}

		if (ref) {
			for (size_t i = 0; i < count; i++) {
				copy[i].name = lwc_string_ref(orig[i].name);
				copy[i].value = orig[i].value;
			}
			copy[count].name = NULL;
			copy[count].value = 0;
		} else {
			memcpy(copy, orig, (count + 1) * sizeof(*copy));
		}
	}

	*copy_out = copy;
	return CSS_OK;
}

/** Copy type:none terminated array of css_computed_content_item items. */
static inline css_error css__copy_computed_content_item_array(
		bool ref,
		const css_computed_content_item *orig,
		css_computed_content_item **copy_out)
{
	size_t count = 0;
	css_computed_content_item *copy = NULL;

	if (orig != NULL) {
		for (const css_computed_content_item *i = orig;
				i->type != CSS_COMPUTED_CONTENT_NONE; i++) {
			count++;
		}

		copy = malloc((count + 1) * sizeof(*copy));
		if (copy == NULL) {
			return CSS_NOMEM;
		}

		if (ref) {
			for (size_t i = 0; i < count; i++) {
				switch (orig[i].type) {
				case CSS_COMPUTED_CONTENT_STRING:
					copy[i].data.string = lwc_string_ref(
							orig[i].data.string);
					break;
				case CSS_COMPUTED_CONTENT_URI:
					copy[i].data.uri = lwc_string_ref(
							orig[i].data.uri);
					break;
				case CSS_COMPUTED_CONTENT_ATTR:
					copy[i].data.attr = lwc_string_ref(
							orig[i].data.attr);
					break;
				case CSS_COMPUTED_CONTENT_COUNTER:
					copy[i].data.counter.name = lwc_string_ref(
							orig[i].data.counter.name);
					copy[i].data.counter.style =
							orig[i].data.counter.style;
					break;
				case CSS_COMPUTED_CONTENT_COUNTERS:
					copy[i].data.counters.name = lwc_string_ref(
							orig[i].data.counters.name);
					copy[i].data.counters.sep = lwc_string_ref(
							orig[i].data.counters.sep);
					copy[i].data.counters.style =
							orig[i].data.counters.style;
					break;
				default:
					break;
				}
				copy[i].type = orig[i].type;
			}
			copy[count].type = CSS_COMPUTED_CONTENT_NONE;
		} else {
			memcpy(copy, orig, (count + 1) * sizeof(*copy));
		}
	}

	*copy_out = copy;
	return CSS_OK;
}

#endif