summaryrefslogtreecommitdiff
path: root/include/libcss/computed.h
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-02-06 14:08:50 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2009-02-06 14:08:50 +0000
commitb230fafd64ed4a23fdeb1c16a991db2f42d6c8a4 (patch)
treed5d52859451f2f653f69fc99ab48a01e671ded9e /include/libcss/computed.h
parentf272b27bbdc558c6c2b30ad6bf8caff3db3b9622 (diff)
downloadlibcss-b230fafd64ed4a23fdeb1c16a991db2f42d6c8a4.tar.gz
libcss-b230fafd64ed4a23fdeb1c16a991db2f42d6c8a4.tar.bz2
Some property accessors.
Define css_unit type. svn path=/trunk/libcss/; revision=6372
Diffstat (limited to 'include/libcss/computed.h')
-rw-r--r--include/libcss/computed.h124
1 files changed, 122 insertions, 2 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