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_quotes(uint32_t opv, css_style *style,
  18.                 css_select_state *state)
  19. {
  20.         uint16_t value = CSS_QUOTES_INHERIT;
  21.         lwc_string **quotes = NULL;
  22.         uint32_t n_quotes = 0;
  23.  
  24.         if (isInherit(opv) == false) {
  25.                 uint32_t v = getValue(opv);
  26.  
  27.                 value = CSS_QUOTES_STRING;
  28.  
  29.                 while (v != QUOTES_NONE) {
  30.                         lwc_string *open, *close;
  31.                         lwc_string **temp;
  32.  
  33.                         css__stylesheet_string_get(style->sheet, *((css_code_t *) style->bytecode), &open);
  34.                         advance_bytecode(style, sizeof(css_code_t));
  35.  
  36.                         css__stylesheet_string_get(style->sheet, *((css_code_t *) style->bytecode), &close);
  37.                         advance_bytecode(style, sizeof(css_code_t));
  38.  
  39.                         temp = state->computed->alloc(quotes,
  40.                                         (n_quotes + 2) * sizeof(lwc_string *),
  41.                                         state->computed->pw);
  42.                         if (temp == NULL) {
  43.                                 if (quotes != NULL) {
  44.                                         state->computed->alloc(quotes, 0,
  45.                                                         state->computed->pw);
  46.                                 }
  47.                                 return CSS_NOMEM;
  48.                         }
  49.  
  50.                         quotes = temp;
  51.  
  52.                         quotes[n_quotes++] = open;
  53.                         quotes[n_quotes++] = close;
  54.  
  55.                         v = *((uint32_t *) style->bytecode);
  56.                         advance_bytecode(style, sizeof(v));
  57.                 }
  58.         }
  59.  
  60.         /* Terminate array, if required */
  61.         if (n_quotes > 0) {
  62.                 lwc_string **temp;
  63.  
  64.                 temp = state->computed->alloc(quotes,
  65.                                 (n_quotes + 1) * sizeof(lwc_string *),
  66.                                 state->computed->pw);
  67.                 if (temp == NULL) {
  68.                         state->computed->alloc(quotes, 0, state->computed->pw);
  69.                         return CSS_NOMEM;
  70.                 }
  71.  
  72.                 quotes = temp;
  73.  
  74.                 quotes[n_quotes] = NULL;
  75.         }
  76.  
  77.         if (css__outranks_existing(getOpcode(opv), isImportant(opv), state,
  78.                         isInherit(opv))) {
  79.                 css_error error;
  80.  
  81.                 error = set_quotes(state->computed, value, quotes);
  82.                 if (error != CSS_OK && quotes != NULL)
  83.                         state->computed->alloc(quotes, 0, state->computed->pw);
  84.  
  85.                 return error;
  86.         } else {
  87.                 if (quotes != NULL)
  88.                         state->computed->alloc(quotes, 0, state->computed->pw);
  89.         }
  90.  
  91.         return CSS_OK;
  92. }
  93.  
  94. css_error css__set_quotes_from_hint(const css_hint *hint,
  95.                 css_computed_style *style)
  96. {
  97.         lwc_string **item;
  98.         css_error error;
  99.                
  100.         error = set_quotes(style, hint->status, hint->data.strings);
  101.  
  102.         for (item = hint->data.strings;
  103.                         item != NULL && (*item) != NULL; item++) {
  104.                 lwc_string_unref(*item);
  105.         }
  106.  
  107.         if (error != CSS_OK && hint->data.strings != NULL)
  108.                 style->alloc(hint->data.strings, 0, style->pw);
  109.  
  110.         return error;
  111. }
  112.  
  113. css_error css__initial_quotes(css_select_state *state)
  114. {
  115.         css_hint hint;
  116.         css_error error;
  117.  
  118.         error = state->handler->ua_default_for_property(state->pw,
  119.                         CSS_PROP_QUOTES, &hint);
  120.         if (error != CSS_OK)
  121.                 return error;
  122.  
  123.         return css__set_quotes_from_hint(&hint, state->computed);
  124. }
  125.  
  126. css_error css__compose_quotes(const css_computed_style *parent,
  127.                 const css_computed_style *child,
  128.                 css_computed_style *result)
  129. {
  130.         css_error error;
  131.         lwc_string **quotes = NULL;
  132.         uint8_t type = get_quotes(child, &quotes);
  133.  
  134.         if (type == CSS_QUOTES_INHERIT || result != child) {
  135.                 size_t n_quotes = 0;
  136.                 lwc_string **copy = NULL;
  137.  
  138.                 if (type == CSS_QUOTES_INHERIT) {
  139.                         type = get_quotes(parent, &quotes);
  140.                 }
  141.  
  142.                 if (quotes != NULL) {
  143.                         lwc_string **i;
  144.  
  145.                         for (i = quotes; (*i) != NULL; i++)
  146.                                 n_quotes++;
  147.  
  148.                         copy = result->alloc(NULL, (n_quotes + 1) *
  149.                                         sizeof(lwc_string *),
  150.                                         result->pw);
  151.                         if (copy == NULL)
  152.                                 return CSS_NOMEM;
  153.  
  154.                         memcpy(copy, quotes, (n_quotes + 1) *
  155.                                         sizeof(lwc_string *));
  156.                 }
  157.  
  158.                 error = set_quotes(result, type, copy);
  159.                 if (error != CSS_OK && copy != NULL)
  160.                         result->alloc(copy, 0, result->pw);
  161.  
  162.                 return error;
  163.         }
  164.  
  165.         return CSS_OK;
  166. }
  167.  
  168.