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

Side by Side Diff: chrome/common/extensions/docs/examples/api/fontSettings/popup.js

Issue 10532105: Use ICU script code "Jpan" instead of "Hrkt" in Japanese pref names (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: change in tests and comment Created 8 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 | Annotate | Revision Log
OLDNEW
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': 'Lorem ipsum Кириллица',
26 'Hang': 'Lorem ipsum 雪海泳 정 참판 양반댁 규수 큰 교자 타고 혼례 치른 날.', 26 'Hans': 'Lorem ipsum 简体字。',
27 'Hans': 'Lorem ipsum 雪海泳 简体字。', 27 'Hant': 'Lorem ipsum 繁體字。',
28 'Hant': 'Lorem ipsum 雪海泳 繁體字。', 28 'Jpan': 'Lorem ipsum バスを待ち大路の春をうたがはず。',
29 'Hrkt': 'Lorem ipsum 雪海泳 バスを待ち大路の春をうたがはず。', 29 // "Khmer language".
30 // "Khmer language".
31 'Khmr': 'Lorem ipsum \u1797\u17B6\u179F\u17B6\u1781\u17D2\u1798\u17C2\u179A', 30 'Khmr': 'Lorem ipsum \u1797\u17B6\u179F\u17B6\u1781\u17D2\u1798\u17C2\u179A',
31 'Kore': 'Lorem ipsum 정 참판 양반댁 규수 큰 교자 타고 혼례 치른 날.',
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
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 list.addEventListener('change', setEncoding); 218 list.addEventListener('change', setEncoding);
212 chrome.experimental.fontSettings.onDefaultCharacterSetChanged.addListener( 219 chrome.experimental.fontSettings.onDefaultCharacterSetChanged.addListener(
213 updateEncoding); 220 updateEncoding);
214 221
215 updateEncoding(); 222 updateEncoding();
216 } 223 }
217 224
218 function clearAllSettings() { 225 function clearAllSettings() {
219 var scripts = 226 var scripts =
220 ["Arab", "Armn", "Beng", "Cans", "Cher", "Cyrl", "Deva", "Ethi", "Geor", 227 ["Arab", "Armn", "Beng", "Cans", "Cher", "Cyrl", "Deva", "Ethi", "Geor",
221 "Grek", "Gujr", "Guru", "Hang", "Hans", "Hant", "Hebr", "Hrkt", "Knda", 228 "Grek", "Gujr", "Guru", "Hans", "Hant", "Hebr", "Jpan", "Khmr", "Knda",
222 "Khmr", "Laoo", "Mlym", "Mong", "Mymr", "Orya", "Sinh", "Taml", "Telu", 229 "Kore", "Laoo", "Mlym", "Mong", "Mymr", "Orya", "Sinh", "Taml", "Telu",
223 "Thaa", "Thai", "Tibt", "Yiii", "Zyyy"]; 230 "Thaa", "Thai", "Tibt", "Yiii", "Zyyy"];
224 var families = 231 var families =
225 ["standard", "sansserif", "serif", "fixed", "cursive", "fantasy"]; 232 ["standard", "sansserif", "serif", "fixed", "cursive", "fantasy"];
226 for (var i = 0; i < scripts.length; i++) { 233 for (var i = 0; i < scripts.length; i++) {
227 for (var j = 0; j < families.length; j++) { 234 for (var j = 0; j < families.length; j++) {
228 chrome.experimental.fontSettings.clearFont({ 235 chrome.experimental.fontSettings.clearFont({
229 script: scripts[i], 236 script: scripts[i],
230 genericFamily: families[j] 237 genericFamily: families[j]
231 }); 238 });
232 } 239 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 chrome.experimental.fontSettings.getMinimumFontSize, 276 chrome.experimental.fontSettings.getMinimumFontSize,
270 chrome.experimental.fontSettings.setMinimumFontSize, 277 chrome.experimental.fontSettings.setMinimumFontSize,
271 chrome.experimental.fontSettings.onMinimumFontSizeChanged); 278 chrome.experimental.fontSettings.onMinimumFontSizeChanged);
272 initEncoding(); 279 initEncoding();
273 280
274 var clearButton = document.getElementById('clearButton'); 281 var clearButton = document.getElementById('clearButton');
275 clearButton.addEventListener('click', clearAllSettings); 282 clearButton.addEventListener('click', clearAllSettings);
276 } 283 }
277 284
278 document.addEventListener('DOMContentLoaded', init); 285 document.addEventListener('DOMContentLoaded', init);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698