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

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

Issue 23434003: UI refresh of Advanced Font Settings Extension (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: keep original name Created 7 years, 3 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
(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 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.
10 // Format: pendingFontChanges_.Cyrl.sansserif = "My SansSerif Cyrillic Font"
11 this.pendingFontChanges_ = {};
12
13 // Format: pendingFontSizeChanges_.defaultFontSize = 12
14 this.pendingFontSizeChanges_ = {};
15 }
16
17 /**
18 * Returns the pending font change for the specified script and family, or null
19 * if it doesn't exist.
20 *
21 * @param {string} script The script code, like "Cyrl".
22 * @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.
23 */
24 PendingChanges.prototype.getFont = function(script, genericFamily) {
25 if (this.pendingFontChanges_[script])
26 return this.pendingFontChanges_[script][genericFamily];
27 return null;
28 }
29
30 /**
31 * Returns the pending font size change, or null if it doesn't exist.
32 *
33 * @param {string} fontSizeKey The font size setting. One of
34 * 'defaultFontSize', 'defaultFixedFontSize', or 'minFontSize'.
yoshiki 2013/08/28 02:53:35 ditto
falken 2013/08/28 08:36:16 Done.
35 */
36 PendingChanges.prototype.getFontSize = function(fontSizeKey) {
37 return this.pendingFontSizeChanges_[fontSizeKey];
38 }
39
40 /**
41 * Sets the pending font change for the specified script and family.
42 *
43 * @param {string} script The script code, like "Cyrl".
44 * @param {string} genericFamily The generic family, like "sansserif".
45 * @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.
46 */
47 PendingChanges.prototype.setFont = function(script, genericFamily, font) {
48 if (!this.pendingFontChanges_[script])
49 this.pendingFontChanges_[script] = {};
50 if (this.pendingFontChanges_[script][genericFamily] == font)
51 return;
52 this.pendingFontChanges_[script][genericFamily] = font;
53 }
54
55 /**
56 * Sets the pending font size change.
57 *
58 * @param {string} fontSizeKey The font size setting. See
59 * getFontSize().
60 * @param {number} size The font size to set the setting to.
61 */
62 PendingChanges.prototype.setFontSize = function(fontSizeKey, size) {
63 if (this.pendingFontSizeChanges_[fontSizeKey] == size)
64 return;
65 this.pendingFontSizeChanges_[fontSizeKey] = size;
66 }
67
68 /**
69 * Commits the pending changes to Chrome. After this function is called, there
70 * are no pending changes.
71 */
72 PendingChanges.prototype.apply = function() {
73 for (script in this.pendingFontChanges_) {
74 for (genericFamily in this.pendingFontChanges_[script]) {
75 var details = {};
76 details.script = script;
77 details.genericFamily = genericFamily;
78 details.fontId = this.pendingFontChanges_[script][genericFamily];
79 chrome.fontSettings.setFont(details);
80 }
81 }
82
83 var size = this.pendingFontSizeChanges_['defaultFontSize'];
84 if (size != null)
85 chrome.fontSettings.setDefaultFontSize( { pixelSize: size });
yoshiki 2013/08/28 02:53:35 chrome.fontSettings.setDefaultFontSize({pixelSize:
falken 2013/08/28 08:36:16 Done.
86
87 size = this.pendingFontSizeChanges_['defaultFixedFontSize'];
88 if (size != null)
89 chrome.fontSettings.setDefaultFixedFontSize( { pixelSize: size });
yoshiki 2013/08/28 02:53:35 ditto
falken 2013/08/28 08:36:16 Done.
90
91 size = this.pendingFontSizeChanges_['minFontSize'];
92 if (size != null)
93 chrome.fontSettings.setMinimumFontSize( { pixelSize: size });
yoshiki 2013/08/28 02:53:35 ditto
falken 2013/08/28 08:36:16 Done.
94
95 this.clear();
96 }
97
98 /**
99 * Clears the pending font changes for a single script.
100 *
101 * @param {string} script The script code, like "Cyrl".
102 */
103 PendingChanges.prototype.clearOneScript = function(script) {
104 this.pendingFontChanges_[script] = {};
105 }
106
107 /**
108 * Clears all pending font changes.
109 */
110 PendingChanges.prototype.clear = function() {
111 this.pendingFontChanges_ = {};
112 this.pendingFontSizeChanges_ = {};
113 }
114
115 /**
116 * Returns true if there are no pending font changes, otherwise, false.
117 */
118 PendingChanges.prototype.isEmpty = function() {
119 for (var script in this.pendingFontChanges_) {
120 for (var genericFamily in this.pendingFontChanges_[script]) {
121 if (this.pendingFontChanges_[script][genericFamily] != null)
122 return false;
123 }
124 }
125 for (var name in this.pendingFontSizeChanges_) {
126 if (this.pendingFontSizeChanges_[name] != null)
127 return false;
128 }
129 return true;
130 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698