summaryrefslogtreecommitdiff
path: root/src/select/computed.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/select/computed.c')
-rw-r--r--src/select/computed.c79
1 files changed, 66 insertions, 13 deletions
diff --git a/src/select/computed.c b/src/select/computed.c
index a1b345b..78f3b80 100644
--- a/src/select/computed.c
+++ b/src/select/computed.c
@@ -12,6 +12,7 @@
#include "select/dispatch.h"
#include "select/propget.h"
#include "select/propset.h"
+#include "select/unit.h"
#include "utils/utils.h"
static css_error compute_absolute_color(css_computed_style *style,
@@ -232,6 +233,37 @@ css_error css__computed_style_initialise(css_computed_style *style,
}
/**
+ * Clone a computed style
+ *
+ * \param orig Style to copy
+ * \param clone_out Returns cloned style on success
+ * \return CSS_OK on success.
+ */
+css_error css__computed_style_clone(
+ const css_computed_style *orig,
+ css_computed_style **clone_out)
+{
+ css_error error;
+ css_computed_style *clone;
+
+ error = css__computed_style_create(&clone);
+ if (error != CSS_OK) {
+ return error;
+ }
+
+ for (size_t i = 0; i < CSS_N_PROPERTIES; i++) {
+ error = prop_dispatch[i].copy(orig, clone);
+ if (error != CSS_OK) {
+ css_computed_style_destroy(clone);
+ return error;
+ }
+ }
+
+ *clone_out = clone;
+ return CSS_OK;
+}
+
+/**
* Compose two computed styles
*
* \param parent Parent style
@@ -247,9 +279,7 @@ css_error css__computed_style_initialise(css_computed_style *style,
css_error css_computed_style_compose(
const css_computed_style *restrict parent,
const css_computed_style *restrict child,
- css_error (*compute_font_size)(void *pw,
- const css_hint *parent, css_hint *size),
- void *pw,
+ const css_unit_ctx *unit_ctx,
css_computed_style **restrict result)
{
css_computed_style *composed;
@@ -275,8 +305,7 @@ css_error css_computed_style_compose(
}
/* Finally, compute absolute values for everything */
- error = css__compute_absolute_values(parent, composed,
- compute_font_size, pw);
+ error = css__compute_absolute_values(parent, composed, unit_ctx);
if (error != CSS_OK) {
return error;
}
@@ -781,6 +810,18 @@ uint8_t css_computed_opacity(const css_computed_style *style,
return get_opacity(style, opacity);
}
+uint8_t css_computed_fill_opacity(const css_computed_style *style,
+ css_fixed *fill_opacity)
+{
+ return get_fill_opacity(style, fill_opacity);
+}
+
+uint8_t css_computed_stroke_opacity(const css_computed_style *style,
+ css_fixed *stroke_opacity)
+{
+ return get_stroke_opacity(style, stroke_opacity);
+}
+
uint8_t css_computed_text_transform(const css_computed_style *style)
{
return get_text_transform(style);
@@ -897,6 +938,8 @@ uint8_t css_computed_display(const css_computed_style *style,
return CSS_DISPLAY_TABLE;
} else if (display == CSS_DISPLAY_INLINE_FLEX) {
return CSS_DISPLAY_FLEX;
+ } else if (display == CSS_DISPLAY_INLINE_GRID) {
+ return CSS_DISPLAY_GRID;
} else if (display == CSS_DISPLAY_INLINE ||
display == CSS_DISPLAY_RUN_IN ||
display == CSS_DISPLAY_TABLE_ROW_GROUP ||
@@ -1087,31 +1130,36 @@ uint8_t css_computed_order(const css_computed_style *style,
*
* \param parent Parent style, or NULL for tree root
* \param style Computed style to process
- * \param compute_font_size Callback to calculate an absolute font-size
- * \param pw Private word for callback
+ * \param unit_ctx Client length conversion context.
* \return CSS_OK on success.
*/
css_error css__compute_absolute_values(const css_computed_style *parent,
css_computed_style *style,
- css_error (*compute_font_size)(void *pw,
- const css_hint *parent, css_hint *size),
- void *pw)
+ const css_unit_ctx *unit_ctx)
{
+ css_hint_length *ref_length = NULL;
css_hint psize, size, ex_size;
css_error error;
- /* Ensure font-size is absolute */
+ /* Get reference font-size for relative sizes. */
if (parent != NULL) {
psize.status = get_font_size(parent,
&psize.data.length.value,
&psize.data.length.unit);
+ if (psize.status != CSS_FONT_SIZE_DIMENSION) {
+ return CSS_BADPARM;
+ }
+ ref_length = &psize.data.length;
}
size.status = get_font_size(style,
&size.data.length.value,
&size.data.length.unit);
- error = compute_font_size(pw, parent != NULL ? &psize : NULL, &size);
+ error = css_unit_compute_absolute_font_size(ref_length,
+ unit_ctx->root_style,
+ unit_ctx->font_size_default,
+ &size);
if (error != CSS_OK)
return error;
@@ -1125,7 +1173,12 @@ css_error css__compute_absolute_values(const css_computed_style *parent,
ex_size.status = CSS_FONT_SIZE_DIMENSION;
ex_size.data.length.value = INTTOFIX(1);
ex_size.data.length.unit = CSS_UNIT_EX;
- error = compute_font_size(pw, &size, &ex_size);
+
+ error = css_unit_compute_absolute_font_size(
+ &size.data.length,
+ unit_ctx->root_style,
+ unit_ctx->font_size_default,
+ &ex_size);
if (error != CSS_OK)
return error;