libcss
Loading...
Searching...
No Matches
helpers.h
Go to the documentation of this file.
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#ifndef css_select_properties_helpers_h_
9#define css_select_properties_helpers_h_
10
11#include "select/helpers.h"
13
14uint32_t generic_destroy_color(void *bytecode);
15uint32_t generic_destroy_uri(void *bytecode);
16uint32_t generic_destroy_length(void *bytecode);
17uint32_t generic_destroy_number(void *bytecode);
18
20 css_select_state *state,
21 css_error (*fun)(css_computed_style *, uint8_t, css_color));
22css_error css__cascade_uri_none(uint32_t opv, css_style *style,
23 css_select_state *state,
24 css_error (*fun)(css_computed_style *, uint8_t,
25 lwc_string *));
27 css_select_state *state,
28 css_error (*fun)(css_computed_style *, uint8_t));
30 css_select_state *state,
31 css_error (*fun)(css_computed_style *, uint8_t, css_fixed,
32 css_unit));
34 css_select_state *state,
35 css_error (*fun)(css_computed_style *, uint8_t, css_fixed,
36 css_unit));
38 css_select_state *state,
40 css_unit));
42 css_select_state *state,
43 css_error (*fun)(css_computed_style *, uint8_t, css_fixed,
44 css_unit));
46 css_select_state *state,
47 css_error (*fun)(css_computed_style *, uint8_t, css_fixed,
48 css_unit));
49css_error css__cascade_length(uint32_t opv, css_style *style,
50 css_select_state *state,
51 css_error (*fun)(css_computed_style *, uint8_t, css_fixed,
52 css_unit));
53css_error css__cascade_number(uint32_t opv, css_style *style,
54 css_select_state *state,
55 css_error (*fun)(css_computed_style *, uint8_t, css_fixed));
57 css_style *style, css_select_state *state,
58 css_error (*fun)(css_computed_style *, uint8_t));
60 css_style *style, css_select_state *state,
61 css_error (*fun)(css_computed_style *, uint8_t));
63 css_select_state *state,
64 css_error (*fun)(css_computed_style *, uint8_t,
66
68static inline css_error css__copy_lwc_string_array(
69 bool ref,
70 lwc_string *const*orig,
71 lwc_string ***copy_out)
72{
73 size_t count = 0;
74 lwc_string **copy = NULL;
75
76 if (orig != NULL) {
77 for (lwc_string *const*i = orig; (*i) != NULL; i++) {
78 count++;
79 }
80
81 copy = malloc((count + 1) * sizeof(*copy));
82 if (copy == NULL) {
83 return CSS_NOMEM;
84 }
85
86 if (ref) {
87 for (size_t i = 0; i < count; i++) {
88 copy[i] = lwc_string_ref(orig[i]);
89 }
90 copy[count] = NULL;
91 } else {
92 memcpy(copy, orig, (count + 1) * sizeof(*copy));
93 }
94 }
95
96 *copy_out = copy;
97 return CSS_OK;
98}
99
101static inline css_error css__copy_computed_counter_array(
102 bool ref,
103 const css_computed_counter *orig,
104 css_computed_counter **copy_out)
105{
106 size_t count = 0;
107 css_computed_counter *copy = NULL;
108
109 if (orig != NULL) {
110 for (const css_computed_counter *i = orig;
111 i->name != NULL; i++) {
112 count++;
113 }
114
115 copy = malloc((count + 1) * sizeof(*copy));
116 if (copy == NULL) {
117 return CSS_NOMEM;
118 }
119
120 if (ref) {
121 for (size_t i = 0; i < count; i++) {
122 copy[i].name = lwc_string_ref(orig[i].name);
123 copy[i].value = orig[i].value;
124 }
125 copy[count].name = NULL;
126 copy[count].value = 0;
127 } else {
128 memcpy(copy, orig, (count + 1) * sizeof(*copy));
129 }
130 }
131
132 *copy_out = copy;
133 return CSS_OK;
134}
135
137static inline css_error css__copy_computed_content_item_array(
138 bool ref,
139 const css_computed_content_item *orig,
140 css_computed_content_item **copy_out)
141{
142 size_t count = 0;
143 css_computed_content_item *copy = NULL;
144
145 if (orig != NULL) {
146 for (const css_computed_content_item *i = orig;
147 i->type != CSS_COMPUTED_CONTENT_NONE; i++) {
148 count++;
149 }
150
151 copy = malloc((count + 1) * sizeof(*copy));
152 if (copy == NULL) {
153 return CSS_NOMEM;
154 }
155
156 if (ref) {
157 for (size_t i = 0; i < count; i++) {
158 switch (orig[i].type) {
160 copy[i].data.string = lwc_string_ref(
161 orig[i].data.string);
162 break;
164 copy[i].data.uri = lwc_string_ref(
165 orig[i].data.uri);
166 break;
168 copy[i].data.attr = lwc_string_ref(
169 orig[i].data.attr);
170 break;
172 copy[i].data.counter.name = lwc_string_ref(
173 orig[i].data.counter.name);
174 copy[i].data.counter.style =
175 orig[i].data.counter.style;
176 break;
178 copy[i].data.counters.name = lwc_string_ref(
179 orig[i].data.counters.name);
180 copy[i].data.counters.sep = lwc_string_ref(
181 orig[i].data.counters.sep);
182 copy[i].data.counters.style =
183 orig[i].data.counters.style;
184 break;
185 default:
186 break;
187 }
188 copy[i].type = orig[i].type;
189 }
190 copy[count].type = CSS_COMPUTED_CONTENT_NONE;
191 } else {
192 memcpy(copy, orig, (count + 1) * sizeof(*copy));
193 }
194 }
195
196 *copy_out = copy;
197 return CSS_OK;
198}
199
200#endif
css_error
Definition errors.h:18
@ CSS_NOMEM
Definition errors.h:21
@ CSS_OK
Definition errors.h:19
int32_t css_fixed
Definition fpmath.h:23
@ CSS_COMPUTED_CONTENT_NONE
Definition computed.h:50
@ CSS_COMPUTED_CONTENT_STRING
Definition computed.h:51
@ CSS_COMPUTED_CONTENT_COUNTERS
Definition computed.h:54
@ CSS_COMPUTED_CONTENT_COUNTER
Definition computed.h:53
@ CSS_COMPUTED_CONTENT_URI
Definition computed.h:52
@ CSS_COMPUTED_CONTENT_ATTR
Definition computed.h:55
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))
Definition helpers.c:394
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))
Definition helpers.c:355
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))
Definition helpers.c:273
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))
Definition helpers.c:141
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))
Definition helpers.c:466
uint32_t generic_destroy_uri(void *bytecode)
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))
Definition helpers.c:188
uint32_t generic_destroy_color(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))
Definition helpers.c:22
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 *))
Definition helpers.c:60
uint32_t generic_destroy_length(void *bytecode)
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 *))
Definition helpers.c:515
css_error css__cascade_length_auto_calc(uint32_t opv, css_style *style, css_select_state *state, css_error(*fun)(css_computed_style *, uint8_t, css_fixed_or_calc, css_unit))
Definition helpers.c:229
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))
Definition helpers.c:314
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))
Definition helpers.c:429
css_error css__cascade_border_style(uint32_t opv, css_style *style, css_select_state *state, css_error(*fun)(css_computed_style *, uint8_t))
Definition helpers.c:90
uint32_t generic_destroy_number(void *bytecode)
Definition computed.h:62
lwc_string * sep
Definition computed.h:74
struct css_computed_content_item::@0::@1 counter
union css_computed_content_item::@0 data
lwc_string * string
Definition computed.h:65
uint8_t type
Definition computed.h:63
lwc_string * attr
Definition computed.h:67
lwc_string * uri
Definition computed.h:66
lwc_string * name
Definition computed.h:69
struct css_computed_content_item::@0::@2 counters
uint8_t style
Definition computed.h:70
Definition computed.h:27
lwc_string * name
Definition computed.h:28
css_fixed value
Definition computed.h:29
Definition autogenerated_computed.h:282
Definition select.h:69
Definition stylesheet.h:29
css_unit
Definition types.h:82
uint32_t css_color
Definition types.h:79
Definition autogenerated_computed.h:13