From b2fd371c4311d5d6abe7c724c8025a37c534942b Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Mon, 30 Sep 2013 20:34:03 +0200 Subject: New type for (incomplete). --- src/css.hh | 8 ++++++++ src/cssparser.cc | 20 ++++++++++++++++---- src/styleengine.cc | 12 +++++------- 3 files changed, 29 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/css.hh b/src/css.hh index b05a18bc..1dcc41cc 100644 --- a/src/css.hh +++ b/src/css.hh @@ -46,6 +46,7 @@ typedef enum { CSS_TYPE_MULTI_ENUM). Used for 'font-family'. */ CSS_TYPE_URI, /* */ + CSS_TYPE_BACKGROUND_POSITION, CSS_TYPE_UNUSED /* Not yet used. Will itself get unused some day. */ } CssValueType; @@ -143,6 +144,7 @@ typedef enum { CSS_PROPERTY_BACKGROUND_ATTACHMENT, CSS_PROPERTY_BACKGROUND_COLOR, CSS_PROPERTY_BACKGROUND_IMAGE, + CSS_PROPERTY_BACKGROUND_POSITION, // 'background-position' is handled as a shorthand. CSS_PROPERTY_BACKGROUND_REPEAT, CSS_PROPERTY_BORDER_BOTTOM_COLOR, @@ -234,9 +236,15 @@ typedef enum { CSS_PROPERTY_LAST } CssPropertyName; +typedef struct { + int32_t posX; + int32_t posY; +} CssBackgroundPosition; + typedef union { int32_t intVal; char *strVal; + CssBackgroundPosition *posVal; } CssPropertyValue; typedef enum { diff --git a/src/cssparser.cc b/src/cssparser.cc index 12e14779..6e414e78 100644 --- a/src/cssparser.cc +++ b/src/cssparser.cc @@ -159,7 +159,7 @@ const CssPropertyInfo Css_property_info[CSS_PROPERTY_LAST] = { Css_background_attachment_enum_vals}, {"background-color", {CSS_TYPE_COLOR, CSS_TYPE_UNUSED}, NULL}, {"background-image", {CSS_TYPE_URI, CSS_TYPE_UNUSED}, NULL}, - // 'background-position' is handled as a shorthand. + {"background-position", {CSS_TYPE_BACKGROUND_POSITION, CSS_TYPE_UNUSED}, NULL}, {"background-repeat", {CSS_TYPE_ENUM, CSS_TYPE_UNUSED}, Css_background_repeat_enum_vals}, {"border-bottom-color", {CSS_TYPE_ENUM, CSS_TYPE_COLOR, CSS_TYPE_UNUSED}, @@ -307,8 +307,7 @@ const CssPropertyName Css_background_properties[] = { CSS_PROPERTY_BACKGROUND_IMAGE, CSS_PROPERTY_BACKGROUND_REPEAT, CSS_PROPERTY_BACKGROUND_ATTACHMENT, - CSS_PROPERTY_X_BACKGROUND_POSITION_X, - CSS_PROPERTY_X_BACKGROUND_POSITION_Y, + CSS_PROPERTY_BACKGROUND_POSITION, (CssPropertyName) - 1 }; @@ -414,7 +413,7 @@ const CssPropertyName Css_font_properties[] = { }; static const CssShorthandInfo Css_shorthand_info[] = { - {"background", CssShorthandInfo::CSS_SHORTHAND_BACKGROUND, + {"background", CssShorthandInfo::CSS_SHORTHAND_MULTIPLE, Css_background_properties}, // For 'background-position', no properties are needed, because // these (CSS_PROPERTY_X_BACKGROUND_POSITION_X and @@ -733,6 +732,7 @@ bool CssParser::tokenMatchesProperty(CssPropertyName prop, CssValueType *type) } break; + case CSS_TYPE_BACKGROUND_POSITION: case CSS_TYPE_LENGTH_PERCENTAGE: case CSS_TYPE_LENGTH_PERCENTAGE_NUMBER: case CSS_TYPE_LENGTH: @@ -1059,6 +1059,18 @@ bool CssParser::parseValue(CssPropertyName prop, } break; + case CSS_TYPE_BACKGROUND_POSITION: + CssPropertyValue posX, posY; + if (parseValue(prop, CSS_TYPE_LENGTH_PERCENTAGE, &posX) && + parseValue(prop, CSS_TYPE_LENGTH_PERCENTAGE, &posY)) { + CssBackgroundPosition *position = (CssBackgroundPosition *) malloc(sizeof(CssBackgroundPosition)); + position->posX = posX.intVal; + position->posY = posY.intVal; + val->posVal = position; + ret = true; + } + break; + case CSS_TYPE_UNUSED: /* nothing */ break; diff --git a/src/styleengine.cc b/src/styleengine.cc index 4c1a315c..8d425371 100644 --- a/src/styleengine.cc +++ b/src/styleengine.cc @@ -629,23 +629,21 @@ void StyleEngine::apply (int i, StyleAttrs *attrs, CssPropertyList *props, else if (attrs->wordSpacing < -1000) attrs->wordSpacing = -1000; break; - case CSS_PROPERTY_X_BACKGROUND_POSITION_X: + case CSS_PROPERTY_BACKGROUND_POSITION: if (p->type == CSS_TYPE_ENUM) // Enums are sorted: 0 = left = 0%; 1 = center = 50%; // 2 = right = 100%. attrs->backgroundPositionX = - createPerLength (0.5 * (double)p->value.intVal); + createPerLength (0.5 * (double)p->value.posVal->posX); else - computeLength (&attrs->backgroundPositionX, p->value.intVal, + computeLength (&attrs->backgroundPositionX, p->value.posVal->posX, attrs->font); - break; - case CSS_PROPERTY_X_BACKGROUND_POSITION_Y: if (p->type == CSS_TYPE_ENUM) // See comment above. attrs->backgroundPositionY = - createPerLength (0.5 * (double)p->value.intVal); + createPerLength (0.5 * (double)p->value.posVal->posY); else - computeLength (&attrs->backgroundPositionY, p->value.intVal, + computeLength (&attrs->backgroundPositionY, p->value.posVal->posY, attrs->font); break; case PROPERTY_X_LINK: -- cgit v1.2.3