#include "config.h"
#include "CSSParser.h"
#include "CString.h"
#include "CSSTimingFunctionValue.h"
#include "CSSBorderImageValue.h"
#include "CSSCharsetRule.h"
#include "CSSCursorImageValue.h"
#include "CSSHelper.h"
#include "CSSImageValue.h"
#include "CSSFontFaceRule.h"
#include "CSSFontFaceSrcValue.h"
#include "CSSImportRule.h"
#include "CSSInheritedValue.h"
#include "CSSInitialValue.h"
#include "CSSMediaRule.h"
#include "CSSMutableStyleDeclaration.h"
#include "CSSPrimitiveValue.h"
#include "CSSProperty.h"
#include "CSSPropertyNames.h"
#include "CSSQuirkPrimitiveValue.h"
#include "CSSRuleList.h"
#include "WebKitCSSKeyframeRule.h"
#include "WebKitCSSKeyframesRule.h"
#include "CSSSelector.h"
#include "CSSStyleRule.h"
#include "CSSStyleSheet.h"
#include "WebKitCSSTransformValue.h"
#include "CSSUnicodeRangeValue.h"
#include "CSSValueKeywords.h"
#include "CSSValueList.h"
#include "Counter.h"
#include "Document.h"
#include "FloatConversion.h"
#include "FontFamilyValue.h"
#include "FontValue.h"
#include "KURL.h"
#include "MediaList.h"
#include "MediaQueryExp.h"
#include "Pair.h"
#include "Rect.h"
#include "ShadowValue.h"
#include <kjs/dtoa.h>
#if ENABLE(DASHBOARD_SUPPORT)
#include "DashboardRegion.h"
#endif
#define YYDEBUG 0
#if YYDEBUG > 0
extern int cssyydebug;
#endif
extern int cssyyparse(void* parser);
using namespace std;
using namespace WTF;
namespace WebCore {
ValueList::~ValueList()
{
size_t numValues = m_values.size();
for (size_t i = 0; i < numValues; i++)
if (m_values[i].unit == Value::Function)
delete m_values[i].function;
}
namespace {
class ShorthandScope {
public:
ShorthandScope(CSSParser* parser, int propId) : m_parser(parser)
{
if (!(m_parser->m_inParseShorthand++))
m_parser->m_currentShorthand = propId;
}
~ShorthandScope()
{
if (!(--m_parser->m_inParseShorthand))
m_parser->m_currentShorthand = 0;
}
private:
CSSParser* m_parser;
};
}
CSSParser* CSSParser::currentParser = 0;
CSSParser::CSSParser(bool strictParsing)
: m_floatingMediaQuery(0)
, m_floatingMediaQueryExp(0)
, m_floatingMediaQueryExpList(0)
{
#ifdef CSS_DEBUG
kdDebug(6080) << "CSSParser::CSSParser this=" << this << endl;
#endif
strict = strictParsing;
parsedProperties = (CSSProperty **)fastMalloc(32 * sizeof(CSSProperty *));
numParsedProperties = 0;
maxParsedProperties = 32;
data = 0;
valueList = 0;
id = 0;
important = false;
m_inParseShorthand = 0;
m_currentShorthand = 0;
m_implicitShorthand = false;
defaultNamespace = starAtom;
yy_start = 1;
#if YYDEBUG > 0
cssyydebug = 1;
#endif
}
CSSParser::~CSSParser()
{
clearProperties();
fastFree(parsedProperties);
delete valueList;
fastFree(data);
if (m_floatingMediaQueryExpList) {
deleteAllValues(*m_floatingMediaQueryExpList);
delete m_floatingMediaQueryExpList;
}
delete m_floatingMediaQueryExp;
delete m_floatingMediaQuery;
deleteAllValues(m_floatingSelectors);
deleteAllValues(m_floatingValueLists);
deleteAllValues(m_floatingFunctions);
}
void ParseString::lower()
{
UChar ored = 0;
for (int i = 0; i < length; i++)
ored |= characters[i];
if (ored & ~0x7F)
for (int i = 0; i < length; i++)
characters[i] = Unicode::toLower(characters[i]);
else
for (int i = 0; i < length; i++)
characters[i] = toASCIILower(characters[i]);
}
void CSSParser::setupParser(const char* prefix, const String& string, const char* suffix)
{
int length = string.length() + strlen(prefix) + strlen(suffix) + 2;
if (data)
fastFree(data);
data = static_cast<UChar*>(fastMalloc(length * sizeof(UChar)));
for (unsigned i = 0; i < strlen(prefix); i++)
data[i] = prefix[i];
memcpy(data + strlen(prefix), string.characters(), string.length() * sizeof(UChar));
unsigned start = strlen(prefix) + string.length();
unsigned end = start + strlen(suffix);
for (unsigned i = start; i < end; i++)
data[i] = suffix[i - start];
data[length - 1] = 0;
data[length - 2] = 0;
yy_hold_char = 0;
yyleng = 0;
yytext = yy_c_buf_p = data;
yy_hold_char = *yy_c_buf_p;
}
void CSSParser::parseSheet(CSSStyleSheet* sheet, const String& string)
{
styleElement = sheet;
defaultNamespace = starAtom;
setupParser("", string, "");
CSSParser* old = currentParser;
currentParser = this;
cssyyparse(this);
currentParser = old;
rule = 0;
}
PassRefPtr<CSSRule> CSSParser::parseRule(CSSStyleSheet *sheet, const String &string)
{
styleElement = sheet;
setupParser("@-webkit-rule{", string, "} ");
CSSParser* old = currentParser;
currentParser = this;
cssyyparse(this);
currentParser = old;
return rule.release();
}
PassRefPtr<CSSRule> CSSParser::parseKeyframeRule(CSSStyleSheet *sheet, const String &string)
{
styleElement = sheet;
setupParser("@-webkit-keyframe-rule{ ", string, "} ");
CSSParser* old = currentParser;
currentParser = this;
cssyyparse(this);
currentParser = old;
return keyframe.release();
}
bool CSSParser::parseValue(CSSMutableStyleDeclaration *declaration, int _id, const String &string, bool _important)
{
styleElement = declaration->stylesheet();
setupParser("@-webkit-value{", string, "} ");
id = _id;
important = _important;
CSSParser* old = currentParser;
currentParser = this;
cssyyparse(this);
currentParser = old;
rule = 0;
bool ok = false;
if (numParsedProperties) {
ok = true;
declaration->addParsedProperties(parsedProperties, numParsedProperties);
clearProperties();
}
return ok;
}
bool CSSParser::parseColor(RGBA32& color, const String &string, bool strict)
{
color = 0;
CSSParser parser(true);
if (!parser.parseColor(string, color, strict)) {
RefPtr<CSSMutableStyleDeclaration> dummyStyleDeclaration(new CSSMutableStyleDeclaration);
if (parser.parseColor(dummyStyleDeclaration.get(), string)) {
CSSValue* value = parser.parsedProperties[0]->value();
if (value->cssValueType() == CSSValue::CSS_PRIMITIVE_VALUE) {
CSSPrimitiveValue *primitiveValue = static_cast<CSSPrimitiveValue *>(value);
color = primitiveValue->getRGBColorValue();
}
} else
return false;
}
return true;
}
bool CSSParser::parseColor(CSSMutableStyleDeclaration *declaration, const String &string)
{
styleElement = declaration->stylesheet();
setupParser("@-webkit-decls{color:", string, "} ");
CSSParser* old = currentParser;
currentParser = this;
cssyyparse(this);
currentParser = old;
rule = 0;
bool ok = false;
if (numParsedProperties && parsedProperties[0]->m_id == CSS_PROP_COLOR)
ok = true;
return ok;
}
bool CSSParser::parseDeclaration(CSSMutableStyleDeclaration *declaration, const String &string)
{
styleElement = declaration->stylesheet();
setupParser("@-webkit-decls{", string, "} ");
CSSParser* old = currentParser;
currentParser = this;
cssyyparse(this);
currentParser = old;
rule = 0;
bool ok = false;
if (numParsedProperties) {
ok = true;
declaration->addParsedProperties(parsedProperties, numParsedProperties);
clearProperties();
}
return ok;
}
bool CSSParser::parseMediaQuery(MediaList* queries, const String& string)
{
if (string.isEmpty() || string.isNull()) {
return true;
}
mediaQuery = 0;
setupParser ("@-webkit-mediaquery ", string, "} ");
CSSParser* old = currentParser;
currentParser = this;
cssyyparse(this);
currentParser = old;
bool ok = false;
if (mediaQuery) {
ok = true;
queries->appendMediaQuery(mediaQuery);
mediaQuery = 0;
}
return ok;
}
void CSSParser::addProperty(int propId, PassRefPtr<CSSValue> value, bool important)
{
CSSProperty *prop = new CSSProperty(propId, value, important, m_currentShorthand, m_implicitShorthand);
if (numParsedProperties >= maxParsedProperties) {
maxParsedProperties += 32;
parsedProperties = (CSSProperty **)fastRealloc(parsedProperties,
maxParsedProperties*sizeof(CSSProperty *));
}
parsedProperties[numParsedProperties++] = prop;
}
void CSSParser::rollbackLastProperties(int num)
{
ASSERT(num >= 0);
ASSERT(numParsedProperties >= num);
for (int i = 0; i < num; ++i)
delete parsedProperties[--numParsedProperties];
}
void CSSParser::clearProperties()
{
for (int i = 0; i < numParsedProperties; i++)
delete parsedProperties[i];
numParsedProperties = 0;
}
Document *CSSParser::document() const
{
StyleBase *root = styleElement;
Document *doc = 0;
while (root->parent())
root = root->parent();
if (root->isCSSStyleSheet())
doc = static_cast<CSSStyleSheet*>(root)->doc();
return doc;
}
bool CSSParser::validUnit(Value* value, Units unitflags, bool strict)
{
if (unitflags & FNonNeg && value->fValue < 0)
return false;
bool b = false;
switch(value->unit) {
case CSSPrimitiveValue::CSS_NUMBER:
b = (unitflags & FNumber);
if (!b && ((unitflags & (FLength | FAngle | FTime)) && (value->fValue == 0 || !strict))) {
value->unit = (unitflags & FLength) ? CSSPrimitiveValue::CSS_PX :
((unitflags & FAngle) ? CSSPrimitiveValue::CSS_DEG : CSSPrimitiveValue::CSS_S);
b = true;
}
if (!b && (unitflags & FInteger) && value->isInt)
b = true;
break;
case CSSPrimitiveValue::CSS_PERCENTAGE:
b = (unitflags & FPercent);
break;
case Value::Q_EMS:
case CSSPrimitiveValue::CSS_EMS:
case CSSPrimitiveValue::CSS_EXS:
case CSSPrimitiveValue::CSS_PX:
case CSSPrimitiveValue::CSS_CM:
case CSSPrimitiveValue::CSS_MM:
case CSSPrimitiveValue::CSS_IN:
case CSSPrimitiveValue::CSS_PT:
case CSSPrimitiveValue::CSS_PC:
b = (unitflags & FLength);
break;
case CSSPrimitiveValue::CSS_MS:
case CSSPrimitiveValue::CSS_S:
b = (unitflags & FTime);
break;
case CSSPrimitiveValue::CSS_DEG:
case CSSPrimitiveValue::CSS_RAD:
case CSSPrimitiveValue::CSS_GRAD:
b = (unitflags & FAngle);
break;
case CSSPrimitiveValue::CSS_HZ:
case CSSPrimitiveValue::CSS_KHZ:
case CSSPrimitiveValue::CSS_DIMENSION:
default:
break;
}
return b;
}
static int unitFromString(Value* value)
{
if (value->unit != CSSPrimitiveValue::CSS_IDENT || value->id)
return 0;
String str = domString(value->string);
if (str == "em")
return CSSPrimitiveValue::CSS_EMS;
if (str == "ex")
return CSSPrimitiveValue::CSS_EXS;
if (str == "px")
return CSSPrimitiveValue::CSS_PX;
if (str == "cm")
return CSSPrimitiveValue::CSS_CM;
if (str == "mm")
return CSSPrimitiveValue::CSS_MM;
if (str == "in")
return CSSPrimitiveValue::CSS_IN;
if (str == "pt")
return CSSPrimitiveValue::CSS_PT;
if (str == "pc")
return CSSPrimitiveValue::CSS_PC;
if (str == "deg")
return CSSPrimitiveValue::CSS_DEG;
if (str == "rad")
return CSSPrimitiveValue::CSS_RAD;
if (str == "grad")
return CSSPrimitiveValue::CSS_GRAD;
if (str == "ms")
return CSSPrimitiveValue::CSS_MS;
if (str == "s")
return CSSPrimitiveValue::CSS_S;
if (str == "Hz")
return CSSPrimitiveValue::CSS_HZ;
if (str == "kHz")
return CSSPrimitiveValue::CSS_KHZ;
return 0;
}
void CSSParser::checkForOrphanedUnits()
{
if (strict || inShorthand())
return;
Value* numericVal = 0;
unsigned size = valueList->size();
for (unsigned i = 0; i < size; i++) {
Value* value = valueList->valueAt(i);
if (numericVal) {
int unit = unitFromString(value);
if (unit) {
numericVal->unit = unit;
numericVal = 0;
valueList->deleteValueAt(i);
i--; size--;
continue;
}
}
numericVal = (value->unit == CSSPrimitiveValue::CSS_NUMBER) ? value : 0;
}
}
bool CSSParser::parseValue(int propId, bool important)
{
if (!valueList)
return false;
Value *value = valueList->current();
if (!value)
return false;
int id = value->id;
int num = inShorthand() ? 1 : valueList->size();
if (id == CSS_VAL_INHERIT) {
if (num != 1)
return false;
addProperty(propId, new CSSInheritedValue(), important);
return true;
}
else if (id == CSS_VAL_INITIAL) {
if (num != 1)
return false;
addProperty(propId, new CSSInitialValue(false), important);
return true;
}
bool valid_primitive = false;
RefPtr<CSSValue> parsedValue;
checkForOrphanedUnits();
switch (static_cast<CSSPropertyID>(propId)) {
case CSS_PROP_SIZE: case CSS_PROP_QUOTES: if (id)
valid_primitive = true;
break;
case CSS_PROP_UNICODE_BIDI: if (id == CSS_VAL_NORMAL ||
id == CSS_VAL_EMBED ||
id == CSS_VAL_BIDI_OVERRIDE)
valid_primitive = true;
break;
case CSS_PROP_POSITION: if (id == CSS_VAL_STATIC ||
id == CSS_VAL_RELATIVE ||
id == CSS_VAL_ABSOLUTE ||
id == CSS_VAL_FIXED)
valid_primitive = true;
break;
case CSS_PROP_PAGE_BREAK_AFTER: case CSS_PROP_PAGE_BREAK_BEFORE:
case CSS_PROP__WEBKIT_COLUMN_BREAK_AFTER:
case CSS_PROP__WEBKIT_COLUMN_BREAK_BEFORE:
if (id == CSS_VAL_AUTO ||
id == CSS_VAL_ALWAYS ||
id == CSS_VAL_AVOID ||
id == CSS_VAL_LEFT ||
id == CSS_VAL_RIGHT)
valid_primitive = true;
break;
case CSS_PROP_PAGE_BREAK_INSIDE: case CSS_PROP__WEBKIT_COLUMN_BREAK_INSIDE:
if (id == CSS_VAL_AUTO || id == CSS_VAL_AVOID)
valid_primitive = true;
break;
case CSS_PROP_EMPTY_CELLS: if (id == CSS_VAL_SHOW ||
id == CSS_VAL_HIDE)
valid_primitive = true;
break;
case CSS_PROP_CONTENT: return parseContent(propId, important);
break;
case CSS_PROP_WHITE_SPACE: if (id == CSS_VAL_NORMAL ||
id == CSS_VAL_PRE ||
id == CSS_VAL_PRE_WRAP ||
id == CSS_VAL_PRE_LINE ||
id == CSS_VAL_NOWRAP)
valid_primitive = true;
break;
case CSS_PROP_CLIP: if (id == CSS_VAL_AUTO)
valid_primitive = true;
else if (value->unit == Value::Function)
return parseShape(propId, important);
break;
case CSS_PROP_CAPTION_SIDE: if (id == CSS_VAL_LEFT || id == CSS_VAL_RIGHT ||
id == CSS_VAL_TOP || id == CSS_VAL_BOTTOM)
valid_primitive = true;
break;
case CSS_PROP_BORDER_COLLAPSE: if (id == CSS_VAL_COLLAPSE || id == CSS_VAL_SEPARATE)
valid_primitive = true;
break;
case CSS_PROP_VISIBILITY: if (id == CSS_VAL_VISIBLE || id == CSS_VAL_HIDDEN || id == CSS_VAL_COLLAPSE)
valid_primitive = true;
break;
case CSS_PROP_OVERFLOW: {
ShorthandScope scope(this, propId);
if (num != 1 || !parseValue(CSS_PROP_OVERFLOW_X, important))
return false;
CSSValue* value = parsedProperties[numParsedProperties - 1]->value();
addProperty(CSS_PROP_OVERFLOW_Y, value, important);
return true;
}
case CSS_PROP_OVERFLOW_X:
case CSS_PROP_OVERFLOW_Y: if (id == CSS_VAL_VISIBLE || id == CSS_VAL_HIDDEN || id == CSS_VAL_SCROLL || id == CSS_VAL_AUTO ||
id == CSS_VAL_OVERLAY || id == CSS_VAL__WEBKIT_MARQUEE)
valid_primitive = true;
break;
case CSS_PROP_LIST_STYLE_POSITION: if (id == CSS_VAL_INSIDE || id == CSS_VAL_OUTSIDE)
valid_primitive = true;
break;
case CSS_PROP_LIST_STYLE_TYPE:
if ((id >= CSS_VAL_DISC && id <= CSS_VAL_KATAKANA_IROHA) || id == CSS_VAL_NONE)
valid_primitive = true;
break;
case CSS_PROP_DISPLAY:
if ((id >= CSS_VAL_INLINE && id <= CSS_VAL__WEBKIT_INLINE_BOX) || id == CSS_VAL_NONE)
valid_primitive = true;
break;
case CSS_PROP_DIRECTION: if (id == CSS_VAL_LTR || id == CSS_VAL_RTL)
valid_primitive = true;
break;
case CSS_PROP_TEXT_TRANSFORM: if ((id >= CSS_VAL_CAPITALIZE && id <= CSS_VAL_LOWERCASE) || id == CSS_VAL_NONE)
valid_primitive = true;
break;
case CSS_PROP_FLOAT: if (id == CSS_VAL_LEFT || id == CSS_VAL_RIGHT ||
id == CSS_VAL_NONE || id == CSS_VAL_CENTER)
valid_primitive = true;
break;
case CSS_PROP_CLEAR: if (id == CSS_VAL_NONE || id == CSS_VAL_LEFT ||
id == CSS_VAL_RIGHT|| id == CSS_VAL_BOTH)
valid_primitive = true;
break;
case CSS_PROP_TEXT_ALIGN:
if ((id >= CSS_VAL__WEBKIT_AUTO && id <= CSS_VAL__WEBKIT_CENTER) || id == CSS_VAL_START || id == CSS_VAL_END ||
value->unit == CSSPrimitiveValue::CSS_STRING)
valid_primitive = true;
break;
case CSS_PROP_OUTLINE_STYLE: if (id == CSS_VAL_AUTO) {
valid_primitive = true;
break;
} case CSS_PROP_BORDER_TOP_STYLE: case CSS_PROP_BORDER_RIGHT_STYLE: case CSS_PROP_BORDER_BOTTOM_STYLE: case CSS_PROP_BORDER_LEFT_STYLE:
case CSS_PROP__WEBKIT_COLUMN_RULE_STYLE:
if (id >= CSS_VAL_NONE && id <= CSS_VAL_DOUBLE)
valid_primitive = true;
break;
case CSS_PROP_FONT_WEIGHT: if (id >= CSS_VAL_NORMAL && id <= CSS_VAL_900) {
valid_primitive = true;
} else if (validUnit(value, FInteger|FNonNeg, false)) {
int weight = (int)value->fValue;
if ((weight % 100))
break;
weight /= 100;
if (weight >= 1 && weight <= 9) {
id = CSS_VAL_100 + weight - 1;
valid_primitive = true;
}
}
break;
case CSS_PROP_BORDER_SPACING: {
const int properties[2] = { CSS_PROP__WEBKIT_BORDER_HORIZONTAL_SPACING,
CSS_PROP__WEBKIT_BORDER_VERTICAL_SPACING };
if (num == 1) {
ShorthandScope scope(this, CSS_PROP_BORDER_SPACING);
if (!parseValue(properties[0], important))
return false;
CSSValue* value = parsedProperties[numParsedProperties-1]->value();
addProperty(properties[1], value, important);
return true;
}
else if (num == 2) {
ShorthandScope scope(this, CSS_PROP_BORDER_SPACING);
if (!parseValue(properties[0], important) || !parseValue(properties[1], important))
return false;
return true;
}
return false;
}
case CSS_PROP__WEBKIT_BORDER_HORIZONTAL_SPACING:
case CSS_PROP__WEBKIT_BORDER_VERTICAL_SPACING:
valid_primitive = validUnit(value, FLength|FNonNeg, strict);
break;
case CSS_PROP_SCROLLBAR_FACE_COLOR: case CSS_PROP_SCROLLBAR_SHADOW_COLOR: case CSS_PROP_SCROLLBAR_HIGHLIGHT_COLOR: case CSS_PROP_SCROLLBAR_3DLIGHT_COLOR: case CSS_PROP_SCROLLBAR_DARKSHADOW_COLOR: case CSS_PROP_SCROLLBAR_TRACK_COLOR: case CSS_PROP_SCROLLBAR_ARROW_COLOR: if (strict)
break;
case CSS_PROP_OUTLINE_COLOR: if (propId == CSS_PROP_OUTLINE_COLOR && (id == CSS_VAL_INVERT || id == CSS_VAL__WEBKIT_FOCUS_RING_COLOR)) {
valid_primitive = true;
break;
}
case CSS_PROP_BACKGROUND_COLOR: case CSS_PROP_BORDER_TOP_COLOR: case CSS_PROP_BORDER_RIGHT_COLOR: case CSS_PROP_BORDER_BOTTOM_COLOR: case CSS_PROP_BORDER_LEFT_COLOR: case CSS_PROP_COLOR: case CSS_PROP_TEXT_LINE_THROUGH_COLOR: case CSS_PROP_TEXT_UNDERLINE_COLOR:
case CSS_PROP_TEXT_OVERLINE_COLOR:
case CSS_PROP__WEBKIT_COLUMN_RULE_COLOR:
case CSS_PROP__WEBKIT_TEXT_FILL_COLOR:
case CSS_PROP__WEBKIT_TEXT_STROKE_COLOR:
if (id == CSS_VAL__WEBKIT_TEXT)
valid_primitive = true; else if (id >= CSS_VAL_AQUA && id <= CSS_VAL_WINDOWTEXT || id == CSS_VAL_MENU ||
(id >= CSS_VAL__WEBKIT_FOCUS_RING_COLOR && id < CSS_VAL__WEBKIT_TEXT && !strict)) {
valid_primitive = true;
} else {
parsedValue = parseColor();
if (parsedValue)
valueList->next();
}
break;
case CSS_PROP_CURSOR: {
RefPtr<CSSValueList> list;
while (value && value->unit == CSSPrimitiveValue::CSS_URI) {
if (!list)
list = new CSSValueList;
String uri = parseURL(domString(value->string));
Vector<int> coords;
value = valueList->next();
while (value && value->unit == CSSPrimitiveValue::CSS_NUMBER) {
coords.append(int(value->fValue));
value = valueList->next();
}
IntPoint hotspot;
int nrcoords = coords.size();
if (nrcoords > 0 && nrcoords != 2) {
if (strict) return false;
} else if(strict && nrcoords == 2)
hotspot = IntPoint(coords[0], coords[1]);
if (strict || coords.size() == 0) {
#if ENABLE(SVG)
if (uri.startsWith("#"))
list->append(new CSSPrimitiveValue(uri, CSSPrimitiveValue::CSS_URI));
else
#endif
if (!uri.isEmpty()) {
list->append(new CSSCursorImageValue(
KURL(styleElement->baseURL().deprecatedString(), uri.deprecatedString()).string(),
hotspot, styleElement));
}
}
if ((strict && !value) || (value && !(value->unit == Value::Operator && value->iValue == ',')))
return false;
value = valueList->next(); }
if (list) {
if (!value) { if (list->length() != 1)
return false;
} else if (!strict && value->id == CSS_VAL_HAND) list->append(new CSSPrimitiveValue(CSS_VAL_POINTER));
else if (value && ((value->id >= CSS_VAL_AUTO && value->id <= CSS_VAL_ALL_SCROLL) || value->id == CSS_VAL_COPY || value->id == CSS_VAL_NONE))
list->append(new CSSPrimitiveValue(value->id));
valueList->next();
parsedValue = list.release();
break;
}
id = value->id;
if (!strict && value->id == CSS_VAL_HAND) { id = CSS_VAL_POINTER;
valid_primitive = true;
} else if ((value->id >= CSS_VAL_AUTO && value->id <= CSS_VAL_ALL_SCROLL) || value->id == CSS_VAL_COPY || value->id == CSS_VAL_NONE)
valid_primitive = true;
break;
}
case CSS_PROP_BACKGROUND_ATTACHMENT:
case CSS_PROP__WEBKIT_BACKGROUND_CLIP:
case CSS_PROP__WEBKIT_BACKGROUND_COMPOSITE:
case CSS_PROP_BACKGROUND_IMAGE:
case CSS_PROP__WEBKIT_BACKGROUND_ORIGIN:
case CSS_PROP_BACKGROUND_POSITION:
case CSS_PROP_BACKGROUND_POSITION_X:
case CSS_PROP_BACKGROUND_POSITION_Y:
case CSS_PROP__WEBKIT_BACKGROUND_SIZE:
case CSS_PROP_BACKGROUND_REPEAT: {
RefPtr<CSSValue> val1;
RefPtr<CSSValue> val2;
int propId1, propId2;
if (parseBackgroundProperty(propId, propId1, propId2, val1, val2)) {
addProperty(propId1, val1.release(), important);
if (val2)
addProperty(propId2, val2.release(), important);
return true;
}
return false;
}
case CSS_PROP_LIST_STYLE_IMAGE: if (id == CSS_VAL_NONE) {
parsedValue = new CSSImageValue();
valueList->next();
}
else if (value->unit == CSSPrimitiveValue::CSS_URI) {
String uri = parseURL(domString(value->string));
if (!uri.isEmpty()) {
parsedValue = new CSSImageValue(
KURL(styleElement->baseURL().deprecatedString(), uri.deprecatedString()).string(),
styleElement);
valueList->next();
}
}
break;
case CSS_PROP__WEBKIT_TEXT_STROKE_WIDTH:
case CSS_PROP_OUTLINE_WIDTH: case CSS_PROP_BORDER_TOP_WIDTH: case CSS_PROP_BORDER_RIGHT_WIDTH: case CSS_PROP_BORDER_BOTTOM_WIDTH: case CSS_PROP_BORDER_LEFT_WIDTH:
case CSS_PROP__WEBKIT_COLUMN_RULE_WIDTH:
if (id == CSS_VAL_THIN || id == CSS_VAL_MEDIUM || id == CSS_VAL_THICK)
valid_primitive = true;
else
valid_primitive = validUnit(value, FLength, strict);
break;
case CSS_PROP_LETTER_SPACING: case CSS_PROP_WORD_SPACING: if (id == CSS_VAL_NORMAL)
valid_primitive = true;
else
valid_primitive = validUnit(value, FLength, strict);
break;
case CSS_PROP_WORD_BREAK: if (id == CSS_VAL_NORMAL || id == CSS_VAL_BREAK_ALL || id == CSS_VAL_BREAK_WORD)
valid_primitive = true;
break;
case CSS_PROP_WORD_WRAP: if (id == CSS_VAL_NORMAL || id == CSS_VAL_BREAK_WORD)
valid_primitive = true;
break;
case CSS_PROP_TEXT_INDENT: case CSS_PROP_PADDING_TOP: case CSS_PROP_PADDING_RIGHT: case CSS_PROP_PADDING_BOTTOM: case CSS_PROP_PADDING_LEFT: case CSS_PROP__WEBKIT_PADDING_START:
valid_primitive = (!id && validUnit(value, FLength|FPercent, strict));
break;
case CSS_PROP_MAX_HEIGHT: case CSS_PROP_MAX_WIDTH: if (id == CSS_VAL_NONE || id == CSS_VAL_INTRINSIC || id == CSS_VAL_MIN_INTRINSIC) {
valid_primitive = true;
break;
}
case CSS_PROP_MIN_HEIGHT: case CSS_PROP_MIN_WIDTH: if (id == CSS_VAL_INTRINSIC || id == CSS_VAL_MIN_INTRINSIC)
valid_primitive = true;
else
valid_primitive = (!id && validUnit(value, FLength|FPercent|FNonNeg, strict));
break;
case CSS_PROP_FONT_SIZE:
if (id >= CSS_VAL_XX_SMALL && id <= CSS_VAL_LARGER)
valid_primitive = true;
else
valid_primitive = (validUnit(value, FLength|FPercent, strict));
break;
case CSS_PROP_FONT_STYLE: if (id == CSS_VAL_NORMAL || id == CSS_VAL_ITALIC || id == CSS_VAL_OBLIQUE)
valid_primitive = true;
break;
case CSS_PROP_FONT_VARIANT: if (id == CSS_VAL_NORMAL || id == CSS_VAL_SMALL_CAPS)
valid_primitive = true;
break;
case CSS_PROP_VERTICAL_ALIGN:
if (id >= CSS_VAL_BASELINE && id <= CSS_VAL__WEBKIT_BASELINE_MIDDLE)
valid_primitive = true;
else
valid_primitive = (!id && validUnit(value, FLength|FPercent, strict));
break;
case CSS_PROP_HEIGHT: case CSS_PROP_WIDTH: if (id == CSS_VAL_AUTO || id == CSS_VAL_INTRINSIC || id == CSS_VAL_MIN_INTRINSIC)
valid_primitive = true;
else
valid_primitive = (!id && validUnit(value, FLength|FPercent|FNonNeg, strict));
break;
case CSS_PROP_BOTTOM: case CSS_PROP_LEFT: case CSS_PROP_RIGHT: case CSS_PROP_TOP: case CSS_PROP_MARGIN_TOP: case CSS_PROP_MARGIN_RIGHT: case CSS_PROP_MARGIN_BOTTOM: case CSS_PROP_MARGIN_LEFT: case CSS_PROP__WEBKIT_MARGIN_START:
if (id == CSS_VAL_AUTO)
valid_primitive = true;
else
valid_primitive = (!id && validUnit(value, FLength|FPercent, strict));
break;
case CSS_PROP_Z_INDEX: if (id == CSS_VAL_AUTO) {
valid_primitive = true;
break;
}
case CSS_PROP_ORPHANS: case CSS_PROP_WIDOWS: valid_primitive = (!id && validUnit(value, FInteger, false));
break;
case CSS_PROP_LINE_HEIGHT: if (id == CSS_VAL_NORMAL)
valid_primitive = true;
else
valid_primitive = (!id && validUnit(value, FNumber|FLength|FPercent, strict));
break;
case CSS_PROP_COUNTER_INCREMENT: if (id != CSS_VAL_NONE)
return parseCounter(propId, 1, important);
valid_primitive = true;
break;
case CSS_PROP_COUNTER_RESET: if (id != CSS_VAL_NONE)
return parseCounter(propId, 0, important);
valid_primitive = true;
break;
case CSS_PROP_FONT_FAMILY:
{
parsedValue = parseFontFamily();
break;
}
case CSS_PROP_TEXT_DECORATION:
case CSS_PROP__WEBKIT_TEXT_DECORATIONS_IN_EFFECT:
if (id == CSS_VAL_NONE) {
valid_primitive = true;
} else {
RefPtr<CSSValueList> list(new CSSValueList);
bool is_valid = true;
while(is_valid && value) {
switch (value->id) {
case CSS_VAL_BLINK:
break;
case CSS_VAL_UNDERLINE:
case CSS_VAL_OVERLINE:
case CSS_VAL_LINE_THROUGH:
list->append(new CSSPrimitiveValue(value->id));
break;
default:
is_valid = false;
}
value = valueList->next();
}
if (list->length() && is_valid) {
parsedValue = list.release();
valueList->next();
}
}
break;
case CSS_PROP_TABLE_LAYOUT: if (id == CSS_VAL_AUTO || id == CSS_VAL_FIXED)
valid_primitive = true;
break;
case CSS_PROP_SRC: return parseFontFaceSrc();
case CSS_PROP_UNICODE_RANGE:
return parseFontFaceUnicodeRange();
case CSS_PROP__WEBKIT_APPEARANCE:
if ((id >= CSS_VAL_CHECKBOX && id <= CSS_VAL_TEXTAREA) || id == CSS_VAL_NONE)
valid_primitive = true;
break;
case CSS_PROP__WEBKIT_BINDING:
#if ENABLE(XBL)
if (id == CSS_VAL_NONE)
valid_primitive = true;
else {
RefPtr<CSSValueList> values(new CSSValueList());
Value* val;
RefPtr<CSSValue> parsedValue;
while ((val = valueList->current())) {
if (val->unit == CSSPrimitiveValue::CSS_URI) {
String value = parseURL(domString(val->string));
parsedValue = new CSSPrimitiveValue(
KURL(styleElement->baseURL().deprecatedString(), value.deprecatedString()).string(),
CSSPrimitiveValue::CSS_URI);
}
if (!parsedValue)
break;
values->append(parsedValue.get());
valueList->next();
}
if (!values->length())
return false;
addProperty(propId, values.release(), important);
valueList->next();
return true;
}
#endif
break;
case CSS_PROP__WEBKIT_BORDER_IMAGE:
if (id == CSS_VAL_NONE)
valid_primitive = true;
else
return parseBorderImage(propId, important);
break;
case CSS_PROP__WEBKIT_BORDER_TOP_RIGHT_RADIUS:
case CSS_PROP__WEBKIT_BORDER_TOP_LEFT_RADIUS:
case CSS_PROP__WEBKIT_BORDER_BOTTOM_LEFT_RADIUS:
case CSS_PROP__WEBKIT_BORDER_BOTTOM_RIGHT_RADIUS:
case CSS_PROP__WEBKIT_BORDER_RADIUS: {
if (num != 1 && num != 2)
return false;
valid_primitive = validUnit(value, FLength, strict);
if (!valid_primitive)
return false;
RefPtr<CSSPrimitiveValue> parsedValue1 = new CSSPrimitiveValue(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit);
RefPtr<CSSPrimitiveValue> parsedValue2;
if (num == 2) {
value = valueList->next();
valid_primitive = validUnit(value, FLength, strict);
if (!valid_primitive)
return false;
parsedValue2 = new CSSPrimitiveValue(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit);
} else
parsedValue2 = parsedValue1;
RefPtr<Pair> pair = new Pair(parsedValue1.release(), parsedValue2.release());
RefPtr<CSSPrimitiveValue> val = new CSSPrimitiveValue(pair.release());
if (propId == CSS_PROP__WEBKIT_BORDER_RADIUS) {
const int properties[4] = { CSS_PROP__WEBKIT_BORDER_TOP_RIGHT_RADIUS,
CSS_PROP__WEBKIT_BORDER_TOP_LEFT_RADIUS,
CSS_PROP__WEBKIT_BORDER_BOTTOM_LEFT_RADIUS,
CSS_PROP__WEBKIT_BORDER_BOTTOM_RIGHT_RADIUS };
for (int i = 0; i < 4; i++)
addProperty(properties[i], val.get(), important);
} else
addProperty(propId, val.release(), important);
return true;
}
case CSS_PROP_OUTLINE_OFFSET:
valid_primitive = validUnit(value, FLength, strict);
break;
case CSS_PROP_TEXT_SHADOW: case CSS_PROP__WEBKIT_BOX_SHADOW:
if (id == CSS_VAL_NONE)
valid_primitive = true;
else
return parseShadow(propId, important);
break;
case CSS_PROP_OPACITY:
valid_primitive = validUnit(value, FNumber, strict);
break;
case CSS_PROP__WEBKIT_BOX_ALIGN:
if (id == CSS_VAL_STRETCH || id == CSS_VAL_START || id == CSS_VAL_END ||
id == CSS_VAL_CENTER || id == CSS_VAL_BASELINE)
valid_primitive = true;
break;
case CSS_PROP__WEBKIT_BOX_DIRECTION:
if (id == CSS_VAL_NORMAL || id == CSS_VAL_REVERSE)
valid_primitive = true;
break;
case CSS_PROP__WEBKIT_BOX_LINES:
if (id == CSS_VAL_SINGLE || id == CSS_VAL_MULTIPLE)
valid_primitive = true;
break;
case CSS_PROP__WEBKIT_BOX_ORIENT:
if (id == CSS_VAL_HORIZONTAL || id == CSS_VAL_VERTICAL ||
id == CSS_VAL_INLINE_AXIS || id == CSS_VAL_BLOCK_AXIS)
valid_primitive = true;
break;
case CSS_PROP__WEBKIT_BOX_PACK:
if (id == CSS_VAL_START || id == CSS_VAL_END ||
id == CSS_VAL_CENTER || id == CSS_VAL_JUSTIFY)
valid_primitive = true;
break;
case CSS_PROP__WEBKIT_BOX_FLEX:
valid_primitive = validUnit(value, FNumber, strict);
break;
case CSS_PROP__WEBKIT_BOX_FLEX_GROUP:
case CSS_PROP__WEBKIT_BOX_ORDINAL_GROUP:
valid_primitive = validUnit(value, FInteger|FNonNeg, true);
break;
case CSS_PROP__WEBKIT_BOX_SIZING:
valid_primitive = id == CSS_VAL_BORDER_BOX || id == CSS_VAL_CONTENT_BOX;
break;
case CSS_PROP__WEBKIT_MARQUEE: {
const int properties[5] = { CSS_PROP__WEBKIT_MARQUEE_DIRECTION, CSS_PROP__WEBKIT_MARQUEE_INCREMENT,
CSS_PROP__WEBKIT_MARQUEE_REPETITION,
CSS_PROP__WEBKIT_MARQUEE_STYLE, CSS_PROP__WEBKIT_MARQUEE_SPEED };
return parseShorthand(propId, properties, 5, important);
}
case CSS_PROP__WEBKIT_MARQUEE_DIRECTION:
if (id == CSS_VAL_FORWARDS || id == CSS_VAL_BACKWARDS || id == CSS_VAL_AHEAD ||
id == CSS_VAL_REVERSE || id == CSS_VAL_LEFT || id == CSS_VAL_RIGHT || id == CSS_VAL_DOWN ||
id == CSS_VAL_UP || id == CSS_VAL_AUTO)
valid_primitive = true;
break;
case CSS_PROP__WEBKIT_MARQUEE_INCREMENT:
if (id == CSS_VAL_SMALL || id == CSS_VAL_LARGE || id == CSS_VAL_MEDIUM)
valid_primitive = true;
else
valid_primitive = validUnit(value, FLength|FPercent, strict);
break;
case CSS_PROP__WEBKIT_MARQUEE_STYLE:
if (id == CSS_VAL_NONE || id == CSS_VAL_SLIDE || id == CSS_VAL_SCROLL || id == CSS_VAL_ALTERNATE)
valid_primitive = true;
break;
case CSS_PROP__WEBKIT_MARQUEE_REPETITION:
if (id == CSS_VAL_INFINITE)
valid_primitive = true;
else
valid_primitive = validUnit(value, FInteger|FNonNeg, strict);
break;
case CSS_PROP__WEBKIT_MARQUEE_SPEED:
if (id == CSS_VAL_NORMAL || id == CSS_VAL_SLOW || id == CSS_VAL_FAST)
valid_primitive = true;
else
valid_primitive = validUnit(value, FTime|FInteger|FNonNeg, strict);
break;
case CSS_PROP__WEBKIT_USER_DRAG: if (id == CSS_VAL_AUTO || id == CSS_VAL_NONE || id == CSS_VAL_ELEMENT)
valid_primitive = true;
break;
case CSS_PROP__WEBKIT_USER_MODIFY: if (id == CSS_VAL_READ_ONLY || id == CSS_VAL_READ_WRITE || id == CSS_VAL_READ_WRITE_PLAINTEXT_ONLY)
valid_primitive = true;
break;
case CSS_PROP__WEBKIT_USER_SELECT: if (id == CSS_VAL_AUTO || id == CSS_VAL_NONE || id == CSS_VAL_TEXT)
valid_primitive = true;
break;
case CSS_PROP_TEXT_OVERFLOW: if (id == CSS_VAL_CLIP || id == CSS_VAL_ELLIPSIS)
valid_primitive = true;
break;
case CSS_PROP__WEBKIT_TRANSFORM:
if (id == CSS_VAL_NONE)
valid_primitive = true;
else {
PassRefPtr<CSSValue> val = parseTransform();
if (val) {
addProperty(propId, val, important);
return true;
}
return false;
}
break;
case CSS_PROP__WEBKIT_TRANSFORM_ORIGIN:
case CSS_PROP__WEBKIT_TRANSFORM_ORIGIN_X:
case CSS_PROP__WEBKIT_TRANSFORM_ORIGIN_Y:
case CSS_PROP__WEBKIT_TRANSFORM_ORIGIN_Z: {
RefPtr<CSSValue> val1;
RefPtr<CSSValue> val2;
RefPtr<CSSValue> val3;
int propId1, propId2, propId3;
if (parseTransformOrigin(propId, propId1, propId2, propId3, val1, val2, val3)) {
addProperty(propId1, val1.release(), important);
if (val2)
addProperty(propId2, val2.release(), important);
if (val3)
addProperty(propId3, val3.release(), important);
return true;
}
return false;
}
case CSS_PROP__WEBKIT_TRANSFORM_STYLE:
if (value->id == CSS_VAL_FLAT || value->id == CSS_VAL_PRESERVE_3D)
valid_primitive = true;
break;
case CSS_PROP__WEBKIT_BACKFACE_VISIBILITY:
if (value->id == CSS_VAL_VISIBLE || value->id == CSS_VAL_HIDDEN)
valid_primitive = true;
break;
case CSS_PROP__WEBKIT_PERSPECTIVE:
if (id == CSS_VAL_NONE)
valid_primitive = true;
else {
if (validUnit(value, FNumber, strict)) {
PassRefPtr<CSSValue> val = new CSSPrimitiveValue(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit);
if (val) {
addProperty(propId, val, important);
return true;
}
return false;
}
}
break;
case CSS_PROP__WEBKIT_PERSPECTIVE_ORIGIN:
case CSS_PROP__WEBKIT_PERSPECTIVE_ORIGIN_X:
case CSS_PROP__WEBKIT_PERSPECTIVE_ORIGIN_Y: {
RefPtr<CSSValue> val1;
RefPtr<CSSValue> val2;
int propId1, propId2;
if (parsePerspectiveOrigin(propId, propId1, propId2, val1, val2)) {
addProperty(propId1, val1.release(), important);
if (val2)
addProperty(propId2, val2.release(), important);
return true;
}
return false;
}
case CSS_PROP__WEBKIT_ANIMATION_DELAY:
case CSS_PROP__WEBKIT_ANIMATION_DIRECTION:
case CSS_PROP__WEBKIT_ANIMATION_DURATION:
case CSS_PROP__WEBKIT_ANIMATION_NAME:
case CSS_PROP__WEBKIT_ANIMATION_PLAY_STATE:
case CSS_PROP__WEBKIT_ANIMATION_ITERATION_COUNT:
case CSS_PROP__WEBKIT_ANIMATION_TIMING_FUNCTION:
case CSS_PROP__WEBKIT_TRANSITION_DELAY:
case CSS_PROP__WEBKIT_TRANSITION_DURATION:
case CSS_PROP__WEBKIT_TRANSITION_NAME:
case CSS_PROP__WEBKIT_TRANSITION_ITERATION_COUNT:
case CSS_PROP__WEBKIT_TRANSITION_TIMING_FUNCTION:
case CSS_PROP__WEBKIT_TRANSITION_PROPERTY: {
RefPtr<CSSValue> val;
if (parseTransitionProperty(propId, val)) {
addProperty(propId, val.release(), important);
return true;
}
return false;
}
case CSS_PROP__WEBKIT_MARGIN_COLLAPSE: {
const int properties[2] = { CSS_PROP__WEBKIT_MARGIN_TOP_COLLAPSE,
CSS_PROP__WEBKIT_MARGIN_BOTTOM_COLLAPSE };
if (num == 1) {
ShorthandScope scope(this, CSS_PROP__WEBKIT_MARGIN_COLLAPSE);
if (!parseValue(properties[0], important))
return false;
CSSValue* value = parsedProperties[numParsedProperties-1]->value();
addProperty(properties[1], value, important);
return true;
}
else if (num == 2) {
ShorthandScope scope(this, CSS_PROP__WEBKIT_MARGIN_COLLAPSE);
if (!parseValue(properties[0], important) || !parseValue(properties[1], important))
return false;
return true;
}
return false;
}
case CSS_PROP__WEBKIT_MARGIN_TOP_COLLAPSE:
case CSS_PROP__WEBKIT_MARGIN_BOTTOM_COLLAPSE:
if (id == CSS_VAL_COLLAPSE || id == CSS_VAL_SEPARATE || id == CSS_VAL_DISCARD)
valid_primitive = true;
break;
case CSS_PROP_TEXT_LINE_THROUGH_MODE:
case CSS_PROP_TEXT_OVERLINE_MODE:
case CSS_PROP_TEXT_UNDERLINE_MODE:
if (id == CSS_VAL_CONTINUOUS || id == CSS_VAL_SKIP_WHITE_SPACE)
valid_primitive = true;
break;
case CSS_PROP_TEXT_LINE_THROUGH_STYLE:
case CSS_PROP_TEXT_OVERLINE_STYLE:
case CSS_PROP_TEXT_UNDERLINE_STYLE:
if (id == CSS_VAL_NONE || id == CSS_VAL_SOLID || id == CSS_VAL_DOUBLE ||
id == CSS_VAL_DASHED || id == CSS_VAL_DOT_DASH || id == CSS_VAL_DOT_DOT_DASH ||
id == CSS_VAL_WAVE)
valid_primitive = true;
break;
case CSS_PROP_TEXT_LINE_THROUGH_WIDTH:
case CSS_PROP_TEXT_OVERLINE_WIDTH:
case CSS_PROP_TEXT_UNDERLINE_WIDTH:
if (id == CSS_VAL_AUTO || id == CSS_VAL_NORMAL || id == CSS_VAL_THIN ||
id == CSS_VAL_MEDIUM || id == CSS_VAL_THICK)
valid_primitive = true;
else
valid_primitive = !id && validUnit(value, FNumber|FLength|FPercent, strict);
break;
case CSS_PROP_RESIZE: if (id == CSS_VAL_NONE || id == CSS_VAL_BOTH || id == CSS_VAL_HORIZONTAL || id == CSS_VAL_VERTICAL || id == CSS_VAL_AUTO)
valid_primitive = true;
break;
case CSS_PROP__WEBKIT_COLUMN_COUNT:
if (id == CSS_VAL_AUTO)
valid_primitive = true;
else
valid_primitive = !id && validUnit(value, FInteger | FNonNeg, false);
break;
case CSS_PROP__WEBKIT_COLUMN_GAP: if (id == CSS_VAL_NORMAL)
valid_primitive = true;
else
valid_primitive = validUnit(value, FLength, strict);
break;
case CSS_PROP__WEBKIT_COLUMN_WIDTH: if (id == CSS_VAL_AUTO)
valid_primitive = true;
else valid_primitive = validUnit(value, FLength, true);
break;
case CSS_PROP__WEBKIT_LINE_CLAMP:
valid_primitive = (!id && validUnit(value, FPercent, false));
break;
case CSS_PROP__WEBKIT_TEXT_SIZE_ADJUST:
if (id == CSS_VAL_AUTO || id == CSS_VAL_NONE)
valid_primitive = true;
else
valid_primitive = (!id && validUnit(value, FPercent|FNonNeg, strict));
break;
case CSS_PROP__WEBKIT_RTL_ORDERING:
if (id == CSS_VAL_LOGICAL || id == CSS_VAL_VISUAL)
valid_primitive = true;
break;
case CSS_PROP__WEBKIT_FONT_SIZE_DELTA: valid_primitive = validUnit(value, FLength, strict);
break;
case CSS_PROP__WEBKIT_NBSP_MODE: if (id == CSS_VAL_NORMAL || id == CSS_VAL_SPACE)
valid_primitive = true;
break;
case CSS_PROP__WEBKIT_LINE_BREAK: if (id == CSS_VAL_NORMAL || id == CSS_VAL_AFTER_WHITE_SPACE)
valid_primitive = true;
break;
case CSS_PROP__WEBKIT_MATCH_NEAREST_MAIL_BLOCKQUOTE_COLOR: if (id == CSS_VAL_NORMAL || id == CSS_VAL_MATCH)
valid_primitive = true;
break;
case CSS_PROP__WEBKIT_HIGHLIGHT:
if (id == CSS_VAL_NONE || value->unit == CSSPrimitiveValue::CSS_STRING)
valid_primitive = true;
break;
case CSS_PROP__WEBKIT_BORDER_FIT:
if (id == CSS_VAL_BORDER || id == CSS_VAL_LINES)
valid_primitive = true;
break;
case CSS_PROP__WEBKIT_TEXT_SECURITY:
if (id == CSS_VAL_DISC || id == CSS_VAL_CIRCLE || id == CSS_VAL_SQUARE|| id == CSS_VAL_NONE)
valid_primitive = true;
break;
#if ENABLE(DASHBOARD_SUPPORT)
case CSS_PROP__WEBKIT_DASHBOARD_REGION: if (value->unit == Value::Function || id == CSS_VAL_NONE)
return parseDashboardRegions(propId, important);
break;
#endif
case CSS_PROP__WEBKIT_IMAGE_LOADING_BORDER:
if(id == CSS_VAL__WEBKIT_LOADING_OUTLINE || id == CSS_VAL_NONE)
valid_primitive = true;
break;
case CSS_PROP__WEBKIT_TAP_HIGHLIGHT_COLOR:
case CSS_PROP__WEBKIT_COMPOSITION_FILL_COLOR:
case CSS_PROP__WEBKIT_COMPOSITION_FRAME_COLOR:
parsedValue = parseColor();
if (parsedValue)
valueList->next();
break;
case CSS_PROP__WEBKIT_TOUCH_CALLOUT:
if(id == CSS_VAL_DEFAULT || id == CSS_VAL_NONE)
valid_primitive = true;
break;
case CSS_PROP_BACKGROUND:
return parseBackgroundShorthand(important);
case CSS_PROP_BORDER:
{
const int properties[3] = { CSS_PROP_BORDER_WIDTH, CSS_PROP_BORDER_STYLE,
CSS_PROP_BORDER_COLOR };
return parseShorthand(propId, properties, 3, important);
}
case CSS_PROP_BORDER_TOP:
{
const int properties[3] = { CSS_PROP_BORDER_TOP_WIDTH, CSS_PROP_BORDER_TOP_STYLE,
CSS_PROP_BORDER_TOP_COLOR};
return parseShorthand(propId, properties, 3, important);
}
case CSS_PROP_BORDER_RIGHT:
{
const int properties[3] = { CSS_PROP_BORDER_RIGHT_WIDTH, CSS_PROP_BORDER_RIGHT_STYLE,
CSS_PROP_BORDER_RIGHT_COLOR };
return parseShorthand(propId, properties, 3, important);
}
case CSS_PROP_BORDER_BOTTOM:
{
const int properties[3] = { CSS_PROP_BORDER_BOTTOM_WIDTH, CSS_PROP_BORDER_BOTTOM_STYLE,
CSS_PROP_BORDER_BOTTOM_COLOR };
return parseShorthand(propId, properties, 3, important);
}
case CSS_PROP_BORDER_LEFT:
{
const int properties[3] = { CSS_PROP_BORDER_LEFT_WIDTH, CSS_PROP_BORDER_LEFT_STYLE,
CSS_PROP_BORDER_LEFT_COLOR };
return parseShorthand(propId, properties, 3, important);
}
case CSS_PROP_OUTLINE:
{
const int properties[3] = { CSS_PROP_OUTLINE_WIDTH, CSS_PROP_OUTLINE_STYLE,
CSS_PROP_OUTLINE_COLOR };
return parseShorthand(propId, properties, 3, important);
}
case CSS_PROP_BORDER_COLOR:
{
const int properties[4] = { CSS_PROP_BORDER_TOP_COLOR, CSS_PROP_BORDER_RIGHT_COLOR,
CSS_PROP_BORDER_BOTTOM_COLOR, CSS_PROP_BORDER_LEFT_COLOR };
return parse4Values(propId, properties, important);
}
case CSS_PROP_BORDER_WIDTH:
{
const int properties[4] = { CSS_PROP_BORDER_TOP_WIDTH, CSS_PROP_BORDER_RIGHT_WIDTH,
CSS_PROP_BORDER_BOTTOM_WIDTH, CSS_PROP_BORDER_LEFT_WIDTH };
return parse4Values(propId, properties, important);
}
case CSS_PROP_BORDER_STYLE:
{
const int properties[4] = { CSS_PROP_BORDER_TOP_STYLE, CSS_PROP_BORDER_RIGHT_STYLE,
CSS_PROP_BORDER_BOTTOM_STYLE, CSS_PROP_BORDER_LEFT_STYLE };
return parse4Values(propId, properties, important);
}
case CSS_PROP_MARGIN:
{
const int properties[4] = { CSS_PROP_MARGIN_TOP, CSS_PROP_MARGIN_RIGHT,
CSS_PROP_MARGIN_BOTTOM, CSS_PROP_MARGIN_LEFT };
return parse4Values(propId, properties, important);
}
case CSS_PROP_PADDING:
{
const int properties[4] = { CSS_PROP_PADDING_TOP, CSS_PROP_PADDING_RIGHT,
CSS_PROP_PADDING_BOTTOM, CSS_PROP_PADDING_LEFT };
return parse4Values(propId, properties, important);
}
case CSS_PROP_FONT:
if (id >= CSS_VAL_CAPTION && id <= CSS_VAL_STATUS_BAR)
valid_primitive = true;
else
return parseFont(important);
break;
case CSS_PROP_LIST_STYLE:
{
const int properties[3] = { CSS_PROP_LIST_STYLE_TYPE, CSS_PROP_LIST_STYLE_POSITION,
CSS_PROP_LIST_STYLE_IMAGE };
return parseShorthand(propId, properties, 3, important);
}
case CSS_PROP__WEBKIT_COLUMNS: {
const int properties[2] = { CSS_PROP__WEBKIT_COLUMN_WIDTH, CSS_PROP__WEBKIT_COLUMN_COUNT };
return parseShorthand(propId, properties, 2, important);
}
case CSS_PROP__WEBKIT_COLUMN_RULE: {
const int properties[3] = { CSS_PROP__WEBKIT_COLUMN_RULE_WIDTH, CSS_PROP__WEBKIT_COLUMN_RULE_STYLE,
CSS_PROP__WEBKIT_COLUMN_RULE_COLOR };
return parseShorthand(propId, properties, 3, important);
}
case CSS_PROP__WEBKIT_TEXT_STROKE: {
const int properties[2] = { CSS_PROP__WEBKIT_TEXT_STROKE_WIDTH, CSS_PROP__WEBKIT_TEXT_STROKE_COLOR };
return parseShorthand(propId, properties, 2, important);
}
case CSS_PROP__WEBKIT_ANIMATION:
return parseAnimationShorthand(important);
case CSS_PROP__WEBKIT_TRANSITION:
return parseTransitionShorthand(important);
case CSS_PROP_INVALID:
return false;
case CSS_PROP_FONT_STRETCH:
case CSS_PROP_PAGE:
case CSS_PROP_TEXT_LINE_THROUGH:
case CSS_PROP_TEXT_OVERLINE:
case CSS_PROP_TEXT_UNDERLINE:
return false;
#if ENABLE(SVG)
default:
return parseSVGValue(propId, important);
#endif
}
if (valid_primitive) {
if (id != 0)
parsedValue = new CSSPrimitiveValue(id);
else if (value->unit == CSSPrimitiveValue::CSS_STRING)
parsedValue = new CSSPrimitiveValue(domString(value->string), (CSSPrimitiveValue::UnitTypes) value->unit);
else if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
parsedValue = new CSSPrimitiveValue(value->fValue, (CSSPrimitiveValue::UnitTypes) value->unit);
else if (value->unit >= Value::Q_EMS)
parsedValue = new CSSQuirkPrimitiveValue(value->fValue, CSSPrimitiveValue::CSS_EMS);
valueList->next();
}
if (parsedValue) {
if (!valueList->current() || inShorthand()) {
addProperty(propId, parsedValue.release(), important);
return true;
}
}
return false;
}
void CSSParser::addBackgroundValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval)
{
if (lval) {
if (lval->isValueList())
static_cast<CSSValueList*>(lval.get())->append(rval);
else {
PassRefPtr<CSSValue> oldlVal(lval.release());
PassRefPtr<CSSValueList> list(new CSSValueList());
list->append(oldlVal);
list->append(rval);
lval = list;
}
}
else
lval = rval;
}
bool CSSParser::parseBackgroundShorthand(bool important)
{
const int properties[] = { CSS_PROP_BACKGROUND_IMAGE, CSS_PROP_BACKGROUND_REPEAT,
CSS_PROP_BACKGROUND_ATTACHMENT, CSS_PROP_BACKGROUND_POSITION, CSS_PROP__WEBKIT_BACKGROUND_CLIP,
CSS_PROP__WEBKIT_BACKGROUND_ORIGIN, CSS_PROP_BACKGROUND_COLOR };
const int numProperties = sizeof(properties) / sizeof(properties[0]);
ShorthandScope scope(this, CSS_PROP_BACKGROUND);
bool parsedProperty[numProperties] = { false }; RefPtr<CSSValue> values[numProperties];
RefPtr<CSSValue> positionYValue;
int i;
while (valueList->current()) {
Value* val = valueList->current();
if (val->unit == Value::Operator && val->iValue == ',') {
valueList->next();
for (i = 0; i < numProperties; ++i) {
if (properties[i] == CSS_PROP_BACKGROUND_COLOR && parsedProperty[i])
return false;
if (!parsedProperty[i] && properties[i] != CSS_PROP_BACKGROUND_COLOR) {
addBackgroundValue(values[i], new CSSInitialValue(true));
if (properties[i] == CSS_PROP_BACKGROUND_POSITION)
addBackgroundValue(positionYValue, new CSSInitialValue(true));
}
parsedProperty[i] = false;
}
if (!valueList->current())
break;
}
bool found = false;
for (i = 0; !found && i < numProperties; ++i) {
if (!parsedProperty[i]) {
RefPtr<CSSValue> val1;
RefPtr<CSSValue> val2;
int propId1, propId2;
if (parseBackgroundProperty(properties[i], propId1, propId2, val1, val2)) {
parsedProperty[i] = found = true;
addBackgroundValue(values[i], val1.release());
if (properties[i] == CSS_PROP_BACKGROUND_POSITION)
addBackgroundValue(positionYValue, val2.release());
}
}
}
if (!found)
return false;
}
for (i = 0; i < numProperties; ++i) {
if (!parsedProperty[i]) {
addBackgroundValue(values[i], new CSSInitialValue(true));
if (properties[i] == CSS_PROP_BACKGROUND_POSITION)
addBackgroundValue(positionYValue, new CSSInitialValue(true));
}
}
for (i = 0; i < numProperties; i++) {
if (properties[i] == CSS_PROP_BACKGROUND_POSITION) {
addProperty(CSS_PROP_BACKGROUND_POSITION_X, values[i].release(), important);
addProperty(CSS_PROP_BACKGROUND_POSITION_Y, positionYValue.release(), important);
} else
addProperty(properties[i], values[i].release(), important);
}
return true;
}
void CSSParser::addTransitionValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval)
{
if (lval) {
if (lval->isValueList())
static_cast<CSSValueList*>(lval.get())->append(rval);
else {
PassRefPtr<CSSValue> oldVal(lval.release());
PassRefPtr<CSSValueList> list(new CSSValueList());
list->append(oldVal);
list->append(rval);
lval = list;
}
}
else
lval = rval;
}
bool CSSParser::parseAnimationShorthand(bool important)
{
const int properties[] = { CSS_PROP__WEBKIT_ANIMATION_NAME,
CSS_PROP__WEBKIT_ANIMATION_DURATION,
CSS_PROP__WEBKIT_ANIMATION_TIMING_FUNCTION,
CSS_PROP__WEBKIT_ANIMATION_DELAY,
CSS_PROP__WEBKIT_ANIMATION_ITERATION_COUNT,
CSS_PROP__WEBKIT_ANIMATION_DIRECTION };
const int numProperties = sizeof(properties) / sizeof(properties[0]);
ShorthandScope scope(this, CSS_PROP__WEBKIT_ANIMATION);
bool parsedProperty[numProperties] = { false }; RefPtr<CSSValue> values[numProperties];
int i;
while (valueList->current()) {
Value* val = valueList->current();
if (val->unit == Value::Operator && val->iValue == ',') {
valueList->next();
for (i = 0; i < numProperties; ++i) {
if (!parsedProperty[i])
addTransitionValue(values[i], new CSSInitialValue(true));
parsedProperty[i] = false;
}
if (!valueList->current())
break;
}
bool found = false;
for (i = 0; !found && i < numProperties; ++i) {
if (!parsedProperty[i]) {
RefPtr<CSSValue> val;
if (parseTransitionProperty(properties[i], val)) {
parsedProperty[i] = found = true;
addTransitionValue(values[i], val.release());
}
}
}
if (!found)
return false;
}
for (i = 0; i < numProperties; ++i) {
if (!parsedProperty[i])
addTransitionValue(values[i], new CSSInitialValue(true));
}
for (i = 0; i < numProperties; i++)
addProperty(properties[i], values[i].release(), important);
return true;
}
bool CSSParser::parseTransitionShorthand(bool important)
{
const int properties[] = { CSS_PROP__WEBKIT_TRANSITION_PROPERTY, CSS_PROP__WEBKIT_TRANSITION_DURATION,
CSS_PROP__WEBKIT_TRANSITION_TIMING_FUNCTION, CSS_PROP__WEBKIT_TRANSITION_ITERATION_COUNT,
CSS_PROP__WEBKIT_TRANSITION_DELAY };
const int numProperties = sizeof(properties) / sizeof(properties[0]);
ShorthandScope scope(this, CSS_PROP__WEBKIT_TRANSITION);
bool parsedProperty[numProperties] = { false }; RefPtr<CSSValue> values[numProperties];
int i;
while (valueList->current()) {
Value* val = valueList->current();
if (val->unit == Value::Operator && val->iValue == ',') {
valueList->next();
for (i = 0; i < numProperties; ++i) {
if (!parsedProperty[i])
addTransitionValue(values[i], new CSSInitialValue(true));
parsedProperty[i] = false;
}
if (!valueList->current())
break;
}
bool found = false;
for (i = 0; !found && i < numProperties; ++i) {
if (!parsedProperty[i]) {
RefPtr<CSSValue> val;
if (parseTransitionProperty(properties[i], val)) {
parsedProperty[i] = found = true;
addTransitionValue(values[i], val.release());
}
}
}
if (!found)
return false;
}
for (i = 0; i < numProperties; ++i) {
if (!parsedProperty[i])
addTransitionValue(values[i], new CSSInitialValue(true));
}
for (i = 0; i < numProperties; i++)
addProperty(properties[i], values[i].release(), important);
return true;
}
bool CSSParser::parseShorthand(int propId, const int *properties, int numProperties, bool important)
{
ShorthandScope scope(this, propId);
bool found = false;
bool fnd[6]; for (int i = 0; i < numProperties; i++)
fnd[i] = false;
while (valueList->current()) {
found = false;
for (int propIndex = 0; !found && propIndex < numProperties; ++propIndex) {
if (!fnd[propIndex]) {
if (parseValue(properties[propIndex], important))
fnd[propIndex] = found = true;
}
}
if (!found)
return false;
}
m_implicitShorthand = true;
for (int i = 0; i < numProperties; ++i) {
if (!fnd[i])
addProperty(properties[i], new CSSInitialValue(true), important);
}
m_implicitShorthand = false;
return true;
}
bool CSSParser::parse4Values(int propId, const int *properties, bool important)
{
int num = inShorthand() ? 1 : valueList->size();
ShorthandScope scope(this, propId);
switch (num) {
case 1: {
if (!parseValue(properties[0], important))
return false;
CSSValue *value = parsedProperties[numParsedProperties-1]->value();
m_implicitShorthand = true;
addProperty(properties[1], value, important);
addProperty(properties[2], value, important);
addProperty(properties[3], value, important);
m_implicitShorthand = false;
break;
}
case 2: {
if (!parseValue(properties[0], important) || !parseValue(properties[1], important))
return false;
CSSValue *value = parsedProperties[numParsedProperties-2]->value();
m_implicitShorthand = true;
addProperty(properties[2], value, important);
value = parsedProperties[numParsedProperties-2]->value();
addProperty(properties[3], value, important);
m_implicitShorthand = false;
break;
}
case 3: {
if (!parseValue(properties[0], important) || !parseValue(properties[1], important) || !parseValue(properties[2], important))
return false;
CSSValue *value = parsedProperties[numParsedProperties-2]->value();
m_implicitShorthand = true;
addProperty(properties[3], value, important);
m_implicitShorthand = false;
break;
}
case 4: {
if (!parseValue(properties[0], important) || !parseValue(properties[1], important) ||
!parseValue(properties[2], important) || !parseValue(properties[3], important))
return false;
break;
}
default: {
return false;
}
}
return true;
}
bool CSSParser::parseContent(int propId, bool important)
{
RefPtr<CSSValueList> values = new CSSValueList;
while (Value* val = valueList->current()) {
RefPtr<CSSValue> parsedValue;
if (val->unit == CSSPrimitiveValue::CSS_URI) {
String value = parseURL(domString(val->string));
parsedValue = new CSSImageValue(
KURL(styleElement->baseURL().deprecatedString(), value.deprecatedString()).string(), styleElement);
} else if (val->unit == Value::Function) {
ValueList *args = val->function->args;
String fname = domString(val->function->name).lower();
if (!args)
return false;
if (fname == "attr(") {
if (args->size() != 1)
return false;
Value* a = args->current();
String attrName = domString(a->string);
if (document()->isHTMLDocument())
attrName = attrName.lower();
parsedValue = new CSSPrimitiveValue(attrName, CSSPrimitiveValue::CSS_ATTR);
} else if (fname == "counter(") {
parsedValue = parseCounterContent(args, false);
if (!parsedValue) return false;
} else if (fname == "counters(") {
parsedValue = parseCounterContent(args, true);
if (!parsedValue)
return false;
} else
return false;
} else if (val->unit == CSSPrimitiveValue::CSS_IDENT) {
} else if (val->unit == CSSPrimitiveValue::CSS_STRING) {
parsedValue = new CSSPrimitiveValue(domString(val->string), CSSPrimitiveValue::CSS_STRING);
}
if (!parsedValue)
break;
values->append(parsedValue.release());
valueList->next();
}
if (values->length()) {
addProperty(propId, values.release(), important);
valueList->next();
return true;
}
return false;
}
PassRefPtr<CSSValue> CSSParser::parseBackgroundColor()
{
int id = valueList->current()->id;
if (id == CSS_VAL__WEBKIT_TEXT || (id >= CSS_VAL_AQUA && id <= CSS_VAL_WINDOWTEXT) || id == CSS_VAL_MENU ||
(id >= CSS_VAL_GREY && id < CSS_VAL__WEBKIT_TEXT && !strict))
return new CSSPrimitiveValue(id);
return parseColor();
}
bool CSSParser::parseBackgroundImage(RefPtr<CSSValue>& value)
{
if (valueList->current()->id == CSS_VAL_NONE) {
value = new CSSImageValue();
return true;
}
if (valueList->current()->unit == CSSPrimitiveValue::CSS_URI) {
String uri = parseURL(domString(valueList->current()->string));
if (!uri.isEmpty())
value = new CSSImageValue(KURL(styleElement->baseURL().deprecatedString(), uri.deprecatedString()).string(),
styleElement);
return true;
}
return false;
}
PassRefPtr<CSSValue> CSSParser::parseBackgroundPositionXY(bool& xFound, bool& yFound)
{
int id = valueList->current()->id;
if (id == CSS_VAL_LEFT || id == CSS_VAL_TOP || id == CSS_VAL_RIGHT || id == CSS_VAL_BOTTOM || id == CSS_VAL_CENTER) {
int percent = 0;
if (id == CSS_VAL_LEFT || id == CSS_VAL_RIGHT) {
if (xFound)
return 0;
xFound = true;
if (id == CSS_VAL_RIGHT)
percent = 100;
}
else if (id == CSS_VAL_TOP || id == CSS_VAL_BOTTOM) {
if (yFound)
return 0;
yFound = true;
if (id == CSS_VAL_BOTTOM)
percent = 100;
}
else if (id == CSS_VAL_CENTER)
percent = 50;
return new CSSPrimitiveValue(percent, CSSPrimitiveValue::CSS_PERCENTAGE);
}
if (validUnit(valueList->current(), FPercent|FLength, strict))
return new CSSPrimitiveValue(valueList->current()->fValue,
(CSSPrimitiveValue::UnitTypes)valueList->current()->unit);
return 0;
}
void CSSParser::parseBackgroundPosition(RefPtr<CSSValue>& value1, RefPtr<CSSValue>& value2)
{
Value* value = valueList->current();
bool value1IsX = false, value1IsY = false;
value1 = parseBackgroundPositionXY(value1IsX, value1IsY);
if (!value1)
return;
value = valueList->next();
if (value && value->unit == Value::Operator && value->iValue == ',')
value = 0;
bool value2IsX = false, value2IsY = false;
if (value) {
value2 = parseBackgroundPositionXY(value2IsX, value2IsY);
if (value2)
valueList->next();
else {
if (!inShorthand()) {
value1.clear();
return;
}
}
}
if (!value2)
value2 = new CSSPrimitiveValue(50, CSSPrimitiveValue::CSS_PERCENTAGE);
if (value1IsY || value2IsX)
value1.swap(value2);
}
void CSSParser::parseTransformOrigin(RefPtr<CSSValue>& value1, RefPtr<CSSValue>& value2, RefPtr<CSSValue>& value3)
{
parseBackgroundPosition(value1, value2);
if (valueList->current() && validUnit(valueList->current(), FLength, strict))
value3 = new CSSPrimitiveValue(valueList->current()->fValue,
(CSSPrimitiveValue::UnitTypes)valueList->current()->unit);
if (value3)
valueList->next();
}
PassRefPtr<CSSValue> CSSParser::parseBackgroundSize()
{
Value* value = valueList->current();
CSSPrimitiveValue* parsedValue1;
if (value->id == CSS_VAL_AUTO)
parsedValue1 = new CSSPrimitiveValue(0, CSSPrimitiveValue::CSS_UNKNOWN);
else {
if (!validUnit(value, FLength|FPercent, strict))
return 0;
parsedValue1 = new CSSPrimitiveValue(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit);
}
CSSPrimitiveValue* parsedValue2 = parsedValue1;
if ((value = valueList->next())) {
if (value->id == CSS_VAL_AUTO)
parsedValue2 = new CSSPrimitiveValue(0, CSSPrimitiveValue::CSS_UNKNOWN);
else {
if (!validUnit(value, FLength|FPercent, strict)) {
delete parsedValue1;
return 0;
}
parsedValue2 = new CSSPrimitiveValue(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit);
}
}
Pair* pair = new Pair(parsedValue1, parsedValue2);
return new CSSPrimitiveValue(pair);
}
bool CSSParser::parseBackgroundProperty(int propId, int& propId1, int& propId2,
RefPtr<CSSValue>& retValue1, RefPtr<CSSValue>& retValue2)
{
RefPtr<CSSValueList> values;
RefPtr<CSSValueList> values2;
Value* val;
RefPtr<CSSValue> value;
RefPtr<CSSValue> value2;
bool allowComma = false;
retValue1 = retValue2 = 0;
propId1 = propId;
propId2 = propId;
if (propId == CSS_PROP_BACKGROUND_POSITION) {
propId1 = CSS_PROP_BACKGROUND_POSITION_X;
propId2 = CSS_PROP_BACKGROUND_POSITION_Y;
}
while ((val = valueList->current())) {
RefPtr<CSSValue> currValue;
RefPtr<CSSValue> currValue2;
if (allowComma) {
if (val->unit != Value::Operator || val->iValue != ',')
return false;
valueList->next();
allowComma = false;
} else {
switch (propId) {
case CSS_PROP_BACKGROUND_ATTACHMENT:
if (val->id == CSS_VAL_SCROLL || val->id == CSS_VAL_FIXED) {
currValue = new CSSPrimitiveValue(val->id);
valueList->next();
}
break;
case CSS_PROP_BACKGROUND_COLOR:
currValue = parseBackgroundColor();
if (currValue)
valueList->next();
break;
case CSS_PROP_BACKGROUND_IMAGE:
if (parseBackgroundImage(currValue))
valueList->next();
break;
case CSS_PROP__WEBKIT_BACKGROUND_CLIP:
case CSS_PROP__WEBKIT_BACKGROUND_ORIGIN:
if (val->id == CSS_VAL_BORDER || val->id == CSS_VAL_PADDING || val->id == CSS_VAL_CONTENT) {
currValue = new CSSPrimitiveValue(val->id);
valueList->next();
}
break;
case CSS_PROP_BACKGROUND_POSITION:
parseBackgroundPosition(currValue, currValue2);
break;
case CSS_PROP_BACKGROUND_POSITION_X: {
bool xFound = false, yFound = true;
currValue = parseBackgroundPositionXY(xFound, yFound);
if (currValue)
valueList->next();
break;
}
case CSS_PROP_BACKGROUND_POSITION_Y: {
bool xFound = true, yFound = false;
currValue = parseBackgroundPositionXY(xFound, yFound);
if (currValue)
valueList->next();
break;
}
case CSS_PROP__WEBKIT_BACKGROUND_COMPOSITE:
if ((val->id >= CSS_VAL_CLEAR && val->id <= CSS_VAL_PLUS_LIGHTER) || val->id == CSS_VAL_HIGHLIGHT) {
currValue = new CSSPrimitiveValue(val->id);
valueList->next();
}
break;
case CSS_PROP_BACKGROUND_REPEAT:
if (val->id >= CSS_VAL_REPEAT && val->id <= CSS_VAL_NO_REPEAT) {
currValue = new CSSPrimitiveValue(val->id);
valueList->next();
}
break;
case CSS_PROP__WEBKIT_BACKGROUND_SIZE:
currValue = parseBackgroundSize();
if (currValue)
valueList->next();
break;
}
if (!currValue)
return false;
if (value && !values) {
values = new CSSValueList();
values->append(value.release());
}
if (value2 && !values2) {
values2 = new CSSValueList();
values2->append(value2.release());
}
if (values)
values->append(currValue.release());
else
value = currValue.release();
if (currValue2) {
if (values2)
values2->append(currValue2.release());
else
value2 = currValue2.release();
}
allowComma = true;
}
if (inShorthand())
break;
}
if (values && values->length()) {
retValue1 = values.release();
if (values2 && values2->length())
retValue2 = values2.release();
return true;
}
if (value) {
retValue1 = value.release();
retValue2 = value2.release();
return true;
}
return false;
}
PassRefPtr<CSSValue> CSSParser::parseAnimationDirection()
{
Value* value = valueList->current();
if (value->id == CSS_VAL_NORMAL || value->id == CSS_VAL_ALTERNATE)
return new CSSPrimitiveValue(value->id);
return 0;
}
PassRefPtr<CSSValue> CSSParser::parseTransitionDuration()
{
Value* value = valueList->current();
if (validUnit(value, FTime | FNonNeg, strict)) {
return new CSSPrimitiveValue(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit);
}
return 0;
}
PassRefPtr<CSSValue> CSSParser::parseAnimationPlayState()
{
Value* value = valueList->current();
if (value->id == CSS_VAL_RUNNING || value->id == CSS_VAL_PAUSED)
return new CSSPrimitiveValue(value->id);
return 0;
}
PassRefPtr<CSSValue> CSSParser::parseTransitionIterationCount()
{
Value* value = valueList->current();
if (value->id == CSS_VAL_INFINITE)
return new CSSPrimitiveValue(value->id);
if (validUnit(value, FNumber|FNonNeg, strict))
return new CSSPrimitiveValue(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit);
return 0;
}
PassRefPtr<CSSValue> CSSParser::parseAnimationDelay()
{
Value* value = valueList->current();
if (value->id == CSS_VAL_NOW)
return new CSSPrimitiveValue(value->id);
if (validUnit(value, FTime, strict))
return new CSSPrimitiveValue(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit);
return 0;
}
bool CSSParser::parseTimingFunctionValue(ValueList*& args, double& result)
{
Value* v = args->current();
if (!validUnit(v, FNumber, strict))
return false;
result = v->fValue;
v = args->next();
if (!v)
return true;
if (v->unit != Value::Operator && v->iValue != ',')
return false;
v = args->next();
return true;
}
PassRefPtr<CSSValue> CSSParser::parseTransitionTimingFunction()
{
Value* value = valueList->current();
if (value->id == CSS_VAL_EASE || value->id == CSS_VAL_LINEAR || value->id == CSS_VAL_EASE_IN || value->id == CSS_VAL_EASE_OUT || value->id == CSS_VAL_EASE_IN_OUT)
return new CSSPrimitiveValue(value->id);
if (value->unit != Value::Function)
return 0;
ValueList* args = value->function->args;
String fname = domString(value->function->name).lower();
if (fname != "cubic-bezier(" || !args || args->size() != 7)
return 0;
double x1, y1, x2, y2;
if (!parseTimingFunctionValue(args, x1))
return 0;
if (!parseTimingFunctionValue(args, y1))
return 0;
if (!parseTimingFunctionValue(args, x2))
return 0;
if (!parseTimingFunctionValue(args, y2))
return 0;
return new CSSTimingFunctionValue(x1, y1, x2, y2);
}
PassRefPtr<CSSValue> CSSParser::parseAnimationName()
{
Value* value = valueList->current();
if (value->unit == CSSPrimitiveValue::CSS_STRING || value->unit == CSSPrimitiveValue::CSS_IDENT) {
String str = domString(value->string);
str.lower();
if (value->id == CSS_VAL_NONE || (value->unit == CSSPrimitiveValue::CSS_STRING && str == "none")) {
return new CSSPrimitiveValue(CSS_VAL_NONE);
} else {
return new CSSPrimitiveValue(str, CSSPrimitiveValue::CSS_STRING);
}
}
return 0;
}
PassRefPtr<CSSValue> CSSParser::parseTransitionProperty()
{
Value* value = valueList->current();
if (value->unit == CSSPrimitiveValue::CSS_IDENT) {
String str = domString(value->string);
str.lower();
if (str == "all")
return new CSSPrimitiveValue(cAnimateAll);
if (str == "none")
return new CSSPrimitiveValue(cAnimateNone);
CString propertyName = str.utf8();
int result = getPropertyID(propertyName.data(), propertyName.length());
if (result)
return new CSSPrimitiveValue(result);
}
return 0;
}
bool CSSParser::parseTransitionProperty(int propId, RefPtr<CSSValue>& result)
{
RefPtr<CSSValueList> values;
Value* val;
RefPtr<CSSValue> value;
bool allowComma = false;
result = 0;
while ((val = valueList->current())) {
RefPtr<CSSValue> currValue;
if (allowComma) {
if (val->unit != Value::Operator || val->iValue != ',')
return false;
valueList->next();
allowComma = false;
}
else {
switch (propId) {
case CSS_PROP__WEBKIT_ANIMATION_DIRECTION:
currValue = parseAnimationDirection();
if (currValue)
valueList->next();
break;
case CSS_PROP__WEBKIT_ANIMATION_DURATION:
case CSS_PROP__WEBKIT_TRANSITION_DURATION:
currValue = parseTransitionDuration();
if (currValue)
valueList->next();
break;
case CSS_PROP__WEBKIT_ANIMATION_NAME:
case CSS_PROP__WEBKIT_TRANSITION_NAME:
currValue = parseAnimationName();
if (currValue)
valueList->next();
break;
case CSS_PROP__WEBKIT_ANIMATION_PLAY_STATE:
currValue = parseAnimationPlayState();
if (currValue)
valueList->next();
break;
case CSS_PROP__WEBKIT_ANIMATION_ITERATION_COUNT:
case CSS_PROP__WEBKIT_TRANSITION_ITERATION_COUNT:
currValue = parseTransitionIterationCount();
if (currValue)
valueList->next();
break;
case CSS_PROP__WEBKIT_ANIMATION_TIMING_FUNCTION:
case CSS_PROP__WEBKIT_TRANSITION_TIMING_FUNCTION:
currValue = parseTransitionTimingFunction();
if (currValue)
valueList->next();
break;
case CSS_PROP__WEBKIT_ANIMATION_DELAY:
case CSS_PROP__WEBKIT_TRANSITION_DELAY:
currValue = parseAnimationDelay();
if (currValue)
valueList->next();
break;
case CSS_PROP__WEBKIT_TRANSITION_PROPERTY:
currValue = parseTransitionProperty();
if (currValue)
valueList->next();
break;
}
if (!currValue)
return false;
if (value && !values) {
values = new CSSValueList();
values->append(value.release());
}
if (values)
values->append(currValue.release());
else
value = currValue.release();
allowComma = true;
}
if (inShorthand())
break;
}
if (values && values->length()) {
result = values.release();
return true;
}
if (value) {
result = value.release();
return true;
}
return false;
}
#if ENABLE(DASHBOARD_SUPPORT)
#define DASHBOARD_REGION_NUM_PARAMETERS 6
#define DASHBOARD_REGION_SHORT_NUM_PARAMETERS 2
static Value *skipCommaInDashboardRegion (ValueList *args)
{
if (args->size() == (DASHBOARD_REGION_NUM_PARAMETERS*2-1) ||
args->size() == (DASHBOARD_REGION_SHORT_NUM_PARAMETERS*2-1)) {
Value *current = args->current();
if (current->unit == Value::Operator && current->iValue == ',')
return args->next();
}
return args->current();
}
bool CSSParser::parseDashboardRegions(int propId, bool important)
{
bool valid = true;
Value *value = valueList->current();
if (value->id == CSS_VAL_NONE) {
if (valueList->next())
return false;
addProperty(propId, new CSSPrimitiveValue(value->id), important);
return valid;
}
RefPtr<DashboardRegion> firstRegion = new DashboardRegion;
DashboardRegion* region = 0;
while (value) {
if (region == 0) {
region = firstRegion.get();
} else {
RefPtr<DashboardRegion> nextRegion = new DashboardRegion();
region->m_next = nextRegion;
region = nextRegion.get();
}
if (value->unit != Value::Function) {
valid = false;
break;
}
ValueList* args = value->function->args;
String fname = domString(value->function->name).lower();
if (fname != "dashboard-region(" || !args) {
valid = false;
break;
}
int numArgs = args->size();
if ((numArgs != DASHBOARD_REGION_NUM_PARAMETERS && numArgs != (DASHBOARD_REGION_NUM_PARAMETERS*2-1)) &&
(numArgs != DASHBOARD_REGION_SHORT_NUM_PARAMETERS && numArgs != (DASHBOARD_REGION_SHORT_NUM_PARAMETERS*2-1))){
valid = false;
break;
}
Value* arg = args->current();
if (arg->unit != CSSPrimitiveValue::CSS_IDENT) {
valid = false;
break;
}
region->m_label = domString(arg->string);
arg = args->next();
arg = skipCommaInDashboardRegion (args);
if (arg->unit != CSSPrimitiveValue::CSS_IDENT) {
valid = false;
break;
}
String geometryType = domString(arg->string).lower();
if (geometryType == "circle")
region->m_isCircle = true;
else if (geometryType == "rectangle")
region->m_isRectangle = true;
else {
valid = false;
break;
}
region->m_geometryType = domString(arg->string);
if (numArgs == DASHBOARD_REGION_SHORT_NUM_PARAMETERS || numArgs == (DASHBOARD_REGION_SHORT_NUM_PARAMETERS*2-1)) {
CSSPrimitiveValue *amount = new CSSPrimitiveValue(CSS_VAL_INVALID);
region->setTop(amount);
region->setRight(amount);
region->setBottom(amount);
region->setLeft(amount);
}
else {
int i;
for (i = 0; i < 4; i++) {
arg = args->next();
arg = skipCommaInDashboardRegion (args);
valid = arg->id == CSS_VAL_AUTO || validUnit(arg, FLength, strict);
if (!valid)
break;
CSSPrimitiveValue *amount = arg->id == CSS_VAL_AUTO ?
new CSSPrimitiveValue(CSS_VAL_AUTO) :
new CSSPrimitiveValue(arg->fValue, (CSSPrimitiveValue::UnitTypes) arg->unit);
if (i == 0)
region->setTop(amount);
else if (i == 1)
region->setRight(amount);
else if (i == 2)
region->setBottom(amount);
else
region->setLeft(amount);
}
}
if (args->next())
return false;
value = valueList->next();
}
if (valid)
addProperty(propId, new CSSPrimitiveValue(firstRegion.release()), important);
return valid;
}
#endif
PassRefPtr<CSSValue> CSSParser::parseCounterContent(ValueList* args, bool counters)
{
unsigned numArgs = args->size();
if (counters && numArgs != 3 && numArgs != 5)
return 0;
if (!counters && numArgs != 1 && numArgs != 3)
return 0;
Value* i = args->current();
RefPtr<CSSPrimitiveValue> identifier = new CSSPrimitiveValue(domString(i->string),
CSSPrimitiveValue::CSS_STRING);
RefPtr<CSSPrimitiveValue> separator;
if (!counters)
separator = new CSSPrimitiveValue(String(), CSSPrimitiveValue::CSS_STRING);
else {
i = args->next();
if (i->unit != Value::Operator || i->iValue != ',')
return 0;
i = args->next();
if (i->unit != CSSPrimitiveValue::CSS_STRING)
return 0;
separator = new CSSPrimitiveValue(domString(i->string), (CSSPrimitiveValue::UnitTypes) i->unit);
}
RefPtr<CSSPrimitiveValue> listStyle;
i = args->next();
if (!i) listStyle = new CSSPrimitiveValue(CSS_VAL_DECIMAL - CSS_VAL_DISC, CSSPrimitiveValue::CSS_NUMBER);
else {
if (i->unit != Value::Operator || i->iValue != ',')
return 0;
i = args->next();
if (i->unit != CSSPrimitiveValue::CSS_IDENT)
return 0;
short ls = 0;
if (i->id == CSS_VAL_NONE)
ls = CSS_VAL_KATAKANA_IROHA - CSS_VAL_DISC + 1;
else if (i->id >= CSS_VAL_DISC && i->id <= CSS_VAL_KATAKANA_IROHA)
ls = i->id - CSS_VAL_DISC;
else
return 0;
listStyle = new CSSPrimitiveValue(ls, (CSSPrimitiveValue::UnitTypes) i->unit);
}
return new CSSPrimitiveValue(new Counter(identifier.release(), listStyle.release(), separator.release()));
}
bool CSSParser::parseShape(int propId, bool important)
{
Value *value = valueList->current();
ValueList *args = value->function->args;
String fname = domString(value->function->name).lower();
if (fname != "rect(" || !args)
return false;
if (args->size() != 4 && args->size() != 7)
return false;
Rect *rect = new Rect();
bool valid = true;
int i = 0;
Value *a = args->current();
while (a) {
valid = a->id == CSS_VAL_AUTO || validUnit(a, FLength | FPercent | FNumber, strict);
if (!valid)
break;
CSSPrimitiveValue *length = a->id == CSS_VAL_AUTO ?
new CSSPrimitiveValue(CSS_VAL_AUTO) :
new CSSPrimitiveValue(a->fValue, (CSSPrimitiveValue::UnitTypes) a->unit);
if (i == 0)
rect->setTop(length);
else if (i == 1)
rect->setRight(length);
else if (i == 2)
rect->setBottom(length);
else
rect->setLeft(length);
a = args->next();
if (a && args->size() == 7) {
if (a->unit == Value::Operator && a->iValue == ',') {
a = args->next();
} else {
valid = false;
break;
}
}
i++;
}
if (valid) {
addProperty(propId, new CSSPrimitiveValue(rect), important);
valueList->next();
return true;
}
delete rect;
return false;
}
bool CSSParser::parseFont(bool important)
{
bool valid = true;
Value *value = valueList->current();
FontValue *font = new FontValue;
while (value) {
int id = value->id;
if (id) {
if (id == CSS_VAL_NORMAL) {
} else if (id == CSS_VAL_ITALIC || id == CSS_VAL_OBLIQUE) {
if (font->style)
goto invalid;
font->style = new CSSPrimitiveValue(id);
} else if (id == CSS_VAL_SMALL_CAPS) {
if (font->variant)
goto invalid;
font->variant = new CSSPrimitiveValue(id);
} else if (id >= CSS_VAL_BOLD && id <= CSS_VAL_LIGHTER) {
if (font->weight)
goto invalid;
font->weight = new CSSPrimitiveValue(id);
} else {
valid = false;
}
} else if (!font->weight && validUnit(value, FInteger|FNonNeg, true)) {
int weight = (int)value->fValue;
int val = 0;
if (weight == 100)
val = CSS_VAL_100;
else if (weight == 200)
val = CSS_VAL_200;
else if (weight == 300)
val = CSS_VAL_300;
else if (weight == 400)
val = CSS_VAL_400;
else if (weight == 500)
val = CSS_VAL_500;
else if (weight == 600)
val = CSS_VAL_600;
else if (weight == 700)
val = CSS_VAL_700;
else if (weight == 800)
val = CSS_VAL_800;
else if (weight == 900)
val = CSS_VAL_900;
if (val)
font->weight = new CSSPrimitiveValue(val);
else
valid = false;
} else {
valid = false;
}
if (!valid)
break;
value = valueList->next();
}
if (!value)
goto invalid;
if (!font->style)
font->style = new CSSPrimitiveValue(CSS_VAL_NORMAL);
if (!font->variant)
font->variant = new CSSPrimitiveValue(CSS_VAL_NORMAL);
if (!font->weight)
font->weight = new CSSPrimitiveValue(CSS_VAL_NORMAL);
if (value->id >= CSS_VAL_XX_SMALL && value->id <= CSS_VAL_LARGER)
font->size = new CSSPrimitiveValue(value->id);
else if (validUnit(value, FLength|FPercent, strict))
font->size = new CSSPrimitiveValue(value->fValue, (CSSPrimitiveValue::UnitTypes) value->unit);
value = valueList->next();
if (!font->size || !value)
goto invalid;
if (value->unit == Value::Operator && value->iValue == '/') {
value = valueList->next();
if (!value)
goto invalid;
if (value->id == CSS_VAL_NORMAL) {
} else if (validUnit(value, FNumber|FLength|FPercent, strict))
font->lineHeight = new CSSPrimitiveValue(value->fValue, (CSSPrimitiveValue::UnitTypes) value->unit);
else
goto invalid;
value = valueList->next();
if (!value)
goto invalid;
}
if (!font->lineHeight)
font->lineHeight = new CSSPrimitiveValue(CSS_VAL_NORMAL);
font->family = parseFontFamily();
if (valueList->current() || !font->family)
goto invalid;
addProperty(CSS_PROP_FONT, font, important);
return true;
invalid:
delete font;
return false;
}
PassRefPtr<CSSValueList> CSSParser::parseFontFamily()
{
CSSValueList* list = new CSSValueList;
Value* value = valueList->current();
FontFamilyValue* currFamily = 0;
while (value) {
Value* nextValue = valueList->next();
bool nextValBreaksFont = !nextValue ||
(nextValue->unit == Value::Operator && nextValue->iValue == ',');
bool nextValIsFontName = nextValue &&
((nextValue->id >= CSS_VAL_SERIF && nextValue->id <= CSS_VAL__WEBKIT_BODY) ||
(nextValue->unit == CSSPrimitiveValue::CSS_STRING || nextValue->unit == CSSPrimitiveValue::CSS_IDENT));
if (value->id >= CSS_VAL_SERIF && value->id <= CSS_VAL__WEBKIT_BODY) {
if (currFamily) {
currFamily->parsedFontName += ' ';
currFamily->parsedFontName += deprecatedString(value->string);
}
else if (nextValBreaksFont || !nextValIsFontName)
list->append(new CSSPrimitiveValue(value->id));
else
list->append(currFamily = new FontFamilyValue(deprecatedString(value->string)));
}
else if (value->unit == CSSPrimitiveValue::CSS_STRING) {
currFamily = 0;
list->append(new FontFamilyValue(deprecatedString(value->string)));
}
else if (value->unit == CSSPrimitiveValue::CSS_IDENT) {
if (currFamily) {
currFamily->parsedFontName += ' ';
currFamily->parsedFontName += deprecatedString(value->string);
}
else if (nextValBreaksFont || !nextValIsFontName)
list->append(new FontFamilyValue(deprecatedString(value->string)));
else
list->append(currFamily = new FontFamilyValue(deprecatedString(value->string)));
}
else {
break;
}
if (!nextValue)
break;
if (nextValBreaksFont) {
value = valueList->next();
currFamily = 0;
}
else if (nextValIsFontName)
value = nextValue;
else
break;
}
if (!list->length()) {
delete list;
list = 0;
}
return list;
}
bool CSSParser::parseFontFaceSrc()
{
RefPtr<CSSValueList> values(new CSSValueList());
Value* val;
bool expectComma = false;
bool allowFormat = false;
bool failed = false;
RefPtr<CSSFontFaceSrcValue> uriValue;
while ((val = valueList->current())) {
RefPtr<CSSFontFaceSrcValue> parsedValue;
if (val->unit == CSSPrimitiveValue::CSS_URI && !expectComma) {
String value = parseURL(domString(val->string));
parsedValue = new CSSFontFaceSrcValue(KURL(styleElement->baseURL().deprecatedString(), value.deprecatedString()).string(), false);
uriValue = parsedValue;
allowFormat = true;
expectComma = true;
} else if (val->unit == Value::Function) {
String fname = domString(val->function->name).lower();
ValueList* args = val->function->args;
if (args && args->size() == 1) {
if (fname == "local(" && !expectComma) {
expectComma = true;
allowFormat = false;
Value* a = args->current();
uriValue.clear();
parsedValue = new CSSFontFaceSrcValue(domString(a->string), true);
} else if (fname == "format(" && allowFormat && uriValue) {
expectComma = true;
allowFormat = false;
uriValue->setFormat(domString(args->current()->string));
uriValue.clear();
valueList->next();
continue;
}
}
} else if (val->unit == Value::Operator && val->iValue == ',' && expectComma) {
expectComma = false;
allowFormat = false;
uriValue.clear();
valueList->next();
continue;
}
if (parsedValue)
values->append(parsedValue.release());
else {
failed = true;
break;
}
valueList->next();
}
if (values->length() && !failed) {
addProperty(CSS_PROP_SRC, values.release(), important);
valueList->next();
return true;
}
return false;
}
bool CSSParser::parseFontFaceUnicodeRange()
{
CSSValueList* values = new CSSValueList();
Value* currentValue;
bool failed = false;
while ((currentValue = valueList->current())) {
if (valueList->current()->unit != CSSPrimitiveValue::CSS_UNICODE_RANGE) {
failed = true;
break;
}
String rangeString = domString(valueList->current()->string);
UChar32 from = 0;
UChar32 to = 0;
unsigned length = rangeString.length();
if (length < 3) {
failed = true;
break;
}
unsigned i = 2;
while (i < length) {
UChar c = rangeString[i];
if (c == '-' || c == '?')
break;
from *= 16;
if (c >= '0' && c <= '9')
from += c - '0';
else if (c >= 'A' && c <= 'F')
from += 10 + c - 'A';
else if (c >= 'a' && c <= 'f')
from += 10 + c - 'a';
else {
failed = true;
break;
}
i++;
}
if (failed)
break;
if (i == length)
to = from;
else if (rangeString[i] == '?') {
unsigned span = 1;
while (i < length && rangeString[i] == '?') {
span *= 16;
from *= 16;
i++;
}
if (i < length)
failed = true;
to = from + span - 1;
} else {
if (length < i + 2) {
failed = true;
break;
}
i++;
while (i < length) {
UChar c = rangeString[i];
to *= 16;
if (c >= '0' && c <= '9')
to += c - '0';
else if (c >= 'A' && c <= 'F')
to += 10 + c - 'A';
else if (c >= 'a' && c <= 'f')
to += 10 + c - 'a';
else {
failed = true;
break;
}
i++;
}
if (failed)
break;
}
values->append(new CSSUnicodeRangeValue(from, to));
valueList->next();
}
if (failed || !values->length()) {
delete values;
return false;
}
addProperty(CSS_PROP_UNICODE_RANGE, values, important);
return true;
}
bool CSSParser::parseColor(const String &name, RGBA32& rgb, bool strict)
{
if (!strict && Color::parseHexColor(name, rgb))
return true;
Color tc;
tc.setNamedColor(name.lower());
if (tc.isValid()) {
rgb = tc.rgb();
return true;
}
return false;
}
bool CSSParser::parseColorParameters(Value* value, int* colorArray, bool parseAlpha)
{
ValueList* args = value->function->args;
Value* v = args->current();
if (!validUnit(v, FInteger | FPercent, true))
return false;
colorArray[0] = static_cast<int>(v->fValue * (v->unit == CSSPrimitiveValue::CSS_PERCENTAGE ? 256.0 / 100.0 : 1.0));
for (int i = 1; i < 3; i++) {
v = args->next();
if (v->unit != Value::Operator && v->iValue != ',')
return false;
v = args->next();
if (!validUnit(v, FInteger | FPercent, true))
return false;
colorArray[i] = static_cast<int>(v->fValue * (v->unit == CSSPrimitiveValue::CSS_PERCENTAGE ? 256.0 / 100.0 : 1.0));
}
if (parseAlpha) {
v = args->next();
if (v->unit != Value::Operator && v->iValue != ',')
return false;
v = args->next();
if (!validUnit(v, FNumber, true))
return false;
colorArray[3] = static_cast<int>(max(0.0, min(1.0, v->fValue)) * 255);
}
return true;
}
bool CSSParser::parseHSLParameters(Value* value, double* colorArray, bool parseAlpha)
{
ValueList* args = value->function->args;
Value* v = args->current();
if (!validUnit(v, FNumber, true))
return false;
colorArray[0] = (((static_cast<int>(v->fValue) % 360) + 360) % 360) / 360.0;
for (int i = 1; i < 3; i++) {
v = args->next();
if (v->unit != Value::Operator && v->iValue != ',')
return false;
v = args->next();
if (!validUnit(v, FPercent, true))
return false;
colorArray[i] = max(0.0, min(100.0, v->fValue)) / 100.0; }
if (parseAlpha) {
v = args->next();
if (v->unit != Value::Operator && v->iValue != ',')
return false;
v = args->next();
if (!validUnit(v, FNumber, true))
return false;
colorArray[3] = max(0.0, min(1.0, v->fValue));
}
return true;
}
PassRefPtr<CSSPrimitiveValue> CSSParser::parseColor(Value* value)
{
RGBA32 c = Color::transparent;
if (!parseColorFromValue(value ? value : valueList->current(), c))
return 0;
return new CSSPrimitiveValue(c);
}
bool CSSParser::parseColorFromValue(Value* value, RGBA32& c, bool svg)
{
if (!strict && value->unit == CSSPrimitiveValue::CSS_NUMBER &&
value->fValue >= 0. && value->fValue < 1000000.) {
String str = String::format("%06d", (int)(value->fValue+.5));
if (!CSSParser::parseColor(str, c, strict))
return false;
} else if (value->unit == CSSPrimitiveValue::CSS_RGBCOLOR ||
value->unit == CSSPrimitiveValue::CSS_IDENT ||
(!strict && value->unit == CSSPrimitiveValue::CSS_DIMENSION)) {
if (!CSSParser::parseColor(domString(value->string), c, strict && value->unit == CSSPrimitiveValue::CSS_IDENT))
return false;
} else if (value->unit == Value::Function &&
value->function->args != 0 &&
value->function->args->size() == 5 &&
domString(value->function->name).lower() == "rgb(") {
int colorValues[3];
if (!parseColorParameters(value, colorValues, false))
return false;
c = makeRGB(colorValues[0], colorValues[1], colorValues[2]);
} else if (!svg) {
if (value->unit == Value::Function &&
value->function->args != 0 &&
value->function->args->size() == 7 &&
domString(value->function->name).lower() == "rgba(") {
int colorValues[4];
if (!parseColorParameters(value, colorValues, true))
return false;
c = makeRGBA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]);
} else if (value->unit == Value::Function &&
value->function->args != 0 &&
value->function->args->size() == 5 &&
domString(value->function->name).lower() == "hsl(") {
double colorValues[3];
if (!parseHSLParameters(value, colorValues, false))
return false;
c = makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], 1.0);
} else if (value->unit == Value::Function &&
value->function->args != 0 &&
value->function->args->size() == 7 &&
domString(value->function->name).lower() == "hsla(") {
double colorValues[4];
if (!parseHSLParameters(value, colorValues, true))
return false;
c = makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]);
} else
return false;
} else
return false;
return true;
}
struct ShadowParseContext {
ShadowParseContext()
: allowX(true)
, allowY(false)
, allowBlur(false)
, allowColor(true)
, allowBreak(true)
{}
bool allowLength() { return allowX || allowY || allowBlur; }
void commitValue() {
if (x || y || blur || color) {
if (!values)
values = new CSSValueList();
values->append(new ShadowValue(x.release(), y.release(), blur.release(), color.release()));
}
x = y = blur = color = 0;
allowX = allowColor = allowBreak = true;
allowY = allowBlur = false;
}
void commitLength(Value* v) {
RefPtr<CSSPrimitiveValue> val = new CSSPrimitiveValue(v->fValue, (CSSPrimitiveValue::UnitTypes)v->unit);
if (allowX) {
x = val.release();
allowX = false; allowY = true; allowColor = false; allowBreak = false;
}
else if (allowY) {
y = val.release();
allowY = false; allowBlur = true; allowColor = true; allowBreak = true;
}
else if (allowBlur) {
blur = val.release();
allowBlur = false;
}
}
void commitColor(PassRefPtr<CSSPrimitiveValue> val) {
color = val;
allowColor = false;
if (allowX)
allowBreak = false;
else
allowBlur = false;
}
RefPtr<CSSValueList> values;
RefPtr<CSSPrimitiveValue> x;
RefPtr<CSSPrimitiveValue> y;
RefPtr<CSSPrimitiveValue> blur;
RefPtr<CSSPrimitiveValue> color;
bool allowX;
bool allowY;
bool allowBlur;
bool allowColor;
bool allowBreak;
};
bool CSSParser::parseShadow(int propId, bool important)
{
ShadowParseContext context;
Value* val;
while ((val = valueList->current())) {
if (val->unit == Value::Operator) {
if (val->iValue != ',' || !context.allowBreak)
return false;
context.commitValue();
}
else if (validUnit(val, FLength, true)) {
if (!context.allowLength())
return false;
context.commitLength(val);
}
else {
RefPtr<CSSPrimitiveValue> parsedColor;
bool isColor = (val->id >= CSS_VAL_AQUA && val->id <= CSS_VAL_WINDOWTEXT || val->id == CSS_VAL_MENU ||
(val->id >= CSS_VAL__WEBKIT_FOCUS_RING_COLOR && val->id <= CSS_VAL__WEBKIT_TEXT && !strict));
if (isColor) {
if (!context.allowColor)
return false;
parsedColor = new CSSPrimitiveValue(val->id);
}
if (!parsedColor)
parsedColor = parseColor(val);
if (!parsedColor || !context.allowColor)
return false;
context.commitColor(parsedColor.release());
}
valueList->next();
}
if (context.allowBreak) {
context.commitValue();
if (context.values->length()) {
addProperty(propId, context.values.release(), important);
valueList->next();
return true;
}
}
return false;
}
struct BorderImageParseContext
{
BorderImageParseContext()
: m_allowBreak(false)
, m_allowNumber(false)
, m_allowSlash(false)
, m_allowWidth(false)
, m_allowRule(false)
, m_borderTop(0)
, m_borderRight(0)
, m_borderBottom(0)
, m_borderLeft(0)
, m_horizontalRule(0)
, m_verticalRule(0)
{}
bool allowBreak() const { return m_allowBreak; }
bool allowNumber() const { return m_allowNumber; }
bool allowSlash() const { return m_allowSlash; }
bool allowWidth() const { return m_allowWidth; }
bool allowRule() const { return m_allowRule; }
void commitImage(CSSImageValue* image) { m_image = image; m_allowNumber = true; }
void commitNumber(Value* v) {
PassRefPtr<CSSPrimitiveValue> val = new CSSPrimitiveValue(v->fValue, (CSSPrimitiveValue::UnitTypes)v->unit);
if (!m_top)
m_top = val;
else if (!m_right)
m_right = val;
else if (!m_bottom)
m_bottom = val;
else {
ASSERT(!m_left);
m_left = val;
}
m_allowBreak = m_allowSlash = m_allowRule = true;
m_allowNumber = !m_left;
}
void commitSlash() { m_allowBreak = m_allowSlash = m_allowNumber = false; m_allowWidth = true; }
void commitWidth(Value* val) {
if (!m_borderTop)
m_borderTop = val;
else if (!m_borderRight)
m_borderRight = val;
else if (!m_borderBottom)
m_borderBottom = val;
else {
ASSERT(!m_borderLeft);
m_borderLeft = val;
}
m_allowBreak = m_allowRule = true;
m_allowWidth = !m_borderLeft;
}
void commitRule(int keyword) {
if (!m_horizontalRule)
m_horizontalRule = keyword;
else if (!m_verticalRule)
m_verticalRule = keyword;
m_allowRule = !m_verticalRule;
}
void commitBorderImage(CSSParser* p, int propId, bool important) {
if (!m_right) {
m_right = new CSSPrimitiveValue(m_top->getDoubleValue(), (CSSPrimitiveValue::UnitTypes)m_top->primitiveType());
m_bottom = new CSSPrimitiveValue(m_top->getDoubleValue(), (CSSPrimitiveValue::UnitTypes)m_top->primitiveType());
m_left = new CSSPrimitiveValue(m_top->getDoubleValue(), (CSSPrimitiveValue::UnitTypes)m_top->primitiveType());
}
if (!m_bottom) {
m_bottom = new CSSPrimitiveValue(m_top->getDoubleValue(), (CSSPrimitiveValue::UnitTypes)m_top->primitiveType());
m_left = new CSSPrimitiveValue(m_right->getDoubleValue(), (CSSPrimitiveValue::UnitTypes)m_right->primitiveType());
}
if (!m_left)
m_left = new CSSPrimitiveValue(m_top->getDoubleValue(), (CSSPrimitiveValue::UnitTypes)m_top->primitiveType());
RefPtr<Rect> rect = new Rect;
rect->setTop(m_top);
rect->setRight(m_right);
rect->setBottom(m_bottom);
rect->setLeft(m_left);
if (!m_horizontalRule)
m_horizontalRule = CSS_VAL_STRETCH;
if (!m_verticalRule)
m_verticalRule = m_horizontalRule;
CSSBorderImageValue* borderImage = new CSSBorderImageValue(m_image, rect.release(), m_horizontalRule, m_verticalRule);
p->addProperty(propId, borderImage, important);
if (m_borderTop) {
ValueList newList;
newList.addValue(*m_borderTop);
if (m_borderRight)
newList.addValue(*m_borderRight);
if (m_borderBottom)
newList.addValue(*m_borderBottom);
if (m_borderLeft)
newList.addValue(*m_borderLeft);
p->valueList = &newList;
p->parseValue(CSS_PROP_BORDER_WIDTH, important);
p->valueList = 0;
}
}
bool m_allowBreak;
bool m_allowNumber;
bool m_allowSlash;
bool m_allowWidth;
bool m_allowRule;
RefPtr<CSSImageValue> m_image;
RefPtr<CSSPrimitiveValue> m_top;
RefPtr<CSSPrimitiveValue> m_right;
RefPtr<CSSPrimitiveValue> m_bottom;
RefPtr<CSSPrimitiveValue> m_left;
Value* m_borderTop;
Value* m_borderRight;
Value* m_borderBottom;
Value* m_borderLeft;
int m_horizontalRule;
int m_verticalRule;
};
bool CSSParser::parseBorderImage(int propId, bool important)
{
BorderImageParseContext context;
Value* val = valueList->current();
if (val->unit != CSSPrimitiveValue::CSS_URI)
return false;
String uri = parseURL(domString(val->string));
if (uri.isEmpty())
return false;
context.commitImage(new CSSImageValue(KURL(styleElement->baseURL().deprecatedString(), uri.deprecatedString()).string(),
styleElement));
while ((val = valueList->next())) {
if (context.allowNumber() && validUnit(val, FInteger|FNonNeg|FPercent, true)) {
context.commitNumber(val);
} else if (context.allowSlash() && val->unit == Value::Operator && val->iValue == '/') {
context.commitSlash();
} else if (context.allowWidth() &&
(val->id == CSS_VAL_THIN || val->id == CSS_VAL_MEDIUM || val->id == CSS_VAL_THICK || validUnit(val, FLength, strict))) {
context.commitWidth(val);
} else if (context.allowRule() &&
(val->id == CSS_VAL_STRETCH || val->id == CSS_VAL_ROUND || val->id == CSS_VAL_REPEAT)) {
context.commitRule(val->id);
} else {
return false;
}
}
if (context.allowBreak()) {
context.commitBorderImage(this, propId, important);
return true;
}
return false;
}
bool CSSParser::parseCounter(int propId, int defaultValue, bool important)
{
enum { ID, VAL } state = ID;
RefPtr<CSSValueList> list = new CSSValueList;
RefPtr<CSSPrimitiveValue> counterName;
while (true) {
Value* val = valueList->current();
switch (state) {
case ID:
if (val && val->unit == CSSPrimitiveValue::CSS_IDENT) {
counterName = new CSSPrimitiveValue(domString(val->string), CSSPrimitiveValue::CSS_STRING);
state = VAL;
valueList->next();
continue;
}
break;
case VAL: {
int i = defaultValue;
if (val && val->unit == CSSPrimitiveValue::CSS_NUMBER) {
i = (int)val->fValue;
valueList->next();
}
list->append(new CSSPrimitiveValue(new Pair(counterName.release(),
new CSSPrimitiveValue(i, CSSPrimitiveValue::CSS_NUMBER))));
state = ID;
continue;
}
}
break;
}
if (list->length() > 0) {
addProperty(propId, list.release(), important);
return true;
}
return false;
}
class TransformOperationInfo
{
public:
TransformOperationInfo(const String& fname)
: m_type(WebKitCSSTransformValue::UnknownTransformOperation)
, m_argCount(1)
, m_allowSingleArgument(false)
, m_unit(CSSParser::FUnknown)
{
if (fname == "scale(" || fname == "scalex(" || fname == "scaley(" || fname == "scalez(") {
m_unit = CSSParser::FNumber;
if (fname == "scale(")
m_type = WebKitCSSTransformValue::ScaleTransformOperation;
else if (fname == "scalex(")
m_type = WebKitCSSTransformValue::ScaleXTransformOperation;
else if (fname == "scaley(")
m_type = WebKitCSSTransformValue::ScaleYTransformOperation;
else
m_type = WebKitCSSTransformValue::ScaleZTransformOperation;
} else if (fname == "rotate(" || fname == "rotatex(" || fname == "rotatey(" || fname == "rotatez(") {
m_unit = CSSParser::FAngle;
if (fname == "rotate(")
m_type = WebKitCSSTransformValue::RotateTransformOperation;
else if (fname == "rotatex(")
m_type = WebKitCSSTransformValue::RotateXTransformOperation;
else if (fname == "rotatey(")
m_type = WebKitCSSTransformValue::RotateYTransformOperation;
else
m_type = WebKitCSSTransformValue::RotateZTransformOperation;
} else if (fname == "skew(" || fname == "skewx(" || fname == "skewy(") {
m_unit = CSSParser::FAngle;
if (fname == "skew(")
m_type = WebKitCSSTransformValue::SkewTransformOperation;
else if (fname == "skewx(")
m_type = WebKitCSSTransformValue::SkewXTransformOperation;
else
m_type = WebKitCSSTransformValue::SkewYTransformOperation;
} else if (fname == "translate(" || fname == "translatex(" || fname == "translatey(" || fname == "translatez(") {
m_unit = CSSParser::FLength | CSSParser::FPercent;
if (fname == "translate(")
m_type = WebKitCSSTransformValue::TranslateTransformOperation;
else if (fname == "translatex(")
m_type = WebKitCSSTransformValue::TranslateXTransformOperation;
else if (fname == "translatey(")
m_type = WebKitCSSTransformValue::TranslateYTransformOperation;
else
m_type = WebKitCSSTransformValue::TranslateZTransformOperation;
} else if (fname == "matrix(") {
m_type = WebKitCSSTransformValue::MatrixTransformOperation;
m_argCount = 11;
m_unit = CSSParser::FNumber;
} else if (fname == "matrix3d(") {
m_type = WebKitCSSTransformValue::Matrix3DTransformOperation;
m_argCount = 31;
m_unit = CSSParser::FNumber;
} else if (fname == "translate3d(") {
m_type = WebKitCSSTransformValue::Translate3DTransformOperation;
m_argCount = 5;
m_unit = CSSParser::FLength | CSSParser::FPercent;
} else if (fname == "scale3d(") {
m_type = WebKitCSSTransformValue::Scale3DTransformOperation;
m_argCount = 5;
m_unit = CSSParser::FNumber;
} else if (fname == "rotate3d(") {
m_type = WebKitCSSTransformValue::Rotate3DTransformOperation;
m_argCount = 7;
m_unit = CSSParser::FNumber;
} else if (fname == "perspective(") {
m_type = WebKitCSSTransformValue::PerspectiveTransformOperation;
m_unit = CSSParser::FNumber;
}
if (fname == "scale(" || fname == "skew(" || fname == "translate(") {
m_allowSingleArgument = true;
m_argCount = 3;
}
}
WebKitCSSTransformValue::TransformOperationType type() const { return m_type; }
unsigned argCount() const { return m_argCount; }
CSSParser::Units unit() const { return m_unit; }
bool unknown() const { return m_type == WebKitCSSTransformValue::UnknownTransformOperation; }
bool hasCorrectArgCount(unsigned argCount) { return m_argCount == argCount || (m_allowSingleArgument && argCount == 1); }
private:
WebKitCSSTransformValue::TransformOperationType m_type;
unsigned m_argCount;
bool m_allowSingleArgument;
CSSParser::Units m_unit;
};
PassRefPtr<CSSValue> CSSParser::parseTransform()
{
if (!valueList)
return 0;
RefPtr<CSSValueList> list = new CSSValueList(true);
for (Value* value = valueList->current(); value; value = valueList->next()) {
if (value->unit != Value::Function || !value->function)
return 0;
String fname = domString(value->function->name).lower();
ValueList* args = value->function->args;
if (!args)
return 0;
TransformOperationInfo info(fname);
if (info.unknown())
return 0;
if (!info.hasCorrectArgCount(args->size()))
return 0;
WebKitCSSTransformValue* transformValue = new WebKitCSSTransformValue(info.type());
list->append(transformValue);
Value* a = args->current();
unsigned argNumber = 0;
while (a) {
CSSParser::Units unit = info.unit();
if (info.type() == WebKitCSSTransformValue::Rotate3DTransformOperation && argNumber == 3) {
if (!validUnit(a, FAngle, true))
return 0;
}
else if (!validUnit(a, unit, true))
return 0;
transformValue->append(new CSSPrimitiveValue(a->fValue, (CSSPrimitiveValue::UnitTypes) a->unit));
a = args->next();
if (!a)
break;
if (a->unit != Value::Operator || a->iValue != ',')
return 0;
a = args->next();
argNumber++;
}
}
return list.release();
}
bool CSSParser::parseTransformOrigin(int propId, int& propId1, int& propId2, int& propId3, RefPtr<CSSValue>& value, RefPtr<CSSValue>& value2, RefPtr<CSSValue>& value3)
{
propId1 = propId;
propId2 = propId;
propId3 = propId;
if (propId == CSS_PROP__WEBKIT_TRANSFORM_ORIGIN) {
propId1 = CSS_PROP__WEBKIT_TRANSFORM_ORIGIN_X;
propId2 = CSS_PROP__WEBKIT_TRANSFORM_ORIGIN_Y;
propId3 = CSS_PROP__WEBKIT_TRANSFORM_ORIGIN_Z;
}
switch (propId) {
case CSS_PROP__WEBKIT_TRANSFORM_ORIGIN:
parseTransformOrigin(value, value2, value3);
break;
case CSS_PROP__WEBKIT_TRANSFORM_ORIGIN_X: {
bool xFound = false, yFound = true;
value = parseBackgroundPositionXY(xFound, yFound);
if (value)
valueList->next();
break;
}
case CSS_PROP__WEBKIT_TRANSFORM_ORIGIN_Y: {
bool xFound = true, yFound = false;
value = parseBackgroundPositionXY(xFound, yFound);
if (value)
valueList->next();
break;
}
case CSS_PROP__WEBKIT_TRANSFORM_ORIGIN_Z: {
if (validUnit(valueList->current(), FLength, strict))
value = new CSSPrimitiveValue(valueList->current()->fValue,
(CSSPrimitiveValue::UnitTypes)valueList->current()->unit);
if (value)
valueList->next();
break;
}
}
return (value != 0);
}
bool CSSParser::parsePerspectiveOrigin(int propId, int& propId1, int& propId2, RefPtr<CSSValue>& value, RefPtr<CSSValue>& value2)
{
propId1 = propId;
propId2 = propId;
if (propId == CSS_PROP__WEBKIT_PERSPECTIVE_ORIGIN) {
propId1 = CSS_PROP__WEBKIT_PERSPECTIVE_ORIGIN_X;
propId2 = CSS_PROP__WEBKIT_PERSPECTIVE_ORIGIN_Y;
}
switch (propId) {
case CSS_PROP__WEBKIT_PERSPECTIVE_ORIGIN:
parseBackgroundPosition(value, value2);
break;
case CSS_PROP__WEBKIT_PERSPECTIVE_ORIGIN_X: {
bool xFound = false, yFound = true;
value = parseBackgroundPositionXY(xFound, yFound);
if (value)
valueList->next();
break;
}
case CSS_PROP__WEBKIT_PERSPECTIVE_ORIGIN_Y: {
bool xFound = true, yFound = false;
value = parseBackgroundPositionXY(xFound, yFound);
if (value)
valueList->next();
break;
}
}
return (value != 0);
}
#ifdef CSS_DEBUG
static inline int yyerror(const char *str)
{
kdDebug(6080) << "CSS parse error " << str << endl;
return 1;
}
#else
static inline int yyerror(const char*) { return 1; }
#endif
#define END_TOKEN 0
#include "CSSGrammar.h"
static inline float convertASCIIToFloat(const UChar* characters, unsigned length)
{
Vector<char, 256> bytes(length + 1);
for (unsigned i = 0; i < length; ++i)
bytes[i] = characters[i];
bytes[length] = 0;
char* end;
return narrowPrecisionToFloat(kjs_strtod(bytes.data(), &end));
}
int CSSParser::lex(void* yylvalWithoutType)
{
YYSTYPE* yylval = static_cast<YYSTYPE*>(yylvalWithoutType);
int token = lex();
int length;
UChar* t = text(&length);
switch(token) {
case WHITESPACE:
case SGML_CD:
case INCLUDES:
case DASHMATCH:
break;
case URI:
case STRING:
case IDENT:
case NTH:
case HEX:
case IDSEL:
case DIMEN:
case UNICODERANGE:
case FUNCTION:
case NOTFUNCTION:
yylval->string.characters = t;
yylval->string.length = length;
break;
case IMPORT_SYM:
case PAGE_SYM:
case MEDIA_SYM:
case WEBKIT_KEYFRAMES_SYM:
case FONT_FACE_SYM:
case CHARSET_SYM:
case NAMESPACE_SYM:
case IMPORTANT_SYM:
break;
case QEMS:
length--;
case GRADS:
length--;
case DEGS:
case RADS:
case KHERZ:
length--;
case MSECS:
case HERZ:
case EMS:
case EXS:
case PXS:
case CMS:
case MMS:
case INS:
case PTS:
case PCS:
length--;
case SECS:
case PERCENTAGE:
length--;
case FLOATTOKEN:
case INTEGER:
yylval->val = convertASCIIToFloat(t, length);
break;
default:
break;
}
return token;
}
static inline int toHex(char c)
{
if ('0' <= c && c <= '9')
return c - '0';
if ('a' <= c && c <= 'f')
return c - 'a' + 10;
if ('A' <= c && c<= 'F')
return c - 'A' + 10;
return 0;
}
UChar* CSSParser::text(int *length)
{
UChar* start = yytext;
int l = yyleng;
switch(yyTok) {
case STRING:
l--;
case HEX:
case IDSEL:
start++;
l--;
break;
case URI:
start += 4;
l -= 5;
while (l &&
(*start == ' ' || *start == '\t' || *start == '\r' ||
*start == '\n' || *start == '\f')) {
start++; l--;
}
if (*start == '"' || *start == '\'') {
start++; l--;
}
while (l &&
(start[l-1] == ' ' || start[l-1] == '\t' || start[l-1] == '\r' ||
start[l-1] == '\n' || start[l-1] == '\f')) {
l--;
}
if (l && (start[l-1] == '\"' || start[l-1] == '\''))
l--;
default:
break;
}
UChar* out = start;
UChar* escape = 0;
for (int i = 0; i < l; i++) {
UChar* current = start + i;
if (escape == current - 1) {
if ((*current >= '0' && *current <= '9') ||
(*current >= 'a' && *current <= 'f') ||
(*current >= 'A' && *current <= 'F'))
continue;
if (yyTok == STRING &&
(*current == '\n' || *current == '\r' || *current == '\f')) {
if (*current != '\r')
escape = 0;
continue;
}
*out++ = *current;
escape = 0;
continue;
}
if (escape == current - 2 && yyTok == STRING &&
*(current-1) == '\r' && *current == '\n') {
escape = 0;
continue;
}
if (escape > current - 7 &&
((*current >= '0' && *current <= '9') ||
(*current >= 'a' && *current <= 'f') ||
(*current >= 'A' && *current <= 'F')))
continue;
if (escape) {
unsigned uc = 0;
escape++;
while (escape < current) {
uc *= 16;
uc += toHex(*escape);
escape++;
}
if (uc > 0xffff)
uc = 0xfffd;
*out++ = uc;
escape = 0;
if (*current == ' ' ||
*current == '\t' ||
*current == '\r' ||
*current == '\n' ||
*current == '\f')
continue;
}
if (!escape && *current == '\\') {
escape = current;
continue;
}
*out++ = *current;
}
if (escape) {
unsigned uc = 0;
escape++;
while (escape < start+l) {
uc *= 16;
uc += toHex(*escape);
escape++;
}
if (uc > 0xffff)
uc = 0xfffd;
*out++ = uc;
}
*length = out - start;
return start;
}
CSSSelector* CSSParser::createFloatingSelector()
{
CSSSelector* selector = new CSSSelector;
m_floatingSelectors.add(selector);
return selector;
}
CSSSelector* CSSParser::sinkFloatingSelector(CSSSelector* selector)
{
if (selector) {
ASSERT(m_floatingSelectors.contains(selector));
m_floatingSelectors.remove(selector);
}
return selector;
}
ValueList* CSSParser::createFloatingValueList()
{
ValueList* list = new ValueList;
m_floatingValueLists.add(list);
return list;
}
ValueList* CSSParser::sinkFloatingValueList(ValueList* list)
{
if (list) {
ASSERT(m_floatingValueLists.contains(list));
m_floatingValueLists.remove(list);
}
return list;
}
Function* CSSParser::createFloatingFunction()
{
Function* function = new Function;
m_floatingFunctions.add(function);
return function;
}
Function* CSSParser::sinkFloatingFunction(Function* function)
{
if (function) {
ASSERT(m_floatingFunctions.contains(function));
m_floatingFunctions.remove(function);
}
return function;
}
Value& CSSParser::sinkFloatingValue(Value& value)
{
if (value.unit == Value::Function) {
ASSERT(m_floatingFunctions.contains(value.function));
m_floatingFunctions.remove(value.function);
}
return value;
}
MediaQueryExp* CSSParser::createFloatingMediaQueryExp(const AtomicString& mediaFeature, ValueList* values)
{
delete m_floatingMediaQueryExp;
m_floatingMediaQueryExp = new MediaQueryExp(mediaFeature, values);
return m_floatingMediaQueryExp;
}
MediaQueryExp* CSSParser::sinkFloatingMediaQueryExp(MediaQueryExp* e)
{
ASSERT(e == m_floatingMediaQueryExp);
m_floatingMediaQueryExp = 0;
return e;
}
Vector<MediaQueryExp*>* CSSParser::createFloatingMediaQueryExpList()
{
if (m_floatingMediaQueryExpList) {
deleteAllValues(*m_floatingMediaQueryExpList);
delete m_floatingMediaQueryExpList;
}
m_floatingMediaQueryExpList = new Vector<MediaQueryExp*>;
return m_floatingMediaQueryExpList;
}
Vector<MediaQueryExp*>* CSSParser::sinkFloatingMediaQueryExpList(Vector<MediaQueryExp*>* l)
{
ASSERT(l == m_floatingMediaQueryExpList);
m_floatingMediaQueryExpList = 0;
return l;
}
MediaQuery* CSSParser::createFloatingMediaQuery(MediaQuery::Restrictor r, const String& mediaType, Vector<MediaQueryExp*>* exprs)
{
delete m_floatingMediaQuery;
m_floatingMediaQuery = new MediaQuery(r, mediaType, exprs);
return m_floatingMediaQuery;
}
MediaQuery* CSSParser::sinkFloatingMediaQuery(MediaQuery* mq)
{
ASSERT(mq == m_floatingMediaQuery);
m_floatingMediaQuery = 0;
return mq;
}
MediaList* CSSParser::createMediaList()
{
MediaList* list = new MediaList;
m_parsedStyleObjects.append(list);
return list;
}
CSSRule* CSSParser::createCharsetRule(const ParseString& charset)
{
if (!styleElement)
return 0;
if (!styleElement->isCSSStyleSheet())
return 0;
CSSCharsetRule* rule = new CSSCharsetRule(styleElement, domString(charset));
m_parsedStyleObjects.append(rule);
return rule;
}
CSSRule* CSSParser::createImportRule(const ParseString& url, MediaList* media)
{
if (!media)
return 0;
if (!styleElement)
return 0;
if (!styleElement->isCSSStyleSheet())
return 0;
CSSImportRule* rule = new CSSImportRule(styleElement, domString(url), media);
m_parsedStyleObjects.append(rule);
return rule;
}
CSSRule* CSSParser::createMediaRule(MediaList* media, CSSRuleList* rules)
{
if (!media)
return 0;
if (!rules)
return 0;
if (!styleElement)
return 0;
if (!styleElement->isCSSStyleSheet())
return 0;
CSSMediaRule* rule = new CSSMediaRule(styleElement, media, rules);
m_parsedStyleObjects.append(rule);
return rule;
}
CSSRuleList* CSSParser::createRuleList()
{
CSSRuleList* list = new CSSRuleList;
m_parsedRuleLists.append(list);
return list;
}
WebKitCSSKeyframesRule* CSSParser::createKeyframesRule()
{
WebKitCSSKeyframesRule* rule = new WebKitCSSKeyframesRule(styleElement);
m_parsedStyleObjects.append(rule);
return rule;
}
CSSRule* CSSParser::createStyleRule(CSSSelector* selector)
{
CSSStyleRule* rule = 0;
if (selector) {
rule = new CSSStyleRule(styleElement);
m_parsedStyleObjects.append(rule);
rule->setSelector(sinkFloatingSelector(selector));
rule->setDeclaration(new CSSMutableStyleDeclaration(rule, parsedProperties, numParsedProperties));
}
clearProperties();
return rule;
}
CSSRule* CSSParser::createFontFaceRule()
{
CSSFontFaceRule* rule = new CSSFontFaceRule(styleElement);
m_parsedStyleObjects.append(rule);
rule->setDeclaration(new CSSMutableStyleDeclaration(rule, parsedProperties, numParsedProperties));
clearProperties();
return rule;
}
WebKitCSSKeyframeRule* CSSParser::createKeyframeRule(float key)
{
WebKitCSSKeyframeRule* keyframe = new WebKitCSSKeyframeRule(styleElement);
m_parsedStyleObjects.append(keyframe);
keyframe->setKey(key);
keyframe->setDeclaration(new CSSMutableStyleDeclaration(0, parsedProperties, numParsedProperties));
clearProperties();
return keyframe;
}
DeprecatedString deprecatedString(const ParseString& ps)
{
return DeprecatedString(reinterpret_cast<const DeprecatedChar*>(ps.characters), ps.length);
}
#define YY_DECL int CSSParser::lex()
#define yyconst const
typedef int yy_state_type;
typedef unsigned YY_CHAR;
#define YY_SC_TO_UI(c) (c > 0xff ? 0xff : c)
#define YY_DO_BEFORE_ACTION \
yytext = yy_bp; \
yyleng = (int) (yy_cp - yy_bp); \
yy_hold_char = *yy_cp; \
*yy_cp = 0; \
yy_c_buf_p = yy_cp;
#define YY_BREAK break;
#define ECHO
#define YY_RULE_SETUP
#define INITIAL 0
#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
#define yyterminate() yyTok = END_TOKEN; return yyTok
#define YY_FATAL_ERROR(a)
#define BEGIN yy_start = 1 + 2 *
#include "tokenizer.cpp"
}