Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> | 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> |
| 4 * Copyright (C) 2009 Joseph Pecoraro | 4 * Copyright (C) 2009 Joseph Pecoraro |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * | 9 * |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 801 child = child.nextSibling; | 801 child = child.nextSibling; |
| 802 } | 802 } |
| 803 // Hide children item. | 803 // Hide children item. |
| 804 if (this._childrenListNode) | 804 if (this._childrenListNode) |
| 805 this._childrenListNode.style.display = "none"; | 805 this._childrenListNode.style.display = "none"; |
| 806 // Append editor. | 806 // Append editor. |
| 807 this.listItemElement.appendChild(this._htmlEditElement); | 807 this.listItemElement.appendChild(this._htmlEditElement); |
| 808 this.listItemElement.classList.add("editing-as-html"); | 808 this.listItemElement.classList.add("editing-as-html"); |
| 809 this.treeOutline.element.addEventListener("mousedown", consume, false); | 809 this.treeOutline.element.addEventListener("mousedown", consume, false); |
| 810 | 810 |
| 811 self.runtime.extension(WebInspector.TextEditorFactory).instance().then(g otFactory.bind(this)); | |
| 812 | |
| 811 /** | 813 /** |
| 812 * @param {!Element} element | 814 * @param {!WebInspector.TextEditorFactory} factory |
| 813 * @param {string} newValue | |
| 814 * @this {WebInspector.ElementsTreeElement} | 815 * @this {WebInspector.ElementsTreeElement} |
| 815 */ | 816 */ |
| 816 function commit(element, newValue) | 817 function gotFactory(factory) |
| 817 { | 818 { |
| 818 commitCallback(initialValue, newValue); | 819 var editor = factory.createEditor({ |
| 819 dispose.call(this); | 820 lineNumbers: false, |
| 821 lineWrapping: WebInspector.moduleSetting("domWordWrap").get(), | |
| 822 mimeType: "text/html", | |
| 823 autoHeight: false | |
| 824 }); | |
| 825 this._htmlEditElement.classList.toggle("multiline-editor", true); | |
|
lushnikov
2016/09/27 18:28:40
can we re-use existing css class for this?
einbinder
2016/09/29 17:36:50
Done.
| |
| 826 editor.widget().show(this._htmlEditElement); | |
| 827 editor.setText(initialValue); | |
| 828 editor.widget().focus(); | |
| 829 var cancelled = false; | |
| 830 this._editing = { | |
| 831 commit: commit.bind(this), | |
| 832 cancel: cancel.bind(this), | |
| 833 editorForTest: editor | |
| 834 } | |
| 835 this.treeOutline.setMultilineEditing(this._editing); | |
| 836 editor.widget().element.addEventListener("blur", this._editing.commi t, true); | |
| 837 editor.widget().element.addEventListener("keydown", keydown.bind(thi s), true); | |
| 838 | |
| 839 /** | |
| 840 * @this {WebInspector.ElementsTreeElement} | |
| 841 */ | |
| 842 function cancel() | |
| 843 { | |
| 844 if (cancelled) | |
|
lushnikov
2016/09/27 18:28:41
maybe you can remove blur listener somewhere?
einbinder
2016/09/29 17:36:51
Done.
| |
| 845 return; | |
| 846 cancelled = true; | |
| 847 editor.widget().detach(); | |
| 848 this._htmlEditElement.classList.toggle("multiline-editor", false ); | |
|
lushnikov
2016/09/27 18:28:41
you probably can just throw away the this._htmlEdi
einbinder
2016/09/29 17:36:51
done.
| |
| 849 disposeCallback(); | |
|
lushnikov
2016/09/27 18:28:41
can we move this to the very end of the cancel fun
einbinder
2016/09/29 17:36:50
We can move to to right before we focus the treeOu
| |
| 850 delete this._editing; | |
| 851 | |
| 852 this.listItemElement.classList.remove("editing-as-html"); | |
| 853 // Remove editor. | |
| 854 this.listItemElement.removeChild(this._htmlEditElement); | |
| 855 delete this._htmlEditElement; | |
| 856 // Unhide children item. | |
| 857 if (this._childrenListNode) | |
| 858 this._childrenListNode.style.removeProperty("display"); | |
| 859 // Unhide header items. | |
| 860 var child = this.listItemElement.firstChild; | |
| 861 while (child) { | |
| 862 child.style.removeProperty("display"); | |
| 863 child = child.nextSibling; | |
| 864 } | |
| 865 | |
| 866 if (!this.treeOutline) | |
| 867 return; | |
| 868 this.treeOutline.element.removeEventListener("mousedown", consum e, false); | |
| 869 this.treeOutline.focus(); | |
| 870 } | |
| 871 | |
| 872 /** | |
| 873 * @this {WebInspector.ElementsTreeElement} | |
| 874 */ | |
| 875 function commit() | |
| 876 { | |
| 877 if (cancelled) | |
| 878 return; | |
| 879 commitCallback(initialValue, editor.text()); | |
| 880 this._editing.cancel.call(this); | |
| 881 } | |
| 882 | |
| 883 /** | |
| 884 * @param {!Event} event | |
| 885 * @this {WebInspector.ElementsTreeElement} | |
| 886 */ | |
| 887 function keydown(event) | |
| 888 { | |
| 889 var isMetaOrCtrl = WebInspector.isMac() ? | |
| 890 event.metaKey && !event.shiftKey && !event.ctrlKey && !event .altKey : | |
| 891 event.ctrlKey && !event.shiftKey && !event.metaKey && !event .altKey; | |
| 892 | |
| 893 if (isEnterKey(event) && (isMetaOrCtrl || event.isMetaOrCtrlForT est)) | |
| 894 this._editing.commit(); | |
| 895 else if (event.key === "Escape") | |
| 896 this._editing.cancel(); | |
| 897 } | |
| 820 } | 898 } |
| 821 | 899 |
| 822 /** | |
| 823 * @this {WebInspector.ElementsTreeElement} | |
| 824 */ | |
| 825 function dispose() | |
| 826 { | |
| 827 disposeCallback(); | |
| 828 delete this._editing; | |
| 829 this.treeOutline.setMultilineEditing(null); | |
| 830 | |
| 831 this.listItemElement.classList.remove("editing-as-html"); | |
| 832 // Remove editor. | |
| 833 this.listItemElement.removeChild(this._htmlEditElement); | |
| 834 delete this._htmlEditElement; | |
| 835 // Unhide children item. | |
| 836 if (this._childrenListNode) | |
| 837 this._childrenListNode.style.removeProperty("display"); | |
| 838 // Unhide header items. | |
| 839 var child = this.listItemElement.firstChild; | |
| 840 while (child) { | |
| 841 child.style.removeProperty("display"); | |
| 842 child = child.nextSibling; | |
| 843 } | |
| 844 | |
| 845 this.treeOutline.element.removeEventListener("mousedown", consume, f alse); | |
| 846 this.treeOutline.focus(); | |
| 847 } | |
| 848 | |
| 849 var config = new WebInspector.InplaceEditor.Config(commit.bind(this), di spose.bind(this)); | |
| 850 config.setMultilineOptions(initialValue, { name: "xml", htmlMode: true } , "web-inspector-html", WebInspector.moduleSetting("domWordWrap").get(), true); | |
| 851 WebInspector.InplaceEditor.startMultilineEditing(this._htmlEditElement, config).then(markAsBeingEdited.bind(this)); | |
| 852 | |
| 853 /** | |
| 854 * @param {!Object} controller | |
| 855 * @this {WebInspector.ElementsTreeElement} | |
| 856 */ | |
| 857 function markAsBeingEdited(controller) | |
| 858 { | |
| 859 this._editing = /** @type {!WebInspector.InplaceEditor.Controller} * / (controller); | |
| 860 this._editing.setWidth(this.treeOutline.visibleWidth()); | |
| 861 this.treeOutline.setMultilineEditing(this._editing); | |
| 862 } | |
| 863 }, | 900 }, |
| 864 | 901 |
| 865 _attributeEditingCommitted: function(element, newText, oldText, attributeNam e, moveDirection) | 902 _attributeEditingCommitted: function(element, newText, oldText, attributeNam e, moveDirection) |
| 866 { | 903 { |
| 867 delete this._editing; | 904 delete this._editing; |
| 868 | 905 |
| 869 var treeOutline = this.treeOutline; | 906 var treeOutline = this.treeOutline; |
| 870 | 907 |
| 871 /** | 908 /** |
| 872 * @param {?Protocol.Error=} error | 909 * @param {?Protocol.Error=} error |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1527 return; | 1564 return; |
| 1528 this._node.removeNode(); | 1565 this._node.removeNode(); |
| 1529 }, | 1566 }, |
| 1530 | 1567 |
| 1531 /** | 1568 /** |
| 1532 * @param {function(boolean)=} callback | 1569 * @param {function(boolean)=} callback |
| 1533 * @param {boolean=} startEditing | 1570 * @param {boolean=} startEditing |
| 1534 */ | 1571 */ |
| 1535 toggleEditAsHTML: function(callback, startEditing) | 1572 toggleEditAsHTML: function(callback, startEditing) |
| 1536 { | 1573 { |
| 1537 if (this._editing && this._htmlEditElement && WebInspector.isBeingEdited (this._htmlEditElement)) { | 1574 if (this._editing && this._htmlEditElement) { |
| 1538 this._editing.commit(); | 1575 this._editing.commit(); |
| 1539 return; | 1576 return; |
| 1540 } | 1577 } |
| 1541 | 1578 |
| 1542 if (startEditing === false) | 1579 if (startEditing === false) |
| 1543 return; | 1580 return; |
| 1544 | 1581 |
| 1545 /** | 1582 /** |
| 1546 * @param {?Protocol.Error} error | 1583 * @param {?Protocol.Error} error |
| 1547 */ | 1584 */ |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1626 }, | 1663 }, |
| 1627 | 1664 |
| 1628 _editAsHTML: function() | 1665 _editAsHTML: function() |
| 1629 { | 1666 { |
| 1630 var promise = WebInspector.Revealer.revealPromise(this.node()); | 1667 var promise = WebInspector.Revealer.revealPromise(this.node()); |
| 1631 promise.then(() => WebInspector.actionRegistry.action("elements.edit-as- html").execute()); | 1668 promise.then(() => WebInspector.actionRegistry.action("elements.edit-as- html").execute()); |
| 1632 }, | 1669 }, |
| 1633 | 1670 |
| 1634 __proto__: TreeElement.prototype | 1671 __proto__: TreeElement.prototype |
| 1635 } | 1672 } |
| OLD | NEW |