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_background_position(uint32_t opv, css_style *style,
  18.                 css_select_state *state)
  19. {
  20.         uint16_t value = CSS_BACKGROUND_POSITION_INHERIT;
  21.         css_fixed hlength = 0;
  22.         css_fixed vlength = 0;
  23.         uint32_t hunit = UNIT_PX;
  24.         uint32_t vunit = UNIT_PX;
  25.  
  26.         if (isInherit(opv) == false) {
  27.                 value = CSS_BACKGROUND_POSITION_SET;
  28.  
  29.                 switch (getValue(opv) & 0xf0) {
  30.                 case BACKGROUND_POSITION_HORZ_SET:
  31.                         hlength = *((css_fixed *) style->bytecode);
  32.                         advance_bytecode(style, sizeof(hlength));
  33.                         hunit = *((uint32_t *) style->bytecode);
  34.                         advance_bytecode(style, sizeof(hunit));
  35.                         break;
  36.                 case BACKGROUND_POSITION_HORZ_CENTER:
  37.                         hlength = INTTOFIX(50);
  38.                         hunit = UNIT_PCT;
  39.                         break;
  40.                 case BACKGROUND_POSITION_HORZ_RIGHT:
  41.                         hlength = INTTOFIX(100);
  42.                         hunit = UNIT_PCT;
  43.                         break;
  44.                 case BACKGROUND_POSITION_HORZ_LEFT:
  45.                         hlength = INTTOFIX(0);
  46.                         hunit = UNIT_PCT;
  47.                         break;
  48.                 }
  49.  
  50.                 switch (getValue(opv) & 0x0f) {
  51.                 case BACKGROUND_POSITION_VERT_SET:
  52.                         vlength = *((css_fixed *) style->bytecode);
  53.                         advance_bytecode(style, sizeof(vlength));
  54.                         vunit = *((uint32_t *) style->bytecode);
  55.                         advance_bytecode(style, sizeof(vunit));
  56.                         break;
  57.                 case BACKGROUND_POSITION_VERT_CENTER:
  58.                         vlength = INTTOFIX(50);
  59.                         vunit = UNIT_PCT;
  60.                         break;
  61.                 case BACKGROUND_POSITION_VERT_BOTTOM:
  62.                         vlength = INTTOFIX(100);
  63.                         vunit = UNIT_PCT;
  64.                         break;
  65.                 case BACKGROUND_POSITION_VERT_TOP:
  66.                         vlength = INTTOFIX(0);
  67.                         vunit = UNIT_PCT;
  68.                         break;
  69.                 }
  70.         }
  71.  
  72.         hunit = css__to_css_unit(hunit);
  73.         vunit = css__to_css_unit(vunit);
  74.  
  75.         if (css__outranks_existing(getOpcode(opv), isImportant(opv), state,
  76.                         isInherit(opv))) {
  77.                 return set_background_position(state->computed, value,
  78.                                 hlength, hunit, vlength, vunit);
  79.         }
  80.  
  81.         return CSS_OK;
  82. }
  83.  
  84. css_error css__set_background_position_from_hint(const css_hint *hint,
  85.                 css_computed_style *style)
  86. {
  87.         return set_background_position(style, hint->status,
  88.                 hint->data.position.h.value, hint->data.position.h.unit,
  89.                 hint->data.position.v.value, hint->data.position.v.unit);
  90. }
  91.  
  92. css_error css__initial_background_position(css_select_state *state)
  93. {
  94.         return set_background_position(state->computed,
  95.                         CSS_BACKGROUND_POSITION_SET,
  96.                         0, CSS_UNIT_PCT, 0, CSS_UNIT_PCT);
  97. }
  98.  
  99. css_error css__compose_background_position(const css_computed_style *parent,
  100.                 const css_computed_style *child,
  101.                 css_computed_style *result)
  102. {
  103.         css_fixed hlength = 0, vlength = 0;
  104.         css_unit hunit = CSS_UNIT_PX, vunit = CSS_UNIT_PX;
  105.         uint8_t type = get_background_position(child, &hlength, &hunit,
  106.                         &vlength, &vunit);
  107.  
  108.         if (type == CSS_BACKGROUND_POSITION_INHERIT) {
  109.                 type = get_background_position(parent,
  110.                                 &hlength, &hunit, &vlength, &vunit);
  111.         }
  112.  
  113.         return set_background_position(result, type, hlength, hunit,
  114.                                 vlength, vunit);
  115. }
  116.  
  117.