OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 /** | |
6 * @fileoverview PendingChanges class tracks changes to be applied when an | |
7 * "Apply Changes" button is clicked. | |
8 */ | |
9 | |
10 /** | |
11 * Creates a PendingChanges object with no pending changes. | |
12 * | |
13 * @constructor | |
14 */ | |
15 var PendingChanges = function() { | |
16 // Format: pendingFontChanges_.Cyrl.sansserif = "My SansSerif Cyrillic Font" | |
17 this.pendingFontChanges_ = {}; | |
18 | |
19 // Format: pendingFontSizeChanges_.defaultFontSize = 12 | |
20 this.pendingFontSizeChanges_ = {}; | |
21 } | |
yoshiki
2013/08/28 08:58:44
Add a semicolon after the bracket, since "var = fu
falken
2013/08/29 09:35:44
Done.
| |
22 | |
23 /** | |
24 * Returns the pending font setting change for the specified script and family, | |
25 * or null if it doesn't exist. | |
26 * | |
27 * @param {string} script The script code, like "Cyrl". | |
28 * @param {string} genericFamily The generic family, like "sansserif". | |
29 * @return {string} The pending font setting, like "My Cyrillic SansSerif Font", | |
yoshiki
2013/08/28 08:58:44
s/string/?string/
falken
2013/08/29 09:35:44
Done.
| |
30 * or null if it doesn't exist. | |
31 */ | |
32 PendingChanges.prototype.getFont = function(script, genericFamily) { | |
33 if (this.pendingFontChanges_[script]) | |
34 return this.pendingFontChanges_[script][genericFamily]; | |
35 return null; | |
36 } | |
37 | |
38 /** | |
39 * Returns the pending font size setting change, or null if it doesn't exist. | |
40 * | |
41 * @param {string} fontSizeKey The font size setting key. One of | |
42 * 'defaultFontSize', 'defaultFixedFontSize', or 'minFontSize'. | |
43 * @return {number} The pending font size setting in pixels, or null if it | |
yoshiki
2013/08/28 08:58:44
s/number/?number/
falken
2013/08/29 09:35:44
Done.
| |
44 * doesn't exist. | |
45 */ | |
46 PendingChanges.prototype.getFontSize = function(fontSizeKey) { | |
47 return this.pendingFontSizeChanges_[fontSizeKey]; | |
48 } | |
49 | |
50 /** | |
51 * Sets the pending font change for the specified script and family. | |
52 * | |
53 * @param {string} script The script code, like "Cyrl". | |
54 * @param {string} genericFamily The generic family, like "sansserif". | |
55 * @param {?string} font The font to set the setting to, or null to clear it. | |
56 */ | |
57 PendingChanges.prototype.setFont = function(script, genericFamily, font) { | |
58 if (!this.pendingFontChanges_[script]) | |
59 this.pendingFontChanges_[script] = {}; | |
60 if (this.pendingFontChanges_[script][genericFamily] == font) | |
61 return; | |
62 this.pendingFontChanges_[script][genericFamily] = font; | |
63 } | |
64 | |
65 /** | |
66 * Sets the pending font size change. | |
67 * | |
68 * @param {string} fontSizeKey The font size setting key. See | |
69 * getFontSize(). | |
70 * @param {number} size The font size to set the setting to. | |
71 */ | |
72 PendingChanges.prototype.setFontSize = function(fontSizeKey, size) { | |
73 if (this.pendingFontSizeChanges_[fontSizeKey] == size) | |
74 return; | |
75 this.pendingFontSizeChanges_[fontSizeKey] = size; | |
76 } | |
77 | |
78 /** | |
79 * Commits the pending changes to Chrome. After this function is called, there | |
80 * are no pending changes. | |
81 */ | |
82 PendingChanges.prototype.apply = function() { | |
83 for (script in this.pendingFontChanges_) { | |
84 for (genericFamily in this.pendingFontChanges_[script]) { | |
85 var details = {}; | |
86 details.script = script; | |
87 details.genericFamily = genericFamily; | |
88 details.fontId = this.pendingFontChanges_[script][genericFamily]; | |
89 chrome.fontSettings.setFont(details); | |
90 } | |
91 } | |
92 | |
93 var size = this.pendingFontSizeChanges_['defaultFontSize']; | |
94 if (size != null) | |
95 chrome.fontSettings.setDefaultFontSize({pixelSize: size}); | |
96 | |
97 size = this.pendingFontSizeChanges_['defaultFixedFontSize']; | |
98 if (size != null) | |
99 chrome.fontSettings.setDefaultFixedFontSize({pixelSize: size}); | |
100 | |
101 size = this.pendingFontSizeChanges_['minFontSize']; | |
102 if (size != null) | |
103 chrome.fontSettings.setMinimumFontSize({pixelSize: size}); | |
104 | |
105 this.clear(); | |
106 } | |
107 | |
108 /** | |
109 * Clears the pending font changes for a single script. | |
110 * | |
111 * @param {string} script The script code, like "Cyrl". | |
112 */ | |
113 PendingChanges.prototype.clearOneScript = function(script) { | |
114 this.pendingFontChanges_[script] = {}; | |
115 } | |
116 | |
117 /** | |
118 * Clears all pending font changes. | |
119 */ | |
120 PendingChanges.prototype.clear = function() { | |
121 this.pendingFontChanges_ = {}; | |
122 this.pendingFontSizeChanges_ = {}; | |
123 } | |
124 | |
125 /** | |
126 * @return {boolean} True if there are no pending changes, otherwise false. | |
127 */ | |
128 PendingChanges.prototype.isEmpty = function() { | |
129 for (var script in this.pendingFontChanges_) { | |
130 for (var genericFamily in this.pendingFontChanges_[script]) { | |
131 if (this.pendingFontChanges_[script][genericFamily] != null) | |
132 return false; | |
133 } | |
134 } | |
135 for (var name in this.pendingFontSizeChanges_) { | |
136 if (this.pendingFontSizeChanges_[name] != null) | |
137 return false; | |
138 } | |
139 return true; | |
140 } | |
OLD | NEW |