| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) |
| 3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) |
| 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc.
All rights reserved. | 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc.
All rights reserved. |
| 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> | 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> |
| 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> | 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> |
| 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) | 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) |
| 8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. | 8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. |
| 9 * Copyright (C) 2012 Intel Corporation. All rights reserved. | 9 * Copyright (C) 2012 Intel Corporation. All rights reserved. |
| 10 * | 10 * |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 , m_styleSheet(0) | 246 , m_styleSheet(0) |
| 247 , m_supportsCondition(false) | 247 , m_supportsCondition(false) |
| 248 , m_selectorListForParseSelector(0) | 248 , m_selectorListForParseSelector(0) |
| 249 , m_numParsedPropertiesBeforeMarginBox(INVALID_NUM_PARSED_PROPERTIES) | 249 , m_numParsedPropertiesBeforeMarginBox(INVALID_NUM_PARSED_PROPERTIES) |
| 250 , m_inParseShorthand(0) | 250 , m_inParseShorthand(0) |
| 251 , m_currentShorthand(CSSPropertyInvalid) | 251 , m_currentShorthand(CSSPropertyInvalid) |
| 252 , m_implicitShorthand(false) | 252 , m_implicitShorthand(false) |
| 253 , m_hasFontFaceOnlyValues(false) | 253 , m_hasFontFaceOnlyValues(false) |
| 254 , m_hadSyntacticallyValidCSSRule(false) | 254 , m_hadSyntacticallyValidCSSRule(false) |
| 255 , m_logErrors(false) | 255 , m_logErrors(false) |
| 256 , m_ignoreErrorsInDeclaration(false) | 256 , m_ignoreErrors(false) |
| 257 , m_inFilterRule(false) | 257 , m_inFilterRule(false) |
| 258 , m_defaultNamespace(starAtom) | 258 , m_defaultNamespace(starAtom) |
| 259 , m_parsedTextPrefixLength(0) | 259 , m_parsedTextPrefixLength(0) |
| 260 , m_parsedTextSuffixLength(0) | 260 , m_parsedTextSuffixLength(0) |
| 261 , m_sourceDataHandler(0) | 261 , m_sourceDataHandler(0) |
| 262 , m_parsingMode(NormalMode) | 262 , m_parsingMode(NormalMode) |
| 263 , m_is8BitSource(false) | 263 , m_is8BitSource(false) |
| 264 , m_currentCharacter8(0) | 264 , m_currentCharacter8(0) |
| 265 , m_currentCharacter16(0) | 265 , m_currentCharacter16(0) |
| 266 , m_source(0) | 266 , m_source(0) |
| 267 , m_length(0) | 267 , m_length(0) |
| 268 , m_token(0) | 268 , m_token(0) |
| 269 , m_lineNumber(0) | 269 , m_lineNumber(0) |
| 270 , m_tokenStartLineNumber(0) | 270 , m_tokenStartLineNumber(0) |
| 271 , m_lastSelectorLineNumber(0) | 271 , m_lastSelectorLineNumber(0) |
| 272 , m_ruleHeaderType(CSSRuleSourceData::UNKNOWN_RULE) |
| 272 , m_allowImportRules(true) | 273 , m_allowImportRules(true) |
| 273 , m_allowNamespaceDeclarations(true) | 274 , m_allowNamespaceDeclarations(true) |
| 274 #if ENABLE(CSS_DEVICE_ADAPTATION) | 275 #if ENABLE(CSS_DEVICE_ADAPTATION) |
| 275 , m_inViewport(false) | 276 , m_inViewport(false) |
| 276 #endif | 277 #endif |
| 277 , m_useCounter(counter) | 278 , m_useCounter(counter) |
| 278 { | 279 { |
| 279 #if YYDEBUG > 0 | 280 #if YYDEBUG > 0 |
| 280 cssyydebug = 1; | 281 cssyydebug = 1; |
| 281 #endif | 282 #endif |
| (...skipping 13 matching lines...) Expand all Loading... |
| 295 | 296 |
| 296 AtomicString CSSParserString::atomicSubstring(unsigned position, unsigned length
) const | 297 AtomicString CSSParserString::atomicSubstring(unsigned position, unsigned length
) const |
| 297 { | 298 { |
| 298 ASSERT(m_length >= position + length); | 299 ASSERT(m_length >= position + length); |
| 299 | 300 |
| 300 if (is8Bit()) | 301 if (is8Bit()) |
| 301 return AtomicString(characters8() + position, length); | 302 return AtomicString(characters8() + position, length); |
| 302 return AtomicString(characters16() + position, length); | 303 return AtomicString(characters16() + position, length); |
| 303 } | 304 } |
| 304 | 305 |
| 306 void CSSParserString::trimTrailingWhitespace() |
| 307 { |
| 308 if (is8Bit()) { |
| 309 while (m_length > 0 && isHTMLSpace(m_data.characters8[m_length - 1])) |
| 310 --m_length; |
| 311 } else { |
| 312 while (m_length > 0 && isHTMLSpace(m_data.characters16[m_length - 1])) |
| 313 --m_length; |
| 314 } |
| 315 } |
| 316 |
| 305 void CSSParser::setupParser(const char* prefix, unsigned prefixLength, const Str
ing& string, const char* suffix, unsigned suffixLength) | 317 void CSSParser::setupParser(const char* prefix, unsigned prefixLength, const Str
ing& string, const char* suffix, unsigned suffixLength) |
| 306 { | 318 { |
| 307 m_parsedTextPrefixLength = prefixLength; | 319 m_parsedTextPrefixLength = prefixLength; |
| 308 m_parsedTextSuffixLength = suffixLength; | 320 m_parsedTextSuffixLength = suffixLength; |
| 309 unsigned stringLength = string.length(); | 321 unsigned stringLength = string.length(); |
| 310 unsigned length = stringLength + m_parsedTextPrefixLength + m_parsedTextSuff
ixLength + 1; | 322 unsigned length = stringLength + m_parsedTextPrefixLength + m_parsedTextSuff
ixLength + 1; |
| 311 m_length = length; | 323 m_length = length; |
| 312 | 324 |
| 313 if (!stringLength || string.is8Bit()) { | 325 if (!stringLength || string.is8Bit()) { |
| 314 m_dataStart8 = adoptArrayPtr(new LChar[length]); | 326 m_dataStart8 = adoptArrayPtr(new LChar[length]); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 setTokenStart<UChar>(m_currentCharacter16); | 364 setTokenStart<UChar>(m_currentCharacter16); |
| 353 m_lexFunc = &CSSParser::realLex<UChar>; | 365 m_lexFunc = &CSSParser::realLex<UChar>; |
| 354 } | 366 } |
| 355 | 367 |
| 356 void CSSParser::parseSheet(StyleSheetContents* sheet, const String& string, int
startLineNumber, SourceDataHandler* sourceDataHandler, bool logErrors) | 368 void CSSParser::parseSheet(StyleSheetContents* sheet, const String& string, int
startLineNumber, SourceDataHandler* sourceDataHandler, bool logErrors) |
| 357 { | 369 { |
| 358 setStyleSheet(sheet); | 370 setStyleSheet(sheet); |
| 359 m_defaultNamespace = starAtom; // Reset the default namespace. | 371 m_defaultNamespace = starAtom; // Reset the default namespace. |
| 360 m_sourceDataHandler = sourceDataHandler; | 372 m_sourceDataHandler = sourceDataHandler; |
| 361 m_logErrors = logErrors && sheet->singleOwnerDocument() && !sheet->baseURL()
.isEmpty() && sheet->singleOwnerDocument()->page(); | 373 m_logErrors = logErrors && sheet->singleOwnerDocument() && !sheet->baseURL()
.isEmpty() && sheet->singleOwnerDocument()->page(); |
| 362 m_ignoreErrorsInDeclaration = false; | 374 m_ignoreErrors = false; |
| 363 m_lineNumber = startLineNumber; | 375 m_lineNumber = startLineNumber; |
| 364 m_source = &string; | 376 m_source = &string; |
| 365 setupParser("", string, ""); | 377 setupParser("", string, ""); |
| 366 cssyyparse(this); | 378 cssyyparse(this); |
| 367 sheet->shrinkToFit(); | 379 sheet->shrinkToFit(); |
| 368 m_source = 0; | 380 m_source = 0; |
| 369 m_sourceDataHandler = 0; | 381 m_sourceDataHandler = 0; |
| 370 m_rule = 0; | 382 m_rule = 0; |
| 371 m_ignoreErrorsInDeclaration = false; | 383 m_ignoreErrors = false; |
| 372 m_logErrors = false; | 384 m_logErrors = false; |
| 373 } | 385 } |
| 374 | 386 |
| 375 PassRefPtr<StyleRuleBase> CSSParser::parseRule(StyleSheetContents* sheet, const
String& string) | 387 PassRefPtr<StyleRuleBase> CSSParser::parseRule(StyleSheetContents* sheet, const
String& string) |
| 376 { | 388 { |
| 377 setStyleSheet(sheet); | 389 setStyleSheet(sheet); |
| 378 m_allowNamespaceDeclarations = false; | 390 m_allowNamespaceDeclarations = false; |
| 379 setupParser("@-internal-rule{", string, "} "); | 391 setupParser("@-internal-rule{", string, "} "); |
| 380 cssyyparse(this); | 392 cssyyparse(this); |
| 381 return m_rule.release(); | 393 return m_rule.release(); |
| (...skipping 10546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10928 size_t length = token.length(); | 10940 size_t length = token.length(); |
| 10929 if (is8BitSource()) { | 10941 if (is8BitSource()) { |
| 10930 size_t offset = token.characters8() - m_dataStart8.get(); | 10942 size_t offset = token.characters8() - m_dataStart8.get(); |
| 10931 makeLower(token.characters8(), m_dataStart8.get() + offset, length); | 10943 makeLower(token.characters8(), m_dataStart8.get() + offset, length); |
| 10932 } else { | 10944 } else { |
| 10933 size_t offset = token.characters16() - m_dataStart16.get(); | 10945 size_t offset = token.characters16() - m_dataStart16.get(); |
| 10934 makeLower(token.characters16(), m_dataStart16.get() + offset, length); | 10946 makeLower(token.characters16(), m_dataStart16.get() + offset, length); |
| 10935 } | 10947 } |
| 10936 } | 10948 } |
| 10937 | 10949 |
| 10950 void CSSParser::endInvalidRuleHeader() |
| 10951 { |
| 10952 if (m_ruleHeaderType == CSSRuleSourceData::UNKNOWN_RULE) |
| 10953 return; |
| 10954 |
| 10955 if (m_source) { |
| 10956 size_t length = safeUserStringTokenOffset() - m_ruleHeaderStartOffset; |
| 10957 CSSParserLocation location; |
| 10958 location.lineNumber = m_ruleHeaderStartLineNumber; |
| 10959 location.content.init(*m_source, m_ruleHeaderStartOffset, length); |
| 10960 location.content.trimTrailingWhitespace(); |
| 10961 |
| 10962 reportError(location, m_ruleHeaderType == CSSRuleSourceData::STYLE_RULE
? InvalidSelectorError : InvalidRuleError); |
| 10963 } |
| 10964 |
| 10965 endRuleHeader(); |
| 10966 } |
| 10967 |
| 10938 void CSSParser::reportError(const CSSParserLocation& location, ErrorType error) | 10968 void CSSParser::reportError(const CSSParserLocation& location, ErrorType error) |
| 10939 { | 10969 { |
| 10940 if (!isLoggingErrors()) | 10970 if (!isLoggingErrors()) |
| 10941 return; | 10971 return; |
| 10942 | 10972 |
| 10943 m_ignoreErrorsInDeclaration = true; | 10973 m_ignoreErrors = true; |
| 10944 if (!InspectorInstrumentation::cssErrorFilter(location, m_id, error)) | 10974 if (!InspectorInstrumentation::cssErrorFilter(location, m_id, error)) |
| 10945 return; | 10975 return; |
| 10946 | 10976 |
| 10947 StringBuilder builder; | 10977 StringBuilder builder; |
| 10948 switch (error) { | 10978 switch (error) { |
| 10949 case PropertyDeclarationError: | 10979 case PropertyDeclarationError: |
| 10950 builder.appendLiteral("Invalid CSS property declaration at: "); | 10980 builder.appendLiteral("Invalid CSS property declaration at: "); |
| 10951 break; | 10981 break; |
| 10952 | 10982 |
| 10953 case InvalidPropertyValueError: | 10983 case InvalidPropertyValueError: |
| 10954 builder.appendLiteral("Invalid CSS property value: "); | 10984 builder.appendLiteral("Invalid CSS property value: "); |
| 10955 break; | 10985 break; |
| 10956 | 10986 |
| 10957 case InvalidPropertyError: | 10987 case InvalidPropertyError: |
| 10958 builder.appendLiteral("Invalid CSS property name: "); | 10988 builder.appendLiteral("Invalid CSS property name: "); |
| 10959 break; | 10989 break; |
| 10960 | 10990 |
| 10991 case InvalidSelectorError: |
| 10992 builder.appendLiteral("Invalid CSS selector: "); |
| 10993 break; |
| 10994 |
| 10995 case InvalidRuleError: |
| 10996 builder.appendLiteral("Invalid CSS rule: "); |
| 10997 break; |
| 10998 |
| 10961 default: | 10999 default: |
| 10962 builder.appendLiteral("Unexpected CSS token: "); | 11000 builder.appendLiteral("Unexpected CSS token: "); |
| 10963 } | 11001 } |
| 10964 | 11002 |
| 10965 if (location.content.is8Bit()) | 11003 if (location.content.is8Bit()) |
| 10966 builder.append(location.content.characters8(), location.content.length()
); | 11004 builder.append(location.content.characters8(), location.content.length()
); |
| 10967 else | 11005 else |
| 10968 builder.append(location.content.characters16(), location.content.length(
)); | 11006 builder.append(location.content.characters16(), location.content.length(
)); |
| 10969 | 11007 |
| 10970 logError(builder.toString(), location.lineNumber); | 11008 logError(builder.toString(), location.lineNumber); |
| 10971 } | 11009 } |
| 10972 | 11010 |
| 10973 bool CSSParser::isLoggingErrors() | 11011 bool CSSParser::isLoggingErrors() |
| 10974 { | 11012 { |
| 10975 return m_logErrors && !m_ignoreErrorsInDeclaration; | 11013 return m_logErrors && !m_ignoreErrors; |
| 10976 } | 11014 } |
| 10977 | 11015 |
| 10978 void CSSParser::logError(const String& message, int lineNumber) | 11016 void CSSParser::logError(const String& message, int lineNumber) |
| 10979 { | 11017 { |
| 10980 PageConsole* console = m_styleSheet->singleOwnerDocument()->page()->console(
); | 11018 PageConsole* console = m_styleSheet->singleOwnerDocument()->page()->console(
); |
| 10981 console->addMessage(CSSMessageSource, WarningMessageLevel, message, m_styleS
heet->baseURL().string(), lineNumber + 1); | 11019 console->addMessage(CSSMessageSource, WarningMessageLevel, message, m_styleS
heet->baseURL().string(), lineNumber + 1); |
| 10982 } | 11020 } |
| 10983 | 11021 |
| 10984 StyleRuleKeyframes* CSSParser::createKeyframesRule(const String& name, PassOwnPt
r<Vector<RefPtr<StyleKeyframe> > > popKeyframes) | 11022 StyleRuleKeyframes* CSSParser::createKeyframesRule(const String& name, PassOwnPt
r<Vector<RefPtr<StyleKeyframe> > > popKeyframes) |
| 10985 { | 11023 { |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11289 m_lastSelectorLineNumber = m_lineNumber; | 11327 m_lastSelectorLineNumber = m_lineNumber; |
| 11290 } | 11328 } |
| 11291 | 11329 |
| 11292 void CSSParser::updateLastMediaLine(MediaQuerySet* media) | 11330 void CSSParser::updateLastMediaLine(MediaQuerySet* media) |
| 11293 { | 11331 { |
| 11294 media->setLastLine(m_lineNumber); | 11332 media->setLastLine(m_lineNumber); |
| 11295 } | 11333 } |
| 11296 | 11334 |
| 11297 void CSSParser::startRuleHeader(CSSRuleSourceData::Type ruleType) | 11335 void CSSParser::startRuleHeader(CSSRuleSourceData::Type ruleType) |
| 11298 { | 11336 { |
| 11337 m_ruleHeaderType = ruleType; |
| 11338 m_ruleHeaderStartOffset = safeUserStringTokenOffset(); |
| 11339 m_ruleHeaderStartLineNumber = m_tokenStartLineNumber; |
| 11299 if (m_sourceDataHandler) | 11340 if (m_sourceDataHandler) |
| 11300 m_sourceDataHandler->startRuleHeader(ruleType, safeUserStringTokenOffset
()); | 11341 m_sourceDataHandler->startRuleHeader(ruleType, m_ruleHeaderStartOffset); |
| 11301 } | 11342 } |
| 11302 | 11343 |
| 11303 void CSSParser::endRuleHeader() | 11344 void CSSParser::endRuleHeader() |
| 11304 { | 11345 { |
| 11346 m_ruleHeaderType = CSSRuleSourceData::UNKNOWN_RULE; |
| 11305 if (m_sourceDataHandler) | 11347 if (m_sourceDataHandler) |
| 11306 m_sourceDataHandler->endRuleHeader(safeUserStringTokenOffset()); | 11348 m_sourceDataHandler->endRuleHeader(safeUserStringTokenOffset()); |
| 11307 } | 11349 } |
| 11308 | 11350 |
| 11309 void CSSParser::startSelector() | 11351 void CSSParser::startSelector() |
| 11310 { | 11352 { |
| 11311 if (m_sourceDataHandler) | 11353 if (m_sourceDataHandler) |
| 11312 m_sourceDataHandler->startSelector(safeUserStringTokenOffset()); | 11354 m_sourceDataHandler->startSelector(safeUserStringTokenOffset()); |
| 11313 } | 11355 } |
| 11314 | 11356 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 11325 } | 11367 } |
| 11326 | 11368 |
| 11327 void CSSParser::endRuleBody(bool discard) | 11369 void CSSParser::endRuleBody(bool discard) |
| 11328 { | 11370 { |
| 11329 if (m_sourceDataHandler) | 11371 if (m_sourceDataHandler) |
| 11330 m_sourceDataHandler->endRuleBody(safeUserStringTokenOffset(), discard); | 11372 m_sourceDataHandler->endRuleBody(safeUserStringTokenOffset(), discard); |
| 11331 } | 11373 } |
| 11332 | 11374 |
| 11333 void CSSParser::startProperty() | 11375 void CSSParser::startProperty() |
| 11334 { | 11376 { |
| 11335 m_ignoreErrorsInDeclaration = false; | 11377 resumeErrorLogging(); |
| 11336 if (m_sourceDataHandler) | 11378 if (m_sourceDataHandler) |
| 11337 m_sourceDataHandler->startProperty(safeUserStringTokenOffset()); | 11379 m_sourceDataHandler->startProperty(safeUserStringTokenOffset()); |
| 11338 } | 11380 } |
| 11339 | 11381 |
| 11340 void CSSParser::endProperty(bool isImportantFound, bool isPropertyParsed, ErrorT
ype errorType) | 11382 void CSSParser::endProperty(bool isImportantFound, bool isPropertyParsed, ErrorT
ype errorType) |
| 11341 { | 11383 { |
| 11342 m_id = CSSPropertyInvalid; | 11384 m_id = CSSPropertyInvalid; |
| 11343 if (m_sourceDataHandler) | 11385 if (m_sourceDataHandler) |
| 11344 m_sourceDataHandler->endProperty(isImportantFound, isPropertyParsed, saf
eUserStringTokenOffset(), errorType); | 11386 m_sourceDataHandler->endProperty(isImportantFound, isPropertyParsed, saf
eUserStringTokenOffset(), errorType); |
| 11345 } | 11387 } |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11698 bool isValidNthToken(const CSSParserString& token) | 11740 bool isValidNthToken(const CSSParserString& token) |
| 11699 { | 11741 { |
| 11700 // The tokenizer checks for the construct of an+b. | 11742 // The tokenizer checks for the construct of an+b. |
| 11701 // However, since the {ident} rule precedes the {nth} rule, some of those | 11743 // However, since the {ident} rule precedes the {nth} rule, some of those |
| 11702 // tokens are identified as string literal. Furthermore we need to accept | 11744 // tokens are identified as string literal. Furthermore we need to accept |
| 11703 // "odd" and "even" which does not match to an+b. | 11745 // "odd" and "even" which does not match to an+b. |
| 11704 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even") | 11746 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even") |
| 11705 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n"); | 11747 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n"); |
| 11706 } | 11748 } |
| 11707 | 11749 |
| 11708 CSSParserLocation CSSParserLocation::trimTrailingWhitespace() const | |
| 11709 { | |
| 11710 CSSParserLocation result; | |
| 11711 result.lineNumber = lineNumber; | |
| 11712 result.content = content; | |
| 11713 size_t newLength = content.length(); | |
| 11714 while (newLength > 0 && isHTMLSpace(result.content[newLength - 1])) | |
| 11715 --newLength; | |
| 11716 result.content.setLength(newLength); | |
| 11717 return result; | |
| 11718 } | 11750 } |
| 11719 | |
| 11720 } | |
| OLD | NEW |