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

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_converter.py

Issue 2633223003: Convert CSSProperties.in to JSON5 format (Closed)
Patch Set: Fix test_converter_unittest Created 3 years, 10 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
OLDNEW
1 # Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 1 # Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions 4 # modification, are permitted provided that the following conditions
5 # are met: 5 # are met:
6 # 6 #
7 # 1. Redistributions of source code must retain the above 7 # 1. Redistributions of source code must retain the above
8 # copyright notice, this list of conditions and the following 8 # copyright notice, this list of conditions and the following
9 # disclaimer. 9 # disclaimer.
10 # 2. Redistributions in binary form must reproduce the above 10 # 2. Redistributions in binary form must reproduce the above
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 self.converted_properties = [] 80 self.converted_properties = []
81 self.in_style_tag = False 81 self.in_style_tag = False
82 self.style_data = [] 82 self.style_data = []
83 self.filename = filename 83 self.filename = filename
84 self.reference_support_info = reference_support_info 84 self.reference_support_info = reference_support_info
85 resources_path = self.path_from_webkit_root('LayoutTests', 'resources') 85 resources_path = self.path_from_webkit_root('LayoutTests', 'resources')
86 resources_relpath = self._filesystem.relpath(resources_path, new_path) 86 resources_relpath = self._filesystem.relpath(resources_path, new_path)
87 self.resources_relpath = resources_relpath 87 self.resources_relpath = resources_relpath
88 88
89 # These settings might vary between WebKit and Blink. 89 # These settings might vary between WebKit and Blink.
90 self._css_property_file = self.path_from_webkit_root('Source', 'core', ' css', 'CSSProperties.in') 90 # Only -webkit-text-emphasis is currently needed. See:
91 self.prefixed_properties = self.read_webkit_prefixed_css_property_list() 91 # https://bugs.chromium.org/p/chromium/issues/detail?id=614955#c1
92 self.prefixed_properties = [
93 '-webkit-text-emphasis',
94 '-webkit-text-emphasis-color',
95 '-webkit-text-emphasis-position',
96 '-webkit-text-emphasis-style',
97 ]
92 prop_regex = r'([\s{]|^)(' + '|'.join( 98 prop_regex = r'([\s{]|^)(' + '|'.join(
93 prop.replace('-webkit-', '') for prop in self.prefixed_properties) + r')(\s+:|:)' 99 prop.replace('-webkit-', '') for prop in self.prefixed_properties) + r')(\s+:|:)'
94 self.prop_re = re.compile(prop_regex) 100 self.prop_re = re.compile(prop_regex)
95 101
96 def output(self): 102 def output(self):
97 return (self.converted_properties, ''.join(self.converted_data)) 103 return (self.converted_properties, ''.join(self.converted_data))
98 104
99 def path_from_webkit_root(self, *comps): 105 def path_from_webkit_root(self, *comps):
100 return self._filesystem.abspath(self._filesystem.join(self._webkit_root, *comps)) 106 return self._filesystem.abspath(self._filesystem.join(self._webkit_root, *comps))
101 107
102 def read_webkit_prefixed_css_property_list(self):
103 prefixed_properties = []
104 unprefixed_properties = set()
105
106 contents = self._filesystem.read_text_file(self._css_property_file)
107 for line in contents.splitlines():
108 if re.match(r'^(#|//|$)', line):
109 # skip comments and preprocessor directives.
110 continue
111 prop = line.split()[0]
112 # Find properties starting with the -webkit- prefix.
113 match = re.match(r'-webkit-([\w|-]*)', prop)
114 if match:
115 prefixed_properties.append(match.group(1))
116 else:
117 unprefixed_properties.add(prop.strip())
118
119 # Ignore any prefixed properties for which an unprefixed version is supp orted.
120 return [prop for prop in prefixed_properties if prop not in unprefixed_p roperties]
121
122 def add_webkit_prefix_to_unprefixed_properties(self, text): 108 def add_webkit_prefix_to_unprefixed_properties(self, text):
123 """Searches |text| for instances of properties requiring the -webkit- pr efix and adds the prefix to them. 109 """Searches |text| for instances of properties requiring the -webkit- pr efix and adds the prefix to them.
124 110
125 Returns the list of converted properties and the modified text. 111 Returns the list of converted properties and the modified text.
126 """ 112 """
127 converted_properties = set() 113 converted_properties = set()
128 text_chunks = [] 114 text_chunks = []
129 cur_pos = 0 115 cur_pos = 0
130 for match in self.prop_re.finditer(text): 116 for match in self.prop_re.finditer(text):
131 text_chunks.extend([ 117 text_chunks.extend([
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 self.converted_data.extend(['&#', name, ';']) 211 self.converted_data.extend(['&#', name, ';'])
226 212
227 def handle_comment(self, data): 213 def handle_comment(self, data):
228 self.converted_data.extend(['<!--', data, '-->']) 214 self.converted_data.extend(['<!--', data, '-->'])
229 215
230 def handle_decl(self, decl): 216 def handle_decl(self, decl):
231 self.converted_data.extend(['<!', decl, '>']) 217 self.converted_data.extend(['<!', decl, '>'])
232 218
233 def handle_pi(self, data): 219 def handle_pi(self, data):
234 self.converted_data.extend(['<?', data, '>']) 220 self.converted_data.extend(['<?', data, '>'])
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698