From 668aaa731a4e3fcb8ad49aa08b694aefe3f7e606 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 27 Aug 2022 15:33:39 +0100 Subject: Select: Add computed style clone function --- src/select/computed.c | 31 +++++++++++++++++++++++++++++++ src/select/computed.h | 4 ++++ 2 files changed, 35 insertions(+) (limited to 'src/select') diff --git a/src/select/computed.c b/src/select/computed.c index c019590..89d6efb 100644 --- a/src/select/computed.c +++ b/src/select/computed.c @@ -232,6 +232,37 @@ css_error css__computed_style_initialise(css_computed_style *style, return CSS_OK; } +/** + * 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 * diff --git a/src/select/computed.h b/src/select/computed.h index a4bd23d..a1e4eed 100644 --- a/src/select/computed.h +++ b/src/select/computed.h @@ -35,6 +35,10 @@ css_error css__computed_style_create(css_computed_style **result); css_error css__computed_style_initialise(css_computed_style *style, struct css_select_handler *handler, void *pw); +css_error css__computed_style_clone( + const css_computed_style *orig, + css_computed_style **clone_out); + css_error css__compute_absolute_values(const css_computed_style *parent, css_computed_style *style, const css_unit_ctx *unit_ctx); -- cgit v1.2.3