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 <assert.h>
  9. #include <string.h>
  10.  
  11. #include "bytecode/bytecode.h"
  12. #include "bytecode/opcodes.h"
  13. #include "parse/properties/properties.h"
  14. #include "parse/properties/utils.h"
  15.  
  16. /**
  17.  * Parse text-decoration
  18.  *
  19.  * \param c       Parsing context
  20.  * \param vector  Vector of tokens to process
  21.  * \param ctx     Pointer to vector iteration context
  22.  * \param result  Pointer to location to receive resulting style
  23.  * \return CSS_OK on success,
  24.  *         CSS_NOMEM on memory exhaustion,
  25.  *         CSS_INVALID if the input is not valid
  26.  *
  27.  * Post condition: \a *ctx is updated with the next token to process
  28.  *                 If the input is invalid, then \a *ctx remains unchanged.
  29.  */
  30. css_error css__parse_text_decoration(css_language *c,
  31.                 const parserutils_vector *vector, int *ctx,
  32.                 css_style *result)
  33. {
  34.         int orig_ctx = *ctx;
  35.         css_error error = CSS_INVALID;
  36.         const css_token *token;
  37.         bool match;
  38.  
  39.         /* IDENT([ underline || overline || line-through || blink ])
  40.          * | IDENT (none, inherit) */
  41.         token = parserutils_vector_iterate(vector, ctx);
  42.         if ((token == NULL) || (token->type != CSS_TOKEN_IDENT) ) {
  43.                 *ctx = orig_ctx;
  44.                 return CSS_INVALID;
  45.         }
  46.  
  47.         if (lwc_string_caseless_isequal(token->idata,
  48.                         c->strings[INHERIT],
  49.                         &match) == lwc_error_ok && match) {
  50.                 error = css_stylesheet_style_inherit(result, CSS_PROP_TEXT_DECORATION);
  51.         } else if (lwc_string_caseless_isequal(token->idata,
  52.                                 c->strings[NONE],
  53.                                 &match) == lwc_error_ok && match) {
  54.                 error = css__stylesheet_style_appendOPV(result,
  55.                                 CSS_PROP_TEXT_DECORATION, 0, TEXT_DECORATION_NONE);
  56.         } else {
  57.                 uint16_t value = 0;
  58.                 while (token != NULL) {
  59.                         if ((lwc_string_caseless_isequal(
  60.                                         token->idata, c->strings[UNDERLINE],
  61.                                         &match) == lwc_error_ok && match)) {
  62.                                 if ((value & TEXT_DECORATION_UNDERLINE) == 0)
  63.                                         value |= TEXT_DECORATION_UNDERLINE;
  64.                                 else {
  65.                                         *ctx = orig_ctx;
  66.                                         return CSS_INVALID;
  67.                                 }
  68.                         } else if ((lwc_string_caseless_isequal(
  69.                                         token->idata, c->strings[OVERLINE],
  70.                                         &match) == lwc_error_ok && match)) {
  71.                                 if ((value & TEXT_DECORATION_OVERLINE) == 0)
  72.                                         value |= TEXT_DECORATION_OVERLINE;
  73.                                 else {
  74.                                         *ctx = orig_ctx;
  75.                                         return CSS_INVALID;
  76.                                 }
  77.                         } else if ((lwc_string_caseless_isequal(
  78.                                         token->idata, c->strings[LINE_THROUGH],
  79.                                         &match) == lwc_error_ok && match)) {
  80.                                 if ((value & TEXT_DECORATION_LINE_THROUGH) == 0)
  81.                                         value |= TEXT_DECORATION_LINE_THROUGH;
  82.                                 else {
  83.                                         *ctx = orig_ctx;
  84.                                         return CSS_INVALID;
  85.                                 }
  86.                         } else if ((lwc_string_caseless_isequal(
  87.                                         token->idata, c->strings[BLINK],
  88.                                         &match) == lwc_error_ok && match)) {
  89.                                 if ((value & TEXT_DECORATION_BLINK) == 0)
  90.                                         value |= TEXT_DECORATION_BLINK;
  91.                                 else {
  92.                                         *ctx = orig_ctx;
  93.                                         return CSS_INVALID;
  94.                                 }
  95.                         } else {
  96.                                 *ctx = orig_ctx;
  97.                                 return CSS_INVALID;
  98.                         }
  99.  
  100.                         consumeWhitespace(vector, ctx);
  101.  
  102.                         token = parserutils_vector_peek(vector, *ctx);
  103.                         if (token != NULL && token->type != CSS_TOKEN_IDENT)
  104.                                 break;
  105.                         token = parserutils_vector_iterate(vector, ctx);
  106.                 }
  107.                 error = css__stylesheet_style_appendOPV(result,
  108.                                 CSS_PROP_TEXT_DECORATION, 0, value);
  109.         }
  110.  
  111.         if (error != CSS_OK)
  112.                 *ctx = orig_ctx;
  113.  
  114.         return error;
  115. }
  116.