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

Unified Diff: chrome/browser/resources/settings/input/input.js

Issue 1368733002: Introduce cr-settings-input and eliminate cr-input (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue_532540_elim_cr_toggle_button
Patch Set: Rebase Created 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/settings/input/input.js
diff --git a/chrome/browser/resources/settings/input/input.js b/chrome/browser/resources/settings/input/input.js
new file mode 100644
index 0000000000000000000000000000000000000000..ee1e582fb8b63b93b5dbc0298854bdabb1b1db50
--- /dev/null
+++ b/chrome/browser/resources/settings/input/input.js
@@ -0,0 +1,138 @@
+// 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
+ * `cr-settings-input` is a single-line text field for user input associated
+ * with a pref value.
+ *
+ * @element cr-settings-input
+ */
+Polymer({
+ is: 'cr-settings-input',
+
+ behaviors: [PolicyControllable],
+
+ properties: {
+ /**
+ * The preference object to control.
+ * @type {chrome.settingsPrivate.PrefObject|undefined}
+ */
+ pref: {
+ type: Object,
+ notify: true,
+ observer: 'prefChanged_'
+ },
+
+ /**
+ * The current value of the input, reflected to/from |pref|.
+ */
+ value: {
+ type: String,
+ value: '',
+ notify: true,
+ },
+
+ /**
+ * Set to true to disable editing the input.
+ */
+ disabled: {
+ type: Boolean,
+ value: false,
+ reflectToAttribute: true
+ },
+
+ /** Propagate the errorMessage property. */
+ errorMessage: { type: String },
+
+ /** Propagate the label property. */
+ label: { type: String },
+
+ /** Propagate the no-label-float property. */
+ noLabelFloat: { type: Boolean, value: false },
+
+ /** Propagate the pattern property. */
+ pattern: { type: String },
+
+ /** Propagate the readonly property. */
+ readonly: { type: Boolean, value: false },
+
+ /** Propagate the required property. */
+ required: { type: Boolean, value: false },
+
+ /** Propagate the type property. */
+ type: { type: String },
+ },
+
+ /** @override */
+ ready: function() {
+ this.$.events.forward(this.$.input, ['change']);
+ },
+
+ /**
+ * Focuses the 'input' element.
+ */
+ focus: function() {
+ this.$.input.inputElement.focus();
+ },
+
+ /**
+ * Polymer changed observer for |pref|.
+ * @private
+ */
+ prefChanged_: function() {
+ if (!this.pref)
+ return;
+
+ // Ignore updates while the input is focused so that user input is not
+ // overwritten.
+ if (this.$.input.focused)
+ return;
+
+ if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) {
+ this.value = this.pref.value.toString();
+ } else {
+ assert(this.pref.type == chrome.settingsPrivate.PrefType.STRING ||
+ this.pref.type == chrome.settingsPrivate.PrefType.URL);
+ this.value = /** @type {string} */(this.pref.value);
+ }
+ },
+
+ /**
+ * Blur method for paper-input. Only update the pref value on a blur event.
+ * @private
+ */
+ onBlur_: function() {
+ if (!this.pref)
+ return;
+
+ if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) {
+ if (!this.value) {
+ // Ignore empty input field and restore value.
+ this.value = this.pref.value.toString();
+ return;
+ }
+ var n = parseInt(this.value, 10);
+ if (isNaN(n)) {
+ console.error('Bad value for numerical pref: ' + this.value);
+ return;
+ }
+ this.set('pref.value', n);
+ } else {
+ assert(this.pref.type == chrome.settingsPrivate.PrefType.STRING ||
+ this.pref.type == chrome.settingsPrivate.PrefType.URL);
+ this.set('pref.value', this.value);
+ }
+ },
+
+ /**
+ * @param {boolean} disabled
+ * @param {?chrome.settingsPrivate.PrefObject} pref
+ * @return {boolean} Whether the element should be disabled.
+ * @private
+ */
+ isDisabled_: function(disabled, pref) {
+ return disabled || this.isPolicyControlled(pref);
+ },
+});
« no previous file with comments | « chrome/browser/resources/settings/input/input.html ('k') | chrome/browser/resources/settings/internet_page/network_proxy.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698