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

Side by Side Diff: grit/gather/chrome_html.py

Issue 15713020: High DPI support for Themes: change chrome_html.py (Closed) Base URL: https://chromium.googlesource.com/external/grit-i18n.git@master
Patch Set: unittest Created 7 years, 6 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
« no previous file with comments | « no previous file | grit/gather/chrome_html_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Prepares a Chrome HTML file by inlining resources and adding references to 6 """Prepares a Chrome HTML file by inlining resources and adding references to
7 high DPI resources and removing references to unsupported scale factors. 7 high DPI resources and removing references to unsupported scale factors.
8 8
9 This is a small gatherer that takes a HTML file, looks for src attributes 9 This is a small gatherer that takes a HTML file, looks for src attributes
10 and inlines the specified file, producing one HTML file with no external 10 and inlines the specified file, producing one HTML file with no external
(...skipping 11 matching lines...) Expand all
22 from grit import util 22 from grit import util
23 from grit.format import html_inline 23 from grit.format import html_inline
24 from grit.gather import interface 24 from grit.gather import interface
25 25
26 26
27 # Distribution string to replace with distribution. 27 # Distribution string to replace with distribution.
28 DIST_SUBSTR = '%DISTRIBUTION%' 28 DIST_SUBSTR = '%DISTRIBUTION%'
29 29
30 30
31 # Matches a chrome theme source URL. 31 # Matches a chrome theme source URL.
32 _THEME_SOURCE = lazy_re.compile('chrome://theme/IDR_[A-Z0-9_]*') 32 _THEME_SOURCE = lazy_re.compile(
33 '(?P<baseurl>chrome://theme/IDR_[A-Z0-9_]*)(?P<query>\?.*)?')
33 # Matches CSS image urls with the capture group 'filename'. 34 # Matches CSS image urls with the capture group 'filename'.
34 _CSS_IMAGE_URLS = lazy_re.compile( 35 _CSS_IMAGE_URLS = lazy_re.compile(
35 '(?P<attribute>content|background|[\w-]*-image):[ ]*' + 36 '(?P<attribute>content|background|[\w-]*-image):[ ]*' +
36 'url\((?P<quote>"|\'|)(?P<filename>[^"\'()]*)(?P=quote)') 37 'url\((?P<quote>"|\'|)(?P<filename>[^"\'()]*)(?P=quote)')
37 # Matches CSS image sets. 38 # Matches CSS image sets.
38 _CSS_IMAGE_SETS = lazy_re.compile( 39 _CSS_IMAGE_SETS = lazy_re.compile(
39 '(?P<attribute>content|background|[\w-]*-image):[ ]*' + 40 '(?P<attribute>content|background|[\w-]*-image):[ ]*' +
40 '-webkit-image-set\((?P<images>' + 41 '-webkit-image-set\((?P<images>' +
41 '([,\r\n ]*url\((?P<quote>"|\'|)[^"\'()]*(?P=quote)\)[ ]*[0-9.]*x)*)\)', 42 '([,\r\n ]*url\((?P<quote>"|\'|)[^"\'()]*(?P=quote)\)[ ]*[0-9.]*x)*)\)',
42 re.MULTILINE) 43 re.MULTILINE)
(...skipping 19 matching lines...) Expand all
62 filename: name of the base image file 63 filename: name of the base image file
63 scale_factors: a list of the supported scale factors (i.e. ['2x']) 64 scale_factors: a list of the supported scale factors (i.e. ['2x'])
64 distribution: string that should replace %DISTRIBUTION% 65 distribution: string that should replace %DISTRIBUTION%
65 66
66 Returns: 67 Returns:
67 array of tuples containing scale factor and image (i.e. 68 array of tuples containing scale factor and image (i.e.
68 [('1x', 'image.png'), ('2x', '2x/image.png')]). 69 [('1x', 'image.png'), ('2x', '2x/image.png')]).
69 """ 70 """
70 # Any matches for which a chrome URL handler will serve all scale factors 71 # Any matches for which a chrome URL handler will serve all scale factors
71 # can simply request all scale factors. 72 # can simply request all scale factors.
72 if _THEME_SOURCE.match(filename): 73 theme_match = _THEME_SOURCE.match(filename)
74 if theme_match:
73 images = [('1x', filename)] 75 images = [('1x', filename)]
74 for scale_factor in scale_factors: 76 for scale_factor in scale_factors:
75 images.append((scale_factor, "%s@%s" % (filename, scale_factor))) 77 scale_filename = "%s@%s" % (theme_match.group('baseurl'), scale_factor)
78 if theme_match.group('query'):
79 scale_filename += theme_match.group('query')
80 images.append((scale_factor, scale_filename))
76 return images 81 return images
77 82
78 if filename.find(':') != -1: 83 if filename.find(':') != -1:
79 # filename is probably a URL, only return filename itself. 84 # filename is probably a URL, only return filename itself.
80 return [('1x', filename)] 85 return [('1x', filename)]
81 86
82 filename = filename.replace(DIST_SUBSTR, distribution) 87 filename = filename.replace(DIST_SUBSTR, distribution)
83 if filename_expansion_function: 88 if filename_expansion_function:
84 filename = filename_expansion_function(filename) 89 filename = filename_expansion_function(filename)
85 filepath = os.path.join(base_path, filename) 90 filepath = os.path.join(base_path, filename)
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 filename_expansion_function=self.filename_expansion_function), 322 filename_expansion_function=self.filename_expansion_function),
318 filename_expansion_function=self.filename_expansion_function) 323 filename_expansion_function=self.filename_expansion_function)
319 else: 324 else:
320 distribution = html_inline.GetDistribution() 325 distribution = html_inline.GetDistribution()
321 self.inlined_text_ = ProcessImageSets( 326 self.inlined_text_ = ProcessImageSets(
322 os.path.dirname(filename), 327 os.path.dirname(filename),
323 util.ReadFile(filename, 'utf-8'), 328 util.ReadFile(filename, 'utf-8'),
324 self.scale_factors_, 329 self.scale_factors_,
325 distribution, 330 distribution,
326 filename_expansion_function=self.filename_expansion_function) 331 filename_expansion_function=self.filename_expansion_function)
OLDNEW
« no previous file with comments | « no previous file | grit/gather/chrome_html_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698