summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-07-04 17:09:07 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2009-07-04 17:09:07 +0000
commit081c8b365001d9ec9df0f06ba5025dd621c8e4ec (patch)
treebeaa0c8a0243a2cb50e869282565033bcdcba6a6
parenta3105d297fa8bb6bc8728d60a21b662d867688ae (diff)
downloadlibcss-081c8b365001d9ec9df0f06ba5025dd621c8e4ec.tar.gz
libcss-081c8b365001d9ec9df0f06ba5025dd621c8e4ec.tar.bz2
Add callback to make client compute the font size.
Some progress towards computing absolute values. svn path=/trunk/libcss/; revision=8311
-rw-r--r--include/libcss/computed.h6
-rw-r--r--include/libcss/select.h5
-rw-r--r--src/select/computed.c41
-rw-r--r--src/select/select.c18
-rw-r--r--test/select-auto.c67
5 files changed, 123 insertions, 14 deletions
diff --git a/include/libcss/computed.h b/include/libcss/computed.h
index 672d504..0d0350e 100644
--- a/include/libcss/computed.h
+++ b/include/libcss/computed.h
@@ -15,6 +15,8 @@
#include <libcss/properties.h>
#include <libcss/types.h>
+struct css_hint;
+
enum css_computed_content_type {
CSS_COMPUTED_CONTENT_NONE = 0,
CSS_COMPUTED_CONTENT_STRING = 1,
@@ -333,6 +335,10 @@ css_error css_computed_style_destroy(css_computed_style *style);
css_error css_computed_style_compose(const css_computed_style *parent,
const css_computed_style *child,
+ css_error (*compute_font_size)(void *pw,
+ const struct css_hint *parent,
+ struct css_hint *size),
+ void *pw,
css_computed_style *result);
/******************************************************************************
diff --git a/include/libcss/select.h b/include/libcss/select.h
index 391f393..e961275 100644
--- a/include/libcss/select.h
+++ b/include/libcss/select.h
@@ -67,8 +67,9 @@ typedef struct css_select_handler {
css_error (*ua_default_for_property)(void *pw, uint32_t property,
css_hint *hint);
-// css_error (*ua_font_keyword_to_size)(void *pw, uint32_t keyword,
-// css_hint *hint);
+
+ css_error (*compute_font_size)(void *pw, const css_hint *parent,
+ css_hint *size);
} css_select_handler;
css_error css_select_ctx_create(css_allocator_fn alloc, void *pw,
diff --git a/src/select/computed.c b/src/select/computed.c
index d8007c1..4c58102 100644
--- a/src/select/computed.c
+++ b/src/select/computed.c
@@ -7,8 +7,7 @@
#include <string.h>
-#include <libcss/computed.h>
-
+#include "select/computed.h"
#include "select/dispatch.h"
#include "utils/utils.h"
@@ -94,9 +93,11 @@ css_error css_computed_style_destroy(css_computed_style *style)
/**
* Compose two computed styles
*
- * \param parent Parent style
- * \param child Child style
- * \param result Pointer to style to compose into
+ * \param parent Parent style
+ * \param child Child style
+ * \param compute_font_size Function to compute an absolute font size
+ * \param pw Client data for compute_font_size
+ * \param result Pointer to style to compose into
* \return CSS_OK on success, appropriate error otherwise.
*
* Precondition: Parent is a fully composed style (thus has no properties
@@ -104,6 +105,9 @@ css_error css_computed_style_destroy(css_computed_style *style)
*/
css_error css_computed_style_compose(const css_computed_style *parent,
const css_computed_style *child,
+ css_error (*compute_font_size)(void *pw,
+ const css_hint *parent, css_hint *size),
+ void *pw,
css_computed_style *result)
{
css_error error = CSS_OK;
@@ -131,6 +135,31 @@ css_error css_computed_style_compose(const css_computed_style *parent,
break;
}
- return error;
+ /* Finally, compute absolute values for everything */
+ return compute_absolute_values(result, compute_font_size, pw);
+}
+
+/******************************************************************************
+ * Library internals *
+ ******************************************************************************/
+
+/**
+ * Compute the absolute values of a style
+ *
+ * \param style Computed style to process
+ * \param compute_font_size Callback to calculate an absolute font-size
+ * \param pw Private word for callback
+ * \return CSS_OK on success.
+ */
+css_error compute_absolute_values(css_computed_style *style,
+ css_error (*compute_font_size)(void *pw,
+ const css_hint *parent, css_hint *size),
+ void *pw)
+{
+ UNUSED(style);
+ UNUSED(compute_font_size);
+ UNUSED(pw);
+
+ return CSS_OK;
}
diff --git a/src/select/select.c b/src/select/select.c
index c839be1..f94b2c2 100644
--- a/src/select/select.c
+++ b/src/select/select.c
@@ -8,12 +8,12 @@
#include <assert.h>
#include <string.h>
-#include <libcss/computed.h>
#include <libcss/select.h>
#include "bytecode/bytecode.h"
#include "bytecode/opcodes.h"
#include "stylesheet.h"
+#include "select/computed.h"
#include "select/dispatch.h"
#include "select/hash.h"
#include "select/propset.h"
@@ -323,10 +323,7 @@ css_error css_select_style(css_select_ctx *ctx, void *node,
}
/* Take account of presentational hints and fix up any remaining
- * unset properties.
- * Those properties which are inherited need to be set as inherit.
- * Those which are not inherited need to be set to their default value.
- */
+ * unset properties. */
for (i = 0; i < CSS_N_PROPERTIES; i++) {
/* If the existing property value came from an author
* stylesheet or a user sheet using !important, then leave
@@ -349,6 +346,17 @@ css_error css_select_style(css_select_ctx *ctx, void *node,
}
}
+ /* If this is the root element, then we must ensure that all
+ * length values are absolute, display and float are correctly
+ * computed, and the default border-{top,right,bottom,left}-color
+ * is set to the computed value of color. */
+ if (parent == NULL) {
+ error = compute_absolute_values(result,
+ handler->compute_font_size, pw);
+ if (error != CSS_OK)
+ goto cleanup;
+ }
+
error = CSS_OK;
cleanup:
if (ctx->sheets[0] != NULL) {
diff --git a/test/select-auto.c b/test/select-auto.c
index fed6204..c52cb0a 100644
--- a/test/select-auto.c
+++ b/test/select-auto.c
@@ -116,6 +116,8 @@ static css_error node_presentational_hint(void *pw, void *node,
uint32_t property, css_hint *hint);
static css_error ua_default_for_property(void *pw, uint32_t property,
css_hint *hint);
+static css_error compute_font_size(void *pw, const css_hint *parent,
+ css_hint *size);
static css_select_handler select_handler = {
node_name,
@@ -138,7 +140,8 @@ static css_select_handler select_handler = {
node_is_focus,
node_is_lang,
node_presentational_hint,
- ua_default_for_property
+ ua_default_for_property,
+ compute_font_size
};
static void *myrealloc(void *data, size_t len, void *pw)
@@ -1110,3 +1113,65 @@ css_error ua_default_for_property(void *pw, uint32_t property, css_hint *hint)
return CSS_OK;
}
+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;
+}
+