Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(702)

Side by Side Diff: Source/core/css/CSSParser.h

Issue 15660004: Reporing invalid CSS selectors. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/css/CSSGrammar.y.in ('k') | Source/core/css/CSSParser.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights reserv ed. 3 * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights reserv ed.
4 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 4 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
5 * Copyright (C) 2009 - 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserve d. 5 * Copyright (C) 2009 - 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserve d.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 class CSSParser { 72 class CSSParser {
73 friend inline int cssyylex(void*, CSSParser*); 73 friend inline int cssyylex(void*, CSSParser*);
74 74
75 public: 75 public:
76 class SourceDataHandler; 76 class SourceDataHandler;
77 enum ErrorType { 77 enum ErrorType {
78 NoError, 78 NoError,
79 PropertyDeclarationError, 79 PropertyDeclarationError,
80 InvalidPropertyValueError, 80 InvalidPropertyValueError,
81 InvalidPropertyError, 81 InvalidPropertyError,
82 InvalidSelectorError,
83 InvalidRuleError,
82 GeneralError 84 GeneralError
83 }; 85 };
84 86
85 CSSParser(const CSSParserContext&, UseCounter* = 0); 87 CSSParser(const CSSParserContext&, UseCounter* = 0);
86 88
87 ~CSSParser(); 89 ~CSSParser();
88 90
89 void parseSheet(StyleSheetContents*, const String&, int startLineNumber = 0, SourceDataHandler* = 0, bool = false); 91 void parseSheet(StyleSheetContents*, const String&, int startLineNumber = 0, SourceDataHandler* = 0, bool = false);
90 PassRefPtr<StyleRuleBase> parseRule(StyleSheetContents*, const String&); 92 PassRefPtr<StyleRuleBase> parseRule(StyleSheetContents*, const String&);
91 PassRefPtr<StyleKeyframe> parseKeyframeRule(StyleSheetContents*, const Strin g&); 93 PassRefPtr<StyleKeyframe> parseKeyframeRule(StyleSheetContents*, const Strin g&);
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 363
362 unsigned m_numParsedPropertiesBeforeMarginBox; 364 unsigned m_numParsedPropertiesBeforeMarginBox;
363 365
364 int m_inParseShorthand; 366 int m_inParseShorthand;
365 CSSPropertyID m_currentShorthand; 367 CSSPropertyID m_currentShorthand;
366 bool m_implicitShorthand; 368 bool m_implicitShorthand;
367 369
368 bool m_hasFontFaceOnlyValues; 370 bool m_hasFontFaceOnlyValues;
369 bool m_hadSyntacticallyValidCSSRule; 371 bool m_hadSyntacticallyValidCSSRule;
370 bool m_logErrors; 372 bool m_logErrors;
371 bool m_ignoreErrorsInDeclaration; 373 bool m_ignoreErrors;
372 374
373 bool m_inFilterRule; 375 bool m_inFilterRule;
374 376
375 AtomicString m_defaultNamespace; 377 AtomicString m_defaultNamespace;
376 378
377 // tokenizer methods and data 379 // tokenizer methods and data
378 size_t m_parsedTextPrefixLength; 380 size_t m_parsedTextPrefixLength;
379 size_t m_parsedTextSuffixLength; 381 size_t m_parsedTextSuffixLength;
380 SourceDataHandler* m_sourceDataHandler; 382 SourceDataHandler* m_sourceDataHandler;
381 383
382 void startRuleHeader(CSSRuleSourceData::Type); 384 void startRuleHeader(CSSRuleSourceData::Type);
383 void endRuleHeader(); 385 void endRuleHeader();
384 void startSelector(); 386 void startSelector();
385 void endSelector(); 387 void endSelector();
386 void startRuleBody(); 388 void startRuleBody();
387 void endRuleBody(bool discard = false); 389 void endRuleBody(bool discard = false);
388 void startProperty(); 390 void startProperty();
389 void endProperty(bool isImportantFound, bool isPropertyParsed, ErrorType = N oError); 391 void endProperty(bool isImportantFound, bool isPropertyParsed, ErrorType = N oError);
390 void startEndUnknownRule(); 392 void startEndUnknownRule();
393
394 void endInvalidRuleHeader();
391 void reportError(const CSSParserLocation&, ErrorType = GeneralError); 395 void reportError(const CSSParserLocation&, ErrorType = GeneralError);
396 void resumeErrorLogging() { m_ignoreErrors = false; }
392 397
393 inline int lex(void* yylval) { return (this->*m_lexFunc)(yylval); } 398 inline int lex(void* yylval) { return (this->*m_lexFunc)(yylval); }
394 399
395 int token() { return m_token; } 400 int token() { return m_token; }
396 401
397 void tokenToLowerCase(const CSSParserString& token); 402 void tokenToLowerCase(const CSSParserString& token);
398 403
399 #if ENABLE(CSS_DEVICE_ADAPTATION) 404 #if ENABLE(CSS_DEVICE_ADAPTATION)
400 void markViewportRuleBodyStart() { m_inViewport = true; } 405 void markViewportRuleBodyStart() { m_inViewport = true; }
401 void markViewportRuleBodyEnd() { m_inViewport = false; } 406 void markViewportRuleBodyEnd() { m_inViewport = false; }
402 StyleRuleBase* createViewportRule(); 407 StyleRuleBase* createViewportRule();
403 #endif 408 #endif
404 409
405 PassRefPtr<CSSPrimitiveValue> createPrimitiveNumericValue(CSSParserValue*); 410 PassRefPtr<CSSPrimitiveValue> createPrimitiveNumericValue(CSSParserValue*);
406 PassRefPtr<CSSPrimitiveValue> createPrimitiveStringValue(CSSParserValue*); 411 PassRefPtr<CSSPrimitiveValue> createPrimitiveStringValue(CSSParserValue*);
407 PassRefPtr<CSSPrimitiveValue> createPrimitiveVariableNameValue(CSSParserValu e*); 412 PassRefPtr<CSSPrimitiveValue> createPrimitiveVariableNameValue(CSSParserValu e*);
408 413
409 static KURL completeURL(const CSSParserContext&, const String& url); 414 static KURL completeURL(const CSSParserContext&, const String& url);
410 415
411 CSSParserLocation currentLocation(); 416 CSSParserLocation currentLocation();
412 CSSParserLocation getSource(const CSSParserLocation& begin, const CSSParserL ocation& end) const;
413 417
414 private: 418 private:
415 enum PropertyType { 419 enum PropertyType {
416 PropertyExplicit, 420 PropertyExplicit,
417 PropertyImplicit 421 PropertyImplicit
418 }; 422 };
419 423
420 class ImplicitScope { 424 class ImplicitScope {
421 WTF_MAKE_NONCOPYABLE(ImplicitScope); 425 WTF_MAKE_NONCOPYABLE(ImplicitScope);
422 public: 426 public:
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 const String* m_source; 566 const String* m_source;
563 union { 567 union {
564 LChar* ptr8; 568 LChar* ptr8;
565 UChar* ptr16; 569 UChar* ptr16;
566 } m_tokenStart; 570 } m_tokenStart;
567 unsigned m_length; 571 unsigned m_length;
568 int m_token; 572 int m_token;
569 int m_lineNumber; 573 int m_lineNumber;
570 int m_tokenStartLineNumber; 574 int m_tokenStartLineNumber;
571 int m_lastSelectorLineNumber; 575 int m_lastSelectorLineNumber;
576 CSSRuleSourceData::Type m_ruleHeaderType;
577 unsigned m_ruleHeaderStartOffset;
578 int m_ruleHeaderStartLineNumber;
572 579
573 bool m_allowImportRules; 580 bool m_allowImportRules;
574 bool m_allowNamespaceDeclarations; 581 bool m_allowNamespaceDeclarations;
575 582
576 #if ENABLE(CSS_DEVICE_ADAPTATION) 583 #if ENABLE(CSS_DEVICE_ADAPTATION)
577 bool parseViewportProperty(CSSPropertyID propId, bool important); 584 bool parseViewportProperty(CSSPropertyID propId, bool important);
578 bool parseViewportShorthand(CSSPropertyID propId, CSSPropertyID first, CSSPr opertyID second, bool important); 585 bool parseViewportShorthand(CSSPropertyID propId, CSSPropertyID first, CSSPr opertyID second, bool important);
579 586
580 bool inViewport() const { return m_inViewport; } 587 bool inViewport() const { return m_inViewport; }
581 bool m_inViewport; 588 bool m_inViewport;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 if (!(--m_parser->m_inParseShorthand)) 678 if (!(--m_parser->m_inParseShorthand))
672 m_parser->m_currentShorthand = CSSPropertyInvalid; 679 m_parser->m_currentShorthand = CSSPropertyInvalid;
673 } 680 }
674 681
675 private: 682 private:
676 CSSParser* m_parser; 683 CSSParser* m_parser;
677 }; 684 };
678 685
679 struct CSSParserLocation { 686 struct CSSParserLocation {
680 int lineNumber; 687 int lineNumber;
681 CSSParserString content; 688 CSSParserString token;
682
683 CSSParserLocation trimTrailingWhitespace() const;
684 }; 689 };
685 690
686 class CSSParser::SourceDataHandler { 691 class CSSParser::SourceDataHandler {
687 public: 692 public:
688 virtual void startRuleHeader(CSSRuleSourceData::Type, unsigned offset) = 0; 693 virtual void startRuleHeader(CSSRuleSourceData::Type, unsigned offset) = 0;
689 virtual void endRuleHeader(unsigned offset) = 0; 694 virtual void endRuleHeader(unsigned offset) = 0;
690 virtual void startSelector(unsigned offset) = 0; 695 virtual void startSelector(unsigned offset) = 0;
691 virtual void endSelector(unsigned offset) = 0; 696 virtual void endSelector(unsigned offset) = 0;
692 virtual void startRuleBody(unsigned offset) = 0; 697 virtual void startRuleBody(unsigned offset) = 0;
693 virtual void endRuleBody(unsigned offset, bool error) = 0; 698 virtual void endRuleBody(unsigned offset, bool error) = 0;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 } 736 }
732 737
733 inline int cssyylex(void* yylval, CSSParser* parser) 738 inline int cssyylex(void* yylval, CSSParser* parser)
734 { 739 {
735 return parser->lex(yylval); 740 return parser->lex(yylval);
736 } 741 }
737 742
738 } // namespace WebCore 743 } // namespace WebCore
739 744
740 #endif // CSSParser_h 745 #endif // CSSParser_h
OLDNEW
« no previous file with comments | « Source/core/css/CSSGrammar.y.in ('k') | Source/core/css/CSSParser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698