Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  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 <jmb@netsurf-browser.org>
  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_counter_reset(uint32_t opv, css_style *style,
  18.                 css_select_state *state)
  19. {
  20.         return css__cascade_counter_increment_reset(opv, style, state,
  21.                         set_counter_reset);
  22. }
  23.  
  24. css_error css__set_counter_reset_from_hint(const css_hint *hint,
  25.                 css_computed_style *style)
  26. {
  27.         css_computed_counter *item;
  28.         css_error error;
  29.  
  30.         error = set_counter_reset(style, hint->status, hint->data.counter);
  31.  
  32.         if (hint->status == CSS_COUNTER_RESET_NAMED &&
  33.                         hint->data.counter != NULL) {
  34.                 for (item = hint->data.counter; item->name != NULL; item++) {
  35.                         lwc_string_unref(item->name);
  36.                 }
  37.         }
  38.  
  39.         if (error != CSS_OK && hint->data.counter != NULL)
  40.                 style->alloc(hint->data.counter, 0, style->pw);
  41.  
  42.         return error;
  43. }
  44.  
  45. css_error css__initial_counter_reset(css_select_state *state)
  46. {
  47.         return set_counter_reset(state->computed, CSS_COUNTER_RESET_NONE, NULL);
  48. }
  49.  
  50. css_error css__compose_counter_reset(const css_computed_style *parent,
  51.                 const css_computed_style *child,
  52.                 css_computed_style *result)
  53. {
  54.         css_error error;
  55.         const css_computed_counter *items = NULL;
  56.         uint8_t type = get_counter_reset(child, &items);
  57.  
  58.         if ((child->uncommon == NULL && parent->uncommon != NULL) ||
  59.                         type == CSS_COUNTER_RESET_INHERIT ||
  60.                         (child->uncommon != NULL && result != child)) {
  61.                 size_t n_items = 0;
  62.                 css_computed_counter *copy = NULL;
  63.  
  64.                 if ((child->uncommon == NULL && parent->uncommon != NULL) ||
  65.                                 type == CSS_COUNTER_RESET_INHERIT) {
  66.                         type = get_counter_reset(parent, &items);
  67.                 }
  68.  
  69.                 if (type == CSS_COUNTER_RESET_NAMED && items != NULL) {
  70.                         const css_computed_counter *i;
  71.  
  72.                         for (i = items; i->name != NULL; i++)
  73.                                 n_items++;
  74.  
  75.                         copy = result->alloc(NULL, (n_items + 1) *
  76.                                         sizeof(css_computed_counter),
  77.                                         result->pw);
  78.                         if (copy == NULL)
  79.                                 return CSS_NOMEM;
  80.  
  81.                         memcpy(copy, items, (n_items + 1) *
  82.                                         sizeof(css_computed_counter));
  83.                 }
  84.  
  85.                 error = set_counter_reset(result, type, copy);
  86.                 if (error != CSS_OK && copy != NULL)
  87.                         result->alloc(copy, 0, result->pw);
  88.  
  89.                 return error;
  90.         }
  91.  
  92.         return CSS_OK;
  93. }
  94.