summaryrefslogtreecommitdiff
path: root/src/select/select.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-07-04 14:02:56 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2009-07-04 14:02:56 +0000
commita3105d297fa8bb6bc8728d60a21b662d867688ae (patch)
tree57180314281f4c21201a8ae35bdff1d63a4416e3 /src/select/select.c
parent3b1a80cbb138c9c714efc0f32729506060c78c81 (diff)
downloadlibcss-a3105d297fa8bb6bc8728d60a21b662d867688ae.tar.gz
libcss-a3105d297fa8bb6bc8728d60a21b662d867688ae.tar.bz2
Ensure that any properties explicitly set to inherit on the root element are set to their initial values.
svn path=/trunk/libcss/; revision=8309
Diffstat (limited to 'src/select/select.c')
-rw-r--r--src/select/select.c124
1 files changed, 71 insertions, 53 deletions
diff --git a/src/select/select.c b/src/select/select.c
index b3fde4e..c839be1 100644
--- a/src/select/select.c
+++ b/src/select/select.c
@@ -33,8 +33,9 @@ struct css_select_ctx {
void *pw; /**< Client-specific private data */
};
-static css_error set_hint_or_initial(css_select_state *state, uint32_t i,
- void *parent);
+static css_error set_hint(css_select_state *state, uint32_t i);
+static css_error set_initial(css_select_state *state, uint32_t i, void *parent);
+
static css_error select_from_sheet(css_select_ctx *ctx,
const css_stylesheet *sheet, css_select_state *state);
static css_error intern_strings_for_sheet(css_select_ctx *ctx,
@@ -333,7 +334,16 @@ css_error css_select_style(css_select_ctx *ctx, void *node,
if (state.props[i].set == false ||
(state.props[i].origin != CSS_ORIGIN_AUTHOR &&
state.props[i].important == false)) {
- error = set_hint_or_initial(&state, i, parent);
+ error = set_hint(&state, i);
+ if (error != CSS_OK)
+ goto cleanup;
+ }
+
+ /* If the property is still unset or it's set to inherit and
+ * we're the root element, then set it to its initial value. */
+ if (state.props[i].set == false || (parent == NULL &&
+ state.props[i].inherit == true)) {
+ error = set_initial(&state, i, parent);
if (error != CSS_OK)
goto cleanup;
}
@@ -383,7 +393,7 @@ cleanup:
* Selection engine internals below here *
******************************************************************************/
-css_error set_hint_or_initial(css_select_state *state, uint32_t i, void *parent)
+css_error set_hint(css_select_state *state, uint32_t i)
{
css_hint hint;
css_error error;
@@ -394,56 +404,62 @@ css_error set_hint_or_initial(css_select_state *state, uint32_t i, void *parent)
if (error != CSS_OK && error != CSS_PROPERTY_NOT_SET)
return error;
- if (error == CSS_OK) {
- /* Hint defined -- set it in the result */
- error = prop_dispatch[i].set_from_hint(&hint, state->result);
- if (error != CSS_OK)
- return error;
+ if (error != CSS_OK)
+ return (error == CSS_PROPERTY_NOT_SET) ? CSS_OK : error;
+
+ /* Hint defined -- set it in the result */
+ error = prop_dispatch[i].set_from_hint(&hint, state->result);
+ if (error != CSS_OK)
+ return error;
+
+ /* Keep selection state in sync with reality */
+ state->props[i].set = 1;
+ state->props[i].specificity = 0;
+ state->props[i].origin = CSS_ORIGIN_AUTHOR;
+ state->props[i].important = 0;
+ state->props[i].inherit = (hint.status == 0);
+
+ return CSS_OK;
+}
- /* Keep selection state in sync with reality */
- state->props[i].set = 1;
- state->props[i].specificity = 0;
- state->props[i].origin = CSS_ORIGIN_AUTHOR;
- state->props[i].important = 0;
- } else if (state->props[i].set == false) {
- /* No hint and property unset */
-
- /* Do nothing if this property is inherited (the default state
- * of a clean computed style is for everything to be set to
- * inherit)
- *
- * If the node is tree root, everything should be defaulted.
+css_error set_initial(css_select_state *state, uint32_t i, void *parent)
+{
+ css_error error;
+
+ /* Do nothing if this property is inherited (the default state
+ * of a clean computed style is for everything to be set to inherit)
+ *
+ * If the node is tree root, everything should be defaulted.
+ */
+ if (prop_dispatch[i].inherited == false || parent == NULL) {
+ /* Remaining properties are neither inherited nor
+ * already set. Thus, we set them to their initial
+ * values here. Except, however, if the property in
+ * question resides in one of the extension blocks and
+ * the extension block has yet to be allocated. In that
+ * case, we do nothing and leave it to the property
+ * accessors to return the initial values for the
+ * property.
*/
- if (prop_dispatch[i].inherited == false || parent == NULL) {
- /* Remaining properties are neither inherited nor
- * already set. Thus, we set them to their initial
- * values here. Except, however, if the property in
- * question resides in one of the extension blocks and
- * the extension block has yet to be allocated. In that
- * case, we do nothing and leave it to the property
- * accessors to return the initial values for the
- * property.
- */
- if (prop_dispatch[i].group == GROUP_NORMAL) {
- error = prop_dispatch[i].initial(state);
- if (error != CSS_OK)
- return error;
- } else if (prop_dispatch[i].group == GROUP_UNCOMMON &&
- state->result->uncommon != NULL) {
- error = prop_dispatch[i].initial(state);
- if (error != CSS_OK)
- return error;
- } else if (prop_dispatch[i].group == GROUP_PAGE &&
- state->result->page != NULL) {
- error = prop_dispatch[i].initial(state);
- if (error != CSS_OK)
- return error;
- } else if (prop_dispatch[i].group == GROUP_AURAL &&
- state->result->aural != NULL) {
- error = prop_dispatch[i].initial(state);
- if (error != CSS_OK)
- return error;
- }
+ if (prop_dispatch[i].group == GROUP_NORMAL) {
+ error = prop_dispatch[i].initial(state);
+ if (error != CSS_OK)
+ return error;
+ } else if (prop_dispatch[i].group == GROUP_UNCOMMON &&
+ state->result->uncommon != NULL) {
+ error = prop_dispatch[i].initial(state);
+ if (error != CSS_OK)
+ return error;
+ } else if (prop_dispatch[i].group == GROUP_PAGE &&
+ state->result->page != NULL) {
+ error = prop_dispatch[i].initial(state);
+ if (error != CSS_OK)
+ return error;
+ } else if (prop_dispatch[i].group == GROUP_AURAL &&
+ state->result->aural != NULL) {
+ error = prop_dispatch[i].initial(state);
+ if (error != CSS_OK)
+ return error;
}
}
@@ -967,7 +983,8 @@ css_error cascade_style(const css_style *style, css_select_state *state)
return CSS_OK;
}
-bool outranks_existing(uint16_t op, bool important, css_select_state *state)
+bool outranks_existing(uint16_t op, bool important, css_select_state *state,
+ bool inherit)
{
prop_state *existing = &state->props[op];
bool outranks = false;
@@ -1062,6 +1079,7 @@ bool outranks_existing(uint16_t op, bool important, css_select_state *state)
existing->specificity = state->current_specificity;
existing->origin = state->current_origin;
existing->important = important;
+ existing->inherit = inherit;
}
return outranks;