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

Unified Diff: chrome/browser/resources/settings/prefs/selectable_pref_behavior.js

Issue 1422023012: MD Settings: Simplify settings-dropdown-menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/settings/prefs/selectable_pref_behavior.js
diff --git a/chrome/browser/resources/settings/prefs/selectable_pref_behavior.js b/chrome/browser/resources/settings/prefs/selectable_pref_behavior.js
new file mode 100644
index 0000000000000000000000000000000000000000..137f019ad02b82058d2f17d36e9bbc504354a408
--- /dev/null
+++ b/chrome/browser/resources/settings/prefs/selectable_pref_behavior.js
@@ -0,0 +1,47 @@
+// Copyright 2015 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 Behavior to convert between a pref value and a string.
+ */
+
+/** @polymerBehavior */
+var SelectablePrefBehavior = {
+ /**
+ * @param {string} value
+ * @return {*}
+ */
+ toPrefValue: function(value) {
stevenjb 2015/11/11 02:04:22 nit: Even tho we're using Closure to type values,
+ if (!this.pref)
+ return undefined;
stevenjb 2015/11/11 02:04:22 I have a slight preference for passing 'this.pref'
michaelpg 2015/11/11 20:29:21 I see your point, but then, should something like
stevenjb 2015/11/11 20:42:28 It certainly could be. In this case maybe that wou
+ if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) {
+ var n = parseInt(value, 10);
+ if (isNaN(n)) {
+ console.error('Bad selected name for numerical pref: ' + value);
+ return undefined;
+ }
+ return n;
+ } else if (this.pref.type == chrome.settingsPrivate.PrefType.BOOLEAN) {
+ return value == 'true';
+ } else {
+ assert(this.pref.type == chrome.settingsPrivate.PrefType.STRING);
+ return value;
+ }
+ },
+
+ /**
+ * Returns the string value of the pref.
+ * @return {string}
+ */
+ prefToString: function() {
+ if (!this.pref)
+ return '';
+ if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER ||
+ this.pref.type == chrome.settingsPrivate.PrefType.BOOLEAN) {
+ return this.pref.value.toString();
+ }
+ assert(this.pref.type == chrome.settingsPrivate.PrefType.STRING);
+ return /** @type {string} */(this.pref.value);
+ },
+};

Powered by Google App Engine
This is Rietveld 408576698