summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2014-01-10 17:02:52 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2014-01-10 17:02:52 +0000
commit5d98b16ffba25edb23be14624f35b0cf5de77566 (patch)
treec81770ef3c96a8bf4d565ebef5198c67c94af6b5 /src
parent54fa7907e366846ce1b79d8249f57d3f0b319736 (diff)
downloadlibcss-5d98b16ffba25edb23be14624f35b0cf5de77566.tar.gz
libcss-5d98b16ffba25edb23be14624f35b0cf5de77566.tar.bz2
Remove implementation duplication in top/right/bottom/left property getters.
Diffstat (limited to 'src')
-rw-r--r--src/select/computed.c160
-rw-r--r--src/select/propget.h40
2 files changed, 85 insertions, 115 deletions
diff --git a/src/select/computed.c b/src/select/computed.c
index 994c306..bd72dc2 100644
--- a/src/select/computed.c
+++ b/src/select/computed.c
@@ -437,202 +437,132 @@ uint8_t css_computed_quotes(const css_computed_style *style,
return get_quotes(style, quotes);
}
-#define CSS_TOP_INDEX 6
-#define CSS_TOP_SHIFT 2
-#define CSS_TOP_MASK 0xfc
-#define CSS_RIGHT_INDEX 7
-#define CSS_RIGHT_SHIFT 2
-#define CSS_RIGHT_MASK 0xfc
-#define CSS_BOTTOM_INDEX 8
-#define CSS_BOTTOM_SHIFT 2
-#define CSS_BOTTOM_MASK 0xfc
-#define CSS_LEFT_INDEX 9
-#define CSS_LEFT_SHIFT 2
-#define CSS_LEFT_MASK 0xfc
-uint8_t css_computed_top(
- const css_computed_style *style,
+uint8_t css_computed_top(const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[CSS_TOP_INDEX];
- bits &= CSS_TOP_MASK;
- bits >>= CSS_TOP_SHIFT;
+ uint8_t position = css_computed_position(style);
+ uint8_t top = get_top(style, length, unit);
/* Fix up, based on computed position */
- if (css_computed_position(style) == CSS_POSITION_STATIC) {
+ if (position == CSS_POSITION_STATIC) {
/* Static -> auto */
- bits = CSS_TOP_AUTO;
- } else if (css_computed_position(style) == CSS_POSITION_RELATIVE) {
+ top = CSS_TOP_AUTO;
+ } else if (position == CSS_POSITION_RELATIVE) {
/* Relative -> follow $9.4.3 */
- uint8_t bottom = style->bits[CSS_BOTTOM_INDEX];
- bottom &= CSS_BOTTOM_MASK;
- bottom >>= CSS_BOTTOM_SHIFT;
+ uint8_t bottom = get_bottom_bits(style);
- if ((bits & 0x3) == CSS_TOP_AUTO &&
- (bottom & 0x3) == CSS_BOTTOM_AUTO) {
+ if (top == CSS_TOP_AUTO && (bottom & 0x3) == CSS_BOTTOM_AUTO) {
/* Both auto => 0px */
*length = 0;
*unit = CSS_UNIT_PX;
- } else if ((bits & 0x3) == CSS_TOP_AUTO) {
+ } else if (top == CSS_TOP_AUTO) {
/* Top is auto => -bottom */
*length = -style->bottom;
*unit = (css_unit) (bottom >> 2);
- } else {
- *length = style->top;
- *unit = (css_unit) (bits >> 2);
}
- bits = CSS_TOP_SET;
- } else if ((bits & 0x3) == CSS_TOP_SET) {
- *length = style->top;
- *unit = (css_unit) (bits >> 2);
+ top = CSS_TOP_SET;
}
- /* 6bits: uuuutt : units | type */
- return (bits & 0x3);
+ return top;
}
-uint8_t css_computed_right(
- const css_computed_style *style,
+uint8_t css_computed_right(const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[CSS_RIGHT_INDEX];
- bits &= CSS_RIGHT_MASK;
- bits >>= CSS_RIGHT_SHIFT;
+ uint8_t position = css_computed_position(style);
+ uint8_t right = get_right(style, length, unit);
/* Fix up, based on computed position */
- if (css_computed_position(style) == CSS_POSITION_STATIC) {
+ if (position == CSS_POSITION_STATIC) {
/* Static -> auto */
- bits = CSS_RIGHT_AUTO;
- } else if (css_computed_position(style) == CSS_POSITION_RELATIVE) {
+ right = CSS_RIGHT_AUTO;
+ } else if (position == CSS_POSITION_RELATIVE) {
/* Relative -> follow $9.4.3 */
- uint8_t left = style->bits[CSS_LEFT_INDEX];
- left &= CSS_LEFT_MASK;
- left >>= CSS_LEFT_SHIFT;
+ uint8_t left = get_left_bits(style);
- if ((bits & 0x3) == CSS_RIGHT_AUTO &&
- (left & 0x3) == CSS_LEFT_AUTO) {
+ if (right == CSS_RIGHT_AUTO && (left & 0x3) == CSS_LEFT_AUTO) {
/* Both auto => 0px */
*length = 0;
*unit = CSS_UNIT_PX;
- } else if ((bits & 0x3) == CSS_RIGHT_AUTO) {
+ } else if (right == CSS_RIGHT_AUTO) {
/* Right is auto => -left */
*length = -style->left;
*unit = (css_unit) (left >> 2);
} else {
/** \todo Consider containing block's direction
* if overconstrained */
- *length = style->right;
- *unit = (css_unit) (bits >> 2);
}
- bits = CSS_RIGHT_SET;
- } else if ((bits & 0x3) == CSS_RIGHT_SET) {
- *length = style->right;
- *unit = (css_unit) (bits >> 2);
+ right = CSS_RIGHT_SET;
}
- /* 6bits: uuuutt : units | type */
- return (bits & 0x3);
+ return right;
}
-uint8_t css_computed_bottom(
- const css_computed_style *style,
+uint8_t css_computed_bottom(const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[CSS_BOTTOM_INDEX];
- bits &= CSS_BOTTOM_MASK;
- bits >>= CSS_BOTTOM_SHIFT;
+ uint8_t position = css_computed_position(style);
+ uint8_t bottom = get_bottom(style, length, unit);
/* Fix up, based on computed position */
- if (css_computed_position(style) == CSS_POSITION_STATIC) {
+ if (position == CSS_POSITION_STATIC) {
/* Static -> auto */
- bits = CSS_BOTTOM_AUTO;
- } else if (css_computed_position(style) == CSS_POSITION_RELATIVE) {
+ bottom = CSS_BOTTOM_AUTO;
+ } else if (position == CSS_POSITION_RELATIVE) {
/* Relative -> follow $9.4.3 */
- uint8_t top = style->bits[CSS_TOP_INDEX];
- top &= CSS_TOP_MASK;
- top >>= CSS_TOP_SHIFT;
+ uint8_t top = get_top_bits(style);
- if ((bits & 0x3) == CSS_BOTTOM_AUTO &&
- (top & 0x3) == CSS_TOP_AUTO) {
+ if (bottom == CSS_BOTTOM_AUTO && (top & 0x3) == CSS_TOP_AUTO) {
/* Both auto => 0px */
*length = 0;
*unit = CSS_UNIT_PX;
- } else if ((bits & 0x3) == CSS_BOTTOM_AUTO ||
+ } else if (bottom == CSS_BOTTOM_AUTO ||
(top & 0x3) != CSS_TOP_AUTO) {
/* Bottom is auto or top is not auto => -top */
*length = -style->top;
*unit = (css_unit) (top >> 2);
- } else {
- *length = style->bottom;
- *unit = (css_unit) (bits >> 2);
}
- bits = CSS_BOTTOM_SET;
- } else if ((bits & 0x3) == CSS_BOTTOM_SET) {
- *length = style->bottom;
- *unit = (css_unit) (bits >> 2);
+ bottom = CSS_BOTTOM_SET;
}
- /* 6bits: uuuutt : units | type */
- return (bits & 0x3);
+ return bottom;
}
-uint8_t css_computed_left(
- const css_computed_style *style,
+uint8_t css_computed_left(const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[CSS_LEFT_INDEX];
- bits &= CSS_LEFT_MASK;
- bits >>= CSS_LEFT_SHIFT;
+ uint8_t position = css_computed_position(style);
+ uint8_t left = get_left(style, length, unit);
/* Fix up, based on computed position */
- if (css_computed_position(style) == CSS_POSITION_STATIC) {
+ if (position == CSS_POSITION_STATIC) {
/* Static -> auto */
- bits = CSS_LEFT_AUTO;
- } else if (css_computed_position(style) == CSS_POSITION_RELATIVE) {
+ left = CSS_LEFT_AUTO;
+ } else if (position == CSS_POSITION_RELATIVE) {
/* Relative -> follow $9.4.3 */
- uint8_t right = style->bits[CSS_RIGHT_INDEX];
- right &= CSS_RIGHT_MASK;
- right >>= CSS_RIGHT_SHIFT;
+ uint8_t right = get_right_bits(style);
- if ((bits & 0x3) == CSS_LEFT_AUTO &&
- (right & 0x3) == CSS_RIGHT_AUTO) {
+ if (left == CSS_LEFT_AUTO && (right & 0x3) == CSS_RIGHT_AUTO) {
/* Both auto => 0px */
*length = 0;
*unit = CSS_UNIT_PX;
- } else if ((bits & 0x3) == CSS_LEFT_AUTO) {
+ } else if (left == CSS_LEFT_AUTO) {
/* Left is auto => -right */
*length = -style->right;
*unit = (css_unit) (right >> 2);
} else {
/** \todo Consider containing block's direction
* if overconstrained */
- *length = style->left;
- *unit = (css_unit) (bits >> 2);
}
- bits = CSS_LEFT_SET;
- } else if ((bits & 0x3) == CSS_LEFT_SET) {
- *length = style->left;
- *unit = (css_unit) (bits >> 2);
+ left = CSS_LEFT_SET;
}
- /* 6bits: uuuutt : units | type */
- return (bits & 0x3);
-}
-#undef CSS_LEFT_MASK
-#undef CSS_LEFT_SHIFT
-#undef CSS_LEFT_INDEX
-#undef CSS_BOTTOM_MASK
-#undef CSS_BOTTOM_SHIFT
-#undef CSS_BOTTOM_INDEX
-#undef CSS_RIGHT_MASK
-#undef CSS_RIGHT_SHIFT
-#undef CSS_RIGHT_INDEX
-#undef CSS_TOP_MASK
-#undef CSS_TOP_SHIFT
-#undef CSS_TOP_INDEX
+ return left;
+}
uint8_t css_computed_border_top_color(const css_computed_style *style,
css_color *color)
diff --git a/src/select/propget.h b/src/select/propget.h
index b2cf16b..7fff136 100644
--- a/src/select/propget.h
+++ b/src/select/propget.h
@@ -603,6 +603,16 @@ static inline uint8_t get_top(
return (bits & 0x3);
}
+static inline uint8_t get_top_bits(
+ const css_computed_style *style)
+{
+ uint8_t bits = style->bits[TOP_INDEX];
+ bits &= TOP_MASK;
+ bits >>= TOP_SHIFT;
+
+ /* 6bits: uuuutt : units | type */
+ return bits;
+}
#undef TOP_MASK
#undef TOP_SHIFT
#undef TOP_INDEX
@@ -626,6 +636,16 @@ static inline uint8_t get_right(
return (bits & 0x3);
}
+static inline uint8_t get_right_bits(
+ const css_computed_style *style)
+{
+ uint8_t bits = style->bits[RIGHT_INDEX];
+ bits &= RIGHT_MASK;
+ bits >>= RIGHT_SHIFT;
+
+ /* 6bits: uuuutt : units | type */
+ return bits;
+}
#undef RIGHT_MASK
#undef RIGHT_SHIFT
#undef RIGHT_INDEX
@@ -649,6 +669,16 @@ static inline uint8_t get_bottom(
return (bits & 0x3);
}
+static inline uint8_t get_bottom_bits(
+ const css_computed_style *style)
+{
+ uint8_t bits = style->bits[BOTTOM_INDEX];
+ bits &= BOTTOM_MASK;
+ bits >>= BOTTOM_SHIFT;
+
+ /* 6bits: uuuutt : units | type */
+ return bits;
+}
#undef BOTTOM_MASK
#undef BOTTOM_SHIFT
#undef BOTTOM_INDEX
@@ -672,6 +702,16 @@ static inline uint8_t get_left(
return (bits & 0x3);
}
+static inline uint8_t get_left_bits(
+ const css_computed_style *style)
+{
+ uint8_t bits = style->bits[LEFT_INDEX];
+ bits &= LEFT_MASK;
+ bits >>= LEFT_SHIFT;
+
+ /* 6bits: uuuutt : units | type */
+ return bits;
+}
#undef LEFT_MASK
#undef LEFT_SHIFT
#undef LEFT_INDEX