Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3584 | sourcerer | 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 |
||
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 | |||
17 | css_error css__cascade_cursor(uint32_t opv, css_style *style, |
||
18 | css_select_state *state) |
||
19 | { |
||
20 | uint16_t value = CSS_CURSOR_INHERIT; |
||
21 | lwc_string **uris = NULL; |
||
22 | uint32_t n_uris = 0; |
||
23 | |||
24 | if (isInherit(opv) == false) { |
||
25 | uint32_t v = getValue(opv); |
||
26 | |||
27 | while (v == CURSOR_URI) { |
||
28 | lwc_string *uri; |
||
29 | lwc_string **temp; |
||
30 | |||
31 | css__stylesheet_string_get(style->sheet, *((css_code_t *) style->bytecode), &uri); |
||
32 | advance_bytecode(style, sizeof(css_code_t)); |
||
33 | |||
34 | temp = state->computed->alloc(uris, |
||
35 | (n_uris + 1) * sizeof(lwc_string *), |
||
36 | state->computed->pw); |
||
37 | if (temp == NULL) { |
||
38 | if (uris != NULL) { |
||
39 | state->computed->alloc(uris, 0, |
||
40 | state->computed->pw); |
||
41 | } |
||
42 | return CSS_NOMEM; |
||
43 | } |
||
44 | |||
45 | uris = temp; |
||
46 | |||
47 | uris[n_uris] = uri; |
||
48 | |||
49 | n_uris++; |
||
50 | |||
51 | v = *((uint32_t *) style->bytecode); |
||
52 | advance_bytecode(style, sizeof(v)); |
||
53 | } |
||
54 | |||
55 | switch (v) { |
||
56 | case CURSOR_AUTO: |
||
57 | value = CSS_CURSOR_AUTO; |
||
58 | break; |
||
59 | case CURSOR_CROSSHAIR: |
||
60 | value = CSS_CURSOR_CROSSHAIR; |
||
61 | break; |
||
62 | case CURSOR_DEFAULT: |
||
63 | value = CSS_CURSOR_DEFAULT; |
||
64 | break; |
||
65 | case CURSOR_POINTER: |
||
66 | value = CSS_CURSOR_POINTER; |
||
67 | break; |
||
68 | case CURSOR_MOVE: |
||
69 | value = CSS_CURSOR_MOVE; |
||
70 | break; |
||
71 | case CURSOR_E_RESIZE: |
||
72 | value = CSS_CURSOR_E_RESIZE; |
||
73 | break; |
||
74 | case CURSOR_NE_RESIZE: |
||
75 | value = CSS_CURSOR_NE_RESIZE; |
||
76 | break; |
||
77 | case CURSOR_NW_RESIZE: |
||
78 | value = CSS_CURSOR_NW_RESIZE; |
||
79 | break; |
||
80 | case CURSOR_N_RESIZE: |
||
81 | value = CSS_CURSOR_N_RESIZE; |
||
82 | break; |
||
83 | case CURSOR_SE_RESIZE: |
||
84 | value = CSS_CURSOR_SE_RESIZE; |
||
85 | break; |
||
86 | case CURSOR_SW_RESIZE: |
||
87 | value = CSS_CURSOR_SW_RESIZE; |
||
88 | break; |
||
89 | case CURSOR_S_RESIZE: |
||
90 | value = CSS_CURSOR_S_RESIZE; |
||
91 | break; |
||
92 | case CURSOR_W_RESIZE: |
||
93 | value = CSS_CURSOR_W_RESIZE; |
||
94 | break; |
||
95 | case CURSOR_TEXT: |
||
96 | value = CSS_CURSOR_TEXT; |
||
97 | break; |
||
98 | case CURSOR_WAIT: |
||
99 | value = CSS_CURSOR_WAIT; |
||
100 | break; |
||
101 | case CURSOR_HELP: |
||
102 | value = CSS_CURSOR_HELP; |
||
103 | break; |
||
104 | case CURSOR_PROGRESS: |
||
105 | value = CSS_CURSOR_PROGRESS; |
||
106 | break; |
||
107 | } |
||
108 | } |
||
109 | |||
110 | /* Terminate array with blank entry, if needed */ |
||
111 | if (n_uris > 0) { |
||
112 | lwc_string **temp; |
||
113 | |||
114 | temp = state->computed->alloc(uris, |
||
115 | (n_uris + 1) * sizeof(lwc_string *), |
||
116 | state->computed->pw); |
||
117 | if (temp == NULL) { |
||
118 | state->computed->alloc(uris, 0, state->computed->pw); |
||
119 | return CSS_NOMEM; |
||
120 | } |
||
121 | |||
122 | uris = temp; |
||
123 | |||
124 | uris[n_uris] = NULL; |
||
125 | } |
||
126 | |||
127 | if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, |
||
128 | isInherit(opv))) { |
||
129 | css_error error; |
||
130 | |||
131 | error = set_cursor(state->computed, value, uris); |
||
132 | if (error != CSS_OK && n_uris > 0) |
||
133 | state->computed->alloc(uris, 0, state->computed->pw); |
||
134 | |||
135 | return error; |
||
136 | } else { |
||
137 | if (n_uris > 0) |
||
138 | state->computed->alloc(uris, 0, state->computed->pw); |
||
139 | } |
||
140 | |||
141 | return CSS_OK; |
||
142 | } |
||
143 | |||
144 | css_error css__set_cursor_from_hint(const css_hint *hint, |
||
145 | css_computed_style *style) |
||
146 | { |
||
147 | lwc_string **item; |
||
148 | css_error error; |
||
149 | |||
150 | error = set_cursor(style, hint->status, hint->data.strings); |
||
151 | |||
152 | for (item = hint->data.strings; |
||
153 | item != NULL && (*item) != NULL; item++) { |
||
154 | lwc_string_unref(*item); |
||
155 | } |
||
156 | |||
157 | if (error != CSS_OK && hint->data.strings != NULL) |
||
158 | style->alloc(hint->data.strings, 0, style->pw); |
||
159 | |||
160 | return error; |
||
161 | } |
||
162 | |||
163 | css_error css__initial_cursor(css_select_state *state) |
||
164 | { |
||
165 | return set_cursor(state->computed, CSS_CURSOR_AUTO, NULL); |
||
166 | } |
||
167 | |||
168 | css_error css__compose_cursor(const css_computed_style *parent, |
||
169 | const css_computed_style *child, |
||
170 | css_computed_style *result) |
||
171 | { |
||
172 | css_error error; |
||
173 | lwc_string **urls = NULL; |
||
174 | uint8_t type = get_cursor(child, &urls); |
||
175 | |||
176 | if ((child->uncommon == NULL && parent->uncommon != NULL) || |
||
177 | type == CSS_CURSOR_INHERIT || |
||
178 | (child->uncommon != NULL && result != child)) { |
||
179 | size_t n_urls = 0; |
||
180 | lwc_string **copy = NULL; |
||
181 | |||
182 | if ((child->uncommon == NULL && parent->uncommon != NULL) || |
||
183 | type == CSS_CURSOR_INHERIT) { |
||
184 | type = get_cursor(parent, &urls); |
||
185 | } |
||
186 | |||
187 | if (urls != NULL) { |
||
188 | lwc_string **i; |
||
189 | |||
190 | for (i = urls; (*i) != NULL; i++) |
||
191 | n_urls++; |
||
192 | |||
193 | copy = result->alloc(NULL, (n_urls + 1) * |
||
194 | sizeof(lwc_string *), |
||
195 | result->pw); |
||
196 | if (copy == NULL) |
||
197 | return CSS_NOMEM; |
||
198 | |||
199 | memcpy(copy, urls, (n_urls + 1) * |
||
200 | sizeof(lwc_string *)); |
||
201 | } |
||
202 | |||
203 | error = set_cursor(result, type, copy); |
||
204 | if (error != CSS_OK && copy != NULL) |
||
205 | result->alloc(copy, 0, result->pw); |
||
206 | |||
207 | return error; |
||
208 | } |
||
209 | |||
210 | return CSS_OK; |
||
211 | } |
||
212 |