| 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' }, |
| 11 { fontList: 'fixedFontList', name: 'fixed' } | 11 { fontList: 'fixedFontList', name: 'fixed' } |
| 12 ]; | 12 ]; |
| 13 | 13 |
| 14 // Ids of elements to contain the "Lorem ipsum" sample text. | 14 // Ids of elements to contain the "Lorem ipsum" sample text. |
| 15 var sampleTextDivIds = [ | 15 var sampleTextDivIds = [ |
| 16 'standardFontSample', | 16 'standardFontSample', |
| 17 'serifFontSample', | 17 'serifFontSample', |
| 18 'sansSerifFontSample', | 18 'sansSerifFontSample', |
| 19 'fixedFontSample' | 19 'fixedFontSample' |
| 20 ]; | 20 ]; |
| 21 | 21 |
| 22 var defaultSampleText = 'Lorem ipsum dolor sit amat.'; | 22 var defaultSampleText = 'Lorem ipsum dolor sit amat.'; |
| 23 var scriptSpecificSampleText = { | 23 var scriptSpecificSampleText = { |
| 24 // "Cyrllic script". | 24 // "Cyrllic script". |
| 25 'Cyrl': 'Lorem ipsum Кириллица', | 25 'Cyrl': 'Кириллица', |
| 26 'Hang': 'Lorem ipsum 雪海泳 정 참판 양반댁 규수 큰 교자 타고 혼례 치른 날.', | 26 'Hans': '床前明月光,疑是地上霜。举头望明月,低头思故乡。', |
| 27 'Hans': 'Lorem ipsum 雪海泳 简体字。', | 27 'Hant': '床前明月光,疑是地上霜。舉頭望明月,低頭思故鄉。', |
| 28 'Hant': 'Lorem ipsum 雪海泳 繁體字。', | 28 'Jpan': '吾輩は猫である。名前はまだ無い。', |
| 29 'Hrkt': 'Lorem ipsum 雪海泳 バスを待ち大路の春をうたがはず。', | 29 // "Khmer language". |
| 30 // "Khmer language". | 30 'Khmr': '\u1797\u17B6\u179F\u17B6\u1781\u17D2\u1798\u17C2\u179A', |
| 31 'Khmr': 'Lorem ipsum \u1797\u17B6\u179F\u17B6\u1781\u17D2\u1798\u17C2\u179A', | 31 'Kore': '정 참판 양반댁 규수 큰 교자 타고 혼례 치른 날.', |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 function getSelectedScript() { | 34 function getSelectedScript() { |
| 35 var scriptList = document.getElementById('scriptList'); | 35 var scriptList = document.getElementById('scriptList'); |
| 36 return scriptList.options[scriptList.selectedIndex].value; | 36 return scriptList.options[scriptList.selectedIndex].value; |
| 37 } | 37 } |
| 38 | 38 |
| 39 function getSelectedFont(fontList) { | 39 function getSelectedFont(fontList) { |
| 40 return fontList.options[fontList.selectedIndex].value; | 40 return fontList.options[fontList.selectedIndex].value; |
| 41 } | 41 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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.fontName); |
| 105 list.disabled = !isControllableLevel(details.levelOfControl); | 105 list.disabled = !isControllableLevel(details.levelOfControl); |
| 106 }; | 106 }; |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Temporary workaround for https://bugs.webkit.org/show_bug.cgi?id=88845. |
| 110 function getScriptUsedByWebKit(script) { |
| 111 if (script == 'Jpan') return 'Hrkt'; |
| 112 if (script == 'Kore') return 'Hang'; |
| 113 return script; |
| 114 } |
| 115 |
| 109 // Called when the script list selection changes. Sets the selected value of | 116 // 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 | 117 // 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. | 118 // so that the samples are shown in the current font setting. |
| 112 function updateFontListsForScript() { | 119 function updateFontListsForScript() { |
| 113 var script = getSelectedScript(); | 120 var script = getSelectedScript(); |
| 114 | 121 |
| 115 for (var i = 0; i < genericFamilies.length; i++) { | 122 for (var i = 0; i < genericFamilies.length; i++) { |
| 116 var list = document.getElementById(genericFamilies[i].fontList); | 123 var list = document.getElementById(genericFamilies[i].fontList); |
| 117 var family = genericFamilies[i].name; | 124 var family = genericFamilies[i].name; |
| 118 | 125 |
| 119 var details = {}; | 126 var details = {}; |
| 120 details.genericFamily = family; | 127 details.genericFamily = family; |
| 121 details.script = script; | 128 details.script = script; |
| 122 // For font selection it's the script code that matters, not language, so | 129 // For font selection it's the script code that matters, not language, so |
| 123 // just use en for lang. | 130 // just use en for lang. |
| 124 document.body.lang = 'en-' + script; | 131 document.body.lang = 'en-' + getScriptUsedByWebKit(script); |
| 125 | 132 |
| 126 chrome.experimental.fontSettings.getFont(details, getFontHandler(list)); | 133 chrome.experimental.fontSettings.getFont(details, getFontHandler(list)); |
| 127 } | 134 } |
| 128 | 135 |
| 129 if (typeof(scriptSpecificSampleText[script]) != 'undefined') | 136 if (typeof(scriptSpecificSampleText[script]) != 'undefined') |
| 130 sample = scriptSpecificSampleText[script]; | 137 sample = scriptSpecificSampleText[script]; |
| 131 else | 138 else |
| 132 sample = defaultSampleText; | 139 sample = defaultSampleText; |
| 133 for (var i = 0; i < sampleTextDivIds.length; i++) { | 140 for (var i = 0; i < sampleTextDivIds.length; i++) { |
| 134 document.getElementById(sampleTextDivIds[i]).innerText = sample; | 141 document.getElementById(sampleTextDivIds[i]).innerText = sample; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 elem.addEventListener('change', getFontSizeChangedFunc(elem, setter)); | 181 elem.addEventListener('change', getFontSizeChangedFunc(elem, setter)); |
| 175 apiEvent.addListener(getFontSizeChangedOnBrowserFunc(elem)); | 182 apiEvent.addListener(getFontSizeChangedOnBrowserFunc(elem)); |
| 176 } | 183 } |
| 177 | 184 |
| 178 function clearAllSettings() { | 185 function clearAllSettings() { |
| 179 var scripts = | 186 var scripts = |
| 180 ["Afak", "Arab", "Armi", "Armn", "Avst", "Bali", "Bamu", "Bass", "Batk", | 187 ["Afak", "Arab", "Armi", "Armn", "Avst", "Bali", "Bamu", "Bass", "Batk", |
| 181 "Beng", "Blis", "Bopo", "Brah", "Brai", "Bugi", "Buhd", "Cakm", "Cans", | 188 "Beng", "Blis", "Bopo", "Brah", "Brai", "Bugi", "Buhd", "Cakm", "Cans", |
| 182 "Cari", "Cham", "Cher", "Cirt", "Copt", "Cprt", "Cyrl", "Cyrs", "Deva", | 189 "Cari", "Cham", "Cher", "Cirt", "Copt", "Cprt", "Cyrl", "Cyrs", "Deva", |
| 183 "Dsrt", "Dupl", "Egyd", "Egyh", "Egyp", "Elba", "Ethi", "Geor", "Geok", | 190 "Dsrt", "Dupl", "Egyd", "Egyh", "Egyp", "Elba", "Ethi", "Geor", "Geok", |
| 184 "Glag", "Goth", "Gran", "Grek", "Gujr", "Guru", "Hang", "Hani", "Hano", | 191 "Glag", "Goth", "Gran", "Grek", "Gujr", "Guru", "Hani", "Hano", "Hans", |
| 185 "Hans", "Hant", "Hebr", "Hluw", "Hmng", "Hrkt", "Hung", "Inds", "Ital", | 192 "Hant", "Hebr", "Hluw", "Hmng", "Hung", "Inds", "Ital", "Java", "Jpan", |
| 186 "Java", "Jurc", "Kali", "Khar", "Khmr", "Khoj", "Knda", "Kpel", "Kthi", | 193 "Jurc", "Kali", "Khar", "Khmr", "Khoj", "Knda", "Kore", "Kpel", "Kthi", |
| 187 "Lana", "Laoo", "Latf", "Latg", "Latn", "Lepc", "Limb", "Lina", "Linb", | 194 "Lana", "Laoo", "Latf", "Latg", "Latn", "Lepc", "Limb", "Lina", "Linb", |
| 188 "Lisu", "Loma", "Lyci", "Lydi", "Mand", "Mani", "Maya", "Mend", "Merc", | 195 "Lisu", "Loma", "Lyci", "Lydi", "Mand", "Mani", "Maya", "Mend", "Merc", |
| 189 "Mero", "Mlym", "Moon", "Mong", "Mroo", "Mtei", "Mymr", "Narb", "Nbat", | 196 "Mero", "Mlym", "Moon", "Mong", "Mroo", "Mtei", "Mymr", "Narb", "Nbat", |
| 190 "Nkgb", "Nkoo", "Nshu", "Ogam", "Olck", "Orkh", "Orya", "Osma", "Palm", | 197 "Nkgb", "Nkoo", "Nshu", "Ogam", "Olck", "Orkh", "Orya", "Osma", "Palm", |
| 191 "Perm", "Phag", "Phli", "Phlp", "Phlv", "Phnx", "Plrd", "Prti", "Rjng", | 198 "Perm", "Phag", "Phli", "Phlp", "Phlv", "Phnx", "Plrd", "Prti", "Rjng", |
| 192 "Roro", "Runr", "Samr", "Sara", "Sarb", "Saur", "Sgnw", "Shaw", "Shrd", | 199 "Roro", "Runr", "Samr", "Sara", "Sarb", "Saur", "Sgnw", "Shaw", "Shrd", |
| 193 "Sind", "Sinh", "Sora", "Sund", "Sylo", "Syrc", "Syre", "Syrj", "Syrn", | 200 "Sind", "Sinh", "Sora", "Sund", "Sylo", "Syrc", "Syre", "Syrj", "Syrn", |
| 194 "Tagb", "Takr", "Tale", "Talu", "Taml", "Tang", "Tavt", "Telu", "Teng", | 201 "Tagb", "Takr", "Tale", "Talu", "Taml", "Tang", "Tavt", "Telu", "Teng", |
| 195 "Tfng", "Tglg", "Thaa", "Thai", "Tibt", "Tirh", "Ugar", "Vaii", "Visp", | 202 "Tfng", "Tglg", "Thaa", "Thai", "Tibt", "Tirh", "Ugar", "Vaii", "Visp", |
| 196 "Wara", "Wole", "Xpeo", "Xsux", "Yiii", "Zmth", "Zsym", "Zyyy"]; | 203 "Wara", "Wole", "Xpeo", "Xsux", "Yiii", "Zmth", "Zsym", "Zyyy"]; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 initFontSizePref('minFontSize', | 247 initFontSizePref('minFontSize', |
| 241 chrome.experimental.fontSettings.getMinimumFontSize, | 248 chrome.experimental.fontSettings.getMinimumFontSize, |
| 242 chrome.experimental.fontSettings.setMinimumFontSize, | 249 chrome.experimental.fontSettings.setMinimumFontSize, |
| 243 chrome.experimental.fontSettings.onMinimumFontSizeChanged); | 250 chrome.experimental.fontSettings.onMinimumFontSizeChanged); |
| 244 | 251 |
| 245 var clearButton = document.getElementById('clearButton'); | 252 var clearButton = document.getElementById('clearButton'); |
| 246 clearButton.addEventListener('click', clearAllSettings); | 253 clearButton.addEventListener('click', clearAllSettings); |
| 247 } | 254 } |
| 248 | 255 |
| 249 document.addEventListener('DOMContentLoaded', init); | 256 document.addEventListener('DOMContentLoaded', init); |
| OLD | NEW |