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_clip(uint32_t opv, css_style *style,
  18.                 css_select_state *state)
  19. {
  20.         uint16_t value = CSS_CLIP_INHERIT;
  21.         css_computed_clip_rect rect = { 0, 0, 0, 0,
  22.                         CSS_UNIT_PX, CSS_UNIT_PX, CSS_UNIT_PX, CSS_UNIT_PX,
  23.                         false, false, false, false };
  24.  
  25.         if (isInherit(opv) == false) {
  26.                 switch (getValue(opv) & CLIP_SHAPE_MASK) {
  27.                 case CLIP_SHAPE_RECT:
  28.                         if (getValue(opv) & CLIP_RECT_TOP_AUTO) {
  29.                                 rect.top_auto = true;
  30.                         } else {
  31.                                 rect.top = *((css_fixed *) style->bytecode);
  32.                                 advance_bytecode(style, sizeof(css_fixed));
  33.                                 rect.tunit = *((uint32_t *) style->bytecode);
  34.                                 advance_bytecode(style, sizeof(uint32_t));
  35.                         }
  36.                         if (getValue(opv) & CLIP_RECT_RIGHT_AUTO) {
  37.                                 rect.right_auto = true;
  38.                         } else {
  39.                                 rect.right = *((css_fixed *) style->bytecode);
  40.                                 advance_bytecode(style, sizeof(css_fixed));
  41.                                 rect.runit = *((uint32_t *) style->bytecode);
  42.                                 advance_bytecode(style, sizeof(uint32_t));
  43.                         }
  44.                         if (getValue(opv) & CLIP_RECT_BOTTOM_AUTO) {
  45.                                 rect.bottom_auto = true;
  46.                         } else {
  47.                                 rect.bottom = *((css_fixed *) style->bytecode);
  48.                                 advance_bytecode(style, sizeof(css_fixed));
  49.                                 rect.bunit = *((uint32_t *) style->bytecode);
  50.                                 advance_bytecode(style, sizeof(uint32_t));
  51.                         }
  52.                         if (getValue(opv) & CLIP_RECT_LEFT_AUTO) {
  53.                                 rect.left_auto = true;
  54.                         } else {
  55.                                 rect.left = *((css_fixed *) style->bytecode);
  56.                                 advance_bytecode(style, sizeof(css_fixed));
  57.                                 rect.lunit = *((uint32_t *) style->bytecode);
  58.                                 advance_bytecode(style, sizeof(uint32_t));
  59.                         }
  60.                         value = CSS_CLIP_RECT;
  61.                         break;
  62.                 case CLIP_AUTO:
  63.                         value = CSS_CLIP_AUTO;
  64.                         break;
  65.                 }
  66.         }
  67.  
  68.         rect.tunit = css__to_css_unit(rect.tunit);
  69.         rect.runit = css__to_css_unit(rect.runit);
  70.         rect.bunit = css__to_css_unit(rect.bunit);
  71.         rect.lunit = css__to_css_unit(rect.lunit);
  72.  
  73.         if (css__outranks_existing(getOpcode(opv), isImportant(opv), state,
  74.                         isInherit(opv))) {
  75.                 return set_clip(state->computed, value, &rect);
  76.         }
  77.  
  78.         return CSS_OK;
  79. }
  80.  
  81. css_error css__set_clip_from_hint(const css_hint *hint,
  82.                 css_computed_style *style)
  83. {
  84.         return set_clip(style, hint->status, hint->data.clip);
  85. }
  86.  
  87. css_error css__initial_clip(css_select_state *state)
  88. {
  89.         css_computed_clip_rect rect = { 0, 0, 0, 0,
  90.                         CSS_UNIT_PX, CSS_UNIT_PX, CSS_UNIT_PX, CSS_UNIT_PX,
  91.                         false, false, false, false };
  92.  
  93.         return set_clip(state->computed, CSS_CLIP_AUTO, &rect);
  94. }
  95.  
  96. css_error css__compose_clip(const css_computed_style *parent,
  97.                 const css_computed_style *child,
  98.                 css_computed_style *result)
  99. {
  100.         css_computed_clip_rect rect = { 0, 0, 0, 0,
  101.                         CSS_UNIT_PX, CSS_UNIT_PX, CSS_UNIT_PX, CSS_UNIT_PX,
  102.                         false, false, false, false };
  103.         uint8_t type = get_clip(child, &rect);
  104.  
  105.         if ((child->uncommon == NULL && parent->uncommon != NULL) ||
  106.                         type == CSS_CLIP_INHERIT ||
  107.                         (child->uncommon != NULL && result != child)) {
  108.                 if ((child->uncommon == NULL && parent->uncommon != NULL) ||
  109.                                 type == CSS_CLIP_INHERIT) {
  110.                         type = get_clip(parent, &rect);
  111.                 }
  112.  
  113.                 return set_clip(result, type, &rect);
  114.         }
  115.  
  116.         return CSS_OK;
  117. }
  118.  
  119.