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

Unified Diff: chrome/browser/resources/options/inline_editable_list.js

Issue 6303003: DOMUI Prefs: Implement inline editability for startup pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CSS tweak Created 9 years, 11 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/options/inline_editable_list.js
diff --git a/chrome/browser/resources/options/inline_editable_list.js b/chrome/browser/resources/options/inline_editable_list.js
index ec0f4a472628a9ddb6bce505b682313f4a722479..84764989bf0c29cf4ec8be8b694ccb25f7cd1467 100644
--- a/chrome/browser/resources/options/inline_editable_list.js
+++ b/chrome/browser/resources/options/inline_editable_list.js
@@ -90,10 +90,12 @@ cr.define('options', function() {
}, 50);
}
} else {
- if (!this.editCancelled_ && this.hasBeenEdited() &&
+ if (!this.editCancelled_ && this.hasBeenEdited &&
this.currentInputIsValid) {
+ this.updateStaticValues_();
cr.dispatchSimpleEvent(this, 'commitedit', true);
} else {
+ this.resetEditableValues_();
cr.dispatchSimpleEvent(this, 'canceledit', true);
}
}
@@ -114,11 +116,12 @@ cr.define('options', function() {
/**
* The HTML element that should have focus initially when editing starts.
- * Should be overriden by subclasses.
+ * Defaults to the first <input> element; can be overriden by subclasses if
+ * a different element should be focused.
* @type {HTMLElement}
*/
get initialFocusElement() {
- return null;
+ return this.contentElement.querySelector('input');
},
/**
@@ -126,6 +129,7 @@ cr.define('options', function() {
* when editing would be submitted, either editing will not be ended,
* or it will be cancelled, depending on the context.
* Can be overrided by subclasses to perform input validation.
+ * @type {boolean}
*/
get currentInputIsValid() {
return true;
@@ -135,12 +139,81 @@ cr.define('options', function() {
* Returns true if the item has been changed by an edit.
* Can be overrided by subclasses to return false when nothing has changed
* to avoid unnecessary commits.
+ * @type {boolean}
*/
- hasBeenEdited: function() {
+ get hasBeenEdited() {
return true;
},
/**
+ * Returns a div containing an <input>, as well as static text if
+ * opt_alwaysEditable is not true.
+ * @param {string} text The text of the cell.
+ * @param {bool} opt_alwaysEditable True if the cell always shows the input.
+ * @return {HTMLElement} The HTML element for the cell.
+ * @private
+ */
+ createEditableTextCell: function(text, opt_alwaysEditable) {
+ var container = this.ownerDocument.createElement('div');
+
+ if (!opt_alwaysEditable) {
+ var textEl = this.ownerDocument.createElement('div');
+ textEl.className = 'static-text';
+ textEl.textContent = text;
+ textEl.setAttribute('editmode', false);
+ container.appendChild(textEl);
+ }
+
+ var inputEl = this.ownerDocument.createElement('input');
+ inputEl.type = 'text';
+ inputEl.value = text;
+ if (!opt_alwaysEditable) {
+ inputEl.setAttribute('editmode', true);
+ inputEl.staticVersion = textEl;
+ }
+ container.appendChild(inputEl);
+
+ return container;
+ },
+
+ /**
+ * Resets the editable version of any controls created by createEditable*
+ * to match the static text.
+ * @private
+ */
+ resetEditableValues_: function() {
+ var editFields = this.querySelectorAll('[editmode=true]');
+ for (var i = 0; i < editFields.length; i++) {
+ var staticLabel = editFields[i].staticVersion;
+ if (!staticLabel)
+ continue;
+ if (editFields[i].tagName == 'INPUT')
+ editFields[i].value = staticLabel.textContent;
+ // Add more tag types here as new createEditable* methods are added.
+
+ editFields[i].setCustomValidity('');
+ }
+ },
+
+ /**
+ * Sets the static version of any controls created by createEditable*
+ * to match the current value of the editable version. Called on commit so
+ * that there's no flicker of the old value before the model updates.
+ * @private
+ */
+ updateStaticValues_: function() {
+ var editFields = this.querySelectorAll('[editmode=true]');
+ for (var i = 0; i < editFields.length; i++) {
+ var staticLabel = editFields[i].staticVersion;
+ if (!staticLabel)
+ continue;
+ if (editFields[i].tagName == 'INPUT')
+ staticLabel.textContent = editFields[i].value;
+ // Add more tag types here as new createEditable* methods are added.
+ }
+ },
+
+ /**
* Called a key is pressed. Handles committing and cancelling edits.
* @param {Event} e The key down event.
* @private
« no previous file with comments | « chrome/browser/resources/options/content_settings.css ('k') | chrome/browser/resources/options/options_page.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698