summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/libcss/computed.h124
-rw-r--r--include/libcss/types.h30
2 files changed, 149 insertions, 5 deletions
diff --git a/include/libcss/computed.h b/include/libcss/computed.h
index 18230b9..15f5941 100644
--- a/include/libcss/computed.h
+++ b/include/libcss/computed.h
@@ -70,7 +70,7 @@ typedef struct css_computed_uncommon {
*
* Bit allocations:
*
- * 01234567
+ * 76543210
* 1 llllllcc letter-spacing | outline-color
* 2 ooooooob outline-width | border-spacing
* 3 bbbbbbbb border-spacing
@@ -192,7 +192,7 @@ struct css_computed_style {
*
* Bit allocations:
*
- * 01234567
+ * 76543210
* 1 vvvvvvvv vertical-align
* 2 ffffffff font-size
* 3 ttttttti border-top-width | background-image
@@ -287,4 +287,124 @@ css_error css_computed_style_compose(const css_computed_style *parent,
const css_computed_style *child,
css_computed_style *result);
+/******************************************************************************
+ * Property accessors below here *
+ ******************************************************************************/
+
+#define LETTER_SPACING_INDEX 0
+#define LETTER_SPACING_SHIFT 2
+#define LETTER_SPACING_MASK 0xfc
+static inline uint8_t css_computed_letter_spacing(
+ const css_computed_style *style,
+ css_fixed *length, css_unit *unit)
+{
+ if (style->uncommon != NULL) {
+ uint8_t bits = style->uncommon->bits[LETTER_SPACING_INDEX];
+ bits &= LETTER_SPACING_MASK;
+ bits >>= LETTER_SPACING_SHIFT;
+
+ /* 6bits: uuuutt : unit | type */
+
+ if ((bits & 3) == CSS_LETTER_SPACING_SET) {
+ *length = style->uncommon->letter_spacing;
+ *unit = bits >> 2;
+ return CSS_LETTER_SPACING_SET;
+ }
+ }
+
+ return CSS_LETTER_SPACING_NORMAL;
+}
+#undef LETTER_SPACING_MASK
+#undef LETTER_SPACING_SHIFT
+#undef LETTER_SPACING_INDEX
+
+#define OUTLINE_COLOR_INDEX 0
+#define OUTLINE_COLOR_SHIFT 0
+#define OUTLINE_COLOR_MASK 0x3
+static inline uint8_t css_computed_outline_color(
+ const css_computed_style *style, css_color *color)
+{
+ if (style->uncommon != NULL) {
+ uint8_t bits = style->uncommon->bits[OUTLINE_COLOR_INDEX];
+ bits &= OUTLINE_COLOR_MASK;
+ bits >>= OUTLINE_COLOR_SHIFT;
+
+ /* 2bits: tt : type */
+
+ if ((bits & 3) == CSS_OUTLINE_COLOR_COLOR) {
+ *color = style->uncommon->outline_color;
+ return CSS_OUTLINE_COLOR_COLOR;
+ }
+ }
+
+ return CSS_OUTLINE_COLOR_INVERT;
+}
+#undef OUTLINE_COLOR_MASK
+#undef OUTLINE_COLOR_SHIFT
+#undef OUTLINE_COLOR_INDEX
+
+#define OUTLINE_WIDTH_INDEX 1
+#define OUTLINE_WIDTH_SHIFT 1
+#define OUTLINE_WIDTH_MASK 0xfe
+static inline uint8_t css_computed_outline_width(
+ const css_computed_style *style,
+ css_fixed *length, css_unit *unit)
+{
+ if (style->uncommon != NULL) {
+ uint8_t bits = style->uncommon->bits[OUTLINE_WIDTH_INDEX];
+ bits &= OUTLINE_WIDTH_MASK;
+ bits >>= OUTLINE_WIDTH_SHIFT;
+
+ /* 7bits: uuuuttt : unit | type */
+
+ if ((bits & 7) == CSS_OUTLINE_WIDTH_WIDTH) {
+ *length = style->uncommon->outline_width;
+ *unit = bits >> 3;
+ return CSS_OUTLINE_WIDTH_WIDTH;
+ } else
+ return (bits & 7);
+ }
+
+ return CSS_OUTLINE_WIDTH_MEDIUM;
+}
+#undef OUTLINE_WIDTH_MASK
+#undef OUTLINE_WIDTH_SHIFT
+#undef OUTLINE_WIDTH_INDEX
+
+#define BORDER_SPACING_INDEX 2
+#define BORDER_SPACING_SHIFT 0
+#define BORDER_SPACING_MASK 0xff
+static inline uint8_t css_computed_border_spacing(
+ const css_computed_style *style,
+ css_fixed *hlength, css_unit *hunit,
+ css_fixed *vlength, css_unit *vunit)
+{
+ if (style->uncommon != NULL) {
+ uint8_t bits = style->uncommon->bits[BORDER_SPACING_INDEX];
+ bits &= BORDER_SPACING_MASK;
+ bits >>= BORDER_SPACING_SHIFT;
+
+ /* There's actually a ninth bit (bit 0 of the previous byte)
+ * This encodes SET/INHERIT. Given that we must be SET here,
+ * we don't bother looking at it */
+
+ /* 8bits: hhhhvvvv : hunit | vunit */
+
+ *hlength = style->uncommon->border_spacing[0];
+ *hunit = bits >> 4;
+
+ *vlength = style->uncommon->border_spacing[1];
+ *vunit = bits & 0xf;
+ } else {
+ *hlength = *vlength = 0;
+ *hunit = *vunit = CSS_UNIT_PX;
+ }
+
+ return CSS_BORDER_SPACING_SET;
+}
+#undef BORDER_SPACING_MASK
+#undef BORDER_SPACING_SHIFT
+#undef BORDER_SPACING_INDEX
+
+
#endif
diff --git a/include/libcss/types.h b/include/libcss/types.h
index 640ef50..9b8da8f 100644
--- a/include/libcss/types.h
+++ b/include/libcss/types.h
@@ -46,9 +46,9 @@ typedef enum css_media_type {
* Stylesheet origin
*/
typedef enum css_origin {
- CSS_ORIGIN_UA = 0, /**< User agent stylesheet */
- CSS_ORIGIN_USER = 1, /**< User stylesheet */
- CSS_ORIGIN_AUTHOR = 2 /**< Author stylesheet */
+ CSS_ORIGIN_UA = 0, /**< User agent stylesheet */
+ CSS_ORIGIN_USER = 1, /**< User stylesheet */
+ CSS_ORIGIN_AUTHOR = 2 /**< Author stylesheet */
} css_origin;
/**
@@ -66,6 +66,30 @@ typedef uint32_t css_color;
/** \todo Do we want to make utils/fp*.h public? */
typedef int32_t css_fixed;
+/* CSS unit */
+typedef enum css_unit {
+ CSS_UNIT_PX = 0x0,
+ CSS_UNIT_EX = 0x1,
+ CSS_UNIT_EM = 0x2,
+ CSS_UNIT_IN = 0x3,
+ CSS_UNIT_CM = 0x4,
+ CSS_UNIT_MM = 0x5,
+ CSS_UNIT_PT = 0x6,
+ CSS_UNIT_PC = 0x7,
+
+ CSS_UNIT_PCT = 0x8, /* Percentage */
+
+ CSS_UNIT_DEG = 0x9,
+ CSS_UNIT_GRAD = 0xa,
+ CSS_UNIT_RAD = 0xb,
+
+ CSS_UNIT_MS = 0xc,
+ CSS_UNIT_S = 0xd,
+
+ CSS_UNIT_HZ = 0xe,
+ CSS_UNIT_KHZ = 0xf
+} css_unit;
+
typedef struct css_stylesheet css_stylesheet;
typedef struct css_select_ctx css_select_ctx;