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. #ifndef css_select_propset_h_
  9. #define css_select_propset_h_
  10.  
  11. #include <string.h>
  12.  
  13. #include <libcss/computed.h>
  14. #include "computed.h"
  15.  
  16. /* Important: keep this file in sync with computed.h */
  17. /** \todo Is there a better way to ensure this happens? */
  18.  
  19. static const css_computed_uncommon default_uncommon = {
  20.         { (CSS_LETTER_SPACING_INHERIT << 2) | CSS_OUTLINE_COLOR_INVERT,
  21.           (CSS_OUTLINE_WIDTH_MEDIUM << 1) | CSS_BORDER_SPACING_INHERIT,
  22.           0,
  23.           (CSS_WORD_SPACING_INHERIT << 2) |
  24.                 (CSS_COUNTER_INCREMENT_NONE << 1) | CSS_COUNTER_RESET_NONE,
  25.           (CSS_CURSOR_INHERIT << 3) | 0,
  26.           0,
  27.           0,
  28.           (CSS_CLIP_AUTO << 2) | CSS_CONTENT_NORMAL
  29.         },
  30.         { 0, 0 },
  31.         { 0, 0, 0, 0 },
  32.         0,
  33.         0,
  34.         0,
  35.         0,
  36.         NULL,
  37.         NULL,
  38.         NULL,
  39.         NULL
  40. };
  41.  
  42. #define ENSURE_UNCOMMON do {                                            \
  43.         if (style->uncommon == NULL) {                                  \
  44.                 style->uncommon = style->alloc(NULL,                    \
  45.                         sizeof(css_computed_uncommon), style->pw);      \
  46.                 if (style->uncommon == NULL)                            \
  47.                         return CSS_NOMEM;                               \
  48.                                                                         \
  49.                 memcpy(style->uncommon, &default_uncommon,              \
  50.                                 sizeof(css_computed_uncommon));         \
  51.         }                                                               \
  52. } while(0)
  53.  
  54. static const css_computed_page default_page = {
  55.         {      
  56.                 (CSS_PAGE_BREAK_INSIDE_AUTO <<  6) |
  57.                         (CSS_PAGE_BREAK_BEFORE_AUTO << 3) |
  58.                         CSS_PAGE_BREAK_AFTER_AUTO,
  59.                 (CSS_WIDOWS_SET << 1) |
  60.                         CSS_ORPHANS_SET
  61.         },
  62.         2 << CSS_RADIX_POINT,
  63.         2 << CSS_RADIX_POINT
  64. };
  65.  
  66. #define ENSURE_PAGE do {                                                \
  67.         if (style->page == NULL) {                                      \
  68.                 style->page = style->alloc(NULL,                        \
  69.                         sizeof(css_computed_page), style->pw);          \
  70.                 if (style->page == NULL)                                \
  71.                         return CSS_NOMEM;                               \
  72.                                                                         \
  73.                 memcpy(style->page, &default_page,                      \
  74.                                 sizeof(css_computed_page));             \
  75.         }                                                               \
  76. } while(0)
  77.  
  78. #define LETTER_SPACING_INDEX 0
  79. #define LETTER_SPACING_SHIFT 2
  80. #define LETTER_SPACING_MASK  0xfc
  81. static inline css_error set_letter_spacing(
  82.                 css_computed_style *style, uint8_t type,
  83.                 css_fixed length, css_unit unit)
  84. {
  85.         uint8_t *bits;
  86.  
  87.         ENSURE_UNCOMMON;
  88.  
  89.         bits = &style->uncommon->bits[LETTER_SPACING_INDEX];
  90.  
  91.         /* 6bits: uuuutt : unit | type */
  92.         *bits = (*bits & ~LETTER_SPACING_MASK) |
  93.                         (((type & 0x3) | unit << 2) << LETTER_SPACING_SHIFT);
  94.  
  95.         style->uncommon->letter_spacing = length;
  96.  
  97.         return CSS_OK;
  98. }
  99. #undef LETTER_SPACING_MASK
  100. #undef LETTER_SPACING_SHIFT
  101. #undef LETTER_SPACING_INDEX
  102.  
  103. #define OUTLINE_COLOR_INDEX 0
  104. #define OUTLINE_COLOR_SHIFT 0
  105. #define OUTLINE_COLOR_MASK  0x3
  106. static inline css_error set_outline_color(
  107.                 css_computed_style *style, uint8_t type, css_color color)
  108. {
  109.         uint8_t *bits;
  110.  
  111.         ENSURE_UNCOMMON;
  112.  
  113.         bits = &style->uncommon->bits[OUTLINE_COLOR_INDEX];
  114.  
  115.         /* 2bits: tt : type */
  116.         *bits = (*bits & ~OUTLINE_COLOR_MASK) |
  117.                         ((type & 0x3) << OUTLINE_COLOR_SHIFT);
  118.  
  119.         style->uncommon->outline_color = color;
  120.  
  121.         return CSS_OK;
  122. }
  123. #undef OUTLINE_COLOR_MASK
  124. #undef OUTLINE_COLOR_SHIFT
  125. #undef OUTLINE_COLOR_INDEX
  126.  
  127. #define OUTLINE_WIDTH_INDEX 1
  128. #define OUTLINE_WIDTH_SHIFT 1
  129. #define OUTLINE_WIDTH_MASK  0xfe
  130. static inline css_error set_outline_width(
  131.                 css_computed_style *style, uint8_t type,
  132.                 css_fixed length, css_unit unit)
  133. {
  134.         uint8_t *bits;
  135.  
  136.         ENSURE_UNCOMMON;
  137.  
  138.         bits = &style->uncommon->bits[OUTLINE_WIDTH_INDEX];
  139.  
  140.         /* 7bits: uuuuttt : unit | type */
  141.         *bits = (*bits & ~OUTLINE_WIDTH_MASK) |
  142.                         (((type & 0x7) | (unit << 3)) << OUTLINE_WIDTH_SHIFT);
  143.  
  144.         style->uncommon->outline_width = length;
  145.  
  146.         return CSS_OK;
  147. }
  148. #undef OUTLINE_WIDTH_MASK
  149. #undef OUTLINE_WIDTH_SHIFT
  150. #undef OUTLINE_WIDTH_INDEX
  151.  
  152. #define BORDER_SPACING_INDEX 1
  153. #define BORDER_SPACING_SHIFT 0
  154. #define BORDER_SPACING_MASK  0x1
  155. #define BORDER_SPACING_INDEX1 2
  156. #define BORDER_SPACING_SHIFT1 0
  157. #define BORDER_SPACING_MASK1 0xff
  158. static inline css_error set_border_spacing(
  159.                 css_computed_style *style, uint8_t type,
  160.                 css_fixed hlength, css_unit hunit,
  161.                 css_fixed vlength, css_unit vunit)
  162. {
  163.         uint8_t *bits;
  164.  
  165.         ENSURE_UNCOMMON;
  166.  
  167.         bits = &style->uncommon->bits[BORDER_SPACING_INDEX];
  168.  
  169.         /* 1 bit: type */
  170.         *bits = (*bits & ~BORDER_SPACING_MASK) |
  171.                         ((type & 0x1) << BORDER_SPACING_SHIFT);
  172.  
  173.         bits = &style->uncommon->bits[BORDER_SPACING_INDEX1];
  174.  
  175.         /* 8bits: hhhhvvvv : hunit | vunit */
  176.         *bits = (*bits & ~BORDER_SPACING_MASK1) |
  177.                         (((hunit << 4) | vunit) << BORDER_SPACING_SHIFT1);
  178.  
  179.  
  180.         style->uncommon->border_spacing[0] = hlength;
  181.         style->uncommon->border_spacing[1] = vlength;
  182.  
  183.         return CSS_OK;
  184. }
  185. #undef BORDER_SPACING_MASK1
  186. #undef BORDER_SPACING_SHIFT1
  187. #undef BORDER_SPACING_INDEX1
  188. #undef BORDER_SPACING_MASK
  189. #undef BORDER_SPACING_SHIFT
  190. #undef BORDER_SPACING_INDEX
  191.  
  192. #define WORD_SPACING_INDEX 3
  193. #define WORD_SPACING_SHIFT 2
  194. #define WORD_SPACING_MASK  0xfc
  195. static inline css_error set_word_spacing(
  196.                 css_computed_style *style, uint8_t type,
  197.                 css_fixed length, css_unit unit)
  198. {
  199.         uint8_t *bits;
  200.  
  201.         ENSURE_UNCOMMON;
  202.  
  203.         bits = &style->uncommon->bits[WORD_SPACING_INDEX];
  204.  
  205.         /* 6bits: uuuutt : unit | type */
  206.         *bits = (*bits & ~WORD_SPACING_MASK) |
  207.                         (((type & 0x3) | (unit << 2)) << WORD_SPACING_SHIFT);
  208.        
  209.         style->uncommon->word_spacing = length;
  210.  
  211.         return CSS_OK;
  212. }
  213. #undef WORD_SPACING_MASK
  214. #undef WORD_SPACING_SHIFT
  215. #undef WORD_SPACING_INDEX
  216.  
  217. #define COUNTER_INCREMENT_INDEX 3
  218. #define COUNTER_INCREMENT_SHIFT 1
  219. #define COUNTER_INCREMENT_MASK  0x2
  220. static inline css_error set_counter_increment(
  221.                 css_computed_style *style, uint8_t type,
  222.                 css_computed_counter *counters)
  223. {
  224.         uint8_t *bits;
  225.         css_computed_counter *oldcounters;
  226.         css_computed_counter *c;
  227.  
  228.         ENSURE_UNCOMMON;
  229.  
  230.         bits = &style->uncommon->bits[COUNTER_INCREMENT_INDEX];
  231.         oldcounters = style->uncommon->counter_increment;
  232.  
  233.         /* 1bit: type */
  234.         *bits = (*bits & ~COUNTER_INCREMENT_MASK) |
  235.                         ((type & 0x1) << COUNTER_INCREMENT_SHIFT);
  236.  
  237.         for (c = counters; c != NULL && c->name != NULL; c++)
  238.                 c->name = lwc_string_ref(c->name);
  239.  
  240.         style->uncommon->counter_increment = counters;
  241.  
  242.         /* Free existing array */
  243.         if (oldcounters != NULL) {
  244.                 for (c = oldcounters; c->name != NULL; c++)
  245.                         lwc_string_unref(c->name);
  246.  
  247.                 if (oldcounters != counters)
  248.                         style->alloc(oldcounters, 0, style->pw);
  249.         }
  250.  
  251.         return CSS_OK;
  252. }
  253. #undef COUNTER_INCREMENT_MASK
  254. #undef COUNTER_INCREMENT_SHIFT
  255. #undef COUNTER_INCREMENT_INDEX
  256.  
  257. #define COUNTER_RESET_INDEX 3
  258. #define COUNTER_RESET_SHIFT 0
  259. #define COUNTER_RESET_MASK  0x1
  260. static inline css_error set_counter_reset(
  261.                 css_computed_style *style, uint8_t type,
  262.                 css_computed_counter *counters)
  263. {
  264.         uint8_t *bits;
  265.         css_computed_counter *oldcounters;
  266.         css_computed_counter *c;
  267.  
  268.         ENSURE_UNCOMMON;
  269.  
  270.         bits = &style->uncommon->bits[COUNTER_RESET_INDEX];
  271.         oldcounters = style->uncommon->counter_reset;
  272.  
  273.         /* 1bit: type */
  274.         *bits = (*bits & ~COUNTER_RESET_MASK) |
  275.                         ((type & 0x1) << COUNTER_RESET_SHIFT);
  276.  
  277.         for (c = counters; c != NULL && c->name != NULL; c++)
  278.                 c->name = lwc_string_ref(c->name);
  279.  
  280.         style->uncommon->counter_reset = counters;
  281.  
  282.         /* Free existing array */
  283.         if (oldcounters != NULL) {
  284.                 for (c = oldcounters; c->name != NULL; c++)
  285.                         lwc_string_unref(c->name);
  286.  
  287.                 if (oldcounters != counters)
  288.                         style->alloc(oldcounters, 0, style->pw);
  289.         }
  290.  
  291.         return CSS_OK;
  292. }
  293. #undef COUNTER_RESET_MASK
  294. #undef COUNTER_RESET_SHIFT
  295. #undef COUNTER_RESET_INDEX
  296.  
  297. #define CURSOR_INDEX 4
  298. #define CURSOR_SHIFT 3
  299. #define CURSOR_MASK  0xf8
  300. static inline css_error set_cursor(
  301.                 css_computed_style *style, uint8_t type,
  302.                 lwc_string **urls)
  303. {
  304.         uint8_t *bits;
  305.         lwc_string **oldurls;
  306.         lwc_string **s;
  307.  
  308.         ENSURE_UNCOMMON;
  309.  
  310.         bits = &style->uncommon->bits[CURSOR_INDEX];
  311.         oldurls = style->uncommon->cursor;
  312.  
  313.         /* 5bits: type */
  314.         *bits = (*bits & ~CURSOR_MASK) |
  315.                         ((type & 0x1f) << CURSOR_SHIFT);
  316.  
  317.         for (s = urls; s != NULL && *s != NULL; s++)
  318.                 *s = lwc_string_ref(*s);
  319.  
  320.         style->uncommon->cursor = urls;
  321.  
  322.         /* Free existing array */
  323.         if (oldurls != NULL) {
  324.                 for (s = oldurls; *s != NULL; s++)
  325.                         lwc_string_unref(*s);
  326.  
  327.                 if (oldurls != urls)
  328.                         style->alloc(oldurls, 0, style->pw);
  329.         }
  330.  
  331.         return CSS_OK;
  332. }
  333. #undef CURSOR_MASK
  334. #undef CURSOR_SHIFT
  335. #undef CURSOR_INDEX
  336.  
  337. #define CLIP_INDEX 7
  338. #define CLIP_SHIFT 2
  339. #define CLIP_MASK  0xfc
  340. #define CLIP_INDEX1 5
  341. #define CLIP_SHIFT1 0
  342. #define CLIP_MASK1 0xff
  343. #define CLIP_INDEX2 6
  344. #define CLIP_SHIFT2 0
  345. #define CLIP_MASK2 0xff
  346. static inline css_error set_clip(
  347.                 css_computed_style *style, uint8_t type,
  348.                 css_computed_clip_rect *rect)
  349. {
  350.         uint8_t *bits;
  351.  
  352.         ENSURE_UNCOMMON;
  353.  
  354.         bits = &style->uncommon->bits[CLIP_INDEX];
  355.  
  356.         /* 6bits: trblyy : top | right | bottom | left | type */
  357.         *bits = (*bits & ~CLIP_MASK) |
  358.                         ((type & 0x3) << CLIP_SHIFT);
  359.  
  360.         if (type == CSS_CLIP_RECT) {
  361.                 *bits |= (((rect->top_auto ? 0x20 : 0) |
  362.                                 (rect->right_auto ? 0x10 : 0) |
  363.                                 (rect->bottom_auto ? 0x8 : 0) |
  364.                                 (rect->left_auto ? 0x4 : 0)) << CLIP_SHIFT);
  365.  
  366.                 bits = &style->uncommon->bits[CLIP_INDEX1];
  367.  
  368.                 /* 8bits: ttttrrrr : top | right */
  369.                 *bits = (*bits & ~CLIP_MASK1) |
  370.                         (((rect->tunit << 4) | rect->runit) << CLIP_SHIFT1);
  371.  
  372.                 bits = &style->uncommon->bits[CLIP_INDEX2];
  373.  
  374.                 /* 8bits: bbbbllll : bottom | left */
  375.                 *bits = (*bits & ~CLIP_MASK2) |
  376.                         (((rect->bunit << 4) | rect->lunit) << CLIP_SHIFT2);
  377.  
  378.                 style->uncommon->clip[0] = rect->top;
  379.                 style->uncommon->clip[1] = rect->right;
  380.                 style->uncommon->clip[2] = rect->bottom;
  381.                 style->uncommon->clip[3] = rect->left;
  382.         }
  383.  
  384.         return CSS_OK;
  385. }
  386. #undef CLIP_MASK2
  387. #undef CLIP_SHIFT2
  388. #undef CLIP_INDEX2
  389. #undef CLIP_MASK1
  390. #undef CLIP_SHIFT1
  391. #undef CLIP_INDEX1
  392. #undef CLIP_MASK
  393. #undef CLIP_SHIFT
  394. #undef CLIP_INDEX
  395.  
  396. #define CONTENT_INDEX 7
  397. #define CONTENT_SHIFT 0
  398. #define CONTENT_MASK  0x3
  399. static inline css_error set_content(
  400.                 css_computed_style *style, uint8_t type,
  401.                 css_computed_content_item *content)
  402. {
  403.         uint8_t *bits;
  404.         css_computed_content_item *oldcontent;
  405.         css_computed_content_item *c;
  406.  
  407.         ENSURE_UNCOMMON;
  408.  
  409.         /* 2bits: type */
  410.         bits = &style->uncommon->bits[CONTENT_INDEX];
  411.         oldcontent = style->uncommon->content;
  412.  
  413.         *bits = (*bits & ~CONTENT_MASK) |
  414.                         ((type & 0x3) << CONTENT_SHIFT);
  415.  
  416.         for (c = content; c != NULL &&
  417.                         c->type != CSS_COMPUTED_CONTENT_NONE; c++) {
  418.                 switch (c->type) {
  419.                 case CSS_COMPUTED_CONTENT_STRING:
  420.                         c->data.string = lwc_string_ref(c->data.string);
  421.                         break;
  422.                 case CSS_COMPUTED_CONTENT_URI:
  423.                         c->data.uri = lwc_string_ref(c->data.uri);
  424.                         break;
  425.                 case CSS_COMPUTED_CONTENT_ATTR:
  426.                         c->data.attr = lwc_string_ref(c->data.attr);
  427.                         break;
  428.                 case CSS_COMPUTED_CONTENT_COUNTER:
  429.                         c->data.counter.name =
  430.                                 lwc_string_ref(c->data.counter.name);
  431.                         break;
  432.                 case CSS_COMPUTED_CONTENT_COUNTERS:
  433.                         c->data.counters.name =
  434.                                 lwc_string_ref(c->data.counters.name);
  435.                         c->data.counters.sep =
  436.                                 lwc_string_ref(c->data.counters.sep);
  437.                         break;
  438.                 default:
  439.                         break;
  440.                 }
  441.         }
  442.  
  443.         style->uncommon->content = content;
  444.  
  445.         /* Free existing array */
  446.         if (oldcontent != NULL) {
  447.                 for (c = oldcontent;
  448.                                 c->type != CSS_COMPUTED_CONTENT_NONE; c++) {
  449.                         switch (c->type) {
  450.                         case CSS_COMPUTED_CONTENT_STRING:
  451.                                 lwc_string_unref(c->data.string);
  452.                                 break;
  453.                         case CSS_COMPUTED_CONTENT_URI:
  454.                                 lwc_string_unref(c->data.uri);
  455.                                 break;
  456.                         case CSS_COMPUTED_CONTENT_ATTR:
  457.                                 lwc_string_unref(c->data.attr);
  458.                                 break;
  459.                         case CSS_COMPUTED_CONTENT_COUNTER:
  460.                                 lwc_string_unref(c->data.counter.name);
  461.                                 break;
  462.                         case CSS_COMPUTED_CONTENT_COUNTERS:
  463.                                 lwc_string_unref(c->data.counters.name);
  464.                                 lwc_string_unref(c->data.counters.sep);
  465.                                 break;
  466.                         default:
  467.                                 break;
  468.                         }
  469.                 }
  470.  
  471.                 if (oldcontent != content)
  472.                         style->alloc(oldcontent, 0, style->pw);
  473.         }
  474.  
  475.         return CSS_OK;
  476. }
  477. #undef CONTENT_MASK
  478. #undef CONTENT_SHIFT
  479. #undef CONTENT_INDEX
  480.  
  481.  
  482. #define VERTICAL_ALIGN_INDEX 0
  483. #define VERTICAL_ALIGN_SHIFT 0
  484. #define VERTICAL_ALIGN_MASK  0xff
  485. static inline css_error set_vertical_align(
  486.                 css_computed_style *style, uint8_t type,
  487.                 css_fixed length, css_unit unit)
  488. {
  489.         uint8_t *bits = &style->bits[VERTICAL_ALIGN_INDEX];
  490.  
  491.         /* 8bits: uuuutttt : units | type */
  492.         *bits = (*bits & ~VERTICAL_ALIGN_MASK) |
  493.                         (((type & 0xf) | (unit << 4)) << VERTICAL_ALIGN_SHIFT);
  494.  
  495.         style->vertical_align = length;
  496.  
  497.         return CSS_OK;
  498. }
  499. #undef VERTICAL_ALIGN_MASK
  500. #undef VERTICAL_ALIGN_SHIFT
  501. #undef VERTICAL_ALIGN_INDEX
  502.  
  503. #define FONT_SIZE_INDEX 1
  504. #define FONT_SIZE_SHIFT 0
  505. #define FONT_SIZE_MASK  0xff
  506. static inline css_error set_font_size(
  507.                 css_computed_style *style, uint8_t type,
  508.                 css_fixed length, css_unit unit)
  509. {
  510.         uint8_t *bits = &style->bits[FONT_SIZE_INDEX];
  511.  
  512.         /* 8bits: uuuutttt : units | type */
  513.         *bits = (*bits & ~FONT_SIZE_MASK) |
  514.                         (((type & 0xf) | (unit << 4)) << FONT_SIZE_SHIFT);
  515.  
  516.         style->font_size = length;
  517.  
  518.         return CSS_OK;
  519. }
  520. #undef FONT_SIZE_MASK
  521. #undef FONT_SIZE_SHIFT
  522. #undef FONT_SIZE_INDEX
  523.  
  524. #define BORDER_TOP_WIDTH_INDEX 2
  525. #define BORDER_TOP_WIDTH_SHIFT 1
  526. #define BORDER_TOP_WIDTH_MASK  0xfe
  527. static inline css_error set_border_top_width(
  528.                 css_computed_style *style, uint8_t type,
  529.                 css_fixed length, css_unit unit)
  530. {
  531.         uint8_t *bits = &style->bits[BORDER_TOP_WIDTH_INDEX];
  532.  
  533.         /* 7bits: uuuuttt : units | type */
  534.         *bits = (*bits & ~BORDER_TOP_WIDTH_MASK) |
  535.                 (((type & 0x7) | (unit << 3)) << BORDER_TOP_WIDTH_SHIFT);
  536.  
  537.         style->border_width[0] = length;
  538.  
  539.         return CSS_OK;
  540. }
  541. #undef BORDER_TOP_WIDTH_MASK
  542. #undef BORDER_TOP_WIDTH_SHIFT
  543. #undef BORDER_TOP_WIDTH_INDEX
  544.  
  545. #define BORDER_RIGHT_WIDTH_INDEX 3
  546. #define BORDER_RIGHT_WIDTH_SHIFT 1
  547. #define BORDER_RIGHT_WIDTH_MASK  0xfe
  548. static inline css_error set_border_right_width(
  549.                 css_computed_style *style, uint8_t type,
  550.                 css_fixed length, css_unit unit)
  551. {
  552.         uint8_t *bits = &style->bits[BORDER_RIGHT_WIDTH_INDEX];
  553.  
  554.         /* 7bits: uuuuttt : units | type */
  555.         *bits = (*bits & ~BORDER_RIGHT_WIDTH_MASK) |
  556.                 (((type & 0x7) | (unit << 3)) << BORDER_RIGHT_WIDTH_SHIFT);
  557.  
  558.         style->border_width[1] = length;
  559.  
  560.         return CSS_OK;
  561. }
  562. #undef BORDER_RIGHT_WIDTH_MASK
  563. #undef BORDER_RIGHT_WIDTH_SHIFT
  564. #undef BORDER_RIGHT_WIDTH_INDEX
  565.  
  566. #define BORDER_BOTTOM_WIDTH_INDEX 4
  567. #define BORDER_BOTTOM_WIDTH_SHIFT 1
  568. #define BORDER_BOTTOM_WIDTH_MASK  0xfe
  569. static inline css_error set_border_bottom_width(
  570.                 css_computed_style *style, uint8_t type,
  571.                 css_fixed length, css_unit unit)
  572. {
  573.         uint8_t *bits = &style->bits[BORDER_BOTTOM_WIDTH_INDEX];
  574.  
  575.         /* 7bits: uuuuttt : units | type */
  576.         *bits = (*bits & ~BORDER_BOTTOM_WIDTH_MASK) |
  577.                 (((type & 0x7) | (unit << 3)) << BORDER_BOTTOM_WIDTH_SHIFT);
  578.  
  579.         style->border_width[2] = length;
  580.  
  581.         return CSS_OK;
  582. }
  583. #undef BORDER_BOTTOM_WIDTH_MASK
  584. #undef BORDER_BOTTOM_WIDTH_SHIFT
  585. #undef BORDER_BOTTOM_WIDTH_INDEX
  586.  
  587. #define BORDER_LEFT_WIDTH_INDEX 5
  588. #define BORDER_LEFT_WIDTH_SHIFT 1
  589. #define BORDER_LEFT_WIDTH_MASK  0xfe
  590. static inline css_error set_border_left_width(
  591.                 css_computed_style *style, uint8_t type,
  592.                 css_fixed length, css_unit unit)
  593. {
  594.         uint8_t *bits = &style->bits[BORDER_LEFT_WIDTH_INDEX];
  595.  
  596.         /* 7bits: uuuuttt : units | type */
  597.         *bits = (*bits & ~BORDER_LEFT_WIDTH_MASK) |
  598.                 (((type & 0x7) | (unit << 3)) << BORDER_LEFT_WIDTH_SHIFT);
  599.  
  600.         style->border_width[3] = length;
  601.  
  602.         return CSS_OK;
  603. }
  604. #undef BORDER_LEFT_WIDTH_MASK
  605. #undef BORDER_LEFT_WIDTH_SHIFT
  606. #undef BORDER_LEFT_WIDTH_INDEX
  607.  
  608. #define BACKGROUND_IMAGE_INDEX 2
  609. #define BACKGROUND_IMAGE_SHIFT 0
  610. #define BACKGROUND_IMAGE_MASK  0x1
  611. static inline css_error set_background_image(
  612.                 css_computed_style *style, uint8_t type,
  613.                 lwc_string *url)
  614. {
  615.         uint8_t *bits = &style->bits[BACKGROUND_IMAGE_INDEX];
  616.         lwc_string *oldurl = style->background_image;
  617.  
  618.         /* 1bit: type */
  619.         *bits = (*bits & ~BACKGROUND_IMAGE_MASK) |
  620.                         ((type & 0x1) << BACKGROUND_IMAGE_SHIFT);
  621.  
  622.         if (url != NULL) {
  623.                 style->background_image = lwc_string_ref(url);
  624.         } else {
  625.                 style->background_image = NULL;
  626.         }
  627.  
  628.         if (oldurl != NULL)
  629.                 lwc_string_unref(oldurl);
  630.  
  631.         return CSS_OK;
  632. }
  633. #undef BACKGROUND_IMAGE_MASK
  634. #undef BACKGROUND_IMAGE_SHIFT
  635. #undef BACKGROUND_IMAGE_INDEX
  636.  
  637. #define COLOR_INDEX 3
  638. #define COLOR_SHIFT 0
  639. #define COLOR_MASK  0x1
  640. static inline css_error set_color(
  641.                 css_computed_style *style, uint8_t type,
  642.                 css_color color)
  643. {
  644.         uint8_t *bits = &style->bits[COLOR_INDEX];
  645.  
  646.         /* 1bit: type */
  647.         *bits = (*bits & ~COLOR_MASK) |
  648.                         ((type & 0x1) << COLOR_SHIFT);
  649.  
  650.         style->color = color;
  651.  
  652.         return CSS_OK;
  653. }
  654. #undef COLOR_MASK
  655. #undef COLOR_SHIFT
  656. #undef COLOR_INDEX
  657.  
  658. #define LIST_STYLE_IMAGE_INDEX 4
  659. #define LIST_STYLE_IMAGE_SHIFT 0
  660. #define LIST_STYLE_IMAGE_MASK  0x1
  661. static inline css_error set_list_style_image(
  662.                 css_computed_style *style, uint8_t type,
  663.                 lwc_string *url)
  664. {
  665.         uint8_t *bits = &style->bits[LIST_STYLE_IMAGE_INDEX];
  666.         lwc_string *oldurl = style->list_style_image;
  667.  
  668.         /* 1bit: type */
  669.         *bits = (*bits & ~LIST_STYLE_IMAGE_MASK) |
  670.                         ((type & 0x1) << LIST_STYLE_IMAGE_SHIFT);
  671.  
  672.         if (url != NULL) {
  673.                 style->list_style_image = lwc_string_ref(url);
  674.         } else {
  675.                 style->list_style_image = NULL;
  676.         }
  677.  
  678.         if (oldurl != NULL)
  679.                 lwc_string_unref(oldurl);
  680.  
  681.         return CSS_OK;
  682. }
  683. #undef LIST_STYLE_IMAGE_MASK
  684. #undef LIST_STYLE_IMAGE_SHIFT
  685. #undef LIST_STYLE_IMAGE_INDEX
  686.  
  687. #define QUOTES_INDEX 5
  688. #define QUOTES_SHIFT 0
  689. #define QUOTES_MASK  0x1
  690. static inline css_error set_quotes(
  691.                 css_computed_style *style, uint8_t type,
  692.                 lwc_string **quotes)
  693. {
  694.         uint8_t *bits = &style->bits[QUOTES_INDEX];
  695.         lwc_string **oldquotes = style->quotes;
  696.         lwc_string **s;
  697.  
  698.         /* 1bit: type */
  699.         *bits = (*bits & ~QUOTES_MASK) |
  700.                         ((type & 0x1) << QUOTES_SHIFT);
  701.  
  702.         for (s = quotes; s != NULL && *s != NULL; s++)
  703.                 *s = lwc_string_ref(*s);
  704.  
  705.         style->quotes = quotes;
  706.  
  707.         /* Free current quotes */
  708.         if (oldquotes != NULL) {
  709.                 for (s = oldquotes; *s != NULL; s++)
  710.                         lwc_string_unref(*s);
  711.  
  712.                 if (oldquotes != quotes)
  713.                         style->alloc(oldquotes, 0, style->pw);
  714.         }
  715.  
  716.         return CSS_OK;
  717. }
  718. #undef QUOTES_MASK
  719. #undef QUOTES_SHIFT
  720. #undef QUOTES_INDEX
  721.  
  722. #define TOP_INDEX 6
  723. #define TOP_SHIFT 2
  724. #define TOP_MASK  0xfc
  725. static inline css_error set_top(
  726.                 css_computed_style *style, uint8_t type,
  727.                 css_fixed length, css_unit unit)
  728. {
  729.         uint8_t *bits = &style->bits[TOP_INDEX];
  730.  
  731.         /* 6bits: uuuutt : units | type */
  732.         *bits = (*bits & ~TOP_MASK) |
  733.                         (((type & 0x3) | (unit << 2)) << TOP_SHIFT);
  734.  
  735.         style->top = length;
  736.  
  737.         return CSS_OK;
  738. }
  739. #undef TOP_MASK
  740. #undef TOP_SHIFT
  741. #undef TOP_INDEX
  742.  
  743. #define RIGHT_INDEX 7
  744. #define RIGHT_SHIFT 2
  745. #define RIGHT_MASK  0xfc
  746. static inline css_error set_right(
  747.                 css_computed_style *style, uint8_t type,
  748.                 css_fixed length, css_unit unit)
  749. {
  750.         uint8_t *bits = &style->bits[RIGHT_INDEX];
  751.  
  752.         /* 6bits: uuuutt : units | type */
  753.         *bits = (*bits & ~RIGHT_MASK) |
  754.                         (((type & 0x3) | (unit << 2)) << RIGHT_SHIFT);
  755.  
  756.         style->right = length;
  757.  
  758.         return CSS_OK;
  759. }
  760. #undef RIGHT_MASK
  761. #undef RIGHT_SHIFT
  762. #undef RIGHT_INDEX
  763.  
  764. #define BOTTOM_INDEX 8
  765. #define BOTTOM_SHIFT 2
  766. #define BOTTOM_MASK  0xfc
  767. static inline css_error set_bottom(
  768.                 css_computed_style *style, uint8_t type,
  769.                 css_fixed length, css_unit unit)
  770. {
  771.         uint8_t *bits = &style->bits[BOTTOM_INDEX];
  772.  
  773.         /* 6bits: uuuutt : units | type */
  774.         *bits = (*bits & ~BOTTOM_MASK) |
  775.                         (((type & 0x3) | (unit << 2)) << BOTTOM_SHIFT);
  776.  
  777.         style->bottom = length;
  778.  
  779.         return CSS_OK;
  780. }
  781. #undef BOTTOM_MASK
  782. #undef BOTTOM_SHIFT
  783. #undef BOTTOM_INDEX
  784.  
  785. #define LEFT_INDEX 9
  786. #define LEFT_SHIFT 2
  787. #define LEFT_MASK  0xfc
  788. static inline css_error set_left(
  789.                 css_computed_style *style, uint8_t type,
  790.                 css_fixed length, css_unit unit)
  791. {
  792.         uint8_t *bits = &style->bits[LEFT_INDEX];
  793.  
  794.         /* 6bits: uuuutt : units | type */
  795.         *bits = (*bits & ~LEFT_MASK) |
  796.                         (((type & 0x3) | (unit << 2)) << LEFT_SHIFT);
  797.  
  798.         style->left = length;
  799.  
  800.         return CSS_OK;
  801. }
  802. #undef LEFT_MASK
  803. #undef LEFT_SHIFT
  804. #undef LEFT_INDEX
  805.  
  806. #define BORDER_TOP_COLOR_INDEX 6
  807. #define BORDER_TOP_COLOR_SHIFT 0
  808. #define BORDER_TOP_COLOR_MASK  0x3
  809. static inline css_error set_border_top_color(
  810.                 css_computed_style *style, uint8_t type,
  811.                 css_color color)
  812. {
  813.         uint8_t *bits = &style->bits[BORDER_TOP_COLOR_INDEX];
  814.  
  815.         /* 2bits: type */
  816.         *bits = (*bits & ~BORDER_TOP_COLOR_MASK) |
  817.                         ((type & 0x3) << BORDER_TOP_COLOR_SHIFT);
  818.  
  819.         style->border_color[0] = color;
  820.  
  821.         return CSS_OK;
  822. }
  823. #undef BORDER_TOP_COLOR_MASK
  824. #undef BORDER_TOP_COLOR_SHIFT
  825. #undef BORDER_TOP_COLOR_INDEX
  826.  
  827. #define BORDER_RIGHT_COLOR_INDEX 7
  828. #define BORDER_RIGHT_COLOR_SHIFT 0
  829. #define BORDER_RIGHT_COLOR_MASK  0x3
  830. static inline css_error set_border_right_color(
  831.                 css_computed_style *style, uint8_t type,
  832.                 css_color color)
  833. {
  834.         uint8_t *bits = &style->bits[BORDER_RIGHT_COLOR_INDEX];
  835.  
  836.         /* 2bits: type */
  837.         *bits = (*bits & ~BORDER_RIGHT_COLOR_MASK) |
  838.                         ((type & 0x3) << BORDER_RIGHT_COLOR_SHIFT);
  839.  
  840.         style->border_color[1] = color;
  841.  
  842.         return CSS_OK;
  843. }
  844. #undef BORDER_RIGHT_COLOR_MASK
  845. #undef BORDER_RIGHT_COLOR_SHIFT
  846. #undef BORDER_RIGHT_COLOR_INDEX
  847.  
  848. #define BORDER_BOTTOM_COLOR_INDEX 8
  849. #define BORDER_BOTTOM_COLOR_SHIFT 0
  850. #define BORDER_BOTTOM_COLOR_MASK  0x3
  851. static inline css_error set_border_bottom_color(
  852.                 css_computed_style *style, uint8_t type,
  853.                 css_color color)
  854. {
  855.         uint8_t *bits = &style->bits[BORDER_BOTTOM_COLOR_INDEX];
  856.  
  857.         /* 2bits: type */
  858.         *bits = (*bits & ~BORDER_BOTTOM_COLOR_MASK) |
  859.                         ((type & 0x3) << BORDER_BOTTOM_COLOR_SHIFT);
  860.  
  861.         style->border_color[2] = color;
  862.  
  863.         return CSS_OK;
  864. }
  865. #undef BORDER_BOTTOM_COLOR_MASK
  866. #undef BORDER_BOTTOM_COLOR_SHIFT
  867. #undef BORDER_BOTTOM_COLOR_INDEX
  868.  
  869. #define BORDER_LEFT_COLOR_INDEX 9
  870. #define BORDER_LEFT_COLOR_SHIFT 0
  871. #define BORDER_LEFT_COLOR_MASK  0x3
  872. static inline css_error set_border_left_color(
  873.                 css_computed_style *style, uint8_t type,
  874.                 css_color color)
  875. {
  876.         uint8_t *bits = &style->bits[BORDER_LEFT_COLOR_INDEX];
  877.  
  878.         /* 2bits: type */
  879.         *bits = (*bits & ~BORDER_LEFT_COLOR_MASK) |
  880.                         ((type & 0x3) << BORDER_LEFT_COLOR_SHIFT);
  881.  
  882.         style->border_color[3] = color;
  883.  
  884.         return CSS_OK;
  885. }
  886. #undef BORDER_LEFT_COLOR_MASK
  887. #undef BORDER_LEFT_COLOR_SHIFT
  888. #undef BORDER_LEFT_COLOR_INDEX
  889.  
  890. #define HEIGHT_INDEX 10
  891. #define HEIGHT_SHIFT 2
  892. #define HEIGHT_MASK  0xfc
  893. static inline css_error set_height(
  894.                 css_computed_style *style, uint8_t type,
  895.                 css_fixed length, css_unit unit)
  896. {
  897.         uint8_t *bits = &style->bits[HEIGHT_INDEX];
  898.  
  899.         /* 6bits: uuuutt : units | type */
  900.         *bits = (*bits & ~HEIGHT_MASK) |
  901.                         (((type & 0x3) | (unit << 2)) << HEIGHT_SHIFT);
  902.  
  903.         style->height = length;
  904.  
  905.         return CSS_OK;
  906. }
  907. #undef HEIGHT_MASK
  908. #undef HEIGHT_SHIFT
  909. #undef HEIGHT_INDEX
  910.  
  911. #define LINE_HEIGHT_INDEX 11
  912. #define LINE_HEIGHT_SHIFT 2
  913. #define LINE_HEIGHT_MASK  0xfc
  914. static inline css_error set_line_height(
  915.                 css_computed_style *style, uint8_t type,
  916.                 css_fixed length, css_unit unit)
  917. {
  918.         uint8_t *bits = &style->bits[LINE_HEIGHT_INDEX];
  919.  
  920.         /* 6bits: uuuutt : units | type */
  921.         *bits = (*bits & ~LINE_HEIGHT_MASK) |
  922.                         (((type & 0x3) | (unit << 2)) << LINE_HEIGHT_SHIFT);
  923.  
  924.         style->line_height = length;
  925.  
  926.         return CSS_OK;
  927. }
  928. #undef LINE_HEIGHT_MASK
  929. #undef LINE_HEIGHT_SHIFT
  930. #undef LINE_HEIGHT_INDEX
  931.  
  932. #define BACKGROUND_COLOR_INDEX 10
  933. #define BACKGROUND_COLOR_SHIFT 0
  934. #define BACKGROUND_COLOR_MASK  0x3
  935. static inline css_error set_background_color(
  936.                 css_computed_style *style, uint8_t type,
  937.                 css_color color)
  938. {
  939.         uint8_t *bits = &style->bits[BACKGROUND_COLOR_INDEX];
  940.  
  941.         /* 2bits: type */
  942.         *bits = (*bits & ~BACKGROUND_COLOR_MASK) |
  943.                         ((type & 0x3) << BACKGROUND_COLOR_SHIFT);
  944.  
  945.         style->background_color = color;
  946.  
  947.         return CSS_OK;
  948. }
  949. #undef BACKGROUND_COLOR_MASK
  950. #undef BACKGROUND_COLOR_SHIFT
  951. #undef BACKGROUND_COLOR_INDEX
  952.  
  953. #define Z_INDEX_INDEX 11
  954. #define Z_INDEX_SHIFT 0
  955. #define Z_INDEX_MASK  0x3
  956. static inline css_error set_z_index(
  957.                 css_computed_style *style, uint8_t type,
  958.                 int32_t z_index)
  959. {
  960.         uint8_t *bits = &style->bits[Z_INDEX_INDEX];
  961.  
  962.         /* 2bits: type */
  963.         *bits = (*bits & ~Z_INDEX_MASK) |
  964.                         ((type & 0x3) << Z_INDEX_SHIFT);
  965.  
  966.         style->z_index = z_index;
  967.  
  968.         return CSS_OK;
  969. }
  970. #undef Z_INDEX_MASK
  971. #undef Z_INDEX_SHIFT
  972. #undef Z_INDEX_INDEX
  973.  
  974. #define MARGIN_TOP_INDEX 12
  975. #define MARGIN_TOP_SHIFT 2
  976. #define MARGIN_TOP_MASK  0xfc
  977. static inline css_error set_margin_top(
  978.                 css_computed_style *style, uint8_t type,
  979.                 css_fixed length, css_unit unit)
  980. {
  981.         uint8_t *bits = &style->bits[MARGIN_TOP_INDEX];
  982.  
  983.         /* 6bits: uuuutt : units | type */
  984.         *bits = (*bits & ~MARGIN_TOP_MASK) |
  985.                         (((type & 0x3) | (unit << 2)) << MARGIN_TOP_SHIFT);
  986.  
  987.         style->margin[0] = length;
  988.  
  989.         return CSS_OK;
  990. }
  991. #undef MARGIN_TOP_MASK
  992. #undef MARGIN_TOP_SHIFT
  993. #undef MARGIN_TOP_INDEX
  994.  
  995. #define MARGIN_RIGHT_INDEX 13
  996. #define MARGIN_RIGHT_SHIFT 2
  997. #define MARGIN_RIGHT_MASK  0xfc
  998. static inline css_error set_margin_right(
  999.                 css_computed_style *style, uint8_t type,
  1000.                 css_fixed length, css_unit unit)
  1001. {
  1002.         uint8_t *bits = &style->bits[MARGIN_RIGHT_INDEX];
  1003.  
  1004.         /* 6bits: uuuutt : units | type */
  1005.         *bits = (*bits & ~MARGIN_RIGHT_MASK) |
  1006.                         (((type & 0x3) | (unit << 2)) << MARGIN_RIGHT_SHIFT);
  1007.  
  1008.         style->margin[1] = length;
  1009.  
  1010.         return CSS_OK;
  1011. }
  1012. #undef MARGIN_RIGHT_MASK
  1013. #undef MARGIN_RIGHT_SHIFT
  1014. #undef MARGIN_RIGHT_INDEX
  1015.  
  1016. #define MARGIN_BOTTOM_INDEX 14
  1017. #define MARGIN_BOTTOM_SHIFT 2
  1018. #define MARGIN_BOTTOM_MASK  0xfc
  1019. static inline css_error set_margin_bottom(
  1020.                 css_computed_style *style, uint8_t type,
  1021.                 css_fixed length, css_unit unit)
  1022. {
  1023.         uint8_t *bits = &style->bits[MARGIN_BOTTOM_INDEX];
  1024.  
  1025.         /* 6bits: uuuutt : units | type */
  1026.         *bits = (*bits & ~MARGIN_BOTTOM_MASK) |
  1027.                         (((type & 0x3) | (unit << 2)) << MARGIN_BOTTOM_SHIFT);
  1028.  
  1029.         style->margin[2] = length;
  1030.  
  1031.         return CSS_OK;
  1032. }
  1033. #undef MARGIN_BOTTOM_MASK
  1034. #undef MARGIN_BOTTOM_SHIFT
  1035. #undef MARGIN_BOTTOM_INDEX
  1036.  
  1037. #define MARGIN_LEFT_INDEX 15
  1038. #define MARGIN_LEFT_SHIFT 2
  1039. #define MARGIN_LEFT_MASK  0xfc
  1040. static inline css_error set_margin_left(
  1041.                 css_computed_style *style, uint8_t type,
  1042.                 css_fixed length, css_unit unit)
  1043. {
  1044.         uint8_t *bits = &style->bits[MARGIN_LEFT_INDEX];
  1045.  
  1046.         /* 6bits: uuuutt : units | type */
  1047.         *bits = (*bits & ~MARGIN_LEFT_MASK) |
  1048.                         (((type & 0x3) | (unit << 2)) << MARGIN_LEFT_SHIFT);
  1049.  
  1050.         style->margin[3] = length;
  1051.  
  1052.         return CSS_OK;
  1053. }
  1054. #undef MARGIN_LEFT_MASK
  1055. #undef MARGIN_LEFT_SHIFT
  1056. #undef MARGIN_LEFT_INDEX
  1057.  
  1058. #define BACKGROUND_ATTACHMENT_INDEX 12
  1059. #define BACKGROUND_ATTACHMENT_SHIFT 0
  1060. #define BACKGROUND_ATTACHMENT_MASK  0x3
  1061. static inline css_error set_background_attachment(
  1062.                 css_computed_style *style, uint8_t type)
  1063. {
  1064.         uint8_t *bits = &style->bits[BACKGROUND_ATTACHMENT_INDEX];
  1065.  
  1066.         /* 2bits: type */
  1067.         *bits = (*bits & ~BACKGROUND_ATTACHMENT_MASK) |
  1068.                         ((type & 0x3) << BACKGROUND_ATTACHMENT_SHIFT);
  1069.  
  1070.         return CSS_OK;
  1071. }
  1072. #undef BACKGROUND_ATTACHMENT_MASK
  1073. #undef BACKGROUND_ATTACHMENT_SHIFT
  1074. #undef BACKGROUND_ATTACHMENT_INDEX
  1075.  
  1076. #define BORDER_COLLAPSE_INDEX 13
  1077. #define BORDER_COLLAPSE_SHIFT 0
  1078. #define BORDER_COLLAPSE_MASK  0x3
  1079. static inline css_error set_border_collapse(
  1080.                 css_computed_style *style, uint8_t type)
  1081. {
  1082.         uint8_t *bits = &style->bits[BORDER_COLLAPSE_INDEX];
  1083.  
  1084.         /* 2bits: type */
  1085.         *bits = (*bits & ~BORDER_COLLAPSE_MASK) |
  1086.                         ((type & 0x3) << BORDER_COLLAPSE_SHIFT);
  1087.  
  1088.         return CSS_OK;
  1089. }
  1090. #undef BORDER_COLLAPSE_MASK
  1091. #undef BORDER_COLLAPSE_SHIFT
  1092. #undef BORDER_COLLAPSE_INDEX
  1093.  
  1094. #define CAPTION_SIDE_INDEX 14
  1095. #define CAPTION_SIDE_SHIFT 0
  1096. #define CAPTION_SIDE_MASK  0x3
  1097. static inline css_error set_caption_side(
  1098.                 css_computed_style *style, uint8_t type)
  1099. {
  1100.         uint8_t *bits = &style->bits[CAPTION_SIDE_INDEX];
  1101.  
  1102.         /* 2bits: type */
  1103.         *bits = (*bits & ~CAPTION_SIDE_MASK) |
  1104.                         ((type & 0x3) << CAPTION_SIDE_SHIFT);
  1105.  
  1106.         return CSS_OK;
  1107. }
  1108. #undef CAPTION_SIDE_MASK
  1109. #undef CAPTION_SIDE_SHIFT
  1110. #undef CAPTION_SIDE_INDEX
  1111.  
  1112. #define DIRECTION_INDEX 15
  1113. #define DIRECTION_SHIFT 0
  1114. #define DIRECTION_MASK  0x3
  1115. static inline css_error set_direction(
  1116.                 css_computed_style *style, uint8_t type)
  1117. {
  1118.         uint8_t *bits = &style->bits[DIRECTION_INDEX];
  1119.  
  1120.         /* 2bits: type */
  1121.         *bits = (*bits & ~DIRECTION_MASK) |
  1122.                         ((type & 0x3) << DIRECTION_SHIFT);
  1123.  
  1124.         return CSS_OK;
  1125. }
  1126. #undef DIRECTION_MASK
  1127. #undef DIRECTION_SHIFT
  1128. #undef DIRECTION_INDEX
  1129.  
  1130. #define MAX_HEIGHT_INDEX 16
  1131. #define MAX_HEIGHT_SHIFT 2
  1132. #define MAX_HEIGHT_MASK  0xfc
  1133. static inline css_error set_max_height(
  1134.                 css_computed_style *style, uint8_t type,
  1135.                 css_fixed length, css_unit unit)
  1136. {
  1137.         uint8_t *bits = &style->bits[MAX_HEIGHT_INDEX];
  1138.  
  1139.         /* 6bits: uuuutt : units | type */
  1140.         *bits = (*bits & ~MAX_HEIGHT_MASK) |
  1141.                         (((type & 0x3) | (unit << 2)) << MAX_HEIGHT_SHIFT);
  1142.  
  1143.         style->max_height = length;
  1144.  
  1145.         return CSS_OK;
  1146. }
  1147. #undef MAX_HEIGHT_MASK
  1148. #undef MAX_HEIGHT_SHIFT
  1149. #undef MAX_HEIGHT_INDEX
  1150.  
  1151. #define MAX_WIDTH_INDEX 17
  1152. #define MAX_WIDTH_SHIFT 2
  1153. #define MAX_WIDTH_MASK  0xfc
  1154. static inline css_error set_max_width(
  1155.                 css_computed_style *style, uint8_t type,
  1156.                 css_fixed length, css_unit unit)
  1157. {
  1158.         uint8_t *bits = &style->bits[MAX_WIDTH_INDEX];
  1159.  
  1160.         /* 6bits: uuuutt : units | type */
  1161.         *bits = (*bits & ~MAX_WIDTH_MASK) |
  1162.                         (((type & 0x3) | (unit << 2)) << MAX_WIDTH_SHIFT);
  1163.  
  1164.         style->max_width = length;
  1165.  
  1166.         return CSS_OK;
  1167. }
  1168. #undef MAX_WIDTH_MASK
  1169. #undef MAX_WIDTH_SHIFT
  1170. #undef MAX_WIDTH_INDEX
  1171.  
  1172. #define WIDTH_INDEX 18
  1173. #define WIDTH_SHIFT 2
  1174. #define WIDTH_MASK  0xfc
  1175. static inline css_error set_width(
  1176.                 css_computed_style *style, uint8_t type,
  1177.                 css_fixed length, css_unit unit)
  1178. {
  1179.         uint8_t *bits = &style->bits[WIDTH_INDEX];
  1180.  
  1181.         /* 6bits: uuuutt : units | type */
  1182.         *bits = (*bits & ~WIDTH_MASK) |
  1183.                         (((type & 0x3) | (unit << 2)) << WIDTH_SHIFT);
  1184.  
  1185.         style->width = length;
  1186.  
  1187.         return CSS_OK;
  1188. }
  1189. #undef WIDTH_MASK
  1190. #undef WIDTH_SHIFT
  1191. #undef WIDTH_INDEX
  1192.  
  1193. #define EMPTY_CELLS_INDEX 16
  1194. #define EMPTY_CELLS_SHIFT 0
  1195. #define EMPTY_CELLS_MASK  0x3
  1196. static inline css_error set_empty_cells(
  1197.                 css_computed_style *style, uint8_t type)
  1198. {
  1199.         uint8_t *bits = &style->bits[EMPTY_CELLS_INDEX];
  1200.  
  1201.         /* 2bits: type */
  1202.         *bits = (*bits & ~EMPTY_CELLS_MASK) |
  1203.                         ((type & 0x3) << EMPTY_CELLS_SHIFT);
  1204.  
  1205.         return CSS_OK;
  1206. }
  1207. #undef EMPTY_CELLS_MASK
  1208. #undef EMPTY_CELLS_SHIFT
  1209. #undef EMPTY_CELLS_INDEX
  1210.  
  1211. #define FLOAT_INDEX 17
  1212. #define FLOAT_SHIFT 0
  1213. #define FLOAT_MASK  0x3
  1214. static inline css_error set_float(
  1215.                 css_computed_style *style, uint8_t type)
  1216. {
  1217.         uint8_t *bits = &style->bits[FLOAT_INDEX];
  1218.  
  1219.         /* 2bits: type */
  1220.         *bits = (*bits & ~FLOAT_MASK) |
  1221.                         ((type & 0x3) << FLOAT_SHIFT);
  1222.  
  1223.         return CSS_OK;
  1224. }
  1225. #undef FLOAT_MASK
  1226. #undef FLOAT_SHIFT
  1227. #undef FLOAT_INDEX
  1228.  
  1229. #define FONT_STYLE_INDEX 18
  1230. #define FONT_STYLE_SHIFT 0
  1231. #define FONT_STYLE_MASK  0x3
  1232. static inline css_error set_font_style(
  1233.                 css_computed_style *style, uint8_t type)
  1234. {
  1235.         uint8_t *bits = &style->bits[FONT_STYLE_INDEX];
  1236.  
  1237.         /* 2bits: type */
  1238.         *bits = (*bits & ~FONT_STYLE_MASK) |
  1239.                         ((type & 0x3) << FONT_STYLE_SHIFT);
  1240.  
  1241.         return CSS_OK;
  1242. }
  1243. #undef FONT_STYLE_MASK
  1244. #undef FONT_STYLE_SHIFT
  1245. #undef FONT_STYLE_INDEX
  1246.  
  1247. #define MIN_HEIGHT_INDEX 19
  1248. #define MIN_HEIGHT_SHIFT 3
  1249. #define MIN_HEIGHT_MASK  0xf8
  1250. static inline css_error set_min_height(
  1251.                 css_computed_style *style, uint8_t type,
  1252.                 css_fixed length, css_unit unit)
  1253. {
  1254.         uint8_t *bits = &style->bits[MIN_HEIGHT_INDEX];
  1255.  
  1256.         /* 5bits: uuuut : units | type */
  1257.         *bits = (*bits & ~MIN_HEIGHT_MASK) |
  1258.                         (((type & 0x1) | (unit << 1)) << MIN_HEIGHT_SHIFT);
  1259.  
  1260.         style->min_height = length;
  1261.  
  1262.         return CSS_OK;
  1263. }
  1264. #undef MIN_HEIGHT_MASK
  1265. #undef MIN_HEIGHT_SHIFT
  1266. #undef MIN_HEIGHT_INDEX
  1267.  
  1268. #define MIN_WIDTH_INDEX 20
  1269. #define MIN_WIDTH_SHIFT 3
  1270. #define MIN_WIDTH_MASK  0xf8
  1271. static inline css_error set_min_width(
  1272.                 css_computed_style *style, uint8_t type,
  1273.                 css_fixed length, css_unit unit)
  1274. {
  1275.         uint8_t *bits = &style->bits[MIN_WIDTH_INDEX];
  1276.  
  1277.         /* 5bits: uuuut : units | type */
  1278.         *bits = (*bits & ~MIN_WIDTH_MASK) |
  1279.                         (((type & 0x1) | (unit << 1)) << MIN_WIDTH_SHIFT);
  1280.  
  1281.         style->min_width = length;
  1282.  
  1283.         return CSS_OK;
  1284. }
  1285. #undef MIN_WIDTH_MASK
  1286. #undef MIN_WIDTH_SHIFT
  1287. #undef MIN_WIDTH_INDEX
  1288.  
  1289. #define BACKGROUND_REPEAT_INDEX 19
  1290. #define BACKGROUND_REPEAT_SHIFT 0
  1291. #define BACKGROUND_REPEAT_MASK  0x7
  1292. static inline css_error set_background_repeat(
  1293.                 css_computed_style *style, uint8_t type)
  1294. {
  1295.         uint8_t *bits = &style->bits[BACKGROUND_REPEAT_INDEX];
  1296.  
  1297.         /* 3bits: type */
  1298.         *bits = (*bits & ~BACKGROUND_REPEAT_MASK) |
  1299.                         ((type & 0x7) << BACKGROUND_REPEAT_SHIFT);
  1300.  
  1301.         return CSS_OK;
  1302. }
  1303. #undef BACKGROUND_REPEAT_MASK
  1304. #undef BACKGROUND_REPEAT_SHIFT
  1305. #undef BACKGROUND_REPEAT_INDEX
  1306.  
  1307. #define CLEAR_INDEX 20
  1308. #define CLEAR_SHIFT 0
  1309. #define CLEAR_MASK  0x7
  1310. static inline css_error set_clear(
  1311.                 css_computed_style *style, uint8_t type)
  1312. {
  1313.         uint8_t *bits = &style->bits[CLEAR_INDEX];
  1314.  
  1315.         /* 3bits: type */
  1316.         *bits = (*bits & ~CLEAR_MASK) |
  1317.                         ((type & 0x7) << CLEAR_SHIFT);
  1318.  
  1319.         return CSS_OK;
  1320. }
  1321. #undef CLEAR_MASK
  1322. #undef CLEAR_SHIFT
  1323. #undef CLEAR_INDEX
  1324.  
  1325. #define PADDING_TOP_INDEX 21
  1326. #define PADDING_TOP_SHIFT 3
  1327. #define PADDING_TOP_MASK  0xf8
  1328. static inline css_error set_padding_top(
  1329.                 css_computed_style *style, uint8_t type,
  1330.                 css_fixed length, css_unit unit)
  1331. {
  1332.         uint8_t *bits = &style->bits[PADDING_TOP_INDEX];
  1333.  
  1334.         /* 5bits: uuuut : units | type */
  1335.         *bits = (*bits & ~PADDING_TOP_MASK) |
  1336.                         (((type & 0x1) | (unit << 1)) << PADDING_TOP_SHIFT);
  1337.  
  1338.         style->padding[0] = length;
  1339.  
  1340.         return CSS_OK;
  1341. }
  1342. #undef PADDING_TOP_MASK
  1343. #undef PADDING_TOP_SHIFT
  1344. #undef PADDING_TOP_INDEX
  1345.  
  1346. #define PADDING_RIGHT_INDEX 22
  1347. #define PADDING_RIGHT_SHIFT 3
  1348. #define PADDING_RIGHT_MASK  0xf8
  1349. static inline css_error set_padding_right(
  1350.                 css_computed_style *style, uint8_t type,
  1351.                 css_fixed length, css_unit unit)
  1352. {
  1353.         uint8_t *bits = &style->bits[PADDING_RIGHT_INDEX];
  1354.  
  1355.         /* 5bits: uuuut : units | type */
  1356.         *bits = (*bits & ~PADDING_RIGHT_MASK) |
  1357.                         (((type & 0x1) | (unit << 1)) << PADDING_RIGHT_SHIFT);
  1358.  
  1359.         style->padding[1] = length;
  1360.  
  1361.         return CSS_OK;
  1362. }
  1363. #undef PADDING_RIGHT_MASK
  1364. #undef PADDING_RIGHT_SHIFT
  1365. #undef PADDING_RIGHT_INDEX
  1366.  
  1367. #define PADDING_BOTTOM_INDEX 23
  1368. #define PADDING_BOTTOM_SHIFT 3
  1369. #define PADDING_BOTTOM_MASK  0xf8
  1370. static inline css_error set_padding_bottom(
  1371.                 css_computed_style *style, uint8_t type,
  1372.                 css_fixed length, css_unit unit)
  1373. {
  1374.         uint8_t *bits = &style->bits[PADDING_BOTTOM_INDEX];
  1375.  
  1376.         /* 5bits: uuuut : units | type */
  1377.         *bits = (*bits & ~PADDING_BOTTOM_MASK) |
  1378.                         (((type & 0x1) | (unit << 1)) << PADDING_BOTTOM_SHIFT);
  1379.  
  1380.         style->padding[2] = length;
  1381.  
  1382.         return CSS_OK;
  1383. }
  1384. #undef PADDING_BOTTOM_MASK
  1385. #undef PADDING_BOTTOM_SHIFT
  1386. #undef PADDING_BOTTOM_INDEX
  1387.  
  1388. #define PADDING_LEFT_INDEX 24
  1389. #define PADDING_LEFT_SHIFT 3
  1390. #define PADDING_LEFT_MASK  0xf8
  1391. static inline css_error set_padding_left(
  1392.                 css_computed_style *style, uint8_t type,
  1393.                 css_fixed length, css_unit unit)
  1394. {
  1395.         uint8_t *bits = &style->bits[PADDING_LEFT_INDEX];
  1396.  
  1397.         /* 5bits: uuuut : units | type */
  1398.         *bits = (*bits & ~PADDING_LEFT_MASK) |
  1399.                         (((type & 0x1) | (unit << 1)) << PADDING_LEFT_SHIFT);
  1400.  
  1401.         style->padding[3] = length;
  1402.  
  1403.         return CSS_OK;
  1404. }
  1405. #undef PADDING_LEFT_MASK
  1406. #undef PADDING_LEFT_SHIFT
  1407. #undef PADDING_LEFT_INDEX
  1408.  
  1409. #define OVERFLOW_INDEX 21
  1410. #define OVERFLOW_SHIFT 0
  1411. #define OVERFLOW_MASK  0x7
  1412. static inline css_error set_overflow(
  1413.                 css_computed_style *style, uint8_t type)
  1414. {
  1415.         uint8_t *bits = &style->bits[OVERFLOW_INDEX];
  1416.  
  1417.         /* 3bits: type */
  1418.         *bits = (*bits & ~OVERFLOW_MASK) |
  1419.                         ((type & 0x7) << OVERFLOW_SHIFT);
  1420.  
  1421.         return CSS_OK;
  1422. }
  1423. #undef OVERFLOW_MASK
  1424. #undef OVERFLOW_SHIFT
  1425. #undef OVERFLOW_INDEX
  1426.  
  1427. #define POSITION_INDEX 22
  1428. #define POSITION_SHIFT 0
  1429. #define POSITION_MASK  0x7
  1430. static inline css_error set_position(
  1431.                 css_computed_style *style, uint8_t type)
  1432. {
  1433.         uint8_t *bits = &style->bits[POSITION_INDEX];
  1434.  
  1435.         /* 3bits: type */
  1436.         *bits = (*bits & ~POSITION_MASK) |
  1437.                         ((type & 0x7) << POSITION_SHIFT);
  1438.  
  1439.         return CSS_OK;
  1440. }
  1441. #undef POSITION_MASK
  1442. #undef POSITION_SHIFT
  1443. #undef POSITION_INDEX
  1444.  
  1445. #define OPACITY_INDEX 23
  1446. #define OPACITY_SHIFT 2
  1447. #define OPACITY_MASK  0x04
  1448. static inline css_error set_opacity(
  1449.                 css_computed_style *style,
  1450.                 uint8_t type, css_fixed opacity)
  1451. {
  1452.         uint8_t *bits = &style->bits[OPACITY_INDEX];
  1453.  
  1454.         /* 1bit: t : type */
  1455.         *bits = (*bits & ~OPACITY_MASK) |
  1456.                         ((type & 0x1) << OPACITY_SHIFT);
  1457.  
  1458.         style->opacity = opacity;
  1459.  
  1460.         return CSS_OK;
  1461. }
  1462. #undef OPACITY_MASK
  1463. #undef OPACITY_SHIFT
  1464. #undef OPACITY_INDEX
  1465.  
  1466. #define TEXT_TRANSFORM_INDEX 24
  1467. #define TEXT_TRANSFORM_SHIFT 0
  1468. #define TEXT_TRANSFORM_MASK  0x7
  1469. static inline css_error set_text_transform(
  1470.                 css_computed_style *style, uint8_t type)
  1471. {
  1472.         uint8_t *bits = &style->bits[TEXT_TRANSFORM_INDEX];
  1473.  
  1474.         /* 3bits: type */
  1475.         *bits = (*bits & ~TEXT_TRANSFORM_MASK) |
  1476.                         ((type & 0x7) << TEXT_TRANSFORM_SHIFT);
  1477.  
  1478.         return CSS_OK;
  1479. }
  1480. #undef TEXT_TRANSFORM_MASK
  1481. #undef TEXT_TRANSFORM_SHIFT
  1482. #undef TEXT_TRANSFORM_INDEX
  1483.  
  1484. #define TEXT_INDENT_INDEX 25
  1485. #define TEXT_INDENT_SHIFT 3
  1486. #define TEXT_INDENT_MASK  0xf8
  1487. static inline css_error set_text_indent(
  1488.                 css_computed_style *style, uint8_t type,
  1489.                 css_fixed length, css_unit unit)
  1490. {
  1491.         uint8_t *bits = &style->bits[TEXT_INDENT_INDEX];
  1492.  
  1493.         /* 5bits: uuuut : units | type */
  1494.         *bits = (*bits & ~TEXT_INDENT_MASK) |
  1495.                         (((type & 0x1) | (unit << 1)) << TEXT_INDENT_SHIFT);
  1496.  
  1497.         style->text_indent = length;
  1498.  
  1499.         return CSS_OK;
  1500. }
  1501. #undef TEXT_INDENT_MASK
  1502. #undef TEXT_INDENT_SHIFT
  1503. #undef TEXT_INDENT_INDEX
  1504.  
  1505. #define WHITE_SPACE_INDEX 25
  1506. #define WHITE_SPACE_SHIFT 0
  1507. #define WHITE_SPACE_MASK  0x7
  1508. static inline css_error set_white_space(
  1509.                 css_computed_style *style, uint8_t type)
  1510. {
  1511.         uint8_t *bits = &style->bits[WHITE_SPACE_INDEX];
  1512.  
  1513.         /* 3bits: type */
  1514.         *bits = (*bits & ~WHITE_SPACE_MASK) |
  1515.                         ((type & 0x7) << WHITE_SPACE_SHIFT);
  1516.  
  1517.         return CSS_OK;
  1518. }
  1519. #undef WHITE_SPACE_MASK
  1520. #undef WHITE_SPACE_SHIFT
  1521. #undef WHITE_SPACE_INDEX
  1522.  
  1523. #define BACKGROUND_POSITION_INDEX 27
  1524. #define BACKGROUND_POSITION_SHIFT 7
  1525. #define BACKGROUND_POSITION_MASK  0x80
  1526. #define BACKGROUND_POSITION_INDEX1 26
  1527. #define BACKGROUND_POSITION_SHIFT1 0
  1528. #define BACKGROUND_POSITION_MASK1 0xff
  1529. static inline css_error set_background_position(
  1530.                 css_computed_style *style, uint8_t type,
  1531.                 css_fixed hlength, css_unit hunit,
  1532.                 css_fixed vlength, css_unit vunit)
  1533. {
  1534.         uint8_t *bits;
  1535.  
  1536.         bits = &style->bits[BACKGROUND_POSITION_INDEX];
  1537.  
  1538.         /* 1 bit: type */
  1539.         *bits = (*bits & ~BACKGROUND_POSITION_MASK) |
  1540.                         ((type & 0x1) << BACKGROUND_POSITION_SHIFT);
  1541.  
  1542.         bits = &style->bits[BACKGROUND_POSITION_INDEX1];
  1543.  
  1544.         /* 8bits: hhhhvvvv : hunit | vunit */
  1545.         *bits = (*bits & ~BACKGROUND_POSITION_MASK1) |
  1546.                         (((hunit << 4) | vunit) << BACKGROUND_POSITION_SHIFT1);
  1547.  
  1548.         style->background_position[0] = hlength;
  1549.         style->background_position[1] = vlength;
  1550.  
  1551.         return CSS_OK;
  1552. }
  1553. #undef BACKGROUND_POSITION_MASK1
  1554. #undef BACKGROUND_POSITION_SHIFT1
  1555. #undef BACKGROUND_POSITION_INDEX1
  1556. #undef BACKGROUND_POSITION_MASK
  1557. #undef BACKGROUND_POSITION_SHIFT
  1558. #undef BACKGROUND_POSITION_INDEX
  1559.  
  1560. #define DISPLAY_INDEX 27
  1561. #define DISPLAY_SHIFT 2
  1562. #define DISPLAY_MASK  0x7c
  1563. static inline css_error set_display(
  1564.                 css_computed_style *style, uint8_t type)
  1565. {
  1566.         uint8_t *bits = &style->bits[DISPLAY_INDEX];
  1567.  
  1568.         /* 5bits: type */
  1569.         *bits = (*bits & ~DISPLAY_MASK) |
  1570.                         ((type & 0x1f) << DISPLAY_SHIFT);
  1571.  
  1572.         return CSS_OK;
  1573. }
  1574. #undef DISPLAY_MASK
  1575. #undef DISPLAY_SHIFT
  1576. #undef DISPLAY_INDEX
  1577.  
  1578. #define FONT_VARIANT_INDEX 27
  1579. #define FONT_VARIANT_SHIFT 0
  1580. #define FONT_VARIANT_MASK  0x3
  1581. static inline css_error set_font_variant(
  1582.                 css_computed_style *style, uint8_t type)
  1583. {
  1584.         uint8_t *bits = &style->bits[FONT_VARIANT_INDEX];
  1585.  
  1586.         /* 2bits: type */
  1587.         *bits = (*bits & ~FONT_VARIANT_MASK) |
  1588.                         ((type & 0x3) << FONT_VARIANT_SHIFT);
  1589.  
  1590.         return CSS_OK;
  1591. }
  1592. #undef FONT_VARIANT_MASK
  1593. #undef FONT_VARIANT_SHIFT
  1594. #undef FONT_VARIANT_INDEX
  1595.  
  1596. #define TEXT_DECORATION_INDEX 28
  1597. #define TEXT_DECORATION_SHIFT 3
  1598. #define TEXT_DECORATION_MASK  0xf8
  1599. static inline css_error set_text_decoration(
  1600.                 css_computed_style *style, uint8_t type)
  1601. {
  1602.         uint8_t *bits = &style->bits[TEXT_DECORATION_INDEX];
  1603.  
  1604.         /* 5bits: type */
  1605.         *bits = (*bits & ~TEXT_DECORATION_MASK) |
  1606.                         ((type & 0x1f) << TEXT_DECORATION_SHIFT);
  1607.  
  1608.         return CSS_OK;
  1609. }
  1610. #undef TEXT_DECORATION_MASK
  1611. #undef TEXT_DECORATION_SHIFT
  1612. #undef TEXT_DECORATION_INDEX
  1613.  
  1614. #define FONT_FAMILY_INDEX 28
  1615. #define FONT_FAMILY_SHIFT 0
  1616. #define FONT_FAMILY_MASK  0x7
  1617. static inline css_error set_font_family(
  1618.                 css_computed_style *style, uint8_t type,
  1619.                 lwc_string **names)
  1620. {
  1621.         uint8_t *bits = &style->bits[FONT_FAMILY_INDEX];
  1622.         lwc_string **oldnames = style->font_family;
  1623.         lwc_string **s;
  1624.  
  1625.         /* 3bits: type */
  1626.         *bits = (*bits & ~FONT_FAMILY_MASK) |
  1627.                         ((type & 0x7) << FONT_FAMILY_SHIFT);
  1628.  
  1629.         for (s = names; s != NULL && *s != NULL; s++)
  1630.                 *s = lwc_string_ref(*s);
  1631.  
  1632.         style->font_family = names;
  1633.  
  1634.         /* Free existing families */
  1635.         if (oldnames != NULL) {
  1636.                 for (s = oldnames; *s != NULL; s++)
  1637.                         lwc_string_unref(*s);
  1638.  
  1639.                 if (oldnames != names)
  1640.                         style->alloc(oldnames, 0, style->pw);
  1641.         }
  1642.  
  1643.         return CSS_OK;
  1644. }
  1645. #undef FONT_FAMILY_MASK
  1646. #undef FONT_FAMILY_SHIFT
  1647. #undef FONT_FAMILY_INDEX
  1648.  
  1649. #define BORDER_TOP_STYLE_INDEX 29
  1650. #define BORDER_TOP_STYLE_SHIFT 4
  1651. #define BORDER_TOP_STYLE_MASK  0xf0
  1652. static inline css_error set_border_top_style(
  1653.                 css_computed_style *style, uint8_t type)
  1654. {
  1655.         uint8_t *bits = &style->bits[BORDER_TOP_STYLE_INDEX];
  1656.  
  1657.         /* 4bits: type */
  1658.         *bits = (*bits & ~BORDER_TOP_STYLE_MASK) |
  1659.                         ((type & 0xf) << BORDER_TOP_STYLE_SHIFT);
  1660.  
  1661.         return CSS_OK;
  1662. }
  1663. #undef BORDER_TOP_STYLE_MASK
  1664. #undef BORDER_TOP_STYLE_SHIFT
  1665. #undef BORDER_TOP_STYLE_INDEX
  1666.  
  1667. #define BORDER_RIGHT_STYLE_INDEX 29
  1668. #define BORDER_RIGHT_STYLE_SHIFT 0
  1669. #define BORDER_RIGHT_STYLE_MASK  0xf
  1670. static inline css_error set_border_right_style(
  1671.                 css_computed_style *style, uint8_t type)
  1672. {
  1673.         uint8_t *bits = &style->bits[BORDER_RIGHT_STYLE_INDEX];
  1674.  
  1675.         /* 4bits: type */
  1676.         *bits = (*bits & ~BORDER_RIGHT_STYLE_MASK) |
  1677.                         ((type & 0xf) << BORDER_RIGHT_STYLE_SHIFT);
  1678.  
  1679.         return CSS_OK;
  1680. }
  1681. #undef BORDER_RIGHT_STYLE_MASK
  1682. #undef BORDER_RIGHT_STYLE_SHIFT
  1683. #undef BORDER_RIGHT_STYLE_INDEX
  1684.  
  1685. #define BORDER_BOTTOM_STYLE_INDEX 30
  1686. #define BORDER_BOTTOM_STYLE_SHIFT 4
  1687. #define BORDER_BOTTOM_STYLE_MASK  0xf0
  1688. static inline css_error set_border_bottom_style(
  1689.                 css_computed_style *style, uint8_t type)
  1690. {
  1691.         uint8_t *bits = &style->bits[BORDER_BOTTOM_STYLE_INDEX];
  1692.  
  1693.         /* 4bits: type */
  1694.         *bits = (*bits & ~BORDER_BOTTOM_STYLE_MASK) |
  1695.                         ((type & 0xf) << BORDER_BOTTOM_STYLE_SHIFT);
  1696.  
  1697.         return CSS_OK;
  1698. }
  1699. #undef BORDER_BOTTOM_STYLE_MASK
  1700. #undef BORDER_BOTTOM_STYLE_SHIFT
  1701. #undef BORDER_BOTTOM_STYLE_INDEX
  1702.  
  1703. #define BORDER_LEFT_STYLE_INDEX 30
  1704. #define BORDER_LEFT_STYLE_SHIFT 0
  1705. #define BORDER_LEFT_STYLE_MASK  0xf
  1706. static inline css_error set_border_left_style(
  1707.                 css_computed_style *style, uint8_t type)
  1708. {
  1709.         uint8_t *bits = &style->bits[BORDER_LEFT_STYLE_INDEX];
  1710.  
  1711.         /* 4bits: type */
  1712.         *bits = (*bits & ~BORDER_LEFT_STYLE_MASK) |
  1713.                         ((type & 0xf) << BORDER_LEFT_STYLE_SHIFT);
  1714.  
  1715.         return CSS_OK;
  1716. }
  1717. #undef BORDER_LEFT_STYLE_MASK
  1718. #undef BORDER_LEFT_STYLE_SHIFT
  1719. #undef BORDER_LEFT_STYLE_INDEX
  1720.  
  1721. #define FONT_WEIGHT_INDEX 31
  1722. #define FONT_WEIGHT_SHIFT 4
  1723. #define FONT_WEIGHT_MASK  0xf0
  1724. static inline css_error set_font_weight(
  1725.                 css_computed_style *style, uint8_t type)
  1726. {
  1727.         uint8_t *bits = &style->bits[FONT_WEIGHT_INDEX];
  1728.  
  1729.         /* 4bits: type */
  1730.         *bits = (*bits & ~FONT_WEIGHT_MASK) |
  1731.                         ((type & 0xf) << FONT_WEIGHT_SHIFT);
  1732.  
  1733.         return CSS_OK;
  1734. }
  1735. #undef FONT_WEIGHT_MASK
  1736. #undef FONT_WEIGHT_SHIFT
  1737. #undef FONT_WEIGHT_INDEX
  1738.  
  1739. #define LIST_STYLE_TYPE_INDEX 31
  1740. #define LIST_STYLE_TYPE_SHIFT 0
  1741. #define LIST_STYLE_TYPE_MASK  0xf
  1742. static inline css_error set_list_style_type(
  1743.                 css_computed_style *style, uint8_t type)
  1744. {
  1745.         uint8_t *bits = &style->bits[LIST_STYLE_TYPE_INDEX];
  1746.  
  1747.         /* 4bits: type */
  1748.         *bits = (*bits & ~LIST_STYLE_TYPE_MASK) |
  1749.                         ((type & 0xf) << LIST_STYLE_TYPE_SHIFT);
  1750.  
  1751.         return CSS_OK;
  1752. }
  1753. #undef LIST_STYLE_TYPE_MASK
  1754. #undef LIST_STYLE_TYPE_SHIFT
  1755. #undef LIST_STYLE_TYPE_INDEX
  1756.  
  1757. #define OUTLINE_STYLE_INDEX 32
  1758. #define OUTLINE_STYLE_SHIFT 4
  1759. #define OUTLINE_STYLE_MASK  0xf0
  1760. static inline css_error set_outline_style(
  1761.                 css_computed_style *style, uint8_t type)
  1762. {
  1763.         uint8_t *bits = &style->bits[OUTLINE_STYLE_INDEX];
  1764.  
  1765.         /* 4bits: type */
  1766.         *bits = (*bits & ~OUTLINE_STYLE_MASK) |
  1767.                         ((type & 0xf) << OUTLINE_STYLE_SHIFT);
  1768.  
  1769.         return CSS_OK;
  1770. }
  1771. #undef OUTLINE_STYLE_MASK
  1772. #undef OUTLINE_STYLE_SHIFT
  1773. #undef OUTLINE_STYLE_INDEX
  1774.  
  1775. #define TABLE_LAYOUT_INDEX 32
  1776. #define TABLE_LAYOUT_SHIFT 2
  1777. #define TABLE_LAYOUT_MASK  0xc
  1778. static inline css_error set_table_layout(
  1779.                 css_computed_style *style, uint8_t type)
  1780. {
  1781.         uint8_t *bits = &style->bits[TABLE_LAYOUT_INDEX];
  1782.  
  1783.         /* 2bits: type */
  1784.         *bits = (*bits & ~TABLE_LAYOUT_MASK) |
  1785.                         ((type & 0x3) << TABLE_LAYOUT_SHIFT);
  1786.  
  1787.         return CSS_OK;
  1788. }
  1789. #undef TABLE_LAYOUT_MASK
  1790. #undef TABLE_LAYOUT_SHIFT
  1791. #undef TABLE_LAYOUT_INDEX
  1792.  
  1793. #define UNICODE_BIDI_INDEX 32
  1794. #define UNICODE_BIDI_SHIFT 0
  1795. #define UNICODE_BIDI_MASK  0x3
  1796. static inline css_error set_unicode_bidi(
  1797.                 css_computed_style *style, uint8_t type)
  1798. {
  1799.         uint8_t *bits = &style->bits[UNICODE_BIDI_INDEX];
  1800.  
  1801.         /* 2bits: type */
  1802.         *bits = (*bits & ~UNICODE_BIDI_MASK) |
  1803.                         ((type & 0x3) << UNICODE_BIDI_SHIFT);
  1804.  
  1805.         return CSS_OK;
  1806. }
  1807. #undef UNICODE_BIDI_MASK
  1808. #undef UNICODE_BIDI_SHIFT
  1809. #undef UNICODE_BIDI_INDEX
  1810.  
  1811. #define VISIBILITY_INDEX 33
  1812. #define VISIBILITY_SHIFT 6
  1813. #define VISIBILITY_MASK  0xc0
  1814. static inline css_error set_visibility(
  1815.                 css_computed_style *style, uint8_t type)
  1816. {
  1817.         uint8_t *bits = &style->bits[VISIBILITY_INDEX];
  1818.  
  1819.         /* 2bits: type */
  1820.         *bits = (*bits & ~VISIBILITY_MASK) |
  1821.                         ((type & 0x3) << VISIBILITY_SHIFT);
  1822.  
  1823.         return CSS_OK;
  1824. }
  1825. #undef VISIBILITY_MASK
  1826. #undef VISIBILITY_SHIFT
  1827. #undef VISIBILITY_INDEX
  1828.  
  1829. #define LIST_STYLE_POSITION_INDEX 33
  1830. #define LIST_STYLE_POSITION_SHIFT 4
  1831. #define LIST_STYLE_POSITION_MASK  0x30
  1832. static inline css_error set_list_style_position(
  1833.                 css_computed_style *style, uint8_t type)
  1834. {
  1835.         uint8_t *bits = &style->bits[LIST_STYLE_POSITION_INDEX];
  1836.  
  1837.         /* 2bits: type */
  1838.         *bits = (*bits & ~LIST_STYLE_POSITION_MASK) |
  1839.                         ((type & 0x3) << LIST_STYLE_POSITION_SHIFT);
  1840.  
  1841.         return CSS_OK;
  1842. }
  1843. #undef LIST_STYLE_POSITION_MASK
  1844. #undef LIST_STYLE_POSITION_SHIFT
  1845. #undef LIST_STYLE_POSITION_INDEX
  1846.  
  1847. #define TEXT_ALIGN_INDEX 33
  1848. #define TEXT_ALIGN_SHIFT 0
  1849. #define TEXT_ALIGN_MASK  0xf
  1850. static inline uint8_t set_text_align(
  1851.                 css_computed_style *style, uint8_t type)
  1852. {
  1853.         uint8_t *bits = &style->bits[TEXT_ALIGN_INDEX];
  1854.  
  1855.         /* 4bits: type */
  1856.         *bits = (*bits & ~TEXT_ALIGN_MASK) |
  1857.                         ((type & 0xf) << TEXT_ALIGN_SHIFT);
  1858.  
  1859.         return CSS_OK;
  1860. }
  1861. #undef TEXT_ALIGN_MASK
  1862. #undef TEXT_ALIGN_SHIFT
  1863. #undef TEXT_ALIGN_INDEX
  1864.  
  1865. #define PAGE_BREAK_AFTER_INDEX 0
  1866. #define PAGE_BREAK_AFTER_SHIFT 0
  1867. #define PAGE_BREAK_AFTER_MASK 0x7
  1868. static inline css_error set_page_break_after(
  1869.                 css_computed_style *style, uint8_t type)
  1870. {
  1871.         uint8_t *bits;
  1872.  
  1873.         if (style->page == NULL) {
  1874.                 if (type == CSS_PAGE_BREAK_AFTER_AUTO) {
  1875.                         return CSS_OK;
  1876.                 }
  1877.         }
  1878.  
  1879.         ENSURE_PAGE;
  1880.  
  1881.         bits = &style->page->bits[PAGE_BREAK_AFTER_INDEX];
  1882.  
  1883.         /* 3bits: type */
  1884.         *bits = (*bits & ~PAGE_BREAK_AFTER_MASK) |
  1885.                         ((type & 0x7) << PAGE_BREAK_AFTER_SHIFT);
  1886.  
  1887.         return CSS_OK;
  1888. }
  1889. #undef PAGE_BREAK_AFTER_INDEX
  1890. #undef PAGE_BREAK_AFTER_SHIFT
  1891. #undef PAGE_BREAK_AFTER_MASK
  1892.  
  1893. #define PAGE_BREAK_BEFORE_INDEX 0
  1894. #define PAGE_BREAK_BEFORE_SHIFT 3
  1895. #define PAGE_BREAK_BEFORE_MASK 0x38
  1896. static inline css_error set_page_break_before(
  1897.                 css_computed_style *style, uint8_t type)
  1898. {
  1899.         uint8_t *bits;
  1900.  
  1901.         if (style->page == NULL) {
  1902.                 if (type == CSS_PAGE_BREAK_BEFORE_AUTO) {
  1903.                         return CSS_OK;
  1904.                 }
  1905.         }
  1906.        
  1907.         ENSURE_PAGE;
  1908.        
  1909.         bits = &style->page->bits[PAGE_BREAK_BEFORE_INDEX];
  1910.  
  1911.         /* 3bits: type */
  1912.         *bits = (*bits & ~PAGE_BREAK_BEFORE_MASK) |
  1913.                         ((type & 0x7) << PAGE_BREAK_BEFORE_SHIFT);
  1914.  
  1915.         return CSS_OK;
  1916. }
  1917. #undef PAGE_BREAK_BEFORE_INDEX
  1918. #undef PAGE_BREAK_BEFORE_SHIFT
  1919. #undef PAGE_BREAK_BEFORE_MASK
  1920.  
  1921. #define PAGE_BREAK_INSIDE_INDEX 0
  1922. #define PAGE_BREAK_INSIDE_SHIFT 6
  1923. #define PAGE_BREAK_INSIDE_MASK 0xc0
  1924. static inline css_error set_page_break_inside(
  1925.                 css_computed_style *style, uint8_t type)
  1926. {
  1927.         uint8_t *bits;
  1928.  
  1929.         if (style->page == NULL) {
  1930.                 if (type == CSS_PAGE_BREAK_INSIDE_AUTO) {
  1931.                         return CSS_OK;
  1932.                 }
  1933.         }
  1934.        
  1935.         ENSURE_PAGE;
  1936.  
  1937.         bits = &style->page->bits[PAGE_BREAK_INSIDE_INDEX];
  1938.  
  1939.         /* 2bits: type */
  1940.         *bits = (*bits & ~PAGE_BREAK_INSIDE_MASK) |
  1941.                         ((type & 0x3) << PAGE_BREAK_INSIDE_SHIFT);
  1942.  
  1943.         return CSS_OK;
  1944. }
  1945. #undef PAGE_BREAK_INSIDE_INDEX
  1946. #undef PAGE_BREAK_INSIDE_SHIFT
  1947. #undef PAGE_BREAK_INSIDE_MASK
  1948.  
  1949. #define ORPHANS_INDEX 1
  1950. #define ORPHANS_SHIFT 0
  1951. #define ORPHANS_MASK 0x1
  1952. static inline css_error set_orphans(
  1953.                 css_computed_style *style, uint8_t type, css_fixed count)
  1954. {
  1955.         uint8_t *bits;
  1956.        
  1957.         if (style->page == NULL) {
  1958.                 if (type == CSS_ORPHANS_SET && count == INTTOFIX(2)) {
  1959.                         return CSS_OK;
  1960.                 }
  1961.         }
  1962.  
  1963.         ENSURE_PAGE;
  1964.        
  1965.         bits = &style->page->bits[ORPHANS_INDEX];
  1966.        
  1967.         /* 1bit: type */
  1968.         *bits = (*bits & ~ORPHANS_MASK) | ((type & 0x1) << ORPHANS_SHIFT);
  1969.        
  1970.         style->page->orphans = count;
  1971.        
  1972.         return CSS_OK;
  1973. }
  1974. #undef ORPHANS_INDEX
  1975. #undef ORPHANS_SHIFT
  1976. #undef ORPHANS_MASK
  1977.  
  1978. #define WIDOWS_INDEX 1
  1979. #define WIDOWS_SHIFT 1
  1980. #define WIDOWS_MASK 0x2
  1981. static inline css_error set_widows(
  1982.                 css_computed_style *style, uint8_t type, css_fixed count)
  1983. {
  1984.         uint8_t *bits;
  1985.        
  1986.         if (style->page == NULL) {
  1987.                 if (type == CSS_WIDOWS_SET && count == INTTOFIX(2)) {
  1988.                         return CSS_OK;
  1989.                 }
  1990.         }
  1991.        
  1992.         ENSURE_PAGE;
  1993.        
  1994.         bits = &style->page->bits[WIDOWS_INDEX];
  1995.        
  1996.         /* 1bit: type */
  1997.         *bits = (*bits & ~WIDOWS_MASK) | ((type & 0x1) << WIDOWS_SHIFT);
  1998.        
  1999.         style->page->widows = count;
  2000.        
  2001.         return CSS_OK;
  2002. }
  2003. #undef WIDOWS_INDEX
  2004. #undef WIDOWS_SHIFT
  2005. #undef WIDOWS_MASK
  2006.  
  2007. #endif
  2008.