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

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: 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 | no next file » | 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 12 matching lines...) Expand all
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('chrome://theme/IDR_[A-Z0-9_]*')
33 # Matches a chrome theme source URL with "?".
34 _THEME_SOURCE_WITH_QUESTIONMARK = lazy_re.compile('chrome://theme/IDR_[A-Z0-9_]* \?')
flackr 2013/06/12 01:05:44 You should use matching groups in the regex to get
sschmitz 2013/06/12 18:00:14 Done.
33 # Matches CSS image urls with the capture group 'filename'. 35 # Matches CSS image urls with the capture group 'filename'.
34 _CSS_IMAGE_URLS = lazy_re.compile( 36 _CSS_IMAGE_URLS = lazy_re.compile(
35 '(?P<attribute>content|background|[\w-]*-image):[ ]*' + 37 '(?P<attribute>content|background|[\w-]*-image):[ ]*' +
36 'url\((?P<quote>"|\'|)(?P<filename>[^"\'()]*)(?P=quote)') 38 'url\((?P<quote>"|\'|)(?P<filename>[^"\'()]*)(?P=quote)')
37 # Matches CSS image sets. 39 # Matches CSS image sets.
38 _CSS_IMAGE_SETS = lazy_re.compile( 40 _CSS_IMAGE_SETS = lazy_re.compile(
39 '(?P<attribute>content|background|[\w-]*-image):[ ]*' + 41 '(?P<attribute>content|background|[\w-]*-image):[ ]*' +
40 '-webkit-image-set\((?P<images>' + 42 '-webkit-image-set\((?P<images>' +
41 '([,\r\n ]*url\((?P<quote>"|\'|)[^"\'()]*(?P=quote)\)[ ]*[0-9.]*x)*)\)', 43 '([,\r\n ]*url\((?P<quote>"|\'|)[^"\'()]*(?P=quote)\)[ ]*[0-9.]*x)*)\)',
42 re.MULTILINE) 44 re.MULTILINE)
(...skipping 21 matching lines...) Expand all
64 distribution: string that should replace %DISTRIBUTION% 66 distribution: string that should replace %DISTRIBUTION%
65 67
66 Returns: 68 Returns:
67 array of tuples containing scale factor and image (i.e. 69 array of tuples containing scale factor and image (i.e.
68 [('1x', 'image.png'), ('2x', '2x/image.png')]). 70 [('1x', 'image.png'), ('2x', '2x/image.png')]).
69 """ 71 """
70 # Any matches for which a chrome URL handler will serve all scale factors 72 # Any matches for which a chrome URL handler will serve all scale factors
71 # can simply request all scale factors. 73 # can simply request all scale factors.
72 if _THEME_SOURCE.match(filename): 74 if _THEME_SOURCE.match(filename):
73 images = [('1x', filename)] 75 images = [('1x', filename)]
76 # If the URL contains a question mark, insert the scale factor text
77 # before it.
78 if _THEME_SOURCE_WITH_QUESTIONMARK.match(filename):
79 fnparts = re.split('\?', filename)
80 for scale_factor in scale_factors:
81 fnscaled = fnparts[0]+'@'+scale_factor+'?'+('?'.join(fnparts[1:]))
82 images.append((scale_factor, fnscaled))
83 return images
84 # If the URL does not contain a question mark, append the scale factor
85 # text.
74 for scale_factor in scale_factors: 86 for scale_factor in scale_factors:
75 images.append((scale_factor, "%s@%s" % (filename, scale_factor))) 87 images.append((scale_factor, "%s@%s" % (filename, scale_factor)))
76 return images 88 return images
77 89
78 if filename.find(':') != -1: 90 if filename.find(':') != -1:
79 # filename is probably a URL, only return filename itself. 91 # filename is probably a URL, only return filename itself.
80 return [('1x', filename)] 92 return [('1x', filename)]
81 93
82 filename = filename.replace(DIST_SUBSTR, distribution) 94 filename = filename.replace(DIST_SUBSTR, distribution)
83 if filename_expansion_function: 95 if filename_expansion_function:
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 filename_expansion_function=self.filename_expansion_function), 329 filename_expansion_function=self.filename_expansion_function),
318 filename_expansion_function=self.filename_expansion_function) 330 filename_expansion_function=self.filename_expansion_function)
319 else: 331 else:
320 distribution = html_inline.GetDistribution() 332 distribution = html_inline.GetDistribution()
321 self.inlined_text_ = ProcessImageSets( 333 self.inlined_text_ = ProcessImageSets(
322 os.path.dirname(filename), 334 os.path.dirname(filename),
323 util.ReadFile(filename, 'utf-8'), 335 util.ReadFile(filename, 'utf-8'),
324 self.scale_factors_, 336 self.scale_factors_,
325 distribution, 337 distribution,
326 filename_expansion_function=self.filename_expansion_function) 338 filename_expansion_function=self.filename_expansion_function)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698