Created
January 26, 2012 20:17
-
-
Save anonymous/1684850 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 891bad0c97b02aa0c2ba61b02d27063394836e17 | |
Author: Alexis Menard <alexis.menard@openbossa.org> | |
Date: Thu Jan 26 17:05:08 2012 -0300 | |
Shorthand 2 | |
diff --git a/Source/WebCore/css/CSSParser.cpp b/Source/WebCore/css/CSSParser.cpp | |
index a56dc6c..3486cf3 100644 | |
--- a/Source/WebCore/css/CSSParser.cpp | |
+++ b/Source/WebCore/css/CSSParser.cpp | |
@@ -837,15 +837,22 @@ bool CSSParser::parseValue(int propId, bool important) | |
int num = inShorthand() ? 1 : m_valueList->size(); | |
+ CSSPropertyID propertyId = static_cast<CSSPropertyID>(propId); | |
+ const ShorthandHandler& handler = m_shorthandParser.shorthandHandler(propertyId); | |
+ | |
if (id == CSSValueInherit) { | |
if (num != 1) | |
return false; | |
+ if (handler.isValid()) | |
+ handler.expand(propId, this, important, true); | |
addProperty(propId, cssValuePool()->createInheritedValue(), important); | |
return true; | |
} | |
else if (id == CSSValueInitial) { | |
if (num != 1) | |
return false; | |
+ if (handler.isValid()) | |
+ handler.expand(propId, this, important, false); | |
addProperty(propId, cssValuePool()->createExplicitInitialValue(), important); | |
return true; | |
} | |
@@ -853,9 +860,7 @@ bool CSSParser::parseValue(int propId, bool important) | |
bool validPrimitive = false; | |
RefPtr<CSSValue> parsedValue; | |
- CSSPropertyID propertyId = static_cast<CSSPropertyID>(propId); | |
// Before continuing lets look if there is a parsing handler. | |
- const ShorthandHandler& handler = m_shorthandParser.shorthandHandler(propertyId); | |
if (handler.isValid()) | |
return handler.parseValue(propId, this, important); | |
diff --git a/Source/WebCore/css/CSSParserShorthands.cpp b/Source/WebCore/css/CSSParserShorthands.cpp | |
index 0dec6bc..97d414a 100644 | |
--- a/Source/WebCore/css/CSSParserShorthands.cpp | |
+++ b/Source/WebCore/css/CSSParserShorthands.cpp | |
@@ -32,6 +32,19 @@ | |
using namespace std; | |
namespace WebCore { | |
+ | |
+ | |
+static void addProperty(int propId, CSSParser* parser, bool important, bool inherit) | |
+{ | |
+ if (inherit) | |
+ parser->addProperty(propId, parser->cssValuePool()->createInheritedValue(), important); | |
+ else if (parser->m_implicitShorthand) | |
+ parser->addProperty(propId, parser->cssValuePool()->createImplicitInitialValue(), important); | |
+ else | |
+ parser->addProperty(propId, parser->cssValuePool()->createExplicitInitialValue(), important); | |
+ | |
+} | |
+ | |
template <CSSPropertyID one = CSSPropertyInvalid, CSSPropertyID two = CSSPropertyInvalid> | |
class TwoValuesShorthandHandler { | |
public: | |
@@ -57,9 +70,16 @@ public: | |
return false; | |
} | |
+ static void expand(int propId, CSSParser* parser, bool important, bool inherit) | |
+ { | |
+ ShorthandScope scope(parser, propId); | |
+ addProperty(one, parser, important, inherit); | |
+ addProperty(two, parser, important, inherit); | |
+ } | |
+ | |
static ShorthandHandler createHandler() | |
{ | |
- return ShorthandHandler(&parseValue); | |
+ return ShorthandHandler(&parseValue, &expand); | |
} | |
}; | |
@@ -124,9 +144,34 @@ public: | |
return true; | |
} | |
+ static void expand(int propId, CSSParser* parser, bool important, bool inherit) | |
+ { | |
+ ShorthandScope scope(parser, propId); | |
+ ShorthandHandler handler = CSSParserShorthands::sharedCSSParserShorthands().shorthandHandler(one); | |
+ if (handler.isValid()) | |
+ handler.expand(one, parser, important, inherit); | |
+ else | |
+ addProperty(one, parser, important, inherit); | |
+ handler = CSSParserShorthands::sharedCSSParserShorthands().shorthandHandler(two); | |
+ if (handler.isValid()) | |
+ handler.expand(two, parser, important, inherit); | |
+ else | |
+ addProperty(two, parser, important, inherit); | |
+ handler = CSSParserShorthands::sharedCSSParserShorthands().shorthandHandler(three); | |
+ if (handler.isValid()) | |
+ handler.expand(three, parser, important, inherit); | |
+ else | |
+ addProperty(three, parser, important, inherit); | |
+ handler = CSSParserShorthands::sharedCSSParserShorthands().shorthandHandler(four); | |
+ if (handler.isValid()) | |
+ handler.expand(four, parser, important, inherit); | |
+ else | |
+ addProperty(four, parser, important, inherit); | |
+ } | |
+ | |
static ShorthandHandler createHandler() | |
{ | |
- return ShorthandHandler(&parseValue); | |
+ return ShorthandHandler(&parseValue, &expand); | |
} | |
}; | |
@@ -177,9 +222,21 @@ public: | |
return true; | |
} | |
+ static void expand(int propId, CSSParser* parser, bool important, bool inherit) | |
+ { | |
+ ShorthandScope scope(parser, propId); | |
+ for (unsigned i = 0; i < numProperties; ++i) { | |
+ ShorthandHandler handler = CSSParserShorthands::sharedCSSParserShorthands().shorthandHandler(static_cast<CSSPropertyID>(properties[i])); | |
+ if (handler.isValid()) | |
+ handler.expand(properties[i], parser, important, inherit); | |
+ else | |
+ addProperty(properties[i], parser, important, inherit); | |
+ } | |
+ } | |
+ | |
static ShorthandHandler createHandler() | |
{ | |
- return ShorthandHandler(&parseValue); | |
+ return ShorthandHandler(&parseValue, &expand); | |
} | |
private: | |
static const int properties[5]; | |
@@ -212,7 +269,7 @@ public: | |
while (parser->m_valueList->current()) { | |
CSSParserValue* val = parser->m_valueList->current(); | |
if (val->unit == CSSParserValue::Operator && val->iValue == ',') { | |
- // We hit the end. Fill in all remaining values with the initial value. | |
+ // We hit the end. Fill in all remaining values with the initial value. | |
parser->m_valueList->next(); | |
for (i = 0; i < numProperties; ++i) { | |
if (properties[i] == CSSPropertyBackgroundColor && parsedProperty[i]) | |
@@ -322,9 +379,21 @@ public: | |
return true; | |
} | |
+ static void expand(int propId, CSSParser* parser, bool important, bool inherit) | |
+ { | |
+ ShorthandScope scope(parser, propId); | |
+ for (unsigned i = 0; i < numProperties; ++i) { | |
+ ShorthandHandler handler = CSSParserShorthands::sharedCSSParserShorthands().shorthandHandler(static_cast<CSSPropertyID>(properties[i])); | |
+ if (handler.isValid()) | |
+ handler.expand(properties[i], parser, important, inherit); | |
+ else | |
+ addProperty(properties[i], parser, important, inherit); | |
+ } | |
+ } | |
+ | |
static ShorthandHandler createHandler() | |
{ | |
- return ShorthandHandler(&parseValue); | |
+ return ShorthandHandler(&parseValue, &expand); | |
} | |
private: | |
static const int properties[7]; | |
diff --git a/Source/WebCore/css/CSSParserShorthands.h b/Source/WebCore/css/CSSParserShorthands.h | |
index 5c6dd1e..45e5a40 100644 | |
--- a/Source/WebCore/css/CSSParserShorthands.h | |
+++ b/Source/WebCore/css/CSSParserShorthands.h | |
@@ -37,13 +37,18 @@ class CSSParser; | |
class ShorthandHandler { | |
public: | |
typedef bool (*ParseFunction)(int, CSSParser*, bool); | |
- ShorthandHandler() : m_parse(0) { } | |
- ShorthandHandler(ParseFunction parse) : m_parse(parse) { } | |
+ typedef void (*ExpandFunction)(int, CSSParser*, bool, bool); | |
+ ShorthandHandler() : m_parse(0), m_expand(0) { } | |
+ ShorthandHandler(ParseFunction parse, ExpandFunction expand) : m_parse(parse), m_expand(expand) { } | |
bool parseValue(int propId, CSSParser* parser, bool important) const { ASSERT(m_parse); return (*m_parse)(propId, parser, important); } | |
- bool isValid() const { return m_parse; } | |
+ void expand(int propId, CSSParser* parser, bool important, bool inherit) const { ASSERT(m_expand); (*m_expand)(propId, parser, important, inherit); } | |
+ | |
+ bool isValid() const { return (m_parse && m_expand) ;} | |
ParseFunction parseFunction() { return m_parse; } | |
+ ExpandFunction expandFunction() { return m_expand; } | |
private: | |
ParseFunction m_parse; | |
+ ExpandFunction m_expand; | |
}; | |
class CSSParserShorthands { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment