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

Side by Side Diff: sky/engine/core/css/parser/CSSTokenizer-in.cpp

Issue 807703003: Remove @media rules. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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
OLDNEW
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 *
11 * This library is free software; you can redistribute it and/or 11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public 12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either 13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version. 14 * version 2 of the License, or (at your option) any later version.
15 * 15 *
16 * This library is distributed in the hope that it will be useful, 16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details. 19 * Library General Public License for more details.
20 * 20 *
21 * You should have received a copy of the GNU Library General Public License 21 * You should have received a copy of the GNU Library General Public License
22 * along with this library; see the file COPYING.LIB. If not, write to 22 * along with this library; see the file COPYING.LIB. If not, write to
23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA. 24 * Boston, MA 02110-1301, USA.
25 */ 25 */
26 26
27 #include "sky/engine/config.h" 27 #include "sky/engine/config.h"
28 #include "sky/engine/core/css/parser/CSSTokenizer.h" 28 #include "sky/engine/core/css/parser/CSSTokenizer.h"
29 29
30 #include "sky/engine/core/css/MediaQuery.h"
31 #include "sky/engine/core/css/StyleRule.h" 30 #include "sky/engine/core/css/StyleRule.h"
32 #include "sky/engine/core/css/parser/BisonCSSParser.h" 31 #include "sky/engine/core/css/parser/BisonCSSParser.h"
33 #include "sky/engine/core/css/parser/CSSParserValues.h" 32 #include "sky/engine/core/css/parser/CSSParserValues.h"
34 #include "sky/engine/core/html/parser/HTMLParserIdioms.h" 33 #include "sky/engine/core/html/parser/HTMLParserIdioms.h"
35 34
36 namespace blink { 35 namespace blink {
37 36
38 #include "gen/sky/core/CSSGrammar.h" 37 #include "gen/sky/core/CSSGrammar.h"
39 38
40 enum CharacterType { 39 enum CharacterType {
41 // Types for the main switch. 40 // Types for the main switch.
42 41
43 // The first 4 types must be grouped together, as they 42 // The first 4 types must be grouped together, as they
44 // represent the allowed chars in an identifier. 43 // represent the allowed chars in an identifier.
45 CharacterCaselessU, 44 CharacterCaselessU,
46 CharacterIdentifierStart, 45 CharacterIdentifierStart,
47 CharacterNumber, 46 CharacterNumber,
48 CharacterDash, 47 CharacterDash,
49 48
50 CharacterOther, 49 CharacterOther,
51 CharacterNull, 50 CharacterNull,
52 CharacterWhiteSpace, 51 CharacterWhiteSpace,
53 CharacterEndMediaQueryOrSupports, 52 CharacterEndSupports,
54 CharacterEndNthChild, 53 CharacterEndNthChild,
55 CharacterQuote, 54 CharacterQuote,
56 CharacterExclamationMark, 55 CharacterExclamationMark,
57 CharacterHashmark, 56 CharacterHashmark,
58 CharacterDollar, 57 CharacterDollar,
59 CharacterAsterisk, 58 CharacterAsterisk,
60 CharacterPlus, 59 CharacterPlus,
61 CharacterDot, 60 CharacterDot,
62 CharacterSlash, 61 CharacterSlash,
63 CharacterLess, 62 CharacterLess,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 /* 49 - 1 */ CharacterNumber, 121 /* 49 - 1 */ CharacterNumber,
123 /* 50 - 2 */ CharacterNumber, 122 /* 50 - 2 */ CharacterNumber,
124 /* 51 - 3 */ CharacterNumber, 123 /* 51 - 3 */ CharacterNumber,
125 /* 52 - 4 */ CharacterNumber, 124 /* 52 - 4 */ CharacterNumber,
126 /* 53 - 5 */ CharacterNumber, 125 /* 53 - 5 */ CharacterNumber,
127 /* 54 - 6 */ CharacterNumber, 126 /* 54 - 6 */ CharacterNumber,
128 /* 55 - 7 */ CharacterNumber, 127 /* 55 - 7 */ CharacterNumber,
129 /* 56 - 8 */ CharacterNumber, 128 /* 56 - 8 */ CharacterNumber,
130 /* 57 - 9 */ CharacterNumber, 129 /* 57 - 9 */ CharacterNumber,
131 /* 58 - : */ CharacterOther, 130 /* 58 - : */ CharacterOther,
132 /* 59 - ; */ CharacterEndMediaQueryOrSupports, 131 /* 59 - ; */ CharacterEndSupports,
133 /* 60 - < */ CharacterLess, 132 /* 60 - < */ CharacterLess,
134 /* 61 - = */ CharacterOther, 133 /* 61 - = */ CharacterOther,
135 /* 62 - > */ CharacterOther, 134 /* 62 - > */ CharacterOther,
136 /* 63 - ? */ CharacterOther, 135 /* 63 - ? */ CharacterOther,
137 /* 64 - @ */ CharacterAt, 136 /* 64 - @ */ CharacterAt,
138 /* 65 - A */ CharacterIdentifierStart, 137 /* 65 - A */ CharacterIdentifierStart,
139 /* 66 - B */ CharacterIdentifierStart, 138 /* 66 - B */ CharacterIdentifierStart,
140 /* 67 - C */ CharacterIdentifierStart, 139 /* 67 - C */ CharacterIdentifierStart,
141 /* 68 - D */ CharacterIdentifierStart, 140 /* 68 - D */ CharacterIdentifierStart,
142 /* 69 - E */ CharacterIdentifierStart, 141 /* 69 - E */ CharacterIdentifierStart,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 /* 113 - q */ CharacterIdentifierStart, 185 /* 113 - q */ CharacterIdentifierStart,
187 /* 114 - r */ CharacterIdentifierStart, 186 /* 114 - r */ CharacterIdentifierStart,
188 /* 115 - s */ CharacterIdentifierStart, 187 /* 115 - s */ CharacterIdentifierStart,
189 /* 116 - t */ CharacterIdentifierStart, 188 /* 116 - t */ CharacterIdentifierStart,
190 /* 117 - u */ CharacterCaselessU, 189 /* 117 - u */ CharacterCaselessU,
191 /* 118 - v */ CharacterIdentifierStart, 190 /* 118 - v */ CharacterIdentifierStart,
192 /* 119 - w */ CharacterIdentifierStart, 191 /* 119 - w */ CharacterIdentifierStart,
193 /* 120 - x */ CharacterIdentifierStart, 192 /* 120 - x */ CharacterIdentifierStart,
194 /* 121 - y */ CharacterIdentifierStart, 193 /* 121 - y */ CharacterIdentifierStart,
195 /* 122 - z */ CharacterIdentifierStart, 194 /* 122 - z */ CharacterIdentifierStart,
196 /* 123 - { */ CharacterEndMediaQueryOrSupports, 195 /* 123 - { */ CharacterEndSupports,
197 /* 124 - | */ CharacterVerticalBar, 196 /* 124 - | */ CharacterVerticalBar,
198 /* 125 - } */ CharacterOther, 197 /* 125 - } */ CharacterOther,
199 /* 126 - ~ */ CharacterTilde, 198 /* 126 - ~ */ CharacterTilde,
200 /* 127 - Delete */ CharacterOther, 199 /* 127 - Delete */ CharacterOther,
201 }; 200 };
202 201
203 // Utility functions for the CSS tokenizer. 202 // Utility functions for the CSS tokenizer.
204 203
205 template <typename CharacterType> 204 template <typename CharacterType>
206 static inline bool isCSSLetter(CharacterType character) 205 static inline bool isCSSLetter(CharacterType character)
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 } 748 }
750 CASE("host") { 749 CASE("host") {
751 m_token = HOSTFUNCTION; 750 m_token = HOSTFUNCTION;
752 return true; 751 return true;
753 } 752 }
754 } 753 }
755 return false; 754 return false;
756 } 755 }
757 756
758 template <typename CharacterType> 757 template <typename CharacterType>
759 inline void CSSTokenizer::detectMediaQueryToken(int length)
760 {
761 ASSERT(m_parsingMode == MediaQueryMode);
762 CharacterType* name = tokenStart<CharacterType>();
763
764 SWITCH(name, length) {
765 CASE("and") {
766 m_token = MEDIA_AND;
767 }
768 CASE("not") {
769 m_token = MEDIA_NOT;
770 }
771 CASE("only") {
772 m_token = MEDIA_ONLY;
773 }
774 CASE("or") {
775 m_token = MEDIA_OR;
776 }
777 }
778 }
779
780 template <typename CharacterType>
781 inline void CSSTokenizer::detectNumberToken(CharacterType* type, int length) 758 inline void CSSTokenizer::detectNumberToken(CharacterType* type, int length)
782 { 759 {
783 ASSERT(length > 0); 760 ASSERT(length > 0);
784 761
785 SWITCH(type, length) { 762 SWITCH(type, length) {
786 CASE("cm") { 763 CASE("cm") {
787 m_token = CMS; 764 m_token = CMS;
788 } 765 }
789 CASE("ch") { 766 CASE("ch") {
790 m_token = CHS; 767 m_token = CHS;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 CASE("charset") { 873 CASE("charset") {
897 if (name - 1 == dataStart<CharacterType>()) 874 if (name - 1 == dataStart<CharacterType>())
898 m_token = CHARSET_SYM; 875 m_token = CHARSET_SYM;
899 } 876 }
900 CASE("font-face") { 877 CASE("font-face") {
901 m_token = FONT_FACE_SYM; 878 m_token = FONT_FACE_SYM;
902 } 879 }
903 CASE("keyframes") { 880 CASE("keyframes") {
904 m_token = KEYFRAMES_SYM; 881 m_token = KEYFRAMES_SYM;
905 } 882 }
906 CASE("media") {
907 m_parsingMode = MediaQueryMode;
908 m_token = MEDIA_SYM;
909 }
910 CASE("supports") { 883 CASE("supports") {
911 m_parsingMode = SupportsMode; 884 m_parsingMode = SupportsMode;
912 m_token = SUPPORTS_SYM; 885 m_token = SUPPORTS_SYM;
913 } 886 }
914 CASE("-internal-rule") { 887 CASE("-internal-rule") {
915 if (LIKELY(!hasEscape && m_internal)) 888 if (LIKELY(!hasEscape && m_internal))
916 m_token = INTERNAL_RULE_SYM; 889 m_token = INTERNAL_RULE_SYM;
917 } 890 }
918 CASE("-internal-decls") { 891 CASE("-internal-decls") {
919 if (LIKELY(!hasEscape && m_internal)) 892 if (LIKELY(!hasEscape && m_internal))
920 m_token = INTERNAL_DECLS_SYM; 893 m_token = INTERNAL_DECLS_SYM;
921 } 894 }
922 CASE("-internal-value") { 895 CASE("-internal-value") {
923 if (LIKELY(!hasEscape && m_internal)) 896 if (LIKELY(!hasEscape && m_internal))
924 m_token = INTERNAL_VALUE_SYM; 897 m_token = INTERNAL_VALUE_SYM;
925 } 898 }
926 CASE("-internal-selector") { 899 CASE("-internal-selector") {
927 if (LIKELY(!hasEscape && m_internal)) 900 if (LIKELY(!hasEscape && m_internal))
928 m_token = INTERNAL_SELECTOR_SYM; 901 m_token = INTERNAL_SELECTOR_SYM;
929 } 902 }
930 CASE("-internal-medialist") {
931 if (!m_internal)
932 return;
933 m_parsingMode = MediaQueryMode;
934 m_token = INTERNAL_MEDIALIST_SYM;
935 }
936 CASE("-internal-keyframe-rule") { 903 CASE("-internal-keyframe-rule") {
937 if (LIKELY(!hasEscape && m_internal)) 904 if (LIKELY(!hasEscape && m_internal))
938 m_token = INTERNAL_KEYFRAME_RULE_SYM; 905 m_token = INTERNAL_KEYFRAME_RULE_SYM;
939 } 906 }
940 CASE("-internal-keyframe-key-list") { 907 CASE("-internal-keyframe-key-list") {
941 if (!m_internal) 908 if (!m_internal)
942 return; 909 return;
943 m_token = INTERNAL_KEYFRAME_KEY_LIST_SYM; 910 m_token = INTERNAL_KEYFRAME_KEY_LIST_SYM;
944 } 911 }
945 CASE("-internal-supports-condition") { 912 CASE("-internal-supports-condition") {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 994
1028 if (m_token == URI) { 995 if (m_token == URI) {
1029 m_token = FUNCTION; 996 m_token = FUNCTION;
1030 // Check whether it is really an URI. 997 // Check whether it is really an URI.
1031 if (yylval->string.is8Bit()) 998 if (yylval->string.is8Bit())
1032 parseURI<LChar>(yylval->string); 999 parseURI<LChar>(yylval->string);
1033 else 1000 else
1034 parseURI<UChar>(yylval->string); 1001 parseURI<UChar>(yylval->string);
1035 } 1002 }
1036 } else if (UNLIKELY(m_parsingMode != NormalMode) && !hasEscape) { 1003 } else if (UNLIKELY(m_parsingMode != NormalMode) && !hasEscape) {
1037 if (m_parsingMode == MediaQueryMode) { 1004 if (m_parsingMode == SupportsMode) {
1038 detectMediaQueryToken<SrcCharacterType>(result - tokenStart<SrcC haracterType>());
1039 } else if (m_parsingMode == SupportsMode) {
1040 detectSupportsToken<SrcCharacterType>(result - tokenStart<SrcCha racterType>()); 1005 detectSupportsToken<SrcCharacterType>(result - tokenStart<SrcCha racterType>());
1041 } 1006 }
1042 } 1007 }
1043 break; 1008 break;
1044 1009
1045 case CharacterDot: 1010 case CharacterDot:
1046 if (!isASCIIDigit(currentCharacter<SrcCharacterType>()[0])) 1011 if (!isASCIIDigit(currentCharacter<SrcCharacterType>()[0]))
1047 break; 1012 break;
1048 // Fall through to CharacterNumber. 1013 // Fall through to CharacterNumber.
1049 1014
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 m_token = WHITESPACE; 1090 m_token = WHITESPACE;
1126 // Might start with a '\n'. 1091 // Might start with a '\n'.
1127 --currentCharacter<SrcCharacterType>(); 1092 --currentCharacter<SrcCharacterType>();
1128 do { 1093 do {
1129 if (*currentCharacter<SrcCharacterType>() == '\n') 1094 if (*currentCharacter<SrcCharacterType>() == '\n')
1130 ++m_lineNumber; 1095 ++m_lineNumber;
1131 ++currentCharacter<SrcCharacterType>(); 1096 ++currentCharacter<SrcCharacterType>();
1132 } while (*currentCharacter<SrcCharacterType>() <= ' ' && (typesOfASCIICh aracters[*currentCharacter<SrcCharacterType>()] == CharacterWhiteSpace)); 1097 } while (*currentCharacter<SrcCharacterType>() <= ' ' && (typesOfASCIICh aracters[*currentCharacter<SrcCharacterType>()] == CharacterWhiteSpace));
1133 break; 1098 break;
1134 1099
1135 case CharacterEndMediaQueryOrSupports: 1100 case CharacterEndSupports:
1136 if (m_parsingMode == MediaQueryMode || m_parsingMode == SupportsMode) 1101 if (m_parsingMode == SupportsMode)
1137 m_parsingMode = NormalMode; 1102 m_parsingMode = NormalMode;
1138 break; 1103 break;
1139 1104
1140 case CharacterQuote: 1105 case CharacterQuote:
1141 if (checkAndSkipString(currentCharacter<SrcCharacterType>(), m_token, Ab ortIfInvalid)) { 1106 if (checkAndSkipString(currentCharacter<SrcCharacterType>(), m_token, Ab ortIfInvalid)) {
1142 ++result; 1107 ++result;
1143 parseString<SrcCharacterType>(result, yylval->string, m_token); 1108 parseString<SrcCharacterType>(result, yylval->string, m_token);
1144 m_token = STRING; 1109 m_token = STRING;
1145 } 1110 }
1146 break; 1111 break;
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 m_dataStart16[length - 1] = 0; 1309 m_dataStart16[length - 1] = 0;
1345 1310
1346 m_is8BitSource = false; 1311 m_is8BitSource = false;
1347 m_currentCharacter8 = 0; 1312 m_currentCharacter8 = 0;
1348 m_currentCharacter16 = m_dataStart16.get(); 1313 m_currentCharacter16 = m_dataStart16.get();
1349 setTokenStart<UChar>(m_currentCharacter16); 1314 setTokenStart<UChar>(m_currentCharacter16);
1350 m_lexFunc = &CSSTokenizer::realLex<UChar>; 1315 m_lexFunc = &CSSTokenizer::realLex<UChar>;
1351 } 1316 }
1352 1317
1353 } // namespace blink 1318 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/css/parser/CSSTokenizer.h ('k') | sky/engine/core/css/resolver/ScopedStyleResolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698