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 var scriptList; | 5 var scriptList; |
6 | 6 |
7 // Mapping between font list ids and the generic family setting they | 7 // Mapping between font list ids and the generic family setting they |
8 // represent. | 8 // represent. |
9 var genericFamilies = [ | 9 var genericFamilies = [ |
10 { fontList: 'standardFontList', name: 'standard' }, | 10 { fontList: 'standardFontList', name: 'standard' }, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 return function() { | 54 return function() { |
55 var script = getSelectedScript(); | 55 var script = getSelectedScript(); |
56 var font = getSelectedFont(fontList); | 56 var font = getSelectedFont(fontList); |
57 | 57 |
58 var details = {}; | 58 var details = {}; |
59 details.genericFamily = genericFamily; | 59 details.genericFamily = genericFamily; |
60 details.fontName = font; | 60 details.fontName = font; |
61 if (script != DEFAULT_SCRIPT) | 61 if (script != DEFAULT_SCRIPT) |
62 details.script = script; | 62 details.script = script; |
63 | 63 |
64 chrome.experimental.fontSettings.setFontName(details); | 64 chrome.experimental.fontSettings.setFont(details); |
65 }; | 65 }; |
66 } | 66 } |
67 | 67 |
68 // Sets the selected value of |fontList| to |fontName|. | 68 // Sets the selected value of |fontList| to |fontName|. |
69 function setSelectedFont(fontList, fontName) { | 69 function setSelectedFont(fontList, fontName) { |
70 var script = getSelectedScript(); | 70 var script = getSelectedScript(); |
71 | 71 |
72 for (var i = 0; i < fontList.length; i++) { | 72 for (var i = 0; i < fontList.length; i++) { |
73 if (fontName == fontList.options[i].value) { | 73 if (fontName == fontList.options[i].value) { |
74 fontList.selectedIndex = i; | 74 fontList.selectedIndex = i; |
75 break; | 75 break; |
76 } | 76 } |
77 } | 77 } |
78 if (i == fontList.length) { | 78 if (i == fontList.length) { |
79 console.warn("font '" + fontName + "' for " + fontList.id + ' for ' + | 79 console.warn("font '" + fontName + "' for " + fontList.id + ' for ' + |
80 script + ' is not on the system'); | 80 script + ' is not on the system'); |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 // Returns a callback function that sets the selected value of |list| to the | 84 // Returns a callback function that sets the selected value of |list| to the |
85 // font returned from |chrome.experimental.fontSettings.getFontName|. | 85 // font returned from |chrome.experimental.fontSettings.getFont|. |
86 function getFontNameHandler(list) { | 86 function getFontHandler(list) { |
87 return function(details) { | 87 return function(details) { |
88 setSelectedFont(list, details.fontName); | 88 setSelectedFont(list, details.fontName); |
89 }; | 89 }; |
90 } | 90 } |
91 | 91 |
92 // Sets the selected value of each font list to the current font setting. | 92 // Sets the selected value of each font list to the current font setting. |
93 function updateListSelections() { | 93 function updateListSelections() { |
94 var script = getSelectedScript(); | 94 var script = getSelectedScript(); |
95 | 95 |
96 for (var i = 0; i < genericFamilies.length; i++) { | 96 for (var i = 0; i < genericFamilies.length; i++) { |
97 var list = document.getElementById(genericFamilies[i].fontList); | 97 var list = document.getElementById(genericFamilies[i].fontList); |
98 var family = genericFamilies[i].name; | 98 var family = genericFamilies[i].name; |
99 | 99 |
100 var details = {}; | 100 var details = {}; |
101 details.genericFamily = family; | 101 details.genericFamily = family; |
102 if (script != DEFAULT_SCRIPT) | 102 if (script != DEFAULT_SCRIPT) |
103 details.script = script; | 103 details.script = script; |
104 | 104 |
105 chrome.experimental.fontSettings.getFontName(details, | 105 chrome.experimental.fontSettings.getFont(details, |
106 getFontNameHandler(list)); | 106 getFontHandler(list)); |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 function defaultFontSizeChanged() { | 110 function defaultFontSizeChanged() { |
111 var defaultFontSizeInput = document.getElementById('defaultFontSize'); | 111 var defaultFontSizeInput = document.getElementById('defaultFontSize'); |
112 var pixelSize = parseInt(defaultFontSizeInput.value); | 112 var pixelSize = parseInt(defaultFontSizeInput.value); |
113 if (!isNaN(pixelSize)) { | 113 if (!isNaN(pixelSize)) { |
114 chrome.experimental.fontSettings.setDefaultFontSize({ | 114 chrome.experimental.fontSettings.setDefaultFontSize({ |
115 pixelSize: pixelSize | 115 pixelSize: pixelSize |
116 }); | 116 }); |
(...skipping 15 matching lines...) Expand all Loading... |
132 } | 132 } |
133 | 133 |
134 var defaultFontSizeInput = document.getElementById('defaultFontSize'); | 134 var defaultFontSizeInput = document.getElementById('defaultFontSize'); |
135 chrome.experimental.fontSettings.getDefaultFontSize({}, function(details) { | 135 chrome.experimental.fontSettings.getDefaultFontSize({}, function(details) { |
136 defaultFontSizeInput.value = details.pixelSize; | 136 defaultFontSizeInput.value = details.pixelSize; |
137 }); | 137 }); |
138 defaultFontSizeInput.addEventListener('change', defaultFontSizeChanged); | 138 defaultFontSizeInput.addEventListener('change', defaultFontSizeChanged); |
139 } | 139 } |
140 | 140 |
141 document.addEventListener('DOMContentLoaded', init); | 141 document.addEventListener('DOMContentLoaded', init); |
OLD | NEW |