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_color(uint32_t opv, css_style *style,
  18.                 css_select_state *state)
  19. {
  20.         bool inherit = isInherit(opv);
  21.         uint16_t value = CSS_COLOR_INHERIT;
  22.         css_color color = 0;
  23.  
  24.         if (inherit == false) {
  25.                 switch (getValue(opv)) {
  26.                 case COLOR_TRANSPARENT:
  27.                         value = CSS_COLOR_COLOR;
  28.                         break;
  29.                 case COLOR_CURRENT_COLOR:
  30.                         /* color: currentColor always computes to inherit */
  31.                         value = CSS_COLOR_INHERIT;
  32.                         inherit = true;
  33.                         break;
  34.                 case COLOR_SET:
  35.                         value = CSS_COLOR_COLOR;
  36.                         color = *((css_color *) style->bytecode);
  37.                         advance_bytecode(style, sizeof(color));
  38.                         break;
  39.                 }
  40.         }
  41.  
  42.         if (css__outranks_existing(getOpcode(opv), isImportant(opv), state,
  43.                         inherit)) {
  44.                 return set_color(state->computed, value, color);
  45.         }
  46.  
  47.         return CSS_OK;
  48. }
  49.  
  50. css_error css__set_color_from_hint(const css_hint *hint,
  51.                 css_computed_style *style)
  52. {
  53.         return set_color(style, hint->status, hint->data.color);
  54. }
  55.  
  56. css_error css__initial_color(css_select_state *state)
  57. {
  58.         css_hint hint;
  59.         css_error error;
  60.  
  61.         error = state->handler->ua_default_for_property(state->pw,
  62.                         CSS_PROP_COLOR, &hint);
  63.         if (error != CSS_OK)
  64.                 return error;
  65.  
  66.         return css__set_color_from_hint(&hint, state->computed);
  67. }
  68.  
  69. css_error css__compose_color(const css_computed_style *parent,
  70.                 const css_computed_style *child,
  71.                 css_computed_style *result)
  72. {
  73.         css_color color;
  74.         uint8_t type = get_color(child, &color);
  75.  
  76.         if (type == CSS_COLOR_INHERIT) {
  77.                 type = get_color(parent, &color);
  78.         }
  79.  
  80.         return set_color(result, type, color);
  81. }
  82.  
  83.