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

Side by Side Diff: third_party/google_input_tools/src/chrome/os/inputview/featuretracker.js

Issue 1257313003: Update Google Input Tools (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Free up grd resources. Created 5 years, 4 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
OLDNEW
1 // Copyright 2015 The ChromeOS IME Authors. All Rights Reserved. 1 // Copyright 2015 The ChromeOS IME Authors. All Rights Reserved.
2 // limitations under the License. 2 // limitations under the License.
3 // See the License for the specific language governing permissions and 3 // See the License for the specific language governing permissions and
4 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 4 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5 // distributed under the License is distributed on an "AS-IS" BASIS, 5 // distributed under the License is distributed on an "AS-IS" BASIS,
6 // Unless required by applicable law or agreed to in writing, software 6 // Unless required by applicable law or agreed to in writing, software
7 // 7 //
8 // http://www.apache.org/licenses/LICENSE-2.0 8 // http://www.apache.org/licenses/LICENSE-2.0
9 // 9 //
10 // You may obtain a copy of the License at 10 // You may obtain a copy of the License at
11 // you may not use this file except in compliance with the License. 11 // you may not use this file except in compliance with the License.
12 // Licensed under the Apache License, Version 2.0 (the "License"); 12 // Licensed under the Apache License, Version 2.0 (the "License");
13 // 13 //
14 goog.provide('i18n.input.chrome.inputview.FeatureTracker'); 14 goog.provide('i18n.input.chrome.inputview.FeatureTracker');
15 15
16 goog.require('goog.object'); 16 goog.require('goog.object');
17 goog.require('i18n.input.chrome.inputview.FeatureName'); 17 goog.require('i18n.input.chrome.inputview.FeatureName');
18 18
19 goog.scope(function() { 19 goog.scope(function() {
20 var Adapter = i18n.input.chrome.inputview.Adapter;
21 var FeatureName = i18n.input.chrome.inputview.FeatureName; 20 var FeatureName = i18n.input.chrome.inputview.FeatureName;
22 21
23 22
24 /** 23 /**
25 * Controller for experimental features. 24 * Controller for experimental features.
26 * 25 *
27 * @constructor 26 * @constructor
28 */ 27 */
29 i18n.input.chrome.inputview.FeatureTracker = function() { 28 i18n.input.chrome.inputview.FeatureTracker = function() {
30 29
31 /** 30 /**
32 * Whether experimental flags is enabled. 31 * Whether experimental flags is enabled.
33 * 32 *
34 * @private {Object.<string, boolean>} 33 * @private {Object.<string, boolean>}
35 */ 34 */
36 this.features_ = {}; 35 this.features_ = {};
37 36
38 /** 37 /**
39 * Features that are enabled by default. Any feature not on this list is 38 * Features that are enabled by default. Any feature not on this list is
40 * disabled unless the runtime --enable-inputview-{feature} flag is present. 39 * disabled unless the runtime --enable-inputview-{feature} flag is present.
41 * 40 *
42 * @const 41 * @const
43 * @private {!Array<FeatureName>} 42 * @private {!Array<FeatureName>}
44 */ 43 */
45 this.ENABLED_BY_DEFAULT_ = []; 44 this.ENABLED_BY_DEFAULT_ = [];
45
46 /**
47 * Whether the features list is ready.
48 *
49 * @private {boolean}
50 */
51 this.ready_ = false;
46 }; 52 };
47 53
48 var FeatureTracker = i18n.input.chrome.inputview.FeatureTracker; 54 var FeatureTracker = i18n.input.chrome.inputview.FeatureTracker;
49 55
50 56
51 /** 57 /**
52 * Whether the feature is enabled. 58 * Whether the feature is enabled.
53 * 59 *
54 * @param {!FeatureName} feature . 60 * @param {!FeatureName} feature .
55 * @return {boolean} 61 * @return {boolean}
56 */ 62 */
57 FeatureTracker.prototype.isEnabled = function(feature) { 63 FeatureTracker.prototype.isEnabled = function(feature) {
64 if (!this.ready_) {
65 console.error('Features not present in config or not ready yet.');
66 }
58 if (feature in this.features_) { 67 if (feature in this.features_) {
59 return this.features_[feature]; 68 return this.features_[feature];
60 } 69 }
61 return (this.ENABLED_BY_DEFAULT_.indexOf(feature) >= 0) || 70 return (this.ENABLED_BY_DEFAULT_.indexOf(feature) >= 0) ||
62 !!this.features_[FeatureName.EXPERIMENTAL]; 71 !!this.features_[FeatureName.EXPERIMENTAL];
63 }; 72 };
64 73
65 74
66 /** 75 /**
67 * Inits the feature tracker. 76 * Inits the feature tracker.
68 * 77 *
69 * @param {!Object} config The keyboard config. 78 * @param {!Object} config The keyboard config.
70 */ 79 */
71 FeatureTracker.prototype.initialize = function(config) { 80 FeatureTracker.prototype.initialize = function(config) {
72 if (config.features) { 81 if (config.features) {
73 var features = config.features; 82 var features = config.features;
74 // Parse the run time flags. 83 // Parse the run time flags.
75 for (var i = 0; i < features.length; i++) { 84 for (var i = 0; i < features.length; i++) {
76 var pieces = features[i].split('-'); 85 var pieces = features[i].split('-');
77 var state = pieces.pop(); 86 var state = pieces.pop();
78 if (state == 'enabled') { 87 if (state == 'enabled') {
79 this.features_[pieces.join('-')] = true; 88 this.features_[pieces.join('-')] = true;
80 } else if (state == 'disabled') { 89 } else if (state == 'disabled') {
81 this.features_[pieces.join('-')] = false; 90 this.features_[pieces.join('-')] = false;
82 } else { 91 } else {
83 console.error('Unrecognized flag: ' + features[i]); 92 console.error('Unrecognized flag: ' + features[i]);
84 } 93 }
85 } 94 }
95 this.ready_ = true;
86 } else { 96 } else {
87 console.error('API Error. Features not present in config.'); 97 console.error('API Error. Features not present in config.');
88 return; 98 return;
89 } 99 }
90 }; 100 };
91 101
92 }); // goog.scope 102 }); // goog.scope
93 103
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698