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_vertical_align(uint32_t opv, css_style *style,
  18.                 css_select_state *state)
  19. {
  20.         uint16_t value = CSS_VERTICAL_ALIGN_INHERIT;
  21.         css_fixed length = 0;
  22.         uint32_t unit = UNIT_PX;
  23.  
  24.         if (isInherit(opv) == false) {
  25.                 switch (getValue(opv)) {
  26.                 case VERTICAL_ALIGN_SET:
  27.                         value = CSS_VERTICAL_ALIGN_SET;
  28.  
  29.                         length = *((css_fixed *) style->bytecode);
  30.                         advance_bytecode(style, sizeof(length));
  31.                         unit = *((uint32_t *) style->bytecode);
  32.                         advance_bytecode(style, sizeof(unit));
  33.                         break;
  34.                 case VERTICAL_ALIGN_BASELINE:
  35.                         value = CSS_VERTICAL_ALIGN_BASELINE;
  36.                         break;
  37.                 case VERTICAL_ALIGN_SUB:
  38.                         value = CSS_VERTICAL_ALIGN_SUB;
  39.                         break;
  40.                 case VERTICAL_ALIGN_SUPER:
  41.                         value = CSS_VERTICAL_ALIGN_SUPER;
  42.                         break;
  43.                 case VERTICAL_ALIGN_TOP:
  44.                         value = CSS_VERTICAL_ALIGN_TOP;
  45.                         break;
  46.                 case VERTICAL_ALIGN_TEXT_TOP:
  47.                         value = CSS_VERTICAL_ALIGN_TEXT_TOP;
  48.                         break;
  49.                 case VERTICAL_ALIGN_MIDDLE:
  50.                         value = CSS_VERTICAL_ALIGN_MIDDLE;
  51.                         break;
  52.                 case VERTICAL_ALIGN_BOTTOM:
  53.                         value = CSS_VERTICAL_ALIGN_BOTTOM;
  54.                         break;
  55.                 case VERTICAL_ALIGN_TEXT_BOTTOM:
  56.                         value = CSS_VERTICAL_ALIGN_TEXT_BOTTOM;
  57.                         break;
  58.                 }
  59.         }
  60.  
  61.         unit = css__to_css_unit(unit);
  62.  
  63.         if (css__outranks_existing(getOpcode(opv), isImportant(opv), state,
  64.                         isInherit(opv))) {
  65.                 return set_vertical_align(state->computed, value, length, unit);
  66.         }
  67.  
  68.         return CSS_OK;
  69. }
  70.  
  71. css_error css__set_vertical_align_from_hint(const css_hint *hint,
  72.                 css_computed_style *style)
  73. {
  74.         return set_vertical_align(style, hint->status,
  75.                         hint->data.length.value, hint->data.length.unit);
  76. }
  77.  
  78. css_error css__initial_vertical_align(css_select_state *state)
  79. {
  80.         return set_vertical_align(state->computed, CSS_VERTICAL_ALIGN_BASELINE,
  81.                         0, CSS_UNIT_PX);
  82. }
  83.  
  84. css_error css__compose_vertical_align(const css_computed_style *parent,
  85.                 const css_computed_style *child,
  86.                 css_computed_style *result)
  87. {
  88.         css_fixed length = 0;
  89.         css_unit unit = CSS_UNIT_PX;
  90.         uint8_t type = get_vertical_align(child, &length, &unit);
  91.  
  92.         if (type == CSS_VERTICAL_ALIGN_INHERIT) {
  93.                 type = get_vertical_align(parent, &length, &unit);
  94.         }
  95.  
  96.         return set_vertical_align(result, type, length, unit);
  97. }
  98.  
  99.