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