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 play-during
  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_play_during(css_language *c,
  31.                 const parserutils_vector *vector, int *ctx,
  32.                 css_style *result)
  33. {
  34.         int orig_ctx = *ctx;
  35.         css_error error;
  36.         const css_token *token;
  37.         uint8_t flags = 0;
  38.         uint16_t value = 0;
  39.         lwc_string *uri;
  40.         bool match;
  41.         uint32_t uri_snumber;
  42.  
  43.         /* URI [ IDENT(mix) || IDENT(repeat) ]? | IDENT(auto,none,inherit) */
  44.         token = parserutils_vector_iterate(vector, ctx);
  45.         if ((token == NULL) ||
  46.             ((token->type != CSS_TOKEN_IDENT) &&
  47.              (token->type != CSS_TOKEN_URI))) {
  48.                 *ctx = orig_ctx;
  49.                 return CSS_INVALID;
  50.         }
  51.  
  52.         if (token->type == CSS_TOKEN_IDENT) {
  53.                 if ((lwc_string_caseless_isequal(
  54.                                 token->idata, c->strings[INHERIT],
  55.                                 &match) == lwc_error_ok && match)) {
  56.                         flags |= FLAG_INHERIT;
  57.                 } else if ((lwc_string_caseless_isequal(
  58.                                 token->idata, c->strings[NONE],
  59.                                 &match) == lwc_error_ok && match)) {
  60.                         value = PLAY_DURING_NONE;
  61.                 } else if ((lwc_string_caseless_isequal(
  62.                                 token->idata, c->strings[AUTO],
  63.                                 &match) == lwc_error_ok && match)) {
  64.                         value = PLAY_DURING_AUTO;
  65.                 } else {
  66.                         *ctx = orig_ctx;
  67.                         return CSS_INVALID;
  68.                 }
  69.         } else {
  70.                 int modifiers;
  71.  
  72.                 value = PLAY_DURING_URI;
  73.  
  74.                 error = c->sheet->resolve(c->sheet->resolve_pw,
  75.                                 c->sheet->url,
  76.                                 token->idata, &uri);
  77.                 if (error != CSS_OK) {
  78.                         *ctx = orig_ctx;
  79.                         return error;
  80.                 }
  81.  
  82.                 error = css__stylesheet_string_add(c->sheet,
  83.                                                   uri,
  84.                                                   &uri_snumber);
  85.                 if (error != CSS_OK) {
  86.                         *ctx = orig_ctx;
  87.                         return error;
  88.                 }
  89.  
  90.  
  91.                 for (modifiers = 0; modifiers < 2; modifiers++) {
  92.                         consumeWhitespace(vector, ctx);
  93.  
  94.                         token = parserutils_vector_peek(vector, *ctx);
  95.                         if (token != NULL && token->type == CSS_TOKEN_IDENT) {
  96.                                 if ((lwc_string_caseless_isequal(
  97.                                                 token->idata, c->strings[MIX],
  98.                                                 &match) == lwc_error_ok &&
  99.                                                 match)) {
  100.                                         if ((value & PLAY_DURING_MIX) == 0)
  101.                                                 value |= PLAY_DURING_MIX;
  102.                                         else {
  103.                                                 *ctx = orig_ctx;
  104.                                                 return CSS_INVALID;
  105.                                         }
  106.                                 } else if (lwc_string_caseless_isequal(
  107.                                                 token->idata,
  108.                                                 c->strings[REPEAT],
  109.                                                 &match) == lwc_error_ok &&
  110.                                                 match) {
  111.                                         if ((value & PLAY_DURING_REPEAT) == 0)
  112.                                                 value |= PLAY_DURING_REPEAT;
  113.                                         else {
  114.                                                 *ctx = orig_ctx;
  115.                                                 return CSS_INVALID;
  116.                                         }
  117.                                 } else {
  118.                                         *ctx = orig_ctx;
  119.                                         return CSS_INVALID;
  120.                                 }
  121.  
  122.                                 parserutils_vector_iterate(vector, ctx);
  123.                         }
  124.                 }
  125.         }
  126.  
  127.         error = css__stylesheet_style_appendOPV(result, CSS_PROP_PLAY_DURING, flags, value);
  128.         if (error != CSS_OK) {
  129.                 *ctx = orig_ctx;
  130.                 return error;
  131.         }
  132.  
  133.         if ((flags & FLAG_INHERIT) == false &&
  134.             (value & PLAY_DURING_TYPE_MASK) == PLAY_DURING_URI) {
  135.                 error = css__stylesheet_style_append(result, uri_snumber);
  136.         }
  137.  
  138.         if (error != CSS_OK)
  139.                 *ctx = orig_ctx;
  140.  
  141.         return error;
  142. }
  143.