summaryrefslogtreecommitdiffstats
path: root/WebCore/css/CSSParser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/css/CSSParser.cpp')
-rw-r--r--WebCore/css/CSSParser.cpp135
1 files changed, 80 insertions, 55 deletions
diff --git a/WebCore/css/CSSParser.cpp b/WebCore/css/CSSParser.cpp
index 0347d69..f098a9f 100644
--- a/WebCore/css/CSSParser.cpp
+++ b/WebCore/css/CSSParser.cpp
@@ -25,16 +25,14 @@
#include "config.h"
#include "CSSParser.h"
-#include "CSSTimingFunctionValue.h"
#include "CSSBorderImageValue.h"
#include "CSSCanvasValue.h"
#include "CSSCharsetRule.h"
#include "CSSCursorImageValue.h"
-#include "CSSHelper.h"
-#include "CSSImageValue.h"
#include "CSSFontFaceRule.h"
#include "CSSFontFaceSrcValue.h"
#include "CSSGradientValue.h"
+#include "CSSImageValue.h"
#include "CSSImportRule.h"
#include "CSSInheritedValue.h"
#include "CSSInitialValue.h"
@@ -51,6 +49,7 @@
#include "CSSSelector.h"
#include "CSSStyleRule.h"
#include "CSSStyleSheet.h"
+#include "CSSTimingFunctionValue.h"
#include "CSSUnicodeRangeValue.h"
#include "CSSValueKeywords.h"
#include "CSSValueList.h"
@@ -62,6 +61,7 @@
#include "FloatConversion.h"
#include "FontFamilyValue.h"
#include "FontValue.h"
+#include "HTMLParserIdioms.h"
#include "HashTools.h"
#include "MediaList.h"
#include "MediaQueryExp.h"
@@ -148,12 +148,11 @@ CSSParser::CSSParser(bool strictParsing)
, m_hasFontFaceOnlyValues(false)
, m_hadSyntacticallyValidCSSRule(false)
, m_defaultNamespace(starAtom)
- , m_ruleBodyStartOffset(0)
- , m_ruleBodyEndOffset(0)
- , m_propertyStartOffset(UINT_MAX)
- , m_propertyEndOffset(UINT_MAX)
+ , m_selectorListRange(0, 0)
+ , m_ruleBodyRange(0, 0)
+ , m_propertyRange(UINT_MAX, UINT_MAX)
, m_ruleRangeMap(0)
- , m_currentStyleData(0)
+ , m_currentRuleData(0)
, m_data(0)
, yy_start(1)
, m_lineNumber(0)
@@ -236,14 +235,16 @@ void CSSParser::parseSheet(CSSStyleSheet* sheet, const String& string, int start
m_styleSheet = sheet;
m_defaultNamespace = starAtom; // Reset the default namespace.
m_ruleRangeMap = ruleRangeMap;
- if (ruleRangeMap)
- m_currentStyleData = CSSStyleSourceData::create();
+ if (ruleRangeMap) {
+ m_currentRuleData = CSSRuleSourceData::create();
+ m_currentRuleData->styleSourceData = CSSStyleSourceData::create();
+ }
m_lineNumber = startLineNumber;
setupParser("", string, "");
cssyyparse(this);
m_ruleRangeMap = 0;
- m_currentStyleData = 0;
+ m_currentRuleData = 0;
m_rule = 0;
#ifdef ANDROID_INSTRUMENT
android::TimeCounter::record(android::TimeCounter::CSSParseTimeCounter, __FUNCTION__);
@@ -373,7 +374,7 @@ void CSSParser::parseSelector(const String& string, Document* doc, CSSSelectorLi
#endif
}
-bool CSSParser::parseDeclaration(CSSMutableStyleDeclaration* declaration, const String& string, CSSStyleSourceData* styleSourceData)
+bool CSSParser::parseDeclaration(CSSMutableStyleDeclaration* declaration, const String& string, RefPtr<CSSStyleSourceData>* styleSourceData)
{
#ifdef ANDROID_INSTRUMENT
android::TimeCounter::start(android::TimeCounter::CSSParseTimeCounter);
@@ -384,7 +385,10 @@ bool CSSParser::parseDeclaration(CSSMutableStyleDeclaration* declaration, const
ASSERT(!declaration->stylesheet() || declaration->stylesheet()->isCSSStyleSheet());
m_styleSheet = static_cast<CSSStyleSheet*>(declaration->stylesheet());
- m_currentStyleData = styleSourceData;
+ if (styleSourceData) {
+ m_currentRuleData = CSSRuleSourceData::create();
+ m_currentRuleData->styleSourceData = CSSStyleSourceData::create();
+ }
setupParser("@-webkit-decls{", string, "} ");
cssyyparse(this);
@@ -399,15 +403,16 @@ bool CSSParser::parseDeclaration(CSSMutableStyleDeclaration* declaration, const
clearProperties();
}
- if (m_currentStyleData) {
- m_currentStyleData->styleBodyRange.start = 0;
- m_currentStyleData->styleBodyRange.end = string.length();
- for (Vector<CSSPropertySourceData>::iterator it = m_currentStyleData->propertyData.begin(); it != m_currentStyleData->propertyData.end(); ++it) {
+ if (m_currentRuleData) {
+ m_currentRuleData->styleSourceData->styleBodyRange.start = 0;
+ m_currentRuleData->styleSourceData->styleBodyRange.end = string.length();
+ for (Vector<CSSPropertySourceData>::iterator it = m_currentRuleData->styleSourceData->propertyData.begin(), endIt = m_currentRuleData->styleSourceData->propertyData.end(); it != endIt; ++it) {
(*it).range.start -= prefixLength;
(*it).range.end -= prefixLength;
}
}
+<<<<<<< HEAD
if (!m_ruleRangeMap)
m_currentStyleData = 0;
@@ -415,6 +420,12 @@ bool CSSParser::parseDeclaration(CSSMutableStyleDeclaration* declaration, const
android::TimeCounter::record(android::TimeCounter::CSSParseTimeCounter, __FUNCTION__);
#endif
+=======
+ if (styleSourceData) {
+ *styleSourceData = m_currentRuleData->styleSourceData.release();
+ m_currentRuleData = 0;
+ }
+>>>>>>> webkit.org at r70209
return ok;
}
@@ -1056,7 +1067,12 @@ bool CSSParser::parseValue(int propId, bool important)
if (id == CSSValueNormal || id == CSSValueBreakWord)
validPrimitive = true;
break;
-
+ case CSSPropertySpeak: // none | normal | spell-out | digits | literal-punctuation | no-punctuation | inherit
+ if (id == CSSValueNone || id == CSSValueNormal || id == CSSValueSpellOut || id == CSSValueDigits
+ || id == CSSValueLiteralPunctuation || id == CSSValueNoPunctuation)
+ validPrimitive = true;
+ break;
+
case CSSPropertyTextIndent: // <length> | <percentage> | inherit
validPrimitive = (!id && validUnit(value, FLength | FPercent, m_strict));
break;
@@ -1826,15 +1842,8 @@ bool CSSParser::parseValue(int propId, bool important)
#endif
// CSS Text Layout Module Level 3: Vertical writing support
- case CSSPropertyWebkitBlockFlow:
- // [ "tb" | "rl" | "lr" | "bt" ]
- if (id == CSSValueTb || id == CSSValueRl || id == CSSValueLr || id == CSSValueBt)
- validPrimitive = true;
- break;
-
case CSSPropertyWebkitWritingMode:
- // [ "lr-tb" | "rl-tb" | "tb-rl" | "bt-rl" | "tb-lr" | "bt-lr" ]
- if (id == CSSValueLrTb || id == CSSValueRlTb || id == CSSValueTbRl || id == CSSValueBtRl || id == CSSValueTbLr || id == CSSValueBtLr)
+ if (id >= CSSValueHorizontalTb && id <= CSSValueHorizontalBt)
validPrimitive = true;
break;
@@ -3849,17 +3858,12 @@ bool CSSParser::parseFontFaceUnicodeRange()
return true;
}
-static inline bool isCSSWhitespace(UChar c)
-{
- return c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\f';
-}
-
static inline bool parseColorInt(const UChar*& string, const UChar* end, UChar terminator, int& value)
{
const UChar* current = string;
int localValue = 0;
bool negative = false;
- while (current != end && isCSSWhitespace(*current))
+ while (current != end && isHTMLSpace(*current))
current++;
if (current != end && *current == '-') {
negative = true;
@@ -3878,7 +3882,7 @@ static inline bool parseColorInt(const UChar*& string, const UChar* end, UChar t
}
localValue = newValue;
}
- while (current != end && isCSSWhitespace(*current))
+ while (current != end && isHTMLSpace(*current))
current++;
if (current == end || *current++ != terminator)
return false;
@@ -3903,7 +3907,7 @@ static inline bool isTenthAlpha(const UChar* string, const int length)
static inline bool parseAlphaValue(const UChar*& string, const UChar* end, UChar terminator, int& value)
{
- while (string != end && isCSSWhitespace(*string))
+ while (string != end && isHTMLSpace(*string))
string++;
value = 0;
@@ -5287,11 +5291,11 @@ UChar* CSSParser::text(int *length)
start += 4;
l -= 5;
// strip {w}
- while (l && isCSSWhitespace(*start)) {
+ while (l && isHTMLSpace(*start)) {
++start;
--l;
}
- while (l && isCSSWhitespace(start[l - 1]))
+ while (l && isHTMLSpace(start[l - 1]))
--l;
if (l && (*start == '"' || *start == '\'')) {
ASSERT(l >= 2 && start[l - 1] == *start);
@@ -5305,11 +5309,11 @@ UChar* CSSParser::text(int *length)
start += 12;
l -= 13;
// strip {w}
- while (l && isCSSWhitespace(*start)) {
+ while (l && isHTMLSpace(*start)) {
++start;
--l;
}
- while (l && isCSSWhitespace(start[l - 1]))
+ while (l && isHTMLSpace(start[l - 1]))
--l;
break;
default:
@@ -5361,7 +5365,7 @@ UChar* CSSParser::text(int *length)
uc = 0xfffd;
*out++ = uc;
escape = 0;
- if (isCSSWhitespace(*current))
+ if (isHTMLSpace(*current))
continue;
}
if (!escape && *current == '\\') {
@@ -5573,12 +5577,15 @@ CSSRule* CSSParser::createStyleRule(Vector<CSSSelector*>* selectors)
result = rule.get();
m_parsedStyleObjects.append(rule.release());
if (m_ruleRangeMap) {
- ASSERT(m_currentStyleData);
- m_currentStyleData->styleBodyRange = SourceRange(m_ruleBodyStartOffset, m_ruleBodyEndOffset);
- m_ruleRangeMap->set(result, m_currentStyleData.release());
- m_currentStyleData = CSSStyleSourceData::create();
+ ASSERT(m_currentRuleData);
+ m_currentRuleData->styleSourceData->styleBodyRange = m_ruleBodyRange;
+ m_currentRuleData->selectorListRange = m_selectorListRange;
+ m_ruleRangeMap->set(result, m_currentRuleData.release());
+ m_currentRuleData = CSSRuleSourceData::create();
+ m_currentRuleData->styleSourceData = CSSStyleSourceData::create();
}
}
+ resetSelectorListMarks();
resetRuleBodyMarks();
clearProperties();
return result;
@@ -5833,26 +5840,44 @@ void CSSParser::updateLastSelectorLineAndPosition()
markRuleBodyStart();
}
+void CSSParser::markSelectorListStart()
+{
+ m_selectorListRange.start = yytext - m_data;
+}
+
+void CSSParser::markSelectorListEnd()
+{
+ if (!m_currentRuleData)
+ return;
+ UChar* listEnd = yytext;
+ while (listEnd > m_data + 1) {
+ if (isHTMLSpace(*(listEnd - 1)))
+ --listEnd;
+ else
+ break;
+ }
+ m_selectorListRange.end = listEnd - m_data;
+}
+
void CSSParser::markRuleBodyStart()
{
unsigned offset = yytext - m_data;
if (*yytext == '{')
++offset; // Skip the rule body opening brace.
- if (offset > m_ruleBodyStartOffset)
- m_ruleBodyStartOffset = offset;
+ if (offset > m_ruleBodyRange.start)
+ m_ruleBodyRange.start = offset;
}
void CSSParser::markRuleBodyEnd()
{
unsigned offset = yytext - m_data;
- if (offset > m_ruleBodyEndOffset)
- m_ruleBodyEndOffset = offset;
+ if (offset > m_ruleBodyRange.end)
+ m_ruleBodyRange.end = offset;
}
void CSSParser::markPropertyStart()
{
- unsigned offset = yytext - m_data;
- m_propertyStartOffset = offset;
+ m_propertyRange.start = yytext - m_data;
}
void CSSParser::markPropertyEnd(bool isImportantFound, bool isPropertyParsed)
@@ -5860,11 +5885,11 @@ void CSSParser::markPropertyEnd(bool isImportantFound, bool isPropertyParsed)
unsigned offset = yytext - m_data;
if (*yytext == ';') // Include semicolon into the property text.
++offset;
- m_propertyEndOffset = offset;
- if (m_propertyStartOffset != UINT_MAX && m_currentStyleData) {
+ m_propertyRange.end = offset;
+ if (m_propertyRange.start != UINT_MAX && m_currentRuleData) {
// This stuff is only executed when the style data retrieval is requested by client.
- const unsigned start = m_propertyStartOffset;
- const unsigned end = m_propertyEndOffset;
+ const unsigned start = m_propertyRange.start;
+ const unsigned end = m_propertyRange.end;
ASSERT(start < end);
String propertyString = String(m_data + start, end - start).stripWhiteSpace();
if (propertyString.endsWith(";", true))
@@ -5876,8 +5901,8 @@ void CSSParser::markPropertyEnd(bool isImportantFound, bool isPropertyParsed)
String name = propertyString.left(colonIndex).stripWhiteSpace();
String value = propertyString.substring(colonIndex + 1, propertyString.length()).stripWhiteSpace();
// The property range is relative to the declaration start offset.
- m_currentStyleData->propertyData.append(
- CSSPropertySourceData(name, value, isImportantFound, isPropertyParsed, SourceRange(m_propertyStartOffset - m_ruleBodyStartOffset, m_propertyEndOffset - m_ruleBodyStartOffset)));
+ m_currentRuleData->styleSourceData->propertyData.append(
+ CSSPropertySourceData(name, value, isImportantFound, isPropertyParsed, SourceRange(start - m_ruleBodyRange.start, end - m_ruleBodyRange.start)));
}
resetPropertyMarks();
}