OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Mapping between font list ids and the generic family setting they | 5 // Mapping between font list ids and the generic family setting they |
6 // represent. | 6 // represent. |
7 var genericFamilies = [ | 7 var genericFamilies = [ |
8 { fontList: 'standardFontList', name: 'standard' }, | 8 { fontList: 'standardFontList', name: 'standard' }, |
9 { fontList: 'serifFontList', name: 'serif' }, | 9 { fontList: 'serifFontList', name: 'serif' }, |
10 { fontList: 'sansSerifFontList', name: 'sansserif' }, | 10 { fontList: 'sansSerifFontList', name: 'sansserif' }, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 // Add special "(none)" item to indicate fallback to the non-per-script | 48 // Add special "(none)" item to indicate fallback to the non-per-script |
49 // font setting. The Font Settings API uses the empty string to indicate | 49 // font setting. The Font Settings API uses the empty string to indicate |
50 // fallback. | 50 // fallback. |
51 var noneItem = document.createElement('option'); | 51 var noneItem = document.createElement('option'); |
52 noneItem.value = ''; | 52 noneItem.value = ''; |
53 noneItem.text = '(none)'; | 53 noneItem.text = '(none)'; |
54 list.add(noneItem); | 54 list.add(noneItem); |
55 | 55 |
56 for (var j = 0; j < fonts.length; j++) { | 56 for (var j = 0; j < fonts.length; j++) { |
57 var item = document.createElement('option'); | 57 var item = document.createElement('option'); |
58 item.value = fonts[j].fontName; | 58 item.value = fonts[j].fontId; |
59 item.text = fonts[j].localizedName; | 59 item.text = fonts[j].displayName; |
60 list.add(item); | 60 list.add(item); |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 updateFontListsForScript(); | 64 updateFontListsForScript(); |
65 } | 65 } |
66 | 66 |
67 // Returns a function that updates the font setting for |genericFamily| | 67 // Returns a function that updates the font setting for |genericFamily| |
68 // to match the selected value in |fontList|. It can be used as an event | 68 // to match the selected value in |fontList|. It can be used as an event |
69 // handler for selection changes in |fontList|. | 69 // handler for selection changes in |fontList|. |
70 function getFontChangeHandler(fontList, genericFamily) { | 70 function getFontChangeHandler(fontList, genericFamily) { |
71 return function() { | 71 return function() { |
72 var script = getSelectedScript(); | 72 var script = getSelectedScript(); |
73 var font = getSelectedFont(fontList); | 73 var font = getSelectedFont(fontList); |
74 | 74 |
75 var details = {}; | 75 var details = {}; |
76 details.genericFamily = genericFamily; | 76 details.genericFamily = genericFamily; |
77 details.fontName = font; | 77 details.fontId = font; |
78 details.script = script; | 78 details.script = script; |
79 | 79 |
80 chrome.experimental.fontSettings.setFont(details); | 80 chrome.experimental.fontSettings.setFont(details); |
81 }; | 81 }; |
82 } | 82 } |
83 | 83 |
84 // Sets the selected value of |fontList| to |fontName|. | 84 // Sets the selected value of |fontList| to |fontId|. |
85 function setSelectedFont(fontList, fontName) { | 85 function setSelectedFont(fontList, fontId) { |
86 var script = getSelectedScript(); | 86 var script = getSelectedScript(); |
87 var i; | 87 var i; |
88 for (i = 0; i < fontList.length; i++) { | 88 for (i = 0; i < fontList.length; i++) { |
89 if (fontName == fontList.options[i].value) { | 89 if (fontId == fontList.options[i].value) { |
90 fontList.selectedIndex = i; | 90 fontList.selectedIndex = i; |
91 break; | 91 break; |
92 } | 92 } |
93 } | 93 } |
94 if (i == fontList.length) { | 94 if (i == fontList.length) { |
95 console.warn("font '" + fontName + "' for " + fontList.id + ' for ' + | 95 console.warn("font '" + fontId + "' for " + fontList.id + ' for ' + |
96 script + ' is not on the system'); | 96 script + ' is not on the system'); |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 // Returns a callback function that sets the selected value of |list| to the | 100 // Returns a callback function that sets the selected value of |list| to the |
101 // font returned from |chrome.experimental.fontSettings.getFont|. | 101 // font returned from |chrome.experimental.fontSettings.getFont|. |
102 function getFontHandler(list) { | 102 function getFontHandler(list) { |
103 return function(details) { | 103 return function(details) { |
104 setSelectedFont(list, details.fontName); | 104 setSelectedFont(list, details.fontId); |
105 list.disabled = !isControllableLevel(details.levelOfControl); | 105 list.disabled = !isControllableLevel(details.levelOfControl); |
106 }; | 106 }; |
107 } | 107 } |
108 | 108 |
109 // Called when the script list selection changes. Sets the selected value of | 109 // Called when the script list selection changes. Sets the selected value of |
110 // each font list to the current font setting, and updates the document's lang | 110 // each font list to the current font setting, and updates the document's lang |
111 // so that the samples are shown in the current font setting. | 111 // so that the samples are shown in the current font setting. |
112 function updateFontListsForScript() { | 112 function updateFontListsForScript() { |
113 var script = getSelectedScript(); | 113 var script = getSelectedScript(); |
114 | 114 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 initFontSizePref('minFontSize', | 240 initFontSizePref('minFontSize', |
241 chrome.experimental.fontSettings.getMinimumFontSize, | 241 chrome.experimental.fontSettings.getMinimumFontSize, |
242 chrome.experimental.fontSettings.setMinimumFontSize, | 242 chrome.experimental.fontSettings.setMinimumFontSize, |
243 chrome.experimental.fontSettings.onMinimumFontSizeChanged); | 243 chrome.experimental.fontSettings.onMinimumFontSizeChanged); |
244 | 244 |
245 var clearButton = document.getElementById('clearButton'); | 245 var clearButton = document.getElementById('clearButton'); |
246 clearButton.addEventListener('click', clearAllSettings); | 246 clearButton.addEventListener('click', clearAllSettings); |
247 } | 247 } |
248 | 248 |
249 document.addEventListener('DOMContentLoaded', init); | 249 document.addEventListener('DOMContentLoaded', init); |
OLD | NEW |