diff options
author | Sebastian Geerken <devnull@localhost> | 2014-09-15 13:45:37 +0200 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2014-09-15 13:45:37 +0200 |
commit | a4d92f6ec2a1bf92c1f0bc408a7060a774bd027d (patch) | |
tree | d573fadd93d460bb3c40fcc88931ac88b637b65a | |
parent | 0941ffb6ccfe4f44ff5add68dbb57626c8b18666 (diff) |
Extended CSS parser and dw::core::Style by 'z-index'.
-rw-r--r-- | dw/style.cc | 4 | ||||
-rw-r--r-- | dw/style.hh | 14 | ||||
-rw-r--r-- | src/cssparser.cc | 19 | ||||
-rw-r--r-- | src/styleengine.cc | 6 |
4 files changed, 38 insertions, 5 deletions
diff --git a/dw/style.cc b/dw/style.cc index d548d209..1c2978b4 100644 --- a/dw/style.cc +++ b/dw/style.cc @@ -92,6 +92,7 @@ void StyleAttrs::initValues () display = DISPLAY_INLINE; whiteSpace = WHITE_SPACE_NORMAL; cursor = CURSOR_DEFAULT; + zIndex = Z_INDEX_AUTO; } /** @@ -200,6 +201,7 @@ bool StyleAttrs::equals (object::Object *other) { listStylePosition == otherAttrs->listStylePosition && listStyleType == otherAttrs->listStyleType && cursor == otherAttrs->cursor && + zIndex == otherAttrs->zIndex && x_link == otherAttrs->x_link && x_lang[0] == otherAttrs->x_lang[0] && x_lang[1] == otherAttrs->x_lang[1] && @@ -256,6 +258,7 @@ int StyleAttrs::hashValue () { listStylePosition + listStyleType + cursor + + zIndex + x_link + x_lang[0] + x_lang[1] + x_img + @@ -376,6 +379,7 @@ void Style::copyAttrs (StyleAttrs *attrs) listStylePosition = attrs->listStylePosition; listStyleType = attrs->listStyleType; cursor = attrs->cursor; + zIndex = attrs->zIndex; x_link = attrs->x_link; x_lang[0] = attrs->x_lang[0]; x_lang[1] = attrs->x_lang[1]; diff --git a/dw/style.hh b/dw/style.hh index bda567ce..9c6bedf1 100644 --- a/dw/style.hh +++ b/dw/style.hh @@ -7,6 +7,8 @@ # error Do not include this file directly, use "core.hh" instead. #endif +#include <limits.h> + #include "../lout/signal.hh" #include "../lout/debug.hh" @@ -367,6 +369,17 @@ enum ClearType { CLEAR_NONE }; +enum { + /** + * \brief 'z-index' is stored as int; use this for the value 'auto'. + * + * Only some random value, which has to be checked explicitly; do + * not compare this (less or greater) to integer values of + * 'z-index'. + */ + Z_INDEX_AUTO = INT_MAX +}; + /** * \brief Type for representing all lengths within dw::core::style. * @@ -544,6 +557,7 @@ public: ListStylePosition listStylePosition; ListStyleType listStyleType; Cursor cursor; + int zIndex; int x_link; int x_img; diff --git a/src/cssparser.cc b/src/cssparser.cc index c02d817e..c400a8e6 100644 --- a/src/cssparser.cc +++ b/src/cssparser.cc @@ -273,7 +273,7 @@ const CssPropertyInfo Css_property_info[CSS_PROPERTY_LAST] = { {"width", {CSS_TYPE_LENGTH_PERCENTAGE, CSS_TYPE_AUTO, CSS_TYPE_UNUSED}, NULL}, {"word-spacing", {CSS_TYPE_ENUM, CSS_TYPE_SIGNED_LENGTH, CSS_TYPE_UNUSED}, Css_word_spacing_enum_vals}, - {"z-index", {CSS_TYPE_UNUSED}, NULL}, + {"z-index", {CSS_TYPE_INTEGER, CSS_TYPE_AUTO, CSS_TYPE_UNUSED}, NULL}, /* These are extensions, for internal used, and never parsed. */ {"x-link", {CSS_TYPE_INTEGER, CSS_TYPE_UNUSED}, NULL}, @@ -789,9 +789,12 @@ bool CssParser::tokenMatchesProperty(CssPropertyName prop, CssValueType *type) return true; break; - case CSS_TYPE_UNUSED: case CSS_TYPE_INTEGER: - /* Not used for parser values. */ + if (ttype == CSS_TK_DECINT) + return true; + break; + + case CSS_TYPE_UNUSED: default: assert(false); break; @@ -1170,12 +1173,18 @@ bool CssParser::parseValue(CssPropertyName prop, } break; + case CSS_TYPE_INTEGER: + if (ttype == CSS_TK_DECINT) { + val->intVal = strtol(tval, NULL, 10); + ret = true; + nextToken(); + } + break; + case CSS_TYPE_UNUSED: /* nothing */ break; - case CSS_TYPE_INTEGER: - /* Not used for parser values. */ default: assert(false); /* not reached */ } diff --git a/src/styleengine.cc b/src/styleengine.cc index f5f0a315..706340b6 100644 --- a/src/styleengine.cc +++ b/src/styleengine.cc @@ -725,6 +725,12 @@ void StyleEngine::apply (int i, StyleAttrs *attrs, CssPropertyList *props, case CSS_PROPERTY_MAX_HEIGHT: computeLength (&attrs->maxHeight, p->value.intVal, attrs->font); break; + case CSS_PROPERTY_Z_INDEX: + if (p->type == CSS_LENGTH_TYPE_AUTO) + attrs->zIndex = dw::core::style::Z_INDEX_AUTO; + else + attrs->zIndex = p->value.intVal; + break; case PROPERTY_X_LINK: attrs->x_link = p->value.intVal; break; |