/
CSSSelectHandlerBase.m
286 lines (250 loc) · 7.92 KB
/
CSSSelectHandlerBase.m
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#import "CSSSelectHandlerBase.h"
#import "CSS.h"
#import <assert.h>
#import <libcss/fpmath.h>
#import <string.h>
/* This macro is used to silence compiler warnings about unused function
* arguments. */
#define UNUSED(x) ((x) = (x))
static css_error node_name(void *pw, void *n, lwc_string **name) {
UNUSED(pw);
lwc_intern_string("", 0, name); // |name| must be a valid lwc_string
return CSS_OK;
}
static css_error node_classes(void *pw, void *n, lwc_string ***classes,
uint32_t *n_classes) {
UNUSED(pw); UNUSED(n);
*classes = NULL;
*n_classes = 0;
return CSS_OK;
}
static css_error node_id(void *pw, void *n, lwc_string **id) {
UNUSED(pw); UNUSED(n);
*id = NULL;
return CSS_OK;
}
static css_error named_ancestor_node(void *pw, void *n, lwc_string *name,
void **ancestor) {
UNUSED(pw); UNUSED(n); UNUSED(name);
*ancestor = NULL;
return CSS_OK;
}
static css_error named_parent_node(void *pw, void *n, lwc_string *name,
void **parent) {
UNUSED(pw); UNUSED(n); UNUSED(name);
*parent = NULL;
return CSS_OK;
}
static css_error named_sibling_node(void *pw, void *n, lwc_string *name,
void **sibling) {
UNUSED(pw); UNUSED(n); UNUSED(name);
*sibling = NULL;
return CSS_OK;
}
static css_error parent_node(void *pw, void *n, void **parent) {
UNUSED(pw); UNUSED(n);
*parent = NULL;
return CSS_OK;
}
static css_error sibling_node(void *pw, void *n, void **sibling) {
UNUSED(pw); UNUSED(n);
*sibling = NULL;
return CSS_OK;
}
static css_error node_has_name(void *pw, void *n, lwc_string *name,
bool *match) {
UNUSED(pw);
*match = false;
return CSS_OK;
}
static css_error node_has_class(void *pw, void *n, lwc_string *name,
bool *match) {
UNUSED(pw); UNUSED(n); UNUSED(name);
*match = false;
return CSS_OK;
}
static css_error node_has_id(void *pw, void *n, lwc_string *name, bool *match) {
UNUSED(pw); UNUSED(n); UNUSED(name);
*match = false;
return CSS_OK;
}
static css_error node_has_attribute(void *pw, void *n, lwc_string *name,
bool *match) {
UNUSED(pw); UNUSED(n); UNUSED(name);
*match = false;
return CSS_OK;
}
static css_error node_has_attribute_equal(void *pw, void *n, lwc_string *name,
lwc_string *value, bool *match) {
UNUSED(pw); UNUSED(n); UNUSED(name); UNUSED(value);
*match = false;
return CSS_OK;
}
static css_error node_has_attribute_dashmatch(void *pw, void *n,
lwc_string *name,
lwc_string *value,
bool *match) {
UNUSED(pw); UNUSED(n); UNUSED(name); UNUSED(value);
*match = false;
return CSS_OK;
}
static css_error node_has_attribute_includes(void *pw, void *n,
lwc_string *name,
lwc_string *value,
bool *match) {
UNUSED(pw); UNUSED(n); UNUSED(name); UNUSED(value);
*match = false;
return CSS_OK;
}
static css_error node_is_first_child(void *pw, void *n, bool *match) {
UNUSED(pw); UNUSED(n);
*match = false;
return CSS_OK;
}
static css_error node_is_link(void *pw, void *n, bool *match) {
UNUSED(pw); UNUSED(n);
*match = false;
return CSS_OK;
}
static css_error node_is_visited(void *pw, void *n, bool *match) {
UNUSED(pw); UNUSED(n);
*match = false;
return CSS_OK;
}
static css_error node_is_hover(void *pw, void *n, bool *match) {
UNUSED(pw); UNUSED(n);
*match = false;
return CSS_OK;
}
static css_error node_is_active(void *pw, void *n, bool *match) {
UNUSED(pw); UNUSED(n);
*match = false;
return CSS_OK;
}
static css_error node_is_focus(void *pw, void *n, bool *match) {
UNUSED(pw); UNUSED(n);
*match = false;
return CSS_OK;
}
static css_error node_is_lang(void *pw, void *n, lwc_string *lang,
bool *match) {
UNUSED(pw); UNUSED(n); UNUSED(lang);
*match = false;
return CSS_OK;
}
// "base" value for property (inherit for all properties)
static css_error node_presentational_hint(void *pw, void *node,
uint32_t property, css_hint *hint) {
UNUSED(pw); UNUSED(node); UNUSED(property); UNUSED(hint);
// a bit nasty: all *_INHERIT flags are 0, so simply set this to 0
hint->status = 0;
/*switch (property) {
case CSS_PROP_COLOR:
case CSS_PROP_BACKGROUND_COLOR:
hint->status = CSS_COLOR_INHERIT; break;
case CSS_PROP_FONT_FAMILY:
hint->status = CSS_FONT_FAMILY_INHERIT; break;
default:
return CSS_PROPERTY_NOT_SET;
}*/
return CSS_OK;
}
static css_error ua_default_for_property(void *pw, uint32_t property,
css_hint *hint) {
UNUSED(pw);
if (property == CSS_PROP_COLOR) {
hint->data.color = 0xff000000;
hint->status = CSS_COLOR_COLOR;
} else if (property == CSS_PROP_BACKGROUND_COLOR) {
hint->data.color = 0xffffffff;
hint->status = CSS_COLOR_COLOR;
} else if (property == CSS_PROP_FONT_FAMILY) {
hint->data.strings = NULL;
hint->status = CSS_FONT_FAMILY_SANS_SERIF;
} else if (property == CSS_PROP_QUOTES) {
hint->data.strings = NULL;
hint->status = CSS_QUOTES_NONE;
} else if (property == CSS_PROP_VOICE_FAMILY) {
hint->data.strings = NULL;
hint->status = 0;
} else {
return CSS_INVALID;
}
return CSS_OK;
}
static css_error compute_font_size(void *pw, const css_hint *parent,
css_hint *size) {
static css_hint_length sizes[] = {
{ FLTTOFIX(6.75), CSS_UNIT_PT },
{ FLTTOFIX(7.50), CSS_UNIT_PT },
{ FLTTOFIX(9.75), CSS_UNIT_PT },
{ FLTTOFIX(12.0), CSS_UNIT_PT },
{ FLTTOFIX(13.5), CSS_UNIT_PT },
{ FLTTOFIX(18.0), CSS_UNIT_PT },
{ FLTTOFIX(24.0), CSS_UNIT_PT }
};
const css_hint_length *parent_size;
UNUSED(pw);
// Grab parent size, defaulting to medium if none
if (parent == NULL) {
parent_size = &sizes[CSS_FONT_SIZE_MEDIUM - 1];
} else {
assert(parent->status == CSS_FONT_SIZE_DIMENSION);
assert(parent->data.length.unit != CSS_UNIT_EM);
assert(parent->data.length.unit != CSS_UNIT_EX);
parent_size = &parent->data.length;
}
assert(size->status != CSS_FONT_SIZE_INHERIT);
if (size->status < CSS_FONT_SIZE_LARGER) {
// Keyword -- simple
size->data.length = sizes[size->status - 1];
} else if (size->status == CSS_FONT_SIZE_LARGER) {
// TODO: Step within table, if appropriate
size->data.length.value = FMUL(parent_size->value, FLTTOFIX(1.2));
size->data.length.unit = parent_size->unit;
} else if (size->status == CSS_FONT_SIZE_SMALLER) {
// TODO: Step within table, if appropriate
size->data.length.value = FMUL(parent_size->value, FLTTOFIX(1.2));
size->data.length.unit = parent_size->unit;
} else if (size->data.length.unit == CSS_UNIT_EM ||
size->data.length.unit == CSS_UNIT_EX) {
size->data.length.value = FMUL(size->data.length.value, parent_size->value);
if (size->data.length.unit == CSS_UNIT_EX) {
size->data.length.value = FMUL(size->data.length.value, FLTTOFIX(0.6));
}
size->data.length.unit = parent_size->unit;
} else if (size->data.length.unit == CSS_UNIT_PCT) {
size->data.length.value = FDIV(FMUL(size->data.length.value,
parent_size->value), FLTTOFIX(100));
size->data.length.unit = parent_size->unit;
}
size->status = CSS_FONT_SIZE_DIMENSION;
return CSS_OK;
}
const css_select_handler CSSSelectHandlerBase = {
node_name,
node_classes,
node_id,
named_ancestor_node,
named_parent_node,
named_sibling_node,
parent_node,
sibling_node,
node_has_name,
node_has_class,
node_has_id,
node_has_attribute,
node_has_attribute_equal,
node_has_attribute_dashmatch,
node_has_attribute_includes,
node_is_first_child,
node_is_link,
node_is_visited,
node_is_hover,
node_is_active,
node_is_focus,
node_is_lang,
node_presentational_hint,
ua_default_for_property,
compute_font_size
};