OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 import os.path | |
4 import re | |
5 import subprocess | 3 import subprocess |
6 import sys | 4 import sys |
7 | 5 |
8 from in_file import InFile | |
9 from name_utilities import enum_for_css_keyword | 6 from name_utilities import enum_for_css_keyword |
10 from name_utilities import upper_first_letter | |
11 import in_generator | 7 import in_generator |
12 import license | 8 import license |
13 | 9 |
14 | 10 |
15 HEADER_TEMPLATE = """ | 11 HEADER_TEMPLATE = """ |
16 %(license)s | 12 %(license)s |
17 | 13 |
18 #ifndef %(class_name)s_h | 14 #ifndef %(class_name)s_h |
19 #define %(class_name)s_h | 15 #define %(class_name)s_h |
20 | 16 |
21 #include "core/css/parser/CSSParserMode.h" | 17 #include "core/css/parser/CSSParserMode.h" |
22 #include <string.h> | 18 #include <string.h> |
23 | 19 |
24 namespace blink { | 20 namespace blink { |
25 | 21 |
26 enum CSSValueID { | 22 enum CSSValueID { |
27 %(value_keyword_enums)s | 23 %(value_keyword_enums)s |
28 }; | 24 }; |
29 | 25 |
30 const int numCSSValueKeywords = %(value_keywords_count)d; | 26 const int numCSSValueKeywords = %(value_keywords_count)d; |
31 const size_t maxCSSValueKeywordLength = %(max_value_keyword_length)d; | 27 const size_t maxCSSValueKeywordLength = %(max_value_keyword_length)d; |
32 | 28 |
33 const char* getValueName(CSSValueID); | 29 const char* getValueName(CSSValueID); |
34 bool isValueAllowedInMode(unsigned short id, CSSParserMode mode); | 30 bool isValueAllowedInMode(unsigned short id, CSSParserMode mode); |
| 31 bool isColorKeyword(CSSValueID); |
35 | 32 |
36 } // namespace blink | 33 } // namespace blink |
37 | 34 |
38 #endif // %(class_name)s_h | 35 #endif // %(class_name)s_h |
39 """ | 36 """ |
40 | 37 |
41 GPERF_TEMPLATE = """ | 38 GPERF_TEMPLATE = """ |
42 %%{ | 39 %%{ |
43 %(license)s | 40 %(license)s |
44 | 41 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 switch (id) { | 92 switch (id) { |
96 %(ua_sheet_mode_values_keywords)s | 93 %(ua_sheet_mode_values_keywords)s |
97 return isUASheetBehavior(mode); | 94 return isUASheetBehavior(mode); |
98 %(quirks_mode_or_ua_sheet_mode_values_keywords)s | 95 %(quirks_mode_or_ua_sheet_mode_values_keywords)s |
99 return isUASheetBehavior(mode) || isQuirksModeBehavior(mode); | 96 return isUASheetBehavior(mode) || isQuirksModeBehavior(mode); |
100 default: | 97 default: |
101 return true; | 98 return true; |
102 } | 99 } |
103 } | 100 } |
104 | 101 |
| 102 bool isColorKeyword(CSSValueID id) |
| 103 { |
| 104 // Named colors and color keywords: |
| 105 // |
| 106 // <named-color> |
| 107 // 'aqua', 'black', 'blue', ..., 'yellow' (CSS3: "basic color keywords") |
| 108 // 'aliceblue', ..., 'yellowgreen' (CSS3: "extended color keywords"
) |
| 109 // 'transparent' |
| 110 // |
| 111 // 'currentcolor' |
| 112 // |
| 113 // <deprecated-system-color> |
| 114 // 'ActiveBorder', ..., 'WindowText' |
| 115 // |
| 116 // WebKit proprietary/internal: |
| 117 // '-webkit-link' |
| 118 // '-webkit-activelink' |
| 119 // '-internal-active-list-box-selection' |
| 120 // '-internal-active-list-box-selection-text' |
| 121 // '-internal-inactive-list-box-selection' |
| 122 // '-internal-inactive-list-box-selection-text' |
| 123 // '-webkit-focus-ring-color' |
| 124 // '-internal-quirk-inherit' |
| 125 // |
| 126 return (id >= CSSValueAqua && id <= CSSValueInternalQuirkInherit) |
| 127 || (id >= CSSValueAliceblue && id <= CSSValueYellowgreen) |
| 128 || id == CSSValueMenu; |
| 129 } |
| 130 |
105 } // namespace blink | 131 } // namespace blink |
106 """ | 132 """ |
107 | 133 |
108 | 134 |
109 class CSSValueKeywordsWriter(in_generator.Writer): | 135 class CSSValueKeywordsWriter(in_generator.Writer): |
110 class_name = "CSSValueKeywords" | 136 class_name = "CSSValueKeywords" |
111 defaults = { | 137 defaults = { |
112 'mode': None, | 138 'mode': None, |
113 } | 139 } |
114 | 140 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 # FIXME: If we could depend on Python 2.7, we would use subprocess.check
_output | 194 # FIXME: If we could depend on Python 2.7, we would use subprocess.check
_output |
169 gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n'] | 195 gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n'] |
170 gperf_args.extend(['-m', '50']) # Pick best of 50 attempts. | 196 gperf_args.extend(['-m', '50']) # Pick best of 50 attempts. |
171 gperf_args.append('-D') # Allow duplicate hashes -> More compact code. | 197 gperf_args.append('-D') # Allow duplicate hashes -> More compact code. |
172 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=subpr
ocess.PIPE, universal_newlines=True) | 198 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=subpr
ocess.PIPE, universal_newlines=True) |
173 return gperf.communicate(gperf_input)[0] | 199 return gperf.communicate(gperf_input)[0] |
174 | 200 |
175 | 201 |
176 if __name__ == "__main__": | 202 if __name__ == "__main__": |
177 in_generator.Maker(CSSValueKeywordsWriter).main(sys.argv) | 203 in_generator.Maker(CSSValueKeywordsWriter).main(sys.argv) |
OLD | NEW |