Index: chrome/common/extensions/docs/examples/api/fontSettings/pending_changes.js |
diff --git a/chrome/common/extensions/docs/examples/api/fontSettings/pending_changes.js b/chrome/common/extensions/docs/examples/api/fontSettings/pending_changes.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e267239f96a23d6d8cc535a2e084f73c2941ad51 |
--- /dev/null |
+++ b/chrome/common/extensions/docs/examples/api/fontSettings/pending_changes.js |
@@ -0,0 +1,130 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+/** |
+ * @fileoverview PendingChanges class tracks changes to be applied when an |
+ * "Apply Changes" button is clicked. |
+ */ |
+PendingChanges = function() { |
yoshiki
2013/08/28 02:53:35
var PendingChanges = function() {
...
or
func
yoshiki
2013/08/28 02:53:35
Add a blank line between the end of @fileoverview
yoshiki
2013/08/28 02:53:35
Write the JSdoc of the this function.
falken
2013/08/28 08:36:16
Done.
falken
2013/08/28 08:36:16
Done.
falken
2013/08/28 08:36:16
Done.
|
+ // Format: pendingFontChanges_.Cyrl.sansserif = "My SansSerif Cyrillic Font" |
+ this.pendingFontChanges_ = {}; |
+ |
+ // Format: pendingFontSizeChanges_.defaultFontSize = 12 |
+ this.pendingFontSizeChanges_ = {}; |
+} |
+ |
+/** |
+ * Returns the pending font change for the specified script and family, or null |
+ * if it doesn't exist. |
+ * |
+ * @param {string} script The script code, like "Cyrl". |
+ * @param {string} genericFamily The generic family, like "sansserif". |
yoshiki
2013/08/28 02:53:35
Add "@return" annotation.
falken
2013/08/28 08:36:16
Done.
|
+ */ |
+PendingChanges.prototype.getFont = function(script, genericFamily) { |
+ if (this.pendingFontChanges_[script]) |
+ return this.pendingFontChanges_[script][genericFamily]; |
+ return null; |
+} |
+ |
+/** |
+ * Returns the pending font size change, or null if it doesn't exist. |
+ * |
+ * @param {string} fontSizeKey The font size setting. One of |
+ * 'defaultFontSize', 'defaultFixedFontSize', or 'minFontSize'. |
yoshiki
2013/08/28 02:53:35
ditto
falken
2013/08/28 08:36:16
Done.
|
+ */ |
+PendingChanges.prototype.getFontSize = function(fontSizeKey) { |
+ return this.pendingFontSizeChanges_[fontSizeKey]; |
+} |
+ |
+/** |
+ * Sets the pending font change for the specified script and family. |
+ * |
+ * @param {string} script The script code, like "Cyrl". |
+ * @param {string} genericFamily The generic family, like "sansserif". |
+ * @param {string} font The font to set the setting to, or null to clear it. |
yoshiki
2013/08/28 02:53:35
If this parameter is a null-able string, use "?str
falken
2013/08/28 08:36:16
Done.
|
+ */ |
+PendingChanges.prototype.setFont = function(script, genericFamily, font) { |
+ if (!this.pendingFontChanges_[script]) |
+ this.pendingFontChanges_[script] = {}; |
+ if (this.pendingFontChanges_[script][genericFamily] == font) |
+ return; |
+ this.pendingFontChanges_[script][genericFamily] = font; |
+} |
+ |
+/** |
+ * Sets the pending font size change. |
+ * |
+ * @param {string} fontSizeKey The font size setting. See |
+ * getFontSize(). |
+ * @param {number} size The font size to set the setting to. |
+ */ |
+PendingChanges.prototype.setFontSize = function(fontSizeKey, size) { |
+ if (this.pendingFontSizeChanges_[fontSizeKey] == size) |
+ return; |
+ this.pendingFontSizeChanges_[fontSizeKey] = size; |
+} |
+ |
+/** |
+ * Commits the pending changes to Chrome. After this function is called, there |
+ * are no pending changes. |
+ */ |
+PendingChanges.prototype.apply = function() { |
+ for (script in this.pendingFontChanges_) { |
+ for (genericFamily in this.pendingFontChanges_[script]) { |
+ var details = {}; |
+ details.script = script; |
+ details.genericFamily = genericFamily; |
+ details.fontId = this.pendingFontChanges_[script][genericFamily]; |
+ chrome.fontSettings.setFont(details); |
+ } |
+ } |
+ |
+ var size = this.pendingFontSizeChanges_['defaultFontSize']; |
+ if (size != null) |
+ chrome.fontSettings.setDefaultFontSize( { pixelSize: size }); |
yoshiki
2013/08/28 02:53:35
chrome.fontSettings.setDefaultFontSize({pixelSize:
falken
2013/08/28 08:36:16
Done.
|
+ |
+ size = this.pendingFontSizeChanges_['defaultFixedFontSize']; |
+ if (size != null) |
+ chrome.fontSettings.setDefaultFixedFontSize( { pixelSize: size }); |
yoshiki
2013/08/28 02:53:35
ditto
falken
2013/08/28 08:36:16
Done.
|
+ |
+ size = this.pendingFontSizeChanges_['minFontSize']; |
+ if (size != null) |
+ chrome.fontSettings.setMinimumFontSize( { pixelSize: size }); |
yoshiki
2013/08/28 02:53:35
ditto
falken
2013/08/28 08:36:16
Done.
|
+ |
+ this.clear(); |
+} |
+ |
+/** |
+ * Clears the pending font changes for a single script. |
+ * |
+ * @param {string} script The script code, like "Cyrl". |
+ */ |
+PendingChanges.prototype.clearOneScript = function(script) { |
+ this.pendingFontChanges_[script] = {}; |
+} |
+ |
+/** |
+ * Clears all pending font changes. |
+ */ |
+PendingChanges.prototype.clear = function() { |
+ this.pendingFontChanges_ = {}; |
+ this.pendingFontSizeChanges_ = {}; |
+} |
+ |
+/** |
+ * Returns true if there are no pending font changes, otherwise, false. |
+ */ |
+PendingChanges.prototype.isEmpty = function() { |
+ for (var script in this.pendingFontChanges_) { |
+ for (var genericFamily in this.pendingFontChanges_[script]) { |
+ if (this.pendingFontChanges_[script][genericFamily] != null) |
+ return false; |
+ } |
+ } |
+ for (var name in this.pendingFontSizeChanges_) { |
+ if (this.pendingFontSizeChanges_[name] != null) |
+ return false; |
+ } |
+ return true; |
+} |