Make CSS variable names case-insensitive.

https://bugs.webkit.org/show_bug.cgi?id=98712

Reviewed by Tony Chang.

Source/WebCore:

This patch modifies the parser to normalize all variable names to lower case,
making variable definitions consistent with other property names, which are also case insensitive.
Spec: http://dev.w3.org/csswg/css-variables/#defining-variables

Test: fast/css/variables/case-insensitive.html

* css/CSSParser.cpp:
(WebCore::CSSParser::createPrimitiveNumericValue):
(WebCore):
(WebCore::CSSParser::createPrimitiveVariableNameValue):
(WebCore::CSSParser::parseValidPrimitive):
(WebCore::CSSParser::parseValue):
(WebCore::CSSParser::storeVariableDeclaration):
(WebCore::CSSParserString::lowerSubstring):
Added function to compute a lower case substring as an AtomicString from a CSSParserString.
* css/CSSParser.h:
(CSSParser):
* css/CSSParserValues.h:
(CSSParserString):
(WebCore::CSSParserString::lowerSubstring):

LayoutTests:

Add test that variable names are match correctly when different case is used.

* fast/css/variables/case-insensitive-expected.html: Added.
* fast/css/variables/case-insensitive.html: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@131313 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c0f17de9
2012-10-15 Luke Macpherson <macpherson@chromium.org>
Make CSS variable names case-insensitive.
https://bugs.webkit.org/show_bug.cgi?id=98712
Reviewed by Tony Chang.
Add test that variable names are match correctly when different case is used.
* fast/css/variables/case-insensitive-expected.html: Added.
* fast/css/variables/case-insensitive.html: Added.
2012-10-15 Vsevolod Vlasov <vsevik@chromium.org>
Unreviewed inspector tests fix.
......
<!DOCTYPE html>
<html>
<style>
div {
background-color: green;
}
</style>
<div>This text should have a green background.</div>
</html>
<!DOCTYPE html>
<html>
<script>
internals.settings.setCSSVariablesEnabled(true);
</script>
<style>
div {
background-color: -webkit-var(NaMe);
-webkit-var-nAmE: green;
}
</style>
<div>This text should have a green background.</div>
</html>
2012-10-15 Luke Macpherson <macpherson@chromium.org>
Make CSS variable names case-insensitive.
https://bugs.webkit.org/show_bug.cgi?id=98712
Reviewed by Tony Chang.
This patch modifies the parser to normalize all variable names to lower case,
making variable definitions consistent with other property names, which are also case insensitive.
Spec: http://dev.w3.org/csswg/css-variables/#defining-variables
Test: fast/css/variables/case-insensitive.html
* css/CSSParser.cpp:
(WebCore::CSSParser::createPrimitiveNumericValue):
(WebCore):
(WebCore::CSSParser::createPrimitiveVariableNameValue):
(WebCore::CSSParser::parseValidPrimitive):
(WebCore::CSSParser::parseValue):
(WebCore::CSSParser::storeVariableDeclaration):
(WebCore::CSSParserString::lowerSubstring):
Added function to compute a lower case substring as an AtomicString from a CSSParserString.
* css/CSSParser.h:
(CSSParser):
* css/CSSParserValues.h:
(CSSParserString):
(WebCore::CSSParserString::lowerSubstring):
2012-10-15 Michael Saboff <msaboff@apple.com>
Update RenderText to use String instead of UChar* for text
......
......@@ -291,31 +291,50 @@ CSSParser::~CSSParser()
}
template <typename CharacterType>
ALWAYS_INLINE static void makeLower(CharacterType* characters, unsigned length)
ALWAYS_INLINE static void makeLower(const CharacterType* input, CharacterType* output, unsigned length)
{
// FIXME: If we need Unicode lowercasing here, then we probably want the real kind
// that can potentially change the length of the string rather than the character
// by character kind. If we don't need Unicode lowercasing, it would be good to
// simplify this function.
if (charactersAreAllASCII(characters, length)) {
if (charactersAreAllASCII(input, length)) {
// Fast case for all-ASCII.
for (unsigned i = 0; i < length; i++)
characters[i] = toASCIILower(characters[i]);
output[i] = toASCIILower(input[i]);
} else {
for (unsigned i = 0; i < length; i++)
characters[i] = Unicode::toLower(characters[i]);
output[i] = Unicode::toLower(input[i]);
}
}
void CSSParserString::lower()
{
if (is8Bit()) {
makeLower(characters8(), length());
makeLower(characters8(), characters8(), length());
return;
}
makeLower(characters16(), length());
makeLower(characters16(), characters16(), length());
}
AtomicString CSSParserString::lowerSubstring(unsigned position, unsigned length) const
{
ASSERT(m_length >= position + length);
RefPtr<StringImpl> result;
if (is8Bit()) {
LChar* buffer;
result = StringImpl::createUninitialized(length, buffer);
makeLower(characters8() + position, buffer, length);
} else {
UChar* buffer = 0;
result = StringImpl::createUninitialized(length, buffer);
makeLower(characters16() + position, buffer, length);
}
return AtomicString(result);
}
void CSSParser::setupParser(const char* prefix, const String& string, const char* suffix)
......@@ -1575,7 +1594,7 @@ inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveNumericValue(CSSP
{
#if ENABLE(CSS_VARIABLES)
if (value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME)
return CSSPrimitiveValue::create(value->string, CSSPrimitiveValue::CSS_VARIABLE_NAME);
return createPrimitiveVariableNameValue(value);
#endif
if (m_parsedCalculation) {
......@@ -1602,6 +1621,15 @@ inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveStringValue(CSSPa
return cssValuePool().createValue(value->string, CSSPrimitiveValue::CSS_STRING);
}
#if ENABLE(CSS_VARIABLES)
inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveVariableNameValue(CSSParserValue* value)
{
ASSERT(value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME);
AtomicString variableName = String(value->string).lower();
return CSSPrimitiveValue::create(variableName, CSSPrimitiveValue::CSS_VARIABLE_NAME);
}
#endif
static inline bool isComma(CSSParserValue* value)
{
return value && value->unit == CSSParserValue::Operator && value->iValue == ',';
......@@ -1642,7 +1670,7 @@ inline PassRefPtr<CSSPrimitiveValue> CSSParser::parseValidPrimitive(int identifi
#endif
#if ENABLE(CSS_VARIABLES)
if (value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME)
return CSSPrimitiveValue::create(value->string, CSSPrimitiveValue::CSS_VARIABLE_NAME);
return createPrimitiveVariableNameValue(value);
#endif
if (value->unit >= CSSParserValue::Q_EMS)
return CSSPrimitiveValue::createAllowingMarginQuirk(value->fValue, CSSPrimitiveValue::CSS_EMS);
......@@ -1685,7 +1713,7 @@ bool CSSParser::parseValue(CSSPropertyID propId, bool important)
#if ENABLE(CSS_VARIABLES)
if (!id && value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME && num == 1) {
addProperty(propId, CSSPrimitiveValue::create(value->string, CSSPrimitiveValue::CSS_VARIABLE_NAME), important);
addProperty(propId, createPrimitiveVariableNameValue(value), important);
m_valueList->next();
return true;
}
......@@ -3028,8 +3056,10 @@ void CSSParser::storeVariableDeclaration(const CSSParserString& name, PassOwnPtr
if (!value)
return;
ASSERT(name.length() > 12);
AtomicString variableName = name.is8Bit() ? AtomicString(name.characters8() + 12, name.length() - 12) : AtomicString(name.characters16() + 12, name.length() - 12);
static const unsigned prefixLength = sizeof("-webkit-var-") - 1;
ASSERT(name.length() > prefixLength);
AtomicString variableName = name.lowerSubstring(prefixLength, name.length() - prefixLength);
StringBuilder builder;
for (unsigned i = 0, size = value->size(); i < size; i++) {
......@@ -3040,7 +3070,7 @@ void CSSParser::storeVariableDeclaration(const CSSParserString& name, PassOwnPtr
return;
builder.append(cssValue->cssText());
}
addProperty(CSSPropertyVariable, CSSVariableValue::create(variableName, builder.toString()), important, false);
addProperty(CSSPropertyVariable, CSSVariableValue::create(variableName, builder.toString().lower()), important, false);
}
#endif
......
......@@ -366,6 +366,9 @@ public:
PassRefPtr<CSSPrimitiveValue> createPrimitiveNumericValue(CSSParserValue*);
PassRefPtr<CSSPrimitiveValue> createPrimitiveStringValue(CSSParserValue*);
#if ENABLE(CSS_VARIABLES)
PassRefPtr<CSSPrimitiveValue> createPrimitiveVariableNameValue(CSSParserValue*);
#endif
static KURL completeURL(const CSSParserContext&, const String& url);
......
......@@ -94,6 +94,8 @@ struct CSSParserString {
operator String() const { return is8Bit() ? String(m_data.characters8, m_length) : String(m_data.characters16, m_length); }
operator AtomicString() const { return is8Bit() ? AtomicString(m_data.characters8, m_length) : AtomicString(m_data.characters16, m_length); }
AtomicString lowerSubstring(unsigned position, unsigned length) const;
union {
LChar* characters8;
UChar* characters16;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment