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) 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 * Copyright (C) 2013 Opera Software ASA. All rights reserved. |
6 * | 7 * |
7 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 11 * version 2 of the License, or (at your option) any later version. |
11 * | 12 * |
12 * This library is distributed in the hope that it will be useful, | 13 * This library is distributed in the hope that it will be useful, |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Library General Public License for more details. | 16 * Library General Public License for more details. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 class StyleRuleBase; | 61 class StyleRuleBase; |
61 class StyleRuleKeyframes; | 62 class StyleRuleKeyframes; |
62 class StyleKeyframe; | 63 class StyleKeyframe; |
63 class StyleSheetContents; | 64 class StyleSheetContents; |
64 class StyledElement; | 65 class StyledElement; |
65 | 66 |
66 class WebKitCSSArrayFunctionValue; | 67 class WebKitCSSArrayFunctionValue; |
67 class WebKitCSSMixFunctionValue; | 68 class WebKitCSSMixFunctionValue; |
68 class WebKitCSSShaderValue; | 69 class WebKitCSSShaderValue; |
69 | 70 |
| 71 // Keep track of matching parentheses using a stack of opening brackets. |
| 72 // Needed for correct error recovery. |
| 73 class BracketStack { |
| 74 public: |
| 75 inline void push(int bracket) { m_stack.append(bracket); } |
| 76 |
| 77 inline void pop(int bracket) |
| 78 { |
| 79 if (m_stack.size() > 0) { |
| 80 switch (bracket) { |
| 81 case '}': |
| 82 if (m_stack.last() == '{') |
| 83 m_stack.removeLast(); |
| 84 break; |
| 85 case ')': |
| 86 if (m_stack.last() == '(') |
| 87 m_stack.removeLast(); |
| 88 break; |
| 89 case ']': |
| 90 if (m_stack.last() == '[') |
| 91 m_stack.removeLast(); |
| 92 break; |
| 93 default: |
| 94 ASSERT_NOT_REACHED(); |
| 95 break; |
| 96 } |
| 97 } |
| 98 } |
| 99 |
| 100 inline int pop() |
| 101 { |
| 102 if (!m_stack.size()) |
| 103 return 0; |
| 104 |
| 105 int ret = 0; |
| 106 switch (top()) { |
| 107 case '{': |
| 108 ret = '}'; |
| 109 break; |
| 110 case '(': |
| 111 ret = ')'; |
| 112 break; |
| 113 case '[': |
| 114 ret = ']'; |
| 115 break; |
| 116 default: |
| 117 ASSERT_NOT_REACHED(); |
| 118 break; |
| 119 } |
| 120 m_stack.removeLast(); |
| 121 return ret; |
| 122 } |
| 123 |
| 124 int top() const { return m_stack.last(); } |
| 125 |
| 126 inline size_t level() const { return m_stack.size(); } |
| 127 |
| 128 private: |
| 129 // Make room for 16 levels deep nesting of parentheses initially. |
| 130 Vector<int, 16> m_stack; |
| 131 }; |
| 132 |
70 class CSSParser { | 133 class CSSParser { |
71 friend inline int cssyylex(void*, CSSParser*); | 134 friend inline int cssyylex(void*, CSSParser*); |
72 | 135 |
73 public: | 136 public: |
74 struct Location; | 137 struct Location; |
75 class SourceDataHandler; | 138 class SourceDataHandler; |
76 enum SyntaxErrorType { | 139 enum SyntaxErrorType { |
77 NoSyntaxError, | 140 NoSyntaxError, |
78 PropertyDeclarationError, | 141 PropertyDeclarationError, |
79 GeneralSyntaxError | 142 GeneralSyntaxError |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 #if ENABLE(CSS_DEVICE_ADAPTATION) | 461 #if ENABLE(CSS_DEVICE_ADAPTATION) |
399 void markViewportRuleBodyStart() { m_inViewport = true; } | 462 void markViewportRuleBodyStart() { m_inViewport = true; } |
400 void markViewportRuleBodyEnd() { m_inViewport = false; } | 463 void markViewportRuleBodyEnd() { m_inViewport = false; } |
401 StyleRuleBase* createViewportRule(); | 464 StyleRuleBase* createViewportRule(); |
402 #endif | 465 #endif |
403 | 466 |
404 PassRefPtr<CSSPrimitiveValue> createPrimitiveNumericValue(CSSParserValue*); | 467 PassRefPtr<CSSPrimitiveValue> createPrimitiveNumericValue(CSSParserValue*); |
405 PassRefPtr<CSSPrimitiveValue> createPrimitiveStringValue(CSSParserValue*); | 468 PassRefPtr<CSSPrimitiveValue> createPrimitiveStringValue(CSSParserValue*); |
406 PassRefPtr<CSSPrimitiveValue> createPrimitiveVariableNameValue(CSSParserValu
e*); | 469 PassRefPtr<CSSPrimitiveValue> createPrimitiveVariableNameValue(CSSParserValu
e*); |
407 | 470 |
| 471 // Store block level. |
| 472 void markMediaListStart(); |
| 473 |
| 474 // Error token reached while parsing a media_query, synchronized at current
token. |
| 475 MediaQuery* recoverMediaQuery(); |
| 476 |
408 static KURL completeURL(const CSSParserContext&, const String& url); | 477 static KURL completeURL(const CSSParserContext&, const String& url); |
409 | 478 |
410 Location currentLocation(); | 479 Location currentLocation(); |
411 | 480 |
412 private: | 481 private: |
413 bool is8BitSource() { return m_is8BitSource; } | 482 bool is8BitSource() { return m_is8BitSource; } |
414 | 483 |
415 template <typename SourceCharacterType> | 484 template <typename SourceCharacterType> |
416 int realLex(void* yylval); | 485 int realLex(void* yylval); |
417 | 486 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 bool m_allowNamespaceDeclarations; | 615 bool m_allowNamespaceDeclarations; |
547 | 616 |
548 #if ENABLE(CSS_DEVICE_ADAPTATION) | 617 #if ENABLE(CSS_DEVICE_ADAPTATION) |
549 bool parseViewportProperty(CSSPropertyID propId, bool important); | 618 bool parseViewportProperty(CSSPropertyID propId, bool important); |
550 bool parseViewportShorthand(CSSPropertyID propId, CSSPropertyID first, CSSPr
opertyID second, bool important); | 619 bool parseViewportShorthand(CSSPropertyID propId, CSSPropertyID first, CSSPr
opertyID second, bool important); |
551 | 620 |
552 bool inViewport() const { return m_inViewport; } | 621 bool inViewport() const { return m_inViewport; } |
553 bool m_inViewport; | 622 bool m_inViewport; |
554 #endif | 623 #endif |
555 | 624 |
| 625 enum ReEmissionState { |
| 626 DontEmit, |
| 627 ReEmit, |
| 628 DidReEmit |
| 629 }; |
| 630 |
| 631 inline void markCurrentTokenForReEmission(); |
| 632 |
| 633 ReEmissionState m_reEmissionState; |
| 634 BracketStack m_brackets; |
| 635 size_t m_storedBlockLevel; |
| 636 |
556 int (CSSParser::*m_lexFunc)(void*); | 637 int (CSSParser::*m_lexFunc)(void*); |
557 | 638 |
558 Vector<RefPtr<StyleRuleBase> > m_parsedRules; | 639 Vector<RefPtr<StyleRuleBase> > m_parsedRules; |
559 Vector<RefPtr<StyleKeyframe> > m_parsedKeyframes; | 640 Vector<RefPtr<StyleKeyframe> > m_parsedKeyframes; |
560 Vector<RefPtr<MediaQuerySet> > m_parsedMediaQuerySets; | 641 Vector<RefPtr<MediaQuerySet> > m_parsedMediaQuerySets; |
561 Vector<OwnPtr<RuleList> > m_parsedRuleLists; | 642 Vector<OwnPtr<RuleList> > m_parsedRuleLists; |
562 HashSet<CSSParserSelector*> m_floatingSelectors; | 643 HashSet<CSSParserSelector*> m_floatingSelectors; |
563 HashSet<Vector<OwnPtr<CSSParserSelector> >*> m_floatingSelectorVectors; | 644 HashSet<Vector<OwnPtr<CSSParserSelector> >*> m_floatingSelectorVectors; |
564 HashSet<CSSParserValueList*> m_floatingValueLists; | 645 HashSet<CSSParserValueList*> m_floatingValueLists; |
565 HashSet<CSSParserFunction*> m_floatingFunctions; | 646 HashSet<CSSParserFunction*> m_floatingFunctions; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 if (is8BitSource()) | 779 if (is8BitSource()) |
699 return *m_tokenStart.ptr8; | 780 return *m_tokenStart.ptr8; |
700 return *m_tokenStart.ptr16; | 781 return *m_tokenStart.ptr16; |
701 } | 782 } |
702 | 783 |
703 inline int cssyylex(void* yylval, CSSParser* parser) | 784 inline int cssyylex(void* yylval, CSSParser* parser) |
704 { | 785 { |
705 return parser->lex(yylval); | 786 return parser->lex(yylval); |
706 } | 787 } |
707 | 788 |
| 789 inline void CSSParser::markCurrentTokenForReEmission() |
| 790 { |
| 791 // Sanity check. |
| 792 // Re-emitting a token which has just been re-emitted may cause an infinite |
| 793 // loop. Also, marking a token for re-emit twice also doesn't make sense. |
| 794 ASSERT(m_reEmissionState == DontEmit); |
| 795 |
| 796 // Make sure we don't enter an infinite loop if the assert triggers. |
| 797 if (m_reEmissionState == DontEmit) |
| 798 m_reEmissionState = ReEmit; |
| 799 } |
| 800 |
708 } // namespace WebCore | 801 } // namespace WebCore |
709 | 802 |
710 #endif // CSSParser_h | 803 #endif // CSSParser_h |
OLD | NEW |